This commit is contained in:
notGreg 2022-09-16 10:29:54 +02:00
parent 19c13e03cd
commit f4a7536862

View File

@ -3,8 +3,8 @@ using BepInEx.Configuration;
using EFT; using EFT;
using UnityEngine; using UnityEngine;
using Comfort.Common; using Comfort.Common;
using System.Collections;
using System.Reflection; using System.Reflection;
using System;
namespace CameraResolutionScale namespace CameraResolutionScale
{ {
@ -14,10 +14,31 @@ namespace CameraResolutionScale
ConfigEntry<int> cameraResolutionScale; ConfigEntry<int> cameraResolutionScale;
ConfigEntry<int> scopeCameraResolutionScale; ConfigEntry<int> scopeCameraResolutionScale;
public event EventHandler SettingChanged;
void Awake() void Awake()
{ {
cameraResolutionScale = Config.Bind("General", "Main camera scale %", 80, new ConfigDescription("Main camera resulution sclae", new AcceptableValueRange<int>(50, 100))); 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))); scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 40, new ConfigDescription("Scope camera resulution scale", new AcceptableValueRange<int>(25, 100)));
cameraResolutionScale.SettingChanged += (s, args) =>
{
updateSSRatio();
};
scopeCameraResolutionScale.SettingChanged += (s, args) =>
{
updateSSRatio();
};
}
void updateSSRatio()
{
if (!isAiming && FPSCamera != null)
{
defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance);
Logger.LogInfo($"Updating defaultSSRatio to {defaultSSRatio}");
}
} }
float defaultSSRatio = 1.0f; float defaultSSRatio = 1.0f;
@ -38,30 +59,38 @@ namespace CameraResolutionScale
{ {
if (!utils.gameIsReady()) if (!utils.gameIsReady())
{ {
//reset everything ahead of time //Logger.LogInfo("Resetting...");
FPSCamera = null;
scopeCamera = null;
doneOnce = false; doneOnce = false;
FPSCamera = null;
ssaaInstance = null; ssaaInstance = null;
scopeCamera = null;
return; return;
} }
if (Camera.allCamerasCount < 1) return; if (Camera.main == null) return;
//Logger.LogInfo("Check FPS camera");
if (GameObject.Find("FPS Camera") != null && FPSCamera == null) if (GameObject.Find("FPS Camera") != null && FPSCamera == null)
{ {
//Logger.LogInfo("Assigning FPS Camera");
FPSCamera = GameObject.Find("FPS Camera").GetComponent<Camera>(); FPSCamera = GameObject.Find("FPS Camera").GetComponent<Camera>();
} }
//Logger.LogInfo("Check Scope camera");
if (GameObject.Find("BaseOpticCamera(Clone)") != null && scopeCamera == null) if (GameObject.Find("BaseOpticCamera(Clone)") != null && scopeCamera == null)
{ {
//Logger.LogInfo("Assigning Scope Camera");
scopeCamera = GameObject.Find("BaseOpticCamera(Clone)").GetComponent<Camera>(); 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;
//Logger.LogInfo("Checking ssaaInstance");
if(ssaaInstance == null) if(ssaaInstance == null)
{ {
ssaaInstance = FPSCamera.GetComponent<SSAA>(); ssaaInstance = FPSCamera.GetComponent<SSAA>();
//figure out a way to update it if resolution or reso scale changes
_nextSSRation = typeof(SSAA).GetField("_nextSSRation", BindingFlags.NonPublic | BindingFlags.Instance); _nextSSRation = typeof(SSAA).GetField("_nextSSRation", BindingFlags.NonPublic | BindingFlags.Instance);
_currentSSRatio = typeof(SSAA).GetField("_currentSSRatio", BindingFlags.NonPublic | BindingFlags.Instance); _currentSSRatio = typeof(SSAA).GetField("_currentSSRatio", BindingFlags.NonPublic | BindingFlags.Instance);
@ -69,6 +98,7 @@ namespace CameraResolutionScale
defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance); defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance);
} }
//Logger.LogInfo("Checking if isAiming");
if (isAiming && !doneOnce) if (isAiming && !doneOnce)
{ {
if (FPSCamera == null) return; if (FPSCamera == null) return;
@ -83,6 +113,7 @@ namespace CameraResolutionScale
return; return;
} }
//Logger.LogInfo("Checking if not isAiming");
if (!isAiming && doneOnce) if (!isAiming && doneOnce)
{ {
Logger.LogInfo($"Restoring default scale: {defaultSSRatio}"); Logger.LogInfo($"Restoring default scale: {defaultSSRatio}");