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

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>
This commit is contained in:
DrakiaXYZ 2024-01-29 19:08:38 +00:00 committed by chomp
parent 2d2b4fb78f
commit c01bd92c78
3 changed files with 62 additions and 1 deletions

View File

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

View File

@ -0,0 +1,60 @@
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

@ -24,7 +24,6 @@ namespace Aki.Custom.BTR.Patches
var btrSide = btrManager.LastInteractedBtrSide;
if (btrSide == null)
{
Logger.LogError($"[AKI-BTR] BTRExtractPassengersPatch - btrSide is null");
return;
}