From 611f9891baa14c36a322cc8afd6c602c944bf455 Mon Sep 17 00:00:00 2001 From: d3xMachina <16732772+d3xMachina@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:22:28 +0200 Subject: [PATCH] fix fast input when the timescale is 0 and improve timescale handling --- Patches/FrameRate.cs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Patches/FrameRate.cs b/Patches/FrameRate.cs index f1cb108..2499be2 100644 --- a/Patches/FrameRate.cs +++ b/Patches/FrameRate.cs @@ -34,14 +34,25 @@ static void UncapFramerate() // As this is always called on frame updates, we adjust the accumulation speed to match the new framerate [HarmonyPatch(typeof(TimeFunction), nameof(TimeFunction.Function))] [HarmonyPrefix] - static void TimeFunctionFix(Action action, ref float waitTime, ref float acceleration, ref float waitTimeLowLimit, bool isAffectedTimeScale) + static bool TimeFunctionFix(TimeFunction __instance, Action action, float waitTime, float acceleration, float waitTimeLowLimit, bool isAffectedTimeScale) { - var rateFix = ModComponent.Instance.DefaultFrameRate / (1f / Time.unscaledDeltaTime); - acceleration *= rateFix; + var deltaTime = Time.unscaledDeltaTime; + __instance.checkTime += deltaTime; - // Fix fast input when the speedhack is enabled - float timeScale = Time.timeScale; - waitTime *= timeScale; - waitTimeLowLimit *= timeScale; + var rateFix = ModComponent.Instance.DefaultFrameRate / (1f / deltaTime); + var waitTimeRemaining = waitTime - (__instance.Acceleration * rateFix); + if (waitTime != 0f && waitTimeRemaining <= waitTimeLowLimit) + { + waitTimeRemaining = waitTimeLowLimit; + } + + if (waitTimeRemaining <= __instance.checkTime) + { + action?.Invoke(); + __instance.checkTime = 0f; + } + + __instance.Acceleration += acceleration; + return false; } }