mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 05:30:43 -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:
parent
53363d5a25
commit
eb443aaa5e
@ -64,8 +64,7 @@ namespace Aki.Custom
|
|||||||
new BTRTransferItemsPatch().Enable();
|
new BTRTransferItemsPatch().Enable();
|
||||||
new BTREndRaidItemDeliveryPatch().Enable();
|
new BTREndRaidItemDeliveryPatch().Enable();
|
||||||
new BTRDestroyAtRaidEndPatch().Enable();
|
new BTRDestroyAtRaidEndPatch().Enable();
|
||||||
new BTRAppFrameratePatches.VehicleBaseInitFpsPatch().Enable();
|
new BTRVehicleMovementSpeedPatch().Enable();
|
||||||
new BTRAppFrameratePatches.VehicleBaseResetFpsPatch().Enable();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -26,7 +26,7 @@ namespace Aki.Custom.BTR.Patches
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PatchPrefix]
|
[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;
|
var gameWorld = Singleton<GameWorld>.Instance;
|
||||||
if (gameWorld == null)
|
if (gameWorld == null)
|
||||||
@ -75,9 +75,7 @@ namespace Aki.Custom.BTR.Patches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tuple = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
|
___valueTuple_0 = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
|
||||||
var btrTurretViewTupleField = AccessTools.Field(__instance.GetType(), "valueTuple_0");
|
|
||||||
btrTurretViewTupleField.SetValue(__instance, tuple);
|
|
||||||
|
|
||||||
__result = true;
|
__result = true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -14,11 +14,9 @@ namespace Aki.Custom.BTR.Patches
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PatchPrefix]
|
[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 flag2 = __instance.method_2();
|
||||||
bool flag3 = __instance.targetPosition != __instance.defaultAimingPosition;
|
bool flag3 = __instance.targetPosition != __instance.defaultAimingPosition;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user