From 7072958905b1e5841230a3879b174b59b6c95fe5 Mon Sep 17 00:00:00 2001 From: notGreg Date: Sun, 3 Jul 2022 09:23:48 +0200 Subject: [PATCH] Added an ability to switch between HFOV and VFOV during calculations. Set HFOV as the default. --- TarkovUniformAim/TarkovUniformAim.csproj | 3 -- TarkovUniformAim/UniformAimPatch.cs | 5 +- TarkovUniformAim/UniformAimPlugin.cs | 69 +++++++++++++----------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/TarkovUniformAim/TarkovUniformAim.csproj b/TarkovUniformAim/TarkovUniformAim.csproj index c918414..b1afccf 100644 --- a/TarkovUniformAim/TarkovUniformAim.csproj +++ b/TarkovUniformAim/TarkovUniformAim.csproj @@ -64,9 +64,6 @@ - - - diff --git a/TarkovUniformAim/UniformAimPatch.cs b/TarkovUniformAim/UniformAimPatch.cs index 2045053..e430820 100644 --- a/TarkovUniformAim/UniformAimPatch.cs +++ b/TarkovUniformAim/UniformAimPatch.cs @@ -1,6 +1,6 @@ -using System.Reflection; -using Aki.Reflection.Patching; +using Aki.Reflection.Patching; using EFT; +using System.Reflection; namespace UniformAim { @@ -66,5 +66,4 @@ namespace UniformAim Plugin.isAiming = ____isAiming; } } - } \ No newline at end of file diff --git a/TarkovUniformAim/UniformAimPlugin.cs b/TarkovUniformAim/UniformAimPlugin.cs index 4e20501..299bbdf 100644 --- a/TarkovUniformAim/UniformAimPlugin.cs +++ b/TarkovUniformAim/UniformAimPlugin.cs @@ -1,6 +1,8 @@ using BepInEx; using BepInEx.Configuration; using System; +using EFT; +using EFT.UI; using UnityEngine; namespace UniformAim @@ -14,6 +16,7 @@ namespace UniformAim public static ConfigEntry configFOV; public static ConfigEntry configCoeff; public static ConfigEntry configSens; + public static ConfigEntry configUseHFOV; public static ConfigEntry configEnableLogging; //TODO: figure out a way to read game settings to default the configFOV.Value to whatever the player has already set @@ -31,6 +34,7 @@ namespace UniformAim float FPSCameraFOV; float ScopeFOV; float currentFOV; + //so we don't keep repeating ourselves float cachedFOV; string cachedDebugInfo; @@ -38,10 +42,12 @@ namespace UniformAim //Return aspect ratio based on game window resolution, currently unused but could be useful in the future float GetAspectRatio() { - string screenWidth = Screen.width.ToString(); - string screenHeight = Screen.height.ToString(); - float resX = Convert.ToUInt16(screenWidth); - float resY = Convert.ToUInt16(screenHeight); + float resX = Convert.ToUInt16(Screen.width.ToString()); + float resY = Convert.ToUInt16(Screen.height.ToString()); + //string screenWidth = Screen.width.ToString(); + //string screenHeight = Screen.height.ToString(); + //float resX = Convert.ToUInt16(screenWidth); + //float resY = Convert.ToUInt16(screenHeight); //Logger.LogInfo("GetAspectRatio(): resX: " + resX + " resY: " + resY); return (resX / resY); @@ -49,20 +55,32 @@ namespace UniformAim //calculate horizontal FOV based on vertical FOV, currently unused but could be useful in the future float CalculateHFOV(float FOV) { - float vFOVRad = FOV * Mathf.Deg2Rad; - float hFOVRad = (float)(2 * Math.Atan(Math.Tan(FOV / 2) * Mathf.Deg2Rad) * GetAspectRatio()); + float vFOVRad = FOV / 2 * Mathf.Deg2Rad; + float hFOVRad = (float)(2 * Math.Atan(GetAspectRatio() * Math.Tan(vFOVRad))); - return (float)(Math.Round(hFOVRad * Mathf.Rad2Deg)); + if (configEnableLogging.Value) { Logger.LogInfo("Calculate HFOV: " + FOV + " Result: " + hFOVRad * Mathf.Rad2Deg); } + + return (float)(hFOVRad * Mathf.Rad2Deg); } //calculate sensitivity based on FOV difference and coefficient float CalculateSensitivity(float aimedFOV, float hipFOV) - { //clamp to avoid invalid values - aimedFOV = Mathf.Clamp(aimedFOV, 1f, 76f); + { + //clamp to avoid invalid values + aimedFOV = Mathf.Clamp(aimedFOV, 1f, 75f); hipFOV = Mathf.Clamp(hipFOV, 1f, 75f); - //halve the angle and convert to radians - aimedFOV = (aimedFOV / 2f) * Mathf.Deg2Rad; - hipFOV = (hipFOV / 2f) * Mathf.Deg2Rad; + //check if configUseHFOV is enabled, convert to horizontal degrees if true + if(configUseHFOV.Value) + { + Logger.LogInfo("HFOV Hip: " + CalculateHFOV(hipFOV) + " HFOV Aim: " + CalculateHFOV(aimedFOV)); + aimedFOV = CalculateHFOV(aimedFOV) / 2 * Mathf.Deg2Rad; + hipFOV = CalculateHFOV(hipFOV) / 2 * Mathf.Deg2Rad; + } + else + { + aimedFOV = aimedFOV / 2 * Mathf.Deg2Rad; + hipFOV = hipFOV / 2 * Mathf.Deg2Rad; + } float exponent = (float)(100f / configCoeff.Value); @@ -86,23 +104,9 @@ namespace UniformAim void DetermineCurrentFOV() { if (SelectedScope == 0 && isScopeCameraActive()) { currentFOV = ScopeFOV; } else {currentFOV = FPSCameraFOV; } - - //if (isScopeCameraActive()) - //{ - // if (SelectedScope == 0) - // { - // currentFOV = ScopeFOV; //Logger.LogInfo("Updating currentFOV to ScopeFOV"); - // } - // if (SelectedScope != 0) - // { - // currentFOV = FPSCameraFOV; //Logger.LogInfo("Updating currentFOV to FPSCameraFOV"); - // } - //} - //else - //{ - // //Logger.LogInfo("Updating currentFOV to FPSCameraFOV"); - // currentFOV = FPSCameraFOV; - //} + + //dirty fix for the Ultima MP-155 shotgun + if(FPSCameraFOV > 35 && isScopeCameraActive() && ScopeFOV == 15) { currentFOV = FPSCameraFOV; } } void LogDebugInfo() @@ -135,17 +139,18 @@ namespace UniformAim //add sensitivity slider configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Sensitivity while aiming", new AcceptableValueRange(1, 200))); + //use HFOV instead of VFOV for sensitivity calculations + configUseHFOV = Config.Bind("General", "Use Horizontal FOV?", true, new ConfigDescription("Toggles between using Horizontal FOV and Vertical FOV for sensitivity calculations.")); + //enable logging configEnableLogging = Config.Bind("Debug", "Enable logging", false, new ConfigDescription("Enables logging in BepInEx console, extremely spammy!")); } - void FixedUpdate() { //FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns. Time.fixedDeltaTime = (1f/50f); - if (isAiming) { //Grab FOV values for calculation @@ -163,7 +168,7 @@ namespace UniformAim } //draw debug info - if (configEnableLogging.Value) { LogDebugInfo(); } + if (configEnableLogging.Value) { LogDebugInfo(); } } } }