2022-06-20 14:08:15 +02:00
|
|
|
|
using BepInEx;
|
|
|
|
|
using BepInEx.Configuration;
|
2022-06-20 15:43:15 +02:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
2022-06-20 14:08:15 +02:00
|
|
|
|
|
2022-06-20 15:43:15 +02:00
|
|
|
|
namespace UniformAim
|
2022-06-20 14:08:15 +02:00
|
|
|
|
{
|
2022-06-20 20:06:49 +02:00
|
|
|
|
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.0.0-rc")]
|
2022-06-20 14:08:15 +02:00
|
|
|
|
[BepInProcess("EscapeFromTarkov.exe")]
|
2022-06-20 15:43:15 +02:00
|
|
|
|
|
|
|
|
|
public class Plugin : BaseUnityPlugin
|
2022-06-20 14:08:15 +02:00
|
|
|
|
{
|
|
|
|
|
//Bepinex.Configurator fields
|
|
|
|
|
public static ConfigEntry<int> configFOV;
|
2022-06-20 20:06:49 +02:00
|
|
|
|
public static ConfigEntry<int> configCoeff;
|
2022-06-20 14:08:15 +02:00
|
|
|
|
public static ConfigEntry<int> configSens;
|
|
|
|
|
|
2022-06-20 15:43:15 +02:00
|
|
|
|
public static float mySens = 2f;
|
|
|
|
|
|
|
|
|
|
// last FOV values for FPS Camera (Main camera) and baseOpticCamera(Clone) (Picture in picture for scopes)
|
|
|
|
|
float lastFOV = -1f;
|
|
|
|
|
float lastFOV2 = -1f;
|
|
|
|
|
|
2022-06-20 20:06:49 +02:00
|
|
|
|
//human-friendly names for variables used later
|
2022-06-20 15:43:15 +02:00
|
|
|
|
float FPSCameraFOV = -1f;
|
|
|
|
|
float ScopeFOV = -1f;
|
|
|
|
|
float currentFOV = -1f;
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
//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, float mySens)
|
|
|
|
|
{ //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;
|
|
|
|
|
|
2022-06-20 20:06:49 +02:00
|
|
|
|
float exponent = (float)(100f / configCoeff.Value);
|
2022-06-20 15:43:15 +02:00
|
|
|
|
|
2022-06-20 20:06:49 +02:00
|
|
|
|
float tanRatio = (float)(Math.Tan(aimedFOV) / Math.Tan(hipFOV));
|
|
|
|
|
|
|
|
|
|
float sensitivity = (float)(configSens.Value/100f);
|
|
|
|
|
|
|
|
|
|
float result = (float)Math.Pow(tanRatio, exponent) * sensitivity;
|
|
|
|
|
|
|
|
|
|
return result;
|
2022-06-20 15:43:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 14:08:15 +02:00
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
//Enable uniform aim patch
|
|
|
|
|
new UpdateSensitivityPatch().Enable();
|
2022-06-20 20:06:49 +02:00
|
|
|
|
new get_AimingSensitivityPatch().Enable();
|
2022-06-20 14:08:15 +02:00
|
|
|
|
|
|
|
|
|
//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
|
2022-06-20 20:06:49 +02:00
|
|
|
|
configCoeff = Config.Bind("General", "Coefficient", 133, new ConfigDescription("Coefficient - increases sensitivity at higher zoom levels", new AcceptableValueRange<int>(1, 300)));
|
2022-06-20 14:08:15 +02:00
|
|
|
|
|
|
|
|
|
//add secondary sensitivity slider for greater control
|
2022-06-20 20:06:49 +02:00
|
|
|
|
configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Sensitivity while aiming", new AcceptableValueRange<int>(1, 200)));
|
2022-06-20 14:08:15 +02:00
|
|
|
|
|
|
|
|
|
}
|
2022-06-20 15:43:15 +02:00
|
|
|
|
|
|
|
|
|
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 < configFOV.Value) { currentFOV = FPSCameraFOV; }
|
|
|
|
|
if (Camera.allCamerasCount >= 2)
|
|
|
|
|
{
|
|
|
|
|
if (FPSCameraFOV == 35) { currentFOV = ScopeFOV; }
|
|
|
|
|
if (FPSCameraFOV == configFOV.Value - 15) { currentFOV = FPSCameraFOV; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mySens = CalculateSensitivity(currentFOV, configFOV.Value, configSens.Value);
|
|
|
|
|
}
|
2022-06-20 14:08:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|