|
1 | 1 | using Celeste.Mod.Core;
|
2 | 2 | using Celeste.Mod.TASHelper.Utils;
|
| 3 | +using Celeste.Mod.UI; |
3 | 4 | using Microsoft.Xna.Framework;
|
4 | 5 | using Mono.Cecil.Cil;
|
5 | 6 | using Monocle;
|
6 | 7 | using MonoMod.Cil;
|
7 |
| -using Celeste.Mod.UI; |
8 | 8 | using CMCore = Celeste.Mod.Core;
|
9 | 9 | namespace Celeste.Mod.TASHelper.Module.Menu;
|
10 | 10 |
|
@@ -523,63 +523,62 @@ private static void DrawIcon(Vector2 position, MTexture icon, Vector2 justify, b
|
523 | 523 | }
|
524 | 524 | }
|
525 | 525 |
|
526 |
| - [Initialize] |
| 526 | + [Initialize] |
527 | 527 | private static void InitializeHook() {
|
528 | 528 | typeof(TextMenu).GetMethod("Update").IlHook((cursor, _) => {
|
529 |
| - if (cursor.TryGotoNext(ins => ins.OpCode == OpCodes.Call, ins => ins.MatchCallvirt(typeof(CoreModuleSettings), "get_MenuPageDown"), ins => true, ins => ins.OpCode == OpCodes.Brfalse)) { |
530 |
| - ILLabel target = (ILLabel)cursor.Next.Next.Next.Next.Operand; |
531 |
| - cursor.MoveAfterLabels(); |
| 529 | + if (cursor.TryGotoNext(ins => ins.OpCode == OpCodes.Call, ins => ins.MatchCallvirt(typeof(CoreModuleSettings), "get_MenuPageDown"), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"))) { |
| 530 | + cursor.Index += 3; |
532 | 531 | cursor.Emit(OpCodes.Ldarg_0);
|
533 | 532 | cursor.EmitDelegate(OnMenuTryPageDown);
|
534 |
| - cursor.Emit(OpCodes.Brtrue, target); |
535 | 533 | }
|
536 | 534 | });
|
537 | 535 |
|
538 | 536 |
|
539 | 537 | typeof(TextMenu).GetMethod("orig_Update").IlHook((cursor, _) => {
|
540 |
| - if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuDown)), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"), ins => ins.OpCode == OpCodes.Brfalse_S)) { |
541 |
| - ILLabel target = (ILLabel)cursor.Next.Next.Next.Operand; |
542 |
| - cursor.MoveAfterLabels(); |
| 538 | + if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuDown)), ins => ins.MatchCallvirt(typeof(VirtualButton), "get_Pressed"))) { |
| 539 | + cursor.Index += 2; |
543 | 540 | cursor.Emit(OpCodes.Ldarg_0);
|
544 | 541 | cursor.EmitDelegate(OnMenuTryDown);
|
545 |
| - cursor.Emit(OpCodes.Brtrue, target); |
546 | 542 | }
|
547 | 543 | });
|
548 | 544 |
|
549 |
| - typeof(OuiModOptions).GetMethod("Update").IlHook(PreventGotoMainMenu); |
| 545 | + typeof(OuiModOptions).GetMethod("Update").IlHook((cursor, _) => { |
| 546 | + if (cursor.TryGotoNext(ins => ins.MatchLdsfld(typeof(Input), nameof(Input.MenuCancel)), ins => ins.MatchCallvirt<VirtualButton>("get_Pressed"))) { |
| 547 | + cursor.Index += 2; |
| 548 | + cursor.Emit(OpCodes.Ldarg_0); |
| 549 | + cursor.EmitDelegate(GetShouldGotoMainMenu); |
| 550 | + } |
| 551 | + }); |
550 | 552 | }
|
551 | 553 |
|
552 |
| - private static bool OnMenuTryPageDown(TextMenu menu) { |
553 |
| - if (CMCore.CoreModule.Settings.MenuPageDown.Pressed && menu.Current is OptionSubMenuExt submenu && !submenu.Focused && submenu.ThisPageEnterable) { |
| 554 | + private static bool OnMenuTryPageDown(bool input, TextMenu menu) { |
| 555 | + if (!input) { |
| 556 | + return false; |
| 557 | + } |
| 558 | + if (menu.Current is OptionSubMenuExt submenu && !submenu.Focused && submenu.ThisPageEnterable) { |
554 | 559 | submenu.ConfirmPressed();
|
555 | 560 | if (submenu.OnPressed != null) {
|
556 | 561 | submenu.OnPressed();
|
557 | 562 | }
|
558 | 563 | submenu.OnPageDown();
|
559 |
| - return true; |
| 564 | + return false; |
560 | 565 | }
|
561 |
| - return false; |
| 566 | + return true; |
562 | 567 | }
|
563 | 568 |
|
564 | 569 |
|
565 |
| - private static bool OnMenuTryDown(TextMenu menu) { |
| 570 | + private static bool OnMenuTryDown(bool input, TextMenu menu) { |
| 571 | + if (!input) { |
| 572 | + return false; |
| 573 | + } |
566 | 574 | if (Input.MenuDown.Pressed && menu.Current is OptionSubMenuExt submenu && !submenu.Focused && submenu.ThisPageEnterable) {
|
567 | 575 | submenu.ConfirmPressed();
|
568 | 576 | if (submenu.OnPressed != null) {
|
569 | 577 | submenu.OnPressed();
|
570 | 578 | }
|
571 |
| - return true; |
| 579 | + return false; |
572 | 580 | }
|
573 |
| - 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 |
| - } |
| 581 | + return true; |
583 | 582 | }
|
584 | 583 |
|
585 | 584 | private static bool GetShouldGotoMainMenu(bool input, OuiModOptions oui) {
|
|
0 commit comments