using BepInEx; using BepInEx.Configuration; using System; using UnityEngine; using EFT; namespace UniformAim { [BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.0.0")] [BepInProcess("EscapeFromTarkov.exe")] public class Plugin : BaseUnityPlugin { //Bepinex.Configurator fields public static ConfigEntry configFOV; public static ConfigEntry configCoeff; public static ConfigEntry configSens; public static ConfigEntry configOverride; //TODO: figure out a way to read game settings to default the configFOV.Value to whatever the player has already set //TODO: figure out a way to read game settings to apply configSens.Value as a multiplier on top of Tarkov's stock sensitivity setting public static float mySens = 1f; //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 float FPSCameraFOV = 50f; float ScopeFOV = 50f; float currentFOV = 50f; //Return aspect ratio based on game window resolution, currently unused but could be useful in the future 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, currently unused but could be useful in the future 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); //convert to radians aimedFOV = aimedFOV * Mathf.Deg2Rad; hipFOV = hipFOV * Mathf.Deg2Rad; float exponent = (float)(100f / configCoeff.Value); float tanRatio = (float)(Math.Tan(aimedFOV / 2) / Math.Tan(hipFOV / 2)); float sensitivity = (float)(configSens.Value/100f); float result = (float)Math.Pow(tanRatio, exponent) * sensitivity; return result; } //used to determine if the player is looking through the scope bool isScopeCameraActive() { if (Camera.allCamerasCount > 1) { return Camera.allCameras[1].GetComponent().isActiveAndEnabled; } return false; } //used to determine the correct FOV for calculations void DetermineCurrentFOV() { if (!isScopeCameraActive()) { currentFOV = FPSCameraFOV; } else { if (SelectedScope == 0) { currentFOV = ScopeFOV;} if (SelectedScope != 0) { currentFOV = FPSCameraFOV; } } } void Awake() { new UpdateSensitivityPatch().Enable(); new get_AimingSensitivityPatch().Enable(); new get_SelectedScopeIndexPatch().Enable(); new get_SelectedScopeModePatch().Enable(); new get_IsAimingPatch().Enable(); //add configuration slider for field of view configFOV = Config.Bind("General", "FOV", 75, new ConfigDescription("In-game Field of View value", new AcceptableValueRange(51, 75))); //add coefficient slider configCoeff = Config.Bind("General", "Coefficient", 133, new ConfigDescription("Coefficient - increases sensitivity at higher zoom levels", new AcceptableValueRange(1, 300))); //add sensitivity slider configSens = Config.Bind("General", "Sensitivity", 25, new ConfigDescription("Sensitivity while aiming", new AcceptableValueRange(1, 200))); //override for consistent mouse to 360 distance configOverride = Config.Bind("Debug", "Override sensitivity", false, new ConfigDescription("Overrides sensitivity to provide consistent mouse to 360 distance regardless of zoom level.")); } void Update() { if (isAiming) { //Grab FOV values for calculation FPSCameraFOV = Camera.allCameras[0].fieldOfView; if (Camera.allCamerasCount > 1) { ScopeFOV = Camera.allCameras[1].fieldOfView; } //calculate what FOV is right DetermineCurrentFOV(); } ////do the magic! mySens = CalculateSensitivity(currentFOV, configFOV.Value, configSens.Value); //Override for crazy people, enables consistent mouse input to 360 rotation. Why would anyone do it? if (configOverride.Value == true) { mySens = (float)(configSens.Value / 100f); } } } }