From dbfc74cd2635b5b49d12dcae482944765bb43a58 Mon Sep 17 00:00:00 2001 From: notGreg Date: Sat, 1 Apr 2023 16:46:33 +0200 Subject: [PATCH] Removed main camera resolution scale while aiming due to performance issues. Updated for SPT-AKI 3.5.3 --- CameraResolutionScale/Plugin.cs | 116 +++--------------- .../notGreg.ScopeTweaks.csproj | 40 +++--- 2 files changed, 36 insertions(+), 120 deletions(-) diff --git a/CameraResolutionScale/Plugin.cs b/CameraResolutionScale/Plugin.cs index d3b3db0..c193334 100644 --- a/CameraResolutionScale/Plugin.cs +++ b/CameraResolutionScale/Plugin.cs @@ -23,10 +23,9 @@ using UnityEngine; */ namespace ScopeTweaks { - [BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.0")] + [BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.3")] public class Plugin : BaseUnityPlugin { - ConfigEntry cameraResolutionScale; ConfigEntry scopeCameraResolutionScale; ConfigEntry scopeFixType; ConfigEntry enableDebug; @@ -41,25 +40,16 @@ namespace ScopeTweaks } //The following assignments should allow for faster patching in the future. - //The correct GClass can be found by searching for "ClearSettings" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc. - //GClass1642 settingsLibrary = Singleton.Instance; //used by SPT-AKI 3.2.3 - //GClass1653 settingsLibrary = Singleton.Instance; //used by SPT-AKI 3.3.0 - //GClass1659 settingsLibrary = Singleton.Instance; //used by SPT-AKI 3.4.1 + //The correct GClass can be found by searching for "ClearSettings" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc. + SharedGameSettingsClass settingsLibrary = Singleton.Instance; //The correct GClass can be found by searching for "SetFov" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc. - - //GClass1774 setFovLibrary = Singleton.Instance; //used by SPT-AKI 3.2.3 - //GClass1785 setFovLibrary = Singleton.Instance; //used by SPT-AKI 3.3.0 - CameraClass setFovLibrary = CameraClass.Instance; //used by SPT-AKI 3.4.1 and 3.5.0 + CameraClass setFovLibrary = CameraClass.Instance; void Awake() { - cameraResolutionScale = Config.Bind( - "General", - "Main camera scale %", - 80, - new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange(25, 100))); + scopeCameraResolutionScale = Config.Bind( "General", @@ -95,7 +85,6 @@ namespace ScopeTweaks subscribeHandsChangedEvent(); if (enableDebug.Value) Logger.LogInfo("Assigning cameras..."); - StartCoroutine(tryGetMainCamera()); StartCoroutine(tryGetScopeCamera()); defaultInGameFOV = inGameFOV; @@ -108,7 +97,6 @@ namespace ScopeTweaks { if (enableDebug.Value) Logger.LogInfo("Resetting..."); - FPSCamera = null; scopeCamera = null; mainPlayer = null; @@ -134,7 +122,7 @@ namespace ScopeTweaks return true; } - Player mainPlayer; + Player mainPlayer = null; //find and return the player character in the session Player getLocalPlayer() { @@ -153,56 +141,22 @@ namespace ScopeTweaks { get { - //int fov = settingsLibrary.Game.Settings.FieldOfView.Value; - //int fov = Singleton.Instance.Game.Settings.FieldOfView.Value; //SPT-AKI 3.4.1 - int fov = Singleton.Instance.Game.Settings.FieldOfView.Value; // SPT-AKI 3.5.0 + int fov = Singleton.Instance.Game.Settings.FieldOfView.Value; if (enableDebug.Value) Logger.LogInfo($"get_defaultInGameFOV: Reading from settings: {fov}"); return fov; } set { 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; - Singleton.Instance.Game.Settings.FieldOfView.Value = value; // SPT-AKI 3.5.0 + Singleton.Instance.Game.Settings.FieldOfView.Value = value; } } /// /// CAMERA SETUP /// - - Camera FPSCamera = null; Camera scopeCamera = null; - SSAA ssaaInstance = null; - FieldInfo _nextSSRation = null; - - WaitForSeconds myDelaySec = new WaitForSeconds(1); - IEnumerator tryGetMainCamera() - { - string cameraName = "FPS Camera"; - if (GameObject.Find(cameraName) != null) - { - FPSCamera = GameObject.Find(cameraName).GetComponent(); - if (enableDebug.Value) Logger.LogInfo($"{FPSCamera.name} found!"); - StopCoroutine(tryGetMainCamera()); - } - else - { - if (enableDebug.Value) Logger.LogMessage($"Camera \"{cameraName}\" not found."); - yield return myDelaySec; - StartCoroutine(tryGetMainCamera()); - yield break; - } - yield return null; - } - - FieldInfo getFieldInfo(string fieldName) - { - return typeof(SSAA).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance); - } - IEnumerator tryGetScopeCamera() { string cameraName = "BaseOpticCamera(Clone)"; @@ -214,19 +168,6 @@ namespace ScopeTweaks } yield break; } - void setMainCameraResolutionScale(int value = 100) - { - if (ssaaInstance == null) - { - ssaaInstance = FPSCamera.GetComponent(); - _nextSSRation = getFieldInfo("_nextSSRation"); - } - float target_res = currentScalingFactor * (value / 100.0f); - - if (enableDebug.Value) Logger.LogInfo($"Setting MainCam res scale to {Mathf.Round(target_res*100.0f)}%"); - //_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * (value / 100.0f))); - - } SSAAOptic ssaaOpticInstance = null; @@ -283,18 +224,19 @@ namespace ScopeTweaks case EFOVScalingMode.ScopesOnly: { if (enableDebug.Value) Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}"); - setMainCameraResolutionScale(); - setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, false); - inGameFOV = defaultInGameFOV; + if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic) + { + setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, false); + inGameFOV = defaultInGameFOV; - mainPlayer.ProceduralWeaponAnimation.ResetFovAdjustments(mainPlayer); + mainPlayer.ProceduralWeaponAnimation.ResetFovAdjustments(mainPlayer); + } break; } case EFOVScalingMode.All: { if (enableDebug.Value) Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}"); - setMainCameraResolutionScale(); setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, false); inGameFOV = defaultInGameFOV; @@ -309,6 +251,7 @@ namespace ScopeTweaks if (mainPlayer.ProceduralWeaponAnimation.IsAiming) { + Logger.LogInfo($"Scope: {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod.Item.LocalizedName()} isOptic: {mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic}"); defaultInGameFOV = inGameFOV; switch (scopeFixType.Value) { @@ -320,14 +263,10 @@ namespace ScopeTweaks case EFOVScalingMode.ScopesOnly: { if (enableDebug.Value) Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}"); - if (scopeCamera != null && scopeCamera.isActiveAndEnabled) + if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic) { applyFixesWhileAiming(); } - else - { - if (enableDebug.Value) Logger.LogInfo("ScopeCamera not found or disabled!"); - } break; } case EFOVScalingMode.All: @@ -345,37 +284,25 @@ namespace ScopeTweaks void applyFixesWhileAiming() { - //if (enableDebug.Value) Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}"); if (enableDebug.Value) Logger.LogInfo("Applying aiming tweaks"); float aimSpeed = mainPlayer.ProceduralWeaponAnimation.AimingSpeed * 0.7f; + // Classic method of forcing 50 fov while aiming + setFovLibrary.SetFov(35, aimSpeed, false); inGameFOV = 50; - if (enableDebug.Value) Logger.LogInfo("Updating scope resolution"); - setMainCameraResolutionScale(cameraResolutionScale.Value); + if (enableDebug.Value) Logger.LogInfo("Updating scope resolution"); setScopeCameraResolutionScale(scopeCameraResolutionScale.Value); } - /// - /// IN-GAME SETTINGS - /// - float currentScalingFactor = 1.0f; float getCurrentScalingFactor() { if (enableDebug.Value) Logger.LogInfo("Getting current scaling factor:"); - //var graphics = settingsLibrary.Graphics.Settings; //SPT-AKI 3.3.0 - //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; - //} + var graphics = Singleton.Instance.Graphics.Settings; if (graphics.DLSSEnabled) { @@ -422,9 +349,6 @@ namespace ScopeTweaks 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 diff --git a/CameraResolutionScale/notGreg.ScopeTweaks.csproj b/CameraResolutionScale/notGreg.ScopeTweaks.csproj index 89a2268..5595627 100644 --- a/CameraResolutionScale/notGreg.ScopeTweaks.csproj +++ b/CameraResolutionScale/notGreg.ScopeTweaks.csproj @@ -35,38 +35,30 @@ - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\BepInEx\core\BepInEx.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\BepInEx\core\BepInEx.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Comfort.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Comfort.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\ItemComponent.Types.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\ItemComponent.Types.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Unity.Postprocessing.Runtime.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Unity.Postprocessing.Runtime.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\UnityEngine.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\UnityEngine.dll - - False - E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll + + E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll