diff --git a/Source/Module/Menu/OptionSubMenuExt.cs b/Source/Module/Menu/OptionSubMenuExt.cs index b30bda0..38fc495 100644 --- a/Source/Module/Menu/OptionSubMenuExt.cs +++ b/Source/Module/Menu/OptionSubMenuExt.cs @@ -1,10 +1,10 @@ using Celeste.Mod.Core; using Celeste.Mod.TASHelper.Utils; +using Celeste.Mod.UI; using Microsoft.Xna.Framework; using Mono.Cecil.Cil; using Monocle; using MonoMod.Cil; -using Celeste.Mod.UI; using CMCore = Celeste.Mod.Core; namespace Celeste.Mod.TASHelper.Module.Menu; @@ -523,63 +523,62 @@ private static void DrawIcon(Vector2 position, MTexture icon, Vector2 justify, b } } - [Initialize] + [Initialize] private static void InitializeHook() { typeof(TextMenu).GetMethod("Update").IlHook((cursor, _) => { - if (cursor.TryGotoNext(ins => ins.OpCode == OpCodes.Call, ins => ins.MatchCallvirt(typeof(CoreModuleSettings), "get_MenuPageDown"), ins => true, ins => ins.OpCode == OpCodes.Brfalse)) { - ILLabel target = (ILLabel)cursor.Next.Next.Next.Next.Operand; - cursor.MoveAfterLabels(); + if (cursor.TryGotoNext(ins => ins.OpCode == OpCodes.Call, ins => ins.MatchCallvirt(typeof(CoreModuleSettings), "get_MenuPageDown"), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"))) { + cursor.Index += 3; cursor.Emit(OpCodes.Ldarg_0); cursor.EmitDelegate(OnMenuTryPageDown); - cursor.Emit(OpCodes.Brtrue, target); } }); typeof(TextMenu).GetMethod("orig_Update").IlHook((cursor, _) => { - if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuDown)), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"), ins => ins.OpCode == OpCodes.Brfalse_S)) { - ILLabel target = (ILLabel)cursor.Next.Next.Next.Operand; - cursor.MoveAfterLabels(); + if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuDown)), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"))) { + cursor.Index += 2; cursor.Emit(OpCodes.Ldarg_0); cursor.EmitDelegate(OnMenuTryDown); - cursor.Emit(OpCodes.Brtrue, target); } }); - typeof(OuiModOptions).GetMethod("Update").IlHook(PreventGotoMainMenu); + typeof(OuiModOptions).GetMethod("Update").IlHook((cursor, _) => { + if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuCancel)), ins => ins.MatchCallvirt("get_Pressed"))) { + cursor.Index += 2; + cursor.Emit(OpCodes.Ldarg_0); + cursor.EmitDelegate(GetShouldGotoMainMenu); + } + }); } - private static bool OnMenuTryPageDown(TextMenu menu) { - if (CMCore.CoreModule.Settings.MenuPageDown.Pressed && menu.Current is OptionSubMenuExt submenu && !submenu.Focused && submenu.ThisPageEnterable) { + private static bool OnMenuTryPageDown(bool input, TextMenu menu) { + if (!input) { + return false; + } + if (menu.Current is OptionSubMenuExt submenu && !submenu.Focused && submenu.ThisPageEnterable) { submenu.ConfirmPressed(); if (submenu.OnPressed != null) { submenu.OnPressed(); } submenu.OnPageDown(); - return true; + return false; } - return false; + return true; } - private static bool OnMenuTryDown(TextMenu menu) { + private static bool OnMenuTryDown(bool input, TextMenu menu) { + if (!input) { + return false; + } if (Input.MenuDown.Pressed && menu.Current is OptionSubMenuExt submenu && !submenu.Focused && submenu.ThisPageEnterable) { submenu.ConfirmPressed(); if (submenu.OnPressed != null) { submenu.OnPressed(); } - return true; + return false; } - return false; - } - - private static void PreventGotoMainMenu(ILContext il) { - ILCursor cursor = new ILCursor(il); - if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuCancel)), ins => ins.MatchCallvirt("get_Pressed"))) { - cursor.Index += 2; - cursor.Emit(OpCodes.Ldarg_0); - cursor.EmitDelegate(GetShouldGotoMainMenu); - } + return true; } private static bool GetShouldGotoMainMenu(bool input, OuiModOptions oui) { diff --git a/Source/Module/Menu/TASHelperMenu.cs b/Source/Module/Menu/TASHelperMenu.cs index 8e6a902..0f7aebb 100644 --- a/Source/Module/Menu/TASHelperMenu.cs +++ b/Source/Module/Menu/TASHelperMenu.cs @@ -1,11 +1,8 @@ using Celeste.Mod.TASHelper.Gameplay; using Celeste.Mod.TASHelper.Gameplay.AutoWatchEntity; using Celeste.Mod.TASHelper.Utils; -using Celeste.Mod.UI; using Microsoft.Xna.Framework; -using Mono.Cecil.Cil; using Monocle; -using MonoMod.Cil; using System.Reflection; using static Celeste.Mod.TASHelper.Module.TASHelperSettings; using CMCore = Celeste.Mod.Core; diff --git a/Source/Module/WhatsNew.cs b/Source/Module/WhatsNew.cs index 90baa83..627d663 100644 --- a/Source/Module/WhatsNew.cs +++ b/Source/Module/WhatsNew.cs @@ -81,6 +81,7 @@ public static void CreateUpdateLog() { AddLog("2.0.8", "Change: Target CelesteTAS v3.41.0", "Feature: Auto-Watch supports more triggers."); AddLog("2.0.9", "Feature: SubMenus support Mod Options' Search Box.", "Bugfix: Predictor results are not cleared after loadstate.", "Change: Don't initialize predictor unless necessary."); // note items inside submenus can't be fetched, coz they are not items of the main menu. AddLog("2.0.10", "Bugfix: Predictor results are not cleared after re-run the tas."); + AddLog("2.0.11", "Rewrite some codes to be compatible with ghost mod."); UpdateLogs.Sort((x, y) => new Version(y.Item1).CompareTo(new Version(x.Item1))); } diff --git a/everest.yaml b/everest.yaml index 5ca9a57..13c385a 100644 --- a/everest.yaml +++ b/everest.yaml @@ -1,5 +1,5 @@ - Name: TASHelper - Version: 2.0.10 + Version: 2.0.11 DLL: bin/Release/net7.0/TASHelper.dll Dependencies: - Name: EverestCore