Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 4115935

Browse files
committed
1.3.2
- Fixed the Scene Filters on the search page, it was not functionally correctly at all. - Fixed GameObjects and Components being displayed as basic objects on search view (they now open to GameObject inspector like they should).
1 parent a2677e2 commit 4115935

File tree

6 files changed

+190
-274
lines changed

6 files changed

+190
-274
lines changed

src/CppExplorer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEngine;
77
using MelonLoader;
88
using UnhollowerBaseLib;
9+
using UnhollowerRuntimeLib;
910
using Harmony;
1011

1112
namespace Explorer
@@ -16,7 +17,7 @@ public class CppExplorer : MelonMod
1617

1718
public const string ID = "com.sinai.cppexplorer";
1819
public const string NAME = "IL2CPP Runtime Explorer";
19-
public const string VERSION = "1.3.1";
20+
public const string VERSION = "1.3.2";
2021
public const string AUTHOR = "Sinai";
2122

2223
// fields
@@ -31,6 +32,13 @@ public class CppExplorer : MelonMod
3132
public static int ArrayLimit { get; set; } = 20;
3233
public bool MouseInspect { get; set; } = false;
3334

35+
// prop helpers
36+
37+
public static Il2CppSystem.Type GameObjectType => Il2CppType.Of<GameObject>();
38+
public static Il2CppSystem.Type TransformType => Il2CppType.Of<Transform>();
39+
public static Il2CppSystem.Type ObjectType => Il2CppType.Of<UnityEngine.Object>();
40+
public static Il2CppSystem.Type ComponentType => Il2CppType.Of<Component>();
41+
3442
public static string ActiveSceneName
3543
{
3644
get

src/MainMenu/Pages/SearchPage.cs

Lines changed: 67 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class SearchPage : WindowPage
2222
private string m_typeInput = "";
2323
private int m_limit = 100;
2424
private int m_pageOffset = 0;
25+
private List<object> m_searchResults = new List<object>();
26+
private Vector2 resultsScroll = Vector2.zero;
2527

2628
public SceneFilter SceneMode = SceneFilter.Any;
2729
public TypeFilter TypeMode = TypeFilter.Object;
@@ -42,9 +44,6 @@ public enum TypeFilter
4244
Custom
4345
}
4446

45-
private List<object> m_searchResults = new List<object>();
46-
private Vector2 resultsScroll = Vector2.zero;
47-
4847
public override void Init()
4948
{
5049
Instance = this;
@@ -114,7 +113,7 @@ public override void DrawWindow()
114113
int offset = m_pageOffset * CppExplorer.ArrayLimit;
115114
int preiterated = 0;
116115

117-
if (offset >= count) offset = 0;
116+
if (offset >= count) m_pageOffset = 0;
118117

119118
for (int i = 0; i < m_searchResults.Count; i++)
120119
{
@@ -246,51 +245,13 @@ private void SceneFilterToggle(SceneFilter mode, string label, float width)
246245
}
247246

248247

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) ----------------- //
289249

290250
// ======= search functions =======
291251

292252
private void Search()
293253
{
254+
m_pageOffset = 0;
294255
m_searchResults = FindAllObjectsOfType(m_searchInput, m_typeInput);
295256
}
296257

@@ -312,73 +273,37 @@ private List<object> FindAllObjectsOfType(string _search, string _type)
312273
}
313274
else if (TypeMode == TypeFilter.Object)
314275
{
315-
type = Il2CppType.Of<Object>();
276+
type = CppExplorer.ObjectType;
316277
}
317278
else if (TypeMode == TypeFilter.GameObject)
318279
{
319-
type = Il2CppType.Of<GameObject>();
280+
type = CppExplorer.GameObjectType;
320281
}
321282
else if (TypeMode == TypeFilter.Component)
322283
{
323-
type = Il2CppType.Of<Component>();
284+
type = CppExplorer.ComponentType;
324285
}
325286

326-
if (!Il2CppType.Of<Object>().IsAssignableFrom(type))
287+
if (!CppExplorer.ObjectType.IsAssignableFrom(type))
327288
{
328289
MelonLogger.LogError("Your Class Type must inherit from UnityEngine.Object! Leave blank to default to UnityEngine.Object");
329290
return new List<object>();
330291
}
331292

332293
var matches = new List<object>();
333294

334-
foreach (var obj in Resources.FindObjectsOfTypeAll(type))
295+
var allObjectsOfType = Resources.FindObjectsOfTypeAll(type);
296+
297+
foreach (var obj in allObjectsOfType)
335298
{
336299
if (_search != "" && !obj.name.ToLower().Contains(_search.ToLower()))
337300
{
338301
continue;
339302
}
340303

341-
if (SceneMode != SceneFilter.Any)
304+
if (SceneMode != SceneFilter.Any && !FilterScene(obj, this.SceneMode))
342305
{
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;
382307
}
383308

384309
if (!matches.Contains(obj))
@@ -390,68 +315,78 @@ private List<object> FindAllObjectsOfType(string _search, string _type)
390315
return matches;
391316
}
392317

