Added an ability to switch between HFOV and VFOV during calculations. Set HFOV as the default.

This commit is contained in:
notGreg 2022-07-03 09:23:48 +02:00
parent 8f043dd9aa
commit 7072958905
3 changed files with 39 additions and 38 deletions

View File

@ -64,9 +64,6 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ClodanUtils\BaseRaidFinishedPatch.cs" />
<Compile Include="ClodanUtils\BaseRaidStartupPatch.cs" />
<Compile Include="ClodanUtils\ReflectionUtils.cs" />
<Compile Include="UniformAimPlugin.cs" /> <Compile Include="UniformAimPlugin.cs" />
<Compile Include="UniformAimPatch.cs" /> <Compile Include="UniformAimPatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -1,6 +1,6 @@
using System.Reflection; using Aki.Reflection.Patching;
using Aki.Reflection.Patching;
using EFT; using EFT;
using System.Reflection;
namespace UniformAim namespace UniformAim
{ {
@ -66,5 +66,4 @@ namespace UniformAim
Plugin.isAiming = ____isAiming; Plugin.isAiming = ____isAiming;
} }
} }
} }

View File

@ -1,6 +1,8 @@
using BepInEx; using BepInEx;
using BepInEx.Configuration; using BepInEx.Configuration;
using System; using System;
using EFT;
using EFT.UI;
using UnityEngine; using UnityEngine;
namespace UniformAim namespace UniformAim
@ -14,6 +16,7 @@ namespace UniformAim
public static ConfigEntry<int> configFOV; public static ConfigEntry<int> configFOV;
public static ConfigEntry<int> configCoeff; public static ConfigEntry<int> configCoeff;
public static ConfigEntry<int> configSens; public static ConfigEntry<int> configSens;
public static ConfigEntry<bool> configUseHFOV;
public static ConfigEntry<bool> configEnableLogging; public static ConfigEntry<bool> configEnableLogging;
//TODO: figure out a way to read game settings to default the configFOV.Value to whatever the player has already set //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 FPSCameraFOV;
float ScopeFOV; float ScopeFOV;
float currentFOV; float currentFOV;
//so we don't keep repeating ourselves //so we don't keep repeating ourselves
float cachedFOV; float cachedFOV;
string cachedDebugInfo; 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 //Return aspect ratio based on game window resolution, currently unused but could be useful in the future
float GetAspectRatio() float GetAspectRatio()
{ {
string screenWidth = Screen.width.ToString(); float resX = Convert.ToUInt16(Screen.width.ToString());
string screenHeight = Screen.height.ToString(); float resY = Convert.ToUInt16(Screen.height.ToString());
float resX = Convert.ToUInt16(screenWidth); //string screenWidth = Screen.width.ToString();
float resY = Convert.ToUInt16(screenHeight); //string screenHeight = Screen.height.ToString();
//float resX = Convert.ToUInt16(screenWidth);
//float resY = Convert.ToUInt16(screenHeight);
//Logger.LogInfo("GetAspectRatio(): resX: " + resX + " resY: " + resY); //Logger.LogInfo("GetAspectRatio(): resX: " + resX + " resY: " + resY);
return (resX / 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 //calculate horizontal FOV based on vertical FOV, currently unused but could be useful in the future
float CalculateHFOV(float FOV) float CalculateHFOV(float FOV)
{ {
float vFOVRad = FOV * Mathf.Deg2Rad; float vFOVRad = FOV / 2 * Mathf.Deg2Rad;
float hFOVRad = (float)(2 * Math.Atan(Math.Tan(FOV / 2) * Mathf.Deg2Rad) * GetAspectRatio()); 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 //calculate sensitivity based on FOV difference and coefficient
float CalculateSensitivity(float aimedFOV, float hipFOV) 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); hipFOV = Mathf.Clamp(hipFOV, 1f, 75f);
//halve the angle and convert to radians //check if configUseHFOV is enabled, convert to horizontal degrees if true
aimedFOV = (aimedFOV / 2f) * Mathf.Deg2Rad; if(configUseHFOV.Value)
hipFOV = (hipFOV / 2f) * Mathf.Deg2Rad; {
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); float exponent = (float)(100f / configCoeff.Value);
@ -87,22 +105,8 @@ namespace UniformAim
{ {
if (SelectedScope == 0 && isScopeCameraActive()) { currentFOV = ScopeFOV; } else {currentFOV = FPSCameraFOV; } if (SelectedScope == 0 && isScopeCameraActive()) { currentFOV = ScopeFOV; } else {currentFOV = FPSCameraFOV; }
//if (isScopeCameraActive()) //dirty fix for the Ultima MP-155 shotgun
//{ if(FPSCameraFOV > 35 && isScopeCameraActive() && ScopeFOV == 15) { currentFOV = FPSCameraFOV; }
// 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;
//}
} }
void LogDebugInfo() void LogDebugInfo()
@ -135,17 +139,18 @@ namespace UniformAim
//add sensitivity slider //add sensitivity slider
configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Sensitivity while aiming", new AcceptableValueRange<int>(1, 200))); configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Sensitivity while aiming", new AcceptableValueRange<int>(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 //enable logging
configEnableLogging = Config.Bind("Debug", "Enable logging", false, new ConfigDescription("Enables logging in BepInEx console, extremely spammy!")); configEnableLogging = Config.Bind("Debug", "Enable logging", false, new ConfigDescription("Enables logging in BepInEx console, extremely spammy!"));
} }
void FixedUpdate() void FixedUpdate()
{ {
//FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns. //FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns.
Time.fixedDeltaTime = (1f/50f); Time.fixedDeltaTime = (1f/50f);
if (isAiming) if (isAiming)
{ {
//Grab FOV values for calculation //Grab FOV values for calculation