From c1c7788cd3900841215f7b320721aee8f85b19bb Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 27 Sep 2024 20:18:53 +0800 Subject: [PATCH] [O] Auto detect if DebugFeature is need to be patched --- AquaMai/AquaMai.csproj | 2 +- AquaMai/AquaMai.toml | 2 -- AquaMai/AquaMai.zh.toml | 2 -- AquaMai/Config.cs | 1 - AquaMai/{Cheat => Fix}/DebugFeature.cs | 32 +++++++++++++++++++++----- AquaMai/Main.cs | 1 + 6 files changed, 28 insertions(+), 12 deletions(-) rename AquaMai/{Cheat => Fix}/DebugFeature.cs (77%) diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj index d66288ca..9b5f785e 100644 --- a/AquaMai/AquaMai.csproj +++ b/AquaMai/AquaMai.csproj @@ -284,12 +284,12 @@ - + diff --git a/AquaMai/AquaMai.toml b/AquaMai/AquaMai.toml index 656f2221..fa18eac3 100644 --- a/AquaMai/AquaMai.toml +++ b/AquaMai/AquaMai.toml @@ -8,8 +8,6 @@ TicketUnlock=true MapUnlock=true # Unlock Utage without the need of DXRating 10000 UnlockUtage=true -# Restore AutoPlay(Home) and Pause(Enter) for SDGA -DebugFeature=true # =================================== # UX: User Experience Improvements diff --git a/AquaMai/AquaMai.zh.toml b/AquaMai/AquaMai.zh.toml index ebdb57ea..512023c1 100644 --- a/AquaMai/AquaMai.zh.toml +++ b/AquaMai/AquaMai.zh.toml @@ -11,8 +11,6 @@ TicketUnlock=true MapUnlock=true # 不需要万分也可以进宴会场 UnlockUtage=true -# 恢复 SDGA 的自动播放(Home)和暂停(Enter)按键 -DebugFeature=true # =================================== # 用户体验改进 diff --git a/AquaMai/Config.cs b/AquaMai/Config.cs index cec4b6df..5a59fa4c 100644 --- a/AquaMai/Config.cs +++ b/AquaMai/Config.cs @@ -18,7 +18,6 @@ namespace AquaMai public bool TicketUnlock { get; set; } public bool MapUnlock { get; set; } public bool UnlockUtage { get; set; } - public bool DebugFeature { get; set; } } public class UXConfig diff --git a/AquaMai/Cheat/DebugFeature.cs b/AquaMai/Fix/DebugFeature.cs similarity index 77% rename from AquaMai/Cheat/DebugFeature.cs rename to AquaMai/Fix/DebugFeature.cs index 5bfbd470..e47a7cb7 100644 --- a/AquaMai/Cheat/DebugFeature.cs +++ b/AquaMai/Fix/DebugFeature.cs @@ -1,22 +1,37 @@ using System; +using System.Collections.Generic; +using System.Reflection; using HarmonyLib; using MAI2.Util; using Manager; +using MelonLoader; using Monitor; using Process; using UnityEngine; -namespace AquaMai.Cheat; +namespace AquaMai.Fix; +[HarmonyPatch] public class DebugFeature { -# if SDGA145 + public static bool IsPatchingSkipped { get; private set; } private static bool isPause; private static double timer; - [HarmonyPostfix] - [HarmonyPatch(typeof(GameProcess), "OnUpdate")] - public static void PostGameProcessUpdate(GameProcess __instance, byte ____sequence, MovieController ____gameMovie, GameMonitor[] ____monitors) + public static IEnumerable TargetMethods() + { + var original = typeof(GameProcess).GetField("debugFeature", BindingFlags.NonPublic | BindingFlags.Instance); + if (original is not null) + { + MelonLogger.Msg("[DebugFeature] Skipped because already included"); + IsPatchingSkipped = true; + return []; + } + + return [AccessTools.Method(typeof(GameProcess), "OnUpdate")]; + } + + public static void Postfix(GameProcess __instance, byte ____sequence, MovieController ____gameMovie, GameMonitor[] ____monitors) { if (____sequence != 4) return; // GameSequence.Play @@ -24,6 +39,7 @@ public class DebugFeature { timer += GameManager.GetGameMSecAddD(); } + if (Input.GetKeyDown(KeyCode.Home)) { GameManager.AutoPlay = (GameManager.AutoPlayMode)((int)(GameManager.AutoPlay + 1) % Enum.GetNames(typeof(GameManager.AutoPlayMode)).Length); @@ -42,10 +58,12 @@ public class DebugFeature { num23 = -1000; } + if (DebugInput.GetKeyDown(KeyCode.RightArrow)) { num23 = 1000; } + int addMsec = ((!DebugInput.GetKey(KeyCode.LeftShift) && !DebugInput.GetKey(KeyCode.RightShift)) ? ((!DebugInput.GetKey(KeyCode.LeftControl) && !DebugInput.GetKey(KeyCode.RightControl)) ? num23 : (num23 * 10)) : (num23 * 5)); Singleton.Instance.Initialize(); DebugTimeSkip(addMsec); @@ -66,12 +84,14 @@ public class DebugFeature { timer = timer + addMsec >= 0.0 ? timer + addMsec : 0.0; } + ____gameMovie.SetSeekFrame(timer); SoundManager.SeekMusic((int)timer); for (int i = 0; i < ____monitors.Length; i++) { ____monitors[i].Seek((int)timer); } + // magic number, dont know why NotesManager.StartPlay((int)timer + 91); NotesManager.Pause(isPause); @@ -84,8 +104,8 @@ public class DebugFeature { ____gameMovie.Pause(pauseFlag: true); } + __instance.UpdateNotes(); } } -# endif } diff --git a/AquaMai/Main.cs b/AquaMai/Main.cs index e4148124..4a132b4b 100644 --- a/AquaMai/Main.cs +++ b/AquaMai/Main.cs @@ -129,6 +129,7 @@ namespace AquaMai Patch(typeof(DisableReboot)); Patch(typeof(ExtendNotesPool)); Patch(typeof(FixCheckAuth)); + Patch(typeof(DebugFeature)); // UX Patch(typeof(CustomVersionString)); Patch(typeof(CustomPlaceName));