Skip to content

Commit 3743839

Browse files
committed
re-impl prevent options submenu go to main menu
fix that accidentally use SRT utils
1 parent 1aa846a commit 3743839

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

Source/Module/Menu/OptionSubMenuExt.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using Celeste.Mod.Core;
2-
using Celeste.Mod.SpeedrunTool.Utils;
2+
using Celeste.Mod.TASHelper.Utils;
33
using Microsoft.Xna.Framework;
44
using Mono.Cecil.Cil;
55
using Monocle;
6-
using MonoMod.Cil;
6+
using MonoMod.Cil;
7+
using Celeste.Mod.UI;
78
using CMCore = Celeste.Mod.Core;
89
namespace Celeste.Mod.TASHelper.Module.Menu;
910

@@ -524,7 +525,7 @@ private static void DrawIcon(Vector2 position, MTexture icon, Vector2 justify, b
524525

525526
[Initialize]
526527
private static void InitializeHook() {
527-
typeof(TextMenu).GetMethod("Update").ILHook((cursor, _) => {
528+
typeof(TextMenu).GetMethod("Update").IlHook((cursor, _) => {
528529
if (cursor.TryGotoNext(ins => ins.OpCode == OpCodes.Call, ins => ins.MatchCallvirt(typeof(CoreModuleSettings), "get_MenuPageDown"), ins => true, ins => ins.OpCode == OpCodes.Brfalse)) {
529530
ILLabel target = (ILLabel)cursor.Next.Next.Next.Next.Operand;
530531
cursor.MoveAfterLabels();
@@ -535,15 +536,17 @@ private static void InitializeHook() {
535536
});
536537

537538

538-
typeof(TextMenu).GetMethod("orig_Update").ILHook((cursor, _) => {
539+
typeof(TextMenu).GetMethod("orig_Update").IlHook((cursor, _) => {
539540
if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuDown)), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"), ins => ins.OpCode == OpCodes.Brfalse_S)) {
540541
ILLabel target = (ILLabel)cursor.Next.Next.Next.Operand;
541542
cursor.MoveAfterLabels();
542543
cursor.Emit(OpCodes.Ldarg_0);
543544
cursor.EmitDelegate(OnMenuTryDown);
544545
cursor.Emit(OpCodes.Brtrue, target);
545546
}
546-
});
547+
});
548+
549+
typeof(OuiModOptions).GetMethod("Update").IlHook(PreventGotoMainMenu);
547550
}
548551

549552
private static bool OnMenuTryPageDown(TextMenu menu) {
@@ -568,6 +571,25 @@ private static bool OnMenuTryDown(TextMenu menu) {
568571
return true;
569572
}
570573
return false;
574+
}
575+
576+
private static void PreventGotoMainMenu(ILContext il) {
577+
ILCursor cursor = new ILCursor(il);
578+
if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuCancel)), ins => ins.MatchCallvirt<VirtualButton>("get_Pressed"))) {
579+
cursor.Index += 2;
580+
cursor.Emit(OpCodes.Ldarg_0);
581+
cursor.EmitDelegate(GetShouldGotoMainMenu);
582+
}
583+
}
584+
585+
private static bool GetShouldGotoMainMenu(bool input, OuiModOptions oui) {
586+
if (!input) {
587+
return false;
588+
}
589+
if (oui?.menu?.Current is OptionSubMenuExt subMenu && subMenu.Visible && subMenu.MenuIndex != 0) {
590+
return false;
591+
}
592+
return true;
571593
}
572594
}
573595

Source/Module/Menu/TASHelperMenu.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -462,39 +462,13 @@ public override void Update() {
462462
}
463463

464464
Visible = alpha != 0;
465-
466-
shouldGotoMainMenu &= !Visible || MenuIndex == 0;
467465
}
468466
public override void Render(Vector2 position, bool highlighted) {
469467
float c = Container.Alpha;
470468
Container.Alpha = alpha;
471469
base.Render(position, highlighted);
472470
Container.Alpha = c;
473471
}
474-
475-
[Initialize]
476-
477-
private static void InitializeHook() {
478-
typeof(OuiModOptions).GetMethod("Update").IlHook(PreventGotoMainMenu);
479-
}
480-
481-
private static void PreventGotoMainMenu(ILContext il) {
482-
ILCursor cursor = new ILCursor(il);
483-
if (cursor.TryGotoNext(ins => ins.OpCode == OpCodes.Brfalse_S)) {
484-
ILLabel label = (ILLabel)cursor.Next.Operand;
485-
cursor.Index -= 2;
486-
cursor.EmitDelegate(GetShouldGotoMainMenu);
487-
cursor.Emit(OpCodes.Brfalse, label);
488-
}
489-
}
490-
491-
private static bool shouldGotoMainMenu = true;
492-
493-
private static bool GetShouldGotoMainMenu() {
494-
bool result = shouldGotoMainMenu;
495-
shouldGotoMainMenu = true;
496-
return result;
497-
}
498472
}
499473

500474

0 commit comments

Comments
 (0)