@@ -22,6 +22,8 @@ public class SearchPage : WindowPage
22
22
private string m_typeInput = "" ;
23
23
private int m_limit = 100 ;
24
24
private int m_pageOffset = 0 ;
25
+ private List < object > m_searchResults = new List < object > ( ) ;
26
+ private Vector2 resultsScroll = Vector2 . zero ;
25
27
26
28
public SceneFilter SceneMode = SceneFilter . Any ;
27
29
public TypeFilter TypeMode = TypeFilter . Object ;
@@ -42,9 +44,6 @@ public enum TypeFilter
42
44
Custom
43
45
}
44
46
45
- private List < object > m_searchResults = new List < object > ( ) ;
46
- private Vector2 resultsScroll = Vector2 . zero ;
47
-
48
47
public override void Init ( )
49
48
{
50
49
Instance = this ;
@@ -114,7 +113,7 @@ public override void DrawWindow()
114
113
int offset = m_pageOffset * CppExplorer . ArrayLimit ;
115
114
int preiterated = 0 ;
116
115
117
- if ( offset >= count ) offset = 0 ;
116
+ if ( offset >= count ) m_pageOffset = 0 ;
118
117
119
118
for ( int i = 0 ; i < m_searchResults . Count ; i ++ )
120
119
{
@@ -246,51 +245,13 @@ private void SceneFilterToggle(SceneFilter mode, string label, float width)
246
245
}
247
246
248
247
249
- // -------------- ACTUAL METHODS (not Gui draw) ----------------- //
250
-
251
- // credit: ManlyMarco (RuntimeUnityEditor)
252
- public static IEnumerable < object > GetInstanceClassScanner ( )
253
- {
254
- var query = AppDomain . CurrentDomain . GetAssemblies ( )
255
- . Where ( x => ! x . FullName . StartsWith ( "Mono" ) )
256
- . SelectMany ( GetTypesSafe )
257
- . Where ( t => t . IsClass && ! t . IsAbstract && ! t . ContainsGenericParameters ) ;
258
-
259
- foreach ( var type in query )
260
- {
261
- object obj = null ;
262
- try
263
- {
264
- obj = type . GetProperty ( "Instance" , BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ? . GetValue ( null , null ) ;
265
- }
266
- catch
267
- {
268
- try
269
- {
270
- obj = type . GetField ( "Instance" , BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ? . GetValue ( null ) ;
271
- }
272
- catch
273
- {
274
- }
275
- }
276
- if ( obj != null && ! obj . ToString ( ) . StartsWith ( "Mono" ) )
277
- {
278
- yield return obj ;
279
- }
280
- }
281
- }
282
-
283
- public static IEnumerable < Type > GetTypesSafe ( Assembly asm )
284
- {
285
- try { return asm . GetTypes ( ) ; }
286
- catch ( ReflectionTypeLoadException e ) { return e . Types . Where ( x => x != null ) ; }
287
- catch { return Enumerable . Empty < Type > ( ) ; }
288
- }
248
+ // -------------- ACTUAL METHODS (not Gui draw) ----------------- //
289
249
290
250
// ======= search functions =======
291
251
292
252
private void Search ( )
293
253
{
254
+ m_pageOffset = 0 ;
294
255
m_searchResults = FindAllObjectsOfType ( m_searchInput , m_typeInput ) ;
295
256
}
296
257
@@ -312,73 +273,37 @@ private List<object> FindAllObjectsOfType(string _search, string _type)
312
273
}
313
274
else if ( TypeMode == TypeFilter . Object )
314
275
{
315
- type = Il2CppType . Of < Object > ( ) ;
276
+ type = CppExplorer . ObjectType ;
316
277
}
317
278
else if ( TypeMode == TypeFilter . GameObject )
318
279
{
319
- type = Il2CppType . Of < GameObject > ( ) ;
280
+ type = CppExplorer . GameObjectType ;
320
281
}
321
282
else if ( TypeMode == TypeFilter . Component )
322
283
{
323
- type = Il2CppType . Of < Component > ( ) ;
284
+ type = CppExplorer . ComponentType ;
324
285
}
325
286
326
- if ( ! Il2CppType . Of < Object > ( ) . IsAssignableFrom ( type ) )
287
+ if ( ! CppExplorer . ObjectType . IsAssignableFrom ( type ) )
327
288
{
328
289
MelonLogger . LogError ( "Your Class Type must inherit from UnityEngine.Object! Leave blank to default to UnityEngine.Object" ) ;
329
290
return new List < object > ( ) ;
330
291
}
331
292
332
293
var matches = new List < object > ( ) ;
333
294
334
- foreach ( var obj in Resources . FindObjectsOfTypeAll ( type ) )
295
+ var allObjectsOfType = Resources . FindObjectsOfTypeAll ( type ) ;
296
+
297
+ foreach ( var obj in allObjectsOfType )
335
298
{
336
299
if ( _search != "" && ! obj . name . ToLower ( ) . Contains ( _search . ToLower ( ) ) )
337
300
{
338
301
continue ;
339
302
}
340
303
341
- if ( SceneMode != SceneFilter . Any )
304
+ if ( SceneMode != SceneFilter . Any && ! FilterScene ( obj , this . SceneMode ) )
342
305
{
343
- if ( SceneMode == SceneFilter . None )
344
- {
345
- if ( ! NoSceneFilter ( obj , obj . GetType ( ) ) )
346
- {
347
- continue ;
348
- }
349
- }
350
- else
351
- {
352
- GameObject go ;
353
-
354
- var objtype = obj . GetType ( ) ;
355
- if ( objtype == typeof ( GameObject ) )
356
- {
357
- go = obj as GameObject ;
358
- }
359
- else if ( typeof ( Component ) . IsAssignableFrom ( objtype ) )
360
- {
361
- go = ( obj as Component ) . gameObject ;
362
- }
363
- else { continue ; }
364
-
365
- if ( ! go ) { continue ; }
366
-
367
- if ( SceneMode == SceneFilter . This )
368
- {
369
- if ( go . scene . name != CppExplorer . ActiveSceneName || go . scene . name == "DontDestroyOnLoad" )
370
- {
371
- continue ;
372
- }
373
- }
374
- else if ( SceneMode == SceneFilter . DontDestroy )
375
- {
376
- if ( go . scene . name != "DontDestroyOnLoad" )
377
- {
378
- continue ;
379
- }
380
- }
381
- }
306
+ continue ;
382
307
}
383
308
384
309
if ( ! matches . Contains ( obj ) )
@@ -390,68 +315,78 @@ private List<object> FindAllObjectsOfType(string _search, string _type)
390
315
return matches ;
391
316
}
392
317
393
- public static bool ThisSceneFilter ( object obj , Type type )
318
+ public static bool FilterScene ( object obj , SceneFilter filter )
394
319
{
395
- if ( type == typeof ( GameObject ) || typeof ( Component ) . IsAssignableFrom ( type ) )
320
+ GameObject go ;
321
+ if ( obj is Il2CppSystem . Object ilObject )
396
322
{
397
- var go = obj as GameObject ?? ( obj as Component ) . gameObject ;
398
-
399
- if ( go != null && go . scene . name == CppExplorer . ActiveSceneName && go . scene . name != "DontDestroyOnLoad" )
400
- {
401
- return true ;
402
- }
323
+ go = ilObject . TryCast < GameObject > ( ) ?? ilObject . TryCast < Component > ( ) . gameObject ;
403
324
}
404
-
405
- return false ;
406
- }
407
-
408
- public static bool DontDestroyFilter ( object obj , Type type )
409
- {
410
- if ( type == typeof ( GameObject ) || typeof ( Component ) . IsAssignableFrom ( type ) )
325
+ else
411
326
{
412
- var go = obj as GameObject ?? ( obj as Component ) . gameObject ;
327
+ go = ( obj as GameObject ) ?? ( obj as Component ) . gameObject ;
328
+ }
413
329
414
- if ( go != null && go . scene . name == "DontDestroyOnLoad" )
415
- {
416
- return true ;
417
- }
330
+ if ( ! go )
331
+ {
332
+ // object is not on a GameObject, cannot perform scene filter operation.
333
+ return false ;
418
334
}
419
335
336
+ if ( filter == SceneFilter . None )
337
+ {
338
+ return string . IsNullOrEmpty ( go . scene . name ) ;
339
+ }
340
+ else if ( filter == SceneFilter . This )
341
+ {
342
+ return go . scene . name == CppExplorer . ActiveSceneName ;
343
+ }
344
+ else if ( filter == SceneFilter . DontDestroy )
345
+ {
346
+ return go . scene . name == "DontDestroyOnLoad" ;
347
+ }
420
348
return false ;
421
349
}
422
350
423
- public static bool NoSceneFilter ( object obj , Type type )
351
+ // ====== other ========
352
+
353
+ // credit: ManlyMarco (RuntimeUnityEditor)
354
+ public static IEnumerable < object > GetInstanceClassScanner ( )
424
355
{
425
- if ( type == typeof ( GameObject ) )
426
- {
427
- var go = obj as GameObject ;
356
+ var query = AppDomain . CurrentDomain . GetAssemblies ( )
357
+ . Where ( x => ! x . FullName . StartsWith ( "Mono" ) )
358
+ . SelectMany ( GetTypesSafe )
359
+ . Where ( t => t . IsClass && ! t . IsAbstract && ! t . ContainsGenericParameters ) ;
428
360
429
- if ( go . scene . name != CppExplorer . ActiveSceneName && go . scene . name != "DontDestroyOnLoad" )
430
- {
431
- return true ;
432
- }
433
- else
361
+ foreach ( var type in query )
362
+ {
363
+ object obj = null ;
364
+ try
434
365
{
435
- return false ;
366
+ obj = type . GetProperty ( "Instance" , BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ? . GetValue ( null , null ) ;
436
367
}
437
- }
438
- else if ( typeof ( Component ) . IsAssignableFrom ( type ) )
439
- {
440
- var go = ( obj as Component ) . gameObject ;
441
-
442
- if ( go == null || ( go . scene . name != CppExplorer . ActiveSceneName && go . scene . name != "DontDestroyOnLoad" ) )
368
+ catch
443
369
{
444
- return true ;
370
+ try
371
+ {
372
+ obj = type . GetField ( "Instance" , BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ? . GetValue ( null ) ;
373
+ }
374
+ catch
375
+ {
376
+ }
445
377
}
446
- else
378
+ if ( obj != null && ! obj . ToString ( ) . StartsWith ( "Mono" ) )
447
379
{
448
- return false ;
380
+ yield return obj ;
449
381
}
450
382
}
451
- else
452
- {
453
- return true ;
454
- }
383
+ }
384
+
385
+ public static IEnumerable < Type > GetTypesSafe ( Assembly asm )
386
+ {
387
+ try { return asm . GetTypes ( ) ; }
388
+ catch ( ReflectionTypeLoadException e ) { return e . Types . Where ( x => x != null ) ; }
389
+ catch { return Enumerable . Empty < Type > ( ) ; }
455
390
}
456
391
}
457
392
}
0 commit comments