Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
1.5.5
Browse files Browse the repository at this point in the history
* Fix for GetRootSceneObjects
* Tidy ups
  • Loading branch information
sinai-dev committed Sep 4, 2020
1 parent 72ec340 commit d20461f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/CppExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions src/MainMenu/Pages/ScenePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ public override void Update()
else
{
var scene = SceneManager.GetSceneByName(m_currentScene);
var rootObjects = scene.GetRootGameObjects();

foreach (var obj in rootObjects)
var list = new Il2CppSystem.Collections.Generic.List<GameObject>
{
Capacity = scene.rootCount
};
Scene.GetRootGameObjectsInternal(scene.handle, list);

foreach (var obj in list)
{
allTransforms.Add(obj.transform);
}
Expand Down
68 changes: 26 additions & 42 deletions src/Unstripping/GUIUnstrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@

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

Expand All @@ -45,7 +42,7 @@ private static GenericStack ScrollStack
// ======= public methods ======= //

// Fix for GUILayoutUtility.GetLastRect().
// Calls UnstripExtensions.GetLastUnstripped.
// Calls UnstripExtensions.GetLastUnstripped().

public static Rect GetLastRect()
{
Expand All @@ -62,24 +59,24 @@ public static Rect GetLastRect()
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.
Expand All @@ -106,7 +103,7 @@ public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] o
{
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)
{
Expand Down Expand Up @@ -141,16 +138,13 @@ public static void EndScrollView(bool handleScrollWheel = true)

// 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<GUIScrollGroup>()
).Il2CppCast(typeof(GUIScrollGroup));
var guiscrollGroup = GUILayoutUtility.BeginLayoutGroup(background, null, Il2CppType.Of<GUIScrollGroup>())
.TryCast<GUIScrollGroup>();

EventType type = Event.current.type;
if (type == EventType.Layout)
Expand All @@ -177,16 +171,16 @@ private static Vector2 BeginScrollView_Impl(Vector2 scrollPosition, bool alwaysS
);
}

// 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<ScrollViewState>(), controlID).Il2CppCast(typeof(ScrollViewState));
var scrollViewState = GUIUtility.GetStateObject(Il2CppType.Of<ScrollViewState>(), controlID).TryCast<ScrollViewState>();

var scrollExt = ScrollViewStateUnstrip.FromPointer(scrollViewState.Pointer);

Expand Down Expand Up @@ -310,16 +304,13 @@ private static void EndScrollView_Impl(bool handleScrollWheel)

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<ScrollViewState>();
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;
Expand All @@ -339,7 +330,6 @@ private static void EndScrollView_Impl(bool handleScrollWheel)
pos.y = 0f;
}

// state.apply = true;
scrollExt.apply = true;

Event.current.Use();
Expand Down Expand Up @@ -368,7 +358,6 @@ private static float Scroller_Impl(Rect position, float value, float size, float
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;
Expand All @@ -382,8 +371,7 @@ private static float Scroller_Impl(Rect position, float value, float size, float
}
if (flag && Event.current.type == EventType.Used)
{
//GUI.s_ScrollControlId = 0;
GUIUnstrip.s_ScrollControlId = 0;
s_ScrollControlId = 0;
}
if (leftValue < rightValue)
{
Expand All @@ -400,7 +388,6 @@ private static float Scroller_Impl(Rect position, float value, float size, float

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);
Expand All @@ -416,11 +403,8 @@ private static bool ScrollerRepeatButton_Impl(int scrollerID, Rect rect, GUIStyl
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)
{
Expand Down
9 changes: 3 additions & 6 deletions src/Unstripping/ScrollViewStateUnstrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
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

Expand Down
9 changes: 3 additions & 6 deletions src/Unstripping/SliderHandlerUnstrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

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

Expand Down Expand Up @@ -282,7 +279,7 @@ private void StartDraggingWithValue(float dragStartValue)

private SliderState SliderState()
{
return (SliderState)GUIUtility.GetStateObject(Il2CppType.Of<SliderState>(), this.id).Il2CppCast(typeof(SliderState));
return (SliderState)GUIUtility.GetStateObject(Il2CppType.Of<SliderState>(), this.id).TryCast<SliderState>();
}

private Rect ThumbRect()
Expand Down
7 changes: 4 additions & 3 deletions src/Unstripping/UnstripExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

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

Expand Down

0 comments on commit d20461f

Please sign in to comment.