From 748e0cabcbc06e046d30700d651bbf3ac46128e7 Mon Sep 17 00:00:00 2001
From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com>
Date: Thu, 1 Oct 2020 20:20:52 +1000
Subject: [PATCH] 1.8.21
* Fixed a bug when editing a Text Field and the input string is `null`. Only affected Il2Cpp games, appeared in 1.8.0.
* Added a menu page for editing the Explorer Settings in-game, called `Options`.
* Added a new setting for default Items per Page Limit (for all "Pages" in Explorer).
---
src/CachedObjects/Object/CacheDictionary.cs | 1 +
src/Config/ModConfig.cs | 1 +
src/Explorer.csproj | 1 +
src/ExplorerCore.cs | 2 +-
src/Helpers/PageHelper.cs | 2 +-
src/Menu/MainMenu/MainMenu.cs | 6 +-
src/Menu/MainMenu/Pages/OptionsPage.cs | 99 +++++++++++++++++++++
src/Menu/MainMenu/Pages/ScenePage.cs | 2 +-
src/Menu/ResizeDrag.cs | 1 +
src/UnstripFixes/Internal.cs | 2 +
10 files changed, 113 insertions(+), 4 deletions(-)
create mode 100644 src/Menu/MainMenu/Pages/OptionsPage.cs
diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs
index c8aaaad..cb40877 100644
--- a/src/CachedObjects/Object/CacheDictionary.cs
+++ b/src/CachedObjects/Object/CacheDictionary.cs
@@ -269,6 +269,7 @@ namespace Explorer
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
+ GUI.skin.label.alignment = TextAnchor.MiddleLeft;
GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) });
key.DrawValue(window, (window.width / 2) - 80f);
diff --git a/src/Config/ModConfig.cs b/src/Config/ModConfig.cs
index 341059c..df2d9f8 100644
--- a/src/Config/ModConfig.cs
+++ b/src/Config/ModConfig.cs
@@ -15,6 +15,7 @@ namespace Explorer
public KeyCode Main_Menu_Toggle = KeyCode.F7;
public Vector2 Default_Window_Size = new Vector2(550, 700);
+ public int Default_Page_Limit = 20;
public static void OnLoad()
{
diff --git a/src/Explorer.csproj b/src/Explorer.csproj
index 57d37fb..cbee9a5 100644
--- a/src/Explorer.csproj
+++ b/src/Explorer.csproj
@@ -243,6 +243,7 @@
+
diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs
index de2983a..69c1a9f 100644
--- a/src/ExplorerCore.cs
+++ b/src/ExplorerCore.cs
@@ -5,7 +5,7 @@ namespace Explorer
public class ExplorerCore
{
public const string NAME = "Explorer (" + PLATFORM + ", " + MODLOADER + ")";
- public const string VERSION = "1.8.2";
+ public const string VERSION = "1.8.21";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.explorer";
diff --git a/src/Helpers/PageHelper.cs b/src/Helpers/PageHelper.cs
index efd6b4a..e7d7250 100644
--- a/src/Helpers/PageHelper.cs
+++ b/src/Helpers/PageHelper.cs
@@ -21,7 +21,7 @@ namespace Explorer
CalculateMaxOffset();
}
}
- private int m_itemsPerPage = 20;
+ private int m_itemsPerPage = ModConfig.Instance.Default_Page_Limit;
public int ItemCount
{
diff --git a/src/Menu/MainMenu/MainMenu.cs b/src/Menu/MainMenu/MainMenu.cs
index 93e3c94..6158459 100644
--- a/src/Menu/MainMenu/MainMenu.cs
+++ b/src/Menu/MainMenu/MainMenu.cs
@@ -17,16 +17,20 @@ namespace Explorer
Pages.Add(new ScenePage());
Pages.Add(new SearchPage());
Pages.Add(new ConsolePage());
+ Pages.Add(new OptionsPage());
for (int i = 0; i < Pages.Count; i++)
{
var page = Pages[i];
page.Init();
+
+ // If page failed to init, it will remove itself from the list. Lower the iterate counter.
+ if (!Pages.Contains(page)) i--;
}
}
public const int MainWindowID = 5000;
- public static Rect MainRect = new Rect(5,5, ModConfig.Instance.Default_Window_Size.x,ModConfig.Instance.Default_Window_Size.y);
+ public static Rect MainRect = new Rect(5, 5, ModConfig.Instance.Default_Window_Size.x, ModConfig.Instance.Default_Window_Size.y);
public static readonly List Pages = new List();
private static int m_currentPage = 0;
diff --git a/src/Menu/MainMenu/Pages/OptionsPage.cs b/src/Menu/MainMenu/Pages/OptionsPage.cs
new file mode 100644
index 0000000..50291dc
--- /dev/null
+++ b/src/Menu/MainMenu/Pages/OptionsPage.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Explorer.Tests;
+using UnityEngine;
+
+namespace Explorer
+{
+ public class OptionsPage : WindowPage
+ {
+ public override string Name => "Options";
+
+ public string toggleKeyInputString = "";
+ public Vector2 defaultSizeInputVector;
+ public int defaultPageLimit;
+
+ private CacheObjectBase toggleKeyInput;
+ private CacheObjectBase defaultSizeInput;
+ private CacheObjectBase defaultPageLimitInput;
+
+ public override void Init()
+ {
+ toggleKeyInputString = ModConfig.Instance.Main_Menu_Toggle.ToString();
+ toggleKeyInput = CacheFactory.GetTypeAndCacheObject(typeof(OptionsPage).GetField("toggleKeyInputString"), this);
+
+ defaultSizeInputVector = ModConfig.Instance.Default_Window_Size;
+ defaultSizeInput = CacheFactory.GetTypeAndCacheObject(typeof(OptionsPage).GetField("defaultSizeInputVector"), this);
+
+ defaultPageLimit = ModConfig.Instance.Default_Page_Limit;
+ defaultPageLimitInput = CacheFactory.GetTypeAndCacheObject(typeof(OptionsPage).GetField("defaultPageLimit"), this);
+ }
+
+ public override void Update() { }
+
+ public override void DrawWindow()
+ {
+ GUI.skin.label.alignment = TextAnchor.MiddleCenter;
+ GUILayout.Label("Settings", new GUILayoutOption[0]);
+ GUI.skin.label.alignment = TextAnchor.MiddleLeft;
+
+ GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]);
+
+ GUILayout.BeginHorizontal(new GUILayoutOption[0]);
+ GUILayout.Label($"Menu Toggle Key:", new GUILayoutOption[] { GUILayout.Width(215f) });
+ toggleKeyInput.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(new GUILayoutOption[0]);
+ GUILayout.Label($"Default Window Size:", new GUILayoutOption[] { GUILayout.Width(215f) });
+ defaultSizeInput.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(new GUILayoutOption[0]);
+ GUILayout.Label($"Default Items per Page:", new GUILayoutOption[] { GUILayout.Width(215f) });
+ defaultPageLimitInput.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
+ GUILayout.EndHorizontal();
+
+ if (GUILayout.Button("Apply and Save", new GUILayoutOption[0]))
+ {
+ ApplyAndSave();
+ }
+
+ GUILayout.EndVertical();
+
+ //GUIUnstrip.Space(10f);
+
+ //GUI.skin.label.alignment = TextAnchor.MiddleCenter;
+ //GUILayout.Label("Other", new GUILayoutOption[0]);
+ //GUI.skin.label.alignment = TextAnchor.MiddleLeft;
+
+ //GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]);
+
+ //if (GUILayout.Button("Inspect Test Class", new GUILayoutOption[0]))
+ //{
+ // WindowManager.InspectObject(TestClass.Instance, out bool _);
+ //}
+
+ //GUILayout.EndVertical();
+ }
+
+ private void ApplyAndSave()
+ {
+ if (Enum.Parse(typeof(KeyCode), toggleKeyInputString) is KeyCode key)
+ {
+ ModConfig.Instance.Main_Menu_Toggle = key;
+ }
+ else
+ {
+ ExplorerCore.LogWarning($"Could not parse '{toggleKeyInputString}' to KeyCode!");
+ }
+
+ ModConfig.Instance.Default_Window_Size = defaultSizeInputVector;
+ ModConfig.Instance.Default_Page_Limit = defaultPageLimit;
+
+ ModConfig.SaveSettings();
+ }
+ }
+}
diff --git a/src/Menu/MainMenu/Pages/ScenePage.cs b/src/Menu/MainMenu/Pages/ScenePage.cs
index 6328827..025d2f6 100644
--- a/src/Menu/MainMenu/Pages/ScenePage.cs
+++ b/src/Menu/MainMenu/Pages/ScenePage.cs
@@ -10,7 +10,7 @@ namespace Explorer
{
public static ScenePage Instance;
- public override string Name { get => "Scene Explorer"; }
+ public override string Name { get => "Scenes"; }
public PageHelper Pages = new PageHelper();
diff --git a/src/Menu/ResizeDrag.cs b/src/Menu/ResizeDrag.cs
index 423ed4b..a3347db 100644
--- a/src/Menu/ResizeDrag.cs
+++ b/src/Menu/ResizeDrag.cs
@@ -150,6 +150,7 @@ namespace Explorer
GUILayout.EndHorizontal();
#endif
+ GUI.skin.label.alignment = TextAnchor.MiddleLeft;
return _rect;
}
diff --git a/src/UnstripFixes/Internal.cs b/src/UnstripFixes/Internal.cs
index da6ac3e..cf4db8a 100644
--- a/src/UnstripFixes/Internal.cs
+++ b/src/UnstripFixes/Internal.cs
@@ -109,6 +109,8 @@ namespace Explorer.UnstripInternals
public static string TextField(string text, GUILayoutOption[] options)
{
+ text = text ?? "";
+
int controlID = GUIUtility.GetControlID(FocusType.Keyboard);
GUIContent guicontent = GUIContent.Temp(text);
bool flag = GUIUtility.keyboardControl != controlID;