1
1
using Celeste . Mod . Core ;
2
- using Celeste . Mod . SpeedrunTool . Utils ;
2
+ using Celeste . Mod . TASHelper . Utils ;
3
3
using Microsoft . Xna . Framework ;
4
4
using Mono . Cecil . Cil ;
5
5
using Monocle ;
6
- using MonoMod . Cil ;
6
+ using MonoMod . Cil ;
7
+ using Celeste . Mod . UI ;
7
8
using CMCore = Celeste . Mod . Core ;
8
9
namespace Celeste . Mod . TASHelper . Module . Menu ;
9
10
@@ -524,7 +525,7 @@ private static void DrawIcon(Vector2 position, MTexture icon, Vector2 justify, b
524
525
525
526
[ Initialize ]
526
527
private static void InitializeHook ( ) {
527
- typeof ( TextMenu ) . GetMethod ( "Update" ) . ILHook ( ( cursor , _ ) => {
528
+ typeof ( TextMenu ) . GetMethod ( "Update" ) . IlHook ( ( cursor , _ ) => {
528
529
if ( cursor . TryGotoNext ( ins => ins . OpCode == OpCodes . Call , ins => ins . MatchCallvirt ( typeof ( CoreModuleSettings ) , "get_MenuPageDown" ) , ins => true , ins => ins . OpCode == OpCodes . Brfalse ) ) {
529
530
ILLabel target = ( ILLabel ) cursor . Next . Next . Next . Next . Operand ;
530
531
cursor . MoveAfterLabels ( ) ;
@@ -535,15 +536,17 @@ private static void InitializeHook() {
535
536
} ) ;
536
537
537
538
538
- typeof ( TextMenu ) . GetMethod ( "orig_Update" ) . ILHook ( ( cursor , _ ) => {
539
+ typeof ( TextMenu ) . GetMethod ( "orig_Update" ) . IlHook ( ( cursor , _ ) => {
539
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 ) ) {
540
541
ILLabel target = ( ILLabel ) cursor . Next . Next . Next . Operand ;
541
542
cursor . MoveAfterLabels ( ) ;
542
543
cursor . Emit ( OpCodes . Ldarg_0 ) ;
543
544
cursor . EmitDelegate ( OnMenuTryDown ) ;
544
545
cursor . Emit ( OpCodes . Brtrue , target ) ;
545
546
}
546
- } ) ;
547
+ } ) ;
548
+
549
+ typeof ( OuiModOptions ) . GetMethod ( "Update" ) . IlHook ( PreventGotoMainMenu ) ;
547
550
}
548
551
549
552
private static bool OnMenuTryPageDown ( TextMenu menu ) {
@@ -568,6 +571,25 @@ private static bool OnMenuTryDown(TextMenu menu) {
568
571
return true ;
569
572
}
570
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
+ }
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 ;
571
593
}
572
594
}
573
595
0 commit comments