Removed HFOV toggle - it's the default way now. Added FOV Range Override for compatibility with FOV-extension mods. Some values should now be grabbed from the game.
119 lines
5.7 KiB
C#
119 lines
5.7 KiB
C#
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace UniformAim
|
|
{
|
|
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.1.0")]
|
|
[BepInProcess("EscapeFromTarkov.exe")]
|
|
|
|
public class Plugin : BaseUnityPlugin
|
|
{
|
|
//Bepinex.Configurator fields
|
|
public static ConfigEntry<int> configFOV;
|
|
int[] FOVRange = new int[2] { 50, 75 };
|
|
public static ConfigEntry<bool> configFOVRangeOverride;
|
|
|
|
public static ConfigEntry<int> configCoeff;
|
|
public static ConfigEntry<int> configSens;
|
|
public static ConfigEntry<bool> configDebug;
|
|
|
|
//only for persistence
|
|
public static ConfigEntry<float> inGameSens;
|
|
|
|
public static float mySens = 1f;
|
|
//public static float aimingSens;
|
|
|
|
//sight data for hacky workarounds
|
|
public static int SelectedScope = 0;
|
|
public static int SelectedScopeMode = 0;
|
|
public static bool isAiming = false;
|
|
|
|
//human-friendly names for variables used later
|
|
public static float baseCameraFOV = 75;
|
|
public static float currentFPSCameraFOV = 75;
|
|
public static float currentScopeCameraFOV = 75;
|
|
|
|
void printDebug()
|
|
{
|
|
Logger.LogInfo($"\nIn-Game FOV: {configFOV.Value} In-Game Sens: {inGameSens.Value} FOV Override: {configFOVRangeOverride.Value}" +
|
|
$"\nFPS Camera FOV: {currentFPSCameraFOV} / {Core.CalculateHFOV(currentFPSCameraFOV)} BaseOpticCamera FOV: {currentScopeCameraFOV} / {Core.CalculateHFOV(currentScopeCameraFOV)} CurrentFOV: {Core.DetermineCurrentFOV()} / {Core.CalculateHFOV(Core.DetermineCurrentFOV())}" +
|
|
$"\nisAiming? {isAiming} SelectedScope: {SelectedScope} SelectedScopeMode:{SelectedScopeMode}" +
|
|
$"\nCalculated sensitivity: {Core.CalculateSensitivity(Core.DetermineCurrentFOV(), baseCameraFOV)}" +
|
|
$"\nAspect Ratio: {Core.GetAspectRatio()}" +
|
|
$"\nFinal Sensitivity: {mySens * inGameSens.Value}");
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
new UpdateSensitivityPatch().Enable();
|
|
new get_AimingSensitivityPatch().Enable();
|
|
new get_SelectedScopeIndexPatch().Enable();
|
|
new get_SelectedScopeModePatch().Enable();
|
|
new get_IsAimingPatch().Enable();
|
|
|
|
//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;
|
|
}
|
|
|
|
//add configuration slider for field of view
|
|
configFOV = Config.Bind("General", "FOV", 75, new ConfigDescription("In-game Field of View value", new AcceptableValueRange<int>(FOVRange[0], FOVRange[1])));
|
|
|
|
//add coefficient slider
|
|
configCoeff = Config.Bind("General", "Coefficient", 133, new ConfigDescription("Coefficient - increases sensitivity at higher zoom levels", new AcceptableValueRange<int>(1, 300)));
|
|
|
|
//add sensitivity slider
|
|
configSens = Config.Bind("General", "Sensitivity", 100, new ConfigDescription("Fine control over sensitivity while aiming", new AcceptableValueRange<int>(1, 200)));
|
|
|
|
//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)));
|
|
|
|
}
|
|
void FixedUpdate()
|
|
{
|
|
//FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns
|
|
Time.fixedDeltaTime = (1f / 50f);
|
|
|
|
//check if the game is running
|
|
var isRunning = Utils.checkIsReady();
|
|
if (!isRunning) return;
|
|
|
|
if (isRunning)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
//cgheck if the player is aiming
|
|
if (isAiming)
|
|
{
|
|
//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);
|
|
}
|
|
}
|
|
}
|
|
//Print debug info in BepInEx console
|
|
if (configDebug.Value) printDebug();
|
|
}
|
|
}
|
|
}
|
|
|