mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-22 08:32:51 +08:00
Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
604c499822 | |||
8964c48ba0 | |||
e85a3e0f1e | |||
c658d393f5 | |||
9a45e29e02 | |||
418ece55e3 | |||
bf455893e7 | |||
6d9cb8205a | |||
0f431e997b | |||
2107df70ad | |||
a9fbea7c96 | |||
77878ddd94 | |||
594abc47f8 | |||
5e326916a2 | |||
31c2debb78 | |||
d919497e43 | |||
0c40b4fad9 | |||
bba912667f | |||
1807e7c5ff | |||
9da2ea9b1b | |||
1a5843f8e1 | |||
25e48f2f37 | |||
1c0011bef9 | |||
9e996816ef | |||
9665753dc8 | |||
942e9d7555 | |||
9efb9581f5 | |||
f10a462b00 | |||
9072b16c5a |
56
README.md
56
README.md
@ -18,7 +18,7 @@
|
||||
- [How to install](#how-to-install)
|
||||
- [Mod Config](#mod-config)
|
||||
- [Building](#building)
|
||||
- [Credits](#credits)
|
||||
- [Acknowledgments](#acknowledgments)
|
||||
|
||||
## Releases
|
||||
|
||||
@ -46,6 +46,32 @@
|
||||
* <b>C# Console</b>: Interactive console for evaluating C# methods on the fly, with some basic helpers.
|
||||
* <b>Inspect-under-mouse</b>: Hover over an object with a collider and inspect it by clicking on it. There's also a UI mode to inspect UI objects.
|
||||
|
||||
### C# Console Tips
|
||||
|
||||
The C# Console can be used to define temporary classes and methods, or it can be used to evaluate an expression, but you cannot do both at the same time.
|
||||
|
||||
For example, you could run this code to define a temporary class (it will be visible within the console until you run `Reset();`).
|
||||
|
||||
```csharp
|
||||
public class MyClass
|
||||
{
|
||||
public static void Method()
|
||||
{
|
||||
UnityExplorer.ExplorerCore.Log("hello");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You could then delete or comment out the class and run the following expression to run that method:
|
||||
|
||||
```csharp
|
||||
MyClass.Method();
|
||||
```
|
||||
|
||||
However, you cannot define a class and run it both at the same time. You must either define class(es) and run that, or define an expression and run that.
|
||||
|
||||
You can also make use of the helper methods in the console to simplify some tasks, which you can see listed when the console has nothing entered for input. These methods are **not** accessible within any temporary classes you define, they can only be used in the expression context.
|
||||
|
||||
## How to install
|
||||
|
||||
### BepInEx
|
||||
@ -110,27 +136,21 @@ You can change the settings via the "Options" page of the main menu, or directly
|
||||
|
||||
## Building
|
||||
|
||||
If you'd like to build this yourself, all you need to do is download this repository and build from Visual Studio. If you want to build for BepInEx or MelonLoader IL2CPP then you will need to install the mod loader for a game and set the directory in the `csproj` file.
|
||||
If you'd like to build this yourself, all you need to do is download this repository and build from Visual Studio.
|
||||
|
||||
For IL2CPP:
|
||||
1. Install BepInEx or MelonLoader for your game.
|
||||
2. Open the `src\UnityExplorer.csproj` file in a text editor.
|
||||
3. Set `BIECppGameFolder` (for BepInEx) and/or `MLCppGameFolder` (for MelonLoader) so the project can locate the necessary references.
|
||||
4. For Standalone builds, you can either install BepInEx for the game to build, or just change the .csproj file and set the Unhollower reference manually.
|
||||
|
||||
For all builds:
|
||||
1. Open the `src\UnityExplorer.sln` project.
|
||||
2. Select `Solution 'UnityExplorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> property to the version you want to build, then build it.
|
||||
2. Select `Solution 'UnityExplorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> property to the version you want to build, then build it. Alternatively, use "Batch Build" and select all releases.
|
||||
3. The DLLs are built to the `Release\` folder in the root of the repository.
|
||||
4. If ILRepack fails or is missing, use the NuGet package manager to re-install `ILRepack.Lib.MSBuild.Task`, then re-build.
|
||||
|
||||
## Credits
|
||||
The references are all inside the `lib\` folder, if you need to change them for some reason then you can replace them there.
|
||||
|
||||
Written by Sinai.
|
||||
## Acknowledgments
|
||||
|
||||
### Licensing
|
||||
* [ManlyMarco](https://github.com/ManlyMarco) for [Runtime Unity Editor](https://github.com/ManlyMarco/RuntimeUnityEditor) (GPL), snippets from the REPL Console were used for UnityExplorer's C# Console.
|
||||
* [denikson](https://github.com/denikson) (aka Horse) for [mcs-unity](https://github.com/denikson/mcs-unity) (MIT), used as the `Mono.CSharp` reference for the C# Console.
|
||||
* [HerpDerpenstine](https://github.com/HerpDerpinstine) for [MelonCoroutines](https://github.com/LavaGang/MelonLoader/blob/master/MelonLoader.Support.Il2Cpp/MelonCoroutines.cs) (Apache), they were included for standalone Il2CPP coroutine support.
|
||||
* [InGameCodeEditor](https://assetstore.unity.com/packages/tools/gui/ingame-code-editor-144254) (Apache) was used as the base for the syntax highlighting for UnityExplorer's C# console (`UnityExplorer.UI.Main.CSConsole.Lexer`).
|
||||
|
||||
This project uses code from:
|
||||
* (GPL) [ManlyMarco](https://github.com/ManlyMarco)'s [Runtime Unity Editor](https://github.com/ManlyMarco/RuntimeUnityEditor), which I used for some aspects of the C# Console and Auto-Complete features. The snippets I used are indicated with a comment.
|
||||
* (MIT) [denikson](https://github.com/denikson) (aka Horse)'s [mcs-unity](https://github.com/denikson/mcs-unity). I commented out the `SkipVisibilityExt` constructor since it was causing an exception with the Hook it attempted in IL2CPP.
|
||||
* (Apache) [InGameCodeEditor](https://assetstore.unity.com/packages/tools/gui/ingame-code-editor-144254) was used as the base for the syntax highlighting for UnityExplorer's C# console, although it has been heavily rewritten and optimized. Used classes are in the `UnityExplorer.CSConsole.Lexer` namespace.
|
||||
### Disclaimer
|
||||
|
||||
UnityExplorer is in no way associated with Unity Technologies. "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere.
|
||||
|
BIN
lib/UnhollowerBaseLib.dll
Normal file
BIN
lib/UnhollowerBaseLib.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/Il2CppSystem.Core.dll
Normal file
BIN
lib/unhollowed/Il2CppSystem.Core.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/Il2Cppmscorlib.dll
Normal file
BIN
lib/unhollowed/Il2Cppmscorlib.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.CoreModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.CoreModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.IMGUIModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.IMGUIModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.PhysicsModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.PhysicsModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.TextRenderingModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.TextRenderingModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.UI.dll
Normal file
BIN
lib/unhollowed/UnityEngine.UI.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.UIModule.dll
Normal file
BIN
lib/unhollowed/UnityEngine.UIModule.dll
Normal file
Binary file not shown.
BIN
lib/unhollowed/UnityEngine.dll
Normal file
BIN
lib/unhollowed/UnityEngine.dll
Normal file
Binary file not shown.
29
src/Core/CSharp/DummyBehaviour.cs
Normal file
29
src/Core/CSharp/DummyBehaviour.cs
Normal file
@ -0,0 +1,29 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public class DummyBehaviour : MonoBehaviour
|
||||
{
|
||||
public static DummyBehaviour Instance;
|
||||
|
||||
public static void Setup()
|
||||
{
|
||||
var obj = new GameObject("Explorer_DummyBehaviour");
|
||||
DontDestroyOnLoad(obj);
|
||||
obj.hideFlags |= HideFlags.HideAndDontSave;
|
||||
|
||||
obj.AddComponent<DummyBehaviour>();
|
||||
}
|
||||
|
||||
internal void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -4,9 +4,9 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using Mono.CSharp;
|
||||
|
||||
// Thanks to ManlyMarco for this
|
||||
// Thanks to ManlyMarco for most of this
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public class ScriptEvaluator : Evaluator, IDisposable
|
||||
{
|
||||
@ -15,11 +15,12 @@ namespace UnityExplorer.CSConsole
|
||||
"mscorlib", "System.Core", "System", "System.Xml"
|
||||
};
|
||||
|
||||
private readonly TextWriter tw;
|
||||
internal static TextWriter _textWriter;
|
||||
internal static StreamReportPrinter _reportPrinter;
|
||||
|
||||
public ScriptEvaluator(TextWriter tw) : base(BuildContext(tw))
|
||||
{
|
||||
this.tw = tw;
|
||||
_textWriter = tw;
|
||||
|
||||
ImportAppdomainAssemblies(ReferenceAssembly);
|
||||
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
|
||||
@ -28,23 +29,22 @@ namespace UnityExplorer.CSConsole
|
||||
public void Dispose()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
|
||||
tw.Dispose();
|
||||
_textWriter.Dispose();
|
||||
}
|
||||
|
||||
private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
|
||||
{
|
||||
string name = args.LoadedAssembly.GetName().Name;
|
||||
|
||||
if (StdLib.Contains(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceAssembly(args.LoadedAssembly);
|
||||
}
|
||||
|
||||
private static CompilerContext BuildContext(TextWriter tw)
|
||||
{
|
||||
var reporter = new StreamReportPrinter(tw);
|
||||
_reportPrinter = new StreamReportPrinter(tw);
|
||||
|
||||
var settings = new CompilerSettings
|
||||
{
|
||||
@ -56,7 +56,7 @@ namespace UnityExplorer.CSConsole
|
||||
EnhancedWarnings = false
|
||||
};
|
||||
|
||||
return new CompilerContext(settings, reporter);
|
||||
return new CompilerContext(settings, _reportPrinter);
|
||||
}
|
||||
|
||||
private static void ImportAppdomainAssemblies(Action<Assembly> import)
|
@ -1,10 +1,16 @@
|
||||
using System;
|
||||
using Mono.CSharp;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.Inspectors;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public class ScriptInteraction : InteractiveBase
|
||||
{
|
||||
@ -13,19 +19,24 @@ namespace UnityExplorer.CSConsole
|
||||
ExplorerCore.Log(message);
|
||||
}
|
||||
|
||||
public static void StartCoroutine(IEnumerator ienumerator)
|
||||
{
|
||||
RuntimeProvider.Instance.StartConsoleCoroutine(ienumerator);
|
||||
}
|
||||
|
||||
public static void AddUsing(string directive)
|
||||
{
|
||||
CSConsolePage.Instance.AddUsing(directive);
|
||||
CSharpConsole.Instance.AddUsing(directive);
|
||||
}
|
||||
|
||||
public static void GetUsing()
|
||||
{
|
||||
ExplorerCore.Log(CSConsolePage.Instance.m_evaluator.GetUsing());
|
||||
ExplorerCore.Log(CSharpConsole.Instance.Evaluator.GetUsing());
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
CSConsolePage.Instance.ResetConsole();
|
||||
CSharpConsole.Instance.ResetConsole();
|
||||
}
|
||||
|
||||
public static object CurrentTarget()
|
@ -3,9 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
public struct Suggestion
|
||||
{
|
||||
@ -48,7 +50,7 @@ namespace UnityExplorer.CSConsole
|
||||
public static HashSet<string> Namespaces => m_namspaces ?? GetNamespaces();
|
||||
private static HashSet<string> m_namspaces;
|
||||
|
||||
public static HashSet<string> Keywords => m_keywords ?? (m_keywords = new HashSet<string>(CSharpLexer.validKeywordMatcher.Keywords));
|
||||
public static HashSet<string> Keywords => m_keywords ?? (m_keywords = new HashSet<string>(CSLexerHighlighter.validKeywordMatcher.Keywords));
|
||||
private static HashSet<string> m_keywords;
|
||||
|
||||
private static readonly Color keywordColor = new Color(80f / 255f, 150f / 255f, 215f / 255f);
|
@ -3,8 +3,10 @@ using System.IO;
|
||||
using UnityEngine;
|
||||
using IniParser;
|
||||
using IniParser.Parser;
|
||||
using UnityExplorer.UI;
|
||||
using System.Globalization;
|
||||
|
||||
namespace UnityExplorer.Config
|
||||
namespace UnityExplorer.Core.Config
|
||||
{
|
||||
public class ExplorerConfig
|
||||
{
|
||||
@ -13,19 +15,25 @@ namespace UnityExplorer.Config
|
||||
internal static readonly IniDataParser _parser = new IniDataParser();
|
||||
internal static readonly string INI_PATH = Path.Combine(ExplorerCore.Loader.ConfigFolder, "config.ini");
|
||||
|
||||
internal static CultureInfo _enCulture = new CultureInfo("en-US");
|
||||
|
||||
static ExplorerConfig()
|
||||
{
|
||||
_parser.Configuration.CommentString = "#";
|
||||
|
||||
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
|
||||
}
|
||||
|
||||
// Actual configs
|
||||
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
public bool Force_Unlock_Mouse = true;
|
||||
public int Default_Page_Limit = 25;
|
||||
public string Default_Output_Path = ExplorerCore.ExplorerFolder + @"\Output";
|
||||
public string Default_Output_Path = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "Output");
|
||||
public bool Log_Unity_Debug = false;
|
||||
public bool Hide_On_Startup = false;
|
||||
//public bool Save_Logs_To_Disk = true;
|
||||
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
|
||||
private const string DEFAULT_WINDOW_ANCHORS = "0.25,0.10,0.78,0.95";
|
||||
|
||||
public static event Action OnConfigChanged;
|
||||
|
||||
@ -75,9 +83,9 @@ namespace UnityExplorer.Config
|
||||
case nameof(Hide_On_Startup):
|
||||
Instance.Hide_On_Startup = bool.Parse(config.Value);
|
||||
break;
|
||||
//case nameof(Save_Logs_To_Disk):
|
||||
// Instance.Save_Logs_To_Disk = bool.Parse(config.Value);
|
||||
// break;
|
||||
case nameof(Window_Anchors):
|
||||
Instance.Window_Anchors = config.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,12 +105,67 @@ namespace UnityExplorer.Config
|
||||
sec.AddKey(nameof(Log_Unity_Debug), Instance.Log_Unity_Debug.ToString());
|
||||
sec.AddKey(nameof(Default_Output_Path), Instance.Default_Output_Path);
|
||||
sec.AddKey(nameof(Hide_On_Startup), Instance.Hide_On_Startup.ToString());
|
||||
//sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
|
||||
sec.AddKey(nameof(Window_Anchors), GetWindowAnchorsString());
|
||||
|
||||
if (!Directory.Exists(ExplorerCore.Loader.ConfigFolder))
|
||||
Directory.CreateDirectory(ExplorerCore.Loader.ConfigFolder);
|
||||
|
||||
File.WriteAllText(INI_PATH, data.ToString());
|
||||
}
|
||||
|
||||
// ============ Window Anchors specific stuff ============== //
|
||||
|
||||
private static void PanelDragger_OnFinishResize()
|
||||
{
|
||||
Instance.Window_Anchors = GetWindowAnchorsString();
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
internal Vector4 GetWindowAnchorsVector()
|
||||
{
|
||||
try
|
||||
{
|
||||
var split = Window_Anchors.Split(',');
|
||||
|
||||
if (split.Length != 4)
|
||||
throw new Exception();
|
||||
|
||||
Vector4 ret = Vector4.zero;
|
||||
ret.x = float.Parse(split[0], _enCulture);
|
||||
ret.y = float.Parse(split[1], _enCulture);
|
||||
ret.z = float.Parse(split[2], _enCulture);
|
||||
ret.w = float.Parse(split[3], _enCulture);
|
||||
return ret;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DefaultWindowAnchors();
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetWindowAnchorsString()
|
||||
{
|
||||
try
|
||||
{
|
||||
var rect = PanelDragger.Instance.Panel;
|
||||
return string.Format(_enCulture, "{0},{1},{2},{3}", new object[]
|
||||
{
|
||||
rect.anchorMin.x,
|
||||
rect.anchorMin.y,
|
||||
rect.anchorMax.x,
|
||||
rect.anchorMax.y
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DEFAULT_WINDOW_ANCHORS;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Vector4 DefaultWindowAnchors()
|
||||
{
|
||||
Instance.Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
return new Vector4(0.25f, 0.1f, 0.78f, 0.95f);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public interface IHandleInput
|
||||
{
|
@ -1,13 +1,9 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Helpers;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using UnityEngine.EventSystems;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public enum InputType
|
||||
{
|
||||
@ -43,12 +39,12 @@ namespace UnityExplorer.Input
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if (InputSystem.TKeyboard != null || (ReflectionHelpers.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
||||
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
||||
{
|
||||
m_inputModule = new InputSystem();
|
||||
CurrentType = InputType.InputSystem;
|
||||
}
|
||||
else if (LegacyInput.TInput != null || (ReflectionHelpers.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
|
||||
else if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
|
||||
{
|
||||
m_inputModule = new LegacyInput();
|
||||
CurrentType = InputType.Legacy;
|
@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public class InputSystem : IHandleInput
|
||||
{
|
||||
@ -17,7 +17,7 @@ namespace UnityExplorer.Input
|
||||
m_kbCurrentProp = TKeyboard.GetProperty("current");
|
||||
m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey });
|
||||
|
||||
var btnControl = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Controls.ButtonControl");
|
||||
var btnControl = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Controls.ButtonControl");
|
||||
m_btnIsPressedProp = btnControl.GetProperty("isPressed");
|
||||
m_btnWasPressedProp = btnControl.GetProperty("wasPressedThisFrame");
|
||||
|
||||
@ -25,21 +25,21 @@ namespace UnityExplorer.Input
|
||||
m_leftButtonProp = TMouse.GetProperty("leftButton");
|
||||
m_rightButtonProp = TMouse.GetProperty("rightButton");
|
||||
|
||||
m_positionProp = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
||||
m_positionProp = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
||||
.GetProperty("position");
|
||||
|
||||
m_readVector2InputMethod = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
||||
m_readVector2InputMethod = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
||||
.MakeGenericType(typeof(Vector2))
|
||||
.GetMethod("ReadValue");
|
||||
}
|
||||
|
||||
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||
private static Type m_tKeyboard;
|
||||
|
||||
public static Type TMouse => m_tMouse ?? (m_tMouse = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Mouse"));
|
||||
public static Type TMouse => m_tMouse ?? (m_tMouse = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Mouse"));
|
||||
private static Type m_tMouse;
|
||||
|
||||
public static Type TKey => m_tKey ?? (m_tKey = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Key"));
|
||||
public static Type TKey => m_tKey ?? (m_tKey = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Key"));
|
||||
private static Type m_tKey;
|
||||
|
||||
private static PropertyInfo m_btnIsPressedProp;
|
@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
public class LegacyInput : IHandleInput
|
||||
{
|
||||
@ -20,7 +20,7 @@ namespace UnityExplorer.Input
|
||||
m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
|
||||
}
|
||||
|
||||
public static Type TInput => m_tInput ?? (m_tInput = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
|
||||
public static Type TInput => m_tInput ?? (m_tInput = ReflectionUtility.GetTypeByName("UnityEngine.Input"));
|
||||
private static Type m_tInput;
|
||||
|
||||
private static PropertyInfo m_mousePositionProp;
|
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
// Just a stub for games where no Input module was able to load at all.
|
||||
|
138
src/Core/InspectorManager.cs
Normal file
138
src/Core/InspectorManager.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Inspectors.Reflection;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class InspectorManager
|
||||
{
|
||||
public static InspectorManager Instance { get; private set; }
|
||||
|
||||
internal static InspectorManagerUI UI;
|
||||
|
||||
public InspectorManager()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
UI = new InspectorManagerUI();
|
||||
UI.ConstructInspectorPane();
|
||||
}
|
||||
|
||||
public InspectorBase m_activeInspector;
|
||||
public readonly List<InspectorBase> m_currentInspectors = new List<InspectorBase>();
|
||||
|
||||
public void Update()
|
||||
{
|
||||
for (int i = 0; i < m_currentInspectors.Count; i++)
|
||||
{
|
||||
if (i >= m_currentInspectors.Count)
|
||||
break;
|
||||
|
||||
m_currentInspectors[i].Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void Inspect(object obj, CacheObjectBase parentMember = null)
|
||||
{
|
||||
obj = ReflectionProvider.Instance.Cast(obj, ReflectionProvider.Instance.GetActualType(obj));
|
||||
|
||||
UnityEngine.Object unityObj = obj as UnityEngine.Object;
|
||||
|
||||
if (obj.IsNullOrDestroyed(false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// check if currently inspecting this object
|
||||
foreach (InspectorBase tab in m_currentInspectors)
|
||||
{
|
||||
if (ReferenceEquals(obj, tab.Target))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
#if CPP
|
||||
else if (unityObj && tab.Target is UnityEngine.Object uTabObj)
|
||||
{
|
||||
if (unityObj.m_CachedPtr == uTabObj.m_CachedPtr)
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
InspectorBase inspector;
|
||||
if (obj is GameObject go)
|
||||
inspector = new GameObjectInspector(go);
|
||||
else
|
||||
inspector = new InstanceInspector(obj);
|
||||
|
||||
if (inspector is ReflectionInspector ri)
|
||||
ri.ParentMember = parentMember;
|
||||
|
||||
m_currentInspectors.Add(inspector);
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void Inspect(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("The provided type was null!");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var tab in m_currentInspectors.Where(x => x is StaticInspector))
|
||||
{
|
||||
if (ReferenceEquals(tab.Target as Type, type))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var inspector = new StaticInspector(type);
|
||||
|
||||
m_currentInspectors.Add(inspector);
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void SetInspectorTab(InspectorBase inspector)
|
||||
{
|
||||
MainMenu.Instance.SetPage(HomePage.Instance);
|
||||
|
||||
if (m_activeInspector == inspector)
|
||||
return;
|
||||
|
||||
UnsetInspectorTab();
|
||||
|
||||
m_activeInspector = inspector;
|
||||
inspector.SetActive();
|
||||
|
||||
UI.OnSetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void UnsetInspectorTab()
|
||||
{
|
||||
if (m_activeInspector == null)
|
||||
return;
|
||||
|
||||
m_activeInspector.SetInactive();
|
||||
|
||||
UI.OnUnsetInspectorTab();
|
||||
|
||||
m_activeInspector = null;
|
||||
}
|
||||
}
|
||||
}
|
101
src/Core/Inspectors/GameObjects/GameObjectInspector.cs
Normal file
101
src/Core/Inspectors/GameObjects/GameObjectInspector.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class GameObjectInspector : InspectorBase
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[G]</color> {TargetGO?.name}";
|
||||
|
||||
public static GameObjectInspector ActiveInstance { get; private set; }
|
||||
|
||||
public GameObject TargetGO;
|
||||
|
||||
public GameObjectInspectorUI UIModule;
|
||||
|
||||
// sub modules
|
||||
internal static ChildList s_childList;
|
||||
internal static ComponentList s_compList;
|
||||
internal static GameObjectControls s_controls;
|
||||
|
||||
internal static bool m_UIConstructed;
|
||||
|
||||
public GameObjectInspector(GameObject target) : base(target)
|
||||
{
|
||||
ActiveInstance = this;
|
||||
|
||||
TargetGO = target;
|
||||
|
||||
if (!TargetGO)
|
||||
{
|
||||
ExplorerCore.LogWarning("Target GameObject is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
// one UI is used for all gameobject inspectors. no point recreating it.
|
||||
if (!m_UIConstructed)
|
||||
{
|
||||
m_UIConstructed = true;
|
||||
|
||||
s_childList = new ChildList();
|
||||
s_compList = new ComponentList();
|
||||
s_controls = new GameObjectControls();
|
||||
|
||||
UIModule.ConstructUI();
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetActive()
|
||||
{
|
||||
base.SetActive();
|
||||
ActiveInstance = this;
|
||||
}
|
||||
|
||||
public override void SetInactive()
|
||||
{
|
||||
base.SetInactive();
|
||||
ActiveInstance = null;
|
||||
}
|
||||
|
||||
internal void ChangeInspectorTarget(GameObject newTarget)
|
||||
{
|
||||
if (!newTarget)
|
||||
return;
|
||||
|
||||
this.Target = this.TargetGO = newTarget;
|
||||
}
|
||||
|
||||
// Update
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (m_pendingDestroy || !this.IsActive)
|
||||
return;
|
||||
|
||||
UIModule.RefreshTopInfo();
|
||||
|
||||
s_childList.RefreshChildObjectList();
|
||||
|
||||
s_compList.RefreshComponentList();
|
||||
|
||||
s_controls.RefreshControls();
|
||||
|
||||
if (GameObjectControls.s_sliderChangedWanted)
|
||||
GameObjectControls.UpdateSliderControl();
|
||||
}
|
||||
|
||||
public override void CreateUIModule()
|
||||
{
|
||||
base.BaseUI = UIModule = new GameObjectInspectorUI();
|
||||
}
|
||||
}
|
||||
}
|
294
src/Core/Inspectors/InspectUnderMouse.cs
Normal file
294
src/Core/Inspectors/InspectUnderMouse.cs
Normal file
@ -0,0 +1,294 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class InspectUnderMouse
|
||||
{
|
||||
public enum MouseInspectMode
|
||||
{
|
||||
World,
|
||||
UI
|
||||
}
|
||||
|
||||
public static bool Enabled { get; set; }
|
||||
|
||||
public static MouseInspectMode Mode { get; set; }
|
||||
|
||||
private static GameObject s_lastHit;
|
||||
private static Vector3 s_lastMousePos;
|
||||
|
||||
internal static MouseInspectorUI UI;
|
||||
|
||||
static InspectUnderMouse()
|
||||
{
|
||||
UI = new MouseInspectorUI();
|
||||
}
|
||||
|
||||
private static readonly List<Graphic> _wasDisabledGraphics = new List<Graphic>();
|
||||
private static readonly List<CanvasGroup> _wasDisabledCanvasGroups = new List<CanvasGroup>();
|
||||
private static readonly List<GameObject> _objectsAddedCastersTo = new List<GameObject>();
|
||||
|
||||
public static void StartInspect(MouseInspectMode mode)
|
||||
{
|
||||
Mode = mode;
|
||||
Enabled = true;
|
||||
MainMenu.Instance.MainPanel.SetActive(false);
|
||||
|
||||
UI.s_UIContent.SetActive(true);
|
||||
|
||||
if (mode == MouseInspectMode.UI)
|
||||
{
|
||||
SetupUIRaycast();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ClearHitData()
|
||||
{
|
||||
s_lastHit = null;
|
||||
UI.s_objNameLabel.text = "No hits...";
|
||||
UI.s_objPathLabel.text = "";
|
||||
}
|
||||
|
||||
public static void StopInspect()
|
||||
{
|
||||
Enabled = false;
|
||||
MainMenu.Instance.MainPanel.SetActive(true);
|
||||
UI.s_UIContent.SetActive(false);
|
||||
|
||||
if (Mode == MouseInspectMode.UI)
|
||||
StopUIInspect();
|
||||
|
||||
ClearHitData();
|
||||
}
|
||||
|
||||
internal static GraphicRaycaster[] m_gCasters;
|
||||
|
||||
public static void UpdateInspect()
|
||||
{
|
||||
if (InputManager.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
StopInspect();
|
||||
return;
|
||||
}
|
||||
|
||||
var mousePos = InputManager.MousePosition;
|
||||
|
||||
if (mousePos != s_lastMousePos)
|
||||
UpdatePosition(mousePos);
|
||||
|
||||
if (!UnityHelper.MainCamera)
|
||||
return;
|
||||
|
||||
// actual inspect raycast
|
||||
|
||||
switch (Mode)
|
||||
{
|
||||
case MouseInspectMode.UI:
|
||||
RaycastUI(mousePos); break;
|
||||
case MouseInspectMode.World:
|
||||
RaycastWorld(mousePos); break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdatePosition(Vector2 mousePos)
|
||||
{
|
||||
s_lastMousePos = mousePos;
|
||||
|
||||
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
|
||||
|
||||
UI.s_mousePosLabel.text = $"<color=grey>Mouse Position:</color> {mousePos.ToString()}";
|
||||
|
||||
float yFix = mousePos.y < 120 ? 80 : -80;
|
||||
UI.s_UIContent.transform.localPosition = new Vector3(inversePos.x, inversePos.y + yFix, 0);
|
||||
}
|
||||
|
||||
internal static void OnHitGameObject(GameObject obj)
|
||||
{
|
||||
if (obj != s_lastHit)
|
||||
{
|
||||
s_lastHit = obj;
|
||||
UI.s_objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
||||
UI.s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
||||
}
|
||||
|
||||
if (InputManager.GetMouseButtonDown(0))
|
||||
{
|
||||
StopInspect();
|
||||
InspectorManager.Instance.Inspect(obj);
|
||||
}
|
||||
}
|
||||
|
||||
// Collider raycasting
|
||||
|
||||
internal static void RaycastWorld(Vector2 mousePos)
|
||||
{
|
||||
var ray = UnityHelper.MainCamera.ScreenPointToRay(mousePos);
|
||||
Physics.Raycast(ray, out RaycastHit hit, 1000f);
|
||||
|
||||
if (hit.transform)
|
||||
{
|
||||
var obj = hit.transform.gameObject;
|
||||
OnHitGameObject(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_lastHit)
|
||||
ClearHitData();
|
||||
}
|
||||
}
|
||||
|
||||
// UI Graphic raycasting
|
||||
|
||||
private static void SetupUIRaycast()
|
||||
{
|
||||
foreach (var obj in RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(Canvas)))
|
||||
{
|
||||
var canvas = obj.Cast(typeof(Canvas)) as Canvas;
|
||||
if (!canvas || !canvas.enabled || !canvas.gameObject.activeInHierarchy)
|
||||
continue;
|
||||
if (!canvas.GetComponent<GraphicRaycaster>())
|
||||
{
|
||||
canvas.gameObject.AddComponent<GraphicRaycaster>();
|
||||
//ExplorerCore.Log("Added raycaster to " + canvas.name);
|
||||
_objectsAddedCastersTo.Add(canvas.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// recache Graphic Raycasters each time we start
|
||||
var casters = RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(GraphicRaycaster));
|
||||
m_gCasters = new GraphicRaycaster[casters.Length];
|
||||
for (int i = 0; i < casters.Length; i++)
|
||||
{
|
||||
m_gCasters[i] = casters[i].Cast(typeof(GraphicRaycaster)) as GraphicRaycaster;
|
||||
}
|
||||
|
||||
// enable raycastTarget on Graphics
|
||||
foreach (var obj in RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(Graphic)))
|
||||
{
|
||||
var graphic = obj.Cast(typeof(Graphic)) as Graphic;
|
||||
if (!graphic || !graphic.enabled || graphic.raycastTarget || !graphic.gameObject.activeInHierarchy)
|
||||
continue;
|
||||
graphic.raycastTarget = true;
|
||||
//ExplorerCore.Log("Enabled raycastTarget on " + graphic.name);
|
||||
_wasDisabledGraphics.Add(graphic);
|
||||
}
|
||||
|
||||
// enable blocksRaycasts on CanvasGroups
|
||||
foreach (var obj in RuntimeProvider.Instance.FindObjectsOfTypeAll(typeof(CanvasGroup)))
|
||||
{
|
||||
var canvas = obj.Cast(typeof(CanvasGroup)) as CanvasGroup;
|
||||
if (!canvas || !canvas.gameObject.activeInHierarchy || canvas.blocksRaycasts)
|
||||
continue;
|
||||
canvas.blocksRaycasts = true;
|
||||
//ExplorerCore.Log("Enabled raycasts on " + canvas.name);
|
||||
_wasDisabledCanvasGroups.Add(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RaycastUI(Vector2 mousePos)
|
||||
{
|
||||
var ped = new PointerEventData(null)
|
||||
{
|
||||
position = mousePos
|
||||
};
|
||||
|
||||
#if MONO
|
||||
var list = new List<RaycastResult>();
|
||||
#else
|
||||
var list = new Il2CppSystem.Collections.Generic.List<RaycastResult>();
|
||||
#endif
|
||||
//ExplorerCore.Log("~~~~~~~~~ begin raycast ~~~~~~~~");
|
||||
GameObject hitObject = null;
|
||||
int highestLayer = int.MinValue;
|
||||
int highestOrder = int.MinValue;
|
||||
int highestDepth = int.MinValue;
|
||||
foreach (var gr in m_gCasters)
|
||||
{
|
||||
gr.Raycast(ped, list);
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
foreach (var hit in list)
|
||||
{
|
||||
if (!hit.gameObject)
|
||||
continue;
|
||||
|
||||
if (hit.gameObject.GetComponent<CanvasGroup>() is CanvasGroup group && group.alpha == 0)
|
||||
continue;
|
||||
|
||||
if (hit.gameObject.GetComponent<Graphic>() is Graphic graphic && graphic.color.a == 0f)
|
||||
continue;
|
||||
|
||||
//ExplorerCore.Log("Hit: " + hit.gameObject.name + ", depth: " + hit.depth + ", layer: " + hit.sortingLayer + ", order: " + hit.sortingOrder);
|
||||
|
||||
if (hit.sortingLayer < highestLayer)
|
||||
continue;
|
||||
|
||||
if (hit.sortingLayer > highestLayer)
|
||||
{
|
||||
highestLayer = hit.sortingLayer;
|
||||
highestOrder = int.MinValue;
|
||||
}
|
||||
|
||||
if (hit.depth < highestDepth)
|
||||
continue;
|
||||
|
||||
if (hit.depth > highestDepth)
|
||||
{
|
||||
highestDepth = hit.depth;
|
||||
highestOrder = int.MinValue;
|
||||
}
|
||||
|
||||
if (hit.sortingOrder <= highestOrder)
|
||||
continue;
|
||||
|
||||
highestOrder = hit.sortingOrder;
|
||||
hitObject = hit.gameObject;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_lastHit)
|
||||
ClearHitData();
|
||||
}
|
||||
}
|
||||
|
||||
if (hitObject)
|
||||
OnHitGameObject(hitObject);
|
||||
|
||||
//ExplorerCore.Log("~~~~~~~~~ end raycast ~~~~~~~~");
|
||||
}
|
||||
|
||||
private static void StopUIInspect()
|
||||
{
|
||||
foreach (var obj in _objectsAddedCastersTo)
|
||||
{
|
||||
if (obj.GetComponent<GraphicRaycaster>() is GraphicRaycaster raycaster)
|
||||
GameObject.Destroy(raycaster);
|
||||
}
|
||||
|
||||
foreach (var graphic in _wasDisabledGraphics)
|
||||
graphic.raycastTarget = false;
|
||||
|
||||
foreach (var canvas in _wasDisabledCanvasGroups)
|
||||
canvas.blocksRaycasts = false;
|
||||
|
||||
_objectsAddedCastersTo.Clear();
|
||||
_wasDisabledCanvasGroups.Clear();
|
||||
_wasDisabledGraphics.Clear();
|
||||
}
|
||||
}
|
||||
}
|
92
src/Core/Inspectors/InspectorBase.cs
Normal file
92
src/Core/Inspectors/InspectorBase.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public abstract class InspectorBase
|
||||
{
|
||||
public object Target;
|
||||
|
||||
public InspectorBaseUI BaseUI;
|
||||
|
||||
public abstract string TabLabel { get; }
|
||||
|
||||
public bool IsActive { get; private set; }
|
||||
|
||||
internal bool m_pendingDestroy;
|
||||
|
||||
public InspectorBase(object target)
|
||||
{
|
||||
Target = target;
|
||||
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
CreateUIModule();
|
||||
|
||||
BaseUI.AddInspectorTab(this);
|
||||
}
|
||||
|
||||
public abstract void CreateUIModule();
|
||||
|
||||
public virtual void SetActive()
|
||||
{
|
||||
this.IsActive = true;
|
||||
BaseUI.Content?.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void SetInactive()
|
||||
{
|
||||
this.IsActive = false;
|
||||
BaseUI.Content?.SetActive(false);
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
BaseUI.tabText.text = TabLabel;
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
m_pendingDestroy = true;
|
||||
|
||||
GameObject tabGroup = BaseUI.tabButton?.transform.parent.gameObject;
|
||||
|
||||
if (tabGroup)
|
||||
{
|
||||
GameObject.Destroy(tabGroup);
|
||||
}
|
||||
|
||||
int thisIndex = -1;
|
||||
if (InspectorManager.Instance.m_currentInspectors.Contains(this))
|
||||
{
|
||||
thisIndex = InspectorManager.Instance.m_currentInspectors.IndexOf(this);
|
||||
InspectorManager.Instance.m_currentInspectors.Remove(this);
|
||||
}
|
||||
|
||||
if (ReferenceEquals(InspectorManager.Instance.m_activeInspector, this))
|
||||
{
|
||||
InspectorManager.Instance.UnsetInspectorTab();
|
||||
|
||||
if (InspectorManager.Instance.m_currentInspectors.Count > 0)
|
||||
{
|
||||
var prevTab = InspectorManager.Instance.m_currentInspectors[thisIndex > 0 ? thisIndex - 1 : 0];
|
||||
InspectorManager.Instance.SetInspectorTab(prevTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheEnumerated : CacheObjectBase
|
||||
{
|
@ -4,10 +4,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheField : CacheMember
|
||||
{
|
@ -5,13 +5,13 @@ using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Helpers;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
#endif
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public abstract class CacheMember : CacheObjectBase
|
||||
{
|
||||
@ -50,10 +50,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
DeclaringType = memberInfo.DeclaringType;
|
||||
DeclaringInstance = declaringInstance;
|
||||
this.m_parentContent = parentContent;
|
||||
#if CPP
|
||||
if (DeclaringInstance != null)
|
||||
DeclaringInstance = DeclaringInstance.Il2CppCast(DeclaringType);
|
||||
#endif
|
||||
|
||||
DeclaringInstance = ReflectionProvider.Instance.Cast(declaringInstance, DeclaringType);
|
||||
}
|
||||
|
||||
public static bool CanProcessArgs(ParameterInfo[] parameters)
|
||||
@ -87,19 +85,19 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
try
|
||||
{
|
||||
#if CPP
|
||||
if (!IsReflectionSupported())
|
||||
throw new Exception("Type not supported with Reflection");
|
||||
#endif
|
||||
Type baseType = ReflectionUtility.GetType(IValue.Value) ?? FallbackType;
|
||||
|
||||
if (!ReflectionProvider.Instance.IsReflectionSupported(baseType))
|
||||
throw new Exception("Type not supported with reflection");
|
||||
|
||||
UpdateReflection();
|
||||
#if CPP
|
||||
|
||||
if (IValue.Value != null)
|
||||
IValue.Value = IValue.Value.Il2CppCast(ReflectionHelpers.GetActualType(IValue.Value));
|
||||
#endif
|
||||
IValue.Value = IValue.Value.Cast(ReflectionUtility.GetType(IValue.Value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e, true);
|
||||
ReflectionException = e.ReflectionExToString(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,46 +177,9 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
private string GetRichTextName()
|
||||
{
|
||||
return m_richTextName = UISyntaxHighlight.ParseFullSyntax(MemInfo.DeclaringType, false, MemInfo);
|
||||
return m_richTextName = SignatureHighlighter.ParseFullSyntax(MemInfo.DeclaringType, false, MemInfo);
|
||||
}
|
||||
|
||||
#if CPP
|
||||
internal bool IsReflectionSupported()
|
||||
{
|
||||
try
|
||||
{
|
||||
var baseType = ReflectionHelpers.GetActualType(IValue.Value) ?? IValue.FallbackType;
|
||||
|
||||
var gArgs = baseType.GetGenericArguments();
|
||||
if (gArgs.Length < 1)
|
||||
return true;
|
||||
|
||||
foreach (var arg in gArgs)
|
||||
{
|
||||
if (!Check(arg))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
bool Check(Type type)
|
||||
{
|
||||
if (!typeof(Il2CppSystem.Object).IsAssignableFrom(type))
|
||||
return true;
|
||||
|
||||
if (!ReflectionHelpers.Il2CppTypeNotNull(type, out IntPtr ptr))
|
||||
return false;
|
||||
|
||||
return Il2CppSystem.Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is Il2CppSystem.Type;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#region UI
|
||||
|
||||
internal float GetMemberLabelWidth(RectTransform scrollRect)
|
||||
@ -380,8 +341,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
var argLabelLayout = argLabelObj.AddComponent<LayoutElement>();
|
||||
argLabelLayout.minHeight = 25;
|
||||
var argText = argLabelObj.GetComponent<Text>();
|
||||
var argTypeTxt = UISyntaxHighlight.ParseFullSyntax(arg.ParameterType, false);
|
||||
argText.text = $"{argTypeTxt} <color={UISyntaxHighlight.Local}>{arg.Name}</color>";
|
||||
var argTypeTxt = SignatureHighlighter.ParseFullSyntax(arg.ParameterType, false);
|
||||
argText.text = $"{argTypeTxt} <color={SignatureHighlighter.LOCAL_ARG}>{arg.Name}</color>";
|
||||
|
||||
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
|
||||
var argInputLayout = argInputObj.AddComponent<LayoutElement>();
|
@ -5,9 +5,11 @@ using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheMethod : CacheMember
|
||||
{
|
||||
@ -75,7 +77,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
e = e.InnerException;
|
||||
|
||||
ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
ReflectionException = ReflectionUtility.ReflectionExToString(e);
|
||||
}
|
||||
|
||||
IValue.Value = ret;
|
||||
@ -90,7 +92,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
for (int i = 0; i < GenericArgs.Length; i++)
|
||||
{
|
||||
var input = m_genericArgInput[i];
|
||||
if (ReflectionHelpers.GetTypeByName(input) is Type t)
|
||||
if (ReflectionUtility.GetTypeByName(input) is Type t)
|
||||
{
|
||||
if (GenericConstraints[i].Length == 0)
|
||||
{
|
||||
@ -150,7 +152,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
if (constrainTxt != "")
|
||||
constrainTxt += ", ";
|
||||
|
||||
constrainTxt += $"{UISyntaxHighlight.ParseFullSyntax(constraint, false)}";
|
||||
constrainTxt += $"{SignatureHighlighter.ParseFullSyntax(constraint, false)}";
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -168,7 +170,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
//var argLayout = argLabelObj.AddComponent<LayoutElement>();
|
||||
//argLayout.minWidth = 20;
|
||||
var argText = argLabelObj.GetComponent<Text>();
|
||||
argText.text = $"{constrainTxt} <color={UISyntaxHighlight.Enum}>{arg.Name}</color>";
|
||||
argText.text = $"{constrainTxt} <color={SignatureHighlighter.CONST_VAR}>{arg.Name}</color>";
|
||||
|
||||
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
|
||||
var argInputLayout = argInputObj.AddComponent<LayoutElement>();
|
@ -4,11 +4,12 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public abstract class CacheObjectBase
|
||||
{
|
||||
@ -54,7 +55,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
// if the type has changed fundamentally, make a new interactivevalue for it
|
||||
var type = value == null
|
||||
? FallbackType
|
||||
: ReflectionHelpers.GetActualType(value);
|
||||
: ReflectionUtility.GetType(value);
|
||||
|
||||
var ivalueType = InteractiveValue.GetIValueForType(type);
|
||||
|
@ -8,7 +8,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public enum PairTypes
|
||||
{
|
@ -4,10 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class CacheProperty : CacheMember
|
||||
{
|
54
src/Core/Inspectors/Reflection/InstanceInspector.cs
Normal file
54
src/Core/Inspectors/Reflection/InstanceInspector.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
using System.IO;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public enum MemberScopes
|
||||
{
|
||||
All,
|
||||
Instance,
|
||||
Static
|
||||
}
|
||||
|
||||
public class InstanceInspector : ReflectionInspector
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[R]</color> {base.TabLabel}";
|
||||
|
||||
internal MemberScopes m_scopeFilter;
|
||||
internal Button m_lastActiveScopeButton;
|
||||
|
||||
public InstanceInspector(object target) : base(target) { }
|
||||
|
||||
internal InstanceInspectorUI InstanceUI;
|
||||
public void CreateInstanceUIModule()
|
||||
{
|
||||
InstanceUI = new InstanceInspectorUI(this);
|
||||
}
|
||||
|
||||
internal void OnScopeFilterClicked(MemberScopes type, Button button)
|
||||
{
|
||||
if (m_lastActiveScopeButton)
|
||||
{
|
||||
var lastColors = m_lastActiveScopeButton.colors;
|
||||
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
m_lastActiveScopeButton.colors = lastColors;
|
||||
}
|
||||
|
||||
m_scopeFilter = type;
|
||||
m_lastActiveScopeButton = button;
|
||||
|
||||
var colors = m_lastActiveScopeButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_lastActiveScopeButton.colors = colors;
|
||||
|
||||
FilterMembers(null, true);
|
||||
base.ReflectionUI.m_sliderScroller.m_slider.value = 1f;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveBool : InteractiveValue
|
||||
{
|
@ -5,16 +5,16 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using System.Reflection;
|
||||
#if CPP
|
||||
using CppDictionary = Il2CppSystem.Collections.IDictionary;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveDictionary : InteractiveValue
|
||||
{
|
@ -4,10 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveEnum : InteractiveValue
|
||||
{
|
@ -6,12 +6,12 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveEnumerable : InteractiveValue
|
||||
{
|
@ -4,10 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveFlags : InteractiveEnum
|
||||
{
|
@ -5,10 +5,12 @@ using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveNumber : InteractiveValue
|
||||
{
|
||||
@ -46,7 +48,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
return;
|
||||
}
|
||||
|
||||
m_baseLabel.text = UISyntaxHighlight.ParseFullSyntax(FallbackType, false);
|
||||
m_baseLabel.text = SignatureHighlighter.ParseFullSyntax(FallbackType, false);
|
||||
m_valueInput.text = Value.ToString();
|
||||
|
||||
var type = Value.GetType();
|
||||
@ -84,7 +86,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not parse input! " + ReflectionHelpers.ExceptionToString(e, true));
|
||||
ExplorerCore.LogWarning("Could not parse input! " + ReflectionUtility.ReflectionExToString(e, true));
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,11 @@ using System.Text;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveString : InteractiveValue
|
||||
{
|
||||
@ -109,7 +110,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
base.ConstructUI(parent, subGroup);
|
||||
|
||||
GetDefaultLabel(false);
|
||||
m_richValueType = UISyntaxHighlight.ParseFullSyntax(FallbackType, false);
|
||||
m_richValueType = SignatureHighlighter.ParseFullSyntax(FallbackType, false);
|
||||
|
||||
m_labelLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
|
||||
|
@ -4,10 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
#region IStructInfo helper
|
||||
|
@ -5,43 +5,64 @@ using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveValue
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the <see cref="InteractiveValue"/> subclass which supports the provided <paramref name="type"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">The <see cref="Type"/> which you want the <see cref="InteractiveValue"/> Type for.</param>
|
||||
/// <returns>The best subclass of <see cref="InteractiveValue"/> which supports the provided <paramref name="type"/>.</returns>
|
||||
public static Type GetIValueForType(Type type)
|
||||
{
|
||||
// rather ugly but I couldn't think of a cleaner way that was worth it.
|
||||
// switch-case doesn't really work here.
|
||||
|
||||
// arbitrarily check some types, fastest methods first.
|
||||
if (type == typeof(bool))
|
||||
return typeof(InteractiveBool);
|
||||
else if (type == typeof(string))
|
||||
return typeof(InteractiveString);
|
||||
// if type is primitive then it must be a number if its not a bool
|
||||
else if (type.IsPrimitive)
|
||||
return typeof(InteractiveNumber);
|
||||
// check for strings
|
||||
else if (type == typeof(string))
|
||||
return typeof(InteractiveString);
|
||||
// check for enum/flags
|
||||
else if (typeof(Enum).IsAssignableFrom(type))
|
||||
{
|
||||
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] attributes && attributes.Length > 0)
|
||||
// NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version.
|
||||
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Any())
|
||||
return typeof(InteractiveFlags);
|
||||
else
|
||||
return typeof(InteractiveEnum);
|
||||
}
|
||||
// check for unity struct types
|
||||
else if (InteractiveUnityStruct.SupportsType(type))
|
||||
return typeof(InteractiveUnityStruct);
|
||||
// check Transform, force InteractiveValue so they dont become InteractiveEnumerables.
|
||||
else if (typeof(Transform).IsAssignableFrom(type))
|
||||
return typeof(InteractiveValue);
|
||||
else if (ReflectionHelpers.IsDictionary(type))
|
||||
// check Dictionaries before Enumerables
|
||||
else if (ReflectionUtility.IsDictionary(type))
|
||||
return typeof(InteractiveDictionary);
|
||||
else if (ReflectionHelpers.IsEnumerable(type))
|
||||
// finally check for Enumerables
|
||||
else if (ReflectionUtility.IsEnumerable(type))
|
||||
return typeof(InteractiveEnumerable);
|
||||
// fallback to default
|
||||
else
|
||||
return typeof(InteractiveValue);
|
||||
}
|
||||
|
||||
public static InteractiveValue Create(object value, Type fallbackType)
|
||||
{
|
||||
var type = ReflectionHelpers.GetActualType(value) ?? fallbackType;
|
||||
var type = ReflectionUtility.GetType(value) ?? fallbackType;
|
||||
var iType = GetIValueForType(type);
|
||||
|
||||
return (InteractiveValue)Activator.CreateInstance(iType, new object[] { value, type });
|
||||
@ -184,7 +205,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
var valueType = Value?.GetType() ?? this.FallbackType;
|
||||
if (updateType)
|
||||
m_richValueType = UISyntaxHighlight.ParseFullSyntax(valueType, true);
|
||||
m_richValueType = SignatureHighlighter.ParseFullSyntax(valueType, true);
|
||||
|
||||
if (!Owner.HasEvaluated)
|
||||
return m_defaultLabel = $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
|
||||
@ -194,6 +215,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
string label;
|
||||
|
||||
// Two dirty fixes for TextAsset and EventSystem, which can have very long ToString results.
|
||||
if (Value is TextAsset textAsset)
|
||||
{
|
||||
label = textAsset.text;
|
||||
@ -207,7 +229,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
label = m_richValueType;
|
||||
}
|
||||
else
|
||||
else // For everything else...
|
||||
{
|
||||
if (!m_gotToStringMethods)
|
||||
{
|
||||
@ -233,17 +255,20 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
else
|
||||
toString = (string)m_toStringMethod.Invoke(Value, new object[0]);
|
||||
|
||||
var fullnametemp = valueType.ToString();
|
||||
if (fullnametemp.StartsWith("Il2CppSystem"))
|
||||
fullnametemp = fullnametemp.Substring(6, fullnametemp.Length - 6);
|
||||
toString = toString ?? "";
|
||||
|
||||
var temp = toString.Replace(fullnametemp, "").Trim();
|
||||
string typeName = valueType.FullName;
|
||||
if (typeName.StartsWith("Il2CppSystem."))
|
||||
typeName = typeName.Substring(6, typeName.Length - 6);
|
||||
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
toString = ReflectionProvider.Instance.ProcessTypeNameInString(valueType, toString, ref typeName);
|
||||
|
||||
// If the ToString is just the type name, use our syntax highlighted type name instead.
|
||||
if (toString == typeName)
|
||||
{
|
||||
label = m_richValueType;
|
||||
}
|
||||
else
|
||||
else // Otherwise, parse the result and put our highlighted name in.
|
||||
{
|
||||
if (toString.Length > 200)
|
||||
toString = toString.Substring(0, 200) + "...";
|
360
src/Core/Inspectors/Reflection/ReflectionInspector.cs
Normal file
360
src/Core/Inspectors/Reflection/ReflectionInspector.cs
Normal file
@ -0,0 +1,360 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core.Inspectors.Reflection;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class ReflectionInspector : InspectorBase
|
||||
{
|
||||
#region STATIC
|
||||
|
||||
public static ReflectionInspector ActiveInstance { get; private set; }
|
||||
|
||||
static ReflectionInspector()
|
||||
{
|
||||
PanelDragger.OnFinishResize += OnContainerResized;
|
||||
SceneExplorer.OnToggleShow += OnContainerResized;
|
||||
}
|
||||
|
||||
private static void OnContainerResized()
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.ReflectionUI.m_widthUpdateWanted = true;
|
||||
}
|
||||
|
||||
// Blacklists
|
||||
private static readonly HashSet<string> bl_typeAndMember = new HashSet<string>
|
||||
{
|
||||
#if CPP
|
||||
// these cause a crash in IL2CPP
|
||||
"Type.DeclaringMethod",
|
||||
"Rigidbody2D.Cast",
|
||||
"Collider2D.Cast",
|
||||
"Collider2D.Raycast",
|
||||
"Texture2D.SetPixelDataImpl",
|
||||
"Camera.CalculateProjectionMatrixFromPhysicalProperties",
|
||||
#endif
|
||||
};
|
||||
private static readonly HashSet<string> bl_memberNameStartsWith = new HashSet<string>
|
||||
{
|
||||
// these are redundant
|
||||
"get_",
|
||||
"set_",
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region INSTANCE
|
||||
|
||||
public override string TabLabel => m_targetTypeShortName;
|
||||
|
||||
internal CacheObjectBase ParentMember { get; set; }
|
||||
|
||||
internal ReflectionInspectorUI ReflectionUI;
|
||||
|
||||
internal readonly Type m_targetType;
|
||||
internal readonly string m_targetTypeShortName;
|
||||
|
||||
// all cached members of the target
|
||||
internal CacheMember[] m_allMembers;
|
||||
// filtered members based on current filters
|
||||
internal readonly List<CacheMember> m_membersFiltered = new List<CacheMember>();
|
||||
// actual shortlist of displayed members
|
||||
internal readonly CacheMember[] m_displayedMembers = new CacheMember[ExplorerConfig.Instance.Default_Page_Limit];
|
||||
|
||||
internal bool m_autoUpdate;
|
||||
|
||||
public ReflectionInspector(object target) : base(target)
|
||||
{
|
||||
if (this is StaticInspector)
|
||||
m_targetType = target as Type;
|
||||
else
|
||||
m_targetType = ReflectionUtility.GetType(target);
|
||||
|
||||
m_targetTypeShortName = SignatureHighlighter.ParseFullSyntax(m_targetType, false);
|
||||
|
||||
ReflectionUI.ConstructUI();
|
||||
|
||||
CacheMembers(m_targetType);
|
||||
|
||||
FilterMembers();
|
||||
}
|
||||
|
||||
public override void CreateUIModule()
|
||||
{
|
||||
BaseUI = ReflectionUI = new ReflectionInspectorUI(this);
|
||||
}
|
||||
|
||||
public override void SetActive()
|
||||
{
|
||||
base.SetActive();
|
||||
ActiveInstance = this;
|
||||
}
|
||||
|
||||
public override void SetInactive()
|
||||
{
|
||||
base.SetInactive();
|
||||
ActiveInstance = null;
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
|
||||
if (this.BaseUI.Content)
|
||||
GameObject.Destroy(this.BaseUI.Content);
|
||||
}
|
||||
|
||||
internal void OnPageTurned()
|
||||
{
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
internal bool IsBlacklisted(string sig) => bl_typeAndMember.Any(it => sig.Contains(it));
|
||||
internal bool IsBlacklisted(MethodInfo method) => bl_memberNameStartsWith.Any(it => method.Name.StartsWith(it));
|
||||
|
||||
internal string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
|
||||
internal string AppendArgsToSig(ParameterInfo[] args)
|
||||
{
|
||||
string ret = " (";
|
||||
foreach (var param in args)
|
||||
ret += $"{param.ParameterType.Name} {param.Name}, ";
|
||||
ret += ")";
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void CacheMembers(Type type)
|
||||
{
|
||||
var list = new List<CacheMember>();
|
||||
var cachedSigs = new HashSet<string>();
|
||||
|
||||
var types = ReflectionUtility.GetAllBaseTypes(type);
|
||||
|
||||
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
||||
if (this is InstanceInspector)
|
||||
flags |= BindingFlags.Instance;
|
||||
|
||||
foreach (var declaringType in types)
|
||||
{
|
||||
var target = Target;
|
||||
target = target.Cast(declaringType);
|
||||
|
||||
IEnumerable<MemberInfo> infos = declaringType.GetMethods(flags);
|
||||
infos = infos.Concat(declaringType.GetProperties(flags));
|
||||
infos = infos.Concat(declaringType.GetFields(flags));
|
||||
|
||||
foreach (var member in infos)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sig = GetSig(member);
|
||||
|
||||
//ExplorerCore.Log($"Trying to cache member {sig}...");
|
||||
//ExplorerCore.Log(member.DeclaringType.FullName + "." + member.Name);
|
||||
|
||||
var mi = member as MethodInfo;
|
||||
var pi = member as PropertyInfo;
|
||||
var fi = member as FieldInfo;
|
||||
|
||||
if (IsBlacklisted(sig) || (mi != null && IsBlacklisted(mi)))
|
||||
continue;
|
||||
|
||||
var args = mi?.GetParameters() ?? pi?.GetIndexParameters();
|
||||
if (args != null)
|
||||
{
|
||||
if (!CacheMember.CanProcessArgs(args))
|
||||
continue;
|
||||
|
||||
sig += AppendArgsToSig(args);
|
||||
}
|
||||
|
||||
if (cachedSigs.Contains(sig))
|
||||
continue;
|
||||
|
||||
cachedSigs.Add(sig);
|
||||
|
||||
if (mi != null)
|
||||
list.Add(new CacheMethod(mi, target, ReflectionUI.m_scrollContent));
|
||||
else if (pi != null)
|
||||
list.Add(new CacheProperty(pi, target, ReflectionUI.m_scrollContent));
|
||||
else
|
||||
list.Add(new CacheField(fi, target, ReflectionUI.m_scrollContent));
|
||||
|
||||
list.Last().ParentInspector = this;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
|
||||
ExplorerCore.Log(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var typeList = types.ToList();
|
||||
|
||||
var sorted = new List<CacheMember>();
|
||||
sorted.AddRange(list.Where(it => it is CacheMethod)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(list.Where(it => it is CacheProperty)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(list.Where(it => it is CacheField)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
|
||||
m_allMembers = sorted.ToArray();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (m_autoUpdate)
|
||||
{
|
||||
foreach (var member in m_displayedMembers)
|
||||
{
|
||||
if (member == null) break;
|
||||
member.UpdateValue();
|
||||
}
|
||||
}
|
||||
|
||||
if (ReflectionUI.m_widthUpdateWanted)
|
||||
{
|
||||
if (!ReflectionUI.m_widthUpdateWaiting)
|
||||
ReflectionUI.m_widthUpdateWaiting = true;
|
||||
else
|
||||
{
|
||||
UpdateWidths();
|
||||
ReflectionUI.m_widthUpdateWaiting = false;
|
||||
ReflectionUI.m_widthUpdateWanted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnMemberFilterClicked(MemberTypes type, Button button)
|
||||
{
|
||||
if (ReflectionUI.m_lastActiveMemButton)
|
||||
{
|
||||
var lastColors = ReflectionUI.m_lastActiveMemButton.colors;
|
||||
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
ReflectionUI.m_lastActiveMemButton.colors = lastColors;
|
||||
}
|
||||
|
||||
ReflectionUI.m_memberFilter = type;
|
||||
ReflectionUI.m_lastActiveMemButton = button;
|
||||
|
||||
var colors = ReflectionUI.m_lastActiveMemButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
ReflectionUI.m_lastActiveMemButton.colors = colors;
|
||||
|
||||
FilterMembers(null, true);
|
||||
ReflectionUI.m_sliderScroller.m_slider.value = 1f;
|
||||
}
|
||||
|
||||
public void FilterMembers(string nameFilter = null, bool force = false)
|
||||
{
|
||||
int lastCount = m_membersFiltered.Count;
|
||||
m_membersFiltered.Clear();
|
||||
|
||||
nameFilter = nameFilter?.ToLower() ?? ReflectionUI.m_nameFilterText.text.ToLower();
|
||||
|
||||
foreach (var mem in m_allMembers)
|
||||
{
|
||||
// membertype filter
|
||||
if (ReflectionUI.m_memberFilter != MemberTypes.All && mem.MemInfo.MemberType != ReflectionUI.m_memberFilter)
|
||||
continue;
|
||||
|
||||
if (this is InstanceInspector ii && ii.m_scopeFilter != MemberScopes.All)
|
||||
{
|
||||
if (mem.IsStatic && ii.m_scopeFilter != MemberScopes.Static)
|
||||
continue;
|
||||
else if (!mem.IsStatic && ii.m_scopeFilter != MemberScopes.Instance)
|
||||
continue;
|
||||
}
|
||||
|
||||
// name filter
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !mem.NameForFiltering.Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
m_membersFiltered.Add(mem);
|
||||
}
|
||||
|
||||
if (force || lastCount != m_membersFiltered.Count)
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public void RefreshDisplay()
|
||||
{
|
||||
var members = m_membersFiltered;
|
||||
ReflectionUI.m_pageHandler.ListCount = members.Count;
|
||||
|
||||
// disable current members
|
||||
for (int i = 0; i < m_displayedMembers.Length; i++)
|
||||
{
|
||||
var mem = m_displayedMembers[i];
|
||||
if (mem != null)
|
||||
mem.Disable();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (members.Count < 1)
|
||||
return;
|
||||
|
||||
foreach (var itemIndex in ReflectionUI.m_pageHandler)
|
||||
{
|
||||
if (itemIndex >= members.Count)
|
||||
break;
|
||||
|
||||
CacheMember member = members[itemIndex];
|
||||
m_displayedMembers[itemIndex - ReflectionUI.m_pageHandler.StartIndex] = member;
|
||||
member.Enable();
|
||||
}
|
||||
|
||||
ReflectionUI.m_widthUpdateWanted = true;
|
||||
}
|
||||
|
||||
internal void UpdateWidths()
|
||||
{
|
||||
float labelWidth = 125;
|
||||
|
||||
foreach (var cache in m_displayedMembers)
|
||||
{
|
||||
if (cache == null)
|
||||
break;
|
||||
|
||||
var width = cache.GetMemberLabelWidth(ReflectionUI.m_scrollContentRect);
|
||||
|
||||
if (width > labelWidth)
|
||||
labelWidth = width;
|
||||
}
|
||||
|
||||
float valueWidth = ReflectionUI.m_scrollContentRect.rect.width - labelWidth - 20;
|
||||
|
||||
foreach (var cache in m_displayedMembers)
|
||||
{
|
||||
if (cache == null)
|
||||
break;
|
||||
cache.SetWidths(labelWidth, valueWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion // end instance
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.Core.Inspectors.Reflection
|
||||
{
|
||||
public class StaticInspector : ReflectionInspector
|
||||
{
|
186
src/Core/ReflectionUtility.cs
Normal file
186
src/Core/ReflectionUtility.cs
Normal file
@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Core
|
||||
{
|
||||
public static class ReflectionUtility
|
||||
{
|
||||
public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
|
||||
|
||||
/// <summary>
|
||||
/// Helper for IL2CPP to get the underlying true Type (Unhollowed) of the object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to get the true Type for.</param>
|
||||
/// <returns>The most accurate Type of the object which could be identified.</returns>
|
||||
public static Type GetType(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
return ReflectionProvider.Instance.GetActualType(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cast an object to its underlying Type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to cast</param>
|
||||
/// <returns>The object, cast to the underlying Type if possible, otherwise the original object.</returns>
|
||||
public static object Cast(this object obj)
|
||||
=> Cast(obj, GetType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Cast an object to a Type, if possible.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to cast</param>
|
||||
/// <param name="castTo">The Type to cast to </param>
|
||||
/// <returns>The object, cast to the Type provided if possible, otherwise the original object.</returns>
|
||||
public static object Cast(this object obj, Type castTo)
|
||||
=> ReflectionProvider.Instance.Cast(obj, castTo);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided Type is assignable to IEnumerable.
|
||||
/// </summary>
|
||||
/// <param name="t">The Type to check</param>
|
||||
/// <returns>True if the Type is assignable to IEnumerable, otherwise false.</returns>
|
||||
public static bool IsEnumerable(this Type t)
|
||||
=> ReflectionProvider.Instance.IsAssignableFrom(typeof(IEnumerable), t);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided Type is assignable to IDictionary.
|
||||
/// </summary>
|
||||
/// <param name="t">The Type to check</param>
|
||||
/// <returns>True if the Type is assignable to IDictionary, otherwise false.</returns>
|
||||
public static bool IsDictionary(this Type t)
|
||||
=> ReflectionProvider.Instance.IsAssignableFrom(typeof(IDictionary), t);
|
||||
|
||||
public static bool LoadModule(string module)
|
||||
=> ReflectionProvider.Instance.LoadModule(module);
|
||||
|
||||
// cache for GetTypeByName
|
||||
internal static readonly Dictionary<string, Type> s_typesByName = new Dictionary<string, Type>();
|
||||
|
||||
/// <summary>
|
||||
/// Find a <see cref="Type"/> in the current AppDomain whose <see cref="Type.FullName"/> matches the provided <paramref name="fullName"/>.
|
||||
/// </summary>
|
||||
/// <param name="fullName">The <see cref="Type.FullName"/> you want to search for - case sensitive and full matches only.</param>
|
||||
/// <returns>The Type if found, otherwise null.</returns>
|
||||
public static Type GetTypeByName(string fullName)
|
||||
{
|
||||
s_typesByName.TryGetValue(fullName, out Type ret);
|
||||
|
||||
if (ret != null)
|
||||
return ret;
|
||||
|
||||
foreach (var type in from asm in AppDomain.CurrentDomain.GetAssemblies()
|
||||
from type in asm.TryGetTypes()
|
||||
select type)
|
||||
{
|
||||
if (type.FullName == fullName)
|
||||
{
|
||||
ret = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_typesByName.ContainsKey(fullName))
|
||||
s_typesByName[fullName] = ret;
|
||||
else
|
||||
s_typesByName.Add(fullName, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// cache for GetBaseTypes
|
||||
internal static readonly Dictionary<string, Type[]> s_cachedTypeInheritance = new Dictionary<string, Type[]>();
|
||||
|
||||
/// <summary>
|
||||
/// Get all base types of the provided Type, including itself.
|
||||
/// </summary>
|
||||
public static Type[] GetAllBaseTypes(this object obj) => GetAllBaseTypes(GetType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Get all base types of the provided Type, including itself.
|
||||
/// </summary>
|
||||
public static Type[] GetAllBaseTypes(this Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException("type");
|
||||
|
||||
var name = type.AssemblyQualifiedName;
|
||||
|
||||
if (s_cachedTypeInheritance.TryGetValue(name, out Type[] ret))
|
||||
return ret;
|
||||
|
||||
List<Type> list = new List<Type>();
|
||||
|
||||
while (type != null)
|
||||
{
|
||||
list.Add(type);
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
ret = list.ToArray();
|
||||
|
||||
s_cachedTypeInheritance.Add(name, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safely get all valid Types inside an Assembly.
|
||||
/// </summary>
|
||||
/// <param name="asm">The Assembly to find Types in.</param>
|
||||
/// <returns>All possible Types which could be retrieved from the Assembly, or an empty array.</returns>
|
||||
public static IEnumerable<Type> TryGetTypes(this Assembly asm)
|
||||
{
|
||||
try
|
||||
{
|
||||
return asm.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
return asm.GetExportedTypes();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return e.Types.Where(t => t != null);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Enumerable.Empty<Type>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper to display a simple "{ExceptionType}: {Message}" of the exception, and optionally use the inner-most exception.
|
||||
/// </summary>
|
||||
/// <param name="e">The Exception to convert to string.</param>
|
||||
/// <param name="innerMost">Should the inner-most Exception of the stack be used? If false, the Exception you provided will be used directly.</param>
|
||||
/// <returns>The exception to string.</returns>
|
||||
public static string ReflectionExToString(this Exception e, bool innerMost = false)
|
||||
{
|
||||
if (innerMost)
|
||||
{
|
||||
while (e.InnerException != null)
|
||||
{
|
||||
#if CPP
|
||||
if (e.InnerException is System.Runtime.CompilerServices.RuntimeWrappedException)
|
||||
break;
|
||||
#endif
|
||||
e = e.InnerException;
|
||||
}
|
||||
}
|
||||
|
||||
return $"{e.GetType()}: {e.Message}";
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ using System.Text;
|
||||
using UnhollowerBaseLib;
|
||||
using UnhollowerRuntimeLib;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Runtime.Il2Cpp;
|
||||
|
||||
namespace UnityExplorer.Unstrip
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public class AssetBundle
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
public static AssetBundle LoadFromFile(string path)
|
||||
{
|
||||
var iCall = ICallHelper.GetICall<d_LoadFromFile>("UnityEngine.AssetBundle::LoadFromFile_Internal");
|
||||
var iCall = ICallManager.GetICall<d_LoadFromFile>("UnityEngine.AssetBundle::LoadFromFile_Internal");
|
||||
|
||||
var ptr = iCall.Invoke(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0UL);
|
||||
|
||||
@ -29,7 +29,7 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0)
|
||||
{
|
||||
var iCall = ICallHelper.GetICall<d_LoadFromMemory>("UnityEngine.AssetBundle::LoadFromMemory_Internal");
|
||||
var iCall = ICallManager.GetICall<d_LoadFromMemory>("UnityEngine.AssetBundle::LoadFromMemory_Internal");
|
||||
|
||||
var ptr = iCall(((Il2CppStructArray<byte>) binary).Pointer, crc);
|
||||
|
||||
@ -48,7 +48,7 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
public UnityEngine.Object[] LoadAllAssets()
|
||||
{
|
||||
var iCall = ICallHelper.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal");
|
||||
var iCall = ICallManager.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal");
|
||||
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), Il2CppType.Of<UnityEngine.Object>().Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
@ -63,7 +63,7 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
public T LoadAsset<T>(string name) where T : UnityEngine.Object
|
||||
{
|
||||
var iCall = ICallHelper.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal");
|
||||
var iCall = ICallManager.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal");
|
||||
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), Il2CppType.Of<T>().Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
43
src/Core/Runtime/Il2Cpp/ICallManager.cs
Normal file
43
src/Core/Runtime/Il2Cpp/ICallManager.cs
Normal file
@ -0,0 +1,43 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
||||
public static class ICallManager
|
||||
{
|
||||
private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();
|
||||
|
||||
/// <summary>
|
||||
/// Helper to get and cache an iCall by providing the signature (eg. "UnityEngine.Resources::FindObjectsOfTypeAll").
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Type of Delegate to provide for the iCall.</typeparam>
|
||||
/// <param name="signature">The signature of the iCall you want to get.</param>
|
||||
/// <returns>The <typeparamref name="T"/> delegate if successful.</returns>
|
||||
/// <exception cref="MissingMethodException">If the iCall could not be found.</exception>
|
||||
public static T GetICall<T>(string signature) where T : Delegate
|
||||
{
|
||||
if (iCallCache.ContainsKey(signature))
|
||||
return (T)iCallCache[signature];
|
||||
|
||||
IntPtr ptr = il2cpp_resolve_icall(signature);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new MissingMethodException($"Could not resolve internal call by name '{signature}'!");
|
||||
}
|
||||
|
||||
Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T));
|
||||
iCallCache.Add(signature, iCall);
|
||||
|
||||
return (T)iCall;
|
||||
}
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr il2cpp_resolve_icall([MarshalAs(UnmanagedType.LPStr)] string name);
|
||||
}
|
||||
}
|
||||
#endif
|
156
src/Core/Runtime/Il2Cpp/Il2CppCoroutine.cs
Normal file
156
src/Core/Runtime/Il2Cpp/Il2CppCoroutine.cs
Normal file
@ -0,0 +1,156 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityEngine;
|
||||
|
||||
// CREDIT HerpDerpenstine
|
||||
// https://github.com/LavaGang/MelonLoader/blob/master/MelonLoader.Support.Il2Cpp/MelonCoroutines.cs
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
public static class Il2CppCoroutine
|
||||
{
|
||||
private struct CoroTuple
|
||||
{
|
||||
public object WaitCondition;
|
||||
public IEnumerator Coroutine;
|
||||
}
|
||||
private static readonly List<CoroTuple> ourCoroutinesStore = new List<CoroTuple>();
|
||||
private static readonly List<IEnumerator> ourNextFrameCoroutines = new List<IEnumerator>();
|
||||
private static readonly List<IEnumerator> ourWaitForFixedUpdateCoroutines = new List<IEnumerator>();
|
||||
private static readonly List<IEnumerator> ourWaitForEndOfFrameCoroutines = new List<IEnumerator>();
|
||||
|
||||
private static readonly List<IEnumerator> tempList = new List<IEnumerator>();
|
||||
|
||||
internal static object Start(IEnumerator routine)
|
||||
{
|
||||
if (routine != null) ProcessNextOfCoroutine(routine);
|
||||
return routine;
|
||||
}
|
||||
|
||||
internal static void Stop(IEnumerator enumerator)
|
||||
{
|
||||
if (ourNextFrameCoroutines.Contains(enumerator)) // the coroutine is running itself
|
||||
ourNextFrameCoroutines.Remove(enumerator);
|
||||
else
|
||||
{
|
||||
int coroTupleIndex = ourCoroutinesStore.FindIndex(c => c.Coroutine == enumerator);
|
||||
if (coroTupleIndex != -1) // the coroutine is waiting for a subroutine
|
||||
{
|
||||
object waitCondition = ourCoroutinesStore[coroTupleIndex].WaitCondition;
|
||||
if (waitCondition is IEnumerator waitEnumerator)
|
||||
Stop(waitEnumerator);
|
||||
|
||||
ourCoroutinesStore.RemoveAt(coroTupleIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessCoroList(List<IEnumerator> target)
|
||||
{
|
||||
if (target.Count == 0) return;
|
||||
|
||||
// use a temp list to make sure waits made during processing are not handled by same processing invocation
|
||||
// additionally, a temp list reduces allocations compared to an array
|
||||
tempList.AddRange(target);
|
||||
target.Clear();
|
||||
foreach (var enumerator in tempList) ProcessNextOfCoroutine(enumerator);
|
||||
tempList.Clear();
|
||||
}
|
||||
|
||||
internal static void Process()
|
||||
{
|
||||
for (var i = ourCoroutinesStore.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var tuple = ourCoroutinesStore[i];
|
||||
if (tuple.WaitCondition is WaitForSeconds waitForSeconds)
|
||||
{
|
||||
if ((waitForSeconds.m_Seconds -= Time.deltaTime) <= 0)
|
||||
{
|
||||
ourCoroutinesStore.RemoveAt(i);
|
||||
ProcessNextOfCoroutine(tuple.Coroutine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProcessCoroList(ourNextFrameCoroutines);
|
||||
}
|
||||
|
||||
internal static void ProcessWaitForFixedUpdate() => ProcessCoroList(ourWaitForFixedUpdateCoroutines);
|
||||
|
||||
internal static void ProcessWaitForEndOfFrame() => ProcessCoroList(ourWaitForEndOfFrameCoroutines);
|
||||
|
||||
private static void ProcessNextOfCoroutine(IEnumerator enumerator)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!enumerator.MoveNext()) // Run the next step of the coroutine. If it's done, restore the parent routine
|
||||
{
|
||||
var indices = ourCoroutinesStore.Select((it, idx) => (idx, it)).Where(it => it.it.WaitCondition == enumerator).Select(it => it.idx).ToList();
|
||||
for (var i = indices.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var index = indices[i];
|
||||
ourNextFrameCoroutines.Add(ourCoroutinesStore[index].Coroutine);
|
||||
ourCoroutinesStore.RemoveAt(index);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogError(e.ToString());
|
||||
Stop(FindOriginalCoro(enumerator)); // We want the entire coroutine hierachy to stop when an error happen
|
||||
}
|
||||
|
||||
var next = enumerator.Current;
|
||||
switch (next)
|
||||
{
|
||||
case null:
|
||||
ourNextFrameCoroutines.Add(enumerator);
|
||||
return;
|
||||
case WaitForFixedUpdate _:
|
||||
ourWaitForFixedUpdateCoroutines.Add(enumerator);
|
||||
return;
|
||||
case WaitForEndOfFrame _:
|
||||
ourWaitForEndOfFrameCoroutines.Add(enumerator);
|
||||
return;
|
||||
case WaitForSeconds _:
|
||||
break; // do nothing, this one is supported in Process
|
||||
case Il2CppObjectBase il2CppObjectBase:
|
||||
var nextAsEnumerator = il2CppObjectBase.TryCast<Il2CppSystem.Collections.IEnumerator>();
|
||||
if (nextAsEnumerator != null) // il2cpp IEnumerator also handles CustomYieldInstruction
|
||||
next = new Il2CppEnumeratorWrapper(nextAsEnumerator);
|
||||
else
|
||||
ExplorerCore.LogWarning($"Unknown coroutine yield object of type {il2CppObjectBase} for coroutine {enumerator}");
|
||||
break;
|
||||
}
|
||||
|
||||
ourCoroutinesStore.Add(new CoroTuple { WaitCondition = next, Coroutine = enumerator });
|
||||
|
||||
if (next is IEnumerator nextCoro)
|
||||
ProcessNextOfCoroutine(nextCoro);
|
||||
}
|
||||
|
||||
private static IEnumerator FindOriginalCoro(IEnumerator enumerator)
|
||||
{
|
||||
int index = ourCoroutinesStore.FindIndex(ct => ct.WaitCondition == enumerator);
|
||||
if (index == -1)
|
||||
return enumerator;
|
||||
return FindOriginalCoro(ourCoroutinesStore[index].Coroutine);
|
||||
}
|
||||
|
||||
private class Il2CppEnumeratorWrapper : IEnumerator
|
||||
{
|
||||
private readonly Il2CppSystem.Collections.IEnumerator il2cppEnumerator;
|
||||
|
||||
public Il2CppEnumeratorWrapper(Il2CppSystem.Collections.IEnumerator il2CppEnumerator) => il2cppEnumerator = il2CppEnumerator;
|
||||
public bool MoveNext() => il2cppEnumerator.MoveNext();
|
||||
public void Reset() => il2cppEnumerator.Reset();
|
||||
public object Current => il2cppEnumerator.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
123
src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
Normal file
123
src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
Normal file
@ -0,0 +1,123 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
using System.Text;
|
||||
using UnhollowerBaseLib;
|
||||
using UnhollowerRuntimeLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
public class Il2CppProvider : RuntimeProvider
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
Reflection = new Il2CppReflection();
|
||||
TextureUtil = new Il2CppTextureUtil();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Application.add_logMessageReceived(new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog));
|
||||
|
||||
var logType = ReflectionUtility.GetTypeByName("UnityEngine.Application+LogCallback");
|
||||
var castMethod = logType.GetMethod("op_Implicit", new[] { typeof(Action<string, string, LogType>) });
|
||||
var addMethod = typeof(Application).GetMethod("add_logMessageReceived", BF.Static | BF.Public, null, new[] { logType }, null);
|
||||
addMethod.Invoke(null, new[]
|
||||
{
|
||||
castMethod.Invoke(null, new[] { new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog) })
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
ExplorerCore.LogWarning("Exception setting up Unity log listener, make sure Unity libraries have been unstripped!");
|
||||
}
|
||||
}
|
||||
|
||||
public override void StartConsoleCoroutine(IEnumerator routine)
|
||||
{
|
||||
Il2CppCoroutine.Start(routine);
|
||||
}
|
||||
|
||||
internal delegate IntPtr d_LayerToName(int layer);
|
||||
|
||||
public override string LayerToName(int layer)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_LayerToName>("UnityEngine.LayerMask::LayerToName");
|
||||
return IL2CPP.Il2CppStringToManaged(iCall.Invoke(layer));
|
||||
}
|
||||
|
||||
internal delegate IntPtr d_FindObjectsOfTypeAll(IntPtr type);
|
||||
|
||||
public override UnityEngine.Object[] FindObjectsOfTypeAll(Type type)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_FindObjectsOfTypeAll>("UnityEngine.Resources::FindObjectsOfTypeAll");
|
||||
var cppType = Il2CppType.From(type);
|
||||
|
||||
return new Il2CppReferenceArray<UnityEngine.Object>(iCall.Invoke(cppType.Pointer));
|
||||
}
|
||||
|
||||
public override int GetSceneHandle(Scene scene)
|
||||
=> scene.handle;
|
||||
|
||||
//Scene.GetRootGameObjects();
|
||||
|
||||
internal delegate void d_GetRootGameObjects(int handle, IntPtr list);
|
||||
|
||||
public override GameObject[] GetRootGameObjects(Scene scene) => GetRootGameObjects(scene.handle);
|
||||
|
||||
public static GameObject[] GetRootGameObjects(int handle)
|
||||
{
|
||||
if (handle == -1)
|
||||
return new GameObject[0];
|
||||
|
||||
int count = GetRootCount(handle);
|
||||
|
||||
if (count < 1)
|
||||
return new GameObject[0];
|
||||
|
||||
var list = new Il2CppSystem.Collections.Generic.List<GameObject>(count);
|
||||
|
||||
var iCall = ICallManager.GetICall<d_GetRootGameObjects>("UnityEngine.SceneManagement.Scene::GetRootGameObjectsInternal");
|
||||
|
||||
iCall.Invoke(handle, list.Pointer);
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
//Scene.rootCount;
|
||||
|
||||
internal delegate int d_GetRootCountInternal(int handle);
|
||||
|
||||
public override int GetRootCount(Scene scene) => GetRootCount(scene.handle);
|
||||
|
||||
public static int GetRootCount(int handle)
|
||||
{
|
||||
return ICallManager.GetICall<d_GetRootCountInternal>("UnityEngine.SceneManagement.Scene::GetRootCountInternal")
|
||||
.Invoke(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnityEventExtensions
|
||||
{
|
||||
public static void AddListener(this UnityEvent action, Action listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
362
src/Core/Runtime/Il2Cpp/Il2CppReflection.cs
Normal file
362
src/Core/Runtime/Il2Cpp/Il2CppReflection.cs
Normal file
@ -0,0 +1,362 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnhollowerRuntimeLib;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using UnityExplorer.Core;
|
||||
using CppType = Il2CppSystem.Type;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
||||
public class Il2CppReflection : ReflectionProvider
|
||||
{
|
||||
public Il2CppReflection() : base()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
TryLoadGameModules();
|
||||
}
|
||||
|
||||
public override object Cast(object obj, Type castTo)
|
||||
{
|
||||
return Il2CppCast(obj, castTo);
|
||||
}
|
||||
|
||||
public override string ProcessTypeNameInString(Type type, string theString, ref string typeName)
|
||||
{
|
||||
if (!Il2CppTypeNotNull(type))
|
||||
return theString;
|
||||
|
||||
var cppType = Il2CppType.From(type);
|
||||
if (cppType != null && s_deobfuscatedTypeNames.ContainsKey(cppType.FullName))
|
||||
{
|
||||
typeName = s_deobfuscatedTypeNames[cppType.FullName];
|
||||
theString = theString.Replace(cppType.FullName, typeName);
|
||||
}
|
||||
|
||||
return theString;
|
||||
}
|
||||
|
||||
public override Type GetActualType(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
var type = obj.GetType();
|
||||
|
||||
if (obj is Il2CppSystem.Object cppObject)
|
||||
{
|
||||
// weird specific case - if the object is an Il2CppSystem.Type, then return so manually.
|
||||
if (cppObject is CppType)
|
||||
return typeof(CppType);
|
||||
|
||||
if (!string.IsNullOrEmpty(type.Namespace))
|
||||
{
|
||||
// Il2CppSystem-namespace objects should just return GetType,
|
||||
// because using GetIl2CppType returns the System namespace type instead.
|
||||
if (type.Namespace.StartsWith("System.") || type.Namespace.StartsWith("Il2CppSystem."))
|
||||
return cppObject.GetType();
|
||||
}
|
||||
|
||||
var cppType = cppObject.GetIl2CppType();
|
||||
|
||||
// check if type is injected
|
||||
IntPtr classPtr = il2cpp_object_get_class(cppObject.Pointer);
|
||||
if (RuntimeSpecificsStore.IsInjected(classPtr))
|
||||
{
|
||||
var typeByName = ReflectionUtility.GetTypeByName(cppType.FullName);
|
||||
if (typeByName != null)
|
||||
return typeByName;
|
||||
}
|
||||
|
||||
// this should be fine for all other il2cpp objects
|
||||
var getType = GetMonoType(cppType);
|
||||
if (getType != null)
|
||||
return getType;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
// caching for GetMonoType
|
||||
private static readonly Dictionary<string, Type> Il2CppToMonoType = new Dictionary<string, Type>();
|
||||
|
||||
// keep deobfuscated type name cache, used to display proper name.
|
||||
internal static Dictionary<string, string> s_deobfuscatedTypeNames = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Try to get the Mono (Unhollowed) Type representation of the provided <see cref="Il2CppSystem.Type"/>.
|
||||
/// </summary>
|
||||
/// <param name="cppType">The Cpp Type you want to convert to Mono.</param>
|
||||
/// <returns>The Mono Type if found, otherwise null.</returns>
|
||||
public static Type GetMonoType(CppType cppType)
|
||||
{
|
||||
string name = cppType.AssemblyQualifiedName;
|
||||
|
||||
if (Il2CppToMonoType.ContainsKey(name))
|
||||
return Il2CppToMonoType[name];
|
||||
|
||||
Type ret = Type.GetType(name);
|
||||
|
||||
if (ret == null)
|
||||
{
|
||||
string baseName = cppType.FullName;
|
||||
string baseAssembly = cppType.Assembly.GetName().name;
|
||||
|
||||
ret = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.FirstOrDefault(a
|
||||
=> a.GetName().Name == baseAssembly)?
|
||||
.TryGetTypes()
|
||||
.FirstOrDefault(t
|
||||
=> t.CustomAttributes.Any(ca
|
||||
=> ca.AttributeType.Name == "ObfuscatedNameAttribute"
|
||||
&& (string)ca.ConstructorArguments[0].Value == baseName));
|
||||
|
||||
if (ret != null)
|
||||
{
|
||||
// deobfuscated type was found, add to cache.
|
||||
s_deobfuscatedTypeNames.Add(cppType.FullName, ret.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
Il2CppToMonoType.Add(name, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// cached class pointers for Il2CppCast
|
||||
private static readonly Dictionary<string, IntPtr> s_cppClassPointers = new Dictionary<string, IntPtr>();
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to cast the object to its underlying type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object you want to cast.</param>
|
||||
/// <returns>The object, as the underlying type if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(object obj) => Il2CppCast(obj, Instance.GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to cast the object to the provided type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object you want to cast.</param>
|
||||
/// <param name="castTo">The Type you want to cast to.</param>
|
||||
/// <returns>The object, as the type (or a normal C# object) if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(object obj, Type castTo)
|
||||
{
|
||||
if (!(obj is Il2CppSystem.Object ilObj))
|
||||
return obj;
|
||||
|
||||
if (!Il2CppTypeNotNull(castTo, out IntPtr castToPtr))
|
||||
return obj;
|
||||
|
||||
IntPtr castFromPtr = il2cpp_object_get_class(ilObj.Pointer);
|
||||
|
||||
if (!il2cpp_class_is_assignable_from(castToPtr, castFromPtr))
|
||||
return obj;
|
||||
|
||||
if (RuntimeSpecificsStore.IsInjected(castToPtr))
|
||||
return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(ilObj.Pointer);
|
||||
|
||||
return Activator.CreateInstance(castTo, ilObj.Pointer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Il2Cpp Class Pointer for the provided Mono (Unhollowed) Type.
|
||||
/// </summary>
|
||||
/// <param name="type">The Mono/Unhollowed Type you want the Il2Cpp Class Pointer for.</param>
|
||||
/// <returns>True if successful, false if not.</returns>
|
||||
public static bool Il2CppTypeNotNull(Type type) => Il2CppTypeNotNull(type, out _);
|
||||
|
||||
/// <summary>
|
||||
/// Get the Il2Cpp Class Pointer for the provided Mono (Unhollowed) Type.
|
||||
/// </summary>
|
||||
/// <param name="type">The Mono/Unhollowed Type you want the Il2Cpp Class Pointer for.</param>
|
||||
/// <param name="il2cppPtr">The IntPtr for the Il2Cpp class, or IntPtr.Zero if not found.</param>
|
||||
/// <returns>True if successful, false if not.</returns>
|
||||
public static bool Il2CppTypeNotNull(Type type, out IntPtr il2cppPtr)
|
||||
{
|
||||
if (s_cppClassPointers.TryGetValue(type.AssemblyQualifiedName, out il2cppPtr))
|
||||
return il2cppPtr != IntPtr.Zero;
|
||||
|
||||
il2cppPtr = (IntPtr)typeof(Il2CppClassPointerStore<>)
|
||||
.MakeGenericType(new Type[] { type })
|
||||
.GetField("NativeClassPtr", BF.Public | BF.Static)
|
||||
.GetValue(null);
|
||||
|
||||
s_cppClassPointers.Add(type.AssemblyQualifiedName, il2cppPtr);
|
||||
|
||||
return il2cppPtr != IntPtr.Zero;
|
||||
}
|
||||
|
||||
// Extern C++ methods
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern bool il2cpp_class_is_assignable_from(IntPtr klass, IntPtr oklass);
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr il2cpp_object_get_class(IntPtr obj);
|
||||
|
||||
internal static IntPtr s_cppEnumerableClassPtr;
|
||||
internal static IntPtr s_cppDictionaryClassPtr;
|
||||
|
||||
public override bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom)
|
||||
{
|
||||
if (toAssignTo.IsAssignableFrom(toAssignFrom))
|
||||
return true;
|
||||
|
||||
if (toAssignTo == typeof(IEnumerable))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (s_cppEnumerableClassPtr == IntPtr.Zero)
|
||||
Il2CppTypeNotNull(typeof(Il2CppSystem.Collections.IEnumerable), out s_cppEnumerableClassPtr);
|
||||
|
||||
if (s_cppEnumerableClassPtr != IntPtr.Zero
|
||||
&& Il2CppTypeNotNull(toAssignFrom, out IntPtr assignFromPtr)
|
||||
&& il2cpp_class_is_assignable_from(s_cppEnumerableClassPtr, assignFromPtr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else if (toAssignTo == typeof(IDictionary))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (s_cppDictionaryClassPtr == IntPtr.Zero)
|
||||
if (!Il2CppTypeNotNull(typeof(Il2CppSystem.Collections.IDictionary), out s_cppDictionaryClassPtr))
|
||||
return false;
|
||||
|
||||
if (Il2CppTypeNotNull(toAssignFrom, out IntPtr classPtr))
|
||||
{
|
||||
if (il2cpp_class_is_assignable_from(s_cppDictionaryClassPtr, classPtr))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsReflectionSupported(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gArgs = type.GetGenericArguments();
|
||||
if (!gArgs.Any())
|
||||
return true;
|
||||
|
||||
foreach (var gType in gArgs)
|
||||
{
|
||||
if (!Supported(gType))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
bool Supported(Type t)
|
||||
{
|
||||
if (!typeof(Il2CppSystem.Object).IsAssignableFrom(t))
|
||||
return true;
|
||||
|
||||
if (!Il2CppTypeNotNull(t, out IntPtr ptr))
|
||||
return false;
|
||||
|
||||
return CppType.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is CppType;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper for IL2CPP to try to make sure the Unhollowed game assemblies are actually loaded.
|
||||
|
||||
internal static void TryLoadGameModules()
|
||||
{
|
||||
Instance.LoadModule("Assembly-CSharp");
|
||||
Instance.LoadModule("Assembly-CSharp-firstpass");
|
||||
}
|
||||
|
||||
public override bool LoadModule(string module)
|
||||
{
|
||||
#if ML
|
||||
var path = Path.Combine("MelonLoader", "Managed", $"{module}.dll");
|
||||
#else
|
||||
var path = Path.Combine("BepInEx", "unhollowed", $"{module}.dll");
|
||||
#endif
|
||||
return LoadModuleInternal(path);
|
||||
}
|
||||
|
||||
internal static bool LoadModuleInternal(string fullPath)
|
||||
{
|
||||
if (!File.Exists(fullPath))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Assembly.Load(File.ReadAllBytes(fullPath));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.GetType() + ", " + e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~ not used ~~~~~~~~~~~~
|
||||
|
||||
// cached il2cpp unbox methods
|
||||
internal static readonly Dictionary<string, MethodInfo> s_unboxMethods = new Dictionary<string, MethodInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to unbox the object to the underlying struct type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object which is a struct underneath.</param>
|
||||
/// <returns>The struct if successful, otherwise null.</returns>
|
||||
public static object Unbox(object obj) => Unbox(obj, Instance.GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to unbox the object to the struct type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object which is a struct underneath.</param>
|
||||
/// <param name="type">The type of the struct you want to unbox to.</param>
|
||||
/// <returns>The struct if successful, otherwise null.</returns>
|
||||
public static object Unbox(object obj, Type type)
|
||||
{
|
||||
if (!type.IsValueType)
|
||||
return null;
|
||||
|
||||
if (!(obj is Il2CppSystem.Object))
|
||||
return obj;
|
||||
|
||||
var name = type.AssemblyQualifiedName;
|
||||
|
||||
if (!s_unboxMethods.ContainsKey(name))
|
||||
{
|
||||
s_unboxMethods.Add(name, typeof(Il2CppObjectBase)
|
||||
.GetMethod("Unbox")
|
||||
.MakeGenericMethod(type));
|
||||
}
|
||||
|
||||
return s_unboxMethods[name].Invoke(obj, new object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
77
src/Core/Runtime/Il2Cpp/Il2CppTextureUtil.cs
Normal file
77
src/Core/Runtime/Il2Cpp/Il2CppTextureUtil.cs
Normal file
@ -0,0 +1,77 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnhollowerBaseLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
{
|
||||
public class Il2CppTextureUtil : TextureUtilProvider
|
||||
{
|
||||
public override Texture2D NewTexture2D(int width, int height)
|
||||
=> new Texture2D((int)width, (int)height, TextureFormat.RGBA32, Texture.GenerateAllMips, false, IntPtr.Zero);
|
||||
|
||||
internal delegate void d_Blit2(IntPtr source, IntPtr dest);
|
||||
|
||||
public override void Blit(Texture2D tex, RenderTexture rt)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_Blit2>("UnityEngine.Graphics::Blit2");
|
||||
iCall.Invoke(tex.Pointer, rt.Pointer);
|
||||
}
|
||||
|
||||
// byte[] ImageConversion.EncodeToPNG(this Texture2D image);
|
||||
|
||||
internal delegate IntPtr d_EncodeToPNG(IntPtr tex);
|
||||
|
||||
public override byte[] EncodeToPNG(Texture2D tex)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_EncodeToPNG>("UnityEngine.ImageConversion::EncodeToPNG");
|
||||
|
||||
IntPtr ptr = iCall.Invoke(tex.Pointer);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new Il2CppStructArray<byte>(ptr);
|
||||
}
|
||||
|
||||
// bool ImageConversion.LoadImage(this Texture2D tex, byte[] data, bool markNonReadable);
|
||||
|
||||
internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
|
||||
|
||||
public override bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
|
||||
{
|
||||
var il2cppArray = (Il2CppStructArray<byte>)data;
|
||||
|
||||
var iCall = ICallManager.GetICall<d_LoadImage>("UnityEngine.ImageConversion::LoadImage");
|
||||
|
||||
return iCall.Invoke(tex.Pointer, il2cppArray.Pointer, markNonReadable);
|
||||
}
|
||||
|
||||
// Sprite Sprite.Create
|
||||
|
||||
public override Sprite CreateSprite(Texture2D texture)
|
||||
{
|
||||
return CreateSpriteImpl(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 100f, 0u, Vector4.zero);
|
||||
}
|
||||
|
||||
internal delegate IntPtr d_CreateSprite(IntPtr texture, ref Rect rect, ref Vector2 pivot, float pixelsPerUnit,
|
||||
uint extrude, int meshType, ref Vector4 border, bool generateFallbackPhysicsShape);
|
||||
|
||||
public static Sprite CreateSpriteImpl(Texture texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, Vector4 border)
|
||||
{
|
||||
var iCall = ICallManager.GetICall<d_CreateSprite>("UnityEngine.Sprite::CreateSprite_Injected");
|
||||
|
||||
var ptr = iCall.Invoke(texture.Pointer, ref rect, ref pivot, pixelsPerUnit, extrude, 1, ref border, false);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return null;
|
||||
else
|
||||
return new Sprite(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
68
src/Core/Runtime/Mono/MonoProvider.cs
Normal file
68
src/Core/Runtime/Mono/MonoProvider.cs
Normal file
@ -0,0 +1,68 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.CSharp;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class MonoProvider : RuntimeProvider
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
Reflection = new MonoReflection();
|
||||
TextureUtil = new MonoTextureUtil();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
{
|
||||
Application.logMessageReceived += ExplorerCore.Instance.OnUnityLog;
|
||||
//SceneManager.sceneLoaded += ExplorerCore.Instance.OnSceneLoaded1;
|
||||
//SceneManager.activeSceneChanged += ExplorerCore.Instance.OnSceneLoaded2;
|
||||
}
|
||||
|
||||
public override void StartConsoleCoroutine(IEnumerator routine)
|
||||
{
|
||||
DummyBehaviour.Instance.StartCoroutine(routine);
|
||||
}
|
||||
|
||||
public override string LayerToName(int layer)
|
||||
=> LayerMask.LayerToName(layer);
|
||||
|
||||
public override UnityEngine.Object[] FindObjectsOfTypeAll(Type type)
|
||||
=> Resources.FindObjectsOfTypeAll(type);
|
||||
|
||||
private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionUtility.CommonFlags);
|
||||
|
||||
public override int GetSceneHandle(Scene scene)
|
||||
{
|
||||
return (int)fi_Scene_handle.GetValue(scene);
|
||||
}
|
||||
|
||||
public override GameObject[] GetRootGameObjects(Scene scene)
|
||||
{
|
||||
return scene.GetRootGameObjects();
|
||||
}
|
||||
|
||||
public override int GetRootCount(Scene scene)
|
||||
{
|
||||
return scene.rootCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MonoExtensions
|
||||
{
|
||||
public static void Clear(this StringBuilder sb)
|
||||
{
|
||||
sb.Remove(0, sb.Length);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
33
src/Core/Runtime/Mono/MonoReflection.cs
Normal file
33
src/Core/Runtime/Mono/MonoReflection.cs
Normal file
@ -0,0 +1,33 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class MonoReflection : ReflectionProvider
|
||||
{
|
||||
// Mono doesn't need to explicitly cast things.
|
||||
public override object Cast(object obj, Type castTo)
|
||||
=> obj;
|
||||
|
||||
// Vanilla GetType is fine for mono
|
||||
public override Type GetActualType(object obj)
|
||||
=> obj.GetType();
|
||||
|
||||
public override bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom)
|
||||
=> toAssignTo.IsAssignableFrom(toAssignFrom);
|
||||
|
||||
public override bool IsReflectionSupported(Type type)
|
||||
=> true;
|
||||
|
||||
public override bool LoadModule(string module)
|
||||
=> true;
|
||||
|
||||
public override string ProcessTypeNameInString(Type type, string theString, ref string typeName)
|
||||
=> theString;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
66
src/Core/Runtime/Mono/MonoTextureUtil.cs
Normal file
66
src/Core/Runtime/Mono/MonoTextureUtil.cs
Normal file
@ -0,0 +1,66 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class MonoTextureUtil : TextureUtilProvider
|
||||
{
|
||||
public override void Blit(Texture2D tex, RenderTexture rt)
|
||||
{
|
||||
Graphics.Blit(tex, rt);
|
||||
}
|
||||
|
||||
public override Sprite CreateSprite(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
||||
}
|
||||
|
||||
public override bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
|
||||
{
|
||||
return tex.LoadImage(data, markNonReadable);
|
||||
}
|
||||
|
||||
public override Texture2D NewTexture2D(int width, int height)
|
||||
{
|
||||
return new Texture2D(width, height);
|
||||
}
|
||||
|
||||
public override byte[] EncodeToPNG(Texture2D tex)
|
||||
{
|
||||
return EncodeToPNGSafe(tex);
|
||||
}
|
||||
|
||||
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod();
|
||||
private static MethodInfo m_encodeToPNGMethod;
|
||||
|
||||
public static byte[] EncodeToPNGSafe(Texture2D tex)
|
||||
{
|
||||
var method = EncodeToPNGMethod;
|
||||
|
||||
if (method.IsStatic)
|
||||
return (byte[])method.Invoke(null, new object[] { tex });
|
||||
else
|
||||
return (byte[])method.Invoke(tex, new object[0]);
|
||||
}
|
||||
|
||||
private static MethodInfo GetEncodeToPNGMethod()
|
||||
{
|
||||
if (ReflectionUtility.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion)
|
||||
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.CommonFlags);
|
||||
|
||||
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.CommonFlags);
|
||||
if (method != null)
|
||||
return m_encodeToPNGMethod = method;
|
||||
|
||||
ExplorerCore.Log("ERROR: Cannot get any EncodeToPNG method!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
29
src/Core/Runtime/ReflectionProvider.cs
Normal file
29
src/Core/Runtime/ReflectionProvider.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
{
|
||||
public abstract class ReflectionProvider
|
||||
{
|
||||
public static ReflectionProvider Instance;
|
||||
|
||||
public ReflectionProvider()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public abstract Type GetActualType(object obj);
|
||||
|
||||
public abstract object Cast(object obj, Type castTo);
|
||||
|
||||
public abstract bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom);
|
||||
|
||||
public abstract bool IsReflectionSupported(Type type);
|
||||
|
||||
public abstract string ProcessTypeNameInString(Type type, string theString, ref string typeName);
|
||||
|
||||
public abstract bool LoadModule(string module);
|
||||
}
|
||||
}
|
54
src/Core/Runtime/RuntimeProvider.cs
Normal file
54
src/Core/Runtime/RuntimeProvider.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
{
|
||||
// Work in progress, this will be used to replace all the "if CPP / if MONO"
|
||||
// pre-processor directives all over the codebase.
|
||||
|
||||
public abstract class RuntimeProvider
|
||||
{
|
||||
public static RuntimeProvider Instance;
|
||||
|
||||
public ReflectionProvider Reflection;
|
||||
public TextureUtilProvider TextureUtil;
|
||||
|
||||
public RuntimeProvider()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
SetupEvents();
|
||||
}
|
||||
|
||||
public static void Init() =>
|
||||
#if CPP
|
||||
Instance = new Il2Cpp.Il2CppProvider();
|
||||
#else
|
||||
Instance = new Mono.MonoProvider();
|
||||
#endif
|
||||
|
||||
|
||||
public abstract void Initialize();
|
||||
|
||||
public abstract void SetupEvents();
|
||||
|
||||
public abstract void StartConsoleCoroutine(IEnumerator routine);
|
||||
|
||||
// Unity API handlers
|
||||
|
||||
public abstract string LayerToName(int layer);
|
||||
|
||||
public abstract UnityEngine.Object[] FindObjectsOfTypeAll(Type type);
|
||||
|
||||
public abstract int GetSceneHandle(Scene scene);
|
||||
|
||||
public abstract GameObject[] GetRootGameObjects(Scene scene);
|
||||
|
||||
public abstract int GetRootCount(Scene scene);
|
||||
}
|
||||
}
|
@ -1,50 +1,32 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
#if CPP
|
||||
using UnityExplorer.Unstrip;
|
||||
#endif
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
{
|
||||
public static class Texture2DHelpers
|
||||
public abstract class TextureUtilProvider
|
||||
{
|
||||
#if MONO
|
||||
private static bool isNewEncodeMethod = false;
|
||||
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod();
|
||||
private static MethodInfo m_encodeToPNGMethod;
|
||||
public static TextureUtilProvider Instance;
|
||||
|
||||
public static byte[] EncodeToPNGSafe(this Texture2D tex)
|
||||
public TextureUtilProvider()
|
||||
{
|
||||
var method = EncodeToPNGMethod;
|
||||
|
||||
if (method.IsStatic)
|
||||
return (byte[])method.Invoke(null, new object[] { tex });
|
||||
else
|
||||
return (byte[])method.Invoke(tex, new object[0]);
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private static MethodInfo GetEncodeToPNGMethod()
|
||||
{
|
||||
if (ReflectionHelpers.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion)
|
||||
{
|
||||
isNewEncodeMethod = true;
|
||||
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionHelpers.CommonFlags);
|
||||
}
|
||||
public abstract byte[] EncodeToPNG(Texture2D tex);
|
||||
|
||||
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionHelpers.CommonFlags);
|
||||
if (method != null)
|
||||
{
|
||||
return m_encodeToPNGMethod = method;
|
||||
}
|
||||
public abstract Texture2D NewTexture2D(int width, int height);
|
||||
|
||||
ExplorerCore.Log("ERROR: Cannot get any EncodeToPNG method!");
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
public abstract void Blit(Texture2D tex, RenderTexture rt);
|
||||
|
||||
public static bool IsReadable(this Texture2D tex)
|
||||
public abstract bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable);
|
||||
|
||||
public abstract Sprite CreateSprite(Texture2D texture);
|
||||
|
||||
public static bool IsReadable(Texture2D tex)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -61,30 +43,30 @@ namespace UnityExplorer.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public static bool LoadImage(Texture2D tex, string filePath, bool markNonReadable)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
return Instance.LoadImage(tex, File.ReadAllBytes(filePath), markNonReadable);
|
||||
}
|
||||
|
||||
public static Texture2D Copy(Texture2D orig, Rect rect)
|
||||
{
|
||||
Color[] pixels;
|
||||
|
||||
if (!orig.IsReadable())
|
||||
if (!IsReadable(orig))
|
||||
orig = ForceReadTexture(orig);
|
||||
|
||||
pixels = orig.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
|
||||
|
||||
// use full constructor for better compatibility
|
||||
#if CPP
|
||||
var _newTex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGBA32, Texture.GenerateAllMips, false, IntPtr.Zero);
|
||||
#else
|
||||
var _newTex = new Texture2D((int)rect.width, (int)rect.height);
|
||||
#endif
|
||||
_newTex.SetPixels(pixels);
|
||||
Texture2D newTex = Instance.NewTexture2D((int)rect.width, (int)rect.height);
|
||||
|
||||
return _newTex;
|
||||
newTex.SetPixels(pixels);
|
||||
|
||||
return newTex;
|
||||
}
|
||||
|
||||
#if CPP
|
||||
internal delegate void d_Blit2(IntPtr source, IntPtr dest);
|
||||
#endif
|
||||
|
||||
public static Texture2D ForceReadTexture(Texture2D tex)
|
||||
{
|
||||
try
|
||||
@ -96,12 +78,7 @@ namespace UnityExplorer.Helpers
|
||||
rt.filterMode = FilterMode.Point;
|
||||
RenderTexture.active = rt;
|
||||
|
||||
#if MONO
|
||||
Graphics.Blit(tex, rt);
|
||||
#else
|
||||
var iCall = ICallHelper.GetICall<d_Blit2>("UnityEngine.Graphics::Blit2");
|
||||
iCall.Invoke(tex.Pointer, rt.Pointer);
|
||||
#endif
|
||||
Instance.Blit(tex, rt);
|
||||
|
||||
var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
|
||||
|
||||
@ -129,7 +106,7 @@ namespace UnityExplorer.Helpers
|
||||
string savepath = dir + @"\" + name + ".png";
|
||||
|
||||
// Make sure we can EncodeToPNG it.
|
||||
if (tex.format != TextureFormat.ARGB32 || !tex.IsReadable())
|
||||
if (tex.format != TextureFormat.ARGB32 || !IsReadable(tex))
|
||||
{
|
||||
tex = ForceReadTexture(tex);
|
||||
}
|
||||
@ -140,20 +117,9 @@ namespace UnityExplorer.Helpers
|
||||
tex.Apply(false, false);
|
||||
}
|
||||
|
||||
#if CPP
|
||||
data = tex.EncodeToPNG();
|
||||
#else
|
||||
if (isNewEncodeMethod)
|
||||
{
|
||||
data = (byte[])EncodeToPNGMethod.Invoke(null, new object[] { tex });
|
||||
}
|
||||
else
|
||||
{
|
||||
data = (byte[])EncodeToPNGMethod.Invoke(tex, new object[0]);
|
||||
}
|
||||
#endif
|
||||
data = Instance.EncodeToPNG(tex);
|
||||
|
||||
if (data == null || data.Length < 1)
|
||||
if (data == null || !data.Any())
|
||||
{
|
||||
ExplorerCore.LogWarning("Couldn't get any data for the texture!");
|
||||
}
|
204
src/Core/SceneExplorer.cs
Normal file
204
src/Core/SceneExplorer.cs
Normal file
@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
|
||||
namespace UnityExplorer.Core.Inspectors
|
||||
{
|
||||
public class SceneExplorer
|
||||
{
|
||||
public static SceneExplorer Instance;
|
||||
|
||||
public static SceneExplorerUI UI;
|
||||
|
||||
internal static Action OnToggleShow;
|
||||
|
||||
public SceneExplorer()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
UI = new SceneExplorerUI();
|
||||
UI.ConstructScenePane();
|
||||
}
|
||||
|
||||
private const float UPDATE_INTERVAL = 1f;
|
||||
private float m_timeOfLastSceneUpdate;
|
||||
|
||||
// private int m_currentSceneHandle = -1;
|
||||
public static Scene DontDestroyScene => DontDestroyObject.scene;
|
||||
internal Scene m_currentScene;
|
||||
internal Scene[] m_currentScenes = new Scene[0];
|
||||
|
||||
internal GameObject[] m_allObjects = new GameObject[0];
|
||||
|
||||
internal GameObject m_selectedSceneObject;
|
||||
internal int m_lastCount;
|
||||
|
||||
internal static GameObject DontDestroyObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!s_dontDestroyObject)
|
||||
{
|
||||
s_dontDestroyObject = new GameObject("DontDestroyMe");
|
||||
GameObject.DontDestroyOnLoad(s_dontDestroyObject);
|
||||
}
|
||||
return s_dontDestroyObject;
|
||||
}
|
||||
}
|
||||
internal static GameObject s_dontDestroyObject;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
RefreshSceneSelector();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (SceneExplorerUI.Hiding || Time.realtimeSinceStartup - m_timeOfLastSceneUpdate < UPDATE_INTERVAL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshSceneSelector();
|
||||
|
||||
if (!m_selectedSceneObject)
|
||||
{
|
||||
if (m_currentScene != default)
|
||||
{
|
||||
var rootObjects = RuntimeProvider.Instance.GetRootGameObjects(m_currentScene);
|
||||
SetSceneObjectList(rootObjects);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshSelectedSceneObject();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshSceneSelector()
|
||||
{
|
||||
var newNames = new List<string>();
|
||||
var newScenes = new List<Scene>();
|
||||
|
||||
if (m_currentScenes == null)
|
||||
m_currentScenes = new Scene[0];
|
||||
|
||||
bool anyChange = SceneManager.sceneCount != m_currentScenes.Length - 1;
|
||||
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
Scene scene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (scene == default)
|
||||
continue;
|
||||
|
||||
int handle = RuntimeProvider.Instance.GetSceneHandle(scene);
|
||||
|
||||
if (!anyChange && !m_currentScenes.Any(it => handle == RuntimeProvider.Instance.GetSceneHandle(it)))
|
||||
anyChange = true;
|
||||
|
||||
newScenes.Add(scene);
|
||||
newNames.Add(scene.name);
|
||||
}
|
||||
|
||||
if (anyChange)
|
||||
{
|
||||
newNames.Add("DontDestroyOnLoad");
|
||||
newScenes.Add(DontDestroyScene);
|
||||
m_currentScenes = newScenes.ToArray();
|
||||
|
||||
UI.OnActiveScenesChanged(newNames);
|
||||
|
||||
SetTargetScene(newScenes[0]);
|
||||
|
||||
SearchPage.Instance.OnSceneChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTargetScene(int index)
|
||||
=> SetTargetScene(m_currentScenes[index]);
|
||||
|
||||
public void SetTargetScene(Scene scene)
|
||||
{
|
||||
if (scene == default)
|
||||
return;
|
||||
|
||||
m_currentScene = scene;
|
||||
var rootObjs = RuntimeProvider.Instance.GetRootGameObjects(scene);
|
||||
SetSceneObjectList(rootObjs);
|
||||
|
||||
m_selectedSceneObject = null;
|
||||
|
||||
UI.OnSceneSelected();
|
||||
}
|
||||
|
||||
public void SetSceneObjectParent()
|
||||
{
|
||||
if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent?.gameObject)
|
||||
{
|
||||
m_selectedSceneObject = null;
|
||||
SetTargetScene(m_currentScene);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTargetObject(m_selectedSceneObject.transform.parent.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTargetObject(GameObject obj)
|
||||
{
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
UI.OnGameObjectSelected(obj);
|
||||
|
||||
m_selectedSceneObject = obj;
|
||||
|
||||
RefreshSelectedSceneObject();
|
||||
}
|
||||
|
||||
private void RefreshSelectedSceneObject()
|
||||
{
|
||||
GameObject[] list = new GameObject[m_selectedSceneObject.transform.childCount];
|
||||
for (int i = 0; i < m_selectedSceneObject.transform.childCount; i++)
|
||||
{
|
||||
list[i] = m_selectedSceneObject.transform.GetChild(i).gameObject;
|
||||
}
|
||||
|
||||
SetSceneObjectList(list);
|
||||
}
|
||||
|
||||
private void SetSceneObjectList(GameObject[] objects)
|
||||
{
|
||||
m_allObjects = objects;
|
||||
RefreshSceneObjectList();
|
||||
}
|
||||
|
||||
internal void RefreshSceneObjectList()
|
||||
{
|
||||
m_timeOfLastSceneUpdate = Time.realtimeSinceStartup;
|
||||
|
||||
UI.RefreshSceneObjectList(m_allObjects, out int newCount);
|
||||
|
||||
m_lastCount = newCount;
|
||||
}
|
||||
|
||||
internal static void InspectSelectedGameObject()
|
||||
{
|
||||
InspectorManager.Instance.Inspect(Instance.m_selectedSceneObject);
|
||||
}
|
||||
|
||||
internal static void InvokeOnToggleShow()
|
||||
{
|
||||
OnToggleShow?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
14
src/Core/Search/ChildFilter.cs
Normal file
14
src/Core/Search/ChildFilter.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
internal enum ChildFilter
|
||||
{
|
||||
Any,
|
||||
RootObject,
|
||||
HasParent
|
||||
}
|
||||
}
|
15
src/Core/Search/SceneFilter.cs
Normal file
15
src/Core/Search/SceneFilter.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
internal enum SceneFilter
|
||||
{
|
||||
Any,
|
||||
Asset,
|
||||
DontDestroyOnLoad,
|
||||
Explicit,
|
||||
}
|
||||
}
|
17
src/Core/Search/SearchContext.cs
Normal file
17
src/Core/Search/SearchContext.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
internal enum SearchContext
|
||||
{
|
||||
UnityObject,
|
||||
GameObject,
|
||||
Component,
|
||||
Custom,
|
||||
Singleton,
|
||||
StaticClass
|
||||
}
|
||||
}
|
227
src/Core/Search/SearchProvider.cs
Normal file
227
src/Core/Search/SearchProvider.cs
Normal file
@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main;
|
||||
|
||||
namespace UnityExplorer.Search
|
||||
{
|
||||
public static class SearchProvider
|
||||
{
|
||||
internal static object[] StaticClassSearch(string input)
|
||||
{
|
||||
var list = new List<Type>();
|
||||
|
||||
var nameFilter = "";
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
nameFilter = input.ToLower();
|
||||
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var type in asm.TryGetTypes().Where(it => it.IsSealed && it.IsAbstract))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
list.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
internal static string[] s_instanceNames = new string[]
|
||||
{
|
||||
"m_instance",
|
||||
"m_Instance",
|
||||
"s_instance",
|
||||
"s_Instance",
|
||||
"_instance",
|
||||
"_Instance",
|
||||
"instance",
|
||||
"Instance",
|
||||
"<Instance>k__BackingField",
|
||||
"<instance>k__BackingField",
|
||||
};
|
||||
|
||||
internal static object[] SingletonSearch(string input)
|
||||
{
|
||||
var instances = new List<object>();
|
||||
|
||||
var nameFilter = "";
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
nameFilter = input.ToLower();
|
||||
|
||||
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
|
||||
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
// Search all non-static, non-enum classes.
|
||||
foreach (var type in asm.TryGetTypes().Where(it => !(it.IsSealed && it.IsAbstract) && !it.IsEnum))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
#if CPP
|
||||
// Only look for Properties in IL2CPP, not for Mono.
|
||||
PropertyInfo pi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
pi = type.GetProperty(name, flags);
|
||||
if (pi != null)
|
||||
{
|
||||
var instance = pi.GetValue(null, null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Look for a typical Instance backing field.
|
||||
FieldInfo fi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
fi = type.GetField(name, flags);
|
||||
if (fi != null)
|
||||
{
|
||||
var instance = fi.GetValue(null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
return instances.ToArray();
|
||||
}
|
||||
|
||||
internal static object[] UnityObjectSearch(string input, string customTypeInput, SearchContext context,
|
||||
ChildFilter childFilter, SceneFilter sceneFilter)
|
||||
{
|
||||
Type searchType = null;
|
||||
switch (context)
|
||||
{
|
||||
case SearchContext.GameObject:
|
||||
searchType = typeof(GameObject); break;
|
||||
|
||||
case SearchContext.Component:
|
||||
searchType = typeof(Component); break;
|
||||
|
||||
case SearchContext.Custom:
|
||||
if (string.IsNullOrEmpty(customTypeInput))
|
||||
{
|
||||
ExplorerCore.LogWarning("Custom Type input must not be empty!");
|
||||
return null;
|
||||
}
|
||||
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
|
||||
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
|
||||
searchType = customType;
|
||||
else
|
||||
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
|
||||
else
|
||||
ExplorerCore.LogWarning($"Could not find a type by the name '{customTypeInput}'!");
|
||||
break;
|
||||
|
||||
default:
|
||||
searchType = typeof(UnityEngine.Object); break;
|
||||
}
|
||||
|
||||
if (searchType == null)
|
||||
return null;
|
||||
|
||||
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(searchType);
|
||||
var results = new List<object>();
|
||||
|
||||
// perform filter comparers
|
||||
|
||||
string nameFilter = null;
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
nameFilter = input.ToLower();
|
||||
|
||||
bool canGetGameObject = (sceneFilter != SceneFilter.Any || childFilter != ChildFilter.Any)
|
||||
&& (context == SearchContext.GameObject || typeof(Component).IsAssignableFrom(searchType));
|
||||
|
||||
string sceneFilterString = null;
|
||||
if (!canGetGameObject)
|
||||
{
|
||||
if (context != SearchContext.UnityObject && (sceneFilter != SceneFilter.Any || childFilter != ChildFilter.Any))
|
||||
ExplorerCore.LogWarning($"Type '{searchType}' cannot have Scene or Child filters applied to it");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sceneFilter == SceneFilter.DontDestroyOnLoad)
|
||||
sceneFilterString = "DontDestroyOnLoad";
|
||||
else if (sceneFilter == SceneFilter.Explicit)
|
||||
sceneFilterString = SearchPage.Instance.m_sceneDropdown.options[SearchPage.Instance.m_sceneDropdown.value].text;
|
||||
}
|
||||
|
||||
foreach (var obj in allObjects)
|
||||
{
|
||||
// name check
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
if (canGetGameObject)
|
||||
{
|
||||
#if MONO
|
||||
var go = context == SearchContext.GameObject
|
||||
? obj as GameObject
|
||||
: (obj as Component).gameObject;
|
||||
#else
|
||||
var go = context == SearchContext.GameObject
|
||||
? obj.TryCast<GameObject>()
|
||||
: obj.TryCast<Component>().gameObject;
|
||||
#endif
|
||||
|
||||
// scene check
|
||||
if (sceneFilter != SceneFilter.Any)
|
||||
{
|
||||
if (!go)
|
||||
continue;
|
||||
|
||||
switch (context)
|
||||
{
|
||||
case SearchContext.GameObject:
|
||||
if (go.scene.name != sceneFilterString)
|
||||
continue;
|
||||
break;
|
||||
case SearchContext.Custom:
|
||||
case SearchContext.Component:
|
||||
if (go.scene.name != sceneFilterString)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (childFilter != ChildFilter.Any)
|
||||
{
|
||||
if (!go)
|
||||
continue;
|
||||
|
||||
// root object check (no parent)
|
||||
if (childFilter == ChildFilter.HasParent && !go.transform.parent)
|
||||
continue;
|
||||
else if (childFilter == ChildFilter.RootObject && go.transform.parent)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(obj);
|
||||
}
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
290
src/Core/Tests/Tests.cs
Normal file
290
src/Core/Tests/Tests.cs
Normal file
@ -0,0 +1,290 @@
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using UnityExplorer.UI;
|
||||
//using UnityEngine;
|
||||
//using System;
|
||||
//using System.Runtime.InteropServices;
|
||||
//using System.Text;
|
||||
//using UnityExplorer.Core.Runtime;
|
||||
|
||||
//namespace UnityExplorer.Core.Tests
|
||||
//{
|
||||
// internal enum TestByteEnum : byte
|
||||
// {
|
||||
// One,
|
||||
// Two,
|
||||
// Three,
|
||||
// TwoFiftyFive = 255,
|
||||
// }
|
||||
|
||||
// public static class StaticTestClass
|
||||
// {
|
||||
// public static int StaticProperty => 5;
|
||||
// public static int StaticField = 69;
|
||||
// public static List<string> StaticList = new List<string>
|
||||
// {
|
||||
// "one",
|
||||
// "two",
|
||||
// "three",
|
||||
// };
|
||||
// public static void StaticMethod() { }
|
||||
// }
|
||||
|
||||
// public class TestClass
|
||||
// {
|
||||
// internal static TestByteEnum testingByte = TestByteEnum.One;
|
||||
|
||||
// public string AAALongString = @"1
|
||||
//2
|
||||
//3
|
||||
//4
|
||||
//5";
|
||||
|
||||
// public Vector2 AATestVector2 = new Vector2(1, 2);
|
||||
// public Vector3 AATestVector3 = new Vector3(1, 2, 3);
|
||||
// public Vector4 AATestVector4 = new Vector4(1, 2, 3, 4);
|
||||
// public Rect AATestRect = new Rect(1, 2, 3, 4);
|
||||
// public Color AATestColor = new Color(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
|
||||
// public bool ATestBoolMethod() => false;
|
||||
|
||||
// public bool this[int index]
|
||||
// {
|
||||
// get => index % 2 == 0;
|
||||
// set => m_thisBool = value;
|
||||
// }
|
||||
// internal bool m_thisBool;
|
||||
|
||||
// static int testInt;
|
||||
// public static List<string> ExceptionList
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// testInt++;
|
||||
// if (testInt % 2 == 0)
|
||||
// throw new Exception("its even");
|
||||
// else
|
||||
// return new List<string> { "one" };
|
||||
// }
|
||||
// }
|
||||
|
||||
// static bool abool;
|
||||
// public static bool ATestExceptionBool
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// abool = !abool;
|
||||
// if (!abool)
|
||||
// throw new Exception("false");
|
||||
// else
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static string ExceptionString => throw new NotImplementedException();
|
||||
|
||||
// public static string ANullString = null;
|
||||
// public static float ATestFloat = 420.69f;
|
||||
// public static int ATestInt = -1;
|
||||
// public static string ATestString = "hello world";
|
||||
// public static uint ATestUInt = 1u;
|
||||
// public static byte ATestByte = 255;
|
||||
// public static ulong AReadonlyUlong = 82934UL;
|
||||
|
||||
// public static TestClass Instance => m_instance ?? (m_instance = new TestClass());
|
||||
// private static TestClass m_instance;
|
||||
|
||||
// public object AmbigObject;
|
||||
|
||||
// public List<List<List<string>>> ANestedNestedList = new List<List<List<string>>>
|
||||
// {
|
||||
// new List<List<string>>
|
||||
// {
|
||||
// new List<string>
|
||||
// {
|
||||
// "one",
|
||||
// "two",
|
||||
// },
|
||||
// new List<string>
|
||||
// {
|
||||
// "three",
|
||||
// "four"
|
||||
// }
|
||||
// },
|
||||
// new List<List<string>>
|
||||
// {
|
||||
// new List<string>
|
||||
// {
|
||||
// "five",
|
||||
// "six"
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// public static bool SetOnlyProperty
|
||||
// {
|
||||
// set => m_setOnlyProperty = value;
|
||||
// }
|
||||
// private static bool m_setOnlyProperty;
|
||||
// public static bool ReadSetOnlyProperty => m_setOnlyProperty;
|
||||
|
||||
// public Texture2D TestTexture;
|
||||
// public static Sprite TestSprite;
|
||||
|
||||
//#if CPP
|
||||
// public static Il2CppSystem.Collections.Generic.HashSet<string> CppHashSetTest;
|
||||
// public static Il2CppSystem.Collections.Generic.List<string> CppStringTest;
|
||||
// public static Il2CppSystem.Collections.IList CppIList;
|
||||
// //public static Il2CppSystem.Collections.Generic.Dictionary<string, string> CppDictTest;
|
||||
// //public static Il2CppSystem.Collections.Generic.Dictionary<int, float> CppDictTest2;
|
||||
//#endif
|
||||
|
||||
// public TestClass()
|
||||
// {
|
||||
// int a = 0;
|
||||
// foreach (var list in ANestedNestedList)
|
||||
// {
|
||||
// foreach (var list2 in list)
|
||||
// {
|
||||
// for (int i = 0; i < 33; i++)
|
||||
// list2.Add(a++.ToString());
|
||||
// }
|
||||
// }
|
||||
|
||||
//#if CPP
|
||||
// //TextureSpriteTest();
|
||||
|
||||
// CppHashSetTest = new Il2CppSystem.Collections.Generic.HashSet<string>();
|
||||
// CppHashSetTest.Add("1");
|
||||
// CppHashSetTest.Add("2");
|
||||
// CppHashSetTest.Add("3");
|
||||
|
||||
// CppStringTest = new Il2CppSystem.Collections.Generic.List<string>();
|
||||
// CppStringTest.Add("1");
|
||||
// CppStringTest.Add("2");
|
||||
|
||||
// //CppDictTest = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
|
||||
// //CppDictTest.Add("key1", "value1");
|
||||
// //CppDictTest.Add("key2", "value2");
|
||||
// //CppDictTest.Add("key3", "value3");
|
||||
|
||||
// //CppDictTest2 = new Il2CppSystem.Collections.Generic.Dictionary<int, float>();
|
||||
// //CppDictTest2.Add(0, 0.5f);
|
||||
// //CppDictTest2.Add(1, 0.5f);
|
||||
// //CppDictTest2.Add(2, 0.5f);
|
||||
//#endif
|
||||
// }
|
||||
|
||||
// //private void TextureSpriteTest()
|
||||
// //{
|
||||
// // TestTexture = new Texture2D(32, 32, TextureFormat.ARGB32, false)
|
||||
// // {
|
||||
// // name = "TestTexture"
|
||||
// // };
|
||||
// // TestSprite = TextureUtilProvider.Instance.CreateSprite(TestTexture);
|
||||
|
||||
// // GameObject.DontDestroyOnLoad(TestTexture);
|
||||
// // GameObject.DontDestroyOnLoad(TestSprite);
|
||||
|
||||
// // // test loading a tex from file
|
||||
// // if (System.IO.File.Exists(@"D:\Downloads\test.png"))
|
||||
// // {
|
||||
// // var dataToLoad = System.IO.File.ReadAllBytes(@"D:\Downloads\test.png");
|
||||
// // ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}");
|
||||
// // }
|
||||
// //}
|
||||
|
||||
// //public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
|
||||
// //{
|
||||
// // arg2 = "this is arg2";
|
||||
|
||||
// // return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
|
||||
// //}
|
||||
|
||||
// // test a non-generic dictionary
|
||||
|
||||
// public Hashtable TestNonGenericDict()
|
||||
// {
|
||||
// return new Hashtable
|
||||
// {
|
||||
// { "One", 1 },
|
||||
// { "Two", 2 },
|
||||
// { "Three", 3 },
|
||||
// };
|
||||
// }
|
||||
|
||||
// // test HashSets
|
||||
|
||||
// public static HashSet<string> HashSetTest = new HashSet<string>
|
||||
// {
|
||||
// "One",
|
||||
// "Two",
|
||||
// "Three"
|
||||
// };
|
||||
|
||||
|
||||
// // Test indexed parameter
|
||||
|
||||
// public string this[int arg0, string arg1]
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return $"arg0: {arg0}, arg1: {arg1}";
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Test basic list
|
||||
|
||||
// public static List<string> TestList = new List<string>
|
||||
// {
|
||||
// "1",
|
||||
// "2",
|
||||
// "3",
|
||||
// "etc..."
|
||||
// };
|
||||
|
||||
// // Test a nested dictionary
|
||||
|
||||
// public static Dictionary<int, Dictionary<string, int>> NestedDictionary = new Dictionary<int, Dictionary<string, int>>
|
||||
// {
|
||||
// {
|
||||
// 1,
|
||||
// new Dictionary<string, int>
|
||||
// {
|
||||
// {
|
||||
// "Sub 1", 123
|
||||
// },
|
||||
// {
|
||||
// "Sub 2", 456
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// 2,
|
||||
// new Dictionary<string, int>
|
||||
// {
|
||||
// {
|
||||
// "Sub 3", 789
|
||||
// },
|
||||
// {
|
||||
// "Sub 4", 000
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// };
|
||||
|
||||
// // Test a basic method
|
||||
|
||||
// public static Color TestMethod(float r, float g, float b, float a)
|
||||
// {
|
||||
// return new Color(r, g, b, a);
|
||||
// }
|
||||
|
||||
// // A method with default arguments
|
||||
|
||||
// public static Vector3 TestDefaultArgs(float arg0, float arg1, float arg2 = 5.0f)
|
||||
// {
|
||||
// return new Vector3(arg0, arg1, arg2);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,9 +1,9 @@
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Unstrip
|
||||
namespace UnityExplorer.Core.Unity
|
||||
{
|
||||
public static class ColorUtilityUnstrip
|
||||
public static class ColorHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts Color to 6-digit RGB hex code (without # symbol). Eg, RGBA(1,0,0,1) -> FF0000
|
@ -1,8 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
namespace UnityExplorer.Core.Unity
|
||||
{
|
||||
public static class UnityHelpers
|
||||
public static class UnityHelper
|
||||
{
|
||||
private static Camera m_mainCamera;
|
||||
|
@ -3,35 +3,36 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.Inspectors;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "UnityExplorer";
|
||||
public const string VERSION = "3.2.1";
|
||||
public const string VERSION = "3.2.9";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.unityexplorer";
|
||||
|
||||
public static ExplorerCore Instance { get; private set; }
|
||||
|
||||
private static IExplorerLoader s_loader;
|
||||
public static IExplorerLoader Loader => s_loader
|
||||
public static IExplorerLoader Loader =>
|
||||
#if ML
|
||||
?? (s_loader = ExplorerMelonMod.Instance);
|
||||
ExplorerMelonMod.Instance;
|
||||
#elif BIE
|
||||
?? (s_loader = ExplorerBepInPlugin.Instance);
|
||||
ExplorerBepInPlugin.Instance;
|
||||
#elif STANDALONE
|
||||
?? (s_loader = ExplorerStandalone.Instance);
|
||||
ExplorerStandalone.Instance;
|
||||
#endif
|
||||
|
||||
public static string ExplorerFolder => Loader.ExplorerFolder;
|
||||
public static string EXPLORER_FOLDER => Loader.ExplorerFolder;
|
||||
|
||||
public ExplorerCore()
|
||||
{
|
||||
@ -43,19 +44,16 @@ namespace UnityExplorer
|
||||
|
||||
Instance = this;
|
||||
|
||||
#if CPP
|
||||
ReflectionHelpers.TryLoadGameModules();
|
||||
#endif
|
||||
|
||||
if (!Directory.Exists(ExplorerFolder))
|
||||
Directory.CreateDirectory(ExplorerFolder);
|
||||
if (!Directory.Exists(EXPLORER_FOLDER))
|
||||
Directory.CreateDirectory(EXPLORER_FOLDER);
|
||||
|
||||
ExplorerConfig.OnLoad();
|
||||
|
||||
InputManager.Init();
|
||||
ForceUnlockCursor.Init();
|
||||
RuntimeProvider.Init();
|
||||
|
||||
SetupEvents();
|
||||
InputManager.Init();
|
||||
|
||||
CursorUnlocker.Init();
|
||||
|
||||
UIManager.ShowMenu = true;
|
||||
|
||||
@ -66,39 +64,13 @@ namespace UnityExplorer
|
||||
{
|
||||
UIManager.CheckUIInit();
|
||||
|
||||
if (MouseInspector.Enabled)
|
||||
MouseInspector.UpdateInspect();
|
||||
if (InspectUnderMouse.Enabled)
|
||||
InspectUnderMouse.UpdateInspect();
|
||||
else
|
||||
UIManager.Update();
|
||||
}
|
||||
|
||||
private void SetupEvents()
|
||||
{
|
||||
#if CPP
|
||||
try
|
||||
{
|
||||
Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
|
||||
|
||||
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((Scene a, LoadSceneMode b) => { OnSceneLoaded(); }));
|
||||
SceneManager.add_activeSceneChanged(new Action<Scene, Scene>((Scene a, Scene b) => { OnSceneLoaded(); }));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// exceptions here are non-fatal, just ignore.
|
||||
}
|
||||
#else
|
||||
Application.logMessageReceived += OnUnityLog;
|
||||
SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); };
|
||||
SceneManager.activeSceneChanged += (Scene a, Scene b) => { OnSceneLoaded(); };
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void OnSceneLoaded()
|
||||
{
|
||||
UIManager.OnSceneChange();
|
||||
}
|
||||
|
||||
private void OnUnityLog(string message, string stackTrace, LogType type)
|
||||
public void OnUnityLog(string message, string stackTrace, LogType type)
|
||||
{
|
||||
if (!DebugConsole.LogUnity)
|
||||
return;
|
||||
|
@ -1,33 +0,0 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
{
|
||||
// Possibly temporary, just so Il2Cpp can do the same style "AddListener" as Mono.
|
||||
// Just saves me having a preprocessor directive for every single AddListener.
|
||||
|
||||
public static class EventHelper
|
||||
{
|
||||
public static void AddListener(this UnityEvent action, Action listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T0, T1>(this UnityEvent<T0, T1> action, Action<T0, T1> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T0, T1, T2>(this UnityEvent<T0, T1, T2> action, Action<T0, T1, T2> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
{
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
||||
public static class ICallHelper
|
||||
{
|
||||
private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();
|
||||
|
||||
public static T GetICall<T>(string iCallName) where T : Delegate
|
||||
{
|
||||
if (iCallCache.ContainsKey(iCallName))
|
||||
return (T)iCallCache[iCallName];
|
||||
|
||||
IntPtr ptr = il2cpp_resolve_icall(iCallName);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new MissingMethodException($"Could not resolve internal call by name '{iCallName}'!");
|
||||
}
|
||||
|
||||
Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T));
|
||||
iCallCache.Add(iCallName, iCall);
|
||||
|
||||
return (T)iCall;
|
||||
}
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr il2cpp_resolve_icall([MarshalAs(UnmanagedType.LPStr)] string name);
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,352 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#if CPP
|
||||
using CppType = Il2CppSystem.Type;
|
||||
using UnhollowerBaseLib;
|
||||
using UnhollowerRuntimeLib;
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
{
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")]
|
||||
public static class ReflectionHelpers
|
||||
{
|
||||
public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
|
||||
|
||||
public static Type GetTypeByName(string fullName)
|
||||
{
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var type in asm.TryGetTypes())
|
||||
{
|
||||
if (type.FullName == fullName)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Type[] GetAllBaseTypes(object obj) => GetAllBaseTypes(GetActualType(obj));
|
||||
|
||||
public static Type[] GetAllBaseTypes(Type type)
|
||||
{
|
||||
List<Type> list = new List<Type>();
|
||||
|
||||
while (type != null)
|
||||
{
|
||||
list.Add(type);
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static Type GetActualType(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
var type = obj.GetType();
|
||||
#if CPP
|
||||
if (obj is Il2CppSystem.Object ilObject)
|
||||
{
|
||||
if (ilObject is CppType)
|
||||
return typeof(CppType);
|
||||
|
||||
if (!string.IsNullOrEmpty(type.Namespace))
|
||||
{
|
||||
// Il2CppSystem-namespace objects should just return GetType,
|
||||
// because using GetIl2CppType returns the System namespace type instead.
|
||||
if (type.Namespace.StartsWith("System.") || type.Namespace.StartsWith("Il2CppSystem."))
|
||||
return ilObject.GetType();
|
||||
}
|
||||
|
||||
var il2cppType = ilObject.GetIl2CppType();
|
||||
|
||||
// check if type is injected
|
||||
IntPtr classPtr = il2cpp_object_get_class(ilObject.Pointer);
|
||||
if (RuntimeSpecificsStore.IsInjected(classPtr))
|
||||
{
|
||||
var typeByName = GetTypeByName(il2cppType.FullName);
|
||||
if (typeByName != null)
|
||||
return typeByName;
|
||||
}
|
||||
|
||||
// this should be fine for all other il2cpp objects
|
||||
var getType = GetMonoType(il2cppType);
|
||||
if (getType != null)
|
||||
return getType;
|
||||
}
|
||||
#endif
|
||||
return type;
|
||||
}
|
||||
|
||||
#if CPP
|
||||
private static readonly Dictionary<string, Type> Il2CppToMonoType = new Dictionary<string, Type>();
|
||||
|
||||
public static Type GetMonoType(CppType cppType)
|
||||
{
|
||||
if (Il2CppToMonoType.ContainsKey(cppType.AssemblyQualifiedName))
|
||||
return Il2CppToMonoType[cppType.AssemblyQualifiedName];
|
||||
|
||||
var getType = Type.GetType(cppType.AssemblyQualifiedName);
|
||||
|
||||
if (getType != null)
|
||||
{
|
||||
Il2CppToMonoType.Add(cppType.AssemblyQualifiedName, getType);
|
||||
return getType;
|
||||
}
|
||||
else
|
||||
{
|
||||
string baseName = cppType.FullName;
|
||||
string baseAssembly = cppType.Assembly.GetName().name;
|
||||
|
||||
Type unhollowedType = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.FirstOrDefault(a => a.GetName().Name == baseAssembly)?
|
||||
.TryGetTypes()
|
||||
.FirstOrDefault(t =>
|
||||
t.CustomAttributes.Any(ca
|
||||
=> ca.AttributeType.Name == "ObfuscatedNameAttribute"
|
||||
&& (string)ca.ConstructorArguments[0].Value == baseName));
|
||||
|
||||
Il2CppToMonoType.Add(cppType.AssemblyQualifiedName, unhollowedType);
|
||||
|
||||
return unhollowedType;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, IntPtr> CppClassPointers = new Dictionary<Type, IntPtr>();
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to cast the object to its underlying type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object you want to cast.</param>
|
||||
/// <returns>The object, as the underlying type if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(this object obj) => Il2CppCast(obj, GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to cast the object to the provided type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object you want to cast.</param>
|
||||
/// <param name="castTo">The Type you want to cast to.</param>
|
||||
/// <returns>The object, as the type (or a normal C# object) if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(this object obj, Type castTo)
|
||||
{
|
||||
if (!(obj is Il2CppSystem.Object ilObj))
|
||||
return obj;
|
||||
|
||||
if (!Il2CppTypeNotNull(castTo, out IntPtr castToPtr))
|
||||
return obj;
|
||||
|
||||
IntPtr castFromPtr = il2cpp_object_get_class(ilObj.Pointer);
|
||||
|
||||
if (!il2cpp_class_is_assignable_from(castToPtr, castFromPtr))
|
||||
return obj;
|
||||
|
||||
if (RuntimeSpecificsStore.IsInjected(castToPtr))
|
||||
return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(ilObj.Pointer);
|
||||
|
||||
return Activator.CreateInstance(castTo, ilObj.Pointer);
|
||||
}
|
||||
|
||||
internal static readonly Dictionary<Type, MethodInfo> s_unboxMethods = new Dictionary<Type, MethodInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to unbox the object to the underlying struct type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object which is a struct underneath.</param>
|
||||
/// <returns>The struct if successful, otherwise null.</returns>
|
||||
public static object Unbox(this object obj) => Unbox(obj, GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to unbox the object to the struct type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object which is a struct underneath.</param>
|
||||
/// <param name="type">The type of the struct you want to unbox to.</param>
|
||||
/// <returns>The struct if successful, otherwise null.</returns>
|
||||
public static object Unbox(this object obj, Type type)
|
||||
{
|
||||
if (!type.IsValueType)
|
||||
return null;
|
||||
|
||||
if (!(obj is Il2CppSystem.Object))
|
||||
return obj;
|
||||
|
||||
if (!s_unboxMethods.ContainsKey(type))
|
||||
{
|
||||
s_unboxMethods.Add(type, typeof(Il2CppObjectBase)
|
||||
.GetMethod("Unbox")
|
||||
.MakeGenericMethod(type));
|
||||
}
|
||||
|
||||
return s_unboxMethods[type].Invoke(obj, new object[0]);
|
||||
}
|
||||
|
||||
public static bool Il2CppTypeNotNull(Type type) => Il2CppTypeNotNull(type, out _);
|
||||
|
||||
public static bool Il2CppTypeNotNull(Type type, out IntPtr il2cppPtr)
|
||||
{
|
||||
if (!CppClassPointers.ContainsKey(type))
|
||||
{
|
||||
il2cppPtr = (IntPtr)typeof(Il2CppClassPointerStore<>)
|
||||
.MakeGenericType(new Type[] { type })
|
||||
.GetField("NativeClassPtr", BF.Public | BF.Static)
|
||||
.GetValue(null);
|
||||
|
||||
CppClassPointers.Add(type, il2cppPtr);
|
||||
}
|
||||
else
|
||||
il2cppPtr = CppClassPointers[type];
|
||||
|
||||
return il2cppPtr != IntPtr.Zero;
|
||||
}
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern bool il2cpp_class_is_assignable_from(IntPtr klass, IntPtr oklass);
|
||||
|
||||
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr il2cpp_object_get_class(IntPtr obj);
|
||||
|
||||
#endif
|
||||
|
||||
public static IEnumerable<Type> TryGetTypes(this Assembly asm)
|
||||
{
|
||||
try
|
||||
{
|
||||
return asm.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
return asm.GetExportedTypes();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return e.Types.Where(t => t != null);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Enumerable.Empty<Type>();
|
||||
}
|
||||
}
|
||||
|
||||
#if CPP
|
||||
internal static void TryLoadGameModules()
|
||||
{
|
||||
LoadModule("Assembly-CSharp");
|
||||
LoadModule("Assembly-CSharp-firstpass");
|
||||
}
|
||||
|
||||
public static bool LoadModule(string module)
|
||||
{
|
||||
#if ML
|
||||
var path = $@"MelonLoader\Managed\{module}.dll";
|
||||
#else
|
||||
var path = $@"BepInEx\unhollowed\{module}.dll";
|
||||
#endif
|
||||
|
||||
return LoadModuleInternal(path);
|
||||
}
|
||||
|
||||
internal static bool LoadModuleInternal(string fullPath)
|
||||
{
|
||||
if (!File.Exists(fullPath))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Assembly.Load(File.ReadAllBytes(fullPath));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.GetType() + ", " + e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
public static bool LoadModule(string module) => true;
|
||||
#endif
|
||||
|
||||
#if CPP
|
||||
internal static IntPtr s_cppEnumerableClassPtr;
|
||||
#endif
|
||||
|
||||
public static bool IsEnumerable(Type t)
|
||||
{
|
||||
if (typeof(IEnumerable).IsAssignableFrom(t))
|
||||
return true;
|
||||
#if CPP
|
||||
try
|
||||
{
|
||||
if (s_cppEnumerableClassPtr == IntPtr.Zero)
|
||||
Il2CppTypeNotNull(typeof(Il2CppSystem.Collections.IEnumerable), out s_cppEnumerableClassPtr);
|
||||
|
||||
if (s_cppEnumerableClassPtr != IntPtr.Zero
|
||||
&& Il2CppTypeNotNull(t, out IntPtr classPtr)
|
||||
&& il2cpp_class_is_assignable_from(s_cppEnumerableClassPtr, classPtr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#if CPP
|
||||
internal static IntPtr s_cppDictionaryClassPtr;
|
||||
#endif
|
||||
|
||||
public static bool IsDictionary(Type t)
|
||||
{
|
||||
if (typeof(IDictionary).IsAssignableFrom(t))
|
||||
return true;
|
||||
#if CPP
|
||||
try
|
||||
{
|
||||
if (s_cppDictionaryClassPtr == IntPtr.Zero)
|
||||
if (!Il2CppTypeNotNull(typeof(Il2CppSystem.Collections.IDictionary), out s_cppDictionaryClassPtr))
|
||||
return false;
|
||||
|
||||
if (Il2CppTypeNotNull(t, out IntPtr classPtr))
|
||||
{
|
||||
if (il2cpp_class_is_assignable_from(s_cppDictionaryClassPtr, classPtr))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string ExceptionToString(Exception e, bool innerMost = false)
|
||||
{
|
||||
while (innerMost && e.InnerException != null)
|
||||
{
|
||||
#if CPP
|
||||
if (e.InnerException is System.Runtime.CompilerServices.RuntimeWrappedException runtimeEx)
|
||||
break;
|
||||
#endif
|
||||
e = e.InnerException;
|
||||
}
|
||||
|
||||
return e.GetType() + ", " + e.Message;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
{
|
||||
public abstract class InspectorBase
|
||||
{
|
||||
public object Target;
|
||||
|
||||
public abstract string TabLabel { get; }
|
||||
|
||||
public bool IsActive { get; private set; }
|
||||
public abstract GameObject Content { get; set; }
|
||||
public Button tabButton;
|
||||
public Text tabText;
|
||||
|
||||
internal bool m_pendingDestroy;
|
||||
|
||||
public InspectorBase(object target)
|
||||
{
|
||||
Target = target;
|
||||
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
AddInspectorTab();
|
||||
}
|
||||
|
||||
public virtual void SetActive()
|
||||
{
|
||||
this.IsActive = true;
|
||||
Content?.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void SetInactive()
|
||||
{
|
||||
this.IsActive = false;
|
||||
Content?.SetActive(false);
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
tabText.text = TabLabel;
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
m_pendingDestroy = true;
|
||||
|
||||
GameObject tabGroup = tabButton?.transform.parent.gameObject;
|
||||
|
||||
if (tabGroup)
|
||||
{
|
||||
GameObject.Destroy(tabGroup);
|
||||
}
|
||||
|
||||
int thisIndex = -1;
|
||||
if (InspectorManager.Instance.m_currentInspectors.Contains(this))
|
||||
{
|
||||
thisIndex = InspectorManager.Instance.m_currentInspectors.IndexOf(this);
|
||||
InspectorManager.Instance.m_currentInspectors.Remove(this);
|
||||
}
|
||||
|
||||
if (ReferenceEquals(InspectorManager.Instance.m_activeInspector, this))
|
||||
{
|
||||
InspectorManager.Instance.UnsetInspectorTab();
|
||||
|
||||
if (InspectorManager.Instance.m_currentInspectors.Count > 0)
|
||||
{
|
||||
var prevTab = InspectorManager.Instance.m_currentInspectors[thisIndex > 0 ? thisIndex - 1 : 0];
|
||||
InspectorManager.Instance.SetInspectorTab(prevTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
public void AddInspectorTab()
|
||||
{
|
||||
var tabContent = InspectorManager.Instance.m_tabBarContent;
|
||||
|
||||
var tabGroupObj = UIFactory.CreateHorizontalGroup(tabContent);
|
||||
var tabGroup = tabGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
tabGroup.childForceExpandWidth = true;
|
||||
tabGroup.childControlWidth = true;
|
||||
var tabLayout = tabGroupObj.AddComponent<LayoutElement>();
|
||||
tabLayout.minWidth = 185;
|
||||
tabLayout.flexibleWidth = 0;
|
||||
tabGroupObj.AddComponent<Mask>();
|
||||
|
||||
var targetButtonObj = UIFactory.CreateButton(tabGroupObj);
|
||||
targetButtonObj.AddComponent<Mask>();
|
||||
var targetButtonLayout = targetButtonObj.AddComponent<LayoutElement>();
|
||||
targetButtonLayout.minWidth = 165;
|
||||
targetButtonLayout.flexibleWidth = 0;
|
||||
|
||||
tabText = targetButtonObj.GetComponentInChildren<Text>();
|
||||
tabText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
tabText.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
tabButton = targetButtonObj.GetComponent<Button>();
|
||||
|
||||
tabButton.onClick.AddListener(() => { InspectorManager.Instance.SetInspectorTab(this); });
|
||||
|
||||
var closeBtnObj = UIFactory.CreateButton(tabGroupObj);
|
||||
var closeBtnLayout = closeBtnObj.AddComponent<LayoutElement>();
|
||||
closeBtnLayout.minWidth = 20;
|
||||
closeBtnLayout.flexibleWidth = 0;
|
||||
var closeBtnText = closeBtnObj.GetComponentInChildren<Text>();
|
||||
closeBtnText.text = "X";
|
||||
closeBtnText.color = new Color(1, 0, 0, 1);
|
||||
|
||||
var closeBtn = closeBtnObj.GetComponent<Button>();
|
||||
|
||||
closeBtn.onClick.AddListener(Destroy);
|
||||
|
||||
var closeColors = closeBtn.colors;
|
||||
closeColors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||
closeBtn.colors = closeColors;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Unstrip;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
{
|
||||
public class MouseInspector
|
||||
{
|
||||
public enum MouseInspectMode
|
||||
{
|
||||
World,
|
||||
UI
|
||||
}
|
||||
|
||||
public static bool Enabled { get; set; }
|
||||
|
||||
public static MouseInspectMode Mode { get; set; }
|
||||
|
||||
internal static Text s_objNameLabel;
|
||||
internal static Text s_objPathLabel;
|
||||
internal static Text s_mousePosLabel;
|
||||
|
||||
private static GameObject s_lastHit;
|
||||
private static Vector3 s_lastMousePos;
|
||||
|
||||
internal static GameObject s_UIContent;
|
||||
|
||||
public static void StartInspect()
|
||||
{
|
||||
Enabled = true;
|
||||
MainMenu.Instance.MainPanel.SetActive(false);
|
||||
s_UIContent.SetActive(true);
|
||||
|
||||
// recache Graphic Raycasters each time we start
|
||||
var casters = ResourcesUnstrip.FindObjectsOfTypeAll(typeof(GraphicRaycaster));
|
||||
m_gCasters = new GraphicRaycaster[casters.Length];
|
||||
for (int i = 0; i < casters.Length; i++)
|
||||
{
|
||||
#if CPP
|
||||
m_gCasters[i] = casters[i].TryCast<GraphicRaycaster>();
|
||||
#else
|
||||
m_gCasters[i] = casters[i] as GraphicRaycaster;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static void StopInspect()
|
||||
{
|
||||
Enabled = false;
|
||||
MainMenu.Instance.MainPanel.SetActive(true);
|
||||
s_UIContent.SetActive(false);
|
||||
|
||||
ClearHitData();
|
||||
}
|
||||
|
||||
internal static GraphicRaycaster[] m_gCasters;
|
||||
|
||||
public static void UpdateInspect()
|
||||
{
|
||||
if (InputManager.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
StopInspect();
|
||||
return;
|
||||
}
|
||||
|
||||
var mousePos = InputManager.MousePosition;
|
||||
|
||||
if (mousePos != s_lastMousePos)
|
||||
UpdatePosition(mousePos);
|
||||
|
||||
if (!UnityHelpers.MainCamera)
|
||||
return;
|
||||
|
||||
// actual inspect raycast
|
||||
|
||||
switch (Mode)
|
||||
{
|
||||
case MouseInspectMode.UI:
|
||||
RaycastUI(mousePos); break;
|
||||
case MouseInspectMode.World:
|
||||
RaycastWorld(mousePos); break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OnHitGameObject(GameObject obj)
|
||||
{
|
||||
if (obj != s_lastHit)
|
||||
{
|
||||
s_lastHit = obj;
|
||||
s_objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
||||
s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
||||
}
|
||||
|
||||
if (InputManager.GetMouseButtonDown(0))
|
||||
{
|
||||
StopInspect();
|
||||
InspectorManager.Instance.Inspect(obj);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RaycastWorld(Vector2 mousePos)
|
||||
{
|
||||
var ray = UnityHelpers.MainCamera.ScreenPointToRay(mousePos);
|
||||
Physics.Raycast(ray, out RaycastHit hit, 1000f);
|
||||
|
||||
if (hit.transform)
|
||||
{
|
||||
var obj = hit.transform.gameObject;
|
||||
OnHitGameObject(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_lastHit)
|
||||
ClearHitData();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RaycastUI(Vector2 mousePos)
|
||||
{
|
||||
var ped = new PointerEventData(null)
|
||||
{
|
||||
position = mousePos
|
||||
};
|
||||
|
||||
#if MONO
|
||||
var list = new List<RaycastResult>();
|
||||
#else
|
||||
var list = new Il2CppSystem.Collections.Generic.List<RaycastResult>();
|
||||
#endif
|
||||
foreach (var gr in m_gCasters)
|
||||
{
|
||||
gr.Raycast(ped, list);
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
foreach (var hit in list)
|
||||
{
|
||||
if (hit.gameObject)
|
||||
{
|
||||
var obj = hit.gameObject;
|
||||
|
||||
OnHitGameObject(obj);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_lastHit)
|
||||
ClearHitData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdatePosition(Vector2 mousePos)
|
||||
{
|
||||
s_lastMousePos = mousePos;
|
||||
|
||||
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
|
||||
|
||||
s_mousePosLabel.text = $"<color=grey>Mouse Position:</color> {mousePos.ToString()}";
|
||||
|
||||
float yFix = mousePos.y < 120 ? 80 : -80;
|
||||
s_UIContent.transform.localPosition = new Vector3(inversePos.x, inversePos.y + yFix, 0);
|
||||
}
|
||||
|
||||
internal static void ClearHitData()
|
||||
{
|
||||
s_lastHit = null;
|
||||
s_objNameLabel.text = "No hits...";
|
||||
s_objPathLabel.text = "";
|
||||
}
|
||||
|
||||
#region UI Construction
|
||||
|
||||
internal static void ConstructUI()
|
||||
{
|
||||
s_UIContent = UIFactory.CreatePanel(UIManager.CanvasRoot, "MouseInspect", out GameObject content);
|
||||
|
||||
s_UIContent.AddComponent<Mask>();
|
||||
|
||||
var baseRect = s_UIContent.GetComponent<RectTransform>();
|
||||
var half = new Vector2(0.5f, 0.5f);
|
||||
baseRect.anchorMin = half;
|
||||
baseRect.anchorMax = half;
|
||||
baseRect.pivot = half;
|
||||
baseRect.sizeDelta = new Vector2(700, 150);
|
||||
|
||||
var group = content.GetComponent<VerticalLayoutGroup>();
|
||||
group.childForceExpandHeight = true;
|
||||
|
||||
// Title text
|
||||
|
||||
var titleObj = UIFactory.CreateLabel(content, TextAnchor.MiddleCenter);
|
||||
var titleText = titleObj.GetComponent<Text>();
|
||||
titleText.text = "<b>Mouse Inspector</b> (press <b>ESC</b> to cancel)";
|
||||
|
||||
var mousePosObj = UIFactory.CreateLabel(content, TextAnchor.MiddleCenter);
|
||||
s_mousePosLabel = mousePosObj.GetComponent<Text>();
|
||||
s_mousePosLabel.text = "Mouse Position:";
|
||||
|
||||
var hitLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||
s_objNameLabel = hitLabelObj.GetComponent<Text>();
|
||||
s_objNameLabel.text = "No hits...";
|
||||
s_objNameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
|
||||
var pathLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||
s_objPathLabel = pathLabelObj.GetComponent<Text>();
|
||||
s_objPathLabel.fontStyle = FontStyle.Italic;
|
||||
s_objPathLabel.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
|
||||
var pathLayout = pathLabelObj.AddComponent<LayoutElement>();
|
||||
pathLayout.minHeight = 75;
|
||||
pathLayout.flexibleHeight = 0;
|
||||
|
||||
s_UIContent.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,617 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Inspectors.Reflection;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
{
|
||||
public class ReflectionInspector : InspectorBase
|
||||
{
|
||||
#region STATIC
|
||||
|
||||
public static ReflectionInspector ActiveInstance { get; private set; }
|
||||
|
||||
static ReflectionInspector()
|
||||
{
|
||||
PanelDragger.OnFinishResize += OnContainerResized;
|
||||
SceneExplorer.OnToggleShow += OnContainerResized;
|
||||
}
|
||||
|
||||
private static void OnContainerResized()
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.m_widthUpdateWanted = true;
|
||||
}
|
||||
|
||||
// Blacklists
|
||||
private static readonly HashSet<string> bl_typeAndMember = new HashSet<string>
|
||||
{
|
||||
#if CPP
|
||||
// these cause a crash in IL2CPP
|
||||
"Type.DeclaringMethod",
|
||||
"Rigidbody2D.Cast",
|
||||
"Collider2D.Cast",
|
||||
"Collider2D.Raycast",
|
||||
"Texture2D.SetPixelDataImpl",
|
||||
"Camera.CalculateProjectionMatrixFromPhysicalProperties",
|
||||
#endif
|
||||
};
|
||||
private static readonly HashSet<string> bl_memberNameStartsWith = new HashSet<string>
|
||||
{
|
||||
// these are redundant
|
||||
"get_",
|
||||
"set_",
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region INSTANCE
|
||||
|
||||
public override string TabLabel => m_targetTypeShortName;
|
||||
|
||||
internal CacheObjectBase ParentMember { get; set; }
|
||||
|
||||
internal readonly Type m_targetType;
|
||||
internal readonly string m_targetTypeShortName;
|
||||
|
||||
// all cached members of the target
|
||||
internal CacheMember[] m_allMembers;
|
||||
// filtered members based on current filters
|
||||
internal readonly List<CacheMember> m_membersFiltered = new List<CacheMember>();
|
||||
// actual shortlist of displayed members
|
||||
internal readonly CacheMember[] m_displayedMembers = new CacheMember[ExplorerConfig.Instance.Default_Page_Limit];
|
||||
|
||||
internal bool m_autoUpdate;
|
||||
|
||||
// UI members
|
||||
|
||||
private GameObject m_content;
|
||||
public override GameObject Content
|
||||
{
|
||||
get => m_content;
|
||||
set => m_content = value;
|
||||
}
|
||||
|
||||
internal Text m_nameFilterText;
|
||||
internal MemberTypes m_memberFilter;
|
||||
internal Button m_lastActiveMemButton;
|
||||
|
||||
internal PageHandler m_pageHandler;
|
||||
internal SliderScrollbar m_sliderScroller;
|
||||
internal GameObject m_scrollContent;
|
||||
internal RectTransform m_scrollContentRect;
|
||||
|
||||
internal bool m_widthUpdateWanted;
|
||||
internal bool m_widthUpdateWaiting;
|
||||
|
||||
public ReflectionInspector(object target) : base(target)
|
||||
{
|
||||
if (this is StaticInspector)
|
||||
m_targetType = target as Type;
|
||||
else
|
||||
m_targetType = ReflectionHelpers.GetActualType(target);
|
||||
|
||||
m_targetTypeShortName = UISyntaxHighlight.ParseFullSyntax(m_targetType, false);
|
||||
|
||||
ConstructUI();
|
||||
|
||||
CacheMembers(m_targetType);
|
||||
|
||||
FilterMembers();
|
||||
}
|
||||
|
||||
public override void SetActive()
|
||||
{
|
||||
base.SetActive();
|
||||
ActiveInstance = this;
|
||||
}
|
||||
|
||||
public override void SetInactive()
|
||||
{
|
||||
base.SetInactive();
|
||||
ActiveInstance = null;
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
|
||||
if (this.Content)
|
||||
GameObject.Destroy(this.Content);
|
||||
}
|
||||
|
||||
private void OnPageTurned()
|
||||
{
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
internal bool IsBlacklisted(string sig) => bl_typeAndMember.Any(it => sig.Contains(it));
|
||||
internal bool IsBlacklisted(MethodInfo method) => bl_memberNameStartsWith.Any(it => method.Name.StartsWith(it));
|
||||
|
||||
internal string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
|
||||
internal string AppendArgsToSig(ParameterInfo[] args)
|
||||
{
|
||||
string ret = " (";
|
||||
foreach (var param in args)
|
||||
ret += $"{param.ParameterType.Name} {param.Name}, ";
|
||||
ret += ")";
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void CacheMembers(Type type)
|
||||
{
|
||||
var list = new List<CacheMember>();
|
||||
var cachedSigs = new HashSet<string>();
|
||||
|
||||
var types = ReflectionHelpers.GetAllBaseTypes(type);
|
||||
|
||||
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
||||
if (this is InstanceInspector)
|
||||
flags |= BindingFlags.Instance;
|
||||
|
||||
foreach (var declaringType in types)
|
||||
{
|
||||
var target = Target;
|
||||
#if CPP
|
||||
target = target.Il2CppCast(declaringType);
|
||||
#endif
|
||||
IEnumerable<MemberInfo> infos = declaringType.GetMethods(flags);
|
||||
infos = infos.Concat(declaringType.GetProperties(flags));
|
||||
infos = infos.Concat(declaringType.GetFields(flags));
|
||||
|
||||
foreach (var member in infos)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sig = GetSig(member);
|
||||
|
||||
//ExplorerCore.Log($"Trying to cache member {sig}...");
|
||||
//ExplorerCore.Log(member.DeclaringType.FullName + "." + member.Name);
|
||||
|
||||
var mi = member as MethodInfo;
|
||||
var pi = member as PropertyInfo;
|
||||
var fi = member as FieldInfo;
|
||||
|
||||
if (IsBlacklisted(sig) || (mi != null && IsBlacklisted(mi)))
|
||||
continue;
|
||||
|
||||
var args = mi?.GetParameters() ?? pi?.GetIndexParameters();
|
||||
if (args != null)
|
||||
{
|
||||
if (!CacheMember.CanProcessArgs(args))
|
||||
continue;
|
||||
|
||||
sig += AppendArgsToSig(args);
|
||||
}
|
||||
|
||||
if (cachedSigs.Contains(sig))
|
||||
continue;
|
||||
|
||||
cachedSigs.Add(sig);
|
||||
|
||||
if (mi != null)
|
||||
list.Add(new CacheMethod(mi, target, m_scrollContent));
|
||||
else if (pi != null)
|
||||
list.Add(new CacheProperty(pi, target, m_scrollContent));
|
||||
else
|
||||
list.Add(new CacheField(fi, target, m_scrollContent));
|
||||
|
||||
list.Last().ParentInspector = this;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
|
||||
ExplorerCore.Log(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var typeList = types.ToList();
|
||||
|
||||
var sorted = new List<CacheMember>();
|
||||
sorted.AddRange(list.Where(it => it is CacheMethod)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(list.Where(it => it is CacheProperty)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(list.Where(it => it is CacheField)
|
||||
.OrderBy(it => typeList.IndexOf(it.DeclaringType))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
|
||||
m_allMembers = sorted.ToArray();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (m_autoUpdate)
|
||||
{
|
||||
foreach (var member in m_displayedMembers)
|
||||
{
|
||||
if (member == null) break;
|
||||
member.UpdateValue();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_widthUpdateWanted)
|
||||
{
|
||||
if (!m_widthUpdateWaiting)
|
||||
m_widthUpdateWaiting = true;
|
||||
else
|
||||
{
|
||||
UpdateWidths();
|
||||
m_widthUpdateWaiting = false;
|
||||
m_widthUpdateWanted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMemberFilterClicked(MemberTypes type, Button button)
|
||||
{
|
||||
if (m_lastActiveMemButton)
|
||||
{
|
||||
var lastColors = m_lastActiveMemButton.colors;
|
||||
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
m_lastActiveMemButton.colors = lastColors;
|
||||
}
|
||||
|
||||
m_memberFilter = type;
|
||||
m_lastActiveMemButton = button;
|
||||
|
||||
var colors = m_lastActiveMemButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_lastActiveMemButton.colors = colors;
|
||||
|
||||
FilterMembers(null, true);
|
||||
m_sliderScroller.m_slider.value = 1f;
|
||||
}
|
||||
|
||||
public void FilterMembers(string nameFilter = null, bool force = false)
|
||||
{
|
||||
int lastCount = m_membersFiltered.Count;
|
||||
m_membersFiltered.Clear();
|
||||
|
||||
nameFilter = nameFilter?.ToLower() ?? m_nameFilterText.text.ToLower();
|
||||
|
||||
foreach (var mem in m_allMembers)
|
||||
{
|
||||
// membertype filter
|
||||
if (m_memberFilter != MemberTypes.All && mem.MemInfo.MemberType != m_memberFilter)
|
||||
continue;
|
||||
|
||||
if (this is InstanceInspector ii && ii.m_scopeFilter != MemberScopes.All)
|
||||
{
|
||||
if (mem.IsStatic && ii.m_scopeFilter != MemberScopes.Static)
|
||||
continue;
|
||||
else if (!mem.IsStatic && ii.m_scopeFilter != MemberScopes.Instance)
|
||||
continue;
|
||||
}
|
||||
|
||||
// name filter
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !mem.NameForFiltering.Contains(nameFilter))
|
||||
continue;
|
||||
|
||||
m_membersFiltered.Add(mem);
|
||||
}
|
||||
|
||||
if (force || lastCount != m_membersFiltered.Count)
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public void RefreshDisplay()
|
||||
{
|
||||
var members = m_membersFiltered;
|
||||
m_pageHandler.ListCount = members.Count;
|
||||
|
||||
// disable current members
|
||||
for (int i = 0; i < m_displayedMembers.Length; i++)
|
||||
{
|
||||
var mem = m_displayedMembers[i];
|
||||
if (mem != null)
|
||||
mem.Disable();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (members.Count < 1)
|
||||
return;
|
||||
|
||||
foreach (var itemIndex in m_pageHandler)
|
||||
{
|
||||
if (itemIndex >= members.Count)
|
||||
break;
|
||||
|
||||
CacheMember member = members[itemIndex];
|
||||
m_displayedMembers[itemIndex - m_pageHandler.StartIndex] = member;
|
||||
member.Enable();
|
||||
}
|
||||
|
||||
m_widthUpdateWanted = true;
|
||||
}
|
||||
|
||||
internal void UpdateWidths()
|
||||
{
|
||||
float labelWidth = 125;
|
||||
|
||||
foreach (var cache in m_displayedMembers)
|
||||
{
|
||||
if (cache == null)
|
||||
break;
|
||||
|
||||
var width = cache.GetMemberLabelWidth(m_scrollContentRect);
|
||||
|
||||
if (width > labelWidth)
|
||||
labelWidth = width;
|
||||
}
|
||||
|
||||
float valueWidth = m_scrollContentRect.rect.width - labelWidth - 20;
|
||||
|
||||
foreach (var cache in m_displayedMembers)
|
||||
{
|
||||
if (cache == null)
|
||||
break;
|
||||
cache.SetWidths(labelWidth, valueWidth);
|
||||
}
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_filterAreaObj;
|
||||
internal GameObject m_updateRowObj;
|
||||
internal GameObject m_memberListObj;
|
||||
|
||||
internal void ConstructUI()
|
||||
{
|
||||
var parent = InspectorManager.Instance.m_inspectorContent;
|
||||
this.Content = UIFactory.CreateVerticalGroup(parent, new Color(0.15f, 0.15f, 0.15f));
|
||||
var mainGroup = Content.GetComponent<VerticalLayoutGroup>();
|
||||
mainGroup.childForceExpandHeight = false;
|
||||
mainGroup.childForceExpandWidth = true;
|
||||
mainGroup.childControlHeight = true;
|
||||
mainGroup.childControlWidth = true;
|
||||
mainGroup.spacing = 5;
|
||||
mainGroup.padding.top = 4;
|
||||
mainGroup.padding.left = 4;
|
||||
mainGroup.padding.right = 4;
|
||||
mainGroup.padding.bottom = 4;
|
||||
|
||||
ConstructTopArea();
|
||||
|
||||
ConstructMemberList();
|
||||
}
|
||||
|
||||
internal void ConstructTopArea()
|
||||
{
|
||||
var nameRowObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
|
||||
var nameRow = nameRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
nameRow.childForceExpandWidth = true;
|
||||
nameRow.childForceExpandHeight = true;
|
||||
nameRow.childControlHeight = true;
|
||||
nameRow.childControlWidth = true;
|
||||
nameRow.padding.top = 2;
|
||||
var nameRowLayout = nameRowObj.AddComponent<LayoutElement>();
|
||||
nameRowLayout.minHeight = 25;
|
||||
nameRowLayout.flexibleHeight = 0;
|
||||
nameRowLayout.minWidth = 200;
|
||||
nameRowLayout.flexibleWidth = 5000;
|
||||
|
||||
var typeLabel = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleLeft);
|
||||
var typeLabelText = typeLabel.GetComponent<Text>();
|
||||
typeLabelText.text = "Type:";
|
||||
typeLabelText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
var typeLabelTextLayout = typeLabel.AddComponent<LayoutElement>();
|
||||
typeLabelTextLayout.minWidth = 40;
|
||||
typeLabelTextLayout.flexibleWidth = 0;
|
||||
typeLabelTextLayout.minHeight = 25;
|
||||
|
||||
var typeDisplayObj = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleLeft);
|
||||
var typeDisplayText = typeDisplayObj.GetComponent<Text>();
|
||||
typeDisplayText.text = UISyntaxHighlight.ParseFullSyntax(m_targetType, true);
|
||||
var typeDisplayLayout = typeDisplayObj.AddComponent<LayoutElement>();
|
||||
typeDisplayLayout.minHeight = 25;
|
||||
typeDisplayLayout.flexibleWidth = 5000;
|
||||
|
||||
// Helper tools
|
||||
|
||||
if (this is InstanceInspector)
|
||||
{
|
||||
(this as InstanceInspector).ConstructInstanceHelpers();
|
||||
}
|
||||
|
||||
ConstructFilterArea();
|
||||
|
||||
ConstructUpdateRow();
|
||||
}
|
||||
|
||||
internal void ConstructFilterArea()
|
||||
{
|
||||
// Filters
|
||||
|
||||
var filterAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var filterLayout = filterAreaObj.AddComponent<LayoutElement>();
|
||||
filterLayout.minHeight = 60;
|
||||
var filterGroup = filterAreaObj.GetComponent<VerticalLayoutGroup>();
|
||||
filterGroup.childForceExpandWidth = true;
|
||||
filterGroup.childForceExpandHeight = true;
|
||||
filterGroup.childControlWidth = true;
|
||||
filterGroup.childControlHeight = true;
|
||||
filterGroup.spacing = 4;
|
||||
filterGroup.padding.left = 4;
|
||||
filterGroup.padding.right = 4;
|
||||
filterGroup.padding.top = 4;
|
||||
filterGroup.padding.bottom = 4;
|
||||
|
||||
m_filterAreaObj = filterAreaObj;
|
||||
|
||||
// name filter
|
||||
|
||||
var nameFilterRowObj = UIFactory.CreateHorizontalGroup(filterAreaObj, new Color(1, 1, 1, 0));
|
||||
var nameFilterGroup = nameFilterRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
nameFilterGroup.childForceExpandHeight = false;
|
||||
nameFilterGroup.childForceExpandWidth = false;
|
||||
nameFilterGroup.childControlWidth = true;
|
||||
nameFilterGroup.childControlHeight = true;
|
||||
nameFilterGroup.spacing = 5;
|
||||
var nameFilterLayout = nameFilterRowObj.AddComponent<LayoutElement>();
|
||||
nameFilterLayout.minHeight = 25;
|
||||
nameFilterLayout.flexibleHeight = 0;
|
||||
nameFilterLayout.flexibleWidth = 5000;
|
||||
|
||||
var nameLabelObj = UIFactory.CreateLabel(nameFilterRowObj, TextAnchor.MiddleLeft);
|
||||
var nameLabelLayout = nameLabelObj.AddComponent<LayoutElement>();
|
||||
nameLabelLayout.minWidth = 100;
|
||||
nameLabelLayout.minHeight = 25;
|
||||
nameLabelLayout.flexibleWidth = 0;
|
||||
var nameLabelText = nameLabelObj.GetComponent<Text>();
|
||||
nameLabelText.text = "Filter names:";
|
||||
nameLabelText.color = Color.grey;
|
||||
|
||||
var nameInputObj = UIFactory.CreateInputField(nameFilterRowObj, 14, (int)TextAnchor.MiddleLeft, (int)HorizontalWrapMode.Overflow);
|
||||
var nameInputLayout = nameInputObj.AddComponent<LayoutElement>();
|
||||
nameInputLayout.flexibleWidth = 5000;
|
||||
nameInputLayout.minWidth = 100;
|
||||
nameInputLayout.minHeight = 25;
|
||||
var nameInput = nameInputObj.GetComponent<InputField>();
|
||||
nameInput.onValueChanged.AddListener((string val) => { FilterMembers(val); });
|
||||
m_nameFilterText = nameInput.textComponent;
|
||||
|
||||
// membertype filter
|
||||
|
||||
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(filterAreaObj, new Color(1, 1, 1, 0));
|
||||
var memFilterGroup = memberFilterRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
memFilterGroup.childForceExpandHeight = false;
|
||||
memFilterGroup.childForceExpandWidth = false;
|
||||
memFilterGroup.childControlWidth = true;
|
||||
memFilterGroup.childControlHeight = true;
|
||||
memFilterGroup.spacing = 5;
|
||||
var memFilterLayout = memberFilterRowObj.AddComponent<LayoutElement>();
|
||||
memFilterLayout.minHeight = 25;
|
||||
memFilterLayout.flexibleHeight = 0;
|
||||
memFilterLayout.flexibleWidth = 5000;
|
||||
|
||||
var memLabelObj = UIFactory.CreateLabel(memberFilterRowObj, TextAnchor.MiddleLeft);
|
||||
var memLabelLayout = memLabelObj.AddComponent<LayoutElement>();
|
||||
memLabelLayout.minWidth = 100;
|
||||
memLabelLayout.minHeight = 25;
|
||||
memLabelLayout.flexibleWidth = 0;
|
||||
var memLabelText = memLabelObj.GetComponent<Text>();
|
||||
memLabelText.text = "Filter members:";
|
||||
memLabelText.color = Color.grey;
|
||||
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.All);
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.Method);
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.Property, true);
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.Field);
|
||||
|
||||
// Instance filters
|
||||
|
||||
if (this is InstanceInspector)
|
||||
{
|
||||
(this as InstanceInspector).ConstructInstanceFilters(filterAreaObj);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddFilterButton(GameObject parent, MemberTypes type, bool setEnabled = false)
|
||||
{
|
||||
var btnObj = UIFactory.CreateButton(parent, new Color(0.2f, 0.2f, 0.2f));
|
||||
|
||||
var btnLayout = btnObj.AddComponent<LayoutElement>();
|
||||
btnLayout.minHeight = 25;
|
||||
btnLayout.minWidth = 70;
|
||||
|
||||
var text = btnObj.GetComponentInChildren<Text>();
|
||||
text.text = type.ToString();
|
||||
|
||||
var btn = btnObj.GetComponent<Button>();
|
||||
|
||||
btn.onClick.AddListener(() => { OnMemberFilterClicked(type, btn); });
|
||||
|
||||
var colors = btn.colors;
|
||||
colors.highlightedColor = new Color(0.3f, 0.7f, 0.3f);
|
||||
|
||||
if (setEnabled)
|
||||
{
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_memberFilter = type;
|
||||
m_lastActiveMemButton = btn;
|
||||
}
|
||||
|
||||
btn.colors = colors;
|
||||
}
|
||||
|
||||
internal void ConstructUpdateRow()
|
||||
{
|
||||
var optionsRowObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
|
||||
var optionsLayout = optionsRowObj.AddComponent<LayoutElement>();
|
||||
optionsLayout.minHeight = 25;
|
||||
var optionsGroup = optionsRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
optionsGroup.childForceExpandHeight = true;
|
||||
optionsGroup.childForceExpandWidth = false;
|
||||
optionsGroup.childAlignment = TextAnchor.MiddleLeft;
|
||||
optionsGroup.spacing = 10;
|
||||
|
||||
m_updateRowObj = optionsRowObj;
|
||||
|
||||
// update button
|
||||
|
||||
var updateButtonObj = UIFactory.CreateButton(optionsRowObj, new Color(0.2f, 0.2f, 0.2f));
|
||||
var updateBtnLayout = updateButtonObj.AddComponent<LayoutElement>();
|
||||
updateBtnLayout.minWidth = 110;
|
||||
updateBtnLayout.flexibleWidth = 0;
|
||||
var updateText = updateButtonObj.GetComponentInChildren<Text>();
|
||||
updateText.text = "Update Values";
|
||||
var updateBtn = updateButtonObj.GetComponent<Button>();
|
||||
updateBtn.onClick.AddListener(() =>
|
||||
{
|
||||
bool orig = m_autoUpdate;
|
||||
m_autoUpdate = true;
|
||||
Update();
|
||||
if (!orig) m_autoUpdate = orig;
|
||||
});
|
||||
|
||||
// auto update
|
||||
|
||||
var autoUpdateObj = UIFactory.CreateToggle(optionsRowObj, out Toggle autoUpdateToggle, out Text autoUpdateText);
|
||||
var autoUpdateLayout = autoUpdateObj.AddComponent<LayoutElement>();
|
||||
autoUpdateLayout.minWidth = 150;
|
||||
autoUpdateLayout.minHeight = 25;
|
||||
autoUpdateText.text = "Auto-update?";
|
||||
autoUpdateToggle.isOn = false;
|
||||
autoUpdateToggle.onValueChanged.AddListener((bool val) => { m_autoUpdate = val; });
|
||||
}
|
||||
|
||||
internal void ConstructMemberList()
|
||||
{
|
||||
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.05f, 0.05f, 0.05f));
|
||||
|
||||
m_memberListObj = scrollobj;
|
||||
m_scrollContentRect = m_scrollContent.GetComponent<RectTransform>();
|
||||
|
||||
var scrollGroup = m_scrollContent.GetComponent<VerticalLayoutGroup>();
|
||||
scrollGroup.spacing = 3;
|
||||
scrollGroup.padding.left = 0;
|
||||
scrollGroup.padding.right = 0;
|
||||
scrollGroup.childForceExpandHeight = true;
|
||||
|
||||
m_pageHandler = new PageHandler(m_sliderScroller);
|
||||
m_pageHandler.ConstructUI(Content);
|
||||
m_pageHandler.OnPageChanged += OnPageTurned;
|
||||
}
|
||||
|
||||
#endregion // end UI
|
||||
|
||||
#endregion // end instance
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.UI.Main;
|
||||
#if CPP
|
||||
using UnhollowerRuntimeLib;
|
||||
using BepInEx.IL2CPP;
|
||||
|
@ -2,6 +2,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using MelonLoader;
|
||||
using UnityExplorer;
|
||||
|
||||
[assembly: MelonInfo(typeof(ExplorerMelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
|
||||
[assembly: MelonGame(null, null)]
|
||||
|
||||
namespace UnityExplorer
|
||||
{
|
||||
@ -30,10 +34,10 @@ namespace UnityExplorer
|
||||
ExplorerCore.Update();
|
||||
}
|
||||
|
||||
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
||||
{
|
||||
ExplorerCore.Instance.OnSceneLoaded();
|
||||
}
|
||||
//public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
||||
//{
|
||||
// ExplorerCore.Instance.OnSceneLoaded();
|
||||
//}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -2,13 +2,6 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityExplorer;
|
||||
|
||||
#if ML
|
||||
using MelonLoader;
|
||||
|
||||
[assembly: MelonInfo(typeof(ExplorerMelonMod), "UnityExplorer", ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
|
||||
[assembly: MelonGame(null, null)]
|
||||
#endif
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
|
@ -1,294 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using UnityExplorer.Unstrip;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
using UnityExplorer.Helpers;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Tests
|
||||
{
|
||||
internal enum TestByteEnum : byte
|
||||
{
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
TwoFiftyFive = 255,
|
||||
}
|
||||
|
||||
public static class StaticTestClass
|
||||
{
|
||||
public static int StaticProperty => 5;
|
||||
public static int StaticField = 69;
|
||||
public static List<string> StaticList = new List<string>
|
||||
{
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
};
|
||||
public static void StaticMethod() { }
|
||||
}
|
||||
|
||||
public class TestClass
|
||||
{
|
||||
internal static TestByteEnum testingByte = TestByteEnum.One;
|
||||
|
||||
public string AAALongString = @"1
|
||||
2
|
||||
3
|
||||
4
|
||||
5";
|
||||
|
||||
public Vector2 AATestVector2 = new Vector2(1, 2);
|
||||
public Vector3 AATestVector3 = new Vector3(1, 2, 3);
|
||||
public Vector4 AATestVector4 = new Vector4(1, 2, 3, 4);
|
||||
public Rect AATestRect = new Rect(1, 2, 3, 4);
|
||||
public Color AATestColor = new Color(0.1f, 0.2f, 0.3f, 0.4f);
|
||||
|
||||
public bool ATestBoolMethod() => false;
|
||||
|
||||
public bool this[int index]
|
||||
{
|
||||
get => index % 2 == 0;
|
||||
set => m_thisBool = value;
|
||||
}
|
||||
internal bool m_thisBool;
|
||||
|
||||
static int testInt;
|
||||
public static List<string> ExceptionList
|
||||
{
|
||||
get
|
||||
{
|
||||
testInt++;
|
||||
if (testInt % 2 == 0)
|
||||
throw new Exception("its even");
|
||||
else
|
||||
return new List<string> { "one" };
|
||||
}
|
||||
}
|
||||
|
||||
static bool abool;
|
||||
public static bool ATestExceptionBool
|
||||
{
|
||||
get
|
||||
{
|
||||
abool = !abool;
|
||||
if (!abool)
|
||||
throw new Exception("false");
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ExceptionString => throw new NotImplementedException();
|
||||
|
||||
public static string ANullString = null;
|
||||
public static float ATestFloat = 420.69f;
|
||||
public static int ATestInt = -1;
|
||||
public static string ATestString = "hello world";
|
||||
public static uint ATestUInt = 1u;
|
||||
public static byte ATestByte = 255;
|
||||
public static ulong AReadonlyUlong = 82934UL;
|
||||
|
||||
public static TestClass Instance => m_instance ?? (m_instance = new TestClass());
|
||||
private static TestClass m_instance;
|
||||
|
||||
public object AmbigObject;
|
||||
|
||||
public List<List<List<string>>> ANestedNestedList = new List<List<List<string>>>
|
||||
{
|
||||
new List<List<string>>
|
||||
{
|
||||
new List<string>
|
||||
{
|
||||
"one",
|
||||
"two",
|
||||
},
|
||||
new List<string>
|
||||
{
|
||||
"three",
|
||||
"four"
|
||||
}
|
||||
},
|
||||
new List<List<string>>
|
||||
{
|
||||
new List<string>
|
||||
{
|
||||
"five",
|
||||
"six"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static bool SetOnlyProperty
|
||||
{
|
||||
set => m_setOnlyProperty = value;
|
||||
}
|
||||
private static bool m_setOnlyProperty;
|
||||
public static bool ReadSetOnlyProperty => m_setOnlyProperty;
|
||||
|
||||
public Texture2D TestTexture;
|
||||
public static Sprite TestSprite;
|
||||
|
||||
#if CPP
|
||||
public static Il2CppSystem.Collections.Generic.HashSet<string> CppHashSetTest;
|
||||
public static Il2CppSystem.Collections.Generic.List<string> CppStringTest;
|
||||
public static Il2CppSystem.Collections.IList CppIList;
|
||||
//public static Il2CppSystem.Collections.Generic.Dictionary<string, string> CppDictTest;
|
||||
//public static Il2CppSystem.Collections.Generic.Dictionary<int, float> CppDictTest2;
|
||||
#endif
|
||||
|
||||
public TestClass()
|
||||
{
|
||||
int a = 0;
|
||||
foreach (var list in ANestedNestedList)
|
||||
{
|
||||
foreach (var list2 in list)
|
||||
{
|
||||
for (int i = 0; i < 33; i++)
|
||||
list2.Add(a++.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#if CPP
|
||||
TextureSpriteTest();
|
||||
|
||||
CppHashSetTest = new Il2CppSystem.Collections.Generic.HashSet<string>();
|
||||
CppHashSetTest.Add("1");
|
||||
CppHashSetTest.Add("2");
|
||||
CppHashSetTest.Add("3");
|
||||
|
||||
CppStringTest = new Il2CppSystem.Collections.Generic.List<string>();
|
||||
CppStringTest.Add("1");
|
||||
CppStringTest.Add("2");
|
||||
|
||||
//CppDictTest = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
|
||||
//CppDictTest.Add("key1", "value1");
|
||||
//CppDictTest.Add("key2", "value2");
|
||||
//CppDictTest.Add("key3", "value3");
|
||||
|
||||
//CppDictTest2 = new Il2CppSystem.Collections.Generic.Dictionary<int, float>();
|
||||
//CppDictTest2.Add(0, 0.5f);
|
||||
//CppDictTest2.Add(1, 0.5f);
|
||||
//CppDictTest2.Add(2, 0.5f);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void TextureSpriteTest()
|
||||
{
|
||||
TestTexture = new Texture2D(32, 32, TextureFormat.ARGB32, false)
|
||||
{
|
||||
name = "TestTexture"
|
||||
};
|
||||
TestSprite = ImageConversionUnstrip.CreateSprite(TestTexture);
|
||||
|
||||
GameObject.DontDestroyOnLoad(TestTexture);
|
||||
GameObject.DontDestroyOnLoad(TestSprite);
|
||||
|
||||
// test loading a tex from file
|
||||
if (System.IO.File.Exists(@"D:\Downloads\test.png"))
|
||||
{
|
||||
var dataToLoad = System.IO.File.ReadAllBytes(@"D:\Downloads\test.png");
|
||||
ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}");
|
||||
}
|
||||
}
|
||||
|
||||
public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
|
||||
{
|
||||
arg2 = "this is arg2";
|
||||
|
||||
return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
|
||||
}
|
||||
|
||||
// test a non-generic dictionary
|
||||
|
||||
public Hashtable TestNonGenericDict()
|
||||
{
|
||||
return new Hashtable
|
||||
{
|
||||
{ "One", 1 },
|
||||
{ "Two", 2 },
|
||||
{ "Three", 3 },
|
||||
};
|
||||
}
|
||||
|
||||
// test HashSets
|
||||
|
||||
public static HashSet<string> HashSetTest = new HashSet<string>
|
||||
{
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
};
|
||||
|
||||
|
||||
// Test indexed parameter
|
||||
|
||||
public string this[int arg0, string arg1]
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"arg0: {arg0}, arg1: {arg1}";
|
||||
}
|
||||
}
|
||||
|
||||
// Test basic list
|
||||
|
||||
public static List<string> TestList = new List<string>
|
||||
{
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"etc..."
|
||||
};
|
||||
|
||||
// Test a nested dictionary
|
||||
|
||||
public static Dictionary<int, Dictionary<string, int>> NestedDictionary = new Dictionary<int, Dictionary<string, int>>
|
||||
{
|
||||
{
|
||||
1,
|
||||
new Dictionary<string, int>
|
||||
{
|
||||
{
|
||||
"Sub 1", 123
|
||||
},
|
||||
{
|
||||
"Sub 2", 456
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
2,
|
||||
new Dictionary<string, int>
|
||||
{
|
||||
{
|
||||
"Sub 3", 789
|
||||
},
|
||||
{
|
||||
"Sub 4", 000
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Test a basic method
|
||||
|
||||
public static Color TestMethod(float r, float g, float b, float a)
|
||||
{
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
|
||||
// A method with default arguments
|
||||
|
||||
public static Vector3 TestDefaultArgs(float arg0, float arg1, float arg2 = 5.0f)
|
||||
{
|
||||
return new Vector3(arg0, arg1, arg2);
|
||||
}
|
||||
}
|
||||
}
|
27
src/UI/Main/BaseMenuPage.cs
Normal file
27
src/UI/Main/BaseMenuPage.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.UI.Main
|
||||
{
|
||||
public abstract class BaseMenuPage
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public GameObject Content;
|
||||
public Button RefNavbarButton { get; set; }
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => Content?.activeSelf ?? false;
|
||||
set => Content?.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public abstract bool Init();
|
||||
public abstract void Update();
|
||||
}
|
||||
}
|
@ -4,11 +4,12 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.CSharp;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.UI.Main;
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
namespace UnityExplorer.UI.Main.CSConsole
|
||||
{
|
||||
public class AutoCompleter
|
||||
{
|
||||
@ -45,7 +46,7 @@ namespace UnityExplorer.CSConsole
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CodeEditor.EnableAutocompletes)
|
||||
if (!CSharpConsole.EnableAutocompletes)
|
||||
{
|
||||
if (m_mainObj.activeSelf)
|
||||
{
|
||||
@ -132,7 +133,7 @@ namespace UnityExplorer.CSConsole
|
||||
{
|
||||
try
|
||||
{
|
||||
var editor = CSConsolePage.Instance.m_codeEditor;
|
||||
var editor = CSharpConsole.Instance;
|
||||
|
||||
if (!editor.InputField.isFocused)
|
||||
return;
|
||||
@ -164,7 +165,7 @@ namespace UnityExplorer.CSConsole
|
||||
|
||||
public static void CheckAutocomplete()
|
||||
{
|
||||
var m_codeEditor = CSConsolePage.Instance.m_codeEditor;
|
||||
var m_codeEditor = CSharpConsole.Instance;
|
||||
string input = m_codeEditor.InputField.text;
|
||||
int caretIndex = m_codeEditor.InputField.caretPosition;
|
||||
|
||||
@ -192,9 +193,9 @@ namespace UnityExplorer.CSConsole
|
||||
|
||||
public static void ClearAutocompletes()
|
||||
{
|
||||
if (CodeEditor.AutoCompletes.Any())
|
||||
if (CSharpConsole.AutoCompletes.Any())
|
||||
{
|
||||
CodeEditor.AutoCompletes.Clear();
|
||||
CSharpConsole.AutoCompletes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,8 +204,8 @@ namespace UnityExplorer.CSConsole
|
||||
try
|
||||
{
|
||||
// Credit ManylMarco
|
||||
CodeEditor.AutoCompletes.Clear();
|
||||
string[] completions = CSConsolePage.Instance.m_evaluator.GetCompletions(input, out string prefix);
|
||||
CSharpConsole.AutoCompletes.Clear();
|
||||
string[] completions = CSharpConsole.Instance.Evaluator.GetCompletions(input, out string prefix);
|
||||
if (completions != null)
|
||||
{
|
||||
if (prefix == null)
|
||||
@ -212,7 +213,7 @@ namespace UnityExplorer.CSConsole
|
||||
prefix = input;
|
||||
}
|
||||
|
||||
CodeEditor.AutoCompletes.AddRange(completions
|
||||
CSharpConsole.AutoCompletes.AddRange(completions
|
||||
.Where(x => !string.IsNullOrEmpty(x))
|
||||
.Select(x => new Suggestion(x, prefix, Suggestion.Contexts.Other))
|
||||
);
|
||||
@ -231,7 +232,7 @@ namespace UnityExplorer.CSConsole
|
||||
x.Substring(0, trimmed.Length),
|
||||
Suggestion.Contexts.Namespace));
|
||||
|
||||
CodeEditor.AutoCompletes.AddRange(namespaces);
|
||||
CSharpConsole.AutoCompletes.AddRange(namespaces);
|
||||
|
||||
IEnumerable<Suggestion> keywords = Suggestion.Keywords
|
||||
.Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length)
|
||||
@ -240,7 +241,7 @@ namespace UnityExplorer.CSConsole
|
||||
x.Substring(0, trimmed.Length),
|
||||
Suggestion.Contexts.Keyword));
|
||||
|
||||
CodeEditor.AutoCompletes.AddRange(keywords);
|
||||
CSharpConsole.AutoCompletes.AddRange(keywords);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -301,7 +302,7 @@ namespace UnityExplorer.CSConsole
|
||||
|
||||
void UseAutocompleteButton()
|
||||
{
|
||||
CSConsolePage.Instance.m_codeEditor.UseAutocomplete(hiddenText.text);
|
||||
CSharpConsole.Instance.UseAutocomplete(hiddenText.text);
|
||||
}
|
||||
|
||||
m_suggestionButtons.Add(buttonObj);
|
@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.CSConsole.Lexer;
|
||||
using UnityExplorer.UI.Main.CSConsole.Lexer;
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
namespace UnityExplorer.UI.Main.CSConsole
|
||||
{
|
||||
public struct LexerMatchInfo
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace UnityExplorer.CSConsole
|
||||
End,
|
||||
};
|
||||
|
||||
public class CSharpLexer
|
||||
public class CSLexerHighlighter
|
||||
{
|
||||
private string inputString;
|
||||
private readonly Matcher[] matchers;
|
||||
@ -53,20 +53,15 @@ namespace UnityExplorer.CSConsole
|
||||
"else", "equals", "false", "finally", "float", "for", "foreach", "from", "global", "goto", "group",
|
||||
"if", "in", "int", "into", "is", "join", "let", "lock", "long", "new", "null", "object", "on", "orderby", "out",
|
||||
"ref", "remove", "return", "sbyte", "select", "short", "sizeof", "stackalloc", "string",
|
||||
"switch", "throw", "true", "try", "typeof", "uint", "ulong", "ushort", "var", "where", "while", "yield" }
|
||||
};
|
||||
|
||||
public static KeywordMatch invalidKeywordMatcher = new KeywordMatch()
|
||||
{
|
||||
highlightColor = new Color(0.95f, 0.10f, 0.10f, 1.0f),
|
||||
Keywords = new[] { "abstract", "async", "base", "class", "delegate", "enum", "explicit", "extern", "fixed", "get",
|
||||
"implicit", "interface", "internal", "namespace", "operator", "override", "params", "private", "protected", "public",
|
||||
"using", "partial", "readonly", "sealed", "set", "static", "struct", "this", "unchecked", "unsafe", "value", "virtual", "volatile", "void" }
|
||||
"switch", "throw", "true", "try", "typeof", "uint", "ulong", "ushort", "var", "where", "while", "yield",
|
||||
"abstract", "async", "base", "class", "delegate", "enum", "explicit", "extern", "fixed", "get",
|
||||
"implicit", "interface", "internal", "namespace", "operator", "override", "params", "private", "protected", "public",
|
||||
"using", "partial", "readonly", "sealed", "set", "static", "struct", "this", "unchecked", "unsafe", "value", "virtual", "volatile", "void"}
|
||||
};
|
||||
|
||||
// ~~~~~~~ ctor ~~~~~~~
|
||||
|
||||
public CSharpLexer()
|
||||
public CSLexerHighlighter()
|
||||
{
|
||||
startDelimiters = new HashSet<char>(delimiters);
|
||||
endDelimiters = new HashSet<char>(delimiters);
|
||||
@ -78,7 +73,6 @@ namespace UnityExplorer.CSConsole
|
||||
numberMatcher,
|
||||
stringMatcher,
|
||||
validKeywordMatcher,
|
||||
invalidKeywordMatcher,
|
||||
};
|
||||
|
||||
foreach (Matcher lexer in matchers)
|
@ -1,24 +1,153 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.CSConsole.Lexer;
|
||||
using UnityExplorer.Core.CSharp;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
#if CPP
|
||||
using UnityExplorer.Core.Runtime.Il2Cpp;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
namespace UnityExplorer.UI.Main.CSConsole
|
||||
{
|
||||
// Handles most of the UI side of the C# console, including syntax highlighting.
|
||||
|
||||
public class CodeEditor
|
||||
public class CSharpConsole : BaseMenuPage
|
||||
{
|
||||
public override string Name => "C# Console";
|
||||
|
||||
public static CSharpConsole Instance { get; private set; }
|
||||
|
||||
public ScriptEvaluator Evaluator;
|
||||
internal StringBuilder m_evalLogBuilder;
|
||||
|
||||
public static List<string> UsingDirectives;
|
||||
|
||||
public static readonly string[] DefaultUsing = new string[]
|
||||
{
|
||||
"System",
|
||||
"System.Linq",
|
||||
"System.Collections",
|
||||
"System.Collections.Generic",
|
||||
"System.Reflection",
|
||||
"UnityEngine",
|
||||
#if CPP
|
||||
"UnhollowerBaseLib",
|
||||
"UnhollowerRuntimeLib",
|
||||
#endif
|
||||
};
|
||||
|
||||
public override bool Init()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
try
|
||||
{
|
||||
InitConsole();
|
||||
|
||||
AutoCompleter.Init();
|
||||
#if MONO
|
||||
DummyBehaviour.Setup();
|
||||
#endif
|
||||
|
||||
ResetConsole(false);
|
||||
// Make sure compiler is supported on this platform
|
||||
Evaluator.Compile("");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string info = "The C# Console has been disabled because";
|
||||
if (e is NotSupportedException && e.TargetSite?.Name == "DefineDynamicAssembly")
|
||||
info += " Reflection.Emit is not supported.";
|
||||
else
|
||||
info += $" of an unknown error.\r\n({e.ReflectionExToString()})";
|
||||
|
||||
ExplorerCore.LogWarning(info);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetConsole(bool log = true)
|
||||
{
|
||||
if (Evaluator != null)
|
||||
Evaluator.Dispose();
|
||||
|
||||
m_evalLogBuilder = new StringBuilder();
|
||||
|
||||
Evaluator = new ScriptEvaluator(new StringWriter(m_evalLogBuilder)) { InteractiveBaseClass = typeof(ScriptInteraction) };
|
||||
|
||||
UsingDirectives = new List<string>();
|
||||
|
||||
foreach (string use in DefaultUsing)
|
||||
AddUsing(use);
|
||||
|
||||
if (log)
|
||||
ExplorerCore.Log($"C# Console reset. Using directives:\r\n{Evaluator.GetUsing()}");
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateConsole();
|
||||
|
||||
AutoCompleter.Update();
|
||||
#if CPP
|
||||
Il2CppCoroutine.Process();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void AddUsing(string asm)
|
||||
{
|
||||
if (!UsingDirectives.Contains(asm))
|
||||
{
|
||||
Evaluate($"using {asm};", true);
|
||||
UsingDirectives.Add(asm);
|
||||
}
|
||||
}
|
||||
|
||||
public void Evaluate(string code, bool supressLog = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
Evaluator.Run(code);
|
||||
|
||||
string output = ScriptEvaluator._textWriter.ToString();
|
||||
var outputSplit = output.Split('\n');
|
||||
if (outputSplit.Length >= 2)
|
||||
output = outputSplit[outputSplit.Length - 2];
|
||||
m_evalLogBuilder.Clear();
|
||||
|
||||
if (ScriptEvaluator._reportPrinter.ErrorsCount > 0)
|
||||
throw new FormatException($"Unable to compile the code. Evaluator's last output was:\r\n{output}");
|
||||
|
||||
if (!supressLog)
|
||||
ExplorerCore.Log("Code executed successfully.");
|
||||
}
|
||||
catch (FormatException fex)
|
||||
{
|
||||
if (!supressLog)
|
||||
ExplorerCore.LogWarning(fex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!supressLog)
|
||||
ExplorerCore.LogWarning(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// =================================================================================================
|
||||
|
||||
// UI stuff
|
||||
|
||||
public InputField InputField { get; internal set; }
|
||||
public Text InputText { get; internal set; }
|
||||
public int CurrentIndent { get; private set; }
|
||||
@ -31,8 +160,7 @@ namespace UnityExplorer.CSConsole
|
||||
public string HighlightedText => inputHighlightText.text;
|
||||
private Text inputHighlightText;
|
||||
|
||||
private readonly CSharpLexer highlightLexer;
|
||||
//private readonly StringBuilder sbHighlight;
|
||||
private CSLexerHighlighter highlightLexer;
|
||||
|
||||
internal int m_lastCaretPos;
|
||||
internal int m_fixCaretPos;
|
||||
@ -51,6 +179,8 @@ The following helper methods are available:
|
||||
|
||||
* <color=#add490>Log(""message"")</color> logs a message to the debug console
|
||||
|
||||
* <color=#add490>StartCoroutine(IEnumerator routine)</color> start the IEnumerator as a UnityEngine.Coroutine
|
||||
|
||||
* <color=#add490>CurrentTarget()</color> returns the currently inspected target on the Home page
|
||||
|
||||
* <color=#add490>AllTargets()</color> returns an object[] array containing all inspected instances
|
||||
@ -66,9 +196,9 @@ The following helper methods are available:
|
||||
* <color=#add490>Reset()</color> resets all using directives and variables
|
||||
";
|
||||
|
||||
public CodeEditor()
|
||||
public void InitConsole()
|
||||
{
|
||||
highlightLexer = new CSharpLexer();
|
||||
highlightLexer = new CSLexerHighlighter();
|
||||
|
||||
ConstructUI();
|
||||
|
||||
@ -81,7 +211,7 @@ The following helper methods are available:
|
||||
&& InputManager.GetKeyDown(KeyCode.V);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
public void UpdateConsole()
|
||||
{
|
||||
if (s_copyPasteBuffer != null)
|
||||
{
|
||||
@ -101,7 +231,7 @@ The following helper methods are available:
|
||||
var text = InputField.text.Trim();
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
CSConsolePage.Instance.Evaluate(text);
|
||||
Evaluate(text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -121,7 +251,7 @@ The following helper methods are available:
|
||||
if (!m_fixwanted)
|
||||
{
|
||||
EventSystem.current.SetSelectedGameObject(InputField.gameObject, null);
|
||||
m_fixwanted = true;
|
||||
m_fixwanted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -175,14 +305,16 @@ The following helper methods are available:
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateIndent(newText);
|
||||
if (EnableAutoIndent)
|
||||
UpdateIndent(newText);
|
||||
|
||||
if (!forceUpdate && string.IsNullOrEmpty(newText))
|
||||
inputHighlightText.text = string.Empty;
|
||||
else
|
||||
inputHighlightText.text = SyntaxHighlightContent(newText);
|
||||
|
||||
UpdateAutocompletes();
|
||||
if (EnableAutocompletes)
|
||||
UpdateAutocompletes();
|
||||
}
|
||||
|
||||
private void UpdateIndent(string newText)
|
||||
@ -209,9 +341,9 @@ The following helper methods are available:
|
||||
|
||||
if (character == '"')
|
||||
stringState = !stringState;
|
||||
else if (!stringState && character == CSharpLexer.indentOpen)
|
||||
else if (!stringState && character == CSLexerHighlighter.indentOpen)
|
||||
CurrentIndent++;
|
||||
else if (!stringState && character == CSharpLexer.indentClose)
|
||||
else if (!stringState && character == CSLexerHighlighter.indentClose)
|
||||
CurrentIndent--;
|
||||
}
|
||||
|
||||
@ -278,8 +410,8 @@ The following helper methods are available:
|
||||
}
|
||||
|
||||
// check if should add auto-close }
|
||||
int numOpen = InputField.text.Where(x => x == CSharpLexer.indentOpen).Count();
|
||||
int numClose = InputField.text.Where(x => x == CSharpLexer.indentClose).Count();
|
||||
int numOpen = InputField.text.Where(x => x == CSLexerHighlighter.indentOpen).Count();
|
||||
int numClose = InputField.text.Where(x => x == CSLexerHighlighter.indentClose).Count();
|
||||
|
||||
if (numOpen > numClose)
|
||||
{
|
||||
@ -324,23 +456,23 @@ The following helper methods are available:
|
||||
|
||||
public void ConstructUI()
|
||||
{
|
||||
CSConsolePage.Instance.Content = UIFactory.CreateUIObject("C# Console", MainMenu.Instance.PageViewport);
|
||||
Content = UIFactory.CreateUIObject("C# Console", MainMenu.Instance.PageViewport);
|
||||
|
||||
var mainLayout = CSConsolePage.Instance.Content.AddComponent<LayoutElement>();
|
||||
var mainLayout = Content.AddComponent<LayoutElement>();
|
||||
mainLayout.preferredHeight = 500;
|
||||
mainLayout.flexibleHeight = 9000;
|
||||
|
||||
var mainGroup = CSConsolePage.Instance.Content.AddComponent<VerticalLayoutGroup>();
|
||||
var mainGroup = Content.AddComponent<VerticalLayoutGroup>();
|
||||
mainGroup.childControlHeight = true;
|
||||
mainGroup.childControlWidth = true;
|
||||
mainGroup.childForceExpandHeight = true;
|
||||
mainGroup.childForceExpandWidth = true;
|
||||
|
||||
#region TOP BAR
|
||||
#region TOP BAR
|
||||
|
||||
// Main group object
|
||||
|
||||
var topBarObj = UIFactory.CreateHorizontalGroup(CSConsolePage.Instance.Content);
|
||||
var topBarObj = UIFactory.CreateHorizontalGroup(Content);
|
||||
LayoutElement topBarLayout = topBarObj.AddComponent<LayoutElement>();
|
||||
topBarLayout.minHeight = 50;
|
||||
topBarLayout.flexibleHeight = 0;
|
||||
@ -412,13 +544,13 @@ The following helper methods are available:
|
||||
autoIndentLayout.flexibleWidth = 0;
|
||||
autoIndentLayout.minHeight = 25;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region CONSOLE INPUT
|
||||
#region CONSOLE INPUT
|
||||
|
||||
int fontSize = 16;
|
||||
|
||||
var inputObj = UIFactory.CreateSrollInputField(CSConsolePage.Instance.Content, out InputFieldScroller consoleScroll, fontSize);
|
||||
var inputObj = UIFactory.CreateSrollInputField(Content, out InputFieldScroller consoleScroll, fontSize);
|
||||
|
||||
var inputField = consoleScroll.inputField;
|
||||
|
||||
@ -445,9 +577,38 @@ The following helper methods are available:
|
||||
|
||||
#endregion
|
||||
|
||||
#region COMPILE BUTTON
|
||||
#region COMPILE BUTTON BAR
|
||||
|
||||
var compileBtnObj = UIFactory.CreateButton(CSConsolePage.Instance.Content);
|
||||
var horozGroupObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
|
||||
var horozGroup = horozGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
horozGroup.padding.left = 2;
|
||||
horozGroup.padding.top = 2;
|
||||
horozGroup.padding.right = 2;
|
||||
horozGroup.padding.bottom = 2;
|
||||
|
||||
var resetBtnObj = UIFactory.CreateButton(horozGroupObj);
|
||||
var resetBtnLayout = resetBtnObj.AddComponent<LayoutElement>();
|
||||
resetBtnLayout.preferredWidth = 80;
|
||||
resetBtnLayout.flexibleWidth = 0;
|
||||
resetBtnLayout.minHeight = 45;
|
||||
resetBtnLayout.flexibleHeight = 0;
|
||||
var resetButton = resetBtnObj.GetComponent<Button>();
|
||||
var resetBtnColors = resetButton.colors;
|
||||
resetBtnColors.normalColor = "666666".ToColor();
|
||||
resetButton.colors = resetBtnColors;
|
||||
var resetBtnText = resetBtnObj.GetComponentInChildren<Text>();
|
||||
resetBtnText.text = "Reset";
|
||||
resetBtnText.fontSize = 18;
|
||||
resetBtnText.color = Color.white;
|
||||
|
||||
// Set compile button callback now that we have the Input Field reference
|
||||
resetButton.onClick.AddListener(ResetCallback);
|
||||
void ResetCallback()
|
||||
{
|
||||
ResetConsole();
|
||||
}
|
||||
|
||||
var compileBtnObj = UIFactory.CreateButton(horozGroupObj);
|
||||
var compileBtnLayout = compileBtnObj.AddComponent<LayoutElement>();
|
||||
compileBtnLayout.preferredWidth = 80;
|
||||
compileBtnLayout.flexibleWidth = 0;
|
||||
@ -468,7 +629,7 @@ The following helper methods are available:
|
||||
{
|
||||
if (!string.IsNullOrEmpty(inputField.text))
|
||||
{
|
||||
CSConsolePage.Instance.Evaluate(inputField.text.Trim());
|
||||
Evaluate(inputField.text.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,5 +654,15 @@ The following helper methods are available:
|
||||
this.InputText = mainTextInput;
|
||||
this.inputHighlightText = highlightTextInput;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ================================================================================================
|
||||
|
||||
private class VoidType
|
||||
{
|
||||
public static readonly VoidType Value = new VoidType();
|
||||
private VoidType() { }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.CSConsole.Lexer
|
||||
namespace UnityExplorer.UI.Main.CSConsole.Lexer
|
||||
{
|
||||
public class CommentMatch : Matcher
|
||||
{
|
||||
@ -12,9 +12,9 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
public override Color HighlightColor => new Color(0.34f, 0.65f, 0.29f, 1.0f);
|
||||
public override IEnumerable<char> StartChars => new char[] { lineCommentStart[0], blockCommentStart[0] };
|
||||
public override IEnumerable<char> EndChars => new char[] { blockCommentEnd[0] };
|
||||
public override bool IsImplicitMatch(CSharpLexer lexer) => IsMatch(lexer, lineCommentStart) || IsMatch(lexer, blockCommentStart);
|
||||
public override bool IsImplicitMatch(CSLexerHighlighter lexer) => IsMatch(lexer, lineCommentStart) || IsMatch(lexer, blockCommentStart);
|
||||
|
||||
private bool IsMatch(CSharpLexer lexer, string commentType)
|
||||
private bool IsMatch(CSLexerHighlighter lexer, string commentType)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(commentType))
|
||||
{
|
||||
@ -41,6 +41,6 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsEndLineOrEndFile(CSharpLexer lexer, char character) => lexer.EndOfStream || character == '\n' || character == '\r';
|
||||
private bool IsEndLineOrEndFile(CSLexerHighlighter lexer, char character) => lexer.EndOfStream || character == '\n' || character == '\r';
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.CSConsole.Lexer
|
||||
namespace UnityExplorer.UI.Main.CSConsole.Lexer
|
||||
{
|
||||
// I use two different KeywordMatch instances (valid and invalid).
|
||||
// This class just contains common implementations.
|
||||
@ -15,7 +15,7 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
private readonly HashSet<string> shortlist = new HashSet<string>();
|
||||
private readonly Stack<string> removeList = new Stack<string>();
|
||||
|
||||
public override bool IsImplicitMatch(CSharpLexer lexer)
|
||||
public override bool IsImplicitMatch(CSLexerHighlighter lexer)
|
||||
{
|
||||
if (!char.IsWhiteSpace(lexer.Previous) &&
|
||||
!lexer.IsSpecialSymbol(lexer.Previous, DelimiterType.End))
|
@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Core.Unity;
|
||||
|
||||
namespace UnityExplorer.CSConsole.Lexer
|
||||
namespace UnityExplorer.UI.Main.CSConsole.Lexer
|
||||
{
|
||||
public abstract class Matcher
|
||||
{
|
||||
@ -15,9 +15,9 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
public virtual IEnumerable<char> StartChars => Enumerable.Empty<char>();
|
||||
public virtual IEnumerable<char> EndChars => Enumerable.Empty<char>();
|
||||
|
||||
public abstract bool IsImplicitMatch(CSharpLexer lexer);
|
||||
public abstract bool IsImplicitMatch(CSLexerHighlighter lexer);
|
||||
|
||||
public bool IsMatch(CSharpLexer lexer)
|
||||
public bool IsMatch(CSLexerHighlighter lexer)
|
||||
{
|
||||
if (IsImplicitMatch(lexer))
|
||||
{
|
@ -1,12 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.CSConsole.Lexer
|
||||
namespace UnityExplorer.UI.Main.CSConsole.Lexer
|
||||
{
|
||||
public class NumberMatch : Matcher
|
||||
{
|
||||
public override Color HighlightColor => new Color(0.58f, 0.33f, 0.33f, 1.0f);
|
||||
|
||||
public override bool IsImplicitMatch(CSharpLexer lexer)
|
||||
public override bool IsImplicitMatch(CSLexerHighlighter lexer)
|
||||
{
|
||||
if (!char.IsWhiteSpace(lexer.Previous) &&
|
||||
!lexer.IsSpecialSymbol(lexer.Previous, DelimiterType.End))
|
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.CSConsole.Lexer
|
||||
namespace UnityExplorer.UI.Main.CSConsole.Lexer
|
||||
{
|
||||
public class StringMatch : Matcher
|
||||
{
|
||||
@ -10,7 +10,7 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
public override IEnumerable<char> StartChars => new[] { '"' };
|
||||
public override IEnumerable<char> EndChars => new[] { '"' };
|
||||
|
||||
public override bool IsImplicitMatch(CSharpLexer lexer)
|
||||
public override bool IsImplicitMatch(CSLexerHighlighter lexer)
|
||||
{
|
||||
if (lexer.ReadNext() == '"')
|
||||
{
|
||||
@ -21,6 +21,6 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsClosingQuoteOrEndFile(CSharpLexer lexer, char character) => lexer.EndOfStream || character == '"';
|
||||
private bool IsClosingQuoteOrEndFile(CSLexerHighlighter lexer, char character) => lexer.EndOfStream || character == '"';
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.CSConsole.Lexer
|
||||
namespace UnityExplorer.UI.Main.CSConsole.Lexer
|
||||
{
|
||||
public class SymbolMatch : Matcher
|
||||
{
|
||||
@ -21,7 +21,7 @@ namespace UnityExplorer.CSConsole.Lexer
|
||||
public override IEnumerable<char> StartChars => symbols.Select(s => s[0]);
|
||||
public override IEnumerable<char> EndChars => symbols.Select(s => s[0]);
|
||||
|
||||
public override bool IsImplicitMatch(CSharpLexer lexer)
|
||||
public override bool IsImplicitMatch(CSLexerHighlighter lexer)
|
||||
{
|
||||
if (lexer == null)
|
||||
return false;
|
@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
|
||||
namespace UnityExplorer.UI.Modules
|
||||
namespace UnityExplorer.UI.Main
|
||||
{
|
||||
public class DebugConsole
|
||||
{
|
||||
@ -52,7 +51,7 @@ namespace UnityExplorer.UI.Modules
|
||||
//if (!SaveToDisk)
|
||||
// return;
|
||||
|
||||
var path = ExplorerCore.ExplorerFolder + @"\Logs";
|
||||
var path = ExplorerCore.EXPLORER_FOLDER + @"\Logs";
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
@ -3,17 +3,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Inspectors;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.Modules
|
||||
namespace UnityExplorer.UI.Main
|
||||
{
|
||||
public class HomePage : MainMenu.Page
|
||||
public class HomePage : BaseMenuPage
|
||||
{
|
||||
public override string Name => "Home";
|
||||
|
||||
public static HomePage Instance { get; internal set; }
|
||||
|
||||
public override void Init()
|
||||
public override bool Init()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
@ -24,6 +24,8 @@ namespace UnityExplorer.UI.Modules
|
||||
new InspectorManager();
|
||||
|
||||
SceneExplorer.Instance.Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
@ -1,147 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Inspectors.Reflection;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.UI.Main;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
namespace UnityExplorer.UI.Main.Home
|
||||
{
|
||||
public class InspectorManager
|
||||
public class InspectorManagerUI
|
||||
{
|
||||
public static InspectorManager Instance { get; private set; }
|
||||
|
||||
public InspectorManager()
|
||||
{
|
||||
Instance = this;
|
||||
ConstructInspectorPane();
|
||||
}
|
||||
|
||||
public InspectorBase m_activeInspector;
|
||||
public readonly List<InspectorBase> m_currentInspectors = new List<InspectorBase>();
|
||||
|
||||
public GameObject m_tabBarContent;
|
||||
public GameObject m_inspectorContent;
|
||||
|
||||
public void Update()
|
||||
public void OnSetInspectorTab(InspectorBase inspector)
|
||||
{
|
||||
for (int i = 0; i < m_currentInspectors.Count; i++)
|
||||
{
|
||||
if (i >= m_currentInspectors.Count)
|
||||
break;
|
||||
|
||||
m_currentInspectors[i].Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void Inspect(object obj, CacheObjectBase parentMember = null)
|
||||
{
|
||||
#if CPP
|
||||
obj = obj.Il2CppCast(ReflectionHelpers.GetActualType(obj));
|
||||
#endif
|
||||
UnityEngine.Object unityObj = obj as UnityEngine.Object;
|
||||
|
||||
if (obj.IsNullOrDestroyed(false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// check if currently inspecting this object
|
||||
foreach (InspectorBase tab in m_currentInspectors)
|
||||
{
|
||||
if (ReferenceEquals(obj, tab.Target))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
#if CPP
|
||||
else if (unityObj && tab.Target is UnityEngine.Object uTabObj)
|
||||
{
|
||||
if (unityObj.m_CachedPtr == uTabObj.m_CachedPtr)
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
InspectorBase inspector;
|
||||
if (obj is GameObject go)
|
||||
inspector = new GameObjectInspector(go);
|
||||
else
|
||||
inspector = new InstanceInspector(obj);
|
||||
|
||||
if (inspector is ReflectionInspector ri)
|
||||
ri.ParentMember = parentMember;
|
||||
|
||||
m_currentInspectors.Add(inspector);
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void Inspect(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("The provided type was null!");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var tab in m_currentInspectors.Where(x => x is StaticInspector))
|
||||
{
|
||||
if (ReferenceEquals(tab.Target as Type, type))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var inspector = new StaticInspector(type);
|
||||
|
||||
m_currentInspectors.Add(inspector);
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public void SetInspectorTab(InspectorBase inspector)
|
||||
{
|
||||
MainMenu.Instance.SetPage(HomePage.Instance);
|
||||
|
||||
if (m_activeInspector == inspector)
|
||||
return;
|
||||
|
||||
UnsetInspectorTab();
|
||||
|
||||
m_activeInspector = inspector;
|
||||
inspector.SetActive();
|
||||
|
||||
Color activeColor = new Color(0, 0.25f, 0, 1);
|
||||
ColorBlock colors = inspector.tabButton.colors;
|
||||
ColorBlock colors = inspector.BaseUI.tabButton.colors;
|
||||
colors.normalColor = activeColor;
|
||||
colors.highlightedColor = activeColor;
|
||||
inspector.tabButton.colors = colors;
|
||||
inspector.BaseUI.tabButton.colors = colors;
|
||||
}
|
||||
|
||||
public void UnsetInspectorTab()
|
||||
public void OnUnsetInspectorTab()
|
||||
{
|
||||
if (m_activeInspector == null)
|
||||
return;
|
||||
|
||||
m_activeInspector.SetInactive();
|
||||
|
||||
ColorBlock colors = m_activeInspector.tabButton.colors;
|
||||
ColorBlock colors = InspectorManager.Instance.m_activeInspector.BaseUI.tabButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||
colors.highlightedColor = new Color(0.1f, 0.3f, 0.1f, 1);
|
||||
m_activeInspector.tabButton.colors = colors;
|
||||
|
||||
m_activeInspector = null;
|
||||
InspectorManager.Instance.m_activeInspector.BaseUI.tabButton.colors = colors;
|
||||
}
|
||||
|
||||
#region INSPECTOR PANE
|
||||
|
||||
public void ConstructInspectorPane()
|
||||
{
|
||||
var mainObj = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f));
|
||||
@ -234,11 +123,11 @@ namespace UnityExplorer.Inspectors
|
||||
invisGroup.spacing = 10;
|
||||
|
||||
// inspect under mouse button
|
||||
AddMouseInspectButton(topRowObj, MouseInspector.MouseInspectMode.UI);
|
||||
AddMouseInspectButton(topRowObj, MouseInspector.MouseInspectMode.World);
|
||||
AddMouseInspectButton(topRowObj, InspectUnderMouse.MouseInspectMode.UI);
|
||||
AddMouseInspectButton(topRowObj, InspectUnderMouse.MouseInspectMode.World);
|
||||
}
|
||||
|
||||
private static void AddMouseInspectButton(GameObject topRowObj, MouseInspector.MouseInspectMode mode)
|
||||
private static void AddMouseInspectButton(GameObject topRowObj, InspectUnderMouse.MouseInspectMode mode)
|
||||
{
|
||||
var inspectObj = UIFactory.CreateButton(topRowObj);
|
||||
var inspectLayout = inspectObj.AddComponent<LayoutElement>();
|
||||
@ -249,7 +138,7 @@ namespace UnityExplorer.Inspectors
|
||||
inspectText.text = "Mouse Inspect";
|
||||
inspectText.fontSize = 13;
|
||||
|
||||
if (mode == MouseInspector.MouseInspectMode.UI)
|
||||
if (mode == InspectUnderMouse.MouseInspectMode.UI)
|
||||
inspectText.text += " (UI)";
|
||||
|
||||
var inspectBtn = inspectObj.GetComponent<Button>();
|
||||
@ -261,11 +150,9 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
void OnInspectMouseClicked()
|
||||
{
|
||||
MouseInspector.Mode = mode;
|
||||
MouseInspector.StartInspect();
|
||||
InspectUnderMouse.StartInspect(mode);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public class ChildList
|
||||
{
|
@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Unstrip;
|
||||
//using TMPro;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public class ComponentList
|
||||
{
|
||||
@ -77,7 +77,7 @@ namespace UnityExplorer.Inspectors.GameObjects
|
||||
|
||||
var text = s_compListTexts[i];
|
||||
|
||||
text.text = UISyntaxHighlight.ParseFullSyntax(ReflectionHelpers.GetActualType(comp), true);
|
||||
text.text = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetType(comp), true);
|
||||
|
||||
var toggle = s_compToggles[i];
|
||||
#if CPP
|
@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
//using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public class GameObjectControls
|
||||
{
|
@ -1,33 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.Unstrip;
|
||||
//using TMPro;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Inspectors.GameObjects;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public class GameObjectInspector : InspectorBase
|
||||
public class GameObjectInspectorUI : InspectorBaseUI
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[G]</color> {TargetGO?.name}";
|
||||
|
||||
public static GameObjectInspector ActiveInstance { get; private set; }
|
||||
|
||||
public GameObject TargetGO;
|
||||
|
||||
// sub modules
|
||||
private static ChildList s_childList;
|
||||
private static ComponentList s_compList;
|
||||
private static GameObjectControls s_controls;
|
||||
|
||||
// static UI elements (only constructed once)
|
||||
|
||||
private static bool m_UIConstructed;
|
||||
|
||||
private static GameObject s_content;
|
||||
public override GameObject Content
|
||||
{
|
||||
@ -55,86 +39,23 @@ namespace UnityExplorer.Inspectors
|
||||
private static Text m_sceneText;
|
||||
private static string m_lastScene;
|
||||
|
||||
public GameObjectInspector(GameObject target) : base(target)
|
||||
internal void RefreshTopInfo()
|
||||
{
|
||||
ActiveInstance = this;
|
||||
var target = GameObjectInspector.ActiveInstance.TargetGO;
|
||||
string name = target.name;
|
||||
|
||||
TargetGO = target;
|
||||
|
||||
if (!TargetGO)
|
||||
if (m_lastName != name)
|
||||
{
|
||||
ExplorerCore.LogWarning("Target GameObject is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
// one UI is used for all gameobject inspectors. no point recreating it.
|
||||
if (!m_UIConstructed)
|
||||
{
|
||||
m_UIConstructed = true;
|
||||
|
||||
s_childList = new ChildList();
|
||||
s_compList = new ComponentList();
|
||||
s_controls = new GameObjectControls();
|
||||
|
||||
ConstructUI();
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetActive()
|
||||
{
|
||||
base.SetActive();
|
||||
ActiveInstance = this;
|
||||
}
|
||||
|
||||
public override void SetInactive()
|
||||
{
|
||||
base.SetInactive();
|
||||
ActiveInstance = null;
|
||||
}
|
||||
|
||||
internal void ChangeInspectorTarget(GameObject newTarget)
|
||||
{
|
||||
if (!newTarget)
|
||||
return;
|
||||
|
||||
this.Target = this.TargetGO = newTarget;
|
||||
}
|
||||
|
||||
// Update
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (m_pendingDestroy || !this.IsActive)
|
||||
return;
|
||||
|
||||
RefreshTopInfo();
|
||||
|
||||
s_childList.RefreshChildObjectList();
|
||||
|
||||
s_compList.RefreshComponentList();
|
||||
|
||||
s_controls.RefreshControls();
|
||||
|
||||
if (GameObjectControls.s_sliderChangedWanted)
|
||||
GameObjectControls.UpdateSliderControl();
|
||||
}
|
||||
|
||||
private void RefreshTopInfo()
|
||||
{
|
||||
if (m_lastName != TargetGO.name)
|
||||
{
|
||||
m_lastName = TargetGO.name;
|
||||
m_lastName = name;
|
||||
m_nameInput.text = m_lastName;
|
||||
}
|
||||
|
||||
if (TargetGO.transform.parent)
|
||||
if (target.transform.parent)
|
||||
{
|
||||
if (!m_pathGroupObj.activeSelf)
|
||||
m_pathGroupObj.SetActive(true);
|
||||
|
||||
var path = TargetGO.transform.GetTransformPath(true);
|
||||
var path = target.transform.GetTransformPath(true);
|
||||
if (m_lastPath != path)
|
||||
{
|
||||
m_lastPath = path;
|
||||
@ -149,26 +70,26 @@ namespace UnityExplorer.Inspectors
|
||||
else if (m_pathGroupObj.activeSelf)
|
||||
m_pathGroupObj.SetActive(false);
|
||||
|
||||
if (m_lastEnabledState != TargetGO.activeSelf)
|
||||
if (m_lastEnabledState != target.activeSelf)
|
||||
{
|
||||
m_lastEnabledState = TargetGO.activeSelf;
|
||||
m_lastEnabledState = target.activeSelf;
|
||||
|
||||
m_enabledToggle.isOn = TargetGO.activeSelf;
|
||||
m_enabledText.text = TargetGO.activeSelf ? "Enabled" : "Disabled";
|
||||
m_enabledText.color = TargetGO.activeSelf ? Color.green : Color.red;
|
||||
m_enabledToggle.isOn = target.activeSelf;
|
||||
m_enabledText.text = target.activeSelf ? "Enabled" : "Disabled";
|
||||
m_enabledText.color = target.activeSelf ? Color.green : Color.red;
|
||||
}
|
||||
|
||||
if (m_lastLayer != TargetGO.layer)
|
||||
if (m_lastLayer != target.layer)
|
||||
{
|
||||
m_lastLayer = TargetGO.layer;
|
||||
m_layerDropdown.value = TargetGO.layer;
|
||||
m_lastLayer = target.layer;
|
||||
m_layerDropdown.value = target.layer;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(m_lastScene) || m_lastScene != TargetGO.scene.name)
|
||||
if (string.IsNullOrEmpty(m_lastScene) || m_lastScene != target.scene.name)
|
||||
{
|
||||
m_lastScene = TargetGO.scene.name;
|
||||
m_lastScene = target.scene.name;
|
||||
|
||||
if (!string.IsNullOrEmpty(TargetGO.scene.name))
|
||||
if (!string.IsNullOrEmpty(target.scene.name))
|
||||
m_sceneText.text = m_lastScene;
|
||||
else
|
||||
m_sceneText.text = "None (Asset/Resource)";
|
||||
@ -179,41 +100,42 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
private static void OnApplyNameClicked()
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
if (GameObjectInspector.ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.TargetGO.name = m_nameInput.text;
|
||||
GameObjectInspector.ActiveInstance.TargetGO.name = m_nameInput.text;
|
||||
}
|
||||
|
||||
private static void OnEnableToggled(bool enabled)
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
if (GameObjectInspector.ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.TargetGO.SetActive(enabled);
|
||||
GameObjectInspector.ActiveInstance.TargetGO.SetActive(enabled);
|
||||
}
|
||||
|
||||
private static void OnLayerSelected(int layer)
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
if (GameObjectInspector.ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.TargetGO.layer = layer;
|
||||
GameObjectInspector.ActiveInstance.TargetGO.layer = layer;
|
||||
}
|
||||
|
||||
internal static void OnBackButtonClicked()
|
||||
{
|
||||
if (ActiveInstance == null)
|
||||
if (GameObjectInspector.ActiveInstance == null)
|
||||
return;
|
||||
|
||||
ActiveInstance.ChangeInspectorTarget(ActiveInstance.TargetGO.transform.parent.gameObject);
|
||||
GameObjectInspector.ActiveInstance.ChangeInspectorTarget(
|
||||
GameObjectInspector.ActiveInstance.TargetGO.transform.parent.gameObject);
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
private void ConstructUI()
|
||||
internal void ConstructUI()
|
||||
{
|
||||
var parent = InspectorManager.Instance.m_inspectorContent;
|
||||
var parent = InspectorManager.UI.m_inspectorContent;
|
||||
|
||||
s_content = UIFactory.CreateScrollView(parent, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
|
||||
|
||||
@ -234,12 +156,12 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
ConstructTopArea(scrollContent);
|
||||
|
||||
s_controls.ConstructControls(scrollContent);
|
||||
GameObjectInspector.s_controls.ConstructControls(scrollContent);
|
||||
|
||||
var midGroupObj = ConstructMidGroup(scrollContent);
|
||||
|
||||
s_childList.ConstructChildList(midGroupObj);
|
||||
s_compList.ConstructCompList(midGroupObj);
|
||||
GameObjectInspector.s_childList.ConstructChildList(midGroupObj);
|
||||
GameObjectInspector.s_compList.ConstructCompList(midGroupObj);
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(s_content.GetComponent<RectTransform>());
|
||||
Canvas.ForceUpdateCanvases();
|
||||
@ -301,7 +223,7 @@ namespace UnityExplorer.Inspectors
|
||||
var pathInputRect = pathInputObj.GetComponent<RectTransform>();
|
||||
pathInputRect.sizeDelta = new Vector2(pathInputRect.sizeDelta.x, 25);
|
||||
m_pathInput = pathInputObj.GetComponent<InputField>();
|
||||
m_pathInput.text = TargetGO.transform.GetTransformPath();
|
||||
m_pathInput.text = GameObjectInspector.ActiveInstance.TargetGO.transform.GetTransformPath();
|
||||
m_pathInput.readOnly = true;
|
||||
m_pathInput.lineType = InputField.LineType.MultiLineNewline;
|
||||
var pathInputLayout = pathInputObj.AddComponent<LayoutElement>();
|
||||
@ -348,7 +270,7 @@ namespace UnityExplorer.Inspectors
|
||||
var nameInputRect = nameInputObj.GetComponent<RectTransform>();
|
||||
nameInputRect.sizeDelta = new Vector2(nameInputRect.sizeDelta.x, 25);
|
||||
m_nameInput = nameInputObj.GetComponent<InputField>();
|
||||
m_nameInput.text = TargetGO.name;
|
||||
m_nameInput.text = GameObjectInspector.ActiveInstance.TargetGO.name;
|
||||
|
||||
var applyNameBtnObj = UIFactory.CreateButton(nameRowObj);
|
||||
var applyNameBtn = applyNameBtnObj.GetComponent<Button>();
|
||||
@ -405,7 +327,7 @@ namespace UnityExplorer.Inspectors
|
||||
m_layerDropdown.options.Clear();
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
var layer = LayerMaskUnstrip.LayerToName(i);
|
||||
var layer = RuntimeProvider.Instance.LayerToName(i);
|
||||
m_layerDropdown.options.Add(new Dropdown.OptionData { text = $"{i}: {layer}" });
|
||||
}
|
||||
//var itemText = layerDropdownObj.transform.Find("Label").GetComponent<Text>();
|
||||
@ -451,6 +373,6 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
return midGroupObj;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
61
src/UI/Main/Home/Inspectors/InspectorBaseUI.cs
Normal file
61
src/UI/Main/Home/Inspectors/InspectorBaseUI.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public abstract class InspectorBaseUI
|
||||
{
|
||||
public abstract GameObject Content { get; set; }
|
||||
public Button tabButton;
|
||||
public Text tabText;
|
||||
|
||||
public void AddInspectorTab(InspectorBase parent)
|
||||
{
|
||||
var tabContent = InspectorManager.UI.m_tabBarContent;
|
||||
|
||||
var tabGroupObj = UIFactory.CreateHorizontalGroup(tabContent);
|
||||
var tabGroup = tabGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
tabGroup.childForceExpandWidth = true;
|
||||
tabGroup.childControlWidth = true;
|
||||
var tabLayout = tabGroupObj.AddComponent<LayoutElement>();
|
||||
tabLayout.minWidth = 185;
|
||||
tabLayout.flexibleWidth = 0;
|
||||
tabGroupObj.AddComponent<Mask>();
|
||||
|
||||
var targetButtonObj = UIFactory.CreateButton(tabGroupObj);
|
||||
targetButtonObj.AddComponent<Mask>();
|
||||
var targetButtonLayout = targetButtonObj.AddComponent<LayoutElement>();
|
||||
targetButtonLayout.minWidth = 165;
|
||||
targetButtonLayout.flexibleWidth = 0;
|
||||
|
||||
tabText = targetButtonObj.GetComponentInChildren<Text>();
|
||||
tabText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
tabText.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
tabButton = targetButtonObj.GetComponent<Button>();
|
||||
|
||||
tabButton.onClick.AddListener(() => { InspectorManager.Instance.SetInspectorTab(parent); });
|
||||
|
||||
var closeBtnObj = UIFactory.CreateButton(tabGroupObj);
|
||||
var closeBtnLayout = closeBtnObj.AddComponent<LayoutElement>();
|
||||
closeBtnLayout.minWidth = 20;
|
||||
closeBtnLayout.flexibleWidth = 0;
|
||||
var closeBtnText = closeBtnObj.GetComponentInChildren<Text>();
|
||||
closeBtnText.text = "X";
|
||||
closeBtnText.color = new Color(1, 0, 0, 1);
|
||||
|
||||
var closeBtn = closeBtnObj.GetComponent<Button>();
|
||||
|
||||
closeBtn.onClick.AddListener(parent.Destroy);
|
||||
|
||||
var closeColors = closeBtn.colors;
|
||||
closeColors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||
closeBtn.colors = closeColors;
|
||||
}
|
||||
}
|
||||
}
|
69
src/UI/Main/Home/Inspectors/MouseInspectorUI.cs
Normal file
69
src/UI/Main/Home/Inspectors/MouseInspectorUI.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public class MouseInspectorUI
|
||||
{
|
||||
internal Text s_objNameLabel;
|
||||
internal Text s_objPathLabel;
|
||||
internal Text s_mousePosLabel;
|
||||
internal GameObject s_UIContent;
|
||||
|
||||
public MouseInspectorUI()
|
||||
{
|
||||
ConstructUI();
|
||||
}
|
||||
|
||||
#region UI Construction
|
||||
|
||||
internal void ConstructUI()
|
||||
{
|
||||
s_UIContent = UIFactory.CreatePanel(UIManager.CanvasRoot, "MouseInspect", out GameObject content);
|
||||
|
||||
s_UIContent.AddComponent<Mask>();
|
||||
|
||||
var baseRect = s_UIContent.GetComponent<RectTransform>();
|
||||
var half = new Vector2(0.5f, 0.5f);
|
||||
baseRect.anchorMin = half;
|
||||
baseRect.anchorMax = half;
|
||||
baseRect.pivot = half;
|
||||
baseRect.sizeDelta = new Vector2(700, 150);
|
||||
|
||||
var group = content.GetComponent<VerticalLayoutGroup>();
|
||||
group.childForceExpandHeight = true;
|
||||
|
||||
// Title text
|
||||
|
||||
var titleObj = UIFactory.CreateLabel(content, TextAnchor.MiddleCenter);
|
||||
var titleText = titleObj.GetComponent<Text>();
|
||||
titleText.text = "<b>Mouse Inspector</b> (press <b>ESC</b> to cancel)";
|
||||
|
||||
var mousePosObj = UIFactory.CreateLabel(content, TextAnchor.MiddleCenter);
|
||||
s_mousePosLabel = mousePosObj.GetComponent<Text>();
|
||||
s_mousePosLabel.text = "Mouse Position:";
|
||||
|
||||
var hitLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||
s_objNameLabel = hitLabelObj.GetComponent<Text>();
|
||||
s_objNameLabel.text = "No hits...";
|
||||
s_objNameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
|
||||
var pathLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||
s_objPathLabel = pathLabelObj.GetComponent<Text>();
|
||||
s_objPathLabel.fontStyle = FontStyle.Italic;
|
||||
s_objPathLabel.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
|
||||
var pathLayout = pathLabelObj.AddComponent<LayoutElement>();
|
||||
pathLayout.minHeight = 75;
|
||||
pathLayout.flexibleHeight = 0;
|
||||
|
||||
s_UIContent.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,56 +1,31 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Unstrip;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.Core.Inspectors.Reflection;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public enum MemberScopes
|
||||
public class InstanceInspectorUI
|
||||
{
|
||||
All,
|
||||
Instance,
|
||||
Static
|
||||
}
|
||||
|
||||
public class InstanceInspector : ReflectionInspector
|
||||
{
|
||||
public override string TabLabel => $" <color=cyan>[R]</color> {base.TabLabel}";
|
||||
|
||||
internal MemberScopes m_scopeFilter;
|
||||
internal Button m_lastActiveScopeButton;
|
||||
|
||||
public InstanceInspector(object target) : base(target) { }
|
||||
|
||||
private void OnScopeFilterClicked(MemberScopes type, Button button)
|
||||
public InstanceInspectorUI(InstanceInspector parent)
|
||||
{
|
||||
if (m_lastActiveScopeButton)
|
||||
{
|
||||
var lastColors = m_lastActiveScopeButton.colors;
|
||||
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
m_lastActiveScopeButton.colors = lastColors;
|
||||
}
|
||||
|
||||
m_scopeFilter = type;
|
||||
m_lastActiveScopeButton = button;
|
||||
|
||||
var colors = m_lastActiveScopeButton.colors;
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_lastActiveScopeButton.colors = colors;
|
||||
|
||||
FilterMembers(null, true);
|
||||
m_sliderScroller.m_slider.value = 1f;
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
internal InstanceInspector Parent;
|
||||
|
||||
public void ConstructInstanceHelpers()
|
||||
{
|
||||
if (!typeof(Component).IsAssignableFrom(m_targetType) && !typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
|
||||
if (!typeof(Component).IsAssignableFrom(Parent.m_targetType) && !typeof(UnityEngine.Object).IsAssignableFrom(Parent.m_targetType))
|
||||
return;
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Parent.ReflectionUI.Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childForceExpandWidth = true;
|
||||
rowGroup.childControlWidth = true;
|
||||
@ -63,16 +38,14 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleWidth = 5000;
|
||||
|
||||
if (typeof(Component).IsAssignableFrom(m_targetType))
|
||||
if (typeof(Component).IsAssignableFrom(Parent.m_targetType))
|
||||
{
|
||||
ConstructCompHelper(rowObj);
|
||||
}
|
||||
|
||||
ConstructUObjHelper(rowObj);
|
||||
|
||||
// WIP
|
||||
|
||||
if (m_targetType == typeof(Texture2D))
|
||||
if (Parent.m_targetType == typeof(Texture2D))
|
||||
ConstructTextureHelper();
|
||||
}
|
||||
|
||||
@ -87,9 +60,9 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
labelText.text = "GameObject:";
|
||||
|
||||
#if MONO
|
||||
var comp = Target as Component;
|
||||
var comp = Parent.Target as Component;
|
||||
#else
|
||||
var comp = (Target as Il2CppSystem.Object).TryCast<Component>();
|
||||
var comp = (Parent.Target as Il2CppSystem.Object).TryCast<Component>();
|
||||
#endif
|
||||
|
||||
var goBtnObj = UIFactory.CreateButton(rowObj, new Color(0.2f, 0.5f, 0.2f));
|
||||
@ -114,9 +87,9 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
labelText.text = "Name:";
|
||||
|
||||
#if MONO
|
||||
var uObj = Target as UnityEngine.Object;
|
||||
var uObj = Parent.Target as UnityEngine.Object;
|
||||
#else
|
||||
var uObj = (Target as Il2CppSystem.Object).TryCast<UnityEngine.Object>();
|
||||
var uObj = (Parent.Target as Il2CppSystem.Object).TryCast<UnityEngine.Object>();
|
||||
#endif
|
||||
|
||||
var inputObj = UIFactory.CreateInputField(rowObj, 14, 3, 1);
|
||||
@ -126,16 +99,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
var inputField = inputObj.GetComponent<InputField>();
|
||||
inputField.readOnly = true;
|
||||
inputField.text = uObj.name;
|
||||
|
||||
//var goBtnObj = UIFactory.CreateButton(rowObj, new Color(0.2f, 0.5f, 0.2f));
|
||||
//var goBtnLayout = goBtnObj.AddComponent<LayoutElement>();
|
||||
//goBtnLayout.minHeight = 25;
|
||||
//goBtnLayout.minWidth = 200;
|
||||
//goBtnLayout.flexibleWidth = 0;
|
||||
//var text = goBtnObj.GetComponentInChildren<Text>();
|
||||
//text.text = comp.name;
|
||||
//var btn = goBtnObj.GetComponent<Button>();
|
||||
//btn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(comp.gameObject); });
|
||||
}
|
||||
|
||||
internal bool showingTextureHelper;
|
||||
@ -145,7 +108,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
internal void ConstructTextureHelper()
|
||||
{
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Parent.ReflectionUI.Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var rowLayout = rowObj.AddComponent<LayoutElement>();
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleHeight = 0;
|
||||
@ -170,7 +133,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
var labelText = labelObj.GetComponent<Text>();
|
||||
labelText.text = "Texture Viewer";
|
||||
|
||||
var textureViewerObj = UIFactory.CreateScrollView(Content, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
|
||||
var textureViewerObj = UIFactory.CreateScrollView(Parent.ReflectionUI.Content, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
|
||||
var viewerGroup = scrollContent.GetComponent<VerticalLayoutGroup>();
|
||||
viewerGroup.childForceExpandHeight = false;
|
||||
viewerGroup.childForceExpandWidth = false;
|
||||
@ -209,10 +172,10 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
constructedTextureViewer = true;
|
||||
|
||||
var tex = Target as Texture2D;
|
||||
var tex = Parent.Target as Texture2D;
|
||||
#if CPP
|
||||
if (!tex)
|
||||
tex = (Target as Il2CppSystem.Object).TryCast<Texture2D>();
|
||||
tex = (Parent.Target as Il2CppSystem.Object).TryCast<Texture2D>();
|
||||
#endif
|
||||
|
||||
if (!tex)
|
||||
@ -251,10 +214,10 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
if (string.IsNullOrEmpty(name))
|
||||
name = "untitled";
|
||||
|
||||
var savePath = $@"{Config.ExplorerConfig.Instance.Default_Output_Path}\{name}.png";
|
||||
var savePath = $@"{Core.Config.ExplorerConfig.Instance.Default_Output_Path}\{name}.png";
|
||||
inputField.text = savePath;
|
||||
|
||||
saveBtn.onClick.AddListener(() =>
|
||||
saveBtn.onClick.AddListener(() =>
|
||||
{
|
||||
if (tex && !string.IsNullOrEmpty(inputField.text))
|
||||
{
|
||||
@ -272,13 +235,10 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
if (!tex.IsReadable())
|
||||
tex = Texture2DHelpers.ForceReadTexture(tex);
|
||||
#if CPP
|
||||
byte[] data = tex.EncodeToPNG();
|
||||
#else
|
||||
byte[] data = tex.EncodeToPNGSafe();
|
||||
#endif
|
||||
if (TextureUtilProvider.IsReadable(tex))
|
||||
tex = TextureUtilProvider.ForceReadTexture(tex);
|
||||
|
||||
byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex);
|
||||
|
||||
File.WriteAllBytes(path, data);
|
||||
}
|
||||
@ -288,7 +248,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
var imageObj = UIFactory.CreateUIObject("TextureViewerImage", parent);
|
||||
var image = imageObj.AddComponent<Image>();
|
||||
var sprite = ImageConversionUnstrip.CreateSprite(tex);
|
||||
var sprite = TextureUtilProvider.Instance.CreateSprite(tex);
|
||||
image.sprite = sprite;
|
||||
|
||||
var fitter = imageObj.AddComponent<ContentSizeFitter>();
|
||||
@ -304,9 +264,9 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
m_textureViewerObj.SetActive(enabled);
|
||||
|
||||
m_filterAreaObj.SetActive(!enabled);
|
||||
m_memberListObj.SetActive(!enabled);
|
||||
m_updateRowObj.SetActive(!enabled);
|
||||
Parent.ReflectionUI.m_filterAreaObj.SetActive(!enabled);
|
||||
Parent.ReflectionUI.m_memberListObj.SetActive(!enabled);
|
||||
Parent.ReflectionUI.m_updateRowObj.SetActive(!enabled);
|
||||
}
|
||||
|
||||
public void ConstructInstanceFilters(GameObject parent)
|
||||
@ -350,7 +310,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
var btn = btnObj.GetComponent<Button>();
|
||||
|
||||
btn.onClick.AddListener(() => { OnScopeFilterClicked(type, btn); });
|
||||
btn.onClick.AddListener(() => { Parent.OnScopeFilterClicked(type, btn); });
|
||||
|
||||
var colors = btn.colors;
|
||||
colors.highlightedColor = new Color(0.3f, 0.7f, 0.3f);
|
||||
@ -358,8 +318,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
if (setEnabled)
|
||||
{
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_scopeFilter = type;
|
||||
m_lastActiveScopeButton = btn;
|
||||
Parent.m_scopeFilter = type;
|
||||
Parent.m_lastActiveScopeButton = btn;
|
||||
}
|
||||
|
||||
btn.colors = colors;
|
288
src/UI/Main/Home/Inspectors/Reflection/ReflectionInspectorUI.cs
Normal file
288
src/UI/Main/Home/Inspectors/Reflection/ReflectionInspectorUI.cs
Normal file
@ -0,0 +1,288 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.Core.Inspectors.Reflection;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
{
|
||||
public class ReflectionInspectorUI : InspectorBaseUI
|
||||
{
|
||||
public ReflectionInspectorUI(ReflectionInspector parent)
|
||||
{
|
||||
this.Parent = parent;
|
||||
}
|
||||
|
||||
public ReflectionInspector Parent;
|
||||
|
||||
// UI members
|
||||
|
||||
private GameObject m_content;
|
||||
public override GameObject Content
|
||||
{
|
||||
get => m_content;
|
||||
set => m_content = value;
|
||||
}
|
||||
|
||||
internal Text m_nameFilterText;
|
||||
internal MemberTypes m_memberFilter;
|
||||
internal Button m_lastActiveMemButton;
|
||||
|
||||
internal PageHandler m_pageHandler;
|
||||
internal SliderScrollbar m_sliderScroller;
|
||||
internal GameObject m_scrollContent;
|
||||
internal RectTransform m_scrollContentRect;
|
||||
|
||||
internal bool m_widthUpdateWanted;
|
||||
internal bool m_widthUpdateWaiting;
|
||||
|
||||
internal GameObject m_filterAreaObj;
|
||||
internal GameObject m_updateRowObj;
|
||||
internal GameObject m_memberListObj;
|
||||
|
||||
internal void ConstructUI()
|
||||
{
|
||||
var parent = InspectorManager.UI.m_inspectorContent;
|
||||
this.Content = UIFactory.CreateVerticalGroup(parent, new Color(0.15f, 0.15f, 0.15f));
|
||||
var mainGroup = Content.GetComponent<VerticalLayoutGroup>();
|
||||
mainGroup.childForceExpandHeight = false;
|
||||
mainGroup.childForceExpandWidth = true;
|
||||
mainGroup.childControlHeight = true;
|
||||
mainGroup.childControlWidth = true;
|
||||
mainGroup.spacing = 5;
|
||||
mainGroup.padding.top = 4;
|
||||
mainGroup.padding.left = 4;
|
||||
mainGroup.padding.right = 4;
|
||||
mainGroup.padding.bottom = 4;
|
||||
|
||||
ConstructTopArea();
|
||||
|
||||
ConstructMemberList();
|
||||
}
|
||||
|
||||
internal void ConstructTopArea()
|
||||
{
|
||||
var nameRowObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
|
||||
var nameRow = nameRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
nameRow.childForceExpandWidth = true;
|
||||
nameRow.childForceExpandHeight = true;
|
||||
nameRow.childControlHeight = true;
|
||||
nameRow.childControlWidth = true;
|
||||
nameRow.padding.top = 2;
|
||||
var nameRowLayout = nameRowObj.AddComponent<LayoutElement>();
|
||||
nameRowLayout.minHeight = 25;
|
||||
nameRowLayout.flexibleHeight = 0;
|
||||
nameRowLayout.minWidth = 200;
|
||||
nameRowLayout.flexibleWidth = 5000;
|
||||
|
||||
var typeLabel = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleLeft);
|
||||
var typeLabelText = typeLabel.GetComponent<Text>();
|
||||
typeLabelText.text = "Type:";
|
||||
typeLabelText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
var typeLabelTextLayout = typeLabel.AddComponent<LayoutElement>();
|
||||
typeLabelTextLayout.minWidth = 40;
|
||||
typeLabelTextLayout.flexibleWidth = 0;
|
||||
typeLabelTextLayout.minHeight = 25;
|
||||
|
||||
var typeDisplayObj = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleLeft);
|
||||
var typeDisplayText = typeDisplayObj.GetComponent<Text>();
|
||||
typeDisplayText.text = SignatureHighlighter.ParseFullSyntax(Parent.m_targetType, true);
|
||||
var typeDisplayLayout = typeDisplayObj.AddComponent<LayoutElement>();
|
||||
typeDisplayLayout.minHeight = 25;
|
||||
typeDisplayLayout.flexibleWidth = 5000;
|
||||
|
||||
// instance helper tools
|
||||
|
||||
if (Parent is InstanceInspector instanceInspector)
|
||||
{
|
||||
instanceInspector.CreateInstanceUIModule();
|
||||
instanceInspector.InstanceUI.ConstructInstanceHelpers();
|
||||
}
|
||||
|
||||
ConstructFilterArea();
|
||||
|
||||
ConstructUpdateRow();
|
||||
}
|
||||
|
||||
internal void ConstructFilterArea()
|
||||
{
|
||||
// Filters
|
||||
|
||||
var filterAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var filterLayout = filterAreaObj.AddComponent<LayoutElement>();
|
||||
filterLayout.minHeight = 60;
|
||||
var filterGroup = filterAreaObj.GetComponent<VerticalLayoutGroup>();
|
||||
filterGroup.childForceExpandWidth = true;
|
||||
filterGroup.childForceExpandHeight = true;
|
||||
filterGroup.childControlWidth = true;
|
||||
filterGroup.childControlHeight = true;
|
||||
filterGroup.spacing = 4;
|
||||
filterGroup.padding.left = 4;
|
||||
filterGroup.padding.right = 4;
|
||||
filterGroup.padding.top = 4;
|
||||
filterGroup.padding.bottom = 4;
|
||||
|
||||
m_filterAreaObj = filterAreaObj;
|
||||
|
||||
// name filter
|
||||
|
||||
var nameFilterRowObj = UIFactory.CreateHorizontalGroup(filterAreaObj, new Color(1, 1, 1, 0));
|
||||
var nameFilterGroup = nameFilterRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
nameFilterGroup.childForceExpandHeight = false;
|
||||
nameFilterGroup.childForceExpandWidth = false;
|
||||
nameFilterGroup.childControlWidth = true;
|
||||
nameFilterGroup.childControlHeight = true;
|
||||
nameFilterGroup.spacing = 5;
|
||||
var nameFilterLayout = nameFilterRowObj.AddComponent<LayoutElement>();
|
||||
nameFilterLayout.minHeight = 25;
|
||||
nameFilterLayout.flexibleHeight = 0;
|
||||
nameFilterLayout.flexibleWidth = 5000;
|
||||
|
||||
var nameLabelObj = UIFactory.CreateLabel(nameFilterRowObj, TextAnchor.MiddleLeft);
|
||||
var nameLabelLayout = nameLabelObj.AddComponent<LayoutElement>();
|
||||
nameLabelLayout.minWidth = 100;
|
||||
nameLabelLayout.minHeight = 25;
|
||||
nameLabelLayout.flexibleWidth = 0;
|
||||
var nameLabelText = nameLabelObj.GetComponent<Text>();
|
||||
nameLabelText.text = "Filter names:";
|
||||
nameLabelText.color = Color.grey;
|
||||
|
||||
var nameInputObj = UIFactory.CreateInputField(nameFilterRowObj, 14, (int)TextAnchor.MiddleLeft, (int)HorizontalWrapMode.Overflow);
|
||||
var nameInputLayout = nameInputObj.AddComponent<LayoutElement>();
|
||||
nameInputLayout.flexibleWidth = 5000;
|
||||
nameInputLayout.minWidth = 100;
|
||||
nameInputLayout.minHeight = 25;
|
||||
var nameInput = nameInputObj.GetComponent<InputField>();
|
||||
nameInput.onValueChanged.AddListener((string val) => { Parent.FilterMembers(val); });
|
||||
m_nameFilterText = nameInput.textComponent;
|
||||
|
||||
// membertype filter
|
||||
|
||||
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(filterAreaObj, new Color(1, 1, 1, 0));
|
||||
var memFilterGroup = memberFilterRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
memFilterGroup.childForceExpandHeight = false;
|
||||
memFilterGroup.childForceExpandWidth = false;
|
||||
memFilterGroup.childControlWidth = true;
|
||||
memFilterGroup.childControlHeight = true;
|
||||
memFilterGroup.spacing = 5;
|
||||
var memFilterLayout = memberFilterRowObj.AddComponent<LayoutElement>();
|
||||
memFilterLayout.minHeight = 25;
|
||||
memFilterLayout.flexibleHeight = 0;
|
||||
memFilterLayout.flexibleWidth = 5000;
|
||||
|
||||
var memLabelObj = UIFactory.CreateLabel(memberFilterRowObj, TextAnchor.MiddleLeft);
|
||||
var memLabelLayout = memLabelObj.AddComponent<LayoutElement>();
|
||||
memLabelLayout.minWidth = 100;
|
||||
memLabelLayout.minHeight = 25;
|
||||
memLabelLayout.flexibleWidth = 0;
|
||||
var memLabelText = memLabelObj.GetComponent<Text>();
|
||||
memLabelText.text = "Filter members:";
|
||||
memLabelText.color = Color.grey;
|
||||
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.All);
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.Method);
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.Property, true);
|
||||
AddFilterButton(memberFilterRowObj, MemberTypes.Field);
|
||||
|
||||
// Instance filters
|
||||
|
||||
if (Parent is InstanceInspector instanceInspector)
|
||||
{
|
||||
instanceInspector.InstanceUI.ConstructInstanceFilters(filterAreaObj);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddFilterButton(GameObject parent, MemberTypes type, bool setEnabled = false)
|
||||
{
|
||||
var btnObj = UIFactory.CreateButton(parent, new Color(0.2f, 0.2f, 0.2f));
|
||||
|
||||
var btnLayout = btnObj.AddComponent<LayoutElement>();
|
||||
btnLayout.minHeight = 25;
|
||||
btnLayout.minWidth = 70;
|
||||
|
||||
var text = btnObj.GetComponentInChildren<Text>();
|
||||
text.text = type.ToString();
|
||||
|
||||
var btn = btnObj.GetComponent<Button>();
|
||||
|
||||
btn.onClick.AddListener(() => { Parent.OnMemberFilterClicked(type, btn); });
|
||||
|
||||
var colors = btn.colors;
|
||||
colors.highlightedColor = new Color(0.3f, 0.7f, 0.3f);
|
||||
|
||||
if (setEnabled)
|
||||
{
|
||||
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
|
||||
m_memberFilter = type;
|
||||
m_lastActiveMemButton = btn;
|
||||
}
|
||||
|
||||
btn.colors = colors;
|
||||
}
|
||||
|
||||
internal void ConstructUpdateRow()
|
||||
{
|
||||
var optionsRowObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
|
||||
var optionsLayout = optionsRowObj.AddComponent<LayoutElement>();
|
||||
optionsLayout.minHeight = 25;
|
||||
var optionsGroup = optionsRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
optionsGroup.childForceExpandHeight = true;
|
||||
optionsGroup.childForceExpandWidth = false;
|
||||
optionsGroup.childAlignment = TextAnchor.MiddleLeft;
|
||||
optionsGroup.spacing = 10;
|
||||
|
||||
m_updateRowObj = optionsRowObj;
|
||||
|
||||
// update button
|
||||
|
||||
var updateButtonObj = UIFactory.CreateButton(optionsRowObj, new Color(0.2f, 0.2f, 0.2f));
|
||||
var updateBtnLayout = updateButtonObj.AddComponent<LayoutElement>();
|
||||
updateBtnLayout.minWidth = 110;
|
||||
updateBtnLayout.flexibleWidth = 0;
|
||||
var updateText = updateButtonObj.GetComponentInChildren<Text>();
|
||||
updateText.text = "Update Values";
|
||||
var updateBtn = updateButtonObj.GetComponent<Button>();
|
||||
updateBtn.onClick.AddListener(() =>
|
||||
{
|
||||
bool orig = Parent.m_autoUpdate;
|
||||
Parent.m_autoUpdate = true;
|
||||
Parent.Update();
|
||||
if (!orig) Parent.m_autoUpdate = orig;
|
||||
});
|
||||
|
||||
// auto update
|
||||
|
||||
var autoUpdateObj = UIFactory.CreateToggle(optionsRowObj, out Toggle autoUpdateToggle, out Text autoUpdateText);
|
||||
var autoUpdateLayout = autoUpdateObj.AddComponent<LayoutElement>();
|
||||
autoUpdateLayout.minWidth = 150;
|
||||
autoUpdateLayout.minHeight = 25;
|
||||
autoUpdateText.text = "Auto-update?";
|
||||
autoUpdateToggle.isOn = false;
|
||||
autoUpdateToggle.onValueChanged.AddListener((bool val) => { Parent.m_autoUpdate = val; });
|
||||
}
|
||||
|
||||
internal void ConstructMemberList()
|
||||
{
|
||||
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.05f, 0.05f, 0.05f));
|
||||
|
||||
m_memberListObj = scrollobj;
|
||||
m_scrollContentRect = m_scrollContent.GetComponent<RectTransform>();
|
||||
|
||||
var scrollGroup = m_scrollContent.GetComponent<VerticalLayoutGroup>();
|
||||
scrollGroup.spacing = 3;
|
||||
scrollGroup.padding.left = 0;
|
||||
scrollGroup.padding.right = 0;
|
||||
scrollGroup.childForceExpandHeight = true;
|
||||
|
||||
m_pageHandler = new PageHandler(m_sliderScroller);
|
||||
m_pageHandler.ConstructUI(Content);
|
||||
m_pageHandler.OnPageChanged += Parent.OnPageTurned;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Inspectors;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
namespace UnityExplorer.UI.Main.Home
|
||||
{
|
||||
public class SceneExplorer
|
||||
public class SceneExplorerUI
|
||||
{
|
||||
public static SceneExplorer Instance;
|
||||
|
||||
internal static Action OnToggleShow;
|
||||
|
||||
public SceneExplorer()
|
||||
{
|
||||
Instance = this;
|
||||
ConstructScenePane();
|
||||
}
|
||||
|
||||
private static bool Hiding;
|
||||
|
||||
private const float UPDATE_INTERVAL = 1f;
|
||||
private float m_timeOfLastSceneUpdate;
|
||||
|
||||
// private int m_currentSceneHandle = -1;
|
||||
public static Scene DontDestroyScene => DontDestroyObject.scene;
|
||||
internal Scene m_currentScene;
|
||||
internal Scene[] m_currentScenes = new Scene[0];
|
||||
|
||||
private GameObject m_selectedSceneObject;
|
||||
private int m_lastCount;
|
||||
internal static bool Hiding;
|
||||
|
||||
private Dropdown m_sceneDropdown;
|
||||
private Text m_sceneDropdownText;
|
||||
@ -45,90 +22,13 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
public PageHandler m_pageHandler;
|
||||
private GameObject m_pageContent;
|
||||
private GameObject[] m_allObjects = new GameObject[0];
|
||||
private readonly List<GameObject> m_shortList = new List<GameObject>();
|
||||
private readonly List<Text> m_shortListTexts = new List<Text>();
|
||||
private readonly List<Toggle> m_shortListToggles = new List<Toggle>();
|
||||
|
||||
internal readonly List<GameObject> m_shortList = new List<GameObject>();
|
||||
|
||||
internal static GameObject DontDestroyObject
|
||||
public void OnActiveScenesChanged(List<string> newNames)
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!s_dontDestroyObject)
|
||||
{
|
||||
s_dontDestroyObject = new GameObject("DontDestroyMe");
|
||||
GameObject.DontDestroyOnLoad(s_dontDestroyObject);
|
||||
}
|
||||
return s_dontDestroyObject;
|
||||
}
|
||||
}
|
||||
internal static GameObject s_dontDestroyObject;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
RefreshSceneSelector();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Hiding || Time.realtimeSinceStartup - m_timeOfLastSceneUpdate < UPDATE_INTERVAL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshSceneSelector();
|
||||
|
||||
if (!m_selectedSceneObject)
|
||||
{
|
||||
if (m_currentScene != default)
|
||||
{
|
||||
#if CPP
|
||||
SetSceneObjectList(SceneUnstrip.GetRootGameObjects(m_currentScene.handle));
|
||||
#else
|
||||
SetSceneObjectList(m_currentScene.GetRootGameObjects());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshSelectedSceneObject();
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnSceneChange()
|
||||
{
|
||||
m_sceneDropdown.OnCancel(null);
|
||||
RefreshSceneSelector();
|
||||
}
|
||||
|
||||
private void RefreshSceneSelector()
|
||||
{
|
||||
var newNames = new List<string>();
|
||||
var newScenes = new List<Scene>();
|
||||
|
||||
if (m_currentScenes == null)
|
||||
m_currentScenes = new Scene[0];
|
||||
|
||||
bool anyChange = SceneManager.sceneCount != m_currentScenes.Length - 1;
|
||||
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
Scene scene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (scene == default)
|
||||
continue;
|
||||
|
||||
if (!anyChange && !m_currentScenes.Any(it => it.GetHandle() == scene.GetHandle()))
|
||||
anyChange = true;
|
||||
|
||||
newScenes.Add(scene);
|
||||
newNames.Add(scene.name);
|
||||
}
|
||||
|
||||
newNames.Add("DontDestroyOnLoad");
|
||||
newScenes.Add(DontDestroyScene);
|
||||
|
||||
m_sceneDropdown.options.Clear();
|
||||
|
||||
foreach (string scene in newNames)
|
||||
@ -136,74 +36,8 @@ namespace UnityExplorer.Inspectors
|
||||
m_sceneDropdown.options.Add(new Dropdown.OptionData { text = scene });
|
||||
}
|
||||
|
||||
if (anyChange)
|
||||
{
|
||||
m_sceneDropdownText.text = newNames[0];
|
||||
SetTargetScene(newScenes[0]);
|
||||
}
|
||||
|
||||
m_currentScenes = newScenes.ToArray();
|
||||
}
|
||||
|
||||
public void SetTargetScene(Scene scene)
|
||||
{
|
||||
if (scene == default)
|
||||
return;
|
||||
|
||||
m_currentScene = scene;
|
||||
#if CPP
|
||||
GameObject[] rootObjs = SceneUnstrip.GetRootGameObjects(scene.handle);
|
||||
#else
|
||||
GameObject[] rootObjs = scene.GetRootGameObjects();
|
||||
#endif
|
||||
SetSceneObjectList(rootObjs);
|
||||
|
||||
m_selectedSceneObject = null;
|
||||
|
||||
if (m_backButtonObj.activeSelf)
|
||||
{
|
||||
m_backButtonObj.SetActive(false);
|
||||
m_mainInspectBtn.SetActive(false);
|
||||
}
|
||||
|
||||
m_scenePathText.text = "Scene root:";
|
||||
//m_scenePathText.ForceMeshUpdate();
|
||||
}
|
||||
|
||||
public void SetTargetObject(GameObject obj)
|
||||
{
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
m_scenePathText.text = obj.name;
|
||||
//m_scenePathText.ForceMeshUpdate();
|
||||
|
||||
m_selectedSceneObject = obj;
|
||||
|
||||
RefreshSelectedSceneObject();
|
||||
|
||||
if (!m_backButtonObj.activeSelf)
|
||||
{
|
||||
m_backButtonObj.SetActive(true);
|
||||
m_mainInspectBtn.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshSelectedSceneObject()
|
||||
{
|
||||
GameObject[] list = new GameObject[m_selectedSceneObject.transform.childCount];
|
||||
for (int i = 0; i < m_selectedSceneObject.transform.childCount; i++)
|
||||
{
|
||||
list[i] = m_selectedSceneObject.transform.GetChild(i).gameObject;
|
||||
}
|
||||
|
||||
SetSceneObjectList(list);
|
||||
}
|
||||
|
||||
private void SetSceneObjectList(GameObject[] objects)
|
||||
{
|
||||
m_allObjects = objects;
|
||||
RefreshSceneObjectList();
|
||||
m_sceneDropdown.OnCancel(null);
|
||||
m_sceneDropdownText.text = newNames[0];
|
||||
}
|
||||
|
||||
private void SceneListObjectClicked(int index)
|
||||
@ -215,35 +49,19 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
var obj = m_shortList[index];
|
||||
if (obj.transform.childCount > 0)
|
||||
SetTargetObject(obj);
|
||||
SceneExplorer.Instance.SetTargetObject(obj);
|
||||
else
|
||||
InspectorManager.Instance.Inspect(obj);
|
||||
}
|
||||
|
||||
private void OnSceneListPageTurn()
|
||||
internal void RefreshSceneObjectList(GameObject[] allObjects, out int newCount)
|
||||
{
|
||||
RefreshSceneObjectList();
|
||||
}
|
||||
|
||||
private void OnToggleClicked(int index, bool val)
|
||||
{
|
||||
if (index >= m_shortList.Count || !m_shortList[index])
|
||||
return;
|
||||
|
||||
var obj = m_shortList[index];
|
||||
obj.SetActive(val);
|
||||
}
|
||||
|
||||
private void RefreshSceneObjectList()
|
||||
{
|
||||
m_timeOfLastSceneUpdate = Time.realtimeSinceStartup;
|
||||
|
||||
var objects = m_allObjects;
|
||||
var objects = allObjects;
|
||||
m_pageHandler.ListCount = objects.Length;
|
||||
|
||||
//int startIndex = m_sceneListPageHandler.StartIndex;
|
||||
|
||||
int newCount = 0;
|
||||
newCount = 0;
|
||||
|
||||
foreach (var itemIndex in m_pageHandler)
|
||||
{
|
||||
@ -254,7 +72,7 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
if (itemIndex >= objects.Length)
|
||||
{
|
||||
if (i > m_lastCount || i >= m_shortListTexts.Count)
|
||||
if (i > SceneExplorer.Instance.m_lastCount || i >= m_shortListTexts.Count)
|
||||
break;
|
||||
|
||||
GameObject label = m_shortListTexts[i].transform.parent.parent.gameObject;
|
||||
@ -298,11 +116,46 @@ namespace UnityExplorer.Inspectors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_lastCount = newCount;
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
private void OnSceneListPageTurn()
|
||||
{
|
||||
SceneExplorer.Instance.RefreshSceneObjectList();
|
||||
}
|
||||
|
||||
private void OnToggleClicked(int index, bool val)
|
||||
{
|
||||
if (index >= m_shortList.Count || !m_shortList[index])
|
||||
return;
|
||||
|
||||
var obj = m_shortList[index];
|
||||
obj.SetActive(val);
|
||||
}
|
||||
|
||||
internal void OnGameObjectSelected(GameObject obj)
|
||||
{
|
||||
m_scenePathText.text = obj.name;
|
||||
//m_scenePathText.ForceMeshUpdate();
|
||||
if (!m_backButtonObj.activeSelf)
|
||||
{
|
||||
m_backButtonObj.SetActive(true);
|
||||
m_mainInspectBtn.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnSceneSelected()
|
||||
{
|
||||
if (m_backButtonObj.activeSelf)
|
||||
{
|
||||
m_backButtonObj.SetActive(false);
|
||||
m_mainInspectBtn.SetActive(false);
|
||||
}
|
||||
|
||||
m_scenePathText.text = "Scene root:";
|
||||
//m_scenePathText.ForceMeshUpdate();
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
public void ConstructScenePane()
|
||||
{
|
||||
@ -343,7 +196,7 @@ namespace UnityExplorer.Inspectors
|
||||
void SetSceneFromDropdown(int val)
|
||||
{
|
||||
//string scene = m_sceneDropdown.options[val].text;
|
||||
SetTargetScene(m_currentScenes[val]);
|
||||
SceneExplorer.Instance.SetTargetScene(val);
|
||||
}
|
||||
|
||||
GameObject scenePathGroupObj = UIFactory.CreateHorizontalGroup(leftPane, new Color(1, 1, 1, 0f));
|
||||
@ -369,20 +222,7 @@ namespace UnityExplorer.Inspectors
|
||||
colors.normalColor = new Color(0.12f, 0.12f, 0.12f);
|
||||
backButton.colors = colors;
|
||||
|
||||
backButton.onClick.AddListener(() => { SetSceneObjectParent(); });
|
||||
|
||||
void SetSceneObjectParent()
|
||||
{
|
||||
if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent?.gameObject)
|
||||
{
|
||||
m_selectedSceneObject = null;
|
||||
SetTargetScene(m_currentScene);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTargetObject(m_selectedSceneObject.transform.parent.gameObject);
|
||||
}
|
||||
}
|
||||
backButton.onClick.AddListener(() => { SceneExplorer.Instance.SetSceneObjectParent(); });
|
||||
|
||||
GameObject scenePathLabel = UIFactory.CreateHorizontalGroup(scenePathGroupObj);
|
||||
Image image = scenePathLabel.GetComponent<Image>();
|
||||
@ -419,7 +259,7 @@ namespace UnityExplorer.Inspectors
|
||||
colors.normalColor = new Color(0.12f, 0.12f, 0.12f);
|
||||
inspectButton.colors = colors;
|
||||
|
||||
inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); });
|
||||
inspectButton.onClick.AddListener(() => { SceneExplorer.InspectSelectedGameObject(); });
|
||||
|
||||
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_pageContent, out SliderScrollbar scroller, new Color(0.1f, 0.1f, 0.1f));
|
||||
|
||||
@ -471,10 +311,10 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
leftLayout.minWidth = 350;
|
||||
|
||||
Update();
|
||||
SceneExplorer.Instance.Update();
|
||||
}
|
||||
|
||||
OnToggleShow?.Invoke();
|
||||
SceneExplorer.InvokeOnToggleShow();
|
||||
}
|
||||
}
|
||||
|
||||
@ -541,6 +381,6 @@ namespace UnityExplorer.Inspectors
|
||||
inspectBtn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_shortList[thisIndex]); });
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,34 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityExplorer.CSConsole;
|
||||
using UnityExplorer.Core.CSharp;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
namespace UnityExplorer.UI.Main
|
||||
{
|
||||
public class MainMenu
|
||||
{
|
||||
public abstract class Page
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public GameObject Content;
|
||||
public Button RefNavbarButton { get; set; }
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => Content?.activeSelf ?? false;
|
||||
set => Content?.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public abstract void Init();
|
||||
public abstract void Update();
|
||||
}
|
||||
|
||||
public static MainMenu Instance { get; set; }
|
||||
|
||||
public PanelDragger Dragger { get; private set; }
|
||||
@ -36,8 +19,8 @@ namespace UnityExplorer.UI
|
||||
public GameObject MainPanel { get; private set; }
|
||||
public GameObject PageViewport { get; private set; }
|
||||
|
||||
public readonly List<Page> Pages = new List<Page>();
|
||||
private Page m_activePage;
|
||||
public readonly List<BaseMenuPage> Pages = new List<BaseMenuPage>();
|
||||
private BaseMenuPage m_activePage;
|
||||
|
||||
// Navbar buttons
|
||||
private Button m_lastNavButtonPressed;
|
||||
@ -57,14 +40,27 @@ namespace UnityExplorer.UI
|
||||
|
||||
Pages.Add(new HomePage());
|
||||
Pages.Add(new SearchPage());
|
||||
Pages.Add(new CSConsolePage());
|
||||
Pages.Add(new CSharpConsole());
|
||||
Pages.Add(new OptionsPage());
|
||||
|
||||
ConstructMenu();
|
||||
|
||||
foreach (Page page in Pages)
|
||||
for (int i = 0; i < Pages.Count; i++)
|
||||
{
|
||||
page.Init();
|
||||
var page = Pages[i];
|
||||
|
||||
if (!page.Init())
|
||||
{
|
||||
// page init failed.
|
||||
Pages.RemoveAt(i);
|
||||
i--;
|
||||
|
||||
if (page.RefNavbarButton)
|
||||
page.RefNavbarButton.interactable = false;
|
||||
|
||||
if (page.Content)
|
||||
GameObject.Destroy(page.Content);
|
||||
}
|
||||
}
|
||||
|
||||
// hide menu until each page has init layout (bit of a hack)
|
||||
@ -97,7 +93,7 @@ namespace UnityExplorer.UI
|
||||
m_activePage?.Update();
|
||||
}
|
||||
|
||||
public void SetPage(Page page)
|
||||
public void SetPage(BaseMenuPage page)
|
||||
{
|
||||
if (page == null || m_activePage == page)
|
||||
return;
|
||||
@ -118,7 +114,7 @@ namespace UnityExplorer.UI
|
||||
m_activePage?.Content?.SetActive(false);
|
||||
|
||||
// unique case for console page, at the moment this will just go here
|
||||
if (m_activePage is CSConsolePage)
|
||||
if (m_activePage is CSharpConsole)
|
||||
AutoCompleter.m_mainObj?.SetActive(false);
|
||||
|
||||
m_activePage = page;
|
||||
@ -155,8 +151,14 @@ namespace UnityExplorer.UI
|
||||
MainPanel = UIFactory.CreatePanel(UIManager.CanvasRoot, "MainMenu", out GameObject content);
|
||||
|
||||
RectTransform panelRect = MainPanel.GetComponent<RectTransform>();
|
||||
panelRect.anchorMin = new Vector2(0.25f, 0.1f);
|
||||
panelRect.anchorMax = new Vector2(0.78f, 0.95f);
|
||||
var anchors = ExplorerConfig.Instance.GetWindowAnchorsVector();
|
||||
SetPanelAnchors(panelRect, anchors);
|
||||
|
||||
if (panelRect.rect.width < 400 || panelRect.rect.height < 400)
|
||||
{
|
||||
anchors = ExplorerConfig.DefaultWindowAnchors();
|
||||
SetPanelAnchors(panelRect, anchors);
|
||||
}
|
||||
|
||||
MainPanel.AddComponent<Mask>();
|
||||
|
||||
@ -169,6 +171,12 @@ namespace UnityExplorer.UI
|
||||
new DebugConsole(content);
|
||||
}
|
||||
|
||||
private void SetPanelAnchors(RectTransform panelRect, Vector4 anchors)
|
||||
{
|
||||
panelRect.anchorMin = new Vector2(anchors.x, anchors.y);
|
||||
panelRect.anchorMax = new Vector2(anchors.z, anchors.w);
|
||||
}
|
||||
|
||||
private void ConstructTitleBar(GameObject content)
|
||||
{
|
||||
// Core title bar holder
|
||||
@ -249,7 +257,7 @@ namespace UnityExplorer.UI
|
||||
navLayout.minHeight = 25;
|
||||
navLayout.flexibleHeight = 0;
|
||||
|
||||
foreach (Page page in Pages)
|
||||
foreach (BaseMenuPage page in Pages)
|
||||
{
|
||||
GameObject btnObj = UIFactory.CreateButton(navbarObj);
|
||||
Button btn = btnObj.GetComponent<Button>();
|
@ -3,14 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.UI.Reusable;
|
||||
|
||||
namespace UnityExplorer.UI.Modules
|
||||
namespace UnityExplorer.UI.Main
|
||||
{
|
||||
public class OptionsPage : MainMenu.Page
|
||||
public class OptionsPage : BaseMenuPage
|
||||
{
|
||||
public override string Name => "Options";
|
||||
|
||||
@ -20,9 +18,11 @@ namespace UnityExplorer.UI.Modules
|
||||
private InputField m_defaultOutputInput;
|
||||
private Toggle m_hideOnStartupToggle;
|
||||
|
||||
public override void Init()
|
||||
public override bool Init()
|
||||
{
|
||||
ConstructUI();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user