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

Commit 72d31ea

Browse files
committed
1.6.1
* Fix for when inspected object gets destroyed * Fix for displaying Dictionaries/Lists nested inside a Dictionary * Cleanups
1 parent 4e8b84b commit 72d31ea

File tree

10 files changed

+185
-164
lines changed

10 files changed

+185
-164
lines changed

src/CachedObjects/CacheObjectBase.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ public abstract class CacheObjectBase
1616
public string ValueTypeName;
1717
public Type ValueType;
1818

19-
// Reflection Inspector only
2019
public MemberInfo MemInfo { get; set; }
2120
public Type DeclaringType { get; set; }
2221
public object DeclaringInstance { get; set; }
23-
public string ReflectionException { get; set; }
24-
2522
public int PropertyIndex { get; private set; }
2623
private string m_propertyIndexInput = "0";
2724

25+
public string ReflectionException { get; set; }
26+
2827
public string RichTextName => m_richTextName ?? GetRichTextName();
2928
private string m_richTextName;
3029

src/CachedObjects/Object/CacheDictionary.cs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
namespace Explorer
1212
{
13-
public class CacheDictionary : CacheObjectBase
13+
public class CacheDictionary : CacheObjectBase, IExpandHeight
1414
{
1515
public bool IsExpanded { get; set; }
16-
public PageHelper Pages = new PageHelper();
16+
public float WhiteSpace { get; set; } = 215f;
17+
public float ButtonWidthOffset { get; set; } = 290f;
1718

18-
public float WhiteSpace = 215f;
19-
public float ButtonWidthOffset = 290f;
19+
public PageHelper Pages = new PageHelper();
2020

2121
private CacheObjectBase[] m_cachedKeys;
2222
private CacheObjectBase[] m_cachedValues;
@@ -48,6 +48,8 @@ public IDictionary IDict
4848
}
4949
private IDictionary m_iDictionary;
5050

51+
// ========== Methods ==========
52+
5153
// This is a bit janky due to Il2Cpp Dictionary not implementing IDictionary.
5254
private IDictionary Il2CppDictionaryToMono()
5355
{
@@ -94,43 +96,36 @@ private IDictionary Il2CppDictionaryToMono()
9496
return dict;
9597
}
9698

97-
// ========== Methods ==========
98-
9999
private void GetGenericArguments()
100100
{
101-
if (m_keysType == null || m_valuesType == null)
101+
if (this.MemInfo != null)
102102
{
103-
if (this.MemInfo != null)
103+
Type memberType = null;
104+
switch (this.MemInfo.MemberType)
104105
{
105-
Type memberType = null;
106-
switch (this.MemInfo.MemberType)
107-
{
108-
case MemberTypes.Field:
109-
memberType = (MemInfo as FieldInfo).FieldType;
110-
break;
111-
case MemberTypes.Property:
112-
memberType = (MemInfo as PropertyInfo).PropertyType;
113-
break;
114-
}
106+
case MemberTypes.Field:
107+
memberType = (MemInfo as FieldInfo).FieldType;
108+
break;
109+
case MemberTypes.Property:
110+
memberType = (MemInfo as PropertyInfo).PropertyType;
111+
break;
112+
}
115113

116-
if (memberType != null && memberType.IsGenericType)
117-
{
118-
m_keysType = memberType.GetGenericArguments()[0];
119-
m_valuesType = memberType.GetGenericArguments()[1];
120-
}
114+
if (memberType != null && memberType.IsGenericType)
115+
{
116+
m_keysType = memberType.GetGenericArguments()[0];
117+
m_valuesType = memberType.GetGenericArguments()[1];
121118
}
122-
else if (Value != null)
119+
}
120+
else if (Value != null)
121+
{
122+
var type = Value.GetType();
123+
if (type.IsGenericType)
123124
{
124-
var type = Value.GetType();
125-
if (type.IsGenericType)
126-
{
127-
m_keysType = type.GetGenericArguments()[0];
128-
m_valuesType = type.GetGenericArguments()[1];
129-
}
125+
m_keysType = type.GetGenericArguments()[0];
126+
m_valuesType = type.GetGenericArguments()[1];
130127
}
131128
}
132-
133-
return;
134129
}
135130

136131
public override void UpdateValue()
@@ -258,15 +253,11 @@ public override void DrawValue(Rect window, float width)
258253
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
259254
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
260255

261-
GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.MinWidth((window.width / 3) - 60f) });
262256
GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) });
263257
key.DrawValue(window, (window.width / 2) - 30f);
264-
GUILayout.EndHorizontal();
265258

