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

Commit 916bdea

Browse files
committed
1.5.0
1 parent d868819 commit 916bdea

File tree

6 files changed

+124
-62
lines changed

6 files changed

+124
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ CppExplorer has two main inspector modes: <b>GameObject Inspector</b>, and <b>Re
6666
* Allows you to inspect Properties, Fields and basic Methods, as well as set primitive values and evaluate primitive methods.
6767
* Can search and filter members for the ones you are interested in.
6868

69-
[![](https://i.imgur.com/eFVTQdh.png)](https://i.imgur.com/eFVTQdh.png)
69+
[![](https://i.imgur.com/iq92m0l.png)](https://i.imgur.com/iq92m0l.png)
7070

7171
### Object Search
7272

src/CachedObjects/CacheList.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Explorer
1010
{
11-
public partial class CacheList : CacheObjectBase
11+
public class CacheList : CacheObjectBase
1212
{
1313
public bool IsExpanded { get; set; }
1414
public int ArrayOffset { get; set; }
@@ -61,7 +61,7 @@ private IEnumerable GetEnumerable()
6161
{
6262
if (m_enumerable == null && Value != null)
6363
{
64-
m_enumerable = Value as IEnumerable ?? CastValueFromList();
64+
m_enumerable = Value as IEnumerable ?? GetEnumerableFromIl2CppList();
6565
}
6666
return m_enumerable;
6767
}
@@ -101,7 +101,7 @@ private PropertyInfo GetItemProperty()
101101
return m_itemProperty;
102102
}
103103

104-
private IEnumerable CastValueFromList()
104+
private IEnumerable GetEnumerableFromIl2CppList()
105105
{
106106
if (Value == null) return null;
107107

@@ -111,11 +111,11 @@ private IEnumerable CastValueFromList()
111111
}
112112
else
113113
{
114-
return CastFromIList();
114+
return ConvertIListToMono();
115115
}
116116
}
117117

118-
private IList CastFromIList()
118+
private IList ConvertIListToMono()
119119
{
120120
try
121121
{
@@ -136,7 +136,7 @@ private IList CastFromIList()
136136
}
137137
catch (Exception e)
138138
{
139-
MelonLogger.Log("Exception casting IList to Array: " + e.GetType() + ", " + e.Message);
139+
MelonLogger.Log("Exception converting Il2Cpp IList to Mono IList: " + e.GetType() + ", " + e.Message);
140140
return null;
141141
}
142142
}
@@ -186,13 +186,12 @@ public override void UpdateValue()
186186
{
187187
base.UpdateValue();
188188

189-
if (Value == null)
189+
if (Value == null || Enumerable == null)
190190
{
191191
return;
192192
}
193193

194-
var enumerator = Enumerable?.GetEnumerator();
195-
194+
var enumerator = Enumerable.GetEnumerator();
196195
if (enumerator == null)
197196
{
198197
return;
@@ -214,6 +213,7 @@ public override void UpdateValue()
214213

215214
list.Add(cached);
216215
}
216+
217217
m_cachedEntries = list.ToArray();
218218
}
219219

src/CachedObjects/CacheObjectBase.cs

Lines changed: 89 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ public abstract class CacheObjectBase
1919
public MemberInfo MemberInfo { get; set; }
2020
public Type DeclaringType { get; set; }
2121
public object DeclaringInstance { get; set; }
22-
public string FullName => $"{MemberInfo.DeclaringType.Name}.{MemberInfo.Name}";
22+
23+
public string RichTextName
24+
{
25+
get
26+
{
27+
if (m_richTextName == null)
28+
{
29+
GetRichTextName();
30+
}
31+
return m_richTextName;
32+
}
33+
}
34+
private string m_richTextName;
35+
2336
public string ReflectionException;
2437

2538
public bool CanWrite
@@ -156,45 +169,7 @@ public static CacheObjectBase GetCacheObject(object obj, MemberInfo memberInfo,
156169
return holder;
157170
}
158171

159-
public const float MAX_LABEL_WIDTH = 400f;
160-
161-
public static void ClampLabelWidth(Rect window, ref float labelWidth)
162-
{
163-
float min = window.width * 0.37f;
164-
if (min > MAX_LABEL_WIDTH) min = MAX_LABEL_WIDTH;
165-
166-
labelWidth = Mathf.Clamp(labelWidth, min, MAX_LABEL_WIDTH);
167-
}
168-
169-
public void Draw(Rect window, float labelWidth = 215f)
170-
{
171-
if (labelWidth > 0)
172-
{
173-
ClampLabelWidth(window, ref labelWidth);
174-
}
175-
176-
if (MemberInfo != null)
177-
{
178-
GUILayout.Label("<color=cyan>" + FullName + "</color>", new GUILayoutOption[] { GUILayout.Width(labelWidth) });
179-
}
180-
else
181-
{
182-
GUILayout.Space(labelWidth);
183-
}
184-
185-
if (!string.IsNullOrEmpty(ReflectionException))
186-
{
187-
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", null);
188-
}
189-
else if (Value == null && MemberInfo?.MemberType != MemberTypes.Method)
190-
{
191-
GUILayout.Label("<i>null (" + ValueType + ")</i>", null);
192-
}
193-
else
194-
{
195-
DrawValue(window, window.width - labelWidth - 90);
196-
}
197-
}
172+
// ======== Updating and Setting Value (memberinfo only) =========
198173

199174
public virtual void UpdateValue()
200175
{
@@ -245,5 +220,79 @@ public void SetValue()
245220
MelonLogger.LogWarning($"Error setting value: {e.GetType()}, {e.Message}");
246221
}
247222
}
223+
224+
// ========= Gui Draw ==========
225+
226+
public const float MAX_LABEL_WIDTH = 400f;
227+
228+
public static void ClampLabelWidth(Rect window, ref float labelWidth)
229+
{
230+
float min = window.width * 0.37f;
231+
if (min > MAX_LABEL_WIDTH) min = MAX_LABEL_WIDTH;
232+
233+
labelWidth = Mathf.Clamp(labelWidth, min, MAX_LABEL_WIDTH);
234+
}
235+
236+
public void Draw(Rect window, float labelWidth = 215f)
237+
{
238+
if (labelWidth > 0)
239+
{
240+
ClampLabelWidth(window, ref labelWidth);
241+
}
242+
243+
if (MemberInfo != null)
244+
{
245+
246+
247+
GUILayout.Label(RichTextName, new GUILayoutOption[] { GUILayout.Width(labelWidth) });
248+
}
249+
else
250+
{
251+
GUILayout.Space(labelWidth);
252+
}
253+
254+
if (!string.IsNullOrEmpty(ReflectionException))
255+
{
256+
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", null);
257+
}
258+
else if (Value == null && MemberInfo?.MemberType != MemberTypes.Method)
259+
{
260+
GUILayout.Label("<i>null (" + ValueType + ")</i>", null);
261+
}
262+
else
263+
{
264+
DrawValue(window, window.width - labelWidth - 90);
265+
}
266+
}
267+
268+
private void GetRichTextName()
269+
{
270+
string memberColor = "";
271+
switch (MemberInfo.MemberType)
272+
{
273+
case MemberTypes.Field:
274+
memberColor = "#c266ff"; break;
275+
case MemberTypes.Property:
276+
memberColor = "#72a6a6"; break;
277+
case MemberTypes.Method:
278+
memberColor = "#ff8000"; break;
279+
};
280+
281+
m_richTextName = $"<color=#2df7b2>{MemberInfo.DeclaringType.Name}</color>.<color={memberColor}>{MemberInfo.Name}</color>";
282+
283+
if (MemberInfo is MethodInfo mi)
284+
{
285+
m_richTextName += "(";
286+
var _params = "";
287+
foreach (var param in mi.GetParameters())
288+
{
289+
if (_params != "") _params += ", ";
290+
291+
_params += $"<color=#a6e9e9>{param.Name}</color>";
292+
}
293+
m_richTextName += _params;
294+
m_richTextName += ")";
295+
}
296+
}
248297
}
249298
}

src/CachedObjects/CachePrimitive.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public override void DrawValue(Rect window, float width)
113113
b = GUILayout.Toggle(b, label, null);
114114
if (b != (bool)Value)
115115
{
116-
SetValue(m_valueToString);
116+
SetValueFromInput(b.ToString());
117117
}
118118
}
119119
else
@@ -142,15 +142,15 @@ public override void DrawValue(Rect window, float width)
142142
{
143143
if (GUILayout.Button("<color=#00FF00>Apply</color>", new GUILayoutOption[] { GUILayout.Width(60) }))
144144
{
145-
SetValue(m_valueToString);
145+
SetValueFromInput(m_valueToString);
146146
}
147147
}
148148

