* Implemented manual unstripping for ScrollView and Resize, should now work on any Unity 2018 or 2019 game.
* Fixed a bug with page view on the Scene Explorer
* Back-end cleanups
This commit is contained in:
sinaioutlander
2020-09-04 21:36:40 +10:00
parent 5de771389e
commit 6adaaf5500
17 changed files with 1002 additions and 103 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Explorer
{
public override void DrawValue(Rect window, float width)
{
UIHelpers.GameobjButton(Value, null, false, width);
UIHelpers.GOButton(Value, null, false, width);
}
public override void UpdateValue()
+4 -8
View File
@@ -279,19 +279,15 @@ namespace Explorer
ClampLabelWidth(window, ref whitespace);
}
Pages.Count = count;
Pages.ItemCount = count;
if (count > Pages.PageLimit)
if (count > Pages.ItemsPerPage)
{
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace);
//int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1;
Pages.CalculateMaxOffset();
//GUILayout.Label($"Page {PH.ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
Pages.CurrentPageLabel();
// prev/next page buttons
@@ -317,7 +313,7 @@ namespace Explorer
//}
int offset = Pages.CalculateOffsetIndex();
for (int i = offset; i < offset + Pages.PageLimit && i < count; i++)
for (int i = offset; i < offset + Pages.ItemsPerPage && i < count; i++)
{
var entry = m_cachedEntries[i];
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Explorer
public class CppExplorer : MelonMod
{
public const string GUID = "com.sinai.cppexplorer";
public const string VERSION = "1.5.3";
public const string VERSION = "1.5.4";
public const string AUTHOR = "Sinai";
public const string NAME = "CppExplorer"
+8 -4
View File
@@ -18,8 +18,8 @@
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Release\</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<OutputPath>..\Release\2019\</OutputPath>
<DefineConstants>Release_2019</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
@@ -30,7 +30,7 @@
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Release\</OutputPath>
<OutputPath>..\Release\2018\</OutputPath>
<DefineConstants>Release_Unity2018</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@@ -44,7 +44,7 @@
</Reference>
<Reference Include="mcs">
<HintPath>..\lib\mcs.dll</HintPath>
<Private>False</Private>
<Private>True</Private>
</Reference>
<Reference Include="MelonLoader.ModHandler">
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\MelonLoader.ModHandler.dll</HintPath>
@@ -129,6 +129,8 @@
<Compile Include="CachedObjects\CacheMethod.cs" />
<Compile Include="CppExplorer.cs" />
<Compile Include="Extensions\ReflectionExtensions.cs" />
<Compile Include="Unstripping\GUIUnstrip.cs" />
<Compile Include="Unstripping\ScrollViewStateUnstrip.cs" />
<Compile Include="Extensions\UnityExtensions.cs" />
<Compile Include="Helpers\PageHelper.cs" />
<Compile Include="Helpers\ReflectionHelpers.cs" />
@@ -136,6 +138,8 @@
<Compile Include="Helpers\UnityHelpers.cs" />
<Compile Include="MainMenu\InspectUnderMouse.cs" />
<Compile Include="CachedObjects\CacheObjectBase.cs" />
<Compile Include="Unstripping\SliderHandlerUnstrip.cs" />
<Compile Include="Unstripping\UnstripExtensions.cs" />
<Compile Include="Windows\ResizeDrag.cs" />
<Compile Include="Windows\TabViewWindow.cs" />
<Compile Include="Windows\UIWindow.cs" />
+1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnhollowerBaseLib;
using UnityEngine;
namespace Explorer
+23 -13
View File
@@ -16,13 +16,23 @@ namespace Explorer
public class PageHelper
{
public int PageOffset { get; set; }
public int PageLimit { get; set; } = 20;
public int Count { get; set; }
public int MaxOffset { get; set; } = -1;
public int CalculateMaxOffset()
public int ItemsPerPage { get; set; } = 20;
public int ItemCount
{
return MaxOffset = (int)Mathf.Ceil((float)(Count / (decimal)PageLimit)) - 1;
get => m_count;
set
{
m_count = value;
CalculateMaxOffset();
}
}
private int m_count;
public int MaxPageOffset { get; private set; } = -1;
private int CalculateMaxOffset()
{
return MaxPageOffset = (int)Mathf.Ceil((float)(ItemCount / (decimal)ItemsPerPage)) - 1;
}
public void CurrentPageLabel()
@@ -30,7 +40,7 @@ namespace Explorer
var orig = GUI.skin.label.alignment;
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label($"Page {PageOffset + 1}/{MaxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
GUILayout.Label($"Page {PageOffset + 1}/{MaxPageOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
GUI.skin.label.alignment = orig;
}
@@ -53,7 +63,7 @@ namespace Explorer
}
else
{
if (PageOffset < MaxOffset)
if (PageOffset < MaxPageOffset)
{
PageOffset++;
scroll = Vector2.zero;
@@ -63,9 +73,9 @@ namespace Explorer
public int CalculateOffsetIndex()
{
int offset = PageOffset * PageLimit;
int offset = PageOffset * ItemsPerPage;
if (offset >= Count)
if (offset >= ItemCount)
{
offset = 0;
PageOffset = 0;
@@ -77,11 +87,11 @@ namespace Explorer
public void DrawLimitInputArea()
{
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
var limit = this.PageLimit.ToString();
var limit = this.ItemsPerPage.ToString();
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
if (limit != PageLimit.ToString() && int.TryParse(limit, out int i))
if (limit != ItemsPerPage.ToString() && int.TryParse(limit, out int i))
{
PageLimit = i;
ItemsPerPage = i;
}
}
}
+7 -34
View File
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using UnhollowerRuntimeLib;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -10,35 +12,6 @@ namespace Explorer
{
public class UIHelpers
{
private static bool ScrollUnstrippingFailed = false;
public static Vector2 BeginScrollView(Vector2 scroll) => BeginScrollView(scroll, null);
public static Vector2 BeginScrollView(Vector2 scroll, GUIStyle style, params GUILayoutOption[] layoutOptions)
{
if (ScrollUnstrippingFailed) return scroll;
try
{
if (style != null)
return GUILayout.BeginScrollView(scroll, style, layoutOptions);
else
return GUILayout.BeginScrollView(scroll, layoutOptions);
}
catch
{
ScrollUnstrippingFailed = true;
return scroll;
}
}
public static void EndScrollView()
{
if (ScrollUnstrippingFailed) return;
GUILayout.EndScrollView();
}
// helper for "Instantiate" button on UnityEngine.Objects
public static void InstantiateButton(Object obj, float width = 100)
{
@@ -51,13 +24,13 @@ namespace Explorer
}
// helper for drawing a styled button for a GameObject or Transform
public static void GameobjButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
public static void GOButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
{
var obj = (_obj as GameObject) ?? (_obj as Transform).gameObject;
bool children = obj.transform.childCount > 0;
bool hasChild = obj.transform.childCount > 0;
string label = children ? "[" + obj.transform.childCount + " children] " : "";
string label = hasChild ? $"[{obj.transform.childCount} children] " : "";
label += obj.name;
bool enabled = obj.activeSelf;
@@ -80,10 +53,10 @@ namespace Explorer
color = Color.red;
}
FastGameobjButton(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
GOButton_Impl(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
}
public static void FastGameobjButton(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
public static void GOButton_Impl(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
{
var obj = _obj as GameObject ?? (_obj as Transform).gameObject;
+2 -2
View File
@@ -75,11 +75,11 @@ namespace Explorer
var page = Pages[m_currentPage];
page.scroll = UIHelpers.BeginScrollView(page.scroll);
page.scroll = GUIUnstrip.BeginScrollView(page.scroll);
page.DrawWindow();
UIHelpers.EndScrollView();
GUIUnstrip.EndScrollView();
MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID);
+11 -7
View File
@@ -83,14 +83,14 @@ namespace Explorer
}
}
Pages.Count = allTransforms.Count;
Pages.ItemCount = allTransforms.Count;
int offset = Pages.CalculateOffsetIndex();
// sort by childcount
allTransforms.Sort((a, b) => b.childCount.CompareTo(a.childCount));
for (int i = offset; i < offset + Pages.PageLimit && i < Pages.Count; i++)
for (int i = offset; i < offset + Pages.ItemsPerPage && i < Pages.ItemCount; i++)
{
var child = allTransforms[i];
m_objectList.Add(new GameObjectCache(child.gameObject));
@@ -124,7 +124,7 @@ namespace Explorer
{
m_searchResults = SearchSceneObjects(m_searchInput);
m_searching = true;
Pages.Count = m_searchResults.Count;
Pages.ItemCount = m_searchResults.Count;
}
public void CancelSearch()
@@ -240,11 +240,13 @@ namespace Explorer
Pages.DrawLimitInputArea();
if (Pages.Count > Pages.PageLimit)
if (Pages.ItemCount > Pages.ItemsPerPage)
{
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{
Pages.TurnPage(Turn.Left, ref this.scroll);
m_timeOfLastUpdate = -1f;
Update();
}
@@ -253,6 +255,8 @@ namespace Explorer
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
{
Pages.TurnPage(Turn.Right, ref this.scroll);
m_timeOfLastUpdate = -1f;
Update();
}
}
@@ -303,7 +307,7 @@ namespace Explorer
}
else
{
UIHelpers.FastGameobjButton(obj.RefGameObject,
UIHelpers.GOButton_Impl(obj.RefGameObject,
obj.EnabledColor,
obj.Label,
obj.RefGameObject.activeSelf,
@@ -328,13 +332,13 @@ namespace Explorer
{
int offset = Pages.CalculateOffsetIndex();
for (int i = offset; i < offset + Pages.PageLimit && i < m_searchResults.Count; i++)
for (int i = offset; i < offset + Pages.ItemsPerPage && i < m_searchResults.Count; i++)
{
var obj = m_searchResults[i];
if (obj.RefGameObject)
{
UIHelpers.FastGameobjButton(obj.RefGameObject,
UIHelpers.GOButton_Impl(obj.RefGameObject,
obj.EnabledColor,
obj.Label,
obj.RefGameObject.activeSelf,
+6 -7
View File
@@ -75,7 +75,7 @@ namespace Explorer
m_searchResults.Add(cache);
}
Pages.Count = m_searchResults.Count;
Pages.ItemCount = m_searchResults.Count;
Pages.PageOffset = 0;
}
@@ -104,17 +104,16 @@ namespace Explorer
GUI.skin.label.alignment = TextAnchor.UpperLeft;
int count = m_searchResults.Count;
Pages.CalculateMaxOffset();
GUILayout.BeginHorizontal(null);
Pages.DrawLimitInputArea();
if (count > Pages.PageLimit)
if (count > Pages.ItemsPerPage)
{
// prev/next page buttons
if (Pages.Count > Pages.PageLimit)
if (Pages.ItemCount > Pages.ItemsPerPage)
{
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{
@@ -132,7 +131,7 @@ namespace Explorer
GUILayout.EndHorizontal();
resultsScroll = UIHelpers.BeginScrollView(resultsScroll);
resultsScroll = GUIUnstrip.BeginScrollView(resultsScroll);
var _temprect = new Rect(MainMenu.MainRect.x, MainMenu.MainRect.y, MainMenu.MainRect.width + 160, MainMenu.MainRect.height);
@@ -142,7 +141,7 @@ namespace Explorer
//if (offset >= count) m_pageOffset = 0;
int offset = Pages.CalculateOffsetIndex();
for (int i = offset; i < offset + Pages.PageLimit && i < count; i++)
for (int i = offset; i < offset + Pages.ItemsPerPage && i < count; i++)
{
m_searchResults[i].Draw(MainMenu.MainRect, 0f);
//m_searchResults[i].DrawValue(MainMenu.MainRect);
@@ -153,7 +152,7 @@ namespace Explorer
GUILayout.Label("<color=red><i>No results found!</i></color>", null);
}
UIHelpers.EndScrollView();
GUIUnstrip.EndScrollView();
GUILayout.EndVertical();
}
catch
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Harmony;
using MelonLoader;
using UnityEngine;
namespace Explorer
{
// This is a manual unstrip of UnityEngine.ScrollViewState.
// This code is provided "as-is".
// 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.
// https://unity3d.com/legal/terms-of-service
// https://unity3d.com/legal/terms-of-service/software
public class ScrollViewStateUnstrip
{
public Rect position;
public Rect visibleRect;
public Rect viewRect;
public Vector2 scrollPosition;
public bool apply;
public static Dictionary<IntPtr, ScrollViewStateUnstrip> Dict = new Dictionary<IntPtr, ScrollViewStateUnstrip>();
public static ScrollViewStateUnstrip FromPointer(IntPtr ptr)
{
if (!Dict.ContainsKey(ptr))
{
Dict.Add(ptr, new ScrollViewStateUnstrip());
}
return Dict[ptr];
}
}
}
File diff suppressed because it is too large Load Diff
+50
View File
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.
// https://unity3d.com/legal/terms-of-service
// https://unity3d.com/legal/terms-of-service/software
public static class UnstripExtensions
{
// This is a manual unstrip of GUILayoutGroup.GetLast().
// I'm using it as an Extension because it's easier this way.
public static Rect GetLastUnstripped(this GUILayoutGroup group)
{
Rect result;
if (group.m_Cursor == 0)
{
Debug.LogError("You cannot call GetLast immediately after beginning a group.");
result = GUILayoutEntry.kDummyRect;
}
else if (group.m_Cursor <= group.entries.Count)
{
GUILayoutEntry guilayoutEntry = group.entries[group.m_Cursor - 1];
result = guilayoutEntry.rect;
}
else
{
Debug.LogError(string.Concat(new object[]
{
"Getting control ",
group.m_Cursor,
"'s position in a group with only ",
group.entries.Count,
" controls when doing ",
Event.current.type
}));
result = GUILayoutEntry.kDummyRect;
}
return result;
}
}
}
+13 -17
View File
@@ -96,7 +96,7 @@ namespace Explorer
list.Sort((a, b) => b.childCount.CompareTo(a.childCount));
m_children = list.ToArray();
ChildPages.Count = m_children.Length;
ChildPages.ItemCount = m_children.Length;
var list2 = new List<Component>();
foreach (var comp in m_object.GetComponents(ReflectionHelpers.ComponentType))
@@ -111,7 +111,7 @@ namespace Explorer
}
m_components = list2.ToArray();
CompPages.Count = m_components.Length;
CompPages.ItemCount = m_components.Length;
}
catch (Exception e)
{
@@ -169,7 +169,7 @@ namespace Explorer
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
}
scroll = UIHelpers.BeginScrollView(scroll);
scroll = GUIUnstrip.BeginScrollView(scroll);
GUILayout.BeginHorizontal(null);
GUILayout.Label("Scene: <color=cyan>" + (m_scene == "" ? "n/a" : m_scene) + "</color>", null);
@@ -220,7 +220,7 @@ namespace Explorer
GameObjectControls();
UIHelpers.EndScrollView();
GUIUnstrip.EndScrollView();
if (!WindowManager.TabView)
{
@@ -238,17 +238,15 @@ namespace Explorer
private void TransformList(Rect m_rect)
{
GUILayout.BeginVertical(GUI.skin.box, null);
m_transformScroll = UIHelpers.BeginScrollView(m_transformScroll);
m_transformScroll = GUIUnstrip.BeginScrollView(m_transformScroll);
GUILayout.Label("<b><size=15>Children</size></b>", null);
GUILayout.BeginHorizontal(null);
ChildPages.DrawLimitInputArea();
if (ChildPages.Count > ChildPages.PageLimit)
if (ChildPages.ItemCount > ChildPages.ItemsPerPage)
{
ChildPages.CalculateMaxOffset();
ChildPages.CurrentPageLabel();
GUILayout.EndHorizontal();
@@ -269,7 +267,7 @@ namespace Explorer
{
int start = ChildPages.CalculateOffsetIndex();
for (int j = start; (j < start + ChildPages.PageLimit && j < ChildPages.Count); j++)
for (int j = start; (j < start + ChildPages.ItemsPerPage && j < ChildPages.ItemCount); j++)
{
var obj = m_children[j];
@@ -279,7 +277,7 @@ namespace Explorer
continue;
}
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 80);
UIHelpers.GOButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 80);
}
}
else
@@ -287,23 +285,21 @@ namespace Explorer
GUILayout.Label("<i>None</i>", null);
}
UIHelpers.EndScrollView();
GUIUnstrip.EndScrollView();
GUILayout.EndVertical();
}
private void ComponentList(Rect m_rect)
{
GUILayout.BeginVertical(GUI.skin.box, null);
m_compScroll = UIHelpers.BeginScrollView(m_compScroll);
m_compScroll = GUIUnstrip.BeginScrollView(m_compScroll);
GUILayout.Label("<b><size=15>Components</size></b>", null);
GUILayout.BeginHorizontal(null);
CompPages.DrawLimitInputArea();
if (CompPages.Count > CompPages.PageLimit)
if (CompPages.ItemCount > CompPages.ItemsPerPage)
{
CompPages.CalculateMaxOffset();
CompPages.CurrentPageLabel();
GUILayout.EndHorizontal();
@@ -330,7 +326,7 @@ namespace Explorer
{
int start = CompPages.CalculateOffsetIndex();
for (int j = start; (j < start + CompPages.PageLimit && j < CompPages.Count); j++)
for (int j = start; (j < start + CompPages.ItemsPerPage && j < CompPages.ItemCount); j++)
{
var component = m_components[j];
@@ -369,7 +365,7 @@ namespace Explorer
}
}
UIHelpers.EndScrollView();
GUIUnstrip.EndScrollView();
GUILayout.EndVertical();
}
+6 -8
View File
@@ -256,17 +256,15 @@ namespace Explorer
GUILayout.Space(10);
Pages.Count = m_cachedMembersFiltered.Length;
Pages.ItemCount = m_cachedMembersFiltered.Length;
// prev/next page buttons
GUILayout.BeginHorizontal(null);
Pages.DrawLimitInputArea();
if (Pages.Count > Pages.PageLimit)
if (Pages.ItemCount > Pages.ItemsPerPage)
{
Pages.CalculateMaxOffset();
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{
Pages.TurnPage(Turn.Left, ref this.scroll);
@@ -283,7 +281,7 @@ namespace Explorer
// ====== BODY ======
scroll = UIHelpers.BeginScrollView(scroll);
scroll = GUIUnstrip.BeginScrollView(scroll);
GUILayout.Space(10);
@@ -294,7 +292,7 @@ namespace Explorer
var members = this.m_cachedMembersFiltered;
int start = Pages.CalculateOffsetIndex();
for (int j = start; (j < start + Pages.PageLimit && j < members.Length); j++)
for (int j = start; (j < start + Pages.ItemsPerPage && j < members.Length); j++)
{
var holder = members[j];
@@ -311,12 +309,12 @@ namespace Explorer
GUILayout.EndHorizontal();
// if not last element
if (!(j == (start + Pages.PageLimit - 1) || j == (members.Length - 1)))
if (!(j == (start + Pages.ItemsPerPage - 1) || j == (members.Length - 1)))
UIStyles.HorizontalLine(new Color(0.07f, 0.07f, 0.07f), true);
}
GUILayout.EndVertical();
UIHelpers.EndScrollView();
GUIUnstrip.EndScrollView();
if (!WindowManager.TabView)
{
+3 -1
View File
@@ -31,7 +31,8 @@ namespace Explorer
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) });
var r = GUILayoutUtility.GetLastRect();
//var r = GUILayoutUtility.GetLastRect();
var r = GUIUnstrip.GetLastRect();
Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y));
@@ -65,6 +66,7 @@ namespace Explorer
{
RESIZE_FAILED = true;
MelonLogger.Log("Exception on GuiResize: " + e.GetType() + ", " + e.Message);
MelonLogger.Log(e.StackTrace);
return origRect;
}