From eca93b02cd952d2c599a1efea36c1de646cced2a Mon Sep 17 00:00:00 2001 From: notGreg Date: Sat, 1 Apr 2023 16:44:32 +0200 Subject: [PATCH] Improved sight detection logic. --- TarkovUniformAim.sln | 6 +- TarkovUniformAim/Plugin.cs | 127 ++++----------------- TarkovUniformAim/notGreg.UniformAim.csproj | 17 ++- 3 files changed, 36 insertions(+), 114 deletions(-) diff --git a/TarkovUniformAim.sln b/TarkovUniformAim.sln index ba12581..8716c15 100644 --- a/TarkovUniformAim.sln +++ b/TarkovUniformAim.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32602.215 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TarkovUniformAim", "TarkovUniformAim\notGreg.UniformAim.csproj", "{B2F4587D-CFE6-42A6-8462-A884EB6E15CD}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "notGreg.UniformAim", "TarkovUniformAim\notGreg.UniformAim.csproj", "{B2F4587D-CFE6-42A6-8462-A884EB6E15CD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,8 +11,8 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B2F4587D-CFE6-42A6-8462-A884EB6E15CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2F4587D-CFE6-42A6-8462-A884EB6E15CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2F4587D-CFE6-42A6-8462-A884EB6E15CD}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {B2F4587D-CFE6-42A6-8462-A884EB6E15CD}.Debug|Any CPU.Build.0 = Release|Any CPU {B2F4587D-CFE6-42A6-8462-A884EB6E15CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {B2F4587D-CFE6-42A6-8462-A884EB6E15CD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection diff --git a/TarkovUniformAim/Plugin.cs b/TarkovUniformAim/Plugin.cs index a94e18f..3f31310 100644 --- a/TarkovUniformAim/Plugin.cs +++ b/TarkovUniformAim/Plugin.cs @@ -17,12 +17,13 @@ using UnityEngine; namespace notGreg.UniformAim { - [BepInPlugin("com.notGreg.UniformAim", "notGreg's Uniform Aim for Tarkov", "3.5.0")] + [BepInPlugin("com.notGreg.UniformAim", "notGreg's Uniform Aim for Tarkov", "3.5.3")] [BepInDependency("RealismMod", BepInDependency.DependencyFlags.SoftDependency)] public class Plugin : BaseUnityPlugin { ConfigEntry configExponent; ConfigEntry configSens; + ConfigEntry enableDebug; public static bool isRealismModPresent = Chainloader.PluginInfos.ContainsKey("RealismMod"); @@ -31,6 +32,8 @@ namespace notGreg.UniformAim configExponent = Config.Bind("General", "Coefficient", 133, new ConfigDescription("", new AcceptableValueRange(10, 500))); configSens = Config.Bind("General", "Sensitivity", 1.0f, new ConfigDescription("", new AcceptableValueRange(0.01f, 2.0f))); + enableDebug = Config.Bind("Debug", "Enable debug logging", false); + if (!isRealismModPresent) { @@ -38,7 +41,7 @@ namespace notGreg.UniformAim } else { - Logger.LogInfo("RealismMod detected! Abandoning aimingSens patch...\nMake sure to use the compatibility plugin!"); + if(enableDebug.Value) Logger.LogInfo("RealismMod detected! Abandoning aimingSens patch...\nMake sure to use the compatibility plugin!"); } } @@ -52,22 +55,17 @@ namespace notGreg.UniformAim void FixedUpdate() { //check if the world instance exists - //Logger.LogInfo("Checking world instance"); if (Singleton.Instance == null) { return; } //grab the game status of the existing instance - //Logger.LogInfo("Checking game status"); GameStatus currentGameStatus = Singleton.Instance.Status; //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(); @@ -75,16 +73,16 @@ namespace notGreg.UniformAim return; } - //Logger.LogInfo("Switch on GameStatus"); + if(enableDebug.Value) Logger.LogInfo("Switch on GameStatus"); switch (currentGameStatus) { case GameStatus.Started: { mainPlayer = getLocalPlayer(); - //Logger.LogInfo($"Subscribing to onAimingChanged event"); + if(enableDebug.Value) Logger.LogInfo($"Subscribing to onAimingChanged event"); subscribeOnAimingChanged(); - //Logger.LogInfo("TryGetCameras coroutines"); + if(enableDebug.Value) Logger.LogInfo("TryGetCameras coroutines"); StartCoroutine(tryGetMainCamera()); StartCoroutine(tryGetScopeCamera()); @@ -107,14 +105,8 @@ namespace notGreg.UniformAim //this function grabs the Field of View from the settings. This is the function that most often needs patching after update. //Appropriate class can usually be found by searching for the ClearSettings function. - - //SharedGameSettingsClass settingsLibrary = SharedGameSettingsClass.Instance; // Futureproofing for 3.5.1 and onwards 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.4.1 - //int fov = Singleton.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.5.0 int fov = Singleton.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.5.3 return fov; } @@ -123,20 +115,14 @@ namespace notGreg.UniformAim //Appropriate class can usually be found by searching for the ClearSettings function. 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.4.1 - //float sens = Singleton.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.5.0 float sens = Singleton.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.5.3 - - //float sens = settingsLibrary.Control.Settings.MouseAimingSensitivity; - //Logger.LogInfo($"In-game AimSens: {sens}"); + if(enableDebug.Value) Logger.LogInfo($"In-game AimSens: {sens}"); return sens; } Player getLocalPlayer() { - //Logger.LogInfo("Setting local player..."); + if(enableDebug.Value) Logger.LogInfo("Setting local player..."); return Singleton.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer); } @@ -151,11 +137,11 @@ namespace notGreg.UniformAim if (GameObject.Find(cameraName) != null) { mainCamera = GameObject.Find(cameraName).GetComponent(); - //Logger.LogInfo($"{mainCamera.name} found!"); + if (enableDebug.Value) Logger.LogInfo($"{mainCamera.name} found!"); } else { - //Logger.LogMessage($"Camera \"{cameraName}\" not found, rescheduling..."); + if (enableDebug.Value) Logger.LogMessage($"Camera \"{cameraName}\" not found, rescheduling..."); yield return myDelay; StartCoroutine(tryGetMainCamera()); yield break; @@ -163,106 +149,42 @@ namespace notGreg.UniformAim yield return null; } - //this coroutine attempts to find existing baseOpticCamera in the scene. The state of this camera is used to determine whether the player is using a magnified optic or not. + //this coroutine attempts to find existing baseOpticCamera in the scene. IEnumerator tryGetScopeCamera() { string cameraName = "BaseOpticCamera(Clone)"; if (GameObject.Find(cameraName) != null) { scopeCamera = GameObject.Find(cameraName).GetComponent(); - //Logger.LogInfo($"{scopeCamera.name} found!"); + if(enableDebug.Value) Logger.LogInfo($"{scopeCamera.name} found!"); } yield break; } - //figure out whether the player is using a magnified optic or not. Return the FOV of the sight. - Camera determineCurrentAimedFOV() + //figure out whether the player is using a magnified optic or not. Return the camera of the sight. + float determineCurrentAimedFOV() { - //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) + if(enableDebug.Value) { - return mainCamera; + Logger.LogInfo($"Current scope: {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod.Item.LocalizedName()} isOptic? {mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic}"); } - var currentAimingMod = mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod; - - - //get the name of the currently active scope - //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 = currentAimingMod.SelectedScopeIndex; - var scopeMode = currentAimingMod.SelectedScopeMode; - - //Logger.LogInfo("Index: " + scopeIndex + "\nMode: " + scopeMode); - - //patches for specific scopes, matches item name - switch (scopeName) + if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic) { - case "tactical_mp155_kalashnikov_ultima_camera": - { - //Logger.LogInfo("MP-155 Thermal"); - return mainCamera; - } - //SAM-SWAT's Leupold D-Evo optic patch. The modes on this scope are reversed. Causes detection based on baseOpticCamera to fail as the magnified optic camera is always active - case "scope_leupold_d_evo": - { - if (scopeMode == 0) - { - //Logger.LogInfo($"Leupold D-EVO BUIS FOV: {mainCamera.fieldOfView}"); - return mainCamera; - } - else - { - //Logger.LogInfo($"Leupold D-EVO Scope FOV: {scopeCamera.fieldOfView}"); - return scopeCamera; - } - } - case "scope_base_trijicon_acog_ta11_3,5x35": - { - if (scopeIndex == 1) - { - //Logger.LogInfo($"G36 Rail sight"); - return mainCamera; - } - else - { - return scopeCamera; - } - } - default: - { - if (scopeCamera == null || scopeCamera.isActiveAndEnabled == false) - { - //Logger.LogInfo($"Non-magnified: {scopeName} FOV: {mainCamera.fieldOfView}"); - return mainCamera; - } - else - { - //Logger.LogInfo($"Magnified: {scopeName} FOV: {scopeCamera.fieldOfView}"); - return scopeCamera; - } - } + return scopeCamera.fieldOfView; } + return mainCamera.fieldOfView; } float calculateSensitivity() { - //Logger.LogInfo("calculateSensitivity()"); + if(enableDebug.Value) 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 * Camera.VerticalToHorizontalFieldOfView(determineCurrentAimedFOV().fieldOfView, mainCamera.aspect); + float aimedFOV = Mathf.Deg2Rad * Camera.VerticalToHorizontalFieldOfView(determineCurrentAimedFOV(), 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; @@ -271,7 +193,7 @@ namespace notGreg.UniformAim float sensitivity = (float)Math.Pow(tanRatio, exponent) * inGameAimedSens; - //Logger.LogInfo($"Sensitivity: {sensitivity}"); + if(enableDebug.Value) Logger.LogInfo($"Sensitivity: {sensitivity}"); return sensitivity * configSens.Value; } @@ -285,6 +207,7 @@ namespace notGreg.UniformAim //onAimingChanged triggers whenever the player starts or stops aiming. mainPlayer.HandsController.OnAimingChanged += (aimArgs) => { + if (enableDebug.Value) Logger.LogInfo($"Scope: {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod.Item.LocalizedName()} isOptic? {mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic}"); inGameFOV = getInGameFOV(); inGameAimedSens = getInGameAimSens(); StartCoroutine(tryGetScopeCamera()); diff --git a/TarkovUniformAim/notGreg.UniformAim.csproj b/TarkovUniformAim/notGreg.UniformAim.csproj index acb8cf7..4e7f693 100644 --- a/TarkovUniformAim/notGreg.UniformAim.csproj +++ b/TarkovUniformAim/notGreg.UniformAim.csproj @@ -7,8 +7,8 @@ {B2F4587D-CFE6-42A6-8462-A884EB6E15CD} Library Properties - TarkovUniformAim - TarkovUniformAim + UniformAim + notGreg.UniformAim v4.8 512 true @@ -37,23 +37,22 @@ - 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 - 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 - E:\SPT-AKI\SPT-AKI 3.5.0\BepInEx\core\BepInEx.dll + E:\SPT-AKI\SPT-AKI 3.5.3\BepInEx\core\BepInEx.dll - 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 - - 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 - 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