Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 56a3cef

Browse files
committed
Add C# Console Assembly blacklist
1 parent 61e7915 commit 56a3cef

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/CSConsole/ConsoleController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static class ConsoleController
5656
"System.Text",
5757
"System.Collections",
5858
"System.Collections.Generic",
59+
"System.Reflection",
5960
"UnityEngine",
6061
"UniverseLib",
6162
#if CPP

src/CSConsole/ScriptEvaluator.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Reflection;
6+
using UnityExplorer.Config;
67

78
// Thanks to ManlyMarco for this
89

910
namespace UnityExplorer.CSConsole
1011
{
1112
public class ScriptEvaluator : Evaluator, IDisposable
1213
{
14+
internal TextWriter _textWriter;
15+
internal static StreamReportPrinter _reportPrinter;
16+
1317
private static readonly HashSet<string> StdLib = new(StringComparer.InvariantCultureIgnoreCase)
1418
{
1519
"mscorlib",
@@ -18,9 +22,6 @@ public class ScriptEvaluator : Evaluator, IDisposable
1822
"System.Xml"
1923
};
2024

21-
internal TextWriter _textWriter;
22-
internal static StreamReportPrinter _reportPrinter;
23-
2425
public ScriptEvaluator(TextWriter tw) : base(BuildContext(tw))
2526
{
2627
_textWriter = tw;
@@ -48,8 +49,19 @@ private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
4849
private void Reference(Assembly asm)
4950
{
5051
string name = asm.GetName().Name;
51-
if (name == "completions")
52+
53+
if (name == "completions") // ignore assemblies generated by mcs' autocomplete.
5254
return;
55+
56+
foreach (string blacklisted in ConfigManager.CSConsole_Assembly_Blacklist.Value.Split(';'))
57+
{
58+
string bl = blacklisted;
59+
if (bl.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
60+
bl = blacklisted.Substring(0, bl.Length - 4);
61+
if (string.Equals(bl, name, StringComparison.OrdinalIgnoreCase))
62+
return;
63+
}
64+
5365
ReferenceAssembly(asm);
5466
}
5567

src/Config/ConfigManager.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public static class ConfigManager
2525
public static ConfigElement<string> Default_Output_Path;
2626
public static ConfigElement<string> DnSpy_Path;
2727
public static ConfigElement<bool> Log_Unity_Debug;
28-
public static ConfigElement<string> Reflection_Signature_Blacklist;
2928
public static ConfigElement<UIManager.VerticalAnchor> Main_Navbar_Anchor;
3029
public static ConfigElement<KeyCode> World_MouseInspect_Keybind;
3130
public static ConfigElement<KeyCode> UI_MouseInspect_Keybind;
31+
public static ConfigElement<string> CSConsole_Assembly_Blacklist;
32+
public static ConfigElement<string> Reflection_Signature_Blacklist;
3233

3334
// internal configs
3435
internal static InternalConfigHandler InternalHandler { get; private set; }
@@ -57,8 +58,6 @@ public static void Init(ConfigHandler configHandler)
5758
#if STANDALONE
5859
Loader.Standalone.ExplorerEditorBehaviour.Instance?.LoadConfigs();
5960
#endif
60-
61-
//InitConsoleCallback();
6261
}
6362

6463
internal static void RegisterConfigElement<T>(ConfigElement<T> configElement)
@@ -77,50 +76,50 @@ internal static void RegisterConfigElement<T>(ConfigElement<T> configElement)
7776

7877
private static void CreateConfigElements()
7978
{
80-
Master_Toggle = new ConfigElement<KeyCode>("UnityExplorer Toggle",
79+
Master_Toggle = new("UnityExplorer Toggle",
8180
"The key to enable or disable UnityExplorer's menu and features.",
8281
KeyCode.F7);
8382

84-
Hide_On_Startup = new ConfigElement<bool>("Hide On Startup",
83+
Hide_On_Startup = new("Hide On Startup",
8584
"Should UnityExplorer be hidden on startup?",
8685
false);
8786

88-
Startup_Delay_Time = new ConfigElement<float>("Startup Delay Time",
87+
Startup_Delay_Time = new("Startup Delay Time",
8988
"The delay on startup before the UI is created.",
9089
1f);
9190

92-
Target_Display = new ConfigElement<int>("Target Display",
91+
Target_Display = new("Target Display",
9392
"The monitor index for UnityExplorer to use, if you have multiple. 0 is the default display, 1 is secondary, etc. " +
9493
"Restart recommended when changing this setting. Make sure your extra monitors are the same resolution as your primary monitor.",
9594
0);
9695

97-
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
96+
Force_Unlock_Mouse = new("Force Unlock Mouse",
9897
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
9998
true);
10099
Force_Unlock_Mouse.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value;
101100

102-
Force_Unlock_Toggle = new ConfigElement<KeyCode>("Force Unlock Toggle Key",
101+
Force_Unlock_Toggle = new("Force Unlock Toggle Key",
103102
"The keybind to toggle the 'Force Unlock Mouse' setting. Only usable when UnityExplorer is open.",
104103
KeyCode.None);
105104

106-
Disable_EventSystem_Override = new ConfigElement<bool>("Disable EventSystem override",
105+
Disable_EventSystem_Override = new("Disable EventSystem override",
107106
"If enabled, UnityExplorer will not override the EventSystem from the game.\n<b>May require restart to take effect.</b>",
108107
false);
109108
Disable_EventSystem_Override.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value;
110109

111-
Default_Output_Path = new ConfigElement<string>("Default Output Path",
110+
Default_Output_Path = new("Default Output Path",
112111
"The default output path when exporting things from UnityExplorer.",
113112
Path.Combine(ExplorerCore.ExplorerFolder, "Output"));
114113

115-
DnSpy_Path = new ConfigElement<string>("dnSpy Path",
114+
DnSpy_Path = new("dnSpy Path",
116115
"The full path to dnSpy.exe (64-bit).",
117116
@"C:/Program Files/dnspy/dnSpy.exe");
118117

119-
Main_Navbar_Anchor = new ConfigElement<UIManager.VerticalAnchor>("Main Navbar Anchor",
118+
Main_Navbar_Anchor = new("Main Navbar Anchor",
120119
"The vertical anchor of the main UnityExplorer Navbar, in case you want to move it.",
121120
UIManager.VerticalAnchor.Top);
122121

123-
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
122+
Log_Unity_Debug = new("Log Unity Debug",
124123
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
125124
false);
126125

@@ -132,7 +131,13 @@ private static void CreateConfigElements()
132131
"Optional keybind to begin a UI-mode Mouse Inspect.",
133132
KeyCode.None);
134133

135-
Reflection_Signature_Blacklist = new ConfigElement<string>("Member Signature Blacklist",
134+
CSConsole_Assembly_Blacklist = new("CSharp Console Assembly Blacklist",
135+
"Use this to blacklist Assembly names from being referenced by the C# Console. Requires a Reset of the C# Console.\n" +
136+
"Separate each Assembly with a semicolon ';'." +
137+
"For example, to blacklist Assembly-CSharp, you would add 'Assembly-CSharp;'",
138+
"");
139+
140+
Reflection_Signature_Blacklist = new("Member Signature Blacklist",
136141
"Use this to blacklist certain member signatures if they are known to cause a crash or other issues.\r\n" +
137142
"Seperate signatures with a semicolon ';'.\r\n" +
138143
"For example, to blacklist Camera.main, you would add 'UnityEngine.Camera.main;'",

0 commit comments

Comments
 (0)