@@ -12,6 +12,8 @@ public class InputSystem : IHandleInput
12
12
{
13
13
public InputSystem ( )
14
14
{
15
+ SetupSupportedDevices ( ) ;
16
+
15
17
m_kbCurrentProp = TKeyboard . GetProperty ( "current" ) ;
16
18
m_kbIndexer = TKeyboard . GetProperty ( "Item" , new Type [ ] { TKey } ) ;
17
19
@@ -32,7 +34,37 @@ public InputSystem()
32
34
. GetMethod ( "ReadValue" ) ;
33
35
}
34
36
35
- #region reflection cache
37
+ internal static void SetupSupportedDevices ( )
38
+ {
39
+ try
40
+ {
41
+ // typeof(InputSystem)
42
+ Type TInputSystem = ReflectionUtility . GetTypeByName ( "UnityEngine.InputSystem.InputSystem" ) ;
43
+ // InputSystem.settings
44
+ var settings = TInputSystem . GetProperty ( "settings" , BindingFlags . Public | BindingFlags . Static ) . GetValue ( null , null ) ;
45
+ // typeof(InputSettings)
46
+ Type TSettings = settings . GetActualType ( ) ;
47
+ // InputSettings.supportedDevices
48
+ PropertyInfo supportedProp = TSettings . GetProperty ( "supportedDevices" , BindingFlags . Public | BindingFlags . Instance ) ;
49
+ var supportedDevices = supportedProp . GetValue ( settings , null ) ;
50
+ // An empty supportedDevices list means all devices are supported.
51
+ #if CPP
52
+ // weird hack for il2cpp, use the implicit operator and cast Il2CppStringArray to ReadOnlyArray<string>
53
+ var args = new object [ ] { new UnhollowerBaseLib . Il2CppStringArray ( 0 ) } ;
54
+ var method = supportedDevices . GetActualType ( ) . GetMethod ( "op_Implicit" , BindingFlags . Static | BindingFlags . Public ) ;
55
+ supportedProp . SetValue ( settings , method . Invoke ( null , args ) , null ) ;
56
+ #else
57
+ supportedProp . SetValue ( settings , Activator . CreateInstance ( supportedDevices . GetActualType ( ) , new object [ ] { new string [ 0 ] } ) , null ) ;
58
+ #endif
59
+ }
60
+ catch ( Exception ex )
61
+ {
62
+ ExplorerCore . LogWarning ( $ "Exception setting up InputSystem.settings.supportedDevices list!") ;
63
+ ExplorerCore . Log ( ex ) ;
64
+ }
65
+ }
66
+
67
+ #region reflection cache
36
68
37
69
public static Type TKeyboard => m_tKeyboard ?? ( m_tKeyboard = ReflectionUtility . GetTypeByName ( "UnityEngine.InputSystem.Keyboard" ) ) ;
38
70
private static Type m_tKeyboard ;
@@ -73,7 +105,7 @@ public InputSystem()
73
105
private static object m_scrollInfo ;
74
106
private static PropertyInfo m_scrollDeltaProp ;
75
107
76
- #endregion
108
+ #endregion
77
109
78
110
public Vector2 MousePosition
79
111
{
@@ -138,6 +170,8 @@ internal object GetActualKey(KeyCode key)
138
170
139
171
public bool GetMouseButtonDown ( int btn )
140
172
{
173
+ if ( CurrentMouse == null )
174
+ return false ;
141
175
switch ( btn )
142
176
{
143
177
case 0 : return ( bool ) m_btnWasPressedProp . GetValue ( LeftMouseButton , null ) ;
@@ -149,6 +183,8 @@ public bool GetMouseButtonDown(int btn)
149
183
150
184
public bool GetMouseButton ( int btn )
151
185
{
186
+ if ( CurrentMouse == null )
187
+ return false ;
152
188
switch ( btn )
153
189
{
154
190
case 0 : return ( bool ) m_btnIsPressedProp . GetValue ( LeftMouseButton , null ) ;
0 commit comments