From d20461fa0e6acc8897d9dfd4e1698cf68845a566 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Fri, 4 Sep 2020 23:49:43 +1000 Subject: [PATCH] 1.5.5 * Fix for GetRootSceneObjects * Tidy ups --- src/CppExplorer.cs | 2 +- src/MainMenu/Pages/ScenePage.cs | 9 ++- src/Unstripping/GUIUnstrip.cs | 68 +++++++++-------------- src/Unstripping/ScrollViewStateUnstrip.cs | 9 +-- src/Unstripping/SliderHandlerUnstrip.cs | 9 +-- src/Unstripping/UnstripExtensions.cs | 7 ++- 6 files changed, 44 insertions(+), 60 deletions(-) diff --git a/src/CppExplorer.cs b/src/CppExplorer.cs index 0dc4dd1..02c1e18 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.4"; + public const string VERSION = "1.5.5"; public const string AUTHOR = "Sinai"; public const string NAME = "CppExplorer" diff --git a/src/MainMenu/Pages/ScenePage.cs b/src/MainMenu/Pages/ScenePage.cs index adc5a15..35f340b 100644 --- a/src/MainMenu/Pages/ScenePage.cs +++ b/src/MainMenu/Pages/ScenePage.cs @@ -75,9 +75,14 @@ namespace Explorer else { var scene = SceneManager.GetSceneByName(m_currentScene); - var rootObjects = scene.GetRootGameObjects(); - foreach (var obj in rootObjects) + var list = new Il2CppSystem.Collections.Generic.List + { + Capacity = scene.rootCount + }; + Scene.GetRootGameObjectsInternal(scene.handle, list); + + foreach (var obj in list) { allTransforms.Add(obj.transform); } diff --git a/src/Unstripping/GUIUnstrip.cs b/src/Unstripping/GUIUnstrip.cs index 95a6ff8..47f85e7 100644 --- a/src/Unstripping/GUIUnstrip.cs +++ b/src/Unstripping/GUIUnstrip.cs @@ -13,13 +13,10 @@ using Harmony; namespace Explorer { - // This is a manual unstrip of UnityEngine.GUI and UnityEngine.GUILayout methods. - // This code is provided "as-is". + // This is a copy+paste of UnityEngine source code, fixed for Il2Cpp. // Taken from dnSpy output using Unity 2018.4.20. - // "Unity", Unity logos, and other Unity trademarks are trademarks or - // registered trademarks of Unity Technologies or its affiliates in the - // U.S. and elsewhere. + // Subject to Unity's License and ToS. // https://unity3d.com/legal/terms-of-service // https://unity3d.com/legal/terms-of-service/software @@ -45,7 +42,7 @@ namespace Explorer // ======= public methods ======= // // Fix for GUILayoutUtility.GetLastRect(). - // Calls UnstripExtensions.GetLastUnstripped. + // Calls UnstripExtensions.GetLastUnstripped(). public static Rect GetLastRect() { @@ -62,24 +59,24 @@ namespace Explorer return last; } - // Fix for GUILayout.Scroller and GUILayout.ScrollerRepeatButton, just calling fixed implementations. - - public static float Scroller(Rect position, float value, float size, float leftValue, float rightValue, GUIStyle slider, GUIStyle thumb, GUIStyle leftButton, GUIStyle rightButton, bool horiz) - => Scroller_Impl(position, value, size, leftValue, rightValue, slider, thumb, leftButton, rightButton, horiz); - - public static bool ScrollerRepeatButton(int scrollerID, Rect rect, GUIStyle style) - => ScrollerRepeatButton_Impl(scrollerID, rect, style); - // Simple unstrips for HorizontalScrollbar and VerticalScrollbar, they just call the Scroller unstrip. public static float HorizontalScrollbar(Rect position, float value, float size, float leftValue, float rightValue, GUIStyle style) { - return Scroller(position, value, size, leftValue, rightValue, style, GUI.skin.GetStyle(style.name + "thumb"), GUI.skin.GetStyle(style.name + "leftbutton"), GUI.skin.GetStyle(style.name + "rightbutton"), true); + return Scroller_Impl(position, value, size, leftValue, rightValue, style, + GUI.skin.GetStyle(style.name + "thumb"), + GUI.skin.GetStyle(style.name + "leftbutton"), + GUI.skin.GetStyle(style.name + "rightbutton"), + true); } public static float VerticalScrollbar(Rect position, float value, float size, float topValue, float bottomValue, GUIStyle style) { - return Scroller(position, value, size, topValue, bottomValue, style, GUI.skin.GetStyle(style.name + "thumb"), GUI.skin.GetStyle(style.name + "upbutton"), GUI.skin.GetStyle(style.name + "downbutton"), false); + return Scroller_Impl(position, value, size, topValue, bottomValue, style, + GUI.skin.GetStyle(style.name + "thumb"), + GUI.skin.GetStyle(style.name + "upbutton"), + GUI.skin.GetStyle(style.name + "downbutton"), + false); } // Fix for BeginScrollView. @@ -106,7 +103,7 @@ namespace Explorer { try { - return BeginScrollView_Impl(scroll, false, false, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUI.skin.scrollView, options); + return BeginScrollView_ImplLayout(scroll, false, false, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUI.skin.scrollView, options); } catch (Exception e) { @@ -141,16 +138,13 @@ namespace Explorer // Actual unstrip of GUILayout.BeginScrollView() - private static Vector2 BeginScrollView_Impl(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, - GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options) + private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, + GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options) { GUIUtility.CheckOnGUI(); - var guiscrollGroup = (GUIScrollGroup)GUILayoutUtility.BeginLayoutGroup( - background, - null, - Il2CppType.Of() - ).Il2CppCast(typeof(GUIScrollGroup)); + var guiscrollGroup = GUILayoutUtility.BeginLayoutGroup(background, null, Il2CppType.Of()) + .TryCast(); EventType type = Event.current.type; if (type == EventType.Layout) @@ -177,16 +171,16 @@ namespace Explorer ); } - // Actual unstrip of GUI.BeginScrollView() -- note: not GUILayout. + // Actual unstrip of GUI.BeginScrollView() - private static Vector2 BeginScrollView_Impl(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, bool alwaysShowVertical, - GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background) + private static Vector2 BeginScrollView_Impl(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, + bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background) { GUIUtility.CheckOnGUI(); int controlID = GUIUtility.GetControlID(GUI.s_ScrollviewHash, FocusType.Passive); - var scrollViewState = (ScrollViewState)GUIUtility.GetStateObject(Il2CppType.Of(), controlID).Il2CppCast(typeof(ScrollViewState)); + var scrollViewState = GUIUtility.GetStateObject(Il2CppType.Of(), controlID).TryCast(); var scrollExt = ScrollViewStateUnstrip.FromPointer(scrollViewState.Pointer); @@ -310,16 +304,13 @@ namespace Explorer if (ScrollStack.Count <= 0) return; - //ScrollViewState scrollViewState = (ScrollViewState)GUI.s_ScrollViewStates.Peek(); - var state = (ScrollViewState)ScrollStack.Peek().Il2CppCast(typeof(ScrollViewState)); - //ScrollViewExtensions.Dict.TryGetValue(state.Pointer, out ScrollViewExtensions scrollExt); + var state = ScrollStack.Peek().TryCast(); var scrollExt = ScrollViewStateUnstrip.FromPointer(state.Pointer); if (scrollExt == null) throw new Exception("Could not get scrollExt!"); GUIClip.Pop(); - //GUI.s_ScrollViewStates.Pop(); ScrollStack.Pop(); var position = scrollExt.position; @@ -339,7 +330,6 @@ namespace Explorer pos.y = 0f; } - // state.apply = true; scrollExt.apply = true; Event.current.Use(); @@ -368,7 +358,6 @@ namespace Explorer rect2 = new Rect(position.x, position.yMax - rightButton.fixedHeight, position.width, rightButton.fixedHeight); } - //value = GUI.Slider(position2, value, size, leftValue, rightValue, slider, thumb, horiz, controlID); value = Slider(position2, value, size, leftValue, rightValue, slider, thumb, horiz, controlID); bool flag = Event.current.type == EventType.MouseUp; @@ -382,8 +371,7 @@ namespace Explorer } if (flag && Event.current.type == EventType.Used) { - //GUI.s_ScrollControlId = 0; - GUIUnstrip.s_ScrollControlId = 0; + s_ScrollControlId = 0; } if (leftValue < rightValue) { @@ -400,7 +388,6 @@ namespace Explorer public static float Slider(Rect position, float value, float size, float start, float end, GUIStyle slider, GUIStyle thumb, bool horiz, int id) { - //GUIUtility.CheckOnGUI(); if (id == 0) { id = GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive, position); @@ -416,11 +403,8 @@ namespace Explorer bool result = false; if (GUI.DoRepeatButton(rect, GUIContent.none, style, FocusType.Passive)) { - //bool flag = GUI.s_ScrollControlId != scrollerID; - //GUI.s_ScrollControlId = scrollerID; - - bool flag = GUIUnstrip.s_ScrollControlId != scrollerID; - GUIUnstrip.s_ScrollControlId = scrollerID; + bool flag = s_ScrollControlId != scrollerID; + s_ScrollControlId = scrollerID; if (flag) { diff --git a/src/Unstripping/ScrollViewStateUnstrip.cs b/src/Unstripping/ScrollViewStateUnstrip.cs index 560d263..575011f 100644 --- a/src/Unstripping/ScrollViewStateUnstrip.cs +++ b/src/Unstripping/ScrollViewStateUnstrip.cs @@ -8,14 +8,11 @@ using MelonLoader; using UnityEngine; namespace Explorer -{ - // This is a manual unstrip of UnityEngine.ScrollViewState. - // This code is provided "as-is". +{ + // This is a copy+paste of UnityEngine source code, fixed for Il2Cpp. // Taken from dnSpy output using Unity 2018.4.20. - // "Unity", Unity logos, and other Unity trademarks are trademarks or - // registered trademarks of Unity Technologies or its affiliates in the - // U.S. and elsewhere. + // Subject to Unity's License and ToS. // https://unity3d.com/legal/terms-of-service // https://unity3d.com/legal/terms-of-service/software diff --git a/src/Unstripping/SliderHandlerUnstrip.cs b/src/Unstripping/SliderHandlerUnstrip.cs index bd9231c..c56f417 100644 --- a/src/Unstripping/SliderHandlerUnstrip.cs +++ b/src/Unstripping/SliderHandlerUnstrip.cs @@ -8,13 +8,10 @@ using UnhollowerRuntimeLib; namespace Explorer { - // This is a manual unstrip of UnityEngine.SliderHandler. - // This code is provided "as-is". + // This is a copy+paste of UnityEngine source code, fixed for Il2Cpp. // Taken from dnSpy output using Unity 2018.4.20. - // "Unity", Unity logos, and other Unity trademarks are trademarks or - // registered trademarks of Unity Technologies or its affiliates in the - // U.S. and elsewhere. + // Subject to Unity's License and ToS. // https://unity3d.com/legal/terms-of-service // https://unity3d.com/legal/terms-of-service/software @@ -282,7 +279,7 @@ namespace Explorer private SliderState SliderState() { - return (SliderState)GUIUtility.GetStateObject(Il2CppType.Of(), this.id).Il2CppCast(typeof(SliderState)); + return (SliderState)GUIUtility.GetStateObject(Il2CppType.Of(), this.id).TryCast(); } private Rect ThumbRect() diff --git a/src/Unstripping/UnstripExtensions.cs b/src/Unstripping/UnstripExtensions.cs index fae1013..a231681 100644 --- a/src/Unstripping/UnstripExtensions.cs +++ b/src/Unstripping/UnstripExtensions.cs @@ -7,9 +7,10 @@ using UnityEngine; namespace Explorer { - // "Unity", Unity logos, and other Unity trademarks are trademarks or - // registered trademarks of Unity Technologies or its affiliates in the - // U.S. and elsewhere. + // This is a copy+paste of UnityEngine source code, fixed for Il2Cpp. + // Taken from dnSpy output using Unity 2018.4.20. + + // Subject to Unity's License and ToS. // https://unity3d.com/legal/terms-of-service // https://unity3d.com/legal/terms-of-service/software