Moved logic to MonoBehaviour instead of BaseUnityPlugin
This commit is contained in:
parent
a43b0237c8
commit
86d26039cd
@ -56,8 +56,9 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="UniformAimPlugin.cs" />
|
||||
<Compile Include="UniformAimPatch.cs" />
|
||||
<Compile Include="UniformAimUtils.cs" />
|
||||
<Compile Include="UniformAim.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
101
TarkovUniformAim/UniformAim.cs
Normal file
101
TarkovUniformAim/UniformAim.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UniformAimPatch;
|
||||
using BepInEx;
|
||||
using UniformAimPlugin;
|
||||
|
||||
|
||||
namespace UniformAimLogic
|
||||
{
|
||||
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "0.1.1")]
|
||||
[BepInProcess("EscapeFromTarkov.exe")]
|
||||
public class Logic : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
new UpdateSensitivityPatch().Enable();
|
||||
}
|
||||
|
||||
//Return aspect ratio based on game window resolution
|
||||
float GetAspectRatio()
|
||||
{
|
||||
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);
|
||||
}
|
||||
//convert degrees to radians
|
||||
//calculate horizontal FOV based on vertical FOV
|
||||
float CalculateHFOV(float FOV)
|
||||
{
|
||||
float vFOVRad = FOV * Mathf.Deg2Rad;
|
||||
float hFOVRad = (float)(2 * Math.Atan(Math.Tan(FOV / 2) * Mathf.Deg2Rad) * GetAspectRatio());
|
||||
|
||||
return (float)(Math.Round(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, 0.1f, 90f);
|
||||
hipFOV = Mathf.Clamp(hipFOV, 0.1f, 90f);
|
||||
|
||||
//halve and convert to radians
|
||||
aimedFOV = aimedFOV / 2 * Mathf.Deg2Rad;
|
||||
hipFOV = hipFOV /2 * Mathf.Deg2Rad;
|
||||
|
||||
//ratio of tangents as sensitivity
|
||||
float sensitivity = (float)(Math.Tan(aimedFOV) / Math.Tan(hipFOV));
|
||||
|
||||
return sensitivity;
|
||||
}
|
||||
|
||||
|
||||
public static float adjustedSensitivity = (float)(Config.configSens.Value) / 100;
|
||||
|
||||
float lastFOV = -1f;
|
||||
float lastFOV2 = -1f;
|
||||
|
||||
float FPSCameraFOV = -1f;
|
||||
float ScopeFOV = -1f;
|
||||
float currentFOV = -1f;
|
||||
|
||||
float configFOV = (float)Config.configFOV.Value;
|
||||
float configSens = (float)Config.configSens.Value;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Camera.allCamerasCount >= 1)
|
||||
{
|
||||
FPSCameraFOV = Camera.allCameras[0].fieldOfView;
|
||||
}
|
||||
if (Camera.allCamerasCount >= 2)
|
||||
{
|
||||
ScopeFOV = Camera.allCameras[1].fieldOfView;
|
||||
}
|
||||
if (Camera.allCamerasCount >= 1 && FPSCameraFOV != lastFOV)
|
||||
{
|
||||
//Logger.LogInfo("[0] FOV: " + FPSCameraFOV);
|
||||
lastFOV = FPSCameraFOV;
|
||||
}
|
||||
if (Camera.allCamerasCount >= 2 && ScopeFOV != lastFOV2)
|
||||
{
|
||||
//Logger.LogInfo("[1] FOV: " + ScopeFOV);
|
||||
lastFOV2 = ScopeFOV;
|
||||
}
|
||||
|
||||
//nasty workaround for sensitivity while using PIP scopes, WILL break when FOV is set to 50
|
||||
if (35 < FPSCameraFOV && FPSCameraFOV < Config.configFOV.Value) { currentFOV = FPSCameraFOV; }
|
||||
if (Camera.allCamerasCount >= 2)
|
||||
{
|
||||
if (FPSCameraFOV == 35) { currentFOV = ScopeFOV; }
|
||||
if (FPSCameraFOV == Config.configFOV.Value - 15) { currentFOV = FPSCameraFOV; }
|
||||
}
|
||||
|
||||
adjustedSensitivity = configSens * CalculateSensitivity(currentFOV, configFOV);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
using System.Reflection;
|
||||
using Aki.Reflection.Patching;
|
||||
using EFT;
|
||||
using UniformAim;
|
||||
using UniformAimLogic;
|
||||
using UniformAimPlugin;
|
||||
|
||||
namespace TarkovUniformAim
|
||||
namespace UniformAimPatch
|
||||
{
|
||||
public class UpdateSensitivityPatch : ModulePatch
|
||||
{
|
||||
@ -15,7 +16,7 @@ namespace TarkovUniformAim
|
||||
[PatchPostfix]
|
||||
public static void PatchPostfix(ref float ____aimingSens)
|
||||
{
|
||||
____aimingSens = UniformAimUtils.adjustedSensitivity;
|
||||
____aimingSens = Logic.adjustedSensitivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
TarkovUniformAim/UniformAimPlugin.cs
Normal file
34
TarkovUniformAim/UniformAimPlugin.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using UniformAimPatch;
|
||||
using UniformAimLogic;
|
||||
|
||||
|
||||
namespace UniformAimPlugin
|
||||
{
|
||||
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "0.1.1")]
|
||||
[BepInProcess("EscapeFromTarkov.exe")]
|
||||
public class Config : BaseUnityPlugin
|
||||
{
|
||||
//Bepinex.Configurator fields
|
||||
public static ConfigEntry<int> configFOV;
|
||||
public static ConfigEntry<float> configCoeff;
|
||||
public static ConfigEntry<int> configSens;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//Enable uniform aim patch
|
||||
new UpdateSensitivityPatch().Enable();
|
||||
|
||||
//add configuration slider for field of view
|
||||
configFOV = Config.Bind("General", "FOV", 75, new ConfigDescription("In-game Field of View value", new AcceptableValueRange<int>(50, 75)));
|
||||
|
||||
//add coefficient slider
|
||||
configCoeff = Config.Bind("General", "Coefficient", 1.33f, new ConfigDescription("Coefficient - increases sensitivity at higher zoom levels, default 4/3", new AcceptableValueRange<float>(0.001f, 5.0f)));
|
||||
|
||||
//add secondary sensitivity slider for greater control
|
||||
configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Secondary sensitivity multiplier in case Tarkov's default isn't enough", new AcceptableValueRange<int>(1, 200)));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using TarkovUniformAim;
|
||||
|
||||
namespace UniformAim
|
||||
{
|
||||
|
||||
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "0.1.1")]
|
||||
[BepInProcess("EscapeFromTarkov.exe")]
|
||||
|
||||
public class UniformAimConfig : BaseUnityPlugin
|
||||
{
|
||||
//Bepinex.Configurator fields
|
||||
public static ConfigEntry<int> configFOV;
|
||||
public static ConfigEntry<float> configCoeff;
|
||||
public static ConfigEntry<int> configSens;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
//Enable uniform aim patch
|
||||
new UpdateSensitivityPatch().Enable();
|
||||
|
||||
//add configuration slider for field of view
|
||||
configFOV = Config.Bind("General", "FOV", 75, new ConfigDescription("In-game Field of View value", new AcceptableValueRange<int>(50, 75)));
|
||||
|
||||
//add coefficient slider
|
||||
configCoeff = Config.Bind("General", "Coefficient", 1.33f, new ConfigDescription("Coefficient - increases sensitivity at higher zoom levels, default 4/3", new AcceptableValueRange<float>(0.001f, 5.0f)));
|
||||
|
||||
//add secondary sensitivity slider for greater control
|
||||
configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Secondary sensitivity multiplier in case Tarkov's default isn't enough", new AcceptableValueRange<int>(1, 200)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class UniformAimUtils : MonoBehaviour
|
||||
{
|
||||
//Return aspect ratio based on game window resolution
|
||||
float GetAspectRatio()
|
||||
{
|
||||
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);
|
||||
}
|
||||
//convert degrees to radians
|
||||
float Deg2Rad(float angle)
|
||||
{
|
||||
return (float)(angle * Math.PI / 180);
|
||||
}
|
||||
//convert radians to degrees
|
||||
float Rad2Deg(float radian)
|
||||
{
|
||||
return (float)(radian * 180 / Math.PI);
|
||||
}
|
||||
//calculate horizontal FOV based on vertical FOV
|
||||
float CalculateHFOV(float FOV)
|
||||
{
|
||||
float vFOVRad = Deg2Rad(FOV);
|
||||
float hFOVRad = (float)(2 * Math.Atan(Math.Tan(Deg2Rad(FOV) / 2) * GetAspectRatio()));
|
||||
|
||||
return (float)(Math.Round(Rad2Deg(hFOVRad)));
|
||||
}
|
||||
//calculate sensitivity based on FOV difference and coefficient
|
||||
float CalculateSensitivity(float aimedFOV, float hipFOV)
|
||||
{ //clamp to avoid invalid values
|
||||
aimedFOV = Mathf.Clamp(aimedFOV, 0.001f, 90f);
|
||||
hipFOV = Mathf.Clamp(hipFOV, 0.001f, 90f);
|
||||
|
||||
//halve and convert to radians
|
||||
aimedFOV = Deg2Rad(aimedFOV / 2);
|
||||
hipFOV = Deg2Rad(hipFOV / 2);
|
||||
|
||||
//ratio of tangents as sensitivity
|
||||
float sensitivity = (float)(Math.Tan(aimedFOV) / Math.Tan(hipFOV));
|
||||
|
||||
return sensitivity;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static float adjustedSensitivity = -1f;
|
||||
|
||||
float lastFOV = -1f;
|
||||
float lastFOV2 = -1f;
|
||||
|
||||
float FPSCameraFOV = -1f;
|
||||
float ScopeFOV = -1f;
|
||||
float currentFOV = -1f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Camera.allCamerasCount >= 1)
|
||||
{
|
||||
FPSCameraFOV = Camera.allCameras[0].fieldOfView;
|
||||
}
|
||||
if (Camera.allCamerasCount >= 2)
|
||||
{
|
||||
ScopeFOV = Camera.allCameras[1].fieldOfView;
|
||||
}
|
||||
if (Camera.allCamerasCount >= 1 && FPSCameraFOV != lastFOV)
|
||||
{
|
||||
//Logger.LogInfo("[0] FOV: " + FPSCameraFOV);
|
||||
lastFOV = FPSCameraFOV;
|
||||
}
|
||||
if (Camera.allCamerasCount >= 2 && ScopeFOV != lastFOV2)
|
||||
{
|
||||
//Logger.LogInfo("[1] FOV: " + ScopeFOV);
|
||||
lastFOV2 = ScopeFOV;
|
||||
}
|
||||
|
||||
//nasty workaround for sensitivity while using PIP scopes, WILL break when FOV is set to 50
|
||||
if (35 < FPSCameraFOV && FPSCameraFOV < UniformAimConfig.configFOV.Value) { currentFOV = FPSCameraFOV; }
|
||||
if (Camera.allCamerasCount >= 2)
|
||||
{
|
||||
if (FPSCameraFOV == 35) { currentFOV = ScopeFOV; }
|
||||
if (FPSCameraFOV == UniformAimConfig.configFOV.Value - 15) { currentFOV = FPSCameraFOV; }
|
||||
}
|
||||
|
||||
adjustedSensitivity = CalculateSensitivity(currentFOV, UniformAimConfig.configFOV.Value) * 0.25f; //(float)(UniformAimConfig.configSens.Value/100)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user