From 0c3067973e18746348efb5823bbb867c5e66d9f7 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Thu, 13 Aug 2020 18:43:34 +1000 Subject: [PATCH] 1.3.2 cleanup - cleanup - fixed a mistake with FieldInfos on reflection window, causing all values to be null. - improved displaying of generic objects (now shows object Type after the name) --- src/Inspectors/Reflection/FieldInfoHolder.cs | 112 ++++++++++++------ .../Reflection/PropertyInfoHolder.cs | 5 +- src/Inspectors/ReflectionWindow.cs | 106 +++++++++-------- src/MainMenu/Pages/SearchPage.cs | 33 ++++-- src/UIStyles.cs | 52 +++----- .../Inspectors/Reflection/FieldInfoHolder.cs | 112 ++++++++++++------ .../Reflection/PropertyInfoHolder.cs | 5 +- src_2018/Inspectors/ReflectionWindow.cs | 106 +++++++++-------- src_2018/MainMenu/Pages/SearchPage.cs | 33 ++++-- src_2018/UIStyles.cs | 38 +++--- 10 files changed, 337 insertions(+), 265 deletions(-) diff --git a/src/Inspectors/Reflection/FieldInfoHolder.cs b/src/Inspectors/Reflection/FieldInfoHolder.cs index 4963a45..24b44a6 100644 --- a/src/Inspectors/Reflection/FieldInfoHolder.cs +++ b/src/Inspectors/Reflection/FieldInfoHolder.cs @@ -22,7 +22,24 @@ namespace Explorer public override void UpdateValue(object obj) { - m_value = fieldInfo.GetValue(fieldInfo.IsStatic ? null : obj); + try + { + if (obj is Il2CppSystem.Object ilObject) + { + var declaringType = this.fieldInfo.DeclaringType; + + var cast = CppExplorer.Il2CppCast(obj, declaringType); + m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : cast); + } + else + { + m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : obj); + } + } + catch (Exception e) + { + MelonLogger.Log($"Error updating FieldInfoHolder | {e.GetType()}: {e.Message}\r\n{e.StackTrace}"); + } } public override void Draw(ReflectionWindow window) @@ -32,51 +49,72 @@ namespace Explorer public override void SetValue(object obj) { - if (fieldInfo.FieldType.IsEnum) + try { - if (System.Enum.Parse(fieldInfo.FieldType, m_value.ToString()) is object enumValue && enumValue != null) + if (fieldInfo.FieldType.IsEnum) { - m_value = enumValue; - } - } - else if (fieldInfo.FieldType.IsPrimitive) - { - if (fieldInfo.FieldType == typeof(float)) - { - if (float.TryParse(m_value.ToString(), out float f)) + if (Enum.Parse(fieldInfo.FieldType, m_value.ToString()) is object enumValue && enumValue != null) { - m_value = f; + m_value = enumValue; + } + } + else if (fieldInfo.FieldType.IsPrimitive) + { + if (fieldInfo.FieldType == typeof(float)) + { + if (float.TryParse(m_value.ToString(), out float f)) + { + m_value = f; + } + else + { + MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!"); + } + } + else if (fieldInfo.FieldType == typeof(double)) + { + if (double.TryParse(m_value.ToString(), out double d)) + { + m_value = d; + } + else + { + MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!"); + } + } + else if (fieldInfo.FieldType != typeof(bool)) + { + if (int.TryParse(m_value.ToString(), out int i)) + { + m_value = i; + } + else + { + MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + fieldInfo.FieldType); + } } else { - MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!"); + MelonLogger.Log("Unsupported primitive field type: " + fieldInfo.FieldType.FullName); } } - else if (fieldInfo.FieldType == typeof(double)) - { - if (double.TryParse(m_value.ToString(), out double d)) - { - m_value = d; - } - else - { - MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!"); - } - } - else if (fieldInfo.FieldType != typeof(bool)) - { - if (int.TryParse(m_value.ToString(), out int i)) - { - m_value = i; - } - else - { - MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + fieldInfo.FieldType); - } - } - } - fieldInfo.SetValue(fieldInfo.IsStatic ? null : obj, m_value); + if (obj is Il2CppSystem.Object ilObject) + { + var declaringType = this.fieldInfo.DeclaringType; + + var cast = CppExplorer.Il2CppCast(obj, declaringType); + fieldInfo.SetValue(fieldInfo.IsStatic ? null : cast, m_value); + } + else + { + fieldInfo.SetValue(fieldInfo.IsStatic ? null : obj, m_value); + } + } + catch (Exception e) + { + MelonLogger.Log($"Error setting FieldInfoHolder | {e.GetType()}: {e.Message}\r\n{e.StackTrace}"); + } } } } diff --git a/src/Inspectors/Reflection/PropertyInfoHolder.cs b/src/Inspectors/Reflection/PropertyInfoHolder.cs index 41f2a16..594bb0a 100644 --- a/src/Inspectors/Reflection/PropertyInfoHolder.cs +++ b/src/Inspectors/Reflection/PropertyInfoHolder.cs @@ -33,6 +33,7 @@ namespace Explorer if (obj is Il2CppSystem.Object ilObject) { var declaringType = this.propInfo.DeclaringType; + if (declaringType == typeof(Il2CppObjectBase)) { m_value = ilObject.Pointer; @@ -40,7 +41,7 @@ namespace Explorer else { var cast = CppExplorer.Il2CppCast(obj, declaringType); - m_value = this.propInfo.GetValue(cast, null); + m_value = this.propInfo.GetValue(this.propInfo.GetAccessors()[0].IsStatic ? null : cast, null); } } else @@ -70,7 +71,7 @@ namespace Explorer { if (propInfo.PropertyType.IsEnum) { - if (System.Enum.Parse(propInfo.PropertyType, m_value.ToString()) is object enumValue && enumValue != null) + if (Enum.Parse(propInfo.PropertyType, m_value.ToString()) is object enumValue && enumValue != null) { m_value = enumValue; } diff --git a/src/Inspectors/ReflectionWindow.cs b/src/Inspectors/ReflectionWindow.cs index b1a4405..37da6c1 100644 --- a/src/Inspectors/ReflectionWindow.cs +++ b/src/Inspectors/ReflectionWindow.cs @@ -31,54 +31,6 @@ namespace Explorer Field } - public Type GetActualType(object m_object) - { - if (m_object is Il2CppSystem.Object ilObject) - { - var iltype = ilObject.GetIl2CppType(); - return Type.GetType(iltype.AssemblyQualifiedName); - } - else - { - return m_object.GetType(); - } - } - - public Type[] GetAllBaseTypes(object m_object) - { - var list = new List(); - - if (m_object is Il2CppSystem.Object ilObject) - { - var ilType = ilObject.GetIl2CppType(); - if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilTypeToManaged) - { - list.Add(ilTypeToManaged); - - while (ilType.BaseType != null) - { - ilType = ilType.BaseType; - if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilBaseTypeToManaged) - { - list.Add(ilBaseTypeToManaged); - } - } - } - } - else - { - var type = m_object.GetType(); - list.Add(type); - while (type.BaseType != null) - { - type = type.BaseType; - list.Add(type); - } - } - - return list.ToArray(); - } - public override void Init() { m_object = Target; @@ -101,7 +53,7 @@ namespace Explorer } catch { } - UpdateValues(); + UpdateValues(true); } public override void Update() @@ -112,9 +64,9 @@ namespace Explorer } } - private void UpdateValues() + private void UpdateValues(bool forceAll = false) { - if (m_filter == MemberFilter.Both || m_filter == MemberFilter.Field) + if (forceAll || m_filter == MemberFilter.Both || m_filter == MemberFilter.Field) { foreach (var holder in this.m_FieldInfos) { @@ -125,7 +77,7 @@ namespace Explorer } } - if (m_filter == MemberFilter.Both || m_filter == MemberFilter.Property) + if (forceAll || m_filter == MemberFilter.Both || m_filter == MemberFilter.Property) { foreach (var holder in this.m_PropertyInfos) { @@ -278,6 +230,56 @@ namespace Explorer GUI.color = Color.white; } + // ============ HELPERS =============== + + public Type GetActualType(object m_object) + { + if (m_object is Il2CppSystem.Object ilObject) + { + var iltype = ilObject.GetIl2CppType(); + return Type.GetType(iltype.AssemblyQualifiedName); + } + else + { + return m_object.GetType(); + } + } + + public Type[] GetAllBaseTypes(object m_object) + { + var list = new List(); + + if (m_object is Il2CppSystem.Object ilObject) + { + var ilType = ilObject.GetIl2CppType(); + if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilTypeToManaged) + { + list.Add(ilTypeToManaged); + + while (ilType.BaseType != null) + { + ilType = ilType.BaseType; + if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilBaseTypeToManaged) + { + list.Add(ilBaseTypeToManaged); + } + } + } + } + else + { + var type = m_object.GetType(); + list.Add(type); + while (type.BaseType != null) + { + type = type.BaseType; + list.Add(type); + } + } + + return list.ToArray(); + } + public static bool IsList(Type t) { return t.IsGenericType diff --git a/src/MainMenu/Pages/SearchPage.cs b/src/MainMenu/Pages/SearchPage.cs index 6129bde..bb418cd 100644 --- a/src/MainMenu/Pages/SearchPage.cs +++ b/src/MainMenu/Pages/SearchPage.cs @@ -20,7 +20,7 @@ namespace Explorer private string m_searchInput = ""; private string m_typeInput = ""; - private int m_limit = 100; + private int m_limit = 20; private int m_pageOffset = 0; private List m_searchResults = new List(); private Vector2 resultsScroll = Vector2.zero; @@ -85,11 +85,11 @@ namespace Explorer int count = m_searchResults.Count; - if (count > CppExplorer.ArrayLimit) + if (count > this.m_limit) { // prev/next page buttons GUILayout.BeginHorizontal(null); - int maxOffset = (int)Mathf.Ceil(count / CppExplorer.ArrayLimit); + int maxOffset = (int)Mathf.Ceil(count / this.m_limit); if (GUILayout.Button("< Prev", null)) { if (m_pageOffset > 0) m_pageOffset--; @@ -110,7 +110,7 @@ namespace Explorer if (m_searchResults.Count > 0) { - int offset = m_pageOffset * CppExplorer.ArrayLimit; + int offset = m_pageOffset * this.m_limit; int preiterated = 0; if (offset >= count) m_pageOffset = 0; @@ -123,7 +123,7 @@ namespace Explorer continue; } - if (i - offset > CppExplorer.ArrayLimit - 1) + if (i - offset > this.m_limit - 1) { break; } @@ -257,14 +257,14 @@ namespace Explorer private List FindAllObjectsOfType(string _search, string _type) { - Il2CppSystem.Type type = null; + Il2CppSystem.Type searchType = null; if (TypeMode == TypeFilter.Custom) { try { var findType = CppExplorer.GetType(_type); - type = Il2CppSystem.Type.GetType(findType.AssemblyQualifiedName); + searchType = Il2CppSystem.Type.GetType(findType.AssemblyQualifiedName); } catch (Exception e) { @@ -273,26 +273,26 @@ namespace Explorer } else if (TypeMode == TypeFilter.Object) { - type = CppExplorer.ObjectType; + searchType = CppExplorer.ObjectType; } else if (TypeMode == TypeFilter.GameObject) { - type = CppExplorer.GameObjectType; + searchType = CppExplorer.GameObjectType; } else if (TypeMode == TypeFilter.Component) { - type = CppExplorer.ComponentType; + searchType = CppExplorer.ComponentType; } - if (!CppExplorer.ObjectType.IsAssignableFrom(type)) + if (!CppExplorer.ObjectType.IsAssignableFrom(searchType)) { - MelonLogger.LogError("Your Class Type must inherit from UnityEngine.Object! Leave blank to default to UnityEngine.Object"); + MelonLogger.LogError("Your Custom Class Type must inherit from UnityEngine.Object!"); return new List(); } var matches = new List(); - var allObjectsOfType = Resources.FindObjectsOfTypeAll(type); + var allObjectsOfType = Resources.FindObjectsOfTypeAll(searchType); foreach (var obj in allObjectsOfType) { @@ -301,6 +301,13 @@ namespace Explorer continue; } + if (searchType == CppExplorer.ComponentType && CppExplorer.TransformType.IsAssignableFrom(obj.GetIl2CppType())) + { + // Transforms shouldn't really be counted as Components, skip them. + // They're more akin to GameObjects. + continue; + } + if (SceneMode != SceneFilter.Any && !FilterScene(obj, this.SceneMode)) { continue; diff --git a/src/UIStyles.cs b/src/UIStyles.cs index 4e97484..dcf8480 100644 --- a/src/UIStyles.cs +++ b/src/UIStyles.cs @@ -236,21 +236,8 @@ namespace Explorer { DrawPrimitive(ref value, rect, setTarget, setAction); } - //else if (valueType == typeof(GameObject) || typeof(Component).IsAssignableFrom(valueType)) - else if (ilType != null && ilType == CppExplorer.GameObjectType || CppExplorer.ComponentType.IsAssignableFrom(ilType)) - { - //GameObject go; - //if (value.GetType() == typeof(Transform)) - //{ - // go = (value as Transform).gameObject; - //} - //else - //{ - // go = (value as GameObject); - //} - - //var go = (value as GameObject) ?? (value as Component).gameObject; - + else if (ilType != null && ilType == CppExplorer.GameObjectType || CppExplorer.TransformType.IsAssignableFrom(ilType)) + { GameObject go; var ilObj = value as Il2CppSystem.Object; if (ilType == CppExplorer.GameObjectType) @@ -259,7 +246,7 @@ namespace Explorer } else { - go = ilObj.TryCast().gameObject; + go = ilObj.TryCast().gameObject; } GameobjButton(go, null, false, rect.width - 250); @@ -438,6 +425,20 @@ namespace Explorer label = col.ToString(); } + string typeLabel; + if (ilType != null) + { + typeLabel = ilType.FullName; + } + else + { + typeLabel = value.GetType().FullName; + } + if (!label.Contains(typeLabel)) + { + label += $" ({typeLabel})"; + } + GUI.skin.button.alignment = TextAnchor.MiddleLeft; if (GUILayout.Button("" + label + "", new GUILayoutOption[] { GUILayout.MaxWidth(rect.width - 230) })) { @@ -447,25 +448,6 @@ namespace Explorer } } - //public static void DrawMember(ref object value, string valueType, string memberName, Rect rect, object setTarget = null, Action setAction = null, float labelWidth = 180, bool autoSet = false) - //{ - // GUILayout.Label("" + memberName + ":", new GUILayoutOption[] { GUILayout.Width(labelWidth) }); - - // DrawValue(ref value, rect, valueType, memberName, setTarget, setAction, autoSet); - //} - - //public static void DrawValue(ref object value, Rect rect, string nullValueType = null, string memberName = null, object setTarget = null, Action setAction = null, bool autoSet = false) - //{ - // if (value == null) - // { - // GUILayout.Label("null (" + nullValueType + ")", null); - // } - // else - // { - - // } - //} - // Helper for drawing primitive values (with Apply button) public static void DrawPrimitive(ref object value, Rect m_rect, object setTarget = null, Action setAction = null, bool autoSet = false) diff --git a/src_2018/Inspectors/Reflection/FieldInfoHolder.cs b/src_2018/Inspectors/Reflection/FieldInfoHolder.cs index 4963a45..24b44a6 100644 --- a/src_2018/Inspectors/Reflection/FieldInfoHolder.cs +++ b/src_2018/Inspectors/Reflection/FieldInfoHolder.cs @@ -22,7 +22,24 @@ namespace Explorer public override void UpdateValue(object obj) { - m_value = fieldInfo.GetValue(fieldInfo.IsStatic ? null : obj); + try + { + if (obj is Il2CppSystem.Object ilObject) + { + var declaringType = this.fieldInfo.DeclaringType; + + var cast = CppExplorer.Il2CppCast(obj, declaringType); + m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : cast); + } + else + { + m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : obj); + } + } + catch (Exception e) + { + MelonLogger.Log($"Error updating FieldInfoHolder | {e.GetType()}: {e.Message}\r\n{e.StackTrace}"); + } } public override void Draw(ReflectionWindow window) @@ -32,51 +49,72 @@ namespace Explorer public override void SetValue(object obj) { - if (fieldInfo.FieldType.IsEnum) + try { - if (System.Enum.Parse(fieldInfo.FieldType, m_value.ToString()) is object enumValue && enumValue != null) + if (fieldInfo.FieldType.IsEnum) { - m_value = enumValue; - } - } - else if (fieldInfo.FieldType.IsPrimitive) - { - if (fieldInfo.FieldType == typeof(float)) - { - if (float.TryParse(m_value.ToString(), out float f)) + if (Enum.Parse(fieldInfo.FieldType, m_value.ToString()) is object enumValue && enumValue != null) { - m_value = f; + m_value = enumValue; + } + } + else if (fieldInfo.FieldType.IsPrimitive) + { + if (fieldInfo.FieldType == typeof(float)) + { + if (float.TryParse(m_value.ToString(), out float f)) + { + m_value = f; + } + else + { + MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!"); + } + } + else if (fieldInfo.FieldType == typeof(double)) + { + if (double.TryParse(m_value.ToString(), out double d)) + { + m_value = d; + } + else + { + MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!"); + } + } + else if (fieldInfo.FieldType != typeof(bool)) + { + if (int.TryParse(m_value.ToString(), out int i)) + { + m_value = i; + } + else + { + MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + fieldInfo.FieldType); + } } else { - MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!"); + MelonLogger.Log("Unsupported primitive field type: " + fieldInfo.FieldType.FullName); } } - else if (fieldInfo.FieldType == typeof(double)) - { - if (double.TryParse(m_value.ToString(), out double d)) - { - m_value = d; - } - else - { - MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!"); - } - } - else if (fieldInfo.FieldType != typeof(bool)) - { - if (int.TryParse(m_value.ToString(), out int i)) - { - m_value = i; - } - else - { - MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + fieldInfo.FieldType); - } - } - } - fieldInfo.SetValue(fieldInfo.IsStatic ? null : obj, m_value); + if (obj is Il2CppSystem.Object ilObject) + { + var declaringType = this.fieldInfo.DeclaringType; + + var cast = CppExplorer.Il2CppCast(obj, declaringType); + fieldInfo.SetValue(fieldInfo.IsStatic ? null : cast, m_value); + } + else + { + fieldInfo.SetValue(fieldInfo.IsStatic ? null : obj, m_value); + } + } + catch (Exception e) + { + MelonLogger.Log($"Error setting FieldInfoHolder | {e.GetType()}: {e.Message}\r\n{e.StackTrace}"); + } } } } diff --git a/src_2018/Inspectors/Reflection/PropertyInfoHolder.cs b/src_2018/Inspectors/Reflection/PropertyInfoHolder.cs index 41f2a16..594bb0a 100644 --- a/src_2018/Inspectors/Reflection/PropertyInfoHolder.cs +++ b/src_2018/Inspectors/Reflection/PropertyInfoHolder.cs @@ -33,6 +33,7 @@ namespace Explorer if (obj is Il2CppSystem.Object ilObject) { var declaringType = this.propInfo.DeclaringType; + if (declaringType == typeof(Il2CppObjectBase)) { m_value = ilObject.Pointer; @@ -40,7 +41,7 @@ namespace Explorer else { var cast = CppExplorer.Il2CppCast(obj, declaringType); - m_value = this.propInfo.GetValue(cast, null); + m_value = this.propInfo.GetValue(this.propInfo.GetAccessors()[0].IsStatic ? null : cast, null); } } else @@ -70,7 +71,7 @@ namespace Explorer { if (propInfo.PropertyType.IsEnum) { - if (System.Enum.Parse(propInfo.PropertyType, m_value.ToString()) is object enumValue && enumValue != null) + if (Enum.Parse(propInfo.PropertyType, m_value.ToString()) is object enumValue && enumValue != null) { m_value = enumValue; } diff --git a/src_2018/Inspectors/ReflectionWindow.cs b/src_2018/Inspectors/ReflectionWindow.cs index b1a4405..37da6c1 100644 --- a/src_2018/Inspectors/ReflectionWindow.cs +++ b/src_2018/Inspectors/ReflectionWindow.cs @@ -31,54 +31,6 @@ namespace Explorer Field } - public Type GetActualType(object m_object) - { - if (m_object is Il2CppSystem.Object ilObject) - { - var iltype = ilObject.GetIl2CppType(); - return Type.GetType(iltype.AssemblyQualifiedName); - } - else - { - return m_object.GetType(); - } - } - - public Type[] GetAllBaseTypes(object m_object) - { - var list = new List(); - - if (m_object is Il2CppSystem.Object ilObject) - { - var ilType = ilObject.GetIl2CppType(); - if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilTypeToManaged) - { - list.Add(ilTypeToManaged); - - while (ilType.BaseType != null) - { - ilType = ilType.BaseType; - if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilBaseTypeToManaged) - { - list.Add(ilBaseTypeToManaged); - } - } - } - } - else - { - var type = m_object.GetType(); - list.Add(type); - while (type.BaseType != null) - { - type = type.BaseType; - list.Add(type); - } - } - - return list.ToArray(); - } - public override void Init() { m_object = Target; @@ -101,7 +53,7 @@ namespace Explorer } catch { } - UpdateValues(); + UpdateValues(true); } public override void Update() @@ -112,9 +64,9 @@ namespace Explorer } } - private void UpdateValues() + private void UpdateValues(bool forceAll = false) { - if (m_filter == MemberFilter.Both || m_filter == MemberFilter.Field) + if (forceAll || m_filter == MemberFilter.Both || m_filter == MemberFilter.Field) { foreach (var holder in this.m_FieldInfos) { @@ -125,7 +77,7 @@ namespace Explorer } } - if (m_filter == MemberFilter.Both || m_filter == MemberFilter.Property) + if (forceAll || m_filter == MemberFilter.Both || m_filter == MemberFilter.Property) { foreach (var holder in this.m_PropertyInfos) { @@ -278,6 +230,56 @@ namespace Explorer GUI.color = Color.white; } + // ============ HELPERS =============== + + public Type GetActualType(object m_object) + { + if (m_object is Il2CppSystem.Object ilObject) + { + var iltype = ilObject.GetIl2CppType(); + return Type.GetType(iltype.AssemblyQualifiedName); + } + else + { + return m_object.GetType(); + } + } + + public Type[] GetAllBaseTypes(object m_object) + { + var list = new List(); + + if (m_object is Il2CppSystem.Object ilObject) + { + var ilType = ilObject.GetIl2CppType(); + if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilTypeToManaged) + { + list.Add(ilTypeToManaged); + + while (ilType.BaseType != null) + { + ilType = ilType.BaseType; + if (Type.GetType(ilType.AssemblyQualifiedName) is Type ilBaseTypeToManaged) + { + list.Add(ilBaseTypeToManaged); + } + } + } + } + else + { + var type = m_object.GetType(); + list.Add(type); + while (type.BaseType != null) + { + type = type.BaseType; + list.Add(type); + } + } + + return list.ToArray(); + } + public static bool IsList(Type t) { return t.IsGenericType diff --git a/src_2018/MainMenu/Pages/SearchPage.cs b/src_2018/MainMenu/Pages/SearchPage.cs index 3259bc6..dd90854 100644 --- a/src_2018/MainMenu/Pages/SearchPage.cs +++ b/src_2018/MainMenu/Pages/SearchPage.cs @@ -20,7 +20,7 @@ namespace Explorer private string m_searchInput = ""; private string m_typeInput = ""; - private int m_limit = 100; + private int m_limit = 20; private int m_pageOffset = 0; private List m_searchResults = new List(); private Vector2 resultsScroll = Vector2.zero; @@ -85,11 +85,11 @@ namespace Explorer int count = m_searchResults.Count; - if (count > CppExplorer.ArrayLimit) + if (count > this.m_limit) { // prev/next page buttons GUILayout.BeginHorizontal(null); - int maxOffset = (int)Mathf.Ceil(count / CppExplorer.ArrayLimit); + int maxOffset = (int)Mathf.Ceil(count / this.m_limit); if (GUILayout.Button("< Prev", null)) { if (m_pageOffset > 0) m_pageOffset--; @@ -110,7 +110,7 @@ namespace Explorer if (m_searchResults.Count > 0) { - int offset = m_pageOffset * CppExplorer.ArrayLimit; + int offset = m_pageOffset * this.m_limit; int preiterated = 0; if (offset >= count) m_pageOffset = 0; @@ -123,7 +123,7 @@ namespace Explorer continue; } - if (i - offset > CppExplorer.ArrayLimit - 1) + if (i - offset > this.m_limit - 1) { break; } @@ -257,14 +257,14 @@ namespace Explorer private List FindAllObjectsOfType(string _search, string _type) { - Il2CppSystem.Type type = null; + Il2CppSystem.Type searchType = null; if (TypeMode == TypeFilter.Custom) { try { var findType = CppExplorer.GetType(_type); - type = Il2CppSystem.Type.GetType(findType.AssemblyQualifiedName); + searchType = Il2CppSystem.Type.GetType(findType.AssemblyQualifiedName); } catch (Exception e) { @@ -273,26 +273,26 @@ namespace Explorer } else if (TypeMode == TypeFilter.Object) { - type = CppExplorer.ObjectType; + searchType = CppExplorer.ObjectType; } else if (TypeMode == TypeFilter.GameObject) { - type = CppExplorer.GameObjectType; + searchType = CppExplorer.GameObjectType; } else if (TypeMode == TypeFilter.Component) { - type = CppExplorer.ComponentType; + searchType = CppExplorer.ComponentType; } - if (!CppExplorer.ObjectType.IsAssignableFrom(type)) + if (!CppExplorer.ObjectType.IsAssignableFrom(searchType)) { - MelonLogger.LogError("Your Class Type must inherit from UnityEngine.Object! Leave blank to default to UnityEngine.Object"); + MelonLogger.LogError("Your Custom Class Type must inherit from UnityEngine.Object!"); return new List(); } var matches = new List(); - var allObjectsOfType = Resources.FindObjectsOfTypeAll(type); + var allObjectsOfType = Resources.FindObjectsOfTypeAll(searchType); foreach (var obj in allObjectsOfType) { @@ -301,6 +301,13 @@ namespace Explorer continue; } + if (searchType == CppExplorer.ComponentType && CppExplorer.TransformType.IsAssignableFrom(obj.GetIl2CppType())) + { + // Transforms shouldn't really be counted as Components, skip them. + // They're more akin to GameObjects. + continue; + } + if (SceneMode != SceneFilter.Any && !FilterScene(obj, this.SceneMode)) { continue; diff --git a/src_2018/UIStyles.cs b/src_2018/UIStyles.cs index 568625f..5a0f542 100644 --- a/src_2018/UIStyles.cs +++ b/src_2018/UIStyles.cs @@ -236,8 +236,7 @@ namespace Explorer { DrawPrimitive(ref value, rect, setTarget, setAction); } - //else if (valueType == typeof(GameObject) || typeof(Component).IsAssignableFrom(valueType)) - else if (ilType != null && ilType == CppExplorer.GameObjectType || CppExplorer.ComponentType.IsAssignableFrom(ilType)) + else if (ilType != null && ilType == CppExplorer.GameObjectType || CppExplorer.TransformType.IsAssignableFrom(ilType)) { GameObject go; var ilObj = value as Il2CppSystem.Object; @@ -247,7 +246,7 @@ namespace Explorer } else { - go = ilObj.TryCast().gameObject; + go = ilObj.TryCast().gameObject; } GameobjButton(go, null, false, rect.width - 250); @@ -426,6 +425,20 @@ namespace Explorer label = col.ToString(); } + string typeLabel; + if (ilType != null) + { + typeLabel = ilType.FullName; + } + else + { + typeLabel = value.GetType().FullName; + } + if (!label.Contains(typeLabel)) + { + label += $" ({typeLabel})"; + } + GUI.skin.button.alignment = TextAnchor.MiddleLeft; if (GUILayout.Button("" + label + "", new GUILayoutOption[] { GUILayout.MaxWidth(rect.width - 230) })) { @@ -435,25 +448,6 @@ namespace Explorer } } - //public static void DrawMember(ref object value, string valueType, string memberName, Rect rect, object setTarget = null, Action setAction = null, float labelWidth = 180, bool autoSet = false) - //{ - // GUILayout.Label("" + memberName + ":", new GUILayoutOption[] { GUILayout.Width(labelWidth) }); - - // DrawValue(ref value, rect, valueType, memberName, setTarget, setAction, autoSet); - //} - - //public static void DrawValue(ref object value, Rect rect, string nullValueType = null, string memberName = null, object setTarget = null, Action setAction = null, bool autoSet = false) - //{ - // if (value == null) - // { - // GUILayout.Label("null (" + nullValueType + ")", null); - // } - // else - // { - - // } - //} - // Helper for drawing primitive values (with Apply button) public static void DrawPrimitive(ref object value, Rect m_rect, object setTarget = null, Action setAction = null, bool autoSet = false)