@@ -13,7 +13,7 @@ namespace Explorer
13
13
public class CppExplorer : MelonMod
14
14
{
15
15
public const string NAME = "CppExplorer" ;
16
- public const string VERSION = "1.6.8 " ;
16
+ public const string VERSION = "1.6.9 " ;
17
17
public const string AUTHOR = "Sinai" ;
18
18
public const string GUID = "com.sinai.cppexplorer" ;
19
19
@@ -24,51 +24,30 @@ public static bool ShowMenu
24
24
get => m_showMenu ;
25
25
set => SetShowMenu ( value ) ;
26
26
}
27
- private static bool m_showMenu ;
28
-
29
- public static bool ForceUnlockMouse
30
- {
31
- get => m_forceUnlock ;
32
- set => SetForceUnlock ( value ) ;
33
- }
34
- private static bool m_forceUnlock ;
35
- private static CursorLockMode m_lastLockMode ;
36
- private static bool m_lastVisibleState ;
37
- private static bool m_currentlySettingCursor = false ;
38
-
39
- public static bool ShouldForceMouse => ShowMenu && ForceUnlockMouse ;
27
+ public static bool m_showMenu ;
40
28
41
29
private static void SetShowMenu ( bool show )
42
30
{
43
31
m_showMenu = show ;
44
- UpdateCursorControl ( ) ;
45
- }
46
-
47
- private static void SetForceUnlock ( bool unlock )
48
- {
49
- m_forceUnlock = unlock ;
50
- UpdateCursorControl ( ) ;
32
+ CursorControl . UpdateCursorControl ( ) ;
51
33
}
52
34
53
35
public override void OnApplicationStart ( )
54
36
{
55
37
Instance = this ;
56
38
39
+ // First, load config
57
40
ModConfig . OnLoad ( ) ;
58
41
42
+ // Setup InputHelper class (UnityEngine.Input)
59
43
InputHelper . Init ( ) ;
60
44
45
+ // Create CppExplorer modules
61
46
new MainMenu ( ) ;
62
47
new WindowManager ( ) ;
63
48
64
- // Get current cursor state and enable cursor
65
- m_lastLockMode = Cursor . lockState ;
66
- m_lastVisibleState = Cursor . visible ;
67
-
68
- // Enable ShowMenu and ForceUnlockMouse
69
- // (set m_showMenu directly to not call UpdateCursorState twice)
70
- m_showMenu = true ;
71
- ForceUnlockMouse = true ;
49
+ // Init cursor control
50
+ CursorControl . Init ( ) ;
72
51
73
52
MelonLogger . Log ( $ "CppExplorer { VERSION } initialized.") ;
74
53
}
@@ -89,109 +68,26 @@ public override void OnUpdate()
89
68
90
69
if ( ShowMenu )
91
70
{
92
- // Check Force-Unlock input
93
- if ( InputHelper . GetKeyDown ( KeyCode . LeftAlt ) )
94
- {
95
- ForceUnlockMouse = ! ForceUnlockMouse ;
96
- }
71
+ CursorControl . Update ( ) ;
72
+ InspectUnderMouse . Update ( ) ;
97
73
98
74
MainMenu . Instance . Update ( ) ;
99
75
WindowManager . Instance . Update ( ) ;
100
- InspectUnderMouse . Update ( ) ;
101
76
}
102
77
}
103
78
104
79
public override void OnGUI ( )
105
80
{
106
81
if ( ! ShowMenu ) return ;
107
82
83
+ var origSkin = GUI . skin ;
84
+ GUI . skin = UIStyles . WindowSkin ;
85
+
108
86
MainMenu . Instance . OnGUI ( ) ;
109
87
WindowManager . Instance . OnGUI ( ) ;
110
88
InspectUnderMouse . OnGUI ( ) ;
111
- }
112
-
113
- private static void UpdateCursorControl ( )
114
- {
115
- m_currentlySettingCursor = true ;
116
- if ( ShouldForceMouse )
117
- {
118
- Cursor . lockState = CursorLockMode . None ;
119
- Cursor . visible = true ;
120
- }
121
- else
122
- {
123
- Cursor . lockState = m_lastLockMode ;
124
- Cursor . visible = m_lastVisibleState ;
125
- }
126
- m_currentlySettingCursor = false ;
127
- }
128
-
129
- // Force mouse to stay unlocked and visible while UnlockMouse and ShowMenu are true.
130
- // Also keep track of when anything else tries to set Cursor state, this will be the
131
- // value that we set back to when we close the menu or disable force-unlock.
132
89
133
- [ HarmonyPatch ( typeof ( Cursor ) , nameof ( Cursor . lockState ) , MethodType . Setter ) ]
134
- public class Cursor_set_lockState
135
- {
136
- [ HarmonyPrefix ]
137
- public static void Prefix ( ref CursorLockMode value )
138
- {
139
- if ( ! m_currentlySettingCursor )
140
- {
141
- m_lastLockMode = value ;
142
-
143
- if ( ShouldForceMouse )
144
- {
145
- value = CursorLockMode . None ;
146
- }
147
- }
148
- }
149
- }
150
-
151
- [ HarmonyPatch ( typeof ( Cursor ) , nameof ( Cursor . visible ) , MethodType . Setter ) ]
152
- public class Cursor_set_visible
153
- {
154
- [ HarmonyPrefix ]
155
- public static void Prefix ( ref bool value )
156
- {
157
- if ( ! m_currentlySettingCursor )
158
- {
159
- m_lastVisibleState = value ;
160
-
161
- if ( ShouldForceMouse )
162
- {
163
- value = true ;
164
- }
165
- }
166
- }
167
- }
168
-
169
- // Make it appear as though UnlockMouse is disabled to the rest of the application.
170
-
171
- [ HarmonyPatch ( typeof ( Cursor ) , nameof ( Cursor . lockState ) , MethodType . Getter ) ]
172
- public class Cursor_get_lockState
173
- {
174
- [ HarmonyPostfix ]
175
- public static void Postfix ( ref CursorLockMode __result )
176
- {
177
- if ( ShouldForceMouse )
178
- {
179
- __result = m_lastLockMode ;
180
- }
181
- }
182
- }
183
-
184
- [ HarmonyPatch ( typeof ( Cursor ) , nameof ( Cursor . visible ) , MethodType . Getter ) ]
185
- public class Cursor_get_visible
186
- {
187
- [ HarmonyPostfix ]
188
- public static void Postfix ( ref bool __result )
189
- {
190
- if ( ShouldForceMouse )
191
- {
192
- __result = m_lastVisibleState ;
193
- }
194
- }
90
+ GUI . skin = origSkin ;
195
91
}
196
92
}
197
93
}
0 commit comments