Update for SPT-AKI 3.2.1
Compatibility patch for Leupold D-EVO mod
This commit is contained in:
parent
43a867df8d
commit
0af21f395f
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace UniformAim
|
namespace UniformAim
|
||||||
@ -6,14 +8,14 @@ namespace UniformAim
|
|||||||
public class Core
|
public class Core
|
||||||
{
|
{
|
||||||
//math stuff
|
//math stuff
|
||||||
public static float CalculateHFOV(float FOV)
|
public float CalculateHFOV(float FOV)
|
||||||
{
|
{
|
||||||
//RETURNS RADIANS
|
//RETURNS RADIANS
|
||||||
return Camera.VerticalToHorizontalFieldOfView(FOV, Camera.main.aspect);
|
return Camera.VerticalToHorizontalFieldOfView(FOV, Camera.main.aspect);
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate sensitivity based on FOV delta and coefficient
|
//calculate sensitivity based on FOV delta and coefficient
|
||||||
public static float CalculateSensitivity(float aimedFOV, float hipFOV)
|
public float CalculateSensitivity(float aimedFOV, float hipFOV)
|
||||||
{
|
{
|
||||||
//calculate horizontal FOV values for inputs
|
//calculate horizontal FOV values for inputs
|
||||||
aimedFOV = CalculateHFOV(aimedFOV) * Mathf.Deg2Rad;
|
aimedFOV = CalculateHFOV(aimedFOV) * Mathf.Deg2Rad;
|
||||||
@ -37,12 +39,53 @@ namespace UniformAim
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//figure out current fov based on scope and in-game camera statuses
|
//figure out current fov based on scope and in-game camera statuses
|
||||||
public static float DetermineCurrentFOV()
|
public float DetermineCurrentFOV(float FPSCameraFOV, float ScopeCameraFOV, int SelectedScope, int SelectedScopeMode = 0)
|
||||||
{
|
{
|
||||||
//dirty fix for the Ultima MP-155 shotgun
|
//dirty fix for the Ultima MP-155 shotgun
|
||||||
if (Plugin.currentFPSCameraFOV> 35 && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; }
|
try
|
||||||
|
{
|
||||||
|
if(GameObject.Find("tactical_mp155_kalashnikov_ultima_camera(Clone)").GetComponent<Behaviour>().isActiveAndEnabled)
|
||||||
|
{
|
||||||
|
if (Plugin.currentFPSCameraFOV > (Plugin.configFOV.Value - 15) && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NullReferenceException)
|
||||||
|
{
|
||||||
|
return Plugin.currentFPSCameraFOV;
|
||||||
|
}
|
||||||
|
//if (Plugin.currentFPSCameraFOV > (Plugin.configFOV.Value - 15) && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; }
|
||||||
|
|
||||||
if (Plugin.SelectedScope == 0 && isScopeCameraActive()) { return Plugin.currentScopeCameraFOV; } else { return Plugin.currentFPSCameraFOV; }
|
//dirty fix for Leupold D-EVO mod
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(GameObject.Find("scope_leupold_d_evo(Clone)").GetComponent<Behaviour>().isActiveAndEnabled)
|
||||||
|
{
|
||||||
|
switch (Plugin.SelectedScope)
|
||||||
|
{
|
||||||
|
case 0: return Plugin.currentFPSCameraFOV;
|
||||||
|
case 1: return Plugin.currentScopeCameraFOV;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(NullReferenceException)
|
||||||
|
{
|
||||||
|
return Plugin.currentFPSCameraFOV;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(Camera.main.isActiveAndEnabled && Plugin.SelectedScope == 0 && isScopeCameraActive())
|
||||||
|
{
|
||||||
|
return Plugin.currentScopeCameraFOV;
|
||||||
|
}
|
||||||
|
else { return Plugin.currentFPSCameraFOV; }
|
||||||
|
}
|
||||||
|
catch (NullReferenceException)
|
||||||
|
{
|
||||||
|
return Plugin.configFOV.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (Plugin.SelectedScope == 0 && isScopeCameraActive()) { return Plugin.currentScopeCameraFOV; } else { return Plugin.currentFPSCameraFOV; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,26 @@
|
|||||||
using BepInEx;
|
using BepInEx;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace UniformAim
|
namespace UniformAim
|
||||||
{
|
{
|
||||||
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.1.2")]
|
[BepInPlugin("com.greg.tarkovuniformaim", "Uniform Aim for Tarkov", "1.1.3")]
|
||||||
[BepInProcess("EscapeFromTarkov.exe")]
|
[BepInProcess("EscapeFromTarkov.exe")]
|
||||||
|
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//Bepinex.Configurator fields
|
//Bepinex.Configurator fields
|
||||||
public static ConfigEntry<int> configFOV;
|
public static ConfigEntry<int> configFOV;
|
||||||
int[] FOVRange = new int[2] { 50, 75 };
|
int[] FOVRange = new int[2] { 50, 75 };
|
||||||
public static ConfigEntry<bool> configFOVRangeOverride;
|
ConfigEntry<bool> configFOVRangeOverride;
|
||||||
|
|
||||||
public static ConfigEntry<int> configCoeff;
|
public static ConfigEntry<int> configCoeff;
|
||||||
public static ConfigEntry<int> configSens;
|
public static ConfigEntry<int> configSens;
|
||||||
public static ConfigEntry<bool> configDebug;
|
ConfigEntry<bool> configDebug;
|
||||||
|
|
||||||
//only for persistence
|
//only for persistence
|
||||||
public static ConfigEntry<float> inGameSens;
|
ConfigEntry<float> inGameSens;
|
||||||
|
|
||||||
public static float mySens = 1f;
|
public static float mySens = 1f;
|
||||||
//public static float aimingSens;
|
//public static float aimingSens;
|
||||||
@ -32,21 +31,14 @@ namespace UniformAim
|
|||||||
public static bool isAiming = false;
|
public static bool isAiming = false;
|
||||||
|
|
||||||
//human-friendly names for variables used later
|
//human-friendly names for variables used later
|
||||||
public static float baseCameraFOV = 75;
|
float baseCameraFOV = 75;
|
||||||
public static float currentFPSCameraFOV = 75;
|
public static float currentFPSCameraFOV = 75;
|
||||||
public static float currentScopeCameraFOV = 75;
|
public static float currentScopeCameraFOV = 75;
|
||||||
|
|
||||||
string lastDebugLog;
|
Core core = new Core();
|
||||||
void printDebug()
|
Utils utils = new Utils();
|
||||||
{
|
Vector2 FOVInfo;
|
||||||
string debugLog = $"\nIn-Game FOV: {configFOV.Value} | In-Game Sens: {inGameSens.Value} | FOV Override: {configFOVRangeOverride.Value}" +
|
Vector2 ScopeInfo;
|
||||||
$"\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)}" +
|
|
||||||
$"\nAspect Ratio: {Camera.main.aspect}" +
|
|
||||||
$"\nFinal Sensitivity: {mySens * inGameSens.Value}";
|
|
||||||
if (lastDebugLog != debugLog) { Logger.LogInfo(debugLog); lastDebugLog = debugLog; }
|
|
||||||
}
|
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@ -77,31 +69,38 @@ namespace UniformAim
|
|||||||
|
|
||||||
//settings for persistence, these values get updated when the in-game menu is opened
|
//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)));
|
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()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
//FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns
|
//FixedUpdate() at 50Hz (Unity default) tickrate appears to resolve the issue of this script breaking when AI spawns
|
||||||
Time.fixedDeltaTime = (1f / 50f);
|
Time.fixedDeltaTime = (1f / 50f);
|
||||||
|
|
||||||
if (Utils.SetRootObject() != null)
|
if (utils.SetRootObject() != null)
|
||||||
{
|
{
|
||||||
var rootObject = Utils.SetRootObject();
|
var rootObject = utils.SetRootObject();
|
||||||
//only update these values if the menu has been opened, otherwise read the config
|
//only update these values if the menu has been opened, otherwise read the config
|
||||||
if (rootObject.transform.Find("Game Settings").gameObject.activeInHierarchy)
|
if (rootObject.transform.Find("Game Settings").gameObject.activeInHierarchy)
|
||||||
{
|
{
|
||||||
if (!configFOVRangeOverride.Value) { configFOV.Value = 50 + Utils.GetInGameFOV(rootObject); }
|
if (!configFOVRangeOverride.Value) { configFOV.Value = 50 + utils.GetInGameFOV(rootObject); }
|
||||||
inGameSens.Value = Utils.GetInGameSens(rootObject);
|
inGameSens.Value = utils.GetInGameSens(rootObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check if the player is in the Hideout or in a Raid
|
||||||
|
var isRunning = utils.checkIsReady();
|
||||||
|
if (!isRunning) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (Camera.main.isActiveAndEnabled != true)
|
||||||
|
{ return; }
|
||||||
|
}catch(NullReferenceException)
|
||||||
|
{
|
||||||
|
Logger.LogInfo("Main camera is disabled!");
|
||||||
|
}
|
||||||
|
|
||||||
//Print debug info in BepInEx console
|
//Print debug info in BepInEx console
|
||||||
if (configDebug.Value) printDebug();
|
if (configDebug.Value) printDebug();
|
||||||
|
|
||||||
//check if the player is in the Hideout or in a Raid
|
|
||||||
var isRunning = Utils.checkIsReady();
|
|
||||||
if (!isRunning) return;
|
|
||||||
|
|
||||||
if (isRunning)
|
if (isRunning)
|
||||||
{
|
{
|
||||||
//check if the player is aiming
|
//check if the player is aiming
|
||||||
@ -113,11 +112,25 @@ namespace UniformAim
|
|||||||
|
|
||||||
//Figure out if the FPSCamera is zoomed in, prevents the script from ticking while the player is healing
|
//Figure out if the FPSCamera is zoomed in, prevents the script from ticking while the player is healing
|
||||||
if (currentFPSCameraFOV < configFOV.Value) {
|
if (currentFPSCameraFOV < configFOV.Value) {
|
||||||
mySens = inGameSens.Value * Core.CalculateSensitivity(Core.DetermineCurrentFOV(), configFOV.Value);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@ namespace UniformAim
|
|||||||
{
|
{
|
||||||
public class Utils
|
public class Utils
|
||||||
{
|
{
|
||||||
public static bool isPlaying = false;
|
//bool isPlaying = false;
|
||||||
public static GameObject rootObject = null;
|
//GameObject rootObject = null;
|
||||||
|
|
||||||
public static bool checkIsReady()
|
public bool checkIsReady()
|
||||||
{
|
{
|
||||||
var gameWorld = Singleton<GameWorld>.Instance;
|
var gameWorld = Singleton<GameWorld>.Instance;
|
||||||
var sessionResultPanel = Singleton<SessionResultPanel>.Instance;
|
var sessionResultPanel = Singleton<SessionResultPanel>.Instance;
|
||||||
@ -26,7 +26,7 @@ namespace UniformAim
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool checkPlayerIsAlive()
|
bool checkPlayerIsAlive()
|
||||||
{
|
{
|
||||||
var gameWorld = Singleton<GameWorld>.Instance;
|
var gameWorld = Singleton<GameWorld>.Instance;
|
||||||
var currentHealth = gameWorld.AllPlayers[0].HealthController.GetBodyPartHealth(EBodyPart.Common).Current;
|
var currentHealth = gameWorld.AllPlayers[0].HealthController.GetBodyPartHealth(EBodyPart.Common).Current;
|
||||||
@ -35,7 +35,7 @@ namespace UniformAim
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static GameObject SetRootObject()
|
public GameObject SetRootObject()
|
||||||
{
|
{
|
||||||
string path = "Common UI/Common UI/SettingsScreen";
|
string path = "Common UI/Common UI/SettingsScreen";
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ namespace UniformAim
|
|||||||
else { return null; }
|
else { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetInGameFOV(GameObject root)
|
public int GetInGameFOV(GameObject root)
|
||||||
{
|
{
|
||||||
GameObject fovObject = root.transform.Find("Game Settings/Image/Other Settings/FOV/FOV").gameObject;
|
GameObject fovObject = root.transform.Find("Game Settings/Image/Other Settings/FOV/FOV").gameObject;
|
||||||
int rootFOV = fovObject.GetComponent<EFT.UI.SelectSlider>().CurrentValue();
|
int rootFOV = fovObject.GetComponent<EFT.UI.SelectSlider>().CurrentValue();
|
||||||
@ -55,7 +55,7 @@ namespace UniformAim
|
|||||||
return rootFOV;
|
return rootFOV;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetInGameSens(GameObject root)
|
public float GetInGameSens(GameObject root)
|
||||||
{
|
{
|
||||||
GameObject sensObject = root.transform.Find("Control Settings/ControlPanel/Mouse Settings/Sensitivity Aiming Panel/Mouse Sensitivity Aiming").gameObject;
|
GameObject sensObject = root.transform.Find("Control Settings/ControlPanel/Mouse Settings/Sensitivity Aiming Panel/Mouse Sensitivity Aiming").gameObject;
|
||||||
float rootSens = sensObject.GetComponent<EFT.UI.FloatSlider>().CurrentValue();
|
float rootSens = sensObject.GetComponent<EFT.UI.FloatSlider>().CurrentValue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user