* 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
This commit is contained in:
sinaioutlander 2020-09-15 17:38:10 +10:00
parent eea581f8d5
commit 5d58993b07
6 changed files with 39 additions and 35 deletions

View File

@ -172,7 +172,7 @@ namespace Explorer
{ {
holder = new CacheDictionary(); holder = new CacheDictionary();
} }
else if (ReflectionHelpers.IsEnumerable(valueType) || ReflectionHelpers.IsCppEnumerable(valueType)) else if (ReflectionHelpers.IsEnumerable(valueType))
{ {
holder = new CacheList(); holder = new CacheList();
} }

View File

@ -98,37 +98,16 @@ namespace Explorer
private void GetGenericArguments() private void GetGenericArguments()
{ {
if (this.MemInfo != null) if (ValueType.IsGenericType)
{ {
Type memberType = null; m_keysType = ValueType.GetGenericArguments()[0];
switch (this.MemInfo.MemberType) m_valuesType = ValueType.GetGenericArguments()[1];
{
case MemberTypes.Field:
memberType = (MemInfo as FieldInfo).FieldType;
break;
case MemberTypes.Property:
memberType = (MemInfo as PropertyInfo).PropertyType;
break;
}
if (memberType != null && memberType.IsGenericType)
{
m_keysType = memberType.GetGenericArguments()[0];
m_valuesType = memberType.GetGenericArguments()[1];
}
} }
else if (Value != null) else
{ {
var type = Value.GetType(); // It's non-generic, just use System.Object to allow for anything.
if (type.IsGenericType) m_keysType = typeof(object);
{ m_valuesType = typeof(object);
m_keysType = type.GetGenericArguments()[0];
m_valuesType = type.GetGenericArguments()[1];
}
else
{
MelonLogger.Log("TODO? Dictionary is of type: " + Value.GetType().FullName);
}
} }
} }
@ -288,10 +267,10 @@ namespace Explorer
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) }); GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) }); GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) });
key.DrawValue(window, (window.width / 2) - 30f); key.DrawValue(window, (window.width / 2) - 80f);
GUILayout.Label("Value:", new GUILayoutOption[] { GUILayout.Width(40) }); GUILayout.Label("Value:", new GUILayoutOption[] { GUILayout.Width(40) });
val.DrawValue(window, (window.width / 2) - 30f); val.DrawValue(window, (window.width / 2) - 80f);
} }
} }

View File

@ -13,7 +13,7 @@ namespace Explorer
public class CppExplorer : MelonMod public class CppExplorer : MelonMod
{ {
public const string NAME = "CppExplorer"; public const string NAME = "CppExplorer";
public const string VERSION = "1.7.3"; public const string VERSION = "1.7.31";
public const string AUTHOR = "Sinai"; public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.cppexplorer"; public const string GUID = "com.sinai.cppexplorer";

View File

@ -36,7 +36,7 @@ namespace Explorer
public static bool IsEnumerable(Type t) public static bool IsEnumerable(Type t)
{ {
return typeof(IEnumerable).IsAssignableFrom(t); return typeof(IEnumerable).IsAssignableFrom(t) || IsCppEnumerable(t);
} }
// Checks for Il2Cpp List or HashSet. // Checks for Il2Cpp List or HashSet.
@ -68,7 +68,8 @@ namespace Explorer
} }
else else
{ {
return typeof(Il2CppSystem.Collections.IDictionary).IsAssignableFrom(t); return typeof(Il2CppSystem.Collections.IDictionary).IsAssignableFrom(t)
|| typeof(Il2CppSystem.Collections.Hashtable).IsAssignableFrom(t);
} }
} }

View File

@ -428,7 +428,7 @@ namespace Explorer
{ {
var t = ReflectionHelpers.GetActualType(obj); var t = ReflectionHelpers.GetActualType(obj);
if (!FilterName(t.FullName) || ReflectionHelpers.IsEnumerable(t) || ReflectionHelpers.IsCppEnumerable(t)) if (!FilterName(t.FullName) || ReflectionHelpers.IsEnumerable(t))
{ {
continue; continue;
} }

View File

@ -22,6 +22,30 @@ namespace Explorer.Tests
ILHashSetTest.Add("3"); ILHashSetTest.Add("3");
} }
// test a non-generic dictionary
public Hashtable TestNonGenericDict()
{
return new Hashtable
{
{ "One", 1 },
{ "Two", 2 },
{ "Three", 3 },
};
}
// IL2CPP HASHTABLE NOT SUPPORTED! Cannot assign Il2CppSystem.Object from primitive struct / string.
// Technically they are "supported" but if they contain System types they will not work.
//public Il2CppSystem.Collections.Hashtable TestIl2CppNonGenericDict()
//{
// var table = new Il2CppSystem.Collections.Hashtable();
// table.Add("One", 1);
// table.Add("One", 2);
// table.Add("One", 3);
// return table;
//}
// test HashSets // test HashSets
public static HashSet<string> HashSetTest = new HashSet<string> public static HashSet<string> HashSetTest = new HashSet<string>