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>
</ItemGroup>
<ItemGroup>
<Compile Include="ClodanUtils\BaseRaidFinishedPatch.cs" />
<Compile Include="ClodanUtils\BaseRaidStartupPatch.cs" />
<Compile Include="ClodanUtils\ReflectionUtils.cs" />
<Compile Include="UniformAimPlugin.cs" />
<Compile Include="UniformAimPatch.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 System.Reflection;
namespace UniformAim
{
@ -66,5 +66,4 @@ namespace UniformAim
Plugin.isAiming = ____isAiming;
}
}
}

View File

@ -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<int> configFOV;
public static ConfigEntry<int> configCoeff;
public static ConfigEntry<int> configSens;
public static ConfigEntry<bool> configUseHFOV;
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
@ -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<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
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(); }
}
}
}