From 835a81765e6ea78c32a36165eddc34c61901d0f0 Mon Sep 17 00:00:00 2001
From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com>
Date: Fri, 11 Sep 2020 00:17:13 +1000
Subject: [PATCH] Add support for Hashset, add try/catch for loading settings
---
src/CachedObjects/CacheObjectBase.cs | 2 +-
src/CachedObjects/Object/CacheDictionary.cs | 2 +-
src/CachedObjects/Object/CacheList.cs | 36 +++++++++++++++---
src/CachedObjects/Struct/CacheColor.cs | 8 ++--
src/Config/ModConfig.cs | 41 ++++++++++++---------
src/CppExplorer.csproj | 8 +++-
src/Helpers/ReflectionHelpers.cs | 24 ++++++------
src/MainMenu/Pages/SearchPage.cs | 2 +-
src/Tests/TestClass.cs | 19 ++++++++++
src/Windows/ReflectionWindow.cs | 12 +++++-
10 files changed, 109 insertions(+), 45 deletions(-)
diff --git a/src/CachedObjects/CacheObjectBase.cs b/src/CachedObjects/CacheObjectBase.cs
index e1b673c..3f6d199 100644
--- a/src/CachedObjects/CacheObjectBase.cs
+++ b/src/CachedObjects/CacheObjectBase.cs
@@ -172,7 +172,7 @@ namespace Explorer
{
holder = new CacheDictionary();
}
- else if (ReflectionHelpers.IsEnumerable(valueType) || ReflectionHelpers.IsCppList(valueType))
+ else if (ReflectionHelpers.IsEnumerable(valueType) || ReflectionHelpers.IsCppEnumerable(valueType))
{
holder = new CacheList();
}
diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs
index af7530b..056eff1 100644
--- a/src/CachedObjects/Object/CacheDictionary.cs
+++ b/src/CachedObjects/Object/CacheDictionary.cs
@@ -228,7 +228,7 @@ namespace Explorer
var negativeWhitespace = window.width - (whitespace + 100f);
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
- string btnLabel = $"[{count}] Dictionary<{TypeOfKeys.FullName}, {TypeOfValues.FullName}>";
+ string btnLabel = $"[{count}] Dictionary<{TypeOfKeys.FullName}, {TypeOfValues.FullName}>";
if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.Width(negativeWhitespace) }))
{
WindowManager.InspectObject(Value, out bool _);
diff --git a/src/CachedObjects/Object/CacheList.cs b/src/CachedObjects/Object/CacheList.cs
index 6713d45..28c2971 100644
--- a/src/CachedObjects/Object/CacheList.cs
+++ b/src/CachedObjects/Object/CacheList.cs
@@ -40,7 +40,7 @@ namespace Explorer
private Type m_genericTypeDef;
// Cached ToArray method for Lists
- public MethodInfo GenericToArrayMethod
+ public MethodInfo CppListToArrayMethod
{
get => GetGenericToArrayMethod();
}
@@ -60,7 +60,7 @@ namespace Explorer
{
if (m_enumerable == null && Value != null)
{
- m_enumerable = Value as IEnumerable ?? GetEnumerableFromIl2CppList();
+ m_enumerable = Value as IEnumerable ?? EnumerateWithReflection();
}
return m_enumerable;
}
@@ -100,21 +100,45 @@ namespace Explorer
return m_itemProperty;
}
- private IEnumerable GetEnumerableFromIl2CppList()
+ private IEnumerable EnumerateWithReflection()
{
if (Value == null) return null;
if (GenericTypeDef == typeof(Il2CppSystem.Collections.Generic.List<>))
{
- return (IEnumerable)GenericToArrayMethod?.Invoke(Value, new object[0]);
+ return (IEnumerable)CppListToArrayMethod?.Invoke(Value, new object[0]);
+ }
+ else if (GenericTypeDef == typeof(Il2CppSystem.Collections.Generic.HashSet<>))
+ {
+ return CppHashSetToMono();
}
else
{
- return ConvertIListToMono();
+ return CppIListToMono();
}
}
- private IList ConvertIListToMono()
+ private IEnumerable CppHashSetToMono()
+ {
+ var set = new HashSet