AquaDX/AquaMai.Mods/UX/OneKeyRetrySkip.cs

69 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AquaMai.Config.Attributes;
using AquaMai.Config.Types;
using AquaMai.Core.Helpers;
using HarmonyLib;
using MAI2.Util;
using Manager;
using MelonLoader;
using Process;
namespace AquaMai.Mods.UX;
[ConfigSection(
en: "One key to retry (1.30+) or skip current chart in gameplay.",
zh: "在游戏中途一键重试1.30+)或跳过当前谱面")]
public class OneKeyRetrySkip
{
[ConfigEntry]
public static readonly KeyCodeOrName retryKey = KeyCodeOrName.Service;
[ConfigEntry]
public static readonly bool retryLongPress = false;
[ConfigEntry]
public static readonly KeyCodeOrName skipKey = KeyCodeOrName.Service;
[ConfigEntry]
public static readonly bool skipLongPress = true;
private static bool dirty = false;
[HarmonyPostfix]
[HarmonyPatch(typeof(GameProcess), "OnStart")]
public static void PostGameProcessStart()
{
#if DEBUG
MelonLogger.Msg("[OneKeyRetrySkip] Dirty flag reset");
#endif
dirty = false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameProcess), "OnUpdate")]
public static void PostGameProcessUpdate(GameProcess __instance, Message[] ____message, ProcessDataContainer ___container)
{
if (dirty) return;
if (KeyListener.GetKeyDownOrLongPress(skipKey, skipLongPress))
{
#if DEBUG
MelonLogger.Msg("[OneKeyRetrySkip] Skip key pressed.");
#endif
dirty = true;
var traverse = Traverse.Create(__instance);
___container.processManager.SendMessage(____message[0]);
Singleton<GamePlayManager>.Instance.SetSyncResult(0);
traverse.Method("SetRelease").GetValue();
}
else if (KeyListener.GetKeyDownOrLongPress(retryKey, retryLongPress) && GameInfo.GameVersion >= 23000)
{
#if DEBUG
MelonLogger.Msg("[OneKeyRetrySkip] Retry key pressed.");
#endif
dirty = true;
// This is original typo in Assembly-CSharp
Singleton<GamePlayManager>.Instance.SetQuickRetryFrag(flag: true);
}
}
}