Implemented the console log, some cleanups

This commit is contained in:
Sinai
2021-05-14 02:45:59 +10:00
parent 89022db5fc
commit 12fe19ba8e
17 changed files with 341 additions and 147 deletions
-3
View File
@@ -108,9 +108,6 @@ namespace UnityExplorer.Core.Config
"\r\nSeperate signatures with a semicolon ';'.",
"DEFAULT");
Reflection_Signature_Blacklist.OnValueChanged += ReflectionUtility.LoadBlacklistString;
ReflectionUtility.LoadBlacklistString(Reflection_Signature_Blacklist.Value);
// Internal configs (panel save data)
ObjectExplorerData = new ConfigElement<string>("ObjectExplorer", "", "", true);
+5 -2
View File
@@ -14,13 +14,16 @@ using System.Diagnostics.CodeAnalysis;
using UnityExplorer.Core;
using CppType = Il2CppSystem.Type;
using BF = System.Reflection.BindingFlags;
using UnityExplorer.Core.Config;
namespace UnityExplorer
{
public class Il2CppReflection : ReflectionUtility
{
public Il2CppReflection()
protected override void Initialize()
{
base.Initialize();
TryLoadGameModules();
BuildDeobfuscationCache();
@@ -70,7 +73,7 @@ namespace UnityExplorer
}
if (DeobfuscatedTypes.Count > 0)
ExplorerCore.Log($"Built deobfuscation cache, count: {DeobfuscatedTypes.Count}");
ExplorerCore.Log($"Built IL2CPP deobfuscation cache, initial count: {DeobfuscatedTypes.Count}");
}
private static void TryCacheDeobfuscatedType(Type type)
+16 -2
View File
@@ -17,16 +17,25 @@ namespace UnityExplorer
{
public const BF FLAGS = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
internal static readonly ReflectionUtility Instance =
internal static ReflectionUtility Instance;
public static void Init()
{
Instance =
#if CPP
new Il2CppReflection();
#else
new ReflectionUtility();
#endif
Instance.Initialize();
}
static ReflectionUtility()
protected virtual void Initialize()
{
SetupTypeCache();
LoadBlacklistString(ConfigManager.Reflection_Signature_Blacklist.Value);
ConfigManager.Reflection_Signature_Blacklist.OnValueChanged += LoadBlacklistString;
}
#region Type cache
@@ -409,7 +418,12 @@ namespace UnityExplorer
public static void LoadBlacklistString(string blacklist)
{
if (string.Equals(blacklist, "DEFAULT", StringComparison.InvariantCultureIgnoreCase))
{
blacklist = Instance.DefaultReflectionBlacklist;
ConfigManager.Reflection_Signature_Blacklist.Value = blacklist;
ConfigManager.Handler.SaveConfig();
return;
}
if (string.IsNullOrEmpty(blacklist))
return;
+7 -11
View File
@@ -8,21 +8,17 @@ namespace UnityExplorer
{
public static class IOUtility
{
public static string EnsureValid(string path)
private static readonly char[] invalidDirectoryCharacters = Path.GetInvalidPathChars();
private static readonly char[] invalidFilenameCharacters = Path.GetInvalidFileNameChars();
public static string EnsureValidDirectory(string path)
{
path = RemoveInvalidChars(path);
var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
return path;
return string.Concat(path.Split(invalidDirectoryCharacters));
}
public static string RemoveInvalidChars(string path)
public static string EnsureValidFilename(string filename)
{
return string.Concat(path.Split(Path.GetInvalidPathChars()));
return string.Concat(filename.Split(invalidFilenameCharacters));
}
}
}
+10 -7
View File
@@ -38,6 +38,8 @@ namespace UnityExplorer
}
Loader = loader;
Log($"{NAME} {VERSION} initializing...");
ExplorerBehaviour.Setup();
if (!Directory.Exists(Loader.ExplorerFolder))
@@ -45,13 +47,15 @@ namespace UnityExplorer
ConfigManager.Init(Loader.ConfigHandler);
ReflectionUtility.Init();
RuntimeProvider.Init();
SceneHandler.Init();
InputManager.Init();
Log($"{NAME} {VERSION} initialized.");
RuntimeProvider.Instance.StartCoroutine(SetupCoroutine());
Log($"Finished core setup, waiting for UI setup...");
}
// Do a delayed setup so that objects aren't destroyed instantly.
@@ -71,11 +75,11 @@ namespace UnityExplorer
yield return null;
}
Log($"Creating UI, after delay of {ConfigManager.Startup_Delay_Time.Value} second(s).");
Log($"Creating UI...");
UIManager.InitUI();
// END
Log($"{NAME} {VERSION} initialized.");
//InspectorManager.Inspect(typeof(TestClass));
}
@@ -123,23 +127,22 @@ namespace UnityExplorer
{
string log = message?.ToString() ?? "";
LogPanel.Log(log, logType);
switch (logType)
{
case LogType.Assert:
case LogType.Log:
Loader.OnLogMessage(log);
//DebugConsole.Log(log, Color.white);
break;
case LogType.Warning:
Loader.OnLogWarning(log);
//DebugConsole.Log(log, Color.yellow);
break;
case LogType.Error:
case LogType.Exception:
Loader.OnLogError(log);
//DebugConsole.Log(log, Color.red);
break;
}
}
+19 -42
View File
@@ -16,47 +16,6 @@ namespace UnityExplorer.UI.CSConsole
{
public static class ConsoleController
{
#region Strings / defaults
internal const string STARTUP_TEXT = @"Welcome to the UnityExplorer C# Console.
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 target of the active Inspector tab as System.Object
* <color=#add490>AllTargets()</color> returns a System.Object[] array containing the targets of all active tabs
* <color=#add490>Inspect(someObject)</color> to inspect an instance, eg. Inspect(Camera.main);
* <color=#add490>Inspect(typeof(SomeClass))</color> to inspect a Class with static reflection
* <color=#add490>AddUsing(""SomeNamespace"")</color> adds a using directive to the C# console
* <color=#add490>GetUsing()</color> logs the current using directives to the debug console
* <color=#add490>Reset()</color> resets all using directives and variables
";
internal static readonly string[] DefaultUsing = new string[]
{
"System",
"System.Linq",
"System.Collections",
"System.Collections.Generic",
"System.Reflection",
"UnityEngine",
#if CPP
"UnhollowerBaseLib",
"UnhollowerRuntimeLib",
#endif
};
#endregion
public static ScriptEvaluator Evaluator;
public static LexerBuilder Lexer;
public static CSAutoCompleter Completer;
@@ -75,16 +34,34 @@ The following helper methods are available:
public static bool EnableAutoIndent { get; private set; } = true;
public static bool EnableSuggestions { get; private set; } = true;
internal static readonly string[] DefaultUsing = new string[]
{
"System",
"System.Linq",
"System.Collections",
"System.Collections.Generic",
"System.Reflection",
"UnityEngine",
#if CPP
"UnhollowerBaseLib",
"UnhollowerRuntimeLib",
#endif
};
public static void Init()
{
try
{
ResetConsole(false);
// ensure the compiler is supported (if this fails then SRE is probably stubbed)
Evaluator.Compile("0 == 0");
}
catch
{
ExplorerCore.LogWarning("C# Console probably not supported, todo");
ExplorerCore.LogWarning("C# Console is not supported, System.Reflection.Emit was probably stubbed! You can use UnityDoorstop to patch this.");
var navButton = Panel.NavButton;
navButton.Component.interactable = false;
navButton.ButtonText.text += "(disabled)";
return;
}
+30 -28
View File
@@ -10,40 +10,37 @@ namespace UnityExplorer.UI.CSConsole
{
public class ScriptInteraction : InteractiveBase
{
internal const string STARTUP_TEXT = @"Welcome to the UnityExplorer C# Console.
Use this console to declare temporary C# classes, or evaluate standalone expressions as though you were executing a method body. "+
@"Use the <b>Reset</b> button to clear all classes and variables, and restore the default using directives.
* <color=#add490>using SomeNamespace;</color> to add a namespace to the Console. This is not required if you use full namespaces to access classes.
When evaluating standalone expressions, these helpers are available:
* System.Object <color=#96b570>CurrentTarget</color> - the target of the active Inspector tab
* System.Object[] <color=#96b570>AllTargets</color> - an array containing the targets of all Inspector tabs
* void <color=#add490>Log(""message"")</color> - logs a message to the console log
* void <color=#add490>Inspect(someObject)</color> - inspect an instance, eg. Inspect(Camera.main);
* void <color=#add490>Inspect(typeof(SomeClass))</color> - inspect a Class with static reflection
* void <color=#add490>StartCoroutine(ienumerator)</color> - start the IEnumerator as a Coroutine
";
public static void Log(object message)
{
ExplorerCore.Log(message);
}
public static void StartCoroutine(IEnumerator ienumerator)
{
RuntimeProvider.Instance.StartCoroutine(ienumerator);
}
public static object CurrentTarget => InspectorManager.ActiveInspector?.Target;
public static void AddUsing(string directive)
{
ConsoleController.AddUsing(directive);
}
public static void GetUsing()
{
ExplorerCore.Log(ConsoleController.Evaluator.GetUsing());
}
public static void Reset()
{
ConsoleController.ResetConsole();
}
public static object CurrentTarget()
{
return InspectorManager.ActiveInspector?.Target;
}
public static object[] AllTargets()
{
return InspectorManager.Inspectors.Select(it => it.Target).ToArray();
}
public static object[] AllTargets() => InspectorManager.Inspectors.Select(it => it.Target).ToArray();
public static void Inspect(object obj)
{
@@ -54,5 +51,10 @@ namespace UnityExplorer.UI.CSConsole
{
InspectorManager.Inspect(type);
}
public static void StartCoroutine(IEnumerator ienumerator)
{
RuntimeProvider.Instance.StartCoroutine(ienumerator);
}
}
}
+3
View File
@@ -33,6 +33,9 @@ namespace UnityExplorer.UI.CacheObject
return;
SetValueFromSource(RefConfigElement.BoxedValue);
if (this.CellView != null)
this.SetDataToCell(CellView);
}
public override void TrySetUserValue(object value)
+1 -1
View File
@@ -256,7 +256,7 @@ namespace UnityExplorer.UI.CacheObject
case MemberTypes.Method:
{
var mi = member as MethodInfo;
if (!ignorePropertyMethodInfos
if (ignorePropertyMethodInfos
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
return;
+1 -1
View File
@@ -79,7 +79,7 @@ namespace UnityExplorer.UI.IValues
return;
}
var path = IOUtility.EnsureValid(SaveFilePath.Text);
var path = IOUtility.EnsureValidDirectory(SaveFilePath.Text);
if (File.Exists(path))
File.Delete(path);
+1 -1
View File
@@ -665,7 +665,7 @@ namespace UnityExplorer.UI.Inspectors
return;
}
path = IOUtility.EnsureValid(path);
path = IOUtility.EnsureValidDirectory(path);
if (File.Exists(path))
File.Delete(path);
+2 -2
View File
@@ -102,7 +102,7 @@ namespace UnityExplorer.UI.Panels
var autoIndentToggleObj = UIFactory.CreateToggle(topBarObj, "IndentToggle", out var AutoIndentToggle, out Text autoIndentToggleText);
UIFactory.SetLayoutElement(autoIndentToggleObj, minWidth: 180, flexibleWidth: 0, minHeight: 25);
autoIndentToggleText.alignment = TextAnchor.UpperLeft;
autoIndentToggleText.text = "Auto-indent on Enter";
autoIndentToggleText.text = "Auto-indent";
AutoIndentToggle.onValueChanged.AddListener((bool val) => { OnAutoIndentToggled?.Invoke(val); });
#endregion
@@ -111,7 +111,7 @@ namespace UnityExplorer.UI.Panels
int fontSize = 16;
var inputObj = UIFactory.CreateSrollInputField(this.content, "ConsoleInput", ConsoleController.STARTUP_TEXT, out var inputScroller, fontSize);
var inputObj = UIFactory.CreateSrollInputField(this.content, "ConsoleInput", ScriptInteraction.STARTUP_TEXT, out var inputScroller, fontSize);
InputScroll = inputScroller;
ConsoleController.defaultInputFieldAlpha = Input.Component.selectionColor.a;
Input.OnValueChanged += InvokeOnValueChanged;
-41
View File
@@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityExplorer.Core.Config;
namespace UnityExplorer.UI.Panels
{
public class ConsoleLogPanel : UIPanel
{
public override string Name => "Console Log";
public override UIManager.Panels PanelType => UIManager.Panels.ConsoleLog;
public override int MinWidth => 300;
public override int MinHeight => 75;
public override string GetSaveDataFromConfigManager()
{
return ConfigManager.ConsoleLogData.Value;
}
public override void DoSaveToConfigElement()
{
ConfigManager.ConsoleLogData.Value = this.ToSaveData();
}
protected internal override void DoSetDefaultPosAndAnchors()
{
mainPanelRect.localPosition = Vector2.zero;
mainPanelRect.pivot = new Vector2(0f, 1f);
mainPanelRect.anchorMin = new Vector2(0.5f, 0.1f);
mainPanelRect.anchorMax = new Vector2(0.9f, 0.25f);
}
public override void ConstructPanelContent()
{
}
}
}
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -80,7 +80,7 @@ namespace UnityExplorer.UI.Panels
{
// Save button
var saveBtn = UIFactory.CreateButton(this.content, "Save", "Save Options", new Color(0.25f, 0.3f, 0.25f));
var saveBtn = UIFactory.CreateButton(this.content, "Save", "Save Options", new Color(0.2f, 0.3f, 0.2f));
UIFactory.SetLayoutElement(saveBtn.Component.gameObject, flexibleWidth: 9999, minHeight: 30, flexibleHeight: 0);
saveBtn.OnClick += ConfigManager.Handler.SaveConfig;
+1 -4
View File
@@ -165,7 +165,7 @@ namespace UnityExplorer.UI
UIPanels.Add(Panels.Inspector, new InspectorPanel());
UIPanels.Add(Panels.CSConsole, new CSConsolePanel());
UIPanels.Add(Panels.Options, new OptionsPanel());
UIPanels.Add(Panels.ConsoleLog, new ConsoleLogPanel());
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
foreach (var panel in UIPanels.Values)
panel.ConstructUI();
@@ -174,7 +174,6 @@ namespace UnityExplorer.UI
ShowMenu = !ConfigManager.Hide_On_Startup.Value;
ExplorerCore.Log("UI initialized.");
Initializing = false;
}
@@ -279,8 +278,6 @@ namespace UnityExplorer.UI
BackupShader = Graphic.defaultGraphicMaterial.shader;
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
ExplorerCore.Log("Loaded UI AssetBundle");
}
private static AssetBundle LoadBundle(string id)
+1 -1
View File
@@ -264,7 +264,7 @@
<Compile Include="UI\Models\InputFieldRef.cs" />
<Compile Include="UI\ObjectPool\IPooledObject.cs" />
<Compile Include="UI\ObjectPool\Pool.cs" />
<Compile Include="UI\Panels\ConsoleLogPanel.cs" />
<Compile Include="UI\Panels\LogPanel.cs" />
<Compile Include="UI\Panels\CSConsolePanel.cs" />
<Compile Include="Core\Utility\IOUtility.cs" />
<Compile Include="UI\Panels\OptionsPanel.cs" />