393-
public static bool ThisSceneFilter(object obj, Type type)
318+
public static bool FilterScene(object obj, SceneFilter filter)
394319
{
395-
if (type == typeof(GameObject) || typeof(Component).IsAssignableFrom(type))
320+
GameObject go;
321+
if (obj is Il2CppSystem.Object ilObject)
396322
{
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;
403324
}
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
411326
{
412-
var go = obj as GameObject ?? (obj as Component).gameObject;
327+
go = (obj as GameObject) ?? (obj as Component).gameObject;
328+
}
413329

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;
418334
}
419335

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+
}
420348
return false;
421349
}
422350

423-
public static bool NoSceneFilter(object obj, Type type)
351+
// ====== other ========
352+
353+
// credit: ManlyMarco (RuntimeUnityEditor)
354+
public static IEnumerable<object> GetInstanceClassScanner()
424355
{
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);
428360

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
434365
{
435-
return false;
366+
obj = type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)?.GetValue(null, null);
436367
}
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
443369
{
444-
return true;
370+
try
371+
{
372+
obj = type.GetField("Instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)?.GetValue(null);
373+
}
374+
catch
375+
{
376+
}
445377
}
446-
else
378+
if (obj != null && !obj.ToString().StartsWith("Mono"))
447379
{
448-
return false;
380+
yield return obj;
449381
}
450382
}
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>(); }
455390
}
456391
}
457392
}

src/UIStyles.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,41 @@ public static void DrawValue(ref object value, ref bool isExpanded, ref int arra
225225
}
226226

227227
var valueType = value.GetType();
228+
229+
Il2CppSystem.Type ilType = null;
230+
if (value is Il2CppSystem.Object ilObject)
231+
{
232+
ilType = ilObject.GetIl2CppType();
233+
}
234+
228235
if (valueType.IsPrimitive || value.GetType() == typeof(string))
229236
{
230237
DrawPrimitive(ref value, rect, setTarget, setAction);
231238
}
232-
else if (valueType == typeof(GameObject) || valueType == typeof(Transform))
239+
//else if (valueType == typeof(GameObject) || typeof(Component).IsAssignableFrom(valueType))
240+
else if (ilType != null && ilType == CppExplorer.GameObjectType || CppExplorer.ComponentType.IsAssignableFrom(ilType))
233241
{
242+
//GameObject go;
243+
//if (value.GetType() == typeof(Transform))
244+
//{
245+
// go = (value as Transform).gameObject;
246+
//}
247+
//else
248+
//{
249+
// go = (value as GameObject);
250+
//}
251+
252+
//var go = (value as GameObject) ?? (value as Component).gameObject;
253+
234254
GameObject go;
235-
if (value.GetType() == typeof(Transform))
255+
var ilObj = value as Il2CppSystem.Object;
256+
if (ilType == CppExplorer.GameObjectType)
236257
{
237-
go = (value as Transform).gameObject;
258+
go = ilObj.TryCast<GameObject>();
238259
}
239260
else
240261
{
241-
go = (value as GameObject);
262+
go = ilObj.TryCast<Component>().gameObject;
242263
}
243264

244265
GameobjButton(go, null, false, rect.width - 250);

src_2018/CppExplorer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEngine;
77
using MelonLoader;
88
using UnhollowerBaseLib;
9+
using UnhollowerRuntimeLib;
910
using Harmony;
1011

1112
namespace Explorer
@@ -16,7 +17,7 @@ public class CppExplorer : MelonMod
1617

1718
public const string ID = "com.sinai.cppexplorer";
1819
public const string NAME = "IL2CPP Runtime Explorer (Unity 2018)";
19-
public const string VERSION = "1.3.1";
20+
public const string VERSION = "1.3.2";
2021
public const string AUTHOR = "Sinai";
2122

2223
// fields
@@ -31,6 +32,13 @@ public class CppExplorer : MelonMod
3132
public static int ArrayLimit { get; set; } = 20;
3233
public bool MouseInspect { get; set; } = false;
3334

35+
// prop helpers
36+
37+
public static Il2CppSystem.Type GameObjectType => Il2CppType.Of<GameObject>();
38+
public static Il2CppSystem.Type TransformType => Il2CppType.Of<Transform>();
39+
public static Il2CppSystem.Type ObjectType => Il2CppType.Of<UnityEngine.Object>();
40+
public static Il2CppSystem.Type ComponentType => Il2CppType.Of<Component>();
41+
3442
public static string ActiveSceneName
3543
{
3644
get

0 commit comments

Comments
 (0)