2022-06-20 14:08:15 +02:00
using BepInEx ;
using BepInEx.Configuration ;
2022-06-20 15:43:15 +02:00
using UniformAim ;
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
{
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "0.1.1")]
[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 ;
public static ConfigEntry < float > configCoeff ;
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 ;
//human-friendly names
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 ) ;
}
//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 , 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 ;
//ratio of tangents as sensitivity
float sensitivity = ( float ) ( ( Math . Tan ( aimedFOV ) / Math . Tan ( hipFOV ) ) * ( mySens / 100 ) ) ;
return sensitivity ;
}
2022-06-20 14:08:15 +02:00
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 ) ) ) ;
}
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
}
}