updated to utilize SSAA ratios for the main camera
This commit is contained in:
parent
a9e11d0ba8
commit
19c13e03cd
@ -4,6 +4,7 @@ using EFT;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Comfort.Common;
|
using Comfort.Common;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace CameraResolutionScale
|
namespace CameraResolutionScale
|
||||||
{
|
{
|
||||||
@ -15,62 +16,80 @@ namespace CameraResolutionScale
|
|||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
cameraResolutionScale = Config.Bind("General", "Main camera scale %", 50, new ConfigDescription("Main camera resulution scae", new AcceptableValueRange<int>(10,200)));
|
cameraResolutionScale = Config.Bind("General", "Main camera scale %", 80, new ConfigDescription("Main camera resulution sclae", new AcceptableValueRange<int>(50, 100)));
|
||||||
scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 33, new ConfigDescription("Scope camera resulution scae", new AcceptableValueRange<int>(10, 200)));
|
scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 40, new ConfigDescription("Scope camera resulution scale", new AcceptableValueRange<int>(25, 100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect defaultMainCameraRect;
|
float defaultSSRatio = 1.0f;
|
||||||
|
Camera FPSCamera = null;
|
||||||
Camera scopeCamera = null;
|
Camera scopeCamera = null;
|
||||||
|
|
||||||
bool isAiming = false;
|
bool isAiming = false;
|
||||||
bool doneOnce = false;
|
bool doneOnce = false;
|
||||||
|
|
||||||
|
SSAA ssaaInstance = null;
|
||||||
|
FieldInfo _currentSSRatio = null;
|
||||||
|
FieldInfo _nextSSRation = null;
|
||||||
|
|
||||||
Utils utils = new Utils();
|
Utils utils = new Utils();
|
||||||
|
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (!utils.gameIsReady())
|
if (!utils.gameIsReady())
|
||||||
|
|
||||||
{
|
{
|
||||||
|
//reset everything ahead of time
|
||||||
|
FPSCamera = null;
|
||||||
|
scopeCamera = null;
|
||||||
|
doneOnce = false;
|
||||||
|
ssaaInstance = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Camera.allCamerasCount < 1) return;
|
if (Camera.allCamerasCount < 1) return;
|
||||||
|
|
||||||
|
if (GameObject.Find("FPS Camera") != null && FPSCamera == null)
|
||||||
|
{
|
||||||
|
FPSCamera = GameObject.Find("FPS Camera").GetComponent<Camera>();
|
||||||
|
}
|
||||||
|
if (GameObject.Find("BaseOpticCamera(Clone)") != null && scopeCamera == null)
|
||||||
|
{
|
||||||
|
scopeCamera = GameObject.Find("BaseOpticCamera(Clone)").GetComponent<Camera>();
|
||||||
|
}
|
||||||
|
|
||||||
var handsController = ((Singleton<GameWorld>.Instance.RegisteredPlayers[0].HandsController));
|
var handsController = ((Singleton<GameWorld>.Instance.RegisteredPlayers[0].HandsController));
|
||||||
isAiming = handsController.IsAiming;
|
isAiming = handsController.IsAiming;
|
||||||
|
|
||||||
|
if(ssaaInstance == null)
|
||||||
|
{
|
||||||
|
ssaaInstance = FPSCamera.GetComponent<SSAA>();
|
||||||
|
_nextSSRation = typeof(SSAA).GetField("_nextSSRation", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
_currentSSRatio = typeof(SSAA).GetField("_currentSSRatio", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
|
||||||
|
Logger.LogInfo($"Updating defaultSSRatio to {_nextSSRation.GetValue(ssaaInstance)}");
|
||||||
|
defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance);
|
||||||
|
}
|
||||||
|
|
||||||
if (isAiming && !doneOnce)
|
if (isAiming && !doneOnce)
|
||||||
{
|
{
|
||||||
if (Camera.main == null || Camera.allCamerasCount <= 1) return;
|
if (FPSCamera == null) return;
|
||||||
if (scopeCamera == null) scopeCamera = Camera.allCameras[1];
|
if (scopeCamera == null || scopeCamera.isActiveAndEnabled == false) return;
|
||||||
scopeCamera = Camera.allCameras[1];
|
|
||||||
|
_nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio * cameraResolutionScale.Value / 100f));
|
||||||
|
Logger.LogInfo($"Updated to: {_nextSSRation.GetValue(ssaaInstance)}");
|
||||||
|
|
||||||
|
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f);
|
||||||
|
|
||||||
StartCoroutine(setScaledCameraRes());
|
|
||||||
doneOnce = true;
|
doneOnce = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isAiming && doneOnce)
|
if (!isAiming && doneOnce)
|
||||||
{
|
{
|
||||||
StartCoroutine(unsetScaledCameraRes());
|
Logger.LogInfo($"Restoring default scale: {defaultSSRatio}");
|
||||||
|
_nextSSRation.SetValue(ssaaInstance, defaultSSRatio);
|
||||||
doneOnce = false;
|
doneOnce = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator setScaledCameraRes()
|
|
||||||
{
|
|
||||||
defaultMainCameraRect = Camera.main.rect;
|
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.05f);
|
|
||||||
|
|
||||||
Camera.main.rect = new Rect(0, 0, defaultMainCameraRect.width * (cameraResolutionScale.Value / 100f), defaultMainCameraRect.height * (cameraResolutionScale.Value / 100f));
|
|
||||||
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f);
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator unsetScaledCameraRes()
|
|
||||||
{
|
|
||||||
Camera.main.rect = defaultMainCameraRect;
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user