From 66c30ee70e22d4bda935b86616ab3dc93fab0d7c Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Wed, 21 Jul 2021 20:48:21 +1000 Subject: [PATCH] Cleanup --- src/Core/Tests/TestClass.cs | 279 +++++++++++++----------------------- src/ExplorerCore.cs | 1 - 2 files changed, 101 insertions(+), 179 deletions(-) diff --git a/src/Core/Tests/TestClass.cs b/src/Core/Tests/TestClass.cs index 40a0fa4..0b4a502 100644 --- a/src/Core/Tests/TestClass.cs +++ b/src/Core/Tests/TestClass.cs @@ -14,112 +14,31 @@ using UnhollowerBaseLib; namespace UnityExplorer.Tests { - public class TestIndexer : IList - { - private readonly List list = new List() { 1, 2, 3, 4, 5 }; - - public int Count => list.Count; - public bool IsReadOnly => false; - - int IList.this[int index] - { - get => list[index]; - set => list[index] = value; - } - - public int IndexOf(int item) => list.IndexOf(item); - public bool Contains(int item) => list.Contains(item); - - public void Add(int item) => list.Add(item); - public void Insert(int index, int item) => list.Insert(index, item); - - public bool Remove(int item) => list.Remove(item); - public void RemoveAt(int index) => list.RemoveAt(index); - - public void Clear() => list.Clear(); - - public void CopyTo(int[] array, int arrayIndex) => list.CopyTo(array, arrayIndex); - - public IEnumerator GetEnumerator() => list.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => list.GetEnumerator(); - } - public static class TestClass { - public static readonly TestIndexer AAAAATest = new TestIndexer(); - - public static void ATestMethod(string s, float f, Vector3 vector, DateTime date, Quaternion quater, bool b, CameraClearFlags enumvalue) + static TestClass() { - ExplorerCore.Log($"{s}, {f}, {vector.ToString()}, {date}, {quater.eulerAngles.ToString()}, {b}, {enumvalue}"); + Init_Mono(); +#if CPP + Init_IL2CPP(); +#endif } - public static List AWritableList = new List { 1, 2, 3, 4, 5 }; - public static Dictionary AWritableDict = new Dictionary { { "one", 1 }, { "two", 2 } }; - - public static IEnumerable ANestedList = new List>> - { - new List> - { - new List - { - "one", - "two", - "one", - "two", - "one", - "two", - "one", - "two", - "one", - "two", - "one", - "two", - "one", - "two", - "one", - "two", - }, - new List - { - "three", - "four", - } - }, - new List> - { - new List - { - "five" - } - } - }; - - public static IDictionary ARandomDictionary = new Dictionary - { - { 1, 2 }, - { "one", "two" }, - { true, false }, - { new Vector3(0,1,2), new Vector3(1,2,3) }, - { CameraClearFlags.Depth, CameraClearFlags.Color }, - { "################################################\r\n##########", null }, - { "subdict", new Dictionary { { "key", "value" } } } - }; - - public static Hashtable TestHashtable = new Hashtable - { - { "one", "value" }, - { "two", "value" }, - { "three", "value" }, - }; - - public const int ConstantInt = 5; - - public static Color AColor = Color.magenta; - public static Color32 AColor32 = Color.red; - + // Test enumerables + public static List ListOfInts; + public static List>> NestedList; + public static IDictionary MixedDictionary; + public static Hashtable Hashtable; public static byte[] ByteArray = new byte[16]; - public static string LongString = new string('#', 10000); - public static List BigList = new List(10000); + public static List ABigList = new List(10000); + + // Test const behaviour (should be a readonly field) + public const int ConstantInt5 = 5; + + // Testing other InteractiveValues + public static Color Color = Color.magenta; + public static Color32 Color32 = Color.red; + public static string ALongString = new string('#', 10000); public static List RandomList { @@ -133,25 +52,7 @@ namespace UnityExplorer.Tests } } - private static void TestGeneric() - { - ExplorerCore.Log("Test1 " + typeof(T).FullName); - } - - private static void TestGenericClass() where T : class - { - ExplorerCore.Log("Test2 " + typeof(T).FullName); - } - - private static void TestComponent() where T : Component - { - ExplorerCore.Log("Test3 " + typeof(T).FullName); - } - - private static void TestStruct() where T : struct - { - ExplorerCore.Log("Test3 " + typeof(T).FullName); - } + // Test methods private static object GetRandomObject() { @@ -165,109 +66,133 @@ namespace UnityExplorer.Tests case 2: return true; case 3: return "hello"; case 4: return 50.5f; - case 5: return UnityEngine.CameraClearFlags.Color; - case 6: return new List { "sub list", "lol" }; + case 5: return CameraClearFlags.Color; + case 6: return new List { "one", "two" }; } return ret; } + public static void TestComponent() where T : Component + { + ExplorerCore.Log($"Test3 {typeof(T).FullName}"); + } + + public static void TestArgumentParse(string s, int i, Color color, CameraClearFlags flags, Vector3 vector, Quaternion quaternion) + { + ExplorerCore.Log($"{s}, {i}, {color.ToString()}, {flags}, {vector.ToString()}, {quaternion.ToString()}"); + } + + private static void Init_Mono() + { + ExplorerCore.Log($"1: Basic list"); + ListOfInts = new List { 1, 2, 3, 4, 5 }; + + ExplorerCore.Log($"2: Nested list"); + NestedList = new List>> + { + new List> { + new List { "1", "2", "3" }, + new List { "4", "5", "6" }, + }, + new List> + { + new List { "7", "8", "9" } + } + }; + + ExplorerCore.Log($"3: Dictionary"); + MixedDictionary = new Dictionary + { + { 1, 2 }, + { "one", "two" }, + { true, false }, + { new Vector3(0,1,2), new Vector3(1,2,3) }, + { CameraClearFlags.Depth, CameraClearFlags.Color }, + { "################################################\r\n##########", null }, + { "subdict", new Dictionary { { "key", "value" } } } + }; + + ExplorerCore.Log($"4: Hashtable"); + Hashtable = new Hashtable { { "One", 1 }, { "Two", 2 } }; + + ExplorerCore.Log($"5: Big list"); + for (int i = 0; i < ABigList.Capacity; i++) + ABigList[i] = (short)UnityEngine.Random.Range(0, short.MaxValue); + + ExplorerCore.Log("Finished TestClass Init_Mono"); + } + #if CPP - - public static Il2CppSystem.Collections.IList IL2CPP_IList; public static Il2CppSystem.Collections.Generic.List IL2CPP_ListString; - public static Il2CppSystem.Collections.Generic.HashSet IL2CPP_HashSet; - - public static Il2CppSystem.Collections.Generic.Dictionary IL2CPP_Dict; - public static Il2CppSystem.Collections.Hashtable IL2CPP_HashTable; - public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict; - - public static string IL2CPP_systemString = "Test"; - public static Il2CppSystem.Object IL2CPP_objectString = "string boxed as cpp object"; - public static Il2CppSystem.String IL2CPP_il2cppString = "string boxed as cpp string"; - public static string nullString = null; - public static List IL2CPP_listOfBoxedObjects; public static Il2CppStructArray IL2CPP_structArray; - public static Il2CppStringArray IL2CPP_stringArray; public static Il2CppReferenceArray IL2CPP_ReferenceArray; + public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict; + public static Il2CppSystem.Collections.IList IL2CPP_IList; + public static Dictionary CppBoxedDict; + public static Il2CppSystem.Collections.Generic.HashSet IL2CPP_HashSet; + public static Il2CppSystem.Collections.Generic.Dictionary IL2CPP_Dict; + public static Il2CppSystem.Collections.Hashtable IL2CPP_HashTable; public static Il2CppSystem.Object cppBoxedInt; public static Il2CppSystem.Int32 cppInt; public static Il2CppSystem.Decimal cppDecimal; public static Il2CppSystem.Object cppDecimalBoxed; public static Il2CppSystem.Object cppVector3Boxed; + public static string IL2CPP_systemString = "Test"; + public static Il2CppSystem.Object IL2CPP_objectString = "string boxed as cpp object"; + public static Il2CppSystem.String IL2CPP_il2cppString = "string boxed as cpp string"; + public static string nullString = null; - public static Il2CppSystem.Object RandomBoxedColor + private static void Init_IL2CPP() { - get - { - int ran = UnityEngine.Random.Range(0, 3); - switch (ran) - { - case 1: return new Color32().BoxIl2CppObject(); - case 2: return Color.magenta.BoxIl2CppObject(); - default: - return null; - } - } - } - - public static Il2CppSystem.Collections.Hashtable cppHashset; - - public static Dictionary CppBoxedDict; - -#endif - - static TestClass() - { - for (int i = 0; i < BigList.Capacity; i++) - BigList.Add(i.ToString()); - -#if CPP + ExplorerCore.Log($"IL2CPP 1: Il2Cpp Dictionary"); IL2CPP_Dict = new Il2CppSystem.Collections.Generic.Dictionary(); IL2CPP_Dict.Add("key1", "value1"); IL2CPP_Dict.Add("key2", "value2"); IL2CPP_Dict.Add("key3", "value3"); + ExplorerCore.Log($"IL2CPP 2: Il2Cpp Hashtable"); IL2CPP_HashTable = new Il2CppSystem.Collections.Hashtable(); IL2CPP_HashTable.Add("key1", "value1"); IL2CPP_HashTable.Add("key2", "value2"); IL2CPP_HashTable.Add("key3", "value3"); + ExplorerCore.Log($"IL2CPP 3: Il2Cpp IDictionary"); var dict2 = new Il2CppSystem.Collections.Generic.Dictionary(); dict2.Add("key1", "value1"); IL2CPP_IDict = dict2.TryCast(); + ExplorerCore.Log($"IL2CPP 4: Il2Cpp List of Il2Cpp Object"); var list = new Il2CppSystem.Collections.Generic.List(5); list.Add("one"); list.Add("two"); IL2CPP_IList = list.TryCast(); + ExplorerCore.Log($"IL2CPP 5: Il2Cpp List of strings"); IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List(); IL2CPP_ListString.Add("hello,"); IL2CPP_ListString.Add("world!"); + ExplorerCore.Log($"IL2CPP 6: Il2Cpp HashSet of strings"); IL2CPP_HashSet = new Il2CppSystem.Collections.Generic.HashSet(); IL2CPP_HashSet.Add("one"); IL2CPP_HashSet.Add("two"); + ExplorerCore.Log($"IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object"); CppBoxedDict = new Dictionary(); CppBoxedDict.Add("1", new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject()); CppBoxedDict.Add("2", new Il2CppSystem.Int32 { m_value = 2 }.BoxIl2CppObject()); CppBoxedDict.Add("3", new Il2CppSystem.Int32 { m_value = 3 }.BoxIl2CppObject()); CppBoxedDict.Add("4", new Il2CppSystem.Int32 { m_value = 4 }.BoxIl2CppObject()); - cppDecimal = new Il2CppSystem.Decimal(1f); - cppDecimalBoxed = new Il2CppSystem.Decimal(1f).BoxIl2CppObject(); - cppVector3Boxed = Vector3.down.BoxIl2CppObject(); - - + ExplorerCore.Log($"IL2CPP 8: List of boxed Il2Cpp Objects"); IL2CPP_listOfBoxedObjects = new List(); IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString"); IL2CPP_listOfBoxedObjects.Add(new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject()); IL2CPP_listOfBoxedObjects.Add(Color.red.BoxIl2CppObject()); - + // boxed enum test try { var cppType = Il2CppType.Of(); @@ -283,9 +208,10 @@ namespace UnityExplorer.Tests } catch (Exception ex) { - ExplorerCore.LogWarning($"Test fail: {ex}"); + ExplorerCore.LogWarning($"Boxed enum test fail: {ex}"); } + ExplorerCore.Log($"IL2CPP 9: Il2Cpp struct array of ints"); IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray(5); IL2CPP_structArray[0] = 0; IL2CPP_structArray[1] = 1; @@ -293,24 +219,21 @@ namespace UnityExplorer.Tests IL2CPP_structArray[3] = 3; IL2CPP_structArray[4] = 4; - IL2CPP_stringArray = new UnhollowerBaseLib.Il2CppStringArray(2); - IL2CPP_stringArray[0] = "hello, "; - IL2CPP_stringArray[1] = "world!"; - + ExplorerCore.Log($"IL2CPP 10: Il2Cpp reference array of boxed objects"); IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray(3); IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject(); IL2CPP_ReferenceArray[1] = null; IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up"; + ExplorerCore.Log($"IL2CPP 11: Misc il2cpp members"); cppBoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject(); cppInt = new Il2CppSystem.Int32 { m_value = 420 }; + cppDecimal = new Il2CppSystem.Decimal(1f); + cppDecimalBoxed = new Il2CppSystem.Decimal(1f).BoxIl2CppObject(); + cppVector3Boxed = Vector3.down.BoxIl2CppObject(); - cppHashset = new Il2CppSystem.Collections.Hashtable(); - cppHashset.Add("key1", "itemOne"); - cppHashset.Add("key2", "itemTwo"); - cppHashset.Add("key3", "itemThree"); - -#endif + ExplorerCore.Log($"Finished Init_Il2Cpp"); } +#endif } } diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 0f7ca21..944781d 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -14,7 +14,6 @@ using UnityExplorer.UI; using UnityExplorer.Inspectors; using UnityExplorer.ObjectExplorer; using UnityExplorer.UI.Panels; -using HarmonyLib; namespace UnityExplorer {