From 634f9390071d0f48f958ad88368af8dd0e38fb69 Mon Sep 17 00:00:00 2001 From: notGreg Date: Mon, 20 Feb 2023 17:08:45 +0100 Subject: [PATCH] Fixed an exception related to updating a non-existent camera Temporarily disabled main camera resolution change due to performance issues --- CameraResolutionScale/Plugin.cs | 64 +++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/CameraResolutionScale/Plugin.cs b/CameraResolutionScale/Plugin.cs index fa0e3be..74dd21c 100644 --- a/CameraResolutionScale/Plugin.cs +++ b/CameraResolutionScale/Plugin.cs @@ -161,7 +161,7 @@ namespace ScopeTweaks if (enableDebug.Value) Logger.LogInfo($"set_defaultInGameFOV: Writing to settings: {value}"); //settingsLibrary.Game.Settings.FieldOfView.Value = value; //int fov = Singleton.Instance.Game.Settings.FieldOfView.Value; - int fov = Singleton.Instance.Game.Settings.FieldOfView.Value; // SPT-AKI 3.5.0 + Singleton.Instance.Game.Settings.FieldOfView.Value = value; // SPT-AKI 3.5.0 } } @@ -183,6 +183,7 @@ namespace ScopeTweaks { FPSCamera = GameObject.Find(cameraName).GetComponent(); if (enableDebug.Value) Logger.LogInfo($"{FPSCamera.name} found!"); + StopCoroutine(tryGetMainCamera()); } else { @@ -206,27 +207,26 @@ namespace ScopeTweaks { scopeCamera = GameObject.Find(cameraName).GetComponent(); if (enableDebug.Value) Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!"); + StopCoroutine(tryGetScopeCamera()); } yield break; } - void setMainCameraResolutionScale(int value = 100) { - - //if (settingsLibrary.Graphics.Settings.DLSSEnabled) - //if (Singleton.Instance.Graphics.Settings.DLSSEnabled) - if (Singleton.Instance.Graphics.Settings.DLSSEnabled) + if (ssaaInstance == null) { - if (enableDebug.Value) Logger.LogInfo("DLSS enabled - skipping MainCamera resolution change"); - return; + ssaaInstance = FPSCamera.GetComponent(); + _nextSSRation = getFieldInfo("_nextSSRation"); } + float target_res = currentScalingFactor * (value / 100.0f); - if (enableDebug.Value) Logger.LogInfo($"Setting MainCam res scale to {value}%"); - ssaaInstance = FPSCamera.GetComponent(); - _nextSSRation = getFieldInfo("_nextSSRation"); - _nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * value / 100f)); + if (enableDebug.Value) Logger.LogInfo($"Setting MainCam res scale to {target_res}%"); + //_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * (value / 100.0f))); + } + SSAAOptic ssaaOpticInstance = null; + void setScopeCameraResolutionScale(int value) { if (scopeCamera == null || !scopeCamera.isActiveAndEnabled) @@ -236,7 +236,13 @@ namespace ScopeTweaks } if (enableDebug.Value) Logger.LogInfo($"Setting Scope res scale to {value}%"); - scopeCamera.GetComponent().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100f)); + + if (ssaaOpticInstance == null) + { + ssaaOpticInstance = scopeCamera.GetComponent(); + } + + ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100.0f)); } /// @@ -259,7 +265,7 @@ namespace ScopeTweaks { currentScalingFactor = getCurrentScalingFactor(); StartCoroutine(tryGetScopeCamera()); - + if (!mainPlayer.ProceduralWeaponAnimation.IsAiming) { switch (scopeFixType.Value) @@ -306,10 +312,13 @@ namespace ScopeTweaks case EFOVScalingMode.ScopesOnly: { if (enableDebug.Value) Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}"); - if (scopeCamera.isActiveAndEnabled) + if (scopeCamera != null && scopeCamera.isActiveAndEnabled) + { + applyFixesWhileAiming(); + } + else { if (enableDebug.Value) Logger.LogInfo("ScopeCamera not found or disabled!"); - applyFixesWhileAiming(); } break; } @@ -328,10 +337,10 @@ namespace ScopeTweaks void applyFixesWhileAiming() { - if (enableDebug.Value) Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}"); - if (enableDebug.Value) Logger.LogInfo("Changing FOV while aiming"); + //if (enableDebug.Value) Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}"); + if (enableDebug.Value) Logger.LogInfo("Applying aiming tweaks"); - setFovLibrary.SetFov(35, 0.25f, false); //SPT-AKI 3.3.0 + setFovLibrary.SetFov(35, 0.25f, false); inGameFOV = 50; if (enableDebug.Value) Logger.LogInfo("Updating scope resolution"); @@ -352,11 +361,11 @@ namespace ScopeTweaks //var graphics = Singleton.Instance.Graphics.Settings; // SPT-AKI 3.4.1 var graphics = Singleton.Instance.Graphics.Settings; // SPT-AKI 3.5.0 - if (!graphics.DLSSEnabled && !graphics.FSREnabled) - { - if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}"); - return graphics.SuperSamplingFactor; - } + //if (!graphics.DLSSEnabled && !graphics.FSREnabled) + //{ + // if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}"); + // return graphics.SuperSamplingFactor; + //} if (graphics.DLSSEnabled) { @@ -401,8 +410,11 @@ namespace ScopeTweaks return FSR2Factor; } - if (enableDebug.Value) Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f"); - return 1.0f; + if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}"); + return graphics.SuperSamplingFactor; + + //if (enableDebug.Value) Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f"); + //return 1.0f; } } } \ No newline at end of file