266-
GUILayout.BeginHorizontal(null);
267259
GUILayout.Label("Value:", new GUILayoutOption[] { GUILayout.Width(40) });
268260
val.DrawValue(window, (window.width / 2) - 30f);
269-
GUILayout.EndHorizontal();
270261
}
271262

272263
}

src/CachedObjects/Object/CacheList.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
namespace Explorer
1010
{
11-
public class CacheList : CacheObjectBase
11+
public class CacheList : CacheObjectBase, IExpandHeight
1212
{
1313
public bool IsExpanded { get; set; }
14-
public PageHelper Pages = new PageHelper();
14+
public float WhiteSpace { get; set; } = 215f;
15+
public float ButtonWidthOffset { get; set; } = 290f;
1516

16-
public float WhiteSpace = 215f;
17-
public float ButtonWidthOffset = 290f;
17+
public PageHelper Pages = new PageHelper();
1818

1919
private CacheObjectBase[] m_cachedEntries;
2020

@@ -52,6 +52,7 @@ public PropertyInfo ItemProperty
5252
{
5353
get => GetItemProperty();
5454
}
55+
5556
private PropertyInfo m_itemProperty;
5657

5758
// ========== Methods ==========

src/CachedObjects/Other/CacheMethod.cs

Lines changed: 82 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,17 @@ public class CacheMethod : CacheObjectBase
1818
private ParameterInfo[] m_arguments;
1919
private string[] m_argumentInput;
2020

21-
public bool HasParameters
22-
{
23-
get
24-
{
25-
if (m_hasParams == null)
26-
{
27-
m_hasParams = (MemInfo as MethodInfo).GetParameters().Length > 0;
28-
}
29-
return (bool)m_hasParams;
30-
}
31-
}
32-
private bool? m_hasParams;
21+
public bool HasParameters => m_arguments != null && m_arguments.Length > 0;
3322

3423
public static bool CanEvaluate(MethodInfo mi)
3524
{
36-
// generic type args not supported yet
25+
// TODO generic args
3726
if (mi.GetGenericArguments().Length > 0)
3827
{
3928
return false;
4029
}
4130

42-
// only primitive and string args supported
31+
// primitive and string args supported
4332
foreach (var param in mi.GetParameters())
4433
{
4534
if (!param.ParameterType.IsPrimitive && param.ParameterType != typeof(string))
@@ -64,7 +53,84 @@ public override void Init()
6453
public override void UpdateValue()
6554
{
6655
//base.UpdateValue();
67-
}
56+
}
57+
58+
private void Evaluate()
59+
{
60+
var mi = MemInfo as MethodInfo;
61+
62+
object ret = null;
63+
64+
if (!HasParameters)
65+
{
66+
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
67+
m_evaluated = true;
68+
}
69+
else
70+
{
71+
var parsedArgs = new List<object>();
72+
for (int i = 0; i < m_arguments.Length; i++)
73+
{
74+
var input = m_argumentInput[i];
75+
var type = m_arguments[i].ParameterType;
76+
77+
if (type == typeof(string))
78+
{
79+
parsedArgs.Add(input);
80+
}
81+
else
82+
{
83+
try
84+
{
85+
if (type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }) is object parsed)
86+
{
87+
parsedArgs.Add(parsed);
88+
}
89+
else
90+
{
91+
// try add a null arg i guess
92+
parsedArgs.Add(null);
93+
}
94+
95+
}
96+
catch
97+
{
98+
MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'");
99+
break;
100+
}
101+
}
102+
}
103+
104+
try
105+
{
106+
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, parsedArgs.ToArray());
107+
m_evaluated = true;
108+
}
109+
catch (Exception e)
110+
{
111+
MelonLogger.Log($"Exception evaluating: {e.GetType()}, {e.Message}");
112+
}
113+
}
114+
115+
if (ret != null)
116+
{
117+
m_cachedReturnValue = GetCacheObject(ret);
118+
119+
if (m_cachedReturnValue is IExpandHeight expander)
120+
{
121+
expander.WhiteSpace = 0f;
122+
expander.ButtonWidthOffset += 70f;
123+
}
124+
125+
m_cachedReturnValue.UpdateValue();
126+
}
127+
else
128+
{
129+
m_cachedReturnValue = null;
130+
}
131+
}
132+
133+
// ==== GUI DRAW ====
68134

69135
public override void DrawValue(Rect window, float width)
70136
{
@@ -124,15 +190,7 @@ public override void DrawValue(Rect window, float width)
124190
{
125191
if (m_cachedReturnValue != null)
126192
{
127-
try
128-
{
129-
m_cachedReturnValue.DrawValue(window, width);
130-
}
131-
catch (Exception e)
132-
{
133-
MelonLogger.Log("Exception drawing m_cachedReturnValue!");
134-
MelonLogger.Log(e.ToString());
135-
}
193+
m_cachedReturnValue.DrawValue(window, width);
136194
}
137195
else
138196
{
@@ -147,82 +205,5 @@ public override void DrawValue(Rect window, float width)
147205

148206
GUILayout.EndVertical();
149207
}
150-
151-
private void Evaluate()
152-
{
153-
var mi = MemInfo as MethodInfo;
154-
155-
object ret = null;
156-
157-
if (!HasParameters)
158-
{
159-
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
160-
m_evaluated = true;
161-
}
162-
else
163-
{
164-
var arguments = new List<object>();
165-
for (int i = 0; i < m_arguments.Length; i++)
166-
{
167-
var input = m_argumentInput[i];
168-
var type = m_arguments[i].ParameterType;
169-
170-
if (type == typeof(string))
171-
{
172-
arguments.Add(input);
173-
}
174-
else
175-
{
176-
try
177-
{
178-
if (type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }) is object parsed)
179-
{
180-
arguments.Add(parsed);
181-
}
182-
else
183-
{
184-
throw new Exception();
185-
}
186-
187-
}
188-
catch
189-
{
190-
MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'");
191-
break;
192-
}
193-
}
194-
}
195-
196-
if (arguments.Count == m_arguments.Length)
197-
{
198-
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, arguments.ToArray());
199-
m_evaluated = true;
200-
}
201-
else
202-
{
203-
MelonLogger.Log($"Did not invoke because {m_arguments.Length - arguments.Count} arguments could not be parsed!");
204-
}
205-
}
206-
207-
if (ret != null)
208-
{
209-
m_cachedReturnValue = GetCacheObject(ret);
210-
if (m_cachedReturnValue is CacheList cacheList)
211-
{
212-
cacheList.WhiteSpace = 0f;
213-
cacheList.ButtonWidthOffset += 70f;
214-
}
215-
else if (m_cachedReturnValue is CacheDictionary cacheDict)
216-
{
217-
cacheDict.WhiteSpace = 0f;
218-
cacheDict.ButtonWidthOffset += 70f;
219-
}
220-
m_cachedReturnValue.UpdateValue();
221-
}
222-
else
223-
{
224-
m_cachedReturnValue = null;
225-
}
226-
}
227208
}
228209
}

src/CppExplorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Explorer
1313
public class CppExplorer : MelonMod
1414
{
1515
public const string GUID = "com.sinai.cppexplorer";
16-
public const string VERSION = "1.6.0";
16+
public const string VERSION = "1.6.1";
1717
public const string AUTHOR = "Sinai";
1818

1919
public const string NAME = "CppExplorer"

src/CppExplorer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
</Reference>
121121
</ItemGroup>
122122
<ItemGroup>
123+
<Compile Include="Helpers\IExpandHeight.cs" />
123124
<Compile Include="CachedObjects\Struct\CacheColor.cs" />
124125
<Compile Include="CachedObjects\Object\CacheDictionary.cs" />
125126
<Compile Include="CachedObjects\Struct\CacheEnum.cs" />

0 commit comments

Comments
 (0)