File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments