diff --git a/CameraResolutionScale/Patch.cs b/CameraResolutionScale/Patch.cs index 61ea1ef..933e727 100644 --- a/CameraResolutionScale/Patch.cs +++ b/CameraResolutionScale/Patch.cs @@ -8,7 +8,7 @@ namespace ScopeTweaks { protected override MethodBase GetTargetMethod() { - return typeof(EFT.Player).GetMethod("CalculateScaleValueByFov"); + return typeof(Player).GetMethod("CalculateScaleValueByFov"); } [PatchPostfix] public static void PatchPostfix(ref float ___float_10) diff --git a/CameraResolutionScale/Plugin.cs b/CameraResolutionScale/Plugin.cs index ae034ac..41cca1d 100644 --- a/CameraResolutionScale/Plugin.cs +++ b/CameraResolutionScale/Plugin.cs @@ -5,6 +5,7 @@ using Comfort.Common; using EFT; using EFT.Settings.Graphics; using System.Collections; +using System.Reflection; using UnityEngine; /* Dependencies: @@ -29,7 +30,6 @@ namespace ScopeTweaks ConfigEntry scopeCameraResolutionScale; ConfigEntry enableDebug; - void Awake() { if (Chainloader.PluginInfos.ContainsKey("FOVFix")) @@ -50,12 +50,30 @@ namespace ScopeTweaks enableDebug = Config.Bind("Debug", "Enable debug logging", false); } - void FixedUpdate() + void Update() { //Check if the game is in a valid state and execute logic depening on the status of the game if (Singleton.Instance == null) return; GameStatus currentGameState = Singleton.Instance.Status; + if (mainPlayer != null) + { + int inGameFov = Singleton.Instance.Game.Settings.FieldOfView; + float fov_clamped = Mathf.Clamp(inGameFov, 50, 75); + target_scale = Mathf.Lerp(1.0f, 0.65f, (fov_clamped - 50) / 25); + + if (mainPlayer.ProceduralWeaponAnimation.IsAiming) + { + mainPlayer.RibcageScaleCurrent = 1.0f; + mainPlayer.RibcageScaleCurrentTarget = 1.0f; + } + else + { + mainPlayer.RibcageScaleCurrentTarget = target_scale; + mainPlayer.RibcageScaleCurrent = target_scale; + } + } + //logic should only execute once per game instead of every frame if (!gameStateChanged(currentGameState)) return; @@ -144,7 +162,7 @@ namespace ScopeTweaks ssaaOpticInstance = scopeCamera.GetComponent(); } - ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100.0f)); + ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentResoScalingFactor * (value / 100.0f)); } /// @@ -160,24 +178,26 @@ namespace ScopeTweaks }; } + internal static float target_scale = 1.0f; void subscribeOnAimingChangedEvent() { if (enableDebug.Value) Logger.LogInfo("Subscribing to OnAimingChanged Event"); mainPlayer.HandsController.OnAimingChanged += (aimingArgs) => { - currentScalingFactor = getCurrentScalingFactor(); + currentResoScalingFactor = getcurrentResoScalingFactor(); StartCoroutine(tryGetScopeCamera()); if (mainPlayer.ProceduralWeaponAnimation.IsAiming) { + target_scale = 1.0f; setScopeCameraResolutionScale(scopeCameraResolutionScale.Value); } }; } - float currentScalingFactor = 1.0f; + float currentResoScalingFactor = 1.0f; - float getCurrentScalingFactor() + float getcurrentResoScalingFactor() { if (enableDebug.Value) Logger.LogInfo("Getting current scaling factor:"); var graphics = Singleton.Instance.Graphics.Settings;