diff --git a/notGregs.UniformAim/Patch.cs b/notGregs.UniformAim/Patch.cs index bb7fc3d..a4e1002 100644 --- a/notGregs.UniformAim/Patch.cs +++ b/notGregs.UniformAim/Patch.cs @@ -15,7 +15,7 @@ namespace notGreg.UniformAim protected override MethodBase GetTargetMethod() { - return typeof(Player.FirearmController).GetMethod("get_AimingSensitivity"); + return typeof(Player.FirearmController).GetMethod("get_AimingSensitivity"); } [PatchPostfix] public static void PatchPostfix(ref float ____aimingSens) diff --git a/notGregs.UniformAim/Plugin.cs b/notGregs.UniformAim/Plugin.cs index 5aa3170..fd4bc01 100644 --- a/notGregs.UniformAim/Plugin.cs +++ b/notGregs.UniformAim/Plugin.cs @@ -1,4 +1,5 @@ using BepInEx; +using BepInEx.Bootstrap; using BepInEx.Configuration; using Comfort.Common; using EFT; @@ -10,23 +11,31 @@ using UnityEngine; namespace notGreg.UniformAim { [BepInPlugin("com.notGreg.UniformAim", "notGreg's Uniform Aim for Tarkov", "3.3.0")] + [BepInDependency("RealismMod", BepInDependency.DependencyFlags.SoftDependency)] public class Plugin : BaseUnityPlugin { ConfigEntry configExponent; ConfigEntry configSens; + public static bool isRealismModPresent = Chainloader.PluginInfos.ContainsKey("RealismMod"); + void Awake() { configExponent = Config.Bind("General", "Coefficient", 133, new ConfigDescription("", new AcceptableValueRange(10, 200))); configSens = Config.Bind("General", "Sensitivity", 1.0f, new ConfigDescription("", new AcceptableValueRange(0.01f, 2.0f))); - new get_AimingSensitivityPatch().Enable(); + + if (!isRealismModPresent) + { + new get_AimingSensitivityPatch().Enable(); + } } Player mainPlayer; int inGameFOV; float inGameAimedSens; - public static float aimingSens; + public static float aimingSens = 1.0f; + //public static float bridgeSens = 1.0f; //this function can be replaced by FixedUpdate() at 50Hz (adjustable via Time.fixedDeltaTime) //FixedUpdate() proved to be slightly more reliable in the past, however it had other unintended effects on the game. @@ -45,12 +54,18 @@ namespace notGreg.UniformAim //check if the game has started and if the player exists. If the player is aiming, update the scoped sensitivity (executed every frame while aiming) //Logger.LogInfo("Checking GameStatus and isAiming"); + //Logger.LogInfo($"GameStatus: {currentGameStatus}"); if (currentGameStatus == GameStatus.Started && mainPlayer != null) { //Logger.LogInfo($"isAiming? {mainPlayer.HandsController.IsAiming}"); if (mainPlayer.HandsController.IsAiming) { - aimingSens = calculateSensitivity(); + //if (isRealismModPresent) + //{ bridgeSens = calculateSensitivity(); } + //else + //{ + aimingSens = calculateSensitivity(); + //} } return; } @@ -81,6 +96,8 @@ namespace notGreg.UniformAim break; } } + + } //this function grabs the Field of View from the settings. This is the function that most often needs patching after update. @@ -88,7 +105,8 @@ namespace notGreg.UniformAim int getInGameFOV() { //int fov = Singleton.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.2.3 - int fov = Singleton.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.3.0 + //int fov = Singleton.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.3.0 + int fov = Singleton.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.4.1 //Logger.LogInfo($"In-game FOV: {fov}"); return fov; } @@ -98,13 +116,15 @@ namespace notGreg.UniformAim float getInGameAimSens() { //float sens = Singleton.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.2.* - float sens = Singleton.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.3.0 + //float sens = Singleton.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.3.0 + float sens = Singleton.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.4.1 //Logger.LogInfo($"In-game AimSens: {sens}"); return sens; } Player getLocalPlayer() { + //Logger.LogInfo("Setting local player..."); return Singleton.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer); } @@ -143,27 +163,31 @@ namespace notGreg.UniformAim yield break; } - //convert vertical FOV (degrees) to horizontal FOV (degrees) - float calculateHFOV(Camera camera) - { - return Camera.VerticalToHorizontalFieldOfView(camera.fieldOfView, camera.aspect); - } - //figure out whether the player is using a magnified optic or not. Return the FOV of the sight. Camera determineCurrentAimedFOV() { - var currentAimingMode = mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod; + //Logger.LogInfo("Get current aiming mod"); + + //Logger.LogInfo($"MainPlayer {mainPlayer.name}"); + //Logger.LogInfo($"ProcWeapAnim {mainPlayer.ProceduralWeaponAnimation}"); + //Logger.LogInfo($"CurrAimMod {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod}"); + if (mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod == null) + { + return mainCamera; + } + var currentAimingMod = mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod; + //get the name of the currently active scope - string scopeName = currentAimingMode.Item.Template.Name; - + //string scopeName = currentAimingMod.Item.Template.Name; + string scopeName = currentAimingMod.Item.Name; //Logger.LogInfo($"Scope name: {scopeName}"); //scopeMode determines the scope being used (e.g. main magnified optic at index 0, backup RDS at index 1) //scopeIndex determines the mode of the scope being used (e.g. x1 magnification at index 0, x4 magnification at index 1) //there are exceptions to this rule thanks to BSG's inconsistency, some of them are patched below - var scopeIndex = currentAimingMode.SelectedScopeIndex; - var scopeMode = currentAimingMode.SelectedScopeMode; + var scopeIndex = currentAimingMod.SelectedScopeIndex; + var scopeMode = currentAimingMod.SelectedScopeMode; //Logger.LogInfo("Index: " + scopeIndex + "\nMode: " + scopeMode); @@ -193,7 +217,7 @@ namespace notGreg.UniformAim { if (scopeIndex == 1) { - //Logger.Loginfo($"G36 Rail sight"); + //Logger.LogInfo($"G36 Rail sight"); return mainCamera; } else @@ -219,13 +243,14 @@ namespace notGreg.UniformAim float calculateSensitivity() { + //Logger.LogInfo("calculateSensitivity()"); //grab vertical hipfire field of view (FOV set by the user in the setting), then convert it to horizontal FOV //convert degrees to radians float hipFOV = Mathf.Deg2Rad * Camera.VerticalToHorizontalFieldOfView(inGameFOV, mainCamera.aspect); //grab current field of view while aiming, then convert it to horizontal FOV //convert degrees to radians - float aimedFOV = Mathf.Deg2Rad * calculateHFOV(determineCurrentAimedFOV()); + float aimedFOV = Mathf.Deg2Rad * Camera.VerticalToHorizontalFieldOfView(determineCurrentAimedFOV().fieldOfView, mainCamera.aspect); //exponent applied to the ratio of aimedFOV to hipFOV, causes sights to become relatively faster or slower as zoom increases float exponent = 100f / configExponent.Value; diff --git a/notGregs.UniformAim/notGreg.UniformAim.csproj b/notGregs.UniformAim/notGreg.UniformAim.csproj index 4453001..2e55154 100644 --- a/notGregs.UniformAim/notGreg.UniformAim.csproj +++ b/notGregs.UniformAim/notGreg.UniformAim.csproj @@ -38,27 +38,27 @@ False - E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll + E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll False - E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll + E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll False - E:\SPT-AKI\SPT-AKI 3.3.0\BepInEx\core\BepInEx.dll + E:\SPT-AKI\SPT-AKI 3.4.1\BepInEx\core\BepInEx.dll False - E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\Comfort.dll + E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\Comfort.dll False - E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\UnityEngine.dll + E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\UnityEngine.dll False - E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll + E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll