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

Commit 5d58993

Browse files
committed
1.7.31
* Added support for Il2Cpp Hashtable (non-generic Dict) * Dictionaries should now display CacheOther values better (smaller buttons) * Cleaned up and improved some of CacheDictionary performance
1 parent eea581f commit 5d58993

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

src/CachedObjects/CacheObjectBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private static CacheObjectBase GetCacheObjectImpl(object obj, MemberInfo memberI
172172
{
173173
holder = new CacheDictionary();
174174
}
175-
else if (ReflectionHelpers.IsEnumerable(valueType) || ReflectionHelpers.IsCppEnumerable(valueType))
175+
else if (ReflectionHelpers.IsEnumerable(valueType))
176176
{
177177
holder = new CacheList();
178178
}

src/CachedObjects/Object/CacheDictionary.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,16 @@ private void EnumerateWithReflection(object collection, List<object> list)
9898

9999
private void GetGenericArguments()
100100
{
101-
if (this.MemInfo != null)
101+
if (ValueType.IsGenericType)
102102
{
103-
Type memberType = null;
104-
switch (this.MemInfo.MemberType)
105-
{
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-
}
113-
114-
if (memberType != null && memberType.IsGenericType)
115-
{
116-
m_keysType = memberType.GetGenericArguments()[0];
117-
m_valuesType = memberType.GetGenericArguments()[1];
118-
}
103+
m_keysType = ValueType.GetGenericArguments()[0];
104+
m_valuesType = ValueType.GetGenericArguments()[1];
119105
}
120-
else if (Value != null)
106+
else
121107
{
122-
var type = Value.GetType();
123-
if (type.IsGenericType)
124-
{
125-
m_keysType = type.GetGenericArguments()[0];
126-
m_valuesType = type.GetGenericArguments()[1];
127-
}
128-
else
129-
{
130-
MelonLogger.Log("TODO? Dictionary is of type: " + Value.GetType().FullName);
131-
}
108+
// It's non-generic, just use System.Object to allow for anything.
109+
m_keysType = typeof(object);
110+
m_valuesType = typeof(object);
132111
}
133112
}
134113

@@ -288,10 +267,10 @@ public override void DrawValue(Rect window, float width)
288267
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
289268

290269
GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) });
291-
key.DrawValue(window, (window.width / 2) - 30f);
270+
key.DrawValue(window, (window.width / 2) - 80f);
292271

293272
GUILayout.Label("Value:", new GUILayoutOption[] { GUILayout.Width(40) });
294-
val.DrawValue(window, (window.width / 2) - 30f);
273+
val.DrawValue(window, (window.width / 2) - 80f);
295274
}
296275

297276
}

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 NAME = "CppExplorer";
16-
public const string VERSION = "1.7.3";
16+
public const string VERSION = "1.7.31";
1717
public const string AUTHOR = "Sinai";
1818
public const string GUID = "com.sinai.cppexplorer";
1919

src/Helpers/ReflectionHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static object Il2CppCast(object obj, Type castTo)
3636

3737
public static bool IsEnumerable(Type t)
3838
{
39-
return typeof(IEnumerable).IsAssignableFrom(t);
39+
return typeof(IEnumerable).IsAssignableFrom(t) || IsCppEnumerable(t);
4040
}
4141

4242
// Checks for Il2Cpp List or HashSet.
@@ -68,7 +68,8 @@ public static bool IsDictionary(Type t)
6868
}
6969
else
7070
{
71-
return typeof(Il2CppSystem.Collections.IDictionary).IsAssignableFrom(t);
71+
return typeof(Il2CppSystem.Collections.IDictionary).IsAssignableFrom(t)
72+
|| typeof(Il2CppSystem.Collections.Hashtable).IsAssignableFrom(t);
7273
}
7374
}
7475

src/Menu/MainMenu/Pages/SearchPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public static IEnumerable<object> GetInstanceClassScanner()
428428
{
429429
var t = ReflectionHelpers.GetActualType(obj);
430430

431-
if (!FilterName(t.FullName) || ReflectionHelpers.IsEnumerable(t) || ReflectionHelpers.IsCppEnumerable(t))
431+
if (!FilterName(t.FullName) || ReflectionHelpers.IsEnumerable(t))
432432
{
433433
continue;
434434
}

src/Tests/TestClass.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ public TestClass()
2222
ILHashSetTest.Add("3");
2323
}
2424

25+
// test a non-generic dictionary
26+
27+
public Hashtable TestNonGenericDict()
28+
{
29+
return new Hashtable
30+
{
31+
{ "One", 1 },
32+
{ "Two", 2 },
33+
{ "Three", 3 },
34+
};
35+
}
36+
37+
// IL2CPP HASHTABLE NOT SUPPORTED! Cannot assign Il2CppSystem.Object from primitive struct / string.
38+
// Technically they are "supported" but if they contain System types they will not work.
39+
40+
//public Il2CppSystem.Collections.Hashtable TestIl2CppNonGenericDict()
41+
//{
42+
// var table = new Il2CppSystem.Collections.Hashtable();
43+
// table.Add("One", 1);
44+
// table.Add("One", 2);
45+
// table.Add("One", 3);
46+
// return table;
47+
//}
48+
2549
// test HashSets
2650

2751
public static HashSet<string> HashSetTest = new HashSet<string>

0 commit comments

Comments
 (0)