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

Commit 2f3b779

Browse files
committed
1.5.1
* Added support for Properties with an index parameter on the Reflection Window (ie. "this[index]") * Fixed a crash that occured when inspecting Il2CppSystem.Type objects * Back-end cleanups
1 parent 916bdea commit 2f3b779

File tree

12 files changed

+345
-251
lines changed

12 files changed

+345
-251
lines changed

src/CachedObjects/CacheEnum.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using System.Reflection;
67
using MelonLoader;
78
using UnityEngine;
89

@@ -15,8 +16,23 @@ public class CacheEnum : CacheObjectBase
1516

1617
public override void Init()
1718
{
18-
EnumType = Value.GetType();
19-
EnumNames = Enum.GetNames(EnumType);
19+
try
20+
{
21+
EnumType = Value.GetType();
22+
}
23+
catch
24+
{
25+
EnumType = (MemInfo as FieldInfo)?.FieldType ?? (MemInfo as PropertyInfo).PropertyType;
26+
}
27+
28+
if (EnumType != null)
29+
{
30+
EnumNames = Enum.GetNames(EnumType);
31+
}
32+
else
33+
{
34+
ReflectionException = "Unknown, could not get Enum names.";
35+
}
2036
}
2137

2238
public override void DrawValue(Rect window, float width)

src/CachedObjects/CacheList.cs

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ private Type GetEntryType()
145145
{
146146
if (m_entryType == null)
147147
{
148-
if (this.MemberInfo != null)
148+
if (this.MemInfo != null)
149149
{
150150
Type memberType = null;
151-
switch (this.MemberInfo.MemberType)
151+
switch (this.MemInfo.MemberType)
152152
{
153153
case MemberTypes.Field:
154-
memberType = (MemberInfo as FieldInfo).FieldType;
154+
memberType = (MemInfo as FieldInfo).FieldType;
155155
break;
156156
case MemberTypes.Property:
157-
memberType = (MemberInfo as PropertyInfo).PropertyType;
157+
memberType = (MemInfo as PropertyInfo).PropertyType;
158158
break;
159159
}
160160

@@ -201,17 +201,47 @@ public override void UpdateValue()
201201
while (enumerator.MoveNext())
202202
{
203203
var obj = enumerator.Current;
204-
var type = ReflectionHelpers.GetActualType(obj);
205204

206-
if (obj is Il2CppSystem.Object iObj)
205+
if (obj != null && ReflectionHelpers.GetActualType(obj) is Type t)
207206
{
208-
obj = iObj.Il2CppCast(type);
207+
if (obj is Il2CppSystem.Object iObj)
208+
{
209+
try
210+
{
211+
var cast = iObj.Il2CppCast(t);
212+
if (cast != null)
213+
{
214+
obj = cast;
215+
}
216+
}
217+
catch { }
218+
}
219+
220+
if (GetCacheObject(obj, t) is CacheObjectBase cached)
221+
{
222+
list.Add(cached);
223+
}
224+
else
225+
{
226+
list.Add(null);
227+
}
228+
}
229+
else
230+
{
231+
list.Add(null);
209232
}
210233

211-
var cached = GetCacheObject(obj, null, null, type);
212-
cached.UpdateValue();
234+
//var type = ReflectionHelpers.GetActualType(obj);
213235

214-
list.Add(cached);
236+
//if (obj is Il2CppSystem.Object iObj)
237+
//{
238+
// obj = iObj.Il2CppCast(type);
239+
//}
240+
241+
//var cached = GetCacheObject(obj, null, null, type);
242+
//cached.UpdateValue();
243+
244+
//list.Add(cached);
215245
}
216246

217247
m_cachedEntries = list.ToArray();
@@ -310,16 +340,18 @@ public override void DrawValue(Rect window, float width)
310340

311341
GUILayout.Space(whitespace);
312342

313-
if (entry.Value == null)
343+
if (entry == null || entry.Value == null)
314344
{
315-
GUILayout.Label(i + "<i><color=grey> (null)</color></i>", null);
345+
GUILayout.Label($"[{i}] <i><color=grey>(null)</color></i>", null);
316346
}
317347
else
318348
{
319349
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
320350
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
321-
entry.DrawValue(window, window.width - (whitespace + 85));
351+
352+
entry.DrawValue(window, window.width - (whitespace + 85));
322353
}
354+
323355
}
324356

325357
GUI.skin.label.alignment = TextAnchor.UpperLeft;

src/CachedObjects/CacheMethod.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public bool HasParameters
2424
{
2525
if (m_hasParams == null)
2626
{
27-
m_hasParams = (MemberInfo as MethodInfo).GetParameters().Length > 0;
27+
m_hasParams = (MemInfo as MethodInfo).GetParameters().Length > 0;
2828
}
2929
return (bool)m_hasParams;
3030
}
@@ -55,7 +55,7 @@ public override void Init()
5555
{
5656
base.Init();
5757

58-
var mi = MemberInfo as MethodInfo;
58+
var mi = MemInfo as MethodInfo;
5959

6060
m_arguments = mi.GetParameters();
6161
m_argumentInput = new string[m_arguments.Length];
@@ -136,12 +136,12 @@ public override void DrawValue(Rect window, float width)
136136
}
137137
else
138138
{
139-
GUILayout.Label($"null (<color=yellow>{ValueType}</color>)", null);
139+
GUILayout.Label($"null (<color=yellow>{ValueTypeName}</color>)", null);
140140
}
141141
}
142142
else
143143
{
144-
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=yellow>{ValueType}</color>)", null);
144+
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=yellow>{ValueTypeName}</color>)", null);
145145
}
146146
GUILayout.EndHorizontal();
147147

@@ -150,7 +150,7 @@ public override void DrawValue(Rect window, float width)
150150

151151
private void Evaluate()
152152
{
153-
var mi = MemberInfo as MethodInfo;
153+
var mi = MemInfo as MethodInfo;
154154

155155
object ret = null;
156156

0 commit comments

Comments
 (0)