149149
GUILayout.Space(5);
150150
}
151151
}
152152

153-
public void SetValue(string value)
153+
public void SetValueFromInput(string value)
154154
{
155155
if (MemberInfo == null)
156156
{

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.4.7";
15+
public const string VERSION = "1.5.0";
1616
public const string AUTHOR = "Sinai";
1717

1818
public const string NAME = "CppExplorer"

src/Windows/ReflectionWindow.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ private bool ShouldProcessMember(CacheObjectBase holder)
9696

9797
if (m_search == "" || holder.MemberInfo == null) return true;
9898

99-
return holder.FullName
100-
.ToLower()
101-
.Contains(m_search.ToLower());
99+
var name = holder.MemberInfo.DeclaringType.Name + "." + holder.MemberInfo.Name;
100+
101+
return name.ToLower().Contains(m_search.ToLower());
102102
}
103103

104104
private void CacheMembers(Type[] types)
@@ -140,25 +140,38 @@ private void CacheMembers(Type[] types)
140140
{
141141
if (member.MemberType == MemberTypes.Field || member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Method)
142142
{
143+
// ignore these
143144
if (member.Name.Contains("Il2CppType") || member.Name.StartsWith("get_") || member.Name.StartsWith("set_"))
144145
continue;
145146

146-
try
147+
var name = member.DeclaringType.Name + "." + member.Name;
148+
if (member is MethodInfo mi)
149+
{
150+
name += " (";
151+
foreach (var param in mi.GetParameters())
152+
{
153+
name += param.ParameterType.Name + ", ";
154+
}
155+
name += ")";
156+
}
157+
if (names.Contains(name))
147158
{
148-
var name = member.DeclaringType.Name + "." + member.Name;
149-
if (names.Contains(name)) continue;
150-
names.Add(name);
159+
continue;
160+
}
151161

162+
try
163+
{
152164
var cached = CacheObjectBase.GetCacheObject(null, member, target);
153165
if (cached != null)
154166
{
167+
names.Add(name);
155168
list.Add(cached);
156169
cached.ReflectionException = exception;
157170
}
158171
}
159172
catch (Exception e)
160173
{
161-
MelonLogger.LogWarning($"Exception caching member {declaringType.Name}.{member.Name}!");
174+
MelonLogger.LogWarning($"Exception caching member {name}!");
162175
MelonLogger.Log(e.ToString());
163176
}
164177
}

0 commit comments

Comments
 (0)