From ff684d4d4b02a982d2b12d7dd5598b8be81ef813 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Wed, 28 Oct 2020 06:39:26 +1100 Subject: [PATCH] Finished scene explorer, lots of cleanups. Inspector and Search left now. --- src/CacheObject/CacheEnumerated.cs | 4 +- src/CacheObject/CacheFactory.cs | 4 +- src/CacheObject/CacheField.cs | 6 +- src/CacheObject/CacheMember.cs | 6 +- src/CacheObject/CacheMethod.cs | 6 +- src/CacheObject/CacheObjectBase.cs | 8 +- src/CacheObject/CacheProperty.cs | 6 +- src/Config/ModConfig.cs | 19 +- src/Explorer.csproj | 64 +- src/ExplorerCore.cs | 49 +- src/ExplorerMelonMod.cs | 4 - src/Extensions/UnityExtensions.cs | 16 +- src/Helpers/ICallHelper.cs | 11 +- src/Helpers/ReflectionHelpers.cs | 28 +- src/Helpers/Texture2DHelpers.cs | 16 +- .../{IAbstractInput.cs => IHandleInput.cs} | 8 +- src/Input/InputManager.cs | 4 +- src/Input/InputSystem.cs | 7 +- src/Input/LegacyInput.cs | 7 +- src/Input/NoInput.cs | 8 +- src/Properties/AssemblyInfo.cs | 1 - .../Tests/TestClass.cs => Tests/Tests.cs} | 17 +- src/UI/ForceUnlockCursor.cs | 5 +- src/UI/InteractiveValue/InteractiveValue.cs | 10 +- .../Main/{Pages => }/Console/AutoCompleter.cs | 93 +- .../Console/Editor => Console}/CSharpLexer.cs | 24 +- .../Console/Editor => Console}/CodeEditor.cs | 80 +- .../Editor => Console}/Lexer/CommentMatch.cs | 12 +- .../Editor => Console}/Lexer/ILexer.cs | 8 +- .../Editor => Console}/Lexer/InputLexer.cs | 44 +- .../Editor => Console}/Lexer/KeywordMatch.cs | 34 +- .../Editor => Console}/Lexer/MatchLexer.cs | 8 +- .../Editor => Console}/Lexer/NumberMatch.cs | 9 +- .../Editor => Console}/Lexer/StringMatch.cs | 14 +- .../Editor => Console}/Lexer/SymbolMatch.cs | 32 +- .../ScriptEvaluator.cs | 10 +- src/UI/Main/Console/ScriptInteraction.cs | 92 ++ src/UI/Main/Console/Suggestion.cs | 81 ++ src/UI/Main/{Pages => }/ConsolePage.cs | 90 +- src/UI/Main/DebugConsole.cs | 97 +- src/UI/Main/HomePage.cs | 53 + src/UI/Main/InspectorManager.cs | 177 +++ src/UI/Main/Inspectors/GameObjectInspector.cs | 42 + src/UI/Main/Inspectors/InspectorBase.cs | 143 +++ src/UI/Main/Inspectors/InstanceInspector.cs | 40 + src/UI/Main/Inspectors/StaticInspector.cs | 26 + src/UI/Main/MainMenu.cs | 100 +- src/UI/Main/{Pages => }/OptionsPage.cs | 9 +- src/UI/Main/Pages/BaseMenuPage.cs | 27 - .../Console/ScriptEvaluator/AutoComplete.cs | 57 - .../ScriptEvaluator/ScriptInteraction.cs | 68 -- src/UI/Main/Pages/HomePage.cs | 311 ----- src/UI/Main/PanelDragger.cs | 94 +- src/UI/Main/SceneExplorer.cs | 478 ++++++++ src/UI/Main/{Pages => }/SearchPage.cs | 9 +- src/UI/Shared/PageHandler.cs | 170 +-- src/UI/Shared/Syntax.cs | 7 +- src/UI/UIFactory.cs | 1053 +++++++++-------- src/UI/UIManager.cs | 32 +- .../ColorUtility/ColorUtilityUnstrip.cs | 14 +- .../ImageConversion/ImageConversionUnstrip.cs | 20 +- src/Unstrip/LayerMask/LayerMaskUnstrip.cs | 6 +- src/Unstrip/Resources/ResourcesUnstrip.cs | 10 +- src/Unstrip/Scene/SceneUnstrip.cs | 12 +- 64 files changed, 2376 insertions(+), 1624 deletions(-) rename src/Input/{IAbstractInput.cs => IHandleInput.cs} (64%) rename src/{CacheObject/Tests/TestClass.cs => Tests/Tests.cs} (89%) rename src/UI/Main/{Pages => }/Console/AutoCompleter.cs (79%) rename src/UI/Main/{Pages/Console/Editor => Console}/CSharpLexer.cs (91%) rename src/UI/Main/{Pages/Console/Editor => Console}/CodeEditor.cs (88%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/CommentMatch.cs (90%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/ILexer.cs (70%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/InputLexer.cs (86%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/KeywordMatch.cs (83%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/MatchLexer.cs (82%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/NumberMatch.cs (83%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/StringMatch.cs (82%) rename src/UI/Main/{Pages/Console/Editor => Console}/Lexer/SymbolMatch.cs (87%) rename src/UI/Main/{Pages/Console/ScriptEvaluator => Console}/ScriptEvaluator.cs (91%) create mode 100644 src/UI/Main/Console/ScriptInteraction.cs create mode 100644 src/UI/Main/Console/Suggestion.cs rename src/UI/Main/{Pages => }/ConsolePage.cs (87%) create mode 100644 src/UI/Main/HomePage.cs create mode 100644 src/UI/Main/InspectorManager.cs create mode 100644 src/UI/Main/Inspectors/GameObjectInspector.cs create mode 100644 src/UI/Main/Inspectors/InspectorBase.cs create mode 100644 src/UI/Main/Inspectors/InstanceInspector.cs create mode 100644 src/UI/Main/Inspectors/StaticInspector.cs rename src/UI/Main/{Pages => }/OptionsPage.cs (53%) delete mode 100644 src/UI/Main/Pages/BaseMenuPage.cs delete mode 100644 src/UI/Main/Pages/Console/ScriptEvaluator/AutoComplete.cs delete mode 100644 src/UI/Main/Pages/Console/ScriptEvaluator/ScriptInteraction.cs delete mode 100644 src/UI/Main/Pages/HomePage.cs create mode 100644 src/UI/Main/SceneExplorer.cs rename src/UI/Main/{Pages => }/SearchPage.cs (52%) diff --git a/src/CacheObject/CacheEnumerated.cs b/src/CacheObject/CacheEnumerated.cs index c3072a7..d750e9a 100644 --- a/src/CacheObject/CacheEnumerated.cs +++ b/src/CacheObject/CacheEnumerated.cs @@ -3,9 +3,9 @@ //using System.Collections.Generic; //using System.Linq; //using System.Text; -//using Explorer.UI; +//using ExplorerBeta.UI; -//namespace Explorer.CacheObject +//namespace ExplorerBeta.CacheObject //{ // public class CacheEnumerated : CacheObjectBase // { diff --git a/src/CacheObject/CacheFactory.cs b/src/CacheObject/CacheFactory.cs index ff01146..3b27307 100644 --- a/src/CacheObject/CacheFactory.cs +++ b/src/CacheObject/CacheFactory.cs @@ -1,8 +1,8 @@ //using System; //using System.Reflection; -//using Explorer.CacheObject; +//using ExplorerBeta.CacheObject; //using UnityEngine; -//using Explorer.Helpers; +//using ExplorerBeta.Helpers; //namespace Explorer //{ diff --git a/src/CacheObject/CacheField.cs b/src/CacheObject/CacheField.cs index 493e61a..2a0fc41 100644 --- a/src/CacheObject/CacheField.cs +++ b/src/CacheObject/CacheField.cs @@ -3,10 +3,10 @@ //using System.Linq; //using System.Text; //using System.Reflection; -//using Explorer.UI; -//using Explorer.Helpers; +//using ExplorerBeta.UI; +//using ExplorerBeta.Helpers; -//namespace Explorer.CacheObject +//namespace ExplorerBeta.CacheObject //{ // public class CacheField : CacheMember // { diff --git a/src/CacheObject/CacheMember.cs b/src/CacheObject/CacheMember.cs index bd5ddd3..19cd677 100644 --- a/src/CacheObject/CacheMember.cs +++ b/src/CacheObject/CacheMember.cs @@ -3,10 +3,10 @@ //using System.Linq; //using System.Reflection; //using UnityEngine; -//using Explorer.UI; -//using Explorer.UI.Shared; +//using ExplorerBeta.UI; +//using ExplorerBeta.UI.Shared; -//namespace Explorer.CacheObject +//namespace ExplorerBeta.CacheObject //{ // public class CacheMember : CacheObjectBase // { diff --git a/src/CacheObject/CacheMethod.cs b/src/CacheObject/CacheMethod.cs index 7006d23..e2e4a17 100644 --- a/src/CacheObject/CacheMethod.cs +++ b/src/CacheObject/CacheMethod.cs @@ -3,10 +3,10 @@ //using System.Linq; //using System.Reflection; //using UnityEngine; -//using Explorer.UI.Shared; -//using Explorer.Helpers; +//using ExplorerBeta.UI.Shared; +//using ExplorerBeta.Helpers; -//namespace Explorer.CacheObject +//namespace ExplorerBeta.CacheObject //{ // public class CacheMethod : CacheMember // { diff --git a/src/CacheObject/CacheObjectBase.cs b/src/CacheObject/CacheObjectBase.cs index d82f8b8..416755b 100644 --- a/src/CacheObject/CacheObjectBase.cs +++ b/src/CacheObject/CacheObjectBase.cs @@ -3,11 +3,11 @@ //using System.Linq; //using System.Reflection; //using UnityEngine; -//using Explorer.UI; -//using Explorer.UI.Shared; -//using Explorer.Helpers; +//using ExplorerBeta.UI; +//using ExplorerBeta.UI.Shared; +//using ExplorerBeta.Helpers; -//namespace Explorer.CacheObject +//namespace ExplorerBeta.CacheObject //{ // public class CacheObjectBase // { diff --git a/src/CacheObject/CacheProperty.cs b/src/CacheObject/CacheProperty.cs index b3322c3..317535a 100644 --- a/src/CacheObject/CacheProperty.cs +++ b/src/CacheObject/CacheProperty.cs @@ -3,10 +3,10 @@ //using System.Linq; //using System.Text; //using System.Reflection; -//using Explorer.UI; -//using Explorer.Helpers; +//using ExplorerBeta.UI; +//using ExplorerBeta.Helpers; -//namespace Explorer.CacheObject +//namespace ExplorerBeta.CacheObject //{ // public class CacheProperty : CacheMember // { diff --git a/src/Config/ModConfig.cs b/src/Config/ModConfig.cs index da7eb5a..197ff98 100644 --- a/src/Config/ModConfig.cs +++ b/src/Config/ModConfig.cs @@ -14,21 +14,20 @@ namespace ExplorerBeta.Config [XmlIgnore] public static ModConfig Instance; // Actual configs - public KeyCode Main_Menu_Toggle = KeyCode.F7; + public KeyCode Main_Menu_Toggle = KeyCode.F7; public Vector2 Default_Window_Size = new Vector2(550, 700); - public int Default_Page_Limit = 20; - public bool Bitwise_Support = false; - public bool Tab_View = true; - public string Default_Output_Path = @"Mods\Explorer"; + public int Default_Page_Limit = 20; + public bool Bitwise_Support = false; + public bool Tab_View = true; + public string Default_Output_Path = @"Mods\Explorer"; public static void OnLoad() { if (!Directory.Exists(EXPLORER_FOLDER)) - { Directory.CreateDirectory(EXPLORER_FOLDER); - } - if (LoadSettings()) return; + if (LoadSettings()) + return; Instance = new ModConfig(); SaveSettings(); @@ -38,7 +37,9 @@ namespace ExplorerBeta.Config public static bool LoadSettings() { if (!File.Exists(SETTINGS_PATH)) + { return false; + } try { @@ -58,7 +59,9 @@ namespace ExplorerBeta.Config public static void SaveSettings() { if (File.Exists(SETTINGS_PATH)) + { File.Delete(SETTINGS_PATH); + } using (var file = File.Create(SETTINGS_PATH)) { diff --git a/src/Explorer.csproj b/src/Explorer.csproj index d201fc9..b1a921e 100644 --- a/src/Explorer.csproj +++ b/src/Explorer.csproj @@ -12,9 +12,10 @@ true ..\Release\Explorer.MelonLoader.Il2Cpp\ - - true - true + + + false + false false none false @@ -22,7 +23,7 @@ 4 x64 false - Explorer + ExplorerBeta ExplorerBeta D:\Steam\steamapps\common\VRChat @@ -85,8 +86,8 @@ False - - + - @@ -149,7 +149,6 @@ False - @@ -201,7 +200,6 @@ False - @@ -257,7 +255,6 @@ False - @@ -346,26 +343,31 @@ + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -384,7 +386,9 @@ - + + + diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 77e077c..3464507 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -1,21 +1,18 @@ using System; -using System.Collections; -using System.Linq; using ExplorerBeta.Config; using ExplorerBeta.Input; using ExplorerBeta.UI; using ExplorerBeta.UI.Main; -using System.Reflection; using UnityEngine; namespace ExplorerBeta { public class ExplorerCore { - public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")"; + public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")"; public const string VERSION = "3.0.0b"; - public const string AUTHOR = "Sinai"; - public const string GUID = "com.sinai.explorer"; + public const string AUTHOR = "Sinai"; + public const string GUID = "com.sinai.explorer"; public const string PLATFORM = #if CPP @@ -71,19 +68,15 @@ namespace ExplorerBeta private static void SetShowMenu(bool show) { m_showMenu = show; - + if (UIManager.CanvasRoot) { UIManager.CanvasRoot.SetActive(show); if (show) - { ForceUnlockCursor.SetEventSystem(); - } else - { ForceUnlockCursor.ReleaseEventSystem(); - } } ForceUnlockCursor.UpdateCursorControl(); @@ -91,24 +84,11 @@ namespace ExplorerBeta public static void Update() { - // Temporary delay before UIManager.Init if (!m_doneUIInit) - { - m_timeSinceStartup += Time.deltaTime; - - if (m_timeSinceStartup > 0.1f) - { - UIManager.Init(); - - Log("Initialized Explorer UI."); - m_doneUIInit = true; - } - } + CheckUIInit(); if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle)) - { ShowMenu = !ShowMenu; - } if (ShowMenu) { @@ -117,6 +97,25 @@ namespace ExplorerBeta } } + private static void CheckUIInit() + { + m_timeSinceStartup += Time.deltaTime; + + if (m_timeSinceStartup > 0.1f) + { + m_doneUIInit = true; + try + { + UIManager.Init(); + Log("Initialized Explorer UI."); + } + catch (Exception e) + { + LogWarning($"Exception setting up UI: {e}"); + } + } + } + public static void OnSceneChange() { UIManager.OnSceneChange(); diff --git a/src/ExplorerMelonMod.cs b/src/ExplorerMelonMod.cs index 6c92d96..816d68d 100644 --- a/src/ExplorerMelonMod.cs +++ b/src/ExplorerMelonMod.cs @@ -1,8 +1,4 @@ #if ML -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using MelonLoader; namespace ExplorerBeta diff --git a/src/Extensions/UnityExtensions.cs b/src/Extensions/UnityExtensions.cs index 70cd779..a7019ab 100644 --- a/src/Extensions/UnityExtensions.cs +++ b/src/Extensions/UnityExtensions.cs @@ -4,20 +4,16 @@ namespace ExplorerBeta { public static class UnityExtensions { - public static string GetGameObjectPath(this Transform _transform) + public static string GetTransformPath(this Transform _transform) { - return GetGameObjectPath(_transform, true); - } + string path = _transform.name; - public static string GetGameObjectPath(this Transform _transform, bool _includeThisName) - { - string path = _includeThisName ? ("/" + _transform.name) : ""; - GameObject gameObject = _transform.gameObject; - while (gameObject.transform.parent != null) + while (_transform.parent != null) { - gameObject = gameObject.transform.parent.gameObject; - path = "/" + gameObject.name + path; + _transform = _transform.parent; + path = _transform.name + "/" + path; } + return path; } } diff --git a/src/Helpers/ICallHelper.cs b/src/Helpers/ICallHelper.cs index 7e60783..ab4fe77 100644 --- a/src/Helpers/ICallHelper.cs +++ b/src/Helpers/ICallHelper.cs @@ -1,11 +1,8 @@ #if CPP using System; using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Reflection; using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ExplorerBeta.Helpers { @@ -17,18 +14,16 @@ namespace ExplorerBeta.Helpers public static T GetICall(string iCallName) where T : Delegate { if (iCallCache.ContainsKey(iCallName)) - { return (T)iCallCache[iCallName]; - } - var ptr = il2cpp_resolve_icall(iCallName); + IntPtr ptr = il2cpp_resolve_icall(iCallName); if (ptr == IntPtr.Zero) { throw new MissingMethodException($"Could not resolve internal call by name '{iCallName}'!"); } - var iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)); + Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)); iCallCache.Add(iCallName, iCall); return (T)iCall; diff --git a/src/Helpers/ReflectionHelpers.cs b/src/Helpers/ReflectionHelpers.cs index 4282fc4..76e0405 100644 --- a/src/Helpers/ReflectionHelpers.cs +++ b/src/Helpers/ReflectionHelpers.cs @@ -22,10 +22,10 @@ namespace ExplorerBeta.Helpers #if CPP public static ILType GameObjectType => Il2CppType.Of(); - public static ILType TransformType => Il2CppType.Of(); - public static ILType ObjectType => Il2CppType.Of(); - public static ILType ComponentType => Il2CppType.Of(); - public static ILType BehaviourType => Il2CppType.Of(); + public static ILType TransformType => Il2CppType.Of(); + public static ILType ObjectType => Il2CppType.Of(); + public static ILType ComponentType => Il2CppType.Of(); + public static ILType BehaviourType => Il2CppType.Of(); #else public static Type GameObjectType => typeof(GameObject); public static Type TransformType => typeof(Transform); @@ -40,10 +40,14 @@ namespace ExplorerBeta.Helpers public static object Il2CppCast(object obj, Type castTo) { if (!(obj is Il2CppSystem.Object ilObj)) + { return obj; + } if (!typeof(Il2CppSystem.Object).IsAssignableFrom(castTo)) + { return obj; + } IntPtr castToPtr; if (!ClassPointers.ContainsKey(castTo)) @@ -61,9 +65,11 @@ namespace ExplorerBeta.Helpers } if (castToPtr == IntPtr.Zero) + { return obj; + } - var classPtr = il2cpp_object_get_class(ilObj.Pointer); + IntPtr classPtr = il2cpp_object_get_class(ilObj.Pointer); if (!il2cpp_class_is_assignable_from(castToPtr, classPtr)) return obj; @@ -100,7 +106,8 @@ namespace ExplorerBeta.Helpers public static Type GetActualType(object obj) { - if (obj == null) return null; + if (obj == null) + return null; #if CPP // Need to use GetIl2CppType for Il2CppSystem Objects @@ -124,7 +131,7 @@ namespace ExplorerBeta.Helpers public static Type[] GetAllBaseTypes(Type type) { - var list = new List(); + List list = new List(); while (type != null) { @@ -139,11 +146,14 @@ namespace ExplorerBeta.Helpers { #if CPP #if ML - var path = $@"MelonLoader\Managed\{module}.dll"; + string path = $@"MelonLoader\Managed\{module}.dll"; #else var path = $@"BepInEx\unhollowed\{module}.dll"; #endif - if (!File.Exists(path)) return false; + if (!File.Exists(path)) + { + return false; + } try { diff --git a/src/Helpers/Texture2DHelpers.cs b/src/Helpers/Texture2DHelpers.cs index 3f0d9de..a326ac9 100644 --- a/src/Helpers/Texture2DHelpers.cs +++ b/src/Helpers/Texture2DHelpers.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; using System.IO; -using System.Reflection; #if CPP using ExplorerBeta.Unstrip.ImageConversion; #endif @@ -61,9 +57,7 @@ namespace ExplorerBeta.Helpers Color[] pixels; if (!orig.IsReadable()) - { orig = ForceReadTexture(orig); - } pixels = orig.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); @@ -77,7 +71,7 @@ namespace ExplorerBeta.Helpers { try { - var origFilter = tex.filterMode; + FilterMode origFilter = tex.filterMode; tex.filterMode = FilterMode.Point; var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32); @@ -105,12 +99,10 @@ namespace ExplorerBeta.Helpers public static void SaveTextureAsPNG(Texture2D tex, string dir, string name, bool isDTXnmNormal = false) { if (!Directory.Exists(dir)) - { Directory.CreateDirectory(dir); - } byte[] data; - var savepath = dir + @"\" + name + ".png"; + string savepath = dir + @"\" + name + ".png"; // Make sure we can EncodeToPNG it. if (tex.format != TextureFormat.ARGB32 || !tex.IsReadable()) @@ -154,12 +146,12 @@ namespace ExplorerBeta.Helpers for (int i = 0; i < colors.Length; i++) { - Color c = colors[i]; + var c = colors[i]; c.r = c.a * 2 - 1; // red <- alpha c.g = c.g * 2 - 1; // green is always the same - Vector2 rg = new Vector2(c.r, c.g); //this is the red-green vector + var rg = new Vector2(c.r, c.g); //this is the red-green vector c.b = Mathf.Sqrt(1 - Mathf.Clamp01(Vector2.Dot(rg, rg))); //recalculate the blue channel colors[i] = new Color( diff --git a/src/Input/IAbstractInput.cs b/src/Input/IHandleInput.cs similarity index 64% rename from src/Input/IAbstractInput.cs rename to src/Input/IHandleInput.cs index cae8ba5..f855ad5 100644 --- a/src/Input/IAbstractInput.cs +++ b/src/Input/IHandleInput.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace ExplorerBeta.Input { - public interface IAbstractInput + public interface IHandleInput { void Init(); diff --git a/src/Input/InputManager.cs b/src/Input/InputManager.cs index 1d28cd2..90157af 100644 --- a/src/Input/InputManager.cs +++ b/src/Input/InputManager.cs @@ -1,7 +1,5 @@ using System; -using System.Reflection; using UnityEngine; -using ExplorerBeta.Input; using ExplorerBeta.Helpers; using System.Diagnostics.CodeAnalysis; #if CPP @@ -13,7 +11,7 @@ namespace ExplorerBeta.Input [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Unity style")] public static class InputManager { - private static IAbstractInput m_inputModule; + private static IHandleInput m_inputModule; public static void Init() { diff --git a/src/Input/InputSystem.cs b/src/Input/InputSystem.cs index d09e88f..473d9c6 100644 --- a/src/Input/InputSystem.cs +++ b/src/Input/InputSystem.cs @@ -1,14 +1,11 @@ using System; using System.Reflection; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; using ExplorerBeta.Helpers; +using UnityEngine; namespace ExplorerBeta.Input { - public class InputSystem : IAbstractInput + public class InputSystem : IHandleInput { public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard")); private static Type m_tKeyboard; diff --git a/src/Input/LegacyInput.cs b/src/Input/LegacyInput.cs index c645dc8..2c43d12 100644 --- a/src/Input/LegacyInput.cs +++ b/src/Input/LegacyInput.cs @@ -1,14 +1,11 @@ using System; using System.Reflection; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; using ExplorerBeta.Helpers; +using UnityEngine; namespace ExplorerBeta.Input { - public class LegacyInput : IAbstractInput + public class LegacyInput : IHandleInput { public static Type TInput => m_tInput ?? (m_tInput = ReflectionHelpers.GetTypeByName("UnityEngine.Input")); private static Type m_tInput; diff --git a/src/Input/NoInput.cs b/src/Input/NoInput.cs index adccd6b..253b5ca 100644 --- a/src/Input/NoInput.cs +++ b/src/Input/NoInput.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace ExplorerBeta.Input { // Just a stub for games where no Input module was able to load at all. - public class NoInput : IAbstractInput + public class NoInput : IHandleInput { public Vector2 MousePosition => Vector2.zero; diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 4687cd6..037709c 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ExplorerBeta; diff --git a/src/CacheObject/Tests/TestClass.cs b/src/Tests/Tests.cs similarity index 89% rename from src/CacheObject/Tests/TestClass.cs rename to src/Tests/Tests.cs index 2f4b283..e61f126 100644 --- a/src/CacheObject/Tests/TestClass.cs +++ b/src/Tests/Tests.cs @@ -1,15 +1,8 @@ using System.Collections; using System.Collections.Generic; -using System; -using UnityEngine; -using System.Reflection; -using System.Runtime.InteropServices; -using ExplorerBeta.UI.Shared; using ExplorerBeta.UI; +using UnityEngine; #if CPP -using UnhollowerBaseLib; -using UnityEngine.SceneManagement; -using ExplorerBeta.Unstrip.ImageConversion; #endif namespace ExplorerBeta.Tests @@ -57,10 +50,10 @@ namespace ExplorerBeta.Tests #if CPP TestTexture.name = "TestTexture"; - var r = new Rect(0, 0, TestTexture.width, TestTexture.height); - var v2 = Vector2.zero; - var v4 = Vector4.zero; - TestSprite = Sprite.CreateSprite_Injected(TestTexture, ref r, ref v2, 100f, 0u, SpriteMeshType.Tight, ref v4, false); + //var r = new Rect(0, 0, TestTexture.width, TestTexture.height); + //var v2 = Vector2.zero; + //var v4 = Vector4.zero; + //TestSprite = Sprite.CreateSprite_Injected(TestTexture, ref r, ref v2, 100f, 0u, SpriteMeshType.Tight, ref v4, false); GameObject.DontDestroyOnLoad(TestTexture); GameObject.DontDestroyOnLoad(TestSprite); diff --git a/src/UI/ForceUnlockCursor.cs b/src/UI/ForceUnlockCursor.cs index bf66234..6de5ee9 100644 --- a/src/UI/ForceUnlockCursor.cs +++ b/src/UI/ForceUnlockCursor.cs @@ -2,7 +2,6 @@ using UnityEngine; using ExplorerBeta.Helpers; using UnityEngine.EventSystems; -using ExplorerBeta.UI; using ExplorerBeta.Input; using BF = System.Reflection.BindingFlags; #if ML @@ -83,7 +82,7 @@ namespace ExplorerBeta.UI { try { - var harmony = + HarmonyInstance harmony = #if ML ExplorerMelonMod.Instance.harmonyInstance; #else @@ -91,7 +90,7 @@ namespace ExplorerBeta.UI #endif ; - var prop = type.GetProperty(property); + System.Reflection.PropertyInfo prop = type.GetProperty(property); if (setter) { diff --git a/src/UI/InteractiveValue/InteractiveValue.cs b/src/UI/InteractiveValue/InteractiveValue.cs index 42927eb..603f490 100644 --- a/src/UI/InteractiveValue/InteractiveValue.cs +++ b/src/UI/InteractiveValue/InteractiveValue.cs @@ -3,11 +3,11 @@ //using System.Linq; //using System.Reflection; //using UnityEngine; -//using Explorer.CacheObject; -//using Explorer.Helpers; -//using Explorer.UI.Shared; +//using ExplorerBeta.CacheObject; +//using ExplorerBeta.Helpers; +//using ExplorerBeta.UI.Shared; -//namespace Explorer.UI +//namespace ExplorerBeta.UI //{ // public class InteractiveValue // { @@ -35,7 +35,7 @@ // GetButtonLabel(); // } - + // private MethodInfo GetToStringMethod() // { diff --git a/src/UI/Main/Pages/Console/AutoCompleter.cs b/src/UI/Main/Console/AutoCompleter.cs similarity index 79% rename from src/UI/Main/Pages/Console/AutoCompleter.cs rename to src/UI/Main/Console/AutoCompleter.cs index 43bcbd0..572713d 100644 --- a/src/UI/Main/Pages/Console/AutoCompleter.cs +++ b/src/UI/Main/Console/AutoCompleter.cs @@ -1,20 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ExplorerBeta; -using ExplorerBeta.Input; -using ExplorerBeta.UI; -using ExplorerBeta.UI.Main; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; #if CPP -using UnhollowerRuntimeLib; #endif -namespace Explorer.UI.Main.Pages.Console +namespace ExplorerBeta.UI.Main.Console { public class AutoCompleter { @@ -31,7 +24,7 @@ namespace Explorer.UI.Main.Pages.Console private static readonly List m_hiddenSuggestionTexts = new List(); private static bool m_suggestionsDirty; - private static AutoComplete[] m_suggestions = new AutoComplete[0]; + private static Suggestion[] m_suggestions = new Suggestion[0]; private static int m_lastBatchIndex; private static string m_prevInput = "NULL"; @@ -47,12 +40,16 @@ namespace Explorer.UI.Main.Pages.Console public static void Update() { if (!m_mainObj) + { return; + } if (!ConsolePage.EnableSuggestions) { if (m_mainObj.activeSelf) + { m_mainObj.SetActive(false); + } return; } @@ -62,7 +59,7 @@ namespace Explorer.UI.Main.Pages.Console UpdatePosition(); } - public static void SetSuggestions(AutoComplete[] suggestions) + public static void SetSuggestions(Suggestion[] suggestions) { m_suggestions = suggestions; @@ -73,12 +70,16 @@ namespace Explorer.UI.Main.Pages.Console private static void RefreshButtons() { if (!m_suggestionsDirty) + { return; + } if (m_suggestions.Length < 1) { if (m_mainObj.activeSelf) + { m_mainObj?.SetActive(false); + } return; } @@ -99,12 +100,16 @@ namespace Explorer.UI.Main.Pages.Console if (i >= m_suggestions.Length) { if (m_suggestionButtons[i].activeSelf) + { m_suggestionButtons[i].SetActive(false); + } } else { if (!m_suggestionButtons[i].activeSelf) + { m_suggestionButtons[i].SetActive(true); + } var suggestion = m_suggestions[i]; var label = m_suggestionTexts[i]; @@ -113,14 +118,7 @@ namespace Explorer.UI.Main.Pages.Console label.text = suggestion.Full; hiddenLabel.text = suggestion.Addition; - if (suggestion.Context == AutoComplete.Contexts.Namespace) - { - label.color = new Color(0.75f, 0.75f, 0.75f, 1.0f); - } - else - { - label.color = Color.white; - } + label.color = suggestion.TextColor; } m_lastBatchIndex = i; @@ -134,14 +132,20 @@ namespace Explorer.UI.Main.Pages.Console var editor = ConsolePage.Instance.m_codeEditor; if (editor.InputField.text.Length < 1) + { return; + } - var caretPos = editor.InputField.caretPosition; + int caretPos = editor.InputField.caretPosition; while (caretPos >= editor.inputText.textInfo.characterInfo.Length) + { caretPos--; + } if (caretPos == m_lastCaretPos) + { return; + } m_lastCaretPos = caretPos; @@ -149,9 +153,9 @@ namespace Explorer.UI.Main.Pages.Console { var pos = editor.inputText.textInfo.characterInfo[caretPos].bottomLeft; - pos = MainMenu.Instance.MainPanel.transform.TransformPoint(pos); + pos = editor.InputField.transform.TransformPoint(pos); - m_mainObj.transform.position = new Vector3(pos.x + m_thisRect.rect.width / 2, pos.y - 12, 0); + m_mainObj.transform.position = new Vector3(pos.x, pos.y - 3, 0); } } @@ -160,14 +164,14 @@ namespace Explorer.UI.Main.Pages.Console public static void CheckAutocomplete() { var m_codeEditor = ConsolePage.Instance.m_codeEditor; - var input = m_codeEditor.InputField.text; - var caretIndex = m_codeEditor.InputField.caretPosition; + string input = m_codeEditor.InputField.text; + int caretIndex = m_codeEditor.InputField.caretPosition; if (!string.IsNullOrEmpty(input)) { try { - var start = caretIndex <= 0 ? 0 : input.LastIndexOfAny(splitChars, caretIndex - 1) + 1; + int start = caretIndex <= 0 ? 0 : input.LastIndexOfAny(splitChars, caretIndex - 1) + 1; input = input.Substring(start, caretIndex - start).Trim(); } catch (ArgumentException) { } @@ -199,39 +203,52 @@ namespace Explorer.UI.Main.Pages.Console { // Credit ManylMarco ConsolePage.AutoCompletes.Clear(); - var completions = ConsolePage.Instance.m_evaluator.GetCompletions(input, out string prefix); + string[] completions = ConsolePage.Instance.m_evaluator.GetCompletions(input, out string prefix); if (completions != null) { if (prefix == null) + { prefix = input; + } ConsolePage.AutoCompletes.AddRange(completions .Where(x => !string.IsNullOrEmpty(x)) - .Select(x => new AutoComplete(x, prefix, AutoComplete.Contexts.Other)) + .Select(x => new Suggestion(x, prefix, Suggestion.Contexts.Other)) ); } - var trimmed = input.Trim(); + string trimmed = input.Trim(); if (trimmed.StartsWith("using")) + { trimmed = trimmed.Remove(0, 5).Trim(); + } - var namespaces = AutoCompleteHelpers.Namespaces + IEnumerable namespaces = Suggestion.Namespaces .Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length) - .Select(x => new AutoComplete( + .Select(x => new Suggestion( x.Substring(trimmed.Length), x.Substring(0, trimmed.Length), - AutoComplete.Contexts.Namespace)); + Suggestion.Contexts.Namespace)); ConsolePage.AutoCompletes.AddRange(namespaces); + + IEnumerable keywords = Suggestion.Keywords + .Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length) + .Select(x => new Suggestion( + x.Substring(trimmed.Length), + x.Substring(0, trimmed.Length), + Suggestion.Contexts.Keyword)); + + ConsolePage.AutoCompletes.AddRange(keywords); } catch (Exception ex) { - ExplorerCore.Log("C# Console error:\r\n" + ex); + ExplorerCore.Log("Autocomplete error:\r\n" + ex.ToString()); ClearAutocompletes(); } } -#region UI Construction + #region UI Construction private static void ConstructUI() { @@ -243,7 +260,7 @@ namespace Explorer.UI.Main.Pages.Console var mainRect = obj.GetComponent(); m_thisRect = mainRect; - mainRect.pivot = new Vector2(0.5f, 0.5f); + mainRect.pivot = new Vector2(0f, 1f); mainRect.anchorMin = new Vector2(0.45f, 0.45f); mainRect.anchorMax = new Vector2(0.65f, 0.6f); mainRect.offsetMin = Vector2.zero; @@ -258,10 +275,10 @@ namespace Explorer.UI.Main.Pages.Console for (int i = 0; i < MAX_LABELS; i++) { var buttonObj = UIFactory.CreateButton(content); - var btn = buttonObj.GetComponent