From 16daa9b33c314720e4e1831f58a0ed0d33bba021 Mon Sep 17 00:00:00 2001 From: notGreg Date: Tue, 4 Apr 2023 19:30:08 +0200 Subject: [PATCH] FOV scaling is now fixed via a method patch instead of arcane workarounds. This might be the one. Removed FOV scaling settings. --- CameraResolutionScale/Patch.cs | 19 +++ CameraResolutionScale/Plugin.cs | 155 +----------------- .../notGreg.ScopeTweaks.csproj | 1 + 3 files changed, 25 insertions(+), 150 deletions(-) create mode 100644 CameraResolutionScale/Patch.cs diff --git a/CameraResolutionScale/Patch.cs b/CameraResolutionScale/Patch.cs new file mode 100644 index 0000000..61ea1ef --- /dev/null +++ b/CameraResolutionScale/Patch.cs @@ -0,0 +1,19 @@ +using Aki.Reflection.Patching; +using EFT; +using System.Reflection; + +namespace ScopeTweaks +{ + internal class CalculateScaleValueByFovPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(EFT.Player).GetMethod("CalculateScaleValueByFov"); + } + [PatchPostfix] + public static void PatchPostfix(ref float ___float_10) + { + ___float_10 = 1.0f; + } + } +} diff --git a/CameraResolutionScale/Plugin.cs b/CameraResolutionScale/Plugin.cs index fc16e0c..ae034ac 100644 --- a/CameraResolutionScale/Plugin.cs +++ b/CameraResolutionScale/Plugin.cs @@ -5,7 +5,6 @@ using Comfort.Common; using EFT; using EFT.Settings.Graphics; using System.Collections; -using System.ComponentModel; using UnityEngine; /* Dependencies: @@ -23,30 +22,13 @@ using UnityEngine; */ namespace ScopeTweaks { - [BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.3")] + [BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.4")] [BepInDependency("FOVFix", BepInDependency.DependencyFlags.SoftDependency)] public class Plugin : BaseUnityPlugin { ConfigEntry scopeCameraResolutionScale; - //ConfigEntry scopeFixType; ConfigEntry enableDebug; - enum EFOVScalingMode - { - Disabled, - [Description("Magnified optics")] - ScopesOnly, - [Description("All sights")] - All, - } - - //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. - SharedGameSettingsClass settingsLibrary = Singleton.Instance; - - //The correct GClass can be found by searching for "SetFov" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc. - CameraClass setFovLibrary = CameraClass.Instance; void Awake() { @@ -54,6 +36,10 @@ namespace ScopeTweaks { Logger.LogWarning("Fontaine's FOV Fix detected! FOV Fix will NOT be available."); } + else + { + new CalculateScaleValueByFovPatch().Enable(); + } scopeCameraResolutionScale = Config.Bind( "General", @@ -61,12 +47,6 @@ namespace ScopeTweaks 80, new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange(10, 100))); - //scopeFixType = Config.Bind( - //"General", - //"High FOV sight tweak", - //EFOVScalingMode.ScopesOnly, - //new ConfigDescription("")); - enableDebug = Config.Bind("Debug", "Enable debug logging", false); } @@ -76,34 +56,6 @@ namespace ScopeTweaks if (Singleton.Instance == null) return; GameStatus currentGameState = Singleton.Instance.Status; - if (mainPlayer != null) - { - if (Input.GetKeyDown("[")) - { - StopAllCoroutines(); - CameraClass.Instance.SetFov(35, 1.0f, true); - } - - if (Input.GetKeyDown("]")) - { - StopAllCoroutines(); - CameraClass.Instance.SetFov(defaultInGameFOV, 1.0f, true); - } - } - - //if (mainPlayer != null && mainPlayer.ProceduralWeaponAnimation.IsAiming) - //{ - // if (Input.GetMouseButtonDown(0)) - // { - // inGameFOV = 50; - // } - - // if (Input.GetMouseButtonUp(0)) - // { - // inGameFOV = defaultInGameFOV; - // } - //} - //logic should only execute once per game instead of every frame if (!gameStateChanged(currentGameState)) return; @@ -119,21 +71,16 @@ namespace ScopeTweaks if (enableDebug.Value) Logger.LogInfo("Assigning cameras..."); StartCoroutine(tryGetScopeCamera()); - defaultInGameFOV = inGameFOV; break; } case GameStatus.SoftStopping: case GameStatus.Stopping: case GameStatus.Stopped: { - if (enableDebug.Value) Logger.LogInfo("Resetting..."); scopeCamera = null; mainPlayer = null; - if (enableDebug.Value) Logger.LogInfo($"Restoring FOV in settings: {defaultInGameFOV}"); - inGameFOV = defaultInGameFOV; - break; } default: break; @@ -163,24 +110,6 @@ namespace ScopeTweaks return localPlayer; } - /// - /// FIELD OF VIEW - /// - /// - private int defaultInGameFOV; - private int inGameFOV - { - get - { - int fov = Singleton.Instance.Game.Settings.FieldOfView.Value; - return fov; - } - set - { - Singleton.Instance.Game.Settings.FieldOfView.Value = value; - } - } - /// /// CAMERA SETUP /// @@ -239,87 +168,13 @@ namespace ScopeTweaks currentScalingFactor = getCurrentScalingFactor(); StartCoroutine(tryGetScopeCamera()); - //if (!mainPlayer.ProceduralWeaponAnimation.IsAiming) - //{ - // float aimSpeed = 0.7f * mainPlayer.ProceduralWeaponAnimation.AimingSpeed; - - // switch (scopeFixType.Value) - // { - // case EFOVScalingMode.Disabled: - // { - // break; - // } - // case EFOVScalingMode.ScopesOnly: - // { - // if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic) - // { - // inGameFOV = defaultInGameFOV; - // StopAllCoroutines(); - // setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, true); - // //mainPlayer.ProceduralWeaponAnimation.ApplyFovAdjustments(mainPlayer); - // } - - // break; - // } - // case EFOVScalingMode.All: - // { - // inGameFOV = defaultInGameFOV; - // StopAllCoroutines(); - // setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, true); - // //mainPlayer.ProceduralWeaponAnimation.ApplyFovAdjustments(mainPlayer); - - // break; - // } - // } - // return; - //} - if (mainPlayer.ProceduralWeaponAnimation.IsAiming) { - if(enableDebug.Value) Logger.LogInfo($"Scope: {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod.Item.LocalizedName()} isOptic: {mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic}"); - - if (enableDebug.Value) Logger.LogInfo("Updating scope resolution"); setScopeCameraResolutionScale(scopeCameraResolutionScale.Value); - - defaultInGameFOV = inGameFOV; - //switch (scopeFixType.Value) - //{ - // case EFOVScalingMode.Disabled: - // { - // break; - // } - // case EFOVScalingMode.ScopesOnly: - // { - // if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic) - // { - // forceADSFOV(); - // } - // break; - // } - // case EFOVScalingMode.All: - // { - // forceADSFOV(); - // break; - // } - //} } }; } - void forceADSFOV() - { - if (enableDebug.Value) Logger.LogInfo("Applying aiming tweaks"); - - float aimSpeed = mainPlayer.ProceduralWeaponAnimation.AimingSpeed * 0.7f; - - //Doesn't take effect if Fontaine's FOV Fix is loaded. - if (!Chainloader.PluginInfos.ContainsKey("FOVFix")) - { - setFovLibrary.SetFov(35, aimSpeed, false); - inGameFOV = 50; - } - } - float currentScalingFactor = 1.0f; float getCurrentScalingFactor() diff --git a/CameraResolutionScale/notGreg.ScopeTweaks.csproj b/CameraResolutionScale/notGreg.ScopeTweaks.csproj index dec7cb0..d983d66 100644 --- a/CameraResolutionScale/notGreg.ScopeTweaks.csproj +++ b/CameraResolutionScale/notGreg.ScopeTweaks.csproj @@ -31,6 +31,7 @@ 4 +