77using UnityExplorer . Core . Config ;
88using UnityExplorer . Core . Input ;
99using UnityExplorer . UI ;
10- using BF = System . Reflection . BindingFlags ;
11-
1210
1311namespace UnityExplorer . Core . Input
1412{
@@ -168,20 +166,37 @@ public static void SetupPatches()
168166
169167 PrefixMethod ( typeof ( EventSystem ) ,
170168 "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 ) ) ) ) ;
173178 }
174179 catch ( Exception ex )
175180 {
176181 ExplorerCore . Log ( $ "Exception setting up Harmony patches:\r \n { ex . ReflectionExToString ( ) } ") ;
177182 }
178183 }
179184
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 )
181186 {
182187 try
183188 {
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 ) ;
185200 processor . AddPrefix ( prefix ) ;
186201 processor . Patch ( ) ;
187202 }
@@ -195,7 +210,7 @@ private static void PrefixPropertySetter(Type type, string property, HarmonyMeth
195210 {
196211 try
197212 {
198- var processor = ExplorerCore . Harmony . CreateProcessor ( type . GetProperty ( property ) . GetSetMethod ( ) ) ;
213+ var processor = ExplorerCore . Harmony . CreateProcessor ( type . GetProperty ( property , ReflectionUtility . FLAGS ) . GetSetMethod ( ) ) ;
199214 processor . AddPrefix ( prefix ) ;
200215 processor . Patch ( ) ;
201216 }
@@ -207,6 +222,11 @@ private static void PrefixPropertySetter(Type type, string property, HarmonyMeth
207222
208223 // Prevent setting non-UnityExplorer objects as selected when menu is open
209224
225+ public static bool Prefix_PointerInputModule_ClearSelection ( )
226+ {
227+ return ! ( UIManager . ShowMenu && UIManager . CanvasRoot ) ;
228+ }
229+
210230 public static bool Prefix_EventSystem_SetSelectedGameObject ( GameObject __0 )
211231 {
212232 if ( ! UIManager . ShowMenu || ! UIManager . CanvasRoot )
0 commit comments