From 205ce2b1bacccc36163371b0ed560d000dec05b8 Mon Sep 17 00:00:00 2001 From: Clansty Date: Wed, 23 Jul 2025 19:46:05 +0800 Subject: [PATCH] fix: LongMusic restart --- AquaMai.Mods/Fix/FixLongMusicRestart.cs | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 AquaMai.Mods/Fix/FixLongMusicRestart.cs diff --git a/AquaMai.Mods/Fix/FixLongMusicRestart.cs b/AquaMai.Mods/Fix/FixLongMusicRestart.cs new file mode 100644 index 00000000..611497a6 --- /dev/null +++ b/AquaMai.Mods/Fix/FixLongMusicRestart.cs @@ -0,0 +1,54 @@ +using System.Diagnostics; +using System.Linq; +using AquaMai.Config.Attributes; +using AquaMai.Core.Attributes; +using HarmonyLib; +using MAI2.Util; +using Manager; +using MelonLoader; +using Process; + +namespace AquaMai.Mods.Fix; + +[EnableGameVersion(25500)] +[ConfigSection(zh: "修复 Long Music 重开时重复扣除 Track 数", + exampleHidden: true, defaultOn: true)] +public class FixLongMusicRestart +{ + private static bool isThisGameRestart = false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(GameProcess), "OnStart")] + public static void PreGameProcessStart() + { + isThisGameRestart = Singleton.Instance.IsQuickRetry(); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(GameProcess), "OnStart")] + public static void PostGameProcessStart() + { + isThisGameRestart = false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(DataManager), nameof(DataManager.IsLong))] + public static bool PatchIsLong(ref bool __result) + { + if (!isThisGameRestart) + { + return true; + } + var stackTrace = new StackTrace(); + var stackFrames = stackTrace.GetFrames(); + if (stackFrames.All(it => it.GetMethod().DeclaringType.Name != "GameProcess")) + { +#if DEBUG + MelonLogger.Msg("[FixLongMusicRestart] IsLong called outside GameProcess, returning true."); +#endif + return true; + } + __result = false; + return false; + } +} \ No newline at end of file