Skip to content

Commit

Permalink
fix fast input when the timescale is 0 and improve timescale handling
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xMachina committed Jun 3, 2024
1 parent 64f0756 commit 611f989
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Patches/FrameRate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 611f989

Please sign in to comment.