@@ -26,18 +26,16 @@ public static bool Unlock
26
26
27
27
public static bool ShouldActuallyUnlock => UIManager . ShowMenu && Unlock ;
28
28
29
- private static CursorLockMode m_lastLockMode ;
30
- private static bool m_lastVisibleState ;
29
+ private static CursorLockMode lastLockMode ;
30
+ private static bool lastVisibleState ;
31
31
32
- private static bool m_currentlySettingCursor = false ;
33
-
34
- private static Type CursorType
35
- => m_cursorType
36
- ?? ( m_cursorType = ReflectionUtility . GetTypeByName ( "UnityEngine.Cursor" ) ) ;
37
- private static Type m_cursorType ;
32
+ private static bool currentlySettingCursor = false ;
38
33
39
34
public static void Init ( )
40
35
{
36
+ lastLockMode = Cursor . lockState ;
37
+ lastVisibleState = Cursor . visible ;
38
+
41
39
SetupPatches ( ) ;
42
40
43
41
UpdateCursorControl ( ) ;
@@ -78,7 +76,7 @@ public static void UpdateCursorControl()
78
76
{
79
77
try
80
78
{
81
- m_currentlySettingCursor = true ;
79
+ currentlySettingCursor = true ;
82
80
83
81
if ( ShouldActuallyUnlock )
84
82
{
@@ -90,14 +88,14 @@ public static void UpdateCursorControl()
90
88
}
91
89
else
92
90
{
93
- Cursor . lockState = m_lastLockMode ;
94
- Cursor . visible = m_lastVisibleState ;
91
+ Cursor . lockState = lastLockMode ;
92
+ Cursor . visible = lastVisibleState ;
95
93
96
94
if ( UIManager . EventSys )
97
95
ReleaseEventSystem ( ) ;
98
96
}
99
97
100
- m_currentlySettingCursor = false ;
98
+ currentlySettingCursor = false ;
101
99
}
102
100
catch ( Exception e )
103
101
{
@@ -107,9 +105,9 @@ public static void UpdateCursorControl()
107
105
108
106
// Event system overrides
109
107
110
- private static bool m_settingEventSystem ;
111
- private static EventSystem m_lastEventSystem ;
112
- private static BaseInputModule m_lastInputModule ;
108
+ private static bool settingEventSystem ;
109
+ private static EventSystem lastEventSystem ;
110
+ private static BaseInputModule lastInputModule ;
113
111
114
112
public static void SetEventSystem ( )
115
113
{
@@ -118,31 +116,31 @@ public static void SetEventSystem()
118
116
119
117
if ( EventSystem . current && EventSystem . current != UIManager . EventSys )
120
118
{
121
- m_lastEventSystem = EventSystem . current ;
122
- m_lastEventSystem . enabled = false ;
119
+ lastEventSystem = EventSystem . current ;
120
+ lastEventSystem . enabled = false ;
123
121
}
124
122
125
123
// Set to our current system
126
- m_settingEventSystem = true ;
124
+ settingEventSystem = true ;
127
125
UIManager . EventSys . enabled = true ;
128
126
EventSystem . current = UIManager . EventSys ;
129
127
InputManager . ActivateUIModule ( ) ;
130
- m_settingEventSystem = false ;
128
+ settingEventSystem = false ;
131
129
}
132
130
133
131
public static void ReleaseEventSystem ( )
134
132
{
135
133
if ( InputManager . CurrentType == InputType . InputSystem )
136
134
return ;
137
135
138
- if ( m_lastEventSystem && m_lastEventSystem . gameObject . activeSelf )
136
+ if ( lastEventSystem && lastEventSystem . gameObject . activeSelf )
139
137
{
140
- m_lastEventSystem . enabled = true ;
138
+ lastEventSystem . enabled = true ;
141
139
142
- m_settingEventSystem = true ;
143
- EventSystem . current = m_lastEventSystem ;
144
- m_lastInputModule ? . ActivateModule ( ) ;
145
- m_settingEventSystem = false ;
140
+ settingEventSystem = true ;
141
+ EventSystem . current = lastEventSystem ;
142
+ lastInputModule ? . ActivateModule ( ) ;
143
+ settingEventSystem = false ;
146
144
}
147
145
}
148
146
@@ -152,30 +150,20 @@ private static void SetupPatches()
152
150
{
153
151
try
154
152
{
155
- if ( CursorType == null )
156
- throw new Exception ( "Could not load Type 'UnityEngine.Cursor'!" ) ;
157
-
158
- // Get current cursor state and enable cursor
159
- m_lastLockMode = ( CursorLockMode ? ) CursorType . GetProperty ( "lockState" , BF . Public | BF . Static ) ? . GetValue ( null , null )
160
- ?? CursorLockMode . None ;
161
-
162
- m_lastVisibleState = ( bool ? ) CursorType . GetProperty ( "visible" , BF . Public | BF . Static ) ? . GetValue ( null , null )
163
- ?? false ;
164
-
165
153
ExplorerCore . Loader . SetupCursorPatches ( ) ;
166
154
}
167
155
catch ( Exception e )
168
156
{
169
- ExplorerCore . Log ( $ "Error on CursorUnlocker.Init! { e . GetType ( ) } , { e . Message } ") ;
157
+ ExplorerCore . Log ( $ "Exception setting up Cursor patches: { e . GetType ( ) } , { e . Message } ") ;
170
158
}
171
159
}
172
160
173
161
public static void Prefix_EventSystem_set_current ( ref EventSystem value )
174
162
{
175
- if ( ! m_settingEventSystem && value != UIManager . EventSys )
163
+ if ( ! settingEventSystem && value != UIManager . EventSys )
176
164
{
177
- m_lastEventSystem = value ;
178
- m_lastInputModule = value ? . currentInputModule ;
165
+ lastEventSystem = value ;
166
+ lastInputModule = value ? . currentInputModule ;
179
167
180
168
if ( ShouldActuallyUnlock )
181
169
{
@@ -191,9 +179,9 @@ public static void Prefix_EventSystem_set_current(ref EventSystem value)
191
179
192
180
public static void Prefix_set_lockState ( ref CursorLockMode value )
193
181
{
194
- if ( ! m_currentlySettingCursor )
182
+ if ( ! currentlySettingCursor )
195
183
{
196
- m_lastLockMode = value ;
184
+ lastLockMode = value ;
197
185
198
186
if ( ShouldActuallyUnlock )
199
187
value = CursorLockMode . None ;
@@ -202,9 +190,9 @@ public static void Prefix_set_lockState(ref CursorLockMode value)
202
190
203
191
public static void Prefix_set_visible ( ref bool value )
204
192
{
205
- if ( ! m_currentlySettingCursor )
193
+ if ( ! currentlySettingCursor )
206
194
{
207
- m_lastVisibleState = value ;
195
+ lastVisibleState = value ;
208
196
209
197
if ( ShouldActuallyUnlock )
210
198
value = true ;
0 commit comments