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

Commit e13f198

Browse files
committed
1.5.8
* Fixed a bug where the Page Helper would not update the total page count after changing the limit per page * Cleaned up the "Find Instances" helper, it will now filter out all types in the `System`, `Mono`, `Il2CppSystem` and `Iced` namespaces. * Improved the Find Instances helper so that it will avoid exceptions and get more results. * Enums now display their value type name * Changed the Scroll View unstrip so that it is less hard-coded for different unity versions and more dynamic.
1 parent 9a059c1 commit e13f198

File tree

8 files changed

+127
-95
lines changed

8 files changed

+127
-95
lines changed

src/CachedObjects/CacheObjectBase.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public abstract class CacheObjectBase
1414
{
1515
public object Value;
1616
public string ValueTypeName;
17+
public Type ValueType;
1718

1819
// Reflection Inspector only
1920
public MemberInfo MemInfo { get; set; }
@@ -79,11 +80,7 @@ public static CacheObjectBase GetCacheObject(object obj, MemberInfo memberInfo,
7980
{
8081
Type type = null;
8182

82-
if (obj != null)
83-
{
84-
type = ReflectionHelpers.GetActualType(obj);
85-
}
86-
else if (memberInfo != null)
83+
if (memberInfo != null)
8784
{
8885
if (memberInfo is FieldInfo fi)
8986
{
@@ -98,6 +95,10 @@ public static CacheObjectBase GetCacheObject(object obj, MemberInfo memberInfo,
9895
type = mi.ReturnType;
9996
}
10097
}
98+
else if (obj != null)
99+
{
100+
type = ReflectionHelpers.GetActualType(obj);
101+
}
101102

102103
if (type == null)
103104
{
@@ -167,6 +168,7 @@ private static CacheObjectBase GetCacheObjectImpl(object obj, MemberInfo memberI
167168
}
168169

169170
holder.Value = obj;
171+
holder.ValueType = valueType;
170172
holder.ValueTypeName = valueType.FullName;
171173

172174
if (memberInfo != null)

src/CachedObjects/Struct/CacheEnum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void DrawValue(Rect window, float width)
5151
}
5252
}
5353

54-
GUILayout.Label(Value.ToString(), null);// + "<color=yellow><i> (" + ValueType + ")</i></color>", null);
54+
GUILayout.Label(Value.ToString() + "<color=yellow><i> (" + ValueType + ")</i></color>", null);
5555
}
5656

5757
public void SetEnum(ref object value, int change)

src/CachedObjects/Struct/CachePrimitive.cs

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,34 @@ namespace Explorer
88
{
99
public class CachePrimitive : CacheObjectBase
1010
{
11-
public enum Types
12-
{
13-
Bool,
14-
Double,
15-
Float,
16-
Int,
17-
String,
18-
Char
19-
}
11+
private bool m_isBool;
12+
private bool m_isString;
2013

2114
private string m_valueToString;
2215

23-
public Types PrimitiveType;
24-
2516
public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }));
2617
private MethodInfo m_parseMethod;
2718

2819
public override void Init()
2920
{
30-
if (Value == null)
21+
if (ValueType == null)
3122
{
32-
// this must mean it is a string. No other primitive type should be nullable.
33-
PrimitiveType = Types.String;
34-
return;
35-
}
23+
ValueType = Value?.GetType();
3624

37-
m_valueToString = Value.ToString();
38-
39-
var type = Value.GetType();
40-
if (type == typeof(bool))
41-
{
42-
PrimitiveType = Types.Bool;
43-
}
44-
else if (type == typeof(double))
45-
{
46-
PrimitiveType = Types.Double;
47-
}
48-
else if (type == typeof(float))
49-
{
50-
PrimitiveType = Types.Float;
51-
}
52-
else if (type == typeof(char))
53-
{
54-
PrimitiveType = Types.Char;
25+
// has to be a string at this point
26+
if (ValueType == null)
27+
{
28+
ValueType = typeof(string);
29+
}
5530
}
56-
else if (typeof(int).IsAssignableFrom(type))
31+
32+
if (ValueType == typeof(string))
5733
{
58-
PrimitiveType = Types.Int;
34+
m_isString = true;
5935
}
60-
else
36+
else if (ValueType == typeof(bool))
6137
{
62-
PrimitiveType = Types.String;
38+
m_isBool = true;
6339
}
6440
}
6541

@@ -72,7 +48,7 @@ public override void UpdateValue()
7248

7349
public override void DrawValue(Rect window, float width)
7450
{
75-
if (PrimitiveType == Types.Bool)
51+
if (m_isBool)
7652
{
7753
var b = (bool)Value;
7854
var label = $"<color={(b ? "lime" : "red")}>{b}</color>";
@@ -92,7 +68,8 @@ public override void DrawValue(Rect window, float width)
9268
}
9369
else
9470
{
95-
GUILayout.Label("<color=yellow><i>" + PrimitiveType + "</i></color>", new GUILayoutOption[] { GUILayout.Width(50) });
71+
// using ValueType.Name instead of ValueTypeName, because we only want the short name.
72+
GUILayout.Label("<color=yellow><i>" + ValueType.Name + "</i></color>", new GUILayoutOption[] { GUILayout.Width(50) });
9673

9774
int dynSize = 25 + (m_valueToString.Length * 15);
9875
var maxwidth = window.width - 300f;
@@ -127,7 +104,7 @@ public void SetValueFromInput(string valueString)
127104
return;
128105
}
129106

130-
if (PrimitiveType == Types.String)
107+
if (m_isString)
131108
{
132109
Value = valueString;
133110
}

src/CppExplorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Explorer
1212
public class CppExplorer : MelonMod
1313
{
1414
public const string GUID = "com.sinai.cppexplorer";
15-
public const string VERSION = "1.5.7";
15+
public const string VERSION = "1.5.8";
1616
public const string AUTHOR = "Sinai";
1717

1818
public const string NAME = "CppExplorer"

src/Helpers/PageHelper.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ public enum Turn
1616
public class PageHelper
1717
{
1818
public int PageOffset { get; set; }
19-
public int ItemsPerPage { get; set; } = 20;
19+
20+
public int ItemsPerPage
21+
{
22+
get => m_itemsPerPage;
23+
set
24+
{
25+
m_itemsPerPage = value;
26+
CalculateMaxOffset();
27+
}
28+
}
29+
private int m_itemsPerPage = 20;
30+
2031
public int ItemCount
2132
{
2233
get => m_count;

src/MainMenu/Pages/ScenePage.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public class ScenePage : WindowPage
2121

2222
private static bool m_getRootObjectsFailed;
2323

24-
// ----- Holders for GUI elements ----- //
25-
2624
private static string m_currentScene = "";
2725

2826
// gameobject list
@@ -34,8 +32,6 @@ public class ScenePage : WindowPage
3432
private string m_searchInput = "";
3533
private List<GameObjectCache> m_searchResults = new List<GameObjectCache>();
3634

37-
// ------------ Init and Update ------------ //
38-
3935
public override void Init()
4036
{
4137
Instance = this;
@@ -126,9 +122,7 @@ private void Update_Impl(bool manual = false)
126122
}
127123
else
128124
{
129-
if (!manual && m_getRootObjectsFailed) return;
130-
131-
if (!manual)
125+
if (!m_getRootObjectsFailed)
132126
{
133127
try
134128
{
@@ -139,12 +133,19 @@ private void Update_Impl(bool manual = false)
139133
}
140134
catch
141135
{
136+
MelonLogger.Log("Exception getting root scene objects, falling back to backup method...");
137+
142138
m_getRootObjectsFailed = true;
143139
allTransforms.AddRange(GetRootObjectsManual_Impl());
144140
}
145141
}
146142
else
147143
{
144+
if (!manual)
145+
{
146+
return;
147+
}
148+
148149
allTransforms.AddRange(GetRootObjectsManual_Impl());
149150
}
150151
}

src/MainMenu/Pages/SearchPage.cs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,11 @@ public override void DrawWindow()
137137

138138
if (m_searchResults.Count > 0)
139139
{
140-
//int offset = m_pageOffset * this.m_limit;
141-
//if (offset >= count) m_pageOffset = 0;
142140
int offset = Pages.CalculateOffsetIndex();
143141

144142
for (int i = offset; i < offset + Pages.ItemsPerPage && i < count; i++)
145143
{
146144
m_searchResults[i].Draw(MainMenu.MainRect, 0f);
147-
//m_searchResults[i].DrawValue(MainMenu.MainRect);
148145
}
149146
}
150147
else
@@ -377,33 +374,67 @@ public static bool FilterScene(object obj, SceneFilter filter)
377374

378375
// ====== other ========
379376

377+
private static bool FilterName(string name)
378+
{
379+
// Don't really want these instances.
380+
return !name.StartsWith("Mono")
381+
&& !name.StartsWith("System")
382+
&& !name.StartsWith("Il2CppSystem")
383+
&& !name.StartsWith("Iced");
384+
}
385+
380386
// credit: ManlyMarco (RuntimeUnityEditor)
381387
public static IEnumerable<object> GetInstanceClassScanner()
382388
{
383389
var query = AppDomain.CurrentDomain.GetAssemblies()
384-
.Where(x => !x.FullName.StartsWith("Mono"))
385390
.SelectMany(GetTypesSafe)
386391
.Where(t => t.IsClass && !t.IsAbstract && !t.ContainsGenericParameters);
387392

393+
var flags = BindingFlags.Public | BindingFlags.Static;
394+
var flatFlags = flags | BindingFlags.FlattenHierarchy;
395+
388396
foreach (var type in query)
389397
{
390398
object obj = null;
391399
try
392400
{
393-
obj = type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)?.GetValue(null, null);
394-
}
395-
catch
396-
{
397-
try
401+
var pi = type.GetProperty("Instance", flags);
402+
403+
if (pi == null)
398404
{
399-
obj = type.GetField("Instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)?.GetValue(null);
405+
pi = type.GetProperty("Instance", flatFlags);
400406
}
401-
catch
407+
408+
if (pi != null)
402409
{
410+
obj = pi.GetValue(null);
411+
}
412+
else
413+
{
414+
var fi = type.GetField("Instance", flags);
415+
416+
if (fi == null)
417+
{
418+
fi = type.GetField("Instance", flatFlags);
419+
}
420+
421+
if (fi != null)
422+
{
423+
obj = fi.GetValue(null);
424+
}
403425
}
404426
}
405-
if (obj != null && !obj.ToString().StartsWith("Mono"))
427+
catch { }
428+
429+
if (obj != null)
406430
{
431+
var t = ReflectionHelpers.GetActualType(obj);
432+
433+
if (!FilterName(t.FullName) || ReflectionHelpers.IsArray(t) || ReflectionHelpers.IsList(t))
434+
{
435+
continue;
436+
}
437+
407438
yield return obj;
408439
}
409440
}

0 commit comments

Comments
 (0)