using ADOFAIRenderer.Core;
using HarmonyLib;
namespace ADOFAIRenderer.Patch.Game;
///
/// Replaces the "any valid input" check with a render-controlled value, so player input cannot affect the level during a render.
///
/// Patched member: scrPlayerManager.AnyValidInputWasTriggered(), true when any player pressed a valid key this frame.
/// scrController uses it to leave the press-to-start wait, to restart after a failure (Fail2_Update) and to
/// leave the level after a win (Won_Update).
///
///
/// Active while (stage >= OnScene). The result is true only while
/// RenderManager.countdown is 0 and RenderManager.frameCount is 0, that is, after the 3 second countdown in
/// SetupPlay has ended and reset the frame counter and before the next frame increments it; it is false otherwise.
/// SetupPlay also sets scrController.levelWasSkipped, which ends the press-to-start wait independently of input.
///
///
[HarmonyPatch(typeof(scrPlayerManager))]
// ReSharper disable once InconsistentNaming
public static class scrPlayerManagerPatch
{
/// Prefix of scrPlayerManager.AnyValidInputWasTriggered.
/// Return value used when the original is skipped (see class summary).
/// True to run the original method (not rendering); false to skip it (rendering).
[HarmonyPrefix]
[HarmonyPatch("AnyValidInputWasTriggered")]
// ReSharper disable once InconsistentNaming
private static bool IgnoreInput(ref bool __result)
{
if (!RenderManager.IsActive) return true;
__result = RenderManager.Instance && RenderManager.Instance.frameCount == 0 && RenderManager.Instance.countdown == 0;
return false;
}
}