mirror of
https://github.com/hykilpikonna/AquaDX.git
synced 2026-09-12 03:15:45 -05:00
fix: LongMusic restart
This commit is contained in:
54
AquaMai.Mods/Fix/FixLongMusicRestart.cs
Normal file
54
AquaMai.Mods/Fix/FixLongMusicRestart.cs
Normal file
@@ -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<GamePlayManager>.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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user