Update for SPT 3.4.1

Realism Mod compatibility
Fix towards weapons with no sight present
This commit is contained in:
notGreg 2023-01-06 17:01:42 +01:00
parent 98767f520f
commit fffbcca2e0
3 changed files with 50 additions and 25 deletions

View File

@ -15,7 +15,7 @@ namespace notGreg.UniformAim
protected override MethodBase GetTargetMethod()
{
return typeof(Player.FirearmController).GetMethod("get_AimingSensitivity");
return typeof(Player.FirearmController).GetMethod("get_AimingSensitivity");
}
[PatchPostfix]
public static void PatchPostfix(ref float ____aimingSens)

View File

@ -1,4 +1,5 @@
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Comfort.Common;
using EFT;
@ -10,23 +11,31 @@ using UnityEngine;
namespace notGreg.UniformAim
{
[BepInPlugin("com.notGreg.UniformAim", "notGreg's Uniform Aim for Tarkov", "3.3.0")]
[BepInDependency("RealismMod", BepInDependency.DependencyFlags.SoftDependency)]
public class Plugin : BaseUnityPlugin
{
ConfigEntry<int> configExponent;
ConfigEntry<float> configSens;
public static bool isRealismModPresent = Chainloader.PluginInfos.ContainsKey("RealismMod");
void Awake()
{
configExponent = Config.Bind("General", "Coefficient", 133, new ConfigDescription("", new AcceptableValueRange<int>(10, 200)));
configSens = Config.Bind("General", "Sensitivity", 1.0f, new ConfigDescription("", new AcceptableValueRange<float>(0.01f, 2.0f)));
new get_AimingSensitivityPatch().Enable();
if (!isRealismModPresent)
{
new get_AimingSensitivityPatch().Enable();
}
}
Player mainPlayer;
int inGameFOV;
float inGameAimedSens;
public static float aimingSens;
public static float aimingSens = 1.0f;
//public static float bridgeSens = 1.0f;
//this function can be replaced by FixedUpdate() at 50Hz (adjustable via Time.fixedDeltaTime)
//FixedUpdate() proved to be slightly more reliable in the past, however it had other unintended effects on the game.
@ -45,12 +54,18 @@ namespace notGreg.UniformAim
//check if the game has started and if the player exists. If the player is aiming, update the scoped sensitivity (executed every frame while aiming)
//Logger.LogInfo("Checking GameStatus and isAiming");
//Logger.LogInfo($"GameStatus: {currentGameStatus}");
if (currentGameStatus == GameStatus.Started && mainPlayer != null)
{
//Logger.LogInfo($"isAiming? {mainPlayer.HandsController.IsAiming}");
if (mainPlayer.HandsController.IsAiming)
{
aimingSens = calculateSensitivity();
//if (isRealismModPresent)
//{ bridgeSens = calculateSensitivity(); }
//else
//{
aimingSens = calculateSensitivity();
//}
}
return;
}
@ -81,6 +96,8 @@ namespace notGreg.UniformAim
break;
}
}
}
//this function grabs the Field of View from the settings. This is the function that most often needs patching after update.
@ -88,7 +105,8 @@ namespace notGreg.UniformAim
int getInGameFOV()
{
//int fov = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.2.3
int fov = Singleton<GClass1653>.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.3.0
//int fov = Singleton<GClass1653>.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.3.0
int fov = Singleton<GClass1659>.Instance.Game.Settings.FieldOfView; //SPT-AKI 3.4.1
//Logger.LogInfo($"In-game FOV: {fov}");
return fov;
}
@ -98,13 +116,15 @@ namespace notGreg.UniformAim
float getInGameAimSens()
{
//float sens = Singleton<GClass1642>.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.2.*
float sens = Singleton<GClass1653>.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.3.0
//float sens = Singleton<GClass1653>.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.3.0
float sens = Singleton<GClass1659>.Instance.Control.Settings.MouseAimingSensitivity; //SPT-AKI 3.4.1
//Logger.LogInfo($"In-game AimSens: {sens}");
return sens;
}
Player getLocalPlayer()
{
//Logger.LogInfo("Setting local player...");
return Singleton<GameWorld>.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer);
}
@ -143,27 +163,31 @@ namespace notGreg.UniformAim
yield break;
}
//convert vertical FOV (degrees) to horizontal FOV (degrees)
float calculateHFOV(Camera camera)
{
return Camera.VerticalToHorizontalFieldOfView(camera.fieldOfView, camera.aspect);
}
//figure out whether the player is using a magnified optic or not. Return the FOV of the sight.
Camera determineCurrentAimedFOV()
{
var currentAimingMode = mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod;
//Logger.LogInfo("Get current aiming mod");
//Logger.LogInfo($"MainPlayer {mainPlayer.name}");
//Logger.LogInfo($"ProcWeapAnim {mainPlayer.ProceduralWeaponAnimation}");
//Logger.LogInfo($"CurrAimMod {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod}");
if (mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod == null)
{
return mainCamera;
}
var currentAimingMod = mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod;
//get the name of the currently active scope
string scopeName = currentAimingMode.Item.Template.Name;
//string scopeName = currentAimingMod.Item.Template.Name;
string scopeName = currentAimingMod.Item.Name;
//Logger.LogInfo($"Scope name: {scopeName}");
//scopeMode determines the scope being used (e.g. main magnified optic at index 0, backup RDS at index 1)
//scopeIndex determines the mode of the scope being used (e.g. x1 magnification at index 0, x4 magnification at index 1)
//there are exceptions to this rule thanks to BSG's inconsistency, some of them are patched below
var scopeIndex = currentAimingMode.SelectedScopeIndex;
var scopeMode = currentAimingMode.SelectedScopeMode;
var scopeIndex = currentAimingMod.SelectedScopeIndex;
var scopeMode = currentAimingMod.SelectedScopeMode;
//Logger.LogInfo("Index: " + scopeIndex + "\nMode: " + scopeMode);
@ -193,7 +217,7 @@ namespace notGreg.UniformAim
{
if (scopeIndex == 1)
{
//Logger.Loginfo($"G36 Rail sight");
//Logger.LogInfo($"G36 Rail sight");
return mainCamera;
}
else
@ -219,13 +243,14 @@ namespace notGreg.UniformAim
float calculateSensitivity()
{
//Logger.LogInfo("calculateSensitivity()");
//grab vertical hipfire field of view (FOV set by the user in the setting), then convert it to horizontal FOV
//convert degrees to radians
float hipFOV = Mathf.Deg2Rad * Camera.VerticalToHorizontalFieldOfView(inGameFOV, mainCamera.aspect);
//grab current field of view while aiming, then convert it to horizontal FOV
//convert degrees to radians
float aimedFOV = Mathf.Deg2Rad * calculateHFOV(determineCurrentAimedFOV());
float aimedFOV = Mathf.Deg2Rad * Camera.VerticalToHorizontalFieldOfView(determineCurrentAimedFOV().fieldOfView, mainCamera.aspect);
//exponent applied to the ratio of aimedFOV to hipFOV, causes sights to become relatively faster or slower as zoom increases
float exponent = 100f / configExponent.Value;

View File

@ -38,27 +38,27 @@
<ItemGroup>
<Reference Include="Aki.Reflection, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll</HintPath>
<HintPath>E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx, Version=5.4.21.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.3.0\BepInEx\core\BepInEx.dll</HintPath>
<HintPath>E:\SPT-AKI\SPT-AKI 3.4.1\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Comfort, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\Comfort.dll</HintPath>
<HintPath>E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\Comfort.dll</HintPath>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.3.0\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>E:\SPT-AKI\SPT-AKI 3.4.1\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />