2022-06-20 14:08:15 +02:00
using BepInEx ;
using BepInEx.Configuration ;
2022-08-30 18:38:31 +02:00
using Comfort.Common ;
2022-06-20 15:43:15 +02:00
using UnityEngine ;
2022-08-28 08:19:09 +02:00
using System ;
2022-08-30 18:38:31 +02:00
using System.Collections ;
using System.Threading.Tasks ;
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-30 18:38:31 +02:00
[BepInPlugin("com.greg.tarkovuniformaim", "notGreg's Uniform Aim for Tarkov", "1.1.4")]
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-08-04 18:13:18 +02:00
int [ ] FOVRange = new int [ 2 ] { 50 , 75 } ;
2022-08-28 08:19:09 +02:00
ConfigEntry < bool > configFOVRangeOverride ;
2022-08-04 18:13:18 +02:00
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-28 08:19:09 +02:00
ConfigEntry < bool > configDebug ;
2022-06-20 14:08:15 +02:00
2022-08-04 18:13:18 +02:00
//only for persistence
2022-08-28 08:19:09 +02:00
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-28 08:19:09 +02:00
float baseCameraFOV = 75 ;
2022-08-04 18:13:18 +02:00
public static float currentFPSCameraFOV = 75 ;
public static float currentScopeCameraFOV = 75 ;
2022-08-05 21:58:10 +02:00
2022-08-28 08:19:09 +02:00
Core core = new Core ( ) ;
Utils utils = new Utils ( ) ;
2022-08-30 18:38:31 +02:00
Vector2 FOVInfo = new Vector2 ( 75 , 35 ) ;
Vector2 ScopeInfo = new Vector2 ( 0 , 0 ) ;
bool delayed = false ;
2022-06-26 18:16:31 +02:00
2022-06-20 14:08:15 +02:00
void Awake ( )
{
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-08-30 18:38:31 +02:00
enablePatches ( ) ;
2022-08-04 18:13:18 +02:00
}
2022-08-30 18:38:31 +02:00
bool doOnce = false ;
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-28 08:19:09 +02:00
if ( utils . SetRootObject ( ) ! = null )
2022-08-05 21:58:10 +02:00
{
2022-08-28 08:19:09 +02:00
var rootObject = utils . SetRootObject ( ) ;
2022-08-05 21:58:10 +02:00
//only update these values if the menu has been opened, otherwise read the config
if ( rootObject . transform . Find ( "Game Settings" ) . gameObject . activeInHierarchy )
{
2022-08-28 08:19:09 +02:00
if ( ! configFOVRangeOverride . Value ) { configFOV . Value = 50 + utils . GetInGameFOV ( rootObject ) ; }
inGameSens . Value = utils . GetInGameSens ( rootObject ) ;
2022-08-05 21:58:10 +02:00
}
}
//check if the player is in the Hideout or in a Raid
2022-08-28 08:19:09 +02:00
var isRunning = utils . checkIsReady ( ) ;
2022-08-30 18:38:31 +02:00
if ( ! isRunning ) {
doOnce = false ;
return ; }
//if (Camera.main == null) return;
2022-08-28 08:19:09 +02:00
2022-08-04 18:13:18 +02:00
if ( isRunning )
{
2022-08-30 18:38:31 +02:00
if ( ! doOnce )
{
SightPatches sightPatches = new SightPatches ( ) ;
StartCoroutine ( sightPatches . delayedLoad ( ) ) ;
doOnce = true ;
}
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 ) {
2022-08-28 08:19:09 +02:00
FOVInfo = new Vector2 ( currentFPSCameraFOV , currentScopeCameraFOV ) ;
ScopeInfo = new Vector2 ( SelectedScope , SelectedScopeMode ) ;
mySens = inGameSens . Value * core . CalculateSensitivity ( core . DetermineCurrentFOV ( FOVInfo . x , FOVInfo . y , ( int ) ScopeInfo . x , ( int ) ScopeInfo . y ) , configFOV . Value ) ;
2022-08-04 18:13:18 +02:00
}
2022-08-02 11:12:35 +02:00
}
2022-08-30 18:38:31 +02:00
//Print debug info in BepInEx console
if ( configDebug . Value & & delayed ) printDebug ( ) ;
2022-06-20 15:43:15 +02:00
}
}
2022-08-28 08:19:09 +02:00
string lastDebugLog ;
void printDebug ( )
{
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(FOVInfo.x, FOVInfo.y, (int)ScopeInfo.x, (int)ScopeInfo.y)}V / {core.CalculateHFOV(core.DetermineCurrentFOV(FOVInfo.x, FOVInfo.y, (int)ScopeInfo.x, (int)ScopeInfo.y))}H" +
$"\nisAiming? {isAiming} | SelectedScope: {SelectedScope} | SelectedScopeMode:{SelectedScopeMode}" +
$"\nCalculated sensitivity: {core.CalculateSensitivity(core.DetermineCurrentFOV(FOVInfo.x, FOVInfo.y, (int)ScopeInfo.x, (int)ScopeInfo.y), baseCameraFOV)}" +
$"\nAspect Ratio: {Camera.main.aspect}" +
$"\nFinal Sensitivity: {mySens}" ;
if ( lastDebugLog ! = debugLog ) { Logger . LogInfo ( debugLog ) ; lastDebugLog = debugLog ; }
}
2022-08-30 18:38:31 +02:00
void enablePatches ( )
{
Logger . LogInfo ( "Enabling patches!" ) ;
new UpdateSensitivityPatch ( ) . Enable ( ) ;
new get_AimingSensitivityPatch ( ) . Enable ( ) ;
new get_SelectedScopeIndexPatch ( ) . Enable ( ) ;
new get_SelectedScopeModePatch ( ) . Enable ( ) ;
new get_IsAimingPatch ( ) . Enable ( ) ;
delayed = true ;
}
2022-06-20 14:08:15 +02:00
}
}
2022-06-22 14:56:37 +02:00