updated to utilize SSAA ratios for the main camera
This commit is contained in:
parent
a9e11d0ba8
commit
19c13e03cd
@ -4,8 +4,9 @@ using EFT;
|
||||
using UnityEngine;
|
||||
using Comfort.Common;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
|
||||
namespace CameraResolutionScale
|
||||
namespace CameraResolutionScale
|
||||
{
|
||||
[BepInPlugin("com.notGreg.cameraScaleControl", "notGreg's Camera Resolution Settings", "1.0.0")]
|
||||
public class Plugin : BaseUnityPlugin
|
||||
@ -15,62 +16,80 @@ namespace CameraResolutionScale
|
||||
|
||||
void Awake()
|
||||
{
|
||||
cameraResolutionScale = Config.Bind("General", "Main camera scale %", 50, new ConfigDescription("Main camera resulution scae", new AcceptableValueRange<int>(10,200)));
|
||||
scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 33, new ConfigDescription("Scope 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 %", 40, new ConfigDescription("Scope camera resulution scale", new AcceptableValueRange<int>(25, 100)));
|
||||
}
|
||||
|
||||
Rect defaultMainCameraRect;
|
||||
float defaultSSRatio = 1.0f;
|
||||
Camera FPSCamera = null;
|
||||
Camera scopeCamera = null;
|
||||
|
||||
bool isAiming = false;
|
||||
bool doneOnce = false;
|
||||
|
||||
SSAA ssaaInstance = null;
|
||||
FieldInfo _currentSSRatio = null;
|
||||
FieldInfo _nextSSRation = null;
|
||||
|
||||
Utils utils = new Utils();
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!utils.gameIsReady())
|
||||
|
||||
if (!utils.gameIsReady())
|
||||
{
|
||||
//reset everything ahead of time
|
||||
FPSCamera = null;
|
||||
scopeCamera = null;
|
||||
doneOnce = false;
|
||||
ssaaInstance = null;
|
||||
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));
|
||||
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 (Camera.main == null || Camera.allCamerasCount <= 1) return;
|
||||
if (scopeCamera == null) scopeCamera = Camera.allCameras[1];
|
||||
scopeCamera = Camera.allCameras[1];
|
||||
|
||||
StartCoroutine(setScaledCameraRes());
|
||||
if (FPSCamera == null) return;
|
||||
if (scopeCamera == null || scopeCamera.isActiveAndEnabled == false) return;
|
||||
|
||||
_nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio * cameraResolutionScale.Value / 100f));
|
||||
Logger.LogInfo($"Updated to: {_nextSSRation.GetValue(ssaaInstance)}");
|
||||
|
||||
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f);
|
||||
|
||||
doneOnce = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isAiming && doneOnce)
|
||||
if (!isAiming && doneOnce)
|
||||
{
|
||||
StartCoroutine(unsetScaledCameraRes());
|
||||
Logger.LogInfo($"Restoring default scale: {defaultSSRatio}");
|
||||
_nextSSRation.SetValue(ssaaInstance, defaultSSRatio);
|
||||
doneOnce = false;
|
||||
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