0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/BTR/Patches/BTRAppFrameratePatches.cs
DrakiaXYZ c01bd92c78 Fix BTR when NVidia Reflex is enabled (!71)
- Before `Application.targetFrameRate` is used in the BTR code, set it to 60. Then set it back afterwards
- Remove an unnecessary error from BTRExtractPassengersPatch, not actually an error state

All credit goes to Ngst for figuring out that NVidia Reflex was causing the BTR issues

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#71
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
2024-01-29 19:08:38 +00:00

61 lines
1.9 KiB
C#

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;
}
}
}
}