2022-06-20 14:08:15 +02:00
using BepInEx ;
using BepInEx.Configuration ;
2022-06-20 15:43:15 +02:00
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-08-09 20:27:16 +02:00
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.1.2")]
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
{
2022-08-09 20:27:16 +02:00
2022-06-20 14:08:15 +02:00
//Bepinex.Configurator fields
public static ConfigEntry < int > configFOV ;
2022-08-04 18:13:18 +02:00
int [ ] FOVRange = new int [ 2 ] { 50 , 75 } ;
public static ConfigEntry < bool > configFOVRangeOverride ;
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-08-04 18:13:18 +02:00
public static ConfigEntry < bool > configDebug ;
2022-06-20 14:08:15 +02:00
2022-08-04 18:13:18 +02:00
//only for persistence
public static ConfigEntry < float > inGameSens ;
2022-06-20 15:43:15 +02:00
2022-06-22 14:56:37 +02:00
public static float mySens = 1f ;
2022-08-04 18:13:18 +02:00
//public static float aimingSens;
2022-06-22 14:56:37 +02:00
//sight data for hacky workarounds
public static int SelectedScope = 0 ;
public static int SelectedScopeMode = 0 ;
public static bool isAiming = false ;
2022-06-20 15:43:15 +02:00
2022-06-20 20:06:49 +02:00
//human-friendly names for variables used later
2022-08-04 18:13:18 +02:00
public static float baseCameraFOV = 75 ;
public static float currentFPSCameraFOV = 75 ;
public static float currentScopeCameraFOV = 75 ;
2022-08-05 21:58:10 +02:00
string lastDebugLog ;
2022-08-04 18:13:18 +02:00
void printDebug ( )
2022-06-22 14:56:37 +02:00
{
2022-08-05 21:58:10 +02:00
string debugLog = $"\nIn-Game FOV: {configFOV.Value} | In-Game Sens: {inGameSens.Value} | FOV Override: {configFOVRangeOverride.Value}" +
$"\nFPS Camera FOV: {currentFPSCameraFOV}V / {Core.CalculateHFOV(currentFPSCameraFOV)}H | BaseOpticCamera FOV: {currentScopeCameraFOV}V / {Core.CalculateHFOV(currentScopeCameraFOV)}H | CurrentFOV: {Core.DetermineCurrentFOV()}V / {Core.CalculateHFOV(Core.DetermineCurrentFOV())}H" +
$"\nisAiming? {isAiming} | SelectedScope: {SelectedScope} | SelectedScopeMode:{SelectedScopeMode}" +
$"\nCalculated sensitivity: {Core.CalculateSensitivity(Core.DetermineCurrentFOV(), baseCameraFOV)}" +
2022-08-09 20:27:16 +02:00
$"\nAspect Ratio: {Camera.main.aspect}" +
2022-08-05 21:58:10 +02:00
$"\nFinal Sensitivity: {mySens * inGameSens.Value}" ;
if ( lastDebugLog ! = debugLog ) { Logger . LogInfo ( debugLog ) ; lastDebugLog = debugLog ; }
2022-06-22 18:35:54 +02:00
}
2022-06-26 18:16:31 +02:00
2022-06-20 14:08:15 +02:00
void Awake ( )
{
new UpdateSensitivityPatch ( ) . Enable ( ) ;
2022-06-20 20:06:49 +02:00
new get_AimingSensitivityPatch ( ) . Enable ( ) ;
2022-06-22 14:56:37 +02:00
new get_SelectedScopeIndexPatch ( ) . Enable ( ) ;
new get_SelectedScopeModePatch ( ) . Enable ( ) ;
new get_IsAimingPatch ( ) . Enable ( ) ;
2022-06-26 18:16:31 +02:00
2022-08-04 18:13:18 +02:00
//override FOV range
configFOVRangeOverride = Config . Bind ( "General" , "FOV Override" , false , new ConfigDescription ( "Override FOV range for compatibility with other mods. Requires restart." ) ) ;
if ( configFOVRangeOverride . Value )
{
FOVRange [ 0 ] = 1 ; FOVRange [ 1 ] = 178 ;
}
2022-06-20 14:08:15 +02:00
//add configuration slider for field of view
2022-08-04 18:13:18 +02:00
configFOV = Config . Bind ( "General" , "FOV" , 75 , new ConfigDescription ( "In-game Field of View value" , new AcceptableValueRange < int > ( FOVRange [ 0 ] , FOVRange [ 1 ] ) ) ) ;
2022-06-20 14:08:15 +02:00
//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
2022-06-22 14:56:37 +02:00
//add sensitivity slider
2022-08-04 18:13:18 +02:00
configSens = Config . Bind ( "General" , "Sensitivity" , 100 , new ConfigDescription ( "Fine control over sensitivity while aiming" , new AcceptableValueRange < int > ( 1 , 200 ) ) ) ;
2022-06-20 14:08:15 +02:00
2022-08-04 18:13:18 +02:00
//enable debug logging
configDebug = Config . Bind ( "Debug" , "Enable logging?" , false , new ConfigDescription ( "Enables logging in BepInEx console" ) ) ;
//settings for persistence, these values get updated when the in-game menu is opened
inGameSens = Config . Bind ( "¡Do not touch unless necessary!" , "In-game Aiming Sensitivity value" , 0.5f , new ConfigDescription ( "Should update on its own - kept for persistence between sessions." , new AcceptableValueRange < float > ( 0.1f , 5.0f ) ) ) ;
2022-06-20 15:43:15 +02:00
2022-08-04 18:13:18 +02:00
}
2022-06-22 22:19:14 +02:00
void FixedUpdate ( )
2022-06-20 15:43:15 +02:00
{
2022-08-04 18:13:18 +02:00
//FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns
2022-08-02 11:12:35 +02:00
Time . fixedDeltaTime = ( 1f / 50f ) ;
2022-06-26 18:16:31 +02:00
2022-08-05 21:58:10 +02:00
if ( Utils . SetRootObject ( ) ! = null )
{
var rootObject = Utils . SetRootObject ( ) ;
//only update these values if the menu has been opened, otherwise read the config
if ( rootObject . transform . Find ( "Game Settings" ) . gameObject . activeInHierarchy )
{
if ( ! configFOVRangeOverride . Value ) { configFOV . Value = 50 + Utils . GetInGameFOV ( rootObject ) ; }
inGameSens . Value = Utils . GetInGameSens ( rootObject ) ;
}
}
//Print debug info in BepInEx console
if ( configDebug . Value ) printDebug ( ) ;
//check if the player is in the Hideout or in a Raid
2022-08-04 18:13:18 +02:00
var isRunning = Utils . checkIsReady ( ) ;
if ( ! isRunning ) return ;
2022-06-22 18:35:54 +02:00
2022-08-04 18:13:18 +02:00
if ( isRunning )
{
2022-08-05 21:58:10 +02:00
//check if the player is aiming
2022-08-04 18:13:18 +02:00
if ( isAiming )
2022-08-02 11:12:35 +02:00
{
2022-08-04 18:13:18 +02:00
//Grab FOV values for calculation
currentFPSCameraFOV = Camera . allCameras [ 0 ] . fieldOfView ; //Camera[0] tends to be FPS Camera
if ( Camera . allCamerasCount > 1 ) { currentScopeCameraFOV = Camera . allCameras [ 1 ] . fieldOfView ; } //Camera[1] tends to be BaseOpticCamera
//Figure out if the FPSCamera is zoomed in, prevents the script from ticking while the player is healing
if ( currentFPSCameraFOV < configFOV . Value ) {
mySens = inGameSens . Value * Core . CalculateSensitivity ( Core . DetermineCurrentFOV ( ) , configFOV . Value ) ;
}
2022-08-02 11:12:35 +02:00
}
2022-06-20 15:43:15 +02:00
}
}
2022-06-20 14:08:15 +02:00
}
}
2022-06-22 14:56:37 +02:00