Skip to content

Commit

Permalink
2.0.11 release
Browse files Browse the repository at this point in the history
  • Loading branch information
LozenChen committed Nov 7, 2024
1 parent 3743839 commit 561c643
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
53 changes: 26 additions & 27 deletions Source/Module/Menu/OptionSubMenuExt.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<VirtualButton>("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<VirtualButton>("get_Pressed"))) {
cursor.Index += 2;
cursor.Emit(OpCodes.Ldarg_0);
cursor.EmitDelegate(GetShouldGotoMainMenu);
}
return true;
}

private static bool GetShouldGotoMainMenu(bool input, OuiModOptions oui) {
Expand Down
3 changes: 0 additions & 3 deletions Source/Module/Menu/TASHelperMenu.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/Module/WhatsNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down
2 changes: 1 addition & 1 deletion everest.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- Name: TASHelper
Version: 2.0.10
Version: 2.0.11
DLL: bin/Release/net7.0/TASHelper.dll
Dependencies:
- Name: EverestCore
Expand Down

0 comments on commit 561c643

Please sign in to comment.