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

Commit fbf9859

Browse files
committed
Fix for GUILayout.BeginArea unstrip and UnityEngine.SystemClock unstrip
and remove some old comments
1 parent 2d7dfa5 commit fbf9859

File tree

9 files changed

+90
-25
lines changed

9 files changed

+90
-25
lines changed

src/CachedObjects/CacheObjectBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ public object[] ParseArguments()
244244
var input = m_argumentInput[i];
245245
var type = m_arguments[i].ParameterType;
246246

247-
// First, try parse the input and use that.
248247
if (!string.IsNullOrEmpty(input))
249248
{
250249
// strings can obviously just be used directly

src/CppExplorer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Explorer
1313
public class CppExplorer : MelonMod
1414
{
1515
public const string NAME = "CppExplorer";
16-
public const string VERSION = "1.7.0";
16+
public const string VERSION = "1.7.1";
1717
public const string AUTHOR = "Sinai";
1818
public const string GUID = "com.sinai.cppexplorer";
1919

@@ -36,17 +36,13 @@ public override void OnApplicationStart()
3636
{
3737
Instance = this;
3838

39-
// First, load config
4039
ModConfig.OnLoad();
4140

42-
// Setup InputHelper class (UnityEngine.Input)
4341
InputHelper.Init();
4442

45-
// Create CppExplorer modules
4643
new MainMenu();
4744
new WindowManager();
4845

49-
// Init cursor control
5046
CursorControl.Init();
5147

5248
MelonLogger.Log($"CppExplorer {VERSION} initialized.");

src/Helpers/ReflectionHelpers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public static Type GetActualType(object obj)
101101
return typeof(ILType);
102102
}
103103

104-
// Get the System.Type using the qualified name, or fallback to GetType.
105104
return Type.GetType(ilObject.GetIl2CppType().AssemblyQualifiedName) ?? obj.GetType();
106105
}
107106

src/Menu/MainMenu/MainMenu.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void MainWindow(int id)
6464
return;
6565
}
6666

67-
GUILayout.BeginArea(new Rect(5, 25, MainRect.width - 10, MainRect.height - 35), GUI.skin.box);
67+
GUIUnstrip.BeginArea(new Rect(5, 25, MainRect.width - 10, MainRect.height - 35), GUI.skin.box);
6868

6969
MainHeader();
7070

@@ -78,7 +78,7 @@ private void MainWindow(int id)
7878

7979
MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID);
8080

81-
GUILayout.EndArea();
81+
GUIUnstrip.EndArea();
8282
}
8383

8484
private void MainHeader()

src/Menu/Windows/GameObjectWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public override void WindowFunction(int windowID)
210210
if (!WindowManager.TabView)
211211
{
212212
Header();
213-
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
213+
GUIUnstrip.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
214214
}
215215

216216
scroll = GUIUnstrip.BeginScrollView(scroll);
@@ -270,7 +270,7 @@ public override void WindowFunction(int windowID)
270270
{
271271
m_rect = ResizeDrag.ResizeWindow(rect, windowID);
272272

273-
GUILayout.EndArea();
273+
GUIUnstrip.EndArea();
274274
}
275275
}
276276
catch (Exception e)

src/Menu/Windows/ReflectionWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public override void WindowFunction(int windowID)
228228
if (!WindowManager.TabView)
229229
{
230230
Header();
231-
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
231+
GUIUnstrip.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
232232
}
233233

234234
GUILayout.BeginHorizontal(null);
@@ -354,7 +354,7 @@ public override void WindowFunction(int windowID)
354354
{
355355
m_rect = ResizeDrag.ResizeWindow(rect, windowID);
356356

357-
GUILayout.EndArea();
357+
GUIUnstrip.EndArea();
358358
}
359359
}
360360
catch (Il2CppException e)

src/Menu/Windows/TabViewWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public override void WindowFunction(int windowID)
6565
return;
6666
}
6767

68-
GUILayout.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box);
68+
GUIUnstrip.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box);
6969

7070
GUILayout.BeginVertical(GUI.skin.box, null);
7171
GUILayout.BeginHorizontal(null);
@@ -109,7 +109,7 @@ public override void WindowFunction(int windowID)
109109
}
110110
catch { }
111111

112-
GUILayout.EndArea();
112+
GUIUnstrip.EndArea();
113113
}
114114
catch { }
115115
}

src/UnstripFixes/GUIUnstrip.cs

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ public class GUIUnstrip
1717
{
1818
public static int s_ScrollControlId;
1919

20-
public static bool ScrollFailed = false;
20+
public static bool ScrollFailed = true;
2121
public static bool ManualUnstripFailed = false;
2222

2323
private static GenericStack ScrollStack => m_scrollStack ?? GetScrollStack();
2424
private static PropertyInfo m_scrollViewStatesInfo;
2525
private static GenericStack m_scrollStack;
2626

27+
public static DateTime nextScrollStepTime;
28+
2729
private static GenericStack GetScrollStack()
2830
{
2931
if (m_scrollViewStatesInfo == null)
@@ -55,7 +57,6 @@ public static void Space(float pixels)
5557
GUIUtility.CheckOnGUI();
5658

5759
if (GUILayoutUtility.current.topLevel.isVertical)
58-
5960
LayoutUtilityUnstrip.GetRect(0, pixels, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Height(pixels) });
6061
else
6162
LayoutUtilityUnstrip.GetRect(pixels, 0, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Width(pixels) });
@@ -66,6 +67,78 @@ public static void Space(float pixels)
6667
}
6768
}
6869

70+
// Fix for BeginArea
71+
72+
static public void BeginArea(Rect screenRect) { BeginArea(screenRect, GUIContent.none, GUIStyle.none); }
73+
static public void BeginArea(Rect screenRect, string text) { BeginArea(screenRect, GUIContent.Temp(text), GUIStyle.none); }
74+
static public void BeginArea(Rect screenRect, Texture image) { BeginArea(screenRect, GUIContent.Temp(image), GUIStyle.none); }
75+
static public void BeginArea(Rect screenRect, GUIContent content) { BeginArea(screenRect, content, GUIStyle.none); }
76+
static public void BeginArea(Rect screenRect, GUIStyle style) { BeginArea(screenRect, GUIContent.none, style); }
77+
static public void BeginArea(Rect screenRect, string text, GUIStyle style) { BeginArea(screenRect, GUIContent.Temp(text), style); }
78+
static public void BeginArea(Rect screenRect, Texture image, GUIStyle style) { BeginArea(screenRect, GUIContent.Temp(image), style); }
79+
80+
// Begin a GUILayout block of GUI controls in a fixed screen area.
81+
static public void BeginArea(Rect screenRect, GUIContent content, GUIStyle style)
82+
{
83+
GUILayoutGroup g = GUILayoutUtility.BeginLayoutArea(style, Il2CppType.Of<GUILayoutGroup>());
84+
if (Event.current.type == EventType.Layout)
85+
{
86+
g.resetCoords = true;
87+
g.minWidth = g.maxWidth = screenRect.width;
88+
g.minHeight = g.maxHeight = screenRect.height;
89+
g.rect = Rect.MinMaxRect(screenRect.xMin, screenRect.yMin, g.rect.xMax, g.rect.yMax);
90+
}
91+
92+
GUI.BeginGroup(g.rect, content, style);
93+
}
94+
95+
// Close a GUILayout block started with BeginArea
96+
static public void EndArea()
97+
{
98+
if (Event.current.type == EventType.Used)
99+
return;
100+
GUILayoutUtility.current.layoutGroups.Pop();
101+
GUILayoutUtility.current.topLevel = GUILayoutUtility.current.layoutGroups.Peek().TryCast<GUILayoutGroup>();
102+
GUI.EndGroup();
103+
}
104+
105+
// Fix for BeginGroup
106+
107+
public static void BeginGroup(Rect position) { BeginGroup(position, GUIContent.none, GUIStyle.none); }
108+
public static void BeginGroup(Rect position, string text) { BeginGroup(position, GUIContent.Temp(text), GUIStyle.none); }
109+
public static void BeginGroup(Rect position, Texture image) { BeginGroup(position, GUIContent.Temp(image), GUIStyle.none); }
110+
public static void BeginGroup(Rect position, GUIContent content) { BeginGroup(position, content, GUIStyle.none); }
111+
public static void BeginGroup(Rect position, GUIStyle style) { BeginGroup(position, GUIContent.none, style); }
112+
public static void BeginGroup(Rect position, string text, GUIStyle style) { BeginGroup(position, GUIContent.Temp(text), style); }
113+
public static void BeginGroup(Rect position, Texture image, GUIStyle style) { BeginGroup(position, GUIContent.Temp(image), style); }
114+
115+
public static void BeginGroup(Rect position, GUIContent content, GUIStyle style) { BeginGroup(position, content, style, Vector2.zero); }
116+
117+
internal static void BeginGroup(Rect position, GUIContent content, GUIStyle style, Vector2 scrollOffset)
118+
{
119+
int id = GUIUtility.GetControlID(GUI.s_BeginGroupHash, FocusType.Passive);
120+
121+
if (content != GUIContent.none || style != GUIStyle.none)
122+
{
123+
switch (Event.current.type)
124+
{
125+
case EventType.Repaint:
126+
style.Draw(position, content, id);
127+
break;
128+
default:
129+
if (position.Contains(Event.current.mousePosition))
130+
GUIUtility.mouseUsed = true;
131+
break;
132+
}
133+
}
134+
GUIClip.Push(position, scrollOffset, Vector2.zero, false);
135+
}
136+
137+
public static void EndGroup()
138+
{
139+
GUIClip.Internal_Pop();
140+
}
141+
69142
// Fix for BeginScrollView.
70143

71144
public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] options)
@@ -120,8 +193,6 @@ public static void EndScrollView(bool handleScrollWheel = true)
120193
private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical,
121194
GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options)
122195
{
123-
GUIUtility.CheckOnGUI();
124-
125196
var guiscrollGroup = GUILayoutUtility.BeginLayoutGroup(background, null, Il2CppType.Of<GUIScrollGroup>())
126197
.TryCast<GUIScrollGroup>();
127198

@@ -396,12 +467,12 @@ private static bool ScrollerRepeatButton_Impl(int scrollerID, Rect rect, GUIStyl
396467
if (flag)
397468
{
398469
result = true;
399-
GUI.nextScrollStepTime = Il2CppSystem.DateTime.Now.AddMilliseconds(250.0);
470+
nextScrollStepTime = DateTime.Now.AddMilliseconds(250.0);
400471
}
401-
else if (Il2CppSystem.DateTime.Now >= GUI.nextScrollStepTime)
472+
else if (DateTime.Now >= nextScrollStepTime)
402473
{
403474
result = true;
404-
GUI.nextScrollStepTime = Il2CppSystem.DateTime.Now.AddMilliseconds(30.0);
475+
nextScrollStepTime = DateTime.Now.AddMilliseconds(30.0);
405476
}
406477
if (Event.current.type == EventType.Repaint)
407478
{

src/UnstripFixes/SliderHandlerUnstrip.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private float OnMouseDown()
8181
if (this.SupportsPageMovements())
8282
{
8383
this.SliderState().isDragging = false;
84-
GUI.nextScrollStepTime = SystemClock.now.AddMilliseconds(250.0);
84+
GUIUnstrip.nextScrollStepTime = DateTime.Now.AddMilliseconds(250.0);
8585
GUI.scrollTroughSide = this.CurrentScrollTroughSide();
8686
result = this.PageMovementValue();
8787
}
@@ -155,7 +155,7 @@ private float OnRepaint()
155155
else
156156
{
157157
GUI.InternalRepaintEditorWindow();
158-
if (SystemClock.now < GUI.nextScrollStepTime)
158+
if (DateTime.Now < GUIUnstrip.nextScrollStepTime)
159159
{
160160
result = this.currentValue;
161161
}
@@ -165,7 +165,7 @@ private float OnRepaint()
165165
}
166166
else
167167
{
168-
GUI.nextScrollStepTime = SystemClock.now.AddMilliseconds(30.0);
168+
GUIUnstrip.nextScrollStepTime = DateTime.Now.AddMilliseconds(30.0);
169169
if (this.SupportsPageMovements())
170170
{
171171
this.SliderState().isDragging = false;

0 commit comments

Comments
 (0)