7
7
using UnityExplorer . Core . Config ;
8
8
using UnityExplorer . Core . Input ;
9
9
using UnityExplorer . UI ;
10
- using BF = System . Reflection . BindingFlags ;
11
-
12
10
13
11
namespace UnityExplorer . Core . Input
14
12
{
@@ -168,20 +166,37 @@ public static void SetupPatches()
168
166
169
167
PrefixMethod ( typeof ( EventSystem ) ,
170
168
"SetSelectedGameObject" ,
171
- new Type [ ] { typeof ( GameObject ) , typeof ( BaseEventData ) , typeof ( int ) } ,
172
- new HarmonyMethod ( typeof ( CursorUnlocker ) . GetMethod ( nameof ( CursorUnlocker . Prefix_EventSystem_SetSelectedGameObject ) ) ) ) ;
169
+ new Type [ ] { typeof ( GameObject ) , typeof ( BaseEventData ) } ,
170
+ new HarmonyMethod ( typeof ( CursorUnlocker ) . GetMethod ( nameof ( CursorUnlocker . Prefix_EventSystem_SetSelectedGameObject ) ) ) ,
171
+ new Type [ ] { typeof ( GameObject ) , typeof ( BaseEventData ) , typeof ( int ) } ) ;
172
+ // some games use a modified version of uGUI that includes this extra int argument on this method.
173
+
174
+ PrefixMethod ( typeof ( PointerInputModule ) ,
175
+ "ClearSelection" ,
176
+ new Type [ ] { } ,
177
+ new HarmonyMethod ( typeof ( CursorUnlocker ) . GetMethod ( nameof ( CursorUnlocker . Prefix_PointerInputModule_ClearSelection ) ) ) ) ;
173
178
}
174
179
catch ( Exception ex )
175
180
{
176
181
ExplorerCore . Log ( $ "Exception setting up Harmony patches:\r \n { ex . ReflectionExToString ( ) } ") ;
177
182
}
178
183
}
179
184
180
- private static void PrefixMethod ( Type type , string method , Type [ ] arguments , HarmonyMethod prefix )
185
+ private static void PrefixMethod ( Type type , string method , Type [ ] arguments , HarmonyMethod prefix , Type [ ] backupArgs = null )
181
186
{
182
187
try
183
188
{
184
- var processor = ExplorerCore . Harmony . CreateProcessor ( type . GetMethod ( method , arguments ) ) ;
189
+ var methodInfo = type . GetMethod ( method , ReflectionUtility . FLAGS , null , arguments , null ) ;
190
+ if ( methodInfo == null )
191
+ {
192
+ if ( backupArgs != null )
193
+ methodInfo = type . GetMethod ( method , ReflectionUtility . FLAGS , null , backupArgs , null ) ;
194
+
195
+ if ( methodInfo == null )
196
+ throw new MissingMethodException ( $ "Could not find method for patching - '{ type . FullName } .{ method } '!") ;
197
+ }
198
+
199
+ var processor = ExplorerCore . Harmony . CreateProcessor ( methodInfo ) ;
185
200
processor . AddPrefix ( prefix ) ;
186
201
processor . Patch ( ) ;
187
202
}
@@ -195,7 +210,7 @@ private static void PrefixPropertySetter(Type type, string property, HarmonyMeth
195
210
{
196
211
try
197
212
{
198
- var processor = ExplorerCore . Harmony . CreateProcessor ( type . GetProperty ( property ) . GetSetMethod ( ) ) ;
213
+ var processor = ExplorerCore . Harmony . CreateProcessor ( type . GetProperty ( property , ReflectionUtility . FLAGS ) . GetSetMethod ( ) ) ;
199
214
processor . AddPrefix ( prefix ) ;
200
215
processor . Patch ( ) ;
201
216
}
@@ -207,6 +222,11 @@ private static void PrefixPropertySetter(Type type, string property, HarmonyMeth
207
222
208
223
// Prevent setting non-UnityExplorer objects as selected when menu is open
209
224
225
+ public static bool Prefix_PointerInputModule_ClearSelection ( )
226
+ {
227
+ return ! ( UIManager . ShowMenu && UIManager . CanvasRoot ) ;
228
+ }
229
+
210
230
public static bool Prefix_EventSystem_SetSelectedGameObject ( GameObject __0 )
211
231
{
212
232
if ( ! UIManager . ShowMenu || ! UIManager . CanvasRoot )
0 commit comments