From 968546d43cea797579432227a2cdabdd50669395 Mon Sep 17 00:00:00 2001
From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com>
Date: Wed, 14 Oct 2020 20:47:19 +1100
Subject: [PATCH] 2.0.6
* Unstrip fixes and cleanups
---
src/Explorer.csproj | 2 +
src/ExplorerCore.cs | 6 +-
src/Helpers/Texture2DHelpers.cs | 44 +-
src/Input/InputManager.cs | 46 +-
.../Reflection/InstanceInspector.cs | 18 +-
src/UI/Inspectors/ReflectionInspector.cs | 5 +-
.../Object/InteractiveEnumerable.cs | 4 +
src/UI/Main/ConsolePage.cs | 10 +-
src/UI/Main/ScenePage.cs | 106 +-
src/UI/Main/SearchPage.cs | 35 +-
src/UI/TabViewWindow.cs | 2 +-
src/Unstrip/IMGUI/GUIUnstrip.cs | 20 +-
src/Unstrip/IMGUI/Internal.cs | 230 ++-
src/Unstrip/IMGUI/Internal_GUIUtility.cs | 66 +
src/Unstrip/IMGUI/Internal_ScrollViewState.cs | 80 +-
src/Unstrip/IMGUI/Internal_SliderHandler.cs | 26 +-
src/Unstrip/IMGUI/Internal_SliderState.cs | 12 -
src/Unstrip/IMGUI/Internal_TextEditor.cs | 1557 +++++++++++++++++
18 files changed, 1972 insertions(+), 297 deletions(-)
create mode 100644 src/Unstrip/IMGUI/Internal_GUIUtility.cs
create mode 100644 src/Unstrip/IMGUI/Internal_TextEditor.cs
diff --git a/src/Explorer.csproj b/src/Explorer.csproj
index dbe84a7..738e97f 100644
--- a/src/Explorer.csproj
+++ b/src/Explorer.csproj
@@ -262,6 +262,8 @@
+
+
diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs
index d88fcb1..a702835 100644
--- a/src/ExplorerCore.cs
+++ b/src/ExplorerCore.cs
@@ -1,4 +1,6 @@
-using Explorer.Config;
+using System.Collections;
+using System.Linq;
+using Explorer.Config;
using Explorer.UI;
using Explorer.UI.Inspectors;
using Explorer.UI.Main;
@@ -10,7 +12,7 @@ namespace Explorer
public class ExplorerCore
{
public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")";
- public const string VERSION = "2.0.5";
+ public const string VERSION = "2.0.6";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.explorer";
diff --git a/src/Helpers/Texture2DHelpers.cs b/src/Helpers/Texture2DHelpers.cs
index 2875b8e..791d4fb 100644
--- a/src/Helpers/Texture2DHelpers.cs
+++ b/src/Helpers/Texture2DHelpers.cs
@@ -13,7 +13,7 @@ namespace Explorer.Helpers
{
public static class Texture2DHelpers
{
-#if CPP
+#if CPP // If Mono
#else
private static bool isNewEncodeMethod = false;
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod();
@@ -56,16 +56,16 @@ namespace Explorer.Helpers
}
}
- public static Texture2D Copy(Texture2D other, Rect rect, bool isDTXnmNormal = false)
+ public static Texture2D Copy(Texture2D orig, Rect rect, bool isDTXnmNormal = false)
{
Color[] pixels;
- if (!other.IsReadable())
+ if (!orig.IsReadable())
{
- other = ForceReadTexture(other, isDTXnmNormal);
+ orig = ForceReadTexture(orig);
}
- pixels = other.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
+ pixels = orig.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
var _newTex = new Texture2D((int)rect.width, (int)rect.height);
_newTex.SetPixels(pixels);
@@ -73,26 +73,21 @@ namespace Explorer.Helpers
return _newTex;
}
- public static Texture2D ForceReadTexture(Texture2D tex, bool isDTXnmNormal = false)
+ public static Texture2D ForceReadTexture(Texture2D tex)
{
try
{
var origFilter = tex.filterMode;
tex.filterMode = FilterMode.Point;
- RenderTexture rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32);
+ var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32);
rt.filterMode = FilterMode.Point;
RenderTexture.active = rt;
Graphics.Blit(tex, rt);
- Texture2D _newTex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
+ var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
+
_newTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
-
- if (isDTXnmNormal)
- {
- _newTex = DTXnmToRGBA(_newTex);
- }
-
_newTex.Apply(false, false);
RenderTexture.active = null;
@@ -117,8 +112,11 @@ namespace Explorer.Helpers
byte[] data;
var savepath = dir + @"\" + name + ".png";
- // Fix for non-Readable or Compressed textures.
- tex = ForceReadTexture(tex, isDTXnmNormal);
+ // Make sure we can EncodeToPNG it.
+ if (tex.format != TextureFormat.ARGB32 || !tex.IsReadable())
+ {
+ tex = ForceReadTexture(tex);
+ }
if (isDTXnmNormal)
{
@@ -129,15 +127,13 @@ namespace Explorer.Helpers
#if CPP
data = tex.EncodeToPNG();
#else
- var method = EncodeToPNGMethod;
-
if (isNewEncodeMethod)
{
- data = (byte[])method.Invoke(null, new object[] { tex });
+ data = (byte[])EncodeToPNGMethod.Invoke(null, new object[] { tex });
}
else
{
- data = (byte[])method.Invoke(tex, new object[0]);
+ data = (byte[])EncodeToPNGMethod.Invoke(tex, new object[0]);
}
#endif
@@ -148,8 +144,10 @@ namespace Explorer.Helpers
else
{
#if CPP
- // The IL2CPP method will return invalid byte data.
- // However, we can just iterate into safe C# byte[] array.
+ // The Il2Cpp EncodeToPNG() method does return System.Byte[],
+ // but for some reason it is not recognized or valid.
+ // Simple fix is iterating into a new array manually.
+
byte[] safeData = new byte[data.Length];
for (int i = 0; i < data.Length; i++)
{
@@ -185,7 +183,7 @@ namespace Explorer.Helpers
);
}
- var newtex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
+ var newtex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
newtex.SetPixels(colors);
return newtex;
diff --git a/src/Input/InputManager.cs b/src/Input/InputManager.cs
index 855513a..358b264 100644
--- a/src/Input/InputManager.cs
+++ b/src/Input/InputManager.cs
@@ -50,33 +50,37 @@ namespace Explorer
public static void ResetInputAxes() => UnityEngine.Input.ResetInputAxes();
#endif
- //#if CPP
- //#pragma warning disable IDE1006
- // // public extern static string compositionString { get; }
+#if CPP
+#pragma warning disable IDE1006
+ // public extern static string compositionString { get; }
- // internal delegate string get_compositionString_delegate();
- // internal static get_compositionString_delegate get_compositionString_iCall =
- // IL2CPP.ResolveICall("UnityEngine.Input::get_compositionString");
+ internal delegate IntPtr d_get_compositionString();
+ internal static d_get_compositionString get_compositionString_iCall =
+ IL2CPP.ResolveICall("UnityEngine.Input::get_compositionString");
- // public static string compositionString => get_compositionString_iCall();
+ public static string compositionString => IL2CPP.Il2CppStringToManaged(get_compositionString_iCall());
- // // public extern static Vector2 compositionCursorPos { get; set; }
+ // public extern static Vector2 compositionCursorPos { get; set; }
- // internal delegate Vector2 get_compositionCursorPos_delegate();
- // internal static get_compositionCursorPos_delegate get_compositionCursorPos_iCall =
- // IL2CPP.ResolveICall("UnityEngine.Input::get_compositionCursorPos");
+ internal delegate void d_get_compositionCursorPos(out Vector2 ret);
+ internal static d_get_compositionCursorPos get_compositionCursorPos_iCall =
+ IL2CPP.ResolveICall("UnityEngine.Input::get_compositionCursorPos_Injected");
- // internal delegate void set_compositionCursorPos_delegate(Vector2 value);
- // internal static set_compositionCursorPos_delegate set_compositionCursorPos_iCall =
- // IL2CPP.ResolveICall("UnityEngine.Input::set_compositionCursorPos");
+ internal delegate void set_compositionCursorPos_delegate(ref Vector2 value);
+ internal static set_compositionCursorPos_delegate set_compositionCursorPos_iCall =
+ IL2CPP.ResolveICall("UnityEngine.Input::set_compositionCursorPos_Injected");
- // public static Vector2 compositionCursorPos
- // {
- // get => get_compositionCursorPos_iCall();
- // set => set_compositionCursorPos_iCall(value);
- // }
+ public static Vector2 compositionCursorPos
+ {
+ get
+ {
+ get_compositionCursorPos_iCall(out Vector2 ret);
+ return ret;
+ }
+ set => set_compositionCursorPos_iCall(ref value);
+ }
- //#pragma warning restore IDE1006
- //#endif
+#pragma warning restore IDE1006
+#endif
}
}
\ No newline at end of file
diff --git a/src/UI/Inspectors/Reflection/InstanceInspector.cs b/src/UI/Inspectors/Reflection/InstanceInspector.cs
index 172ad01..013f823 100644
--- a/src/UI/Inspectors/Reflection/InstanceInspector.cs
+++ b/src/UI/Inspectors/Reflection/InstanceInspector.cs
@@ -72,11 +72,11 @@ namespace Explorer.UI.Inspectors
public void DrawInstanceControls(Rect rect)
{
- if (m_uObj)
- {
- GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
- }
- GUILayout.EndHorizontal();
+ //if (m_uObj)
+ //{
+ // GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
+ //}
+ //GUILayout.EndHorizontal();
if (m_uObj)
{
@@ -89,13 +89,17 @@ namespace Explorer.UI.Inspectors
GUILayout.Label("GameObject:", new GUILayoutOption[] { GUILayout.Width(135) });
var charWidth = obj.name.Length * 15;
var maxWidth = rect.width - 350;
- var labelWidth = charWidth < maxWidth ? charWidth : maxWidth;
- if (GUILayout.Button("" + obj.name + "", new GUILayoutOption[] { GUILayout.Width(labelWidth) }))
+ var btnWidth = charWidth < maxWidth ? charWidth : maxWidth;
+ if (GUILayout.Button("" + obj.name + "", new GUILayoutOption[] { GUILayout.Width(btnWidth) }))
{
WindowManager.InspectObject(obj, out bool _);
}
GUI.skin.label.alignment = TextAnchor.UpperLeft;
}
+ else
+ {
+ GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]);
+ }
GUILayout.EndHorizontal();
}
}
diff --git a/src/UI/Inspectors/ReflectionInspector.cs b/src/UI/Inspectors/ReflectionInspector.cs
index eb9ac3e..189e22c 100644
--- a/src/UI/Inspectors/ReflectionInspector.cs
+++ b/src/UI/Inspectors/ReflectionInspector.cs
@@ -263,15 +263,12 @@ namespace Explorer.UI.Inspectors
? new GUILayoutOption[] { GUILayout.Width(245f) }
: new GUILayoutOption[0];
GUILayout.Label("Type: " + TargetType.FullName + "", labelWidth);
+ GUILayout.EndHorizontal();
if (asInstance != null)
{
asInstance.DrawInstanceControls(rect);
}
- else
- {
- GUILayout.EndHorizontal();
- }
UIStyles.HorizontalLine(Color.grey);
diff --git a/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs b/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs
index 8d62f00..32fc71d 100644
--- a/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs
+++ b/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs
@@ -6,6 +6,10 @@ using System.Reflection;
using UnityEngine;
using Explorer.UI.Shared;
using Explorer.CacheObject;
+using System.Linq;
+#if CPP
+using UnhollowerBaseLib;
+#endif
namespace Explorer.UI
{
diff --git a/src/UI/Main/ConsolePage.cs b/src/UI/Main/ConsolePage.cs
index 8d03a38..3777c05 100644
--- a/src/UI/Main/ConsolePage.cs
+++ b/src/UI/Main/ConsolePage.cs
@@ -33,7 +33,7 @@ namespace Explorer.UI.Main
public static TextEditor textEditor;
private bool shouldRefocus;
- public static GUIStyle AutocompleteStyle => autocompleteStyle ?? GetCompletionStyle();
+ public static GUIStyle AutocompleteStyle => autocompleteStyle ?? GetAutocompleteStyle();
private static GUIStyle autocompleteStyle;
public static readonly string[] DefaultUsing = new string[]
@@ -342,9 +342,9 @@ Help();";
}
// Credit ManlyMarco
- private static GUIStyle GetCompletionStyle()
+ private static GUIStyle GetAutocompleteStyle()
{
- return autocompleteStyle = new GUIStyle(GUI.skin.button)
+ var style = new GUIStyle
{
border = new RectOffset(0, 0, 0, 0),
margin = new RectOffset(0, 0, 0, 0),
@@ -353,8 +353,10 @@ Help();";
normal = { background = null },
focused = { background = Texture2D.whiteTexture, textColor = Color.black },
active = { background = Texture2D.whiteTexture, textColor = Color.black },
- alignment = TextAnchor.MiddleLeft,
+ alignment = TextAnchor.MiddleLeft
};
+
+ return autocompleteStyle = style;
}
private class VoidType
diff --git a/src/UI/Main/ScenePage.cs b/src/UI/Main/ScenePage.cs
index f9a0fdf..2b2c706 100644
--- a/src/UI/Main/ScenePage.cs
+++ b/src/UI/Main/ScenePage.cs
@@ -19,8 +19,6 @@ namespace Explorer.UI.Main
private float m_timeOfLastUpdate = -1f;
private const int PASSIVE_UPDATE_INTERVAL = 1;
- private static bool m_getRootObjectsFailed;
-
private static string m_currentScene = "";
// gameobject list
@@ -50,7 +48,7 @@ namespace Explorer.UI.Main
if (m_searching)
CancelSearch();
- Update_Impl(true);
+ Update_Impl();
}
public void TraverseUp()
@@ -75,11 +73,6 @@ namespace Explorer.UI.Main
public void CancelSearch()
{
m_searching = false;
-
- if (m_getRootObjectsFailed && !m_currentTransform)
- {
- GetRootObjectsManual_Impl();
- }
}
public List SearchSceneObjects(string _search)
@@ -112,7 +105,7 @@ namespace Explorer.UI.Main
Update_Impl();
}
- private void Update_Impl(bool manual = false)
+ private void Update_Impl()
{
List allTransforms = new List();
@@ -126,39 +119,23 @@ namespace Explorer.UI.Main
}
else
{
- if (!m_getRootObjectsFailed)
+ for (int i = 0; i < SceneManager.sceneCount; i++)
{
- try
+ var scene = SceneManager.GetSceneAt(i);
+
+ if (scene.name == m_currentScene)
{
- for (int i = 0; i < SceneManager.sceneCount; i++)
- {
- var scene = SceneManager.GetSceneAt(i);
+ var rootObjects =
+#if CPP
+ Unstrip.Scenes.SceneUnstrip.GetRootGameObjects(scene)
+ .Select(it => it.transform);
+#else
+ scene.GetRootGameObjects().Select(it => it.transform);
+#endif
+ allTransforms.AddRange(rootObjects);
- if (scene.name == m_currentScene)
- {
- allTransforms.AddRange(scene.GetRootGameObjects()
- .Select(it => it.transform));
-
- break;
- }
- }
+ break;
}
- catch
- {
- ExplorerCore.Log("Exception getting root scene objects, falling back to backup method...");
-
- m_getRootObjectsFailed = true;
- allTransforms.AddRange(GetRootObjectsManual_Impl());
- }
- }
- else
- {
- if (!manual)
- {
- return;
- }
-
- allTransforms.AddRange(GetRootObjectsManual_Impl());
}
}
@@ -178,36 +155,6 @@ namespace Explorer.UI.Main
}
}
- private IEnumerable GetRootObjectsManual_Impl()
- {
- try
- {
- var array = Resources.FindObjectsOfTypeAll(ReflectionHelpers.TransformType);
-
- var list = new List();
- foreach (var obj in array)
- {
-#if CPP
- var transform = obj.TryCast();
-#else
- var transform = obj as Transform;
-#endif
- if (transform.parent == null && transform.gameObject.scene.name == m_currentScene)
- {
- list.Add(transform);
- }
- }
- return list;
- }
- catch (Exception e)
- {
- ExplorerCore.Log("Exception getting root scene objects (manual): "
- + e.GetType() + ", " + e.Message + "\r\n"
- + e.StackTrace);
- return new Transform[0];
- }
- }
-
// --------- GUI Draw Function --------- //
public override void DrawWindow()
@@ -292,15 +239,12 @@ namespace Explorer.UI.Main
{
int index = names.IndexOf(m_currentScene);
index += changeWanted;
- if (index > scenes.Count - 1)
+
+ if (index >= 0 && index < SceneManager.sceneCount)
{
- index = 0;
+ m_currentScene = scenes[index].name;
+ Update_Impl();
}
- else if (index < 0)
- {
- index = scenes.Count - 1;
- }
- m_currentScene = scenes[index].name;
}
}
}
@@ -317,7 +261,7 @@ namespace Explorer.UI.Main
{
Pages.TurnPage(Turn.Left, ref this.scroll);
- Update_Impl(true);
+ Update_Impl();
}
Pages.CurrentPageLabel();
@@ -326,7 +270,7 @@ namespace Explorer.UI.Main
{
Pages.TurnPage(Turn.Right, ref this.scroll);
- Update_Impl(true);
+ Update_Impl();
}
}
@@ -356,14 +300,6 @@ namespace Explorer.UI.Main
else
{
GUILayout.Label("Scene Root GameObjects:", new GUILayoutOption[0]);
-
- if (m_getRootObjectsFailed)
- {
- if (GUILayout.Button("Update Root Object List (auto-update failed!)", new GUILayoutOption[0]))
- {
- Update_Impl(true);
- }
- }
}
if (m_objectList.Count > 0)
diff --git a/src/UI/Main/SearchPage.cs b/src/UI/Main/SearchPage.cs
index 5a92949..f4b50ad 100644
--- a/src/UI/Main/SearchPage.cs
+++ b/src/UI/Main/SearchPage.cs
@@ -117,13 +117,6 @@ namespace Explorer.UI.Main
Pages.PageOffset = 0;
- // Would use Task, but Explorer is .NET 3.5-compatible.
- var objectsOfType = FindAllObjectsOfType(m_searchInput, m_typeInput);
- CacheResults(objectsOfType);
- }
-
- private List