From ffb6cad8c28c93ea22e045e93f2bc55fc67b72e3 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Sun, 6 Sep 2020 03:19:21 +1000 Subject: [PATCH] 1.5.7 * More fixes for failed unstripping, should fix most issues in Audica and other games * If `GetRootSceneObjects` fails and we fall back to the manual implementation, the auto-update for root scene objects will be disabled. Instead, there will be a button to press to update the list. * Transforms are now listed on the Components list in the GameObject inspector * Various cleanups --- src/CppExplorer.cs | 2 +- src/MainMenu/Pages/ConsolePage.cs | 2 +- src/MainMenu/Pages/ScenePage.cs | 77 +++++++++++++++++++------------ src/MainMenu/Pages/SearchPage.cs | 5 +- src/MainMenu/Pages/WindowPage.cs | 2 +- src/Windows/GameObjectWindow.cs | 24 ++++------ src/Windows/TabViewWindow.cs | 1 + src/Windows/WindowManager.cs | 2 +- 8 files changed, 65 insertions(+), 50 deletions(-) diff --git a/src/CppExplorer.cs b/src/CppExplorer.cs index 0c534b7..969f7e2 100644 --- a/src/CppExplorer.cs +++ b/src/CppExplorer.cs @@ -12,7 +12,7 @@ namespace Explorer public class CppExplorer : MelonMod { public const string GUID = "com.sinai.cppexplorer"; - public const string VERSION = "1.5.6"; + public const string VERSION = "1.5.7"; public const string AUTHOR = "Sinai"; public const string NAME = "CppExplorer" diff --git a/src/MainMenu/Pages/ConsolePage.cs b/src/MainMenu/Pages/ConsolePage.cs index 122778e..1162a30 100644 --- a/src/MainMenu/Pages/ConsolePage.cs +++ b/src/MainMenu/Pages/ConsolePage.cs @@ -14,7 +14,7 @@ namespace Explorer { public class ConsolePage : WindowPage { - public override string Name { get => "C# Console"; set => base.Name = value; } + public override string Name { get => "C# Console"; } private ScriptEvaluator _evaluator; private readonly StringBuilder _sb = new StringBuilder(); diff --git a/src/MainMenu/Pages/ScenePage.cs b/src/MainMenu/Pages/ScenePage.cs index 1def893..fc5ad32 100644 --- a/src/MainMenu/Pages/ScenePage.cs +++ b/src/MainMenu/Pages/ScenePage.cs @@ -17,9 +17,7 @@ namespace Explorer public PageHelper Pages = new PageHelper(); private float m_timeOfLastUpdate = -1f; - private static int PASSIVE_UPDATE_INTERVAL = 1; - - private static bool m_getRootObjectsFailed = false; + private const int PASSIVE_UPDATE_INTERVAL = 1; // ----- Holders for GUI elements ----- // @@ -54,7 +52,7 @@ namespace Explorer if (m_searching) CancelSearch(); - Update_Impl(); + Update_Impl(true); } public void TraverseUp() @@ -90,11 +88,12 @@ namespace Explorer { var matches = new List(); - foreach (var obj in Resources.FindObjectsOfTypeAll()) + foreach (var obj in Resources.FindObjectsOfTypeAll(ReflectionHelpers.GameObjectType)) { - if (obj.name.ToLower().Contains(_search.ToLower()) && obj.scene.name == m_currentScene) + var go = obj.TryCast(); + if (go.name.ToLower().Contains(_search.ToLower()) && go.scene.name == m_currentScene) { - matches.Add(new GameObjectCache(obj)); + matches.Add(new GameObjectCache(go)); } } @@ -111,9 +110,9 @@ namespace Explorer Update_Impl(); } - private void Update_Impl() + private void Update_Impl(bool manual = false) { - var allTransforms = new List(); + List allTransforms = new List(); // get current list of all transforms (either scene root or our current transform children) if (m_currentTransform) @@ -125,30 +124,26 @@ namespace Explorer } else { - if (!m_getRootObjectsFailed) + if (!manual && m_getRootObjectsFailed) return; + + if (!manual) { try { - var list = SceneManager.GetSceneByName(m_currentScene) - .GetRootGameObjects() - .ToArray(); + var scene = SceneManager.GetSceneByName(m_currentScene); - foreach (var obj in list) - { - allTransforms.Add(obj.transform); - } + allTransforms.AddRange(scene.GetRootGameObjects() + .Select(it => it.transform)); } catch { m_getRootObjectsFailed = true; - PASSIVE_UPDATE_INTERVAL = 2; - - allTransforms = GetRootObjectsManual_Impl(); + allTransforms.AddRange(GetRootObjectsManual_Impl()); } } else { - allTransforms = GetRootObjectsManual_Impl(); + allTransforms.AddRange(GetRootObjectsManual_Impl()); } } @@ -168,14 +163,30 @@ namespace Explorer } } - private List GetRootObjectsManual_Impl() + private IEnumerable GetRootObjectsManual_Impl() { - var allTransforms = Resources.FindObjectsOfTypeAll() - .Where(x => x.parent == null - && x.gameObject.scene.name == m_currentScene) - .ToList(); + try + { + var array = Resources.FindObjectsOfTypeAll(ReflectionHelpers.TransformType); - return allTransforms; + var list = new List(); + foreach (var obj in array) + { + var transform = obj.TryCast(); + if (transform.parent == null && transform.gameObject.scene.name == m_currentScene) + { + list.Add(transform); + } + } + return list; + } + catch (Exception e) + { + MelonLogger.Log("Exception getting root scene objects (manual): " + + e.GetType() + ", " + e.Message + "\r\n" + + e.StackTrace); + return new Transform[0]; + } } // --------- GUI Draw Function --------- // @@ -277,7 +288,7 @@ namespace Explorer { Pages.TurnPage(Turn.Left, ref this.scroll); - Update_Impl(); + Update_Impl(true); } Pages.CurrentPageLabel(); @@ -286,7 +297,7 @@ namespace Explorer { Pages.TurnPage(Turn.Right, ref this.scroll); - Update_Impl(); + Update_Impl(true); } } @@ -316,6 +327,14 @@ namespace Explorer else { GUILayout.Label("Scene Root GameObjects:", null); + + if (m_getRootObjectsFailed) + { + if (GUILayout.Button("Update Root Object List (auto-update failed!)", null)) + { + Update_Impl(true); + } + } } if (m_objectList.Count > 0) diff --git a/src/MainMenu/Pages/SearchPage.cs b/src/MainMenu/Pages/SearchPage.cs index dd9a627..33aee4f 100644 --- a/src/MainMenu/Pages/SearchPage.cs +++ b/src/MainMenu/Pages/SearchPage.cs @@ -13,7 +13,7 @@ namespace Explorer { public static SearchPage Instance; - public override string Name { get => "Object Search"; set => base.Name = value; } + public override string Name { get => "Object Search"; } private string m_searchInput = ""; private string m_typeInput = ""; @@ -318,7 +318,8 @@ namespace Explorer continue; } - if (searchType == ReflectionHelpers.ComponentType && ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetIl2CppType())) + if (searchType.FullName == ReflectionHelpers.ComponentType.FullName + && ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetIl2CppType())) { // Transforms shouldn't really be counted as Components, skip them. // They're more akin to GameObjects. diff --git a/src/MainMenu/Pages/WindowPage.cs b/src/MainMenu/Pages/WindowPage.cs index b4c056b..5f39be5 100644 --- a/src/MainMenu/Pages/WindowPage.cs +++ b/src/MainMenu/Pages/WindowPage.cs @@ -9,7 +9,7 @@ namespace Explorer { public abstract class WindowPage { - public virtual string Name { get; set; } + public virtual string Name { get; } public Vector2 scroll = Vector2.zero; diff --git a/src/Windows/GameObjectWindow.cs b/src/Windows/GameObjectWindow.cs index 754e060..5ae22d4 100644 --- a/src/Windows/GameObjectWindow.cs +++ b/src/Windows/GameObjectWindow.cs @@ -128,28 +128,22 @@ namespace Explorer m_object.transform.localScale = m_frozenScale; } - var list = new List(); + // update child objects + var childList = new List(); for (int i = 0; i < m_object.transform.childCount; i++) { - list.Add(m_object.transform.GetChild(i)); + childList.Add(m_object.transform.GetChild(i)); } - list.Sort((a, b) => b.childCount.CompareTo(a.childCount)); - m_children = list.ToArray(); + childList.Sort((a, b) => b.childCount.CompareTo(a.childCount)); + m_children = childList.ToArray(); ChildPages.ItemCount = m_children.Length; - var list2 = new List(); - foreach (var comp in m_object.GetComponents(ReflectionHelpers.ComponentType)) - { - var ilType = comp.GetIl2CppType(); - if (ilType == ReflectionHelpers.TransformType) - { - continue; - } + // update components + var compList = new Il2CppSystem.Collections.Generic.List(); + m_object.GetComponentsInternal(ReflectionHelpers.ComponentType, true, false, true, false, compList); - list2.Add(comp); - } - m_components = list2.ToArray(); + m_components = compList.ToArray(); CompPages.ItemCount = m_components.Length; } diff --git a/src/Windows/TabViewWindow.cs b/src/Windows/TabViewWindow.cs index 29ca491..7a4973b 100644 --- a/src/Windows/TabViewWindow.cs +++ b/src/Windows/TabViewWindow.cs @@ -26,6 +26,7 @@ namespace Explorer } public override void Init() { } + public override void Update() { while (TargetTabID >= WindowManager.Windows.Count) diff --git a/src/Windows/WindowManager.cs b/src/Windows/WindowManager.cs index 0288438..fd8f36a 100644 --- a/src/Windows/WindowManager.cs +++ b/src/Windows/WindowManager.cs @@ -109,7 +109,7 @@ namespace Explorer if (!equals && iObj is Il2CppSystem.Object iCurrent && window.Target is Il2CppSystem.Object iTarget) { - if (iCurrent.GetIl2CppType() != iTarget.GetIl2CppType()) + if (iCurrent.GetIl2CppType().FullName != iTarget.GetIl2CppType().FullName) { if (iCurrent is Transform transform) {