Skip to content

Commit 205ce2b

Browse files
committed
fix: LongMusic restart
1 parent 6210829 commit 205ce2b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Diagnostics;
2+
using System.Linq;
3+
using AquaMai.Config.Attributes;
4+
using AquaMai.Core.Attributes;
5+
using HarmonyLib;
6+
using MAI2.Util;
7+
using Manager;
8+
using MelonLoader;
9+
using Process;
10+
11+
namespace AquaMai.Mods.Fix;
12+
13+
[EnableGameVersion(25500)]
14+
[ConfigSection(zh: "修复 Long Music 重开时重复扣除 Track 数",
15+
exampleHidden: true, defaultOn: true)]
16+
public class FixLongMusicRestart
17+
{
18+
private static bool isThisGameRestart = false;
19+
20+
[HarmonyPrefix]
21+
[HarmonyPatch(typeof(GameProcess), "OnStart")]
22+
public static void PreGameProcessStart()
23+
{
24+
isThisGameRestart = Singleton<GamePlayManager>.Instance.IsQuickRetry();
25+
}
26+
27+
[HarmonyPostfix]
28+
[HarmonyPatch(typeof(GameProcess), "OnStart")]
29+
public static void PostGameProcessStart()
30+
{
31+
isThisGameRestart = false;
32+
}
33+
34+
[HarmonyPrefix]
35+
[HarmonyPatch(typeof(DataManager), nameof(DataManager.IsLong))]
36+
public static bool PatchIsLong(ref bool __result)
37+
{
38+
if (!isThisGameRestart)
39+
{
40+
return true;
41+
}
42+
var stackTrace = new StackTrace();
43+
var stackFrames = stackTrace.GetFrames();
44+
if (stackFrames.All(it => it.GetMethod().DeclaringType.Name != "GameProcess"))
45+
{
46+
#if DEBUG
47+
MelonLogger.Msg("[FixLongMusicRestart] IsLong called outside GameProcess, returning true.");
48+
#endif
49+
return true;
50+
}
51+
__result = false;
52+
return false;
53+
}
54+
}

0 commit comments

Comments
 (0)