0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 02:30:44 -05:00

Fixed BTR movement speed being tied to a static framerate (!73)

By multiplying `moveSpeed` by `Time.deltaTime` in `BTRVehicle.Update()`, it prevents the BTR movement from desyncing, and possibly going faster or slower than expected.

Reviewed-on: SPT-AKI/Modules#73
Co-authored-by: Arys <arys@noreply.dev.sp-tarkov.com>
Co-committed-by: Arys <arys@noreply.dev.sp-tarkov.com>
This commit is contained in:
Arys 2024-01-30 09:37:33 +00:00 committed by chomp
parent 53363d5a25
commit eb443aaa5e
5 changed files with 27 additions and 70 deletions

View File

@ -64,8 +64,7 @@ namespace Aki.Custom
new BTRTransferItemsPatch().Enable();
new BTREndRaidItemDeliveryPatch().Enable();
new BTRDestroyAtRaidEndPatch().Enable();
new BTRAppFrameratePatches.VehicleBaseInitFpsPatch().Enable();
new BTRAppFrameratePatches.VehicleBaseResetFpsPatch().Enable();
new BTRVehicleMovementSpeedPatch().Enable();
}
catch (Exception ex)
{

View File

@ -1,60 +0,0 @@
using Aki.Reflection.Patching;
using HarmonyLib;
using System.Reflection;
using UnityEngine;
namespace Aki.Custom.BTR.Patches
{
/**
* This class contains two patches because it's the two places that Application.targetFrameRate are used
* and I wanted to keep the patches together
*
* These patches are used to set the target framerate used by vehicle movement calculations to a static
* value, avoiding issues caused by enabling NVidia Reflex. These values are then set back after the methods
* complete
*/
public static class BTRAppFrameratePatches
{
public class VehicleBaseInitFpsPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(VehicleBase), nameof(VehicleBase.Initialization));
}
[PatchPrefix]
private static void PrefixPatch(out int __state)
{
__state = Application.targetFrameRate;
Application.targetFrameRate = 60;
}
[PatchPostfix]
private static void PostfixPatch(int __state)
{
Application.targetFrameRate = __state;
}
}
public class VehicleBaseResetFpsPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(VehicleBase), nameof(VehicleBase.Reset));
}
[PatchPrefix]
private static void PrefixPatch(out int __state)
{
__state = Application.targetFrameRate;
Application.targetFrameRate = 60;
}
[PatchPostfix]
private static void PostfixPatch(int __state)
{
Application.targetFrameRate = __state;
}
}
}
}

View File

@ -26,7 +26,7 @@ namespace Aki.Custom.BTR.Patches
}
[PatchPrefix]
private static bool PatchPrefix(BTRTurretView __instance, int btrBotId, ref bool __result)
private static bool PatchPrefix(ref ValueTuple<ObservedPlayerView, bool> ___valueTuple_0, int btrBotId, ref bool __result)
{
var gameWorld = Singleton<GameWorld>.Instance;
if (gameWorld == null)
@ -75,9 +75,7 @@ namespace Aki.Custom.BTR.Patches
}
}
var tuple = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
var btrTurretViewTupleField = AccessTools.Field(__instance.GetType(), "valueTuple_0");
btrTurretViewTupleField.SetValue(__instance, tuple);
___valueTuple_0 = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
__result = true;
return false;

View File

@ -14,11 +14,9 @@ namespace Aki.Custom.BTR.Patches
}
[PatchPrefix]
private static bool PatchPrefix(BTRTurretServer __instance)
private static bool PatchPrefix(BTRTurretServer __instance, Transform ___defaultTargetTransform)
{
Transform defaultTargetTransform = (Transform)AccessTools.Field(__instance.GetType(), "defaultTargetTransform").GetValue(__instance);
bool flag = __instance.targetTransform != null && __instance.targetTransform != defaultTargetTransform;
bool flag = __instance.targetTransform != null && __instance.targetTransform != ___defaultTargetTransform;
bool flag2 = __instance.method_2();
bool flag3 = __instance.targetPosition != __instance.defaultAimingPosition;

View File

@ -0,0 +1,22 @@
using Aki.Reflection.Patching;
using EFT.Vehicle;
using HarmonyLib;
using System.Reflection;
using UnityEngine;
namespace Aki.Custom.BTR.Patches
{
public class BTRVehicleMovementSpeedPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BTRVehicle), nameof(BTRVehicle.Update));
}
[PatchPrefix]
private static void PatchPrefix(ref float ___float_10, float ___moveSpeed)
{
___float_10 = ___moveSpeed * Time.deltaTime;
}
}
}