From f477cd17d050a55c114f933313ca8692ec66412e Mon Sep 17 00:00:00 2001 From: notGreg Date: Fri, 5 Aug 2022 21:58:10 +0200 Subject: [PATCH] Aiming Sensitivity and Field of View values should now update correctly if the player hasn't spawned. Debug log should be less spammy now. --- TarkovUniformAim/UniformAimCore.cs | 10 +++---- TarkovUniformAim/UniformAimPlugin.cs | 45 +++++++++++++++------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/TarkovUniformAim/UniformAimCore.cs b/TarkovUniformAim/UniformAimCore.cs index 2690854..4f2ee0a 100644 --- a/TarkovUniformAim/UniformAimCore.cs +++ b/TarkovUniformAim/UniformAimCore.cs @@ -1,5 +1,4 @@ -using BepInEx; -using System; +using System; using UnityEngine; namespace UniformAim @@ -18,15 +17,16 @@ namespace UniformAim float vFOVRad = FOV / 2 * Mathf.Deg2Rad; float hFOVRad = (float)(2 * Math.Atan(GetAspectRatio() * Math.Tan(vFOVRad))); - return (float)(hFOVRad * Mathf.Rad2Deg); + //RETURNS RADIANS + return hFOVRad; } //calculate sensitivity based on FOV delta and coefficient public static float CalculateSensitivity(float aimedFOV, float hipFOV) { //calculate horizontal FOV values for inputs - aimedFOV = CalculateHFOV(aimedFOV) * Mathf.Deg2Rad; - hipFOV = CalculateHFOV(hipFOV) * Mathf.Deg2Rad; + aimedFOV = CalculateHFOV(aimedFOV); + hipFOV = CalculateHFOV(hipFOV); float exponent = (float)(100f / Plugin.configCoeff.Value); diff --git a/TarkovUniformAim/UniformAimPlugin.cs b/TarkovUniformAim/UniformAimPlugin.cs index 696ed3d..e897242 100644 --- a/TarkovUniformAim/UniformAimPlugin.cs +++ b/TarkovUniformAim/UniformAimPlugin.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace UniformAim { - [BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.1.0")] + [BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.1.1")] [BepInProcess("EscapeFromTarkov.exe")] public class Plugin : BaseUnityPlugin @@ -35,15 +35,17 @@ namespace UniformAim public static float baseCameraFOV = 75; public static float currentFPSCameraFOV = 75; public static float currentScopeCameraFOV = 75; - + + string lastDebugLog; void printDebug() { - Logger.LogInfo($"\nIn-Game FOV: {configFOV.Value} In-Game Sens: {inGameSens.Value} FOV Override: {configFOVRangeOverride.Value}" + - $"\nFPS Camera FOV: {currentFPSCameraFOV} / {Core.CalculateHFOV(currentFPSCameraFOV)} BaseOpticCamera FOV: {currentScopeCameraFOV} / {Core.CalculateHFOV(currentScopeCameraFOV)} CurrentFOV: {Core.DetermineCurrentFOV()} / {Core.CalculateHFOV(Core.DetermineCurrentFOV())}" + - $"\nisAiming? {isAiming} SelectedScope: {SelectedScope} SelectedScopeMode:{SelectedScopeMode}" + - $"\nCalculated sensitivity: {Core.CalculateSensitivity(Core.DetermineCurrentFOV(), baseCameraFOV)}" + + string debugLog = $"\nIn-Game FOV: {configFOV.Value} | In-Game Sens: {inGameSens.Value} | FOV Override: {configFOVRangeOverride.Value}" + + $"\nFPS Camera FOV: {currentFPSCameraFOV}V / {Core.CalculateHFOV(currentFPSCameraFOV)}H | BaseOpticCamera FOV: {currentScopeCameraFOV}V / {Core.CalculateHFOV(currentScopeCameraFOV)}H | CurrentFOV: {Core.DetermineCurrentFOV()}V / {Core.CalculateHFOV(Core.DetermineCurrentFOV())}H" + + $"\nisAiming? {isAiming} | SelectedScope: {SelectedScope} | SelectedScopeMode:{SelectedScopeMode}" + + $"\nCalculated sensitivity: {Core.CalculateSensitivity(Core.DetermineCurrentFOV(), baseCameraFOV)}" + $"\nAspect Ratio: {Core.GetAspectRatio()}" + - $"\nFinal Sensitivity: {mySens * inGameSens.Value}"); + $"\nFinal Sensitivity: {mySens * inGameSens.Value}"; + if (lastDebugLog != debugLog) { Logger.LogInfo(debugLog); lastDebugLog = debugLog; } } void Awake() @@ -82,22 +84,27 @@ namespace UniformAim //FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns Time.fixedDeltaTime = (1f / 50f); - //check if the game is running + if (Utils.SetRootObject() != null) + { + var rootObject = Utils.SetRootObject(); + //only update these values if the menu has been opened, otherwise read the config + if (rootObject.transform.Find("Game Settings").gameObject.activeInHierarchy) + { + if (!configFOVRangeOverride.Value) { configFOV.Value = 50 + Utils.GetInGameFOV(rootObject); } + inGameSens.Value = Utils.GetInGameSens(rootObject); + } + } + + //Print debug info in BepInEx console + if (configDebug.Value) printDebug(); + + //check if the player is in the Hideout or in a Raid var isRunning = Utils.checkIsReady(); if (!isRunning) return; if (isRunning) { - if (Utils.SetRootObject() != null) { - var rootObject = Utils.SetRootObject(); - //only update these values if the menu has been opened, otherwise read the config - if (rootObject.transform.Find("Game Settings").gameObject.activeInHierarchy) - { - if (!configFOVRangeOverride.Value) { configFOV.Value = 50 + Utils.GetInGameFOV(rootObject); } - inGameSens.Value = Utils.GetInGameSens(rootObject); - } - } - //cgheck if the player is aiming + //check if the player is aiming if (isAiming) { //Grab FOV values for calculation @@ -110,8 +117,6 @@ namespace UniformAim } } } - //Print debug info in BepInEx console - if (configDebug.Value) printDebug(); } } }