diff --git a/project/Aki.Custom/AkiCustomPlugin.cs b/project/Aki.Custom/AkiCustomPlugin.cs index 20b240f..954dd88 100644 --- a/project/Aki.Custom/AkiCustomPlugin.cs +++ b/project/Aki.Custom/AkiCustomPlugin.cs @@ -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) { diff --git a/project/Aki.Custom/BTR/Patches/BTRAppFrameratePatches.cs b/project/Aki.Custom/BTR/Patches/BTRAppFrameratePatches.cs new file mode 100644 index 0000000..61a14d9 --- /dev/null +++ b/project/Aki.Custom/BTR/Patches/BTRAppFrameratePatches.cs @@ -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; + } + } + } +} diff --git a/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs b/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs index b90bb0b..68e5744 100644 --- a/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs @@ -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; }