1+ using System . Collections . Generic ;
12using System . Reflection ;
23using AMDaemon ;
34using AquaMai . Config . Attributes ;
@@ -24,7 +25,7 @@ DebugInput 与 IO4(兼容 IO4 板 / segatools IO4 模拟)独立工作。
2425public class KeyMap
2526{
2627 [ ConfigEntry (
27- name : "禁用 IO4" ,
28+ name : "禁用 IO4(1P) " ,
2829 en : """
2930 Disable IO4 (IO4-compatible board / segatools IO4 emulation) input.
3031 With IO4 input disabled, your IO4-compatible board or segatools IO4 emulation is ignored.
@@ -33,7 +34,19 @@ Disable IO4 (IO4-compatible board / segatools IO4 emulation) input.
3334 禁用 IO4(兼容 IO4 板 / segatools IO4 模拟)输入。
3435 在禁用 IO4 输入后,你的兼容 IO4 板或 segatools IO4 模拟将被忽略。
3536 """ ) ]
36- private static readonly bool disableIO4 = false ;
37+ private static readonly bool disableIO4_1P = false ;
38+ [ ConfigEntry ( "禁用 IO4(2P)" ) ]
39+ private static readonly bool disableIO4_2P = false ;
40+
41+ [ ConfigEntry (
42+ name : "禁用 IO4(系统按键)" ,
43+ en : """
44+ System buttons (test, service) input.
45+ """ ,
46+ zh : """
47+ 禁用系统按键的 IO4 输入,输入源同上。
48+ """ ) ]
49+ private static readonly bool disableIO4System = false ;
3750
3851 [ ConfigEntry (
3952 name : "禁用 DebugInput" ,
@@ -59,30 +72,45 @@ 禁用 DebugFeature Polyfill 的快捷键,比如说回车暂停,左右键快
5972 """ ) ]
6073 public static readonly bool disableDebugFeatureHotkeys = false ; // Implemented in DebugFeature
6174
62- [ EnableIf ( nameof ( disableIO4 ) ) ]
75+ private static bool DisableIO4 => disableIO4_1P || disableIO4_2P || disableIO4System ;
76+ private static List < SwitchInput > disabledSwitchInputs = [ ] ;
77+
78+ [ EnableIf ( nameof ( DisableIO4 ) ) ]
6379 [ HarmonyPatch ( "IO.Jvs+JvsSwitch" , ".ctor" , MethodType . Constructor , [ typeof ( int ) , typeof ( string ) , typeof ( KeyCode ) , typeof ( bool ) , typeof ( bool ) ] ) ]
64- [ HarmonyPrefix ]
65- public static void PreJvsSwitchConstructor ( ref bool invert )
80+ [ HarmonyPostfix ]
81+ public static void PostJvsSwitchConstructor ( ref bool ____invert , int playerNo , bool systemButton , SwitchInput ____switchInput )
6682 {
67- invert = false ;
83+ if ( ( systemButton && disableIO4System ) || ( playerNo == 0 && disableIO4_1P ) || ( playerNo == 1 && disableIO4_2P ) )
84+ {
85+ ____invert = false ;
86+ disabledSwitchInputs . Add ( ____switchInput ) ;
87+ }
6888 }
6989
70- [ EnableIf ( nameof ( disableIO4 ) ) ]
71- [ HarmonyPatch ( typeof ( SwitchInput ) , "get_IsOn" ) ]
90+ [ EnableIf ( nameof ( DisableIO4 ) ) ]
91+ [ HarmonyPatch ( typeof ( SwitchInput ) , nameof ( SwitchInput . IsOn ) , MethodType . Getter ) ]
7292 [ HarmonyPrefix ]
73- public static bool PreGetIsOn ( ref bool __result )
93+ public static bool PreGetIsOn ( ref bool __result , SwitchInput __instance )
7494 {
75- __result = false ;
76- return false ;
95+ if ( disabledSwitchInputs . Contains ( __instance ) )
96+ {
97+ __result = false ;
98+ return false ;
99+ }
100+ return true ;
77101 }
78102
79- [ EnableIf ( nameof ( disableIO4 ) ) ]
80- [ HarmonyPatch ( typeof ( SwitchInput ) , "get_HasOnNow" ) ]
103+ [ EnableIf ( nameof ( DisableIO4 ) ) ]
104+ [ HarmonyPatch ( typeof ( SwitchInput ) , nameof ( SwitchInput . HasOnNow ) , MethodType . Getter ) ]
81105 [ HarmonyPrefix ]
82- public static bool PreGetHasOnNow ( ref bool __result )
106+ public static bool PreGetHasOnNow ( ref bool __result , SwitchInput __instance )
83107 {
84- __result = false ;
85- return false ;
108+ if ( disabledSwitchInputs . Contains ( __instance ) )
109+ {
110+ __result = false ;
111+ return false ;
112+ }
113+ return true ;
86114 }
87115
88116 [ ConfigEntry ]
0 commit comments