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

Commit ade7539

Browse files
committed
cleanups
1 parent 5c588e5 commit ade7539

22 files changed

+698
-607
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* <b>Reflection Inspector</b>: Inspect Properties and Fields. Can also set primitive values and evaluate primitive methods.
4545
* <b>Search</b>: Search for UnityEngine.Objects with various filters, or use the helpers for static Instances and Classes.
4646
* <b>C# Console</b>: Interactive console for evaluating C# methods on the fly, with some basic helpers.
47-
* <b>Inspect-under-mouse</b>: Hover over an object with a collider and inspect it by clicking on it.
47+
* <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.
4848

4949
## How to install
5050

@@ -68,9 +68,15 @@ Note: You must use version 0.3 of MelonLoader or greater. Version 0.3 is current
6868
### Standalone
6969

7070
0. Load the DLL from your mod or inject it. You must also make sure that the required libraries (Harmony, Unhollower for Il2Cpp, etc) are loaded.
71-
1. Create an instance of Unity Explorer with `new ExplorerCore();`
72-
2. You will need to call `ExplorerCore.Update()` (static method) from your Update method.
73-
3. Subscribe to the `ExplorerCore.OnLog__` methods for logging.
71+
1. Create an instance of Unity Explorer with `ExplorerStandalone.CreateInstance();`
72+
2. You will need to call `ExplorerStandalone.Update()` from your Update method.
73+
3. Subscribe to the `ExplorerStandalone.OnLog` event to handle logging if you wish.
74+
75+
## Logging
76+
77+
Explorer saves all logs to disk (only keeps the most recent 10 logs). They can be found in a "UnityExplorer" folder in the same place as where you put the DLL file.
78+
79+
These logs are also visible in the Debug Console part of the UI.
7480

7581
## Settings
7682

src/Config/ModConfig.cs renamed to src/Config/ExplorerConfig.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
namespace UnityExplorer.Config
88
{
9-
public class ModConfig
9+
public class ExplorerConfig
1010
{
11-
public static ModConfig Instance;
11+
public static ExplorerConfig Instance;
1212

1313
internal static readonly IniDataParser _parser = new IniDataParser();
14-
internal static readonly string INI_PATH = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "config.ini");
14+
internal static readonly string INI_PATH = Path.Combine(ExplorerCore.Loader.ConfigFolder, "config.ini");
1515

16-
static ModConfig()
16+
static ExplorerConfig()
1717
{
1818
_parser.Configuration.CommentString = "#";
1919
}
@@ -22,7 +22,7 @@ static ModConfig()
2222
public KeyCode Main_Menu_Toggle = KeyCode.F7;
2323
public bool Force_Unlock_Mouse = true;
2424
public int Default_Page_Limit = 25;
25-
public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER + @"\Output";
25+
public string Default_Output_Path = ExplorerCore.ExplorerFolder + @"\Output";
2626
public bool Log_Unity_Debug = false;
2727
public bool Hide_On_Startup = false;
2828
//public bool Save_Logs_To_Disk = true;
@@ -36,7 +36,7 @@ internal static void InvokeConfigChanged()
3636

3737
public static void OnLoad()
3838
{
39-
Instance = new ModConfig();
39+
Instance = new ExplorerConfig();
4040

4141
if (LoadSettings())
4242
return;
@@ -99,6 +99,9 @@ public static void SaveSettings()
9999
sec.AddKey(nameof(Hide_On_Startup), Instance.Hide_On_Startup.ToString());
100100
//sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
101101

102+
if (!Directory.Exists(ExplorerCore.Loader.ConfigFolder))
103+
Directory.CreateDirectory(ExplorerCore.Loader.ConfigFolder);
104+
102105
File.WriteAllText(INI_PATH, data.ToString());
103106
}
104107
}

src/ExplorerBepIn5Plugin.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/ExplorerCore.cs

Lines changed: 22 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,19 @@ public class ExplorerCore
1919
public const string AUTHOR = "Sinai";
2020
public const string GUID = "com.sinai.unityexplorer";
2121

22+
public static ExplorerCore Instance { get; private set; }
23+
24+
private static IExplorerLoader s_loader;
25+
public static IExplorerLoader Loader => s_loader
2226
#if ML
23-
public static string EXPLORER_FOLDER = Path.Combine("Mods", NAME);
27+
?? (s_loader = ExplorerMelonMod.Instance);
2428
#elif BIE
25-
public static string EXPLORER_FOLDER = Path.Combine(BepInEx.Paths.ConfigPath, NAME);
29+
?? (s_loader = ExplorerBepInPlugin.Instance);
2630
#elif STANDALONE
27-
public static string EXPLORER_FOLDER
28-
{
29-
get
30-
{
31-
if (s_explorerFolder == null)
32-
{
33-
s_explorerFolder = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
34-
s_explorerFolder = Uri.UnescapeDataString(s_explorerFolder);
35-
s_explorerFolder = Path.GetDirectoryName(s_explorerFolder);
36-
}
37-
38-
return s_explorerFolder;
39-
}
40-
}
41-
private static string s_explorerFolder;
31+
?? (s_loader = ExplorerStandalone.Instance);
4232
#endif
4333

44-
public static ExplorerCore Instance { get; private set; }
45-
46-
public static bool ShowMenu
47-
{
48-
get => s_showMenu;
49-
set => SetShowMenu(value);
50-
}
51-
public static bool s_showMenu;
52-
53-
private static bool s_doneUIInit;
54-
private static float s_timeSinceStartup;
34+
public static string ExplorerFolder => Loader.ExplorerFolder;
5535

5636
public ExplorerCore()
5737
{
@@ -67,60 +47,29 @@ public ExplorerCore()
6747
ReflectionHelpers.TryLoadGameModules();
6848
#endif
6949

70-
if (!Directory.Exists(EXPLORER_FOLDER))
71-
Directory.CreateDirectory(EXPLORER_FOLDER);
50+
if (!Directory.Exists(ExplorerFolder))
51+
Directory.CreateDirectory(ExplorerFolder);
7252

73-
ModConfig.OnLoad();
53+
ExplorerConfig.OnLoad();
7454

7555
InputManager.Init();
7656
ForceUnlockCursor.Init();
7757

7858
SetupEvents();
7959

80-
ShowMenu = true;
60+
UIManager.ShowMenu = true;
8161

8262
Log($"{NAME} {VERSION} initialized.");
8363
}
8464

8565
public static void Update()
8666
{
87-
if (!s_doneUIInit)
88-
CheckUIInit();
67+
UIManager.CheckUIInit();
8968

9069
if (MouseInspector.Enabled)
9170
MouseInspector.UpdateInspect();
9271
else
93-
{
94-
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
95-
ShowMenu = !ShowMenu;
96-
97-
if (ShowMenu && s_doneUIInit)
98-
UIManager.Update();
99-
}
100-
}
101-
102-
private static void CheckUIInit()
103-
{
104-
s_timeSinceStartup += Time.deltaTime;
105-
106-
if (s_timeSinceStartup > 0.1f)
107-
{
108-
s_doneUIInit = true;
109-
try
110-
{
111-
UIManager.Init();
112-
Log("Initialized UnityExplorer UI.");
113-
114-
if (ModConfig.Instance.Hide_On_Startup)
115-
ShowMenu = false;
116-
117-
// InspectorManager.Instance.Inspect(Tests.TestClass.Instance);
118-
}
119-
catch (Exception e)
120-
{
121-
LogWarning($"Exception setting up UI: {e}");
122-
}
123-
}
72+
UIManager.Update();
12473
}
12574

12675
private void SetupEvents()
@@ -129,10 +78,14 @@ private void SetupEvents()
12978
try
13079
{
13180
Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
81+
13282
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((Scene a, LoadSceneMode b) => { OnSceneLoaded(); }));
13383
SceneManager.add_activeSceneChanged(new Action<Scene, Scene>((Scene a, Scene b) => { OnSceneLoaded(); }));
13484
}
135-
catch { }
85+
catch (Exception ex)
86+
{
87+
LogWarning($"Exception setting up Unity event listeners!\r\n{ex}");
88+
}
13689
#else
13790
Application.logMessageReceived += OnUnityLog;
13891
SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); };
@@ -145,23 +98,6 @@ internal void OnSceneLoaded()
14598
UIManager.OnSceneChange();
14699
}
147100

148-
private static void SetShowMenu(bool show)
149-
{
150-
s_showMenu = show;
151-
152-
if (UIManager.CanvasRoot)
153-
{
154-
UIManager.CanvasRoot.SetActive(show);
155-
156-
if (show)
157-
ForceUnlockCursor.SetEventSystem();
158-
else
159-
ForceUnlockCursor.ReleaseEventSystem();
160-
}
161-
162-
ForceUnlockCursor.UpdateCursorControl();
163-
}
164-
165101
private void OnUnityLog(string message, string stackTrace, LogType type)
166102
{
167103
if (!DebugConsole.LogUnity)
@@ -185,26 +121,14 @@ private void OnUnityLog(string message, string stackTrace, LogType type)
185121
}
186122
}
187123

188-
#if STANDALONE
189-
public static Action<string> OnLogMessage;
190-
public static Action<string> OnLogWarning;
191-
public static Action<string> OnLogError;
192-
#endif
193-
194124
public static void Log(object message, bool unity = false)
195125
{
196126
DebugConsole.Log(message?.ToString());
197127

198128
if (unity)
199129
return;
200130

201-
#if ML
202-
MelonLoader.MelonLogger.Msg(message?.ToString());
203-
#elif BIE
204-
ExplorerBepInPlugin.Logging?.LogMessage(message?.ToString());
205-
#elif STANDALONE
206-
OnLogMessage?.Invoke(message?.ToString());
207-
#endif
131+
Loader.OnLogMessage(message);
208132
}
209133

210134
public static void LogWarning(object message, bool unity = false)
@@ -214,13 +138,7 @@ public static void LogWarning(object message, bool unity = false)
214138
if (unity)
215139
return;
216140

217-
#if ML
218-
MelonLoader.MelonLogger.Msg(message?.ToString());
219-
#elif BIE
220-
ExplorerBepInPlugin.Logging?.LogWarning(message?.ToString());
221-
#elif STANDALONE
222-
OnLogWarning?.Invoke(message?.ToString());
223-
#endif
141+
Loader.OnLogWarning(message);
224142
}
225143

226144
public static void LogError(object message, bool unity = false)
@@ -230,24 +148,7 @@ public static void LogError(object message, bool unity = false)
230148
if (unity)
231149
return;
232150

233-
#if ML
234-
MelonLoader.MelonLogger.Msg(message?.ToString());
235-
#elif BIE
236-
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
237-
#elif STANDALONE
238-
OnLogError?.Invoke(message?.ToString());
239-
#endif
240-
}
241-
242-
243-
public static string RemoveInvalidFilenameChars(string s)
244-
{
245-
var invalid = System.IO.Path.GetInvalidFileNameChars();
246-
foreach (var c in invalid)
247-
{
248-
s = s.Replace(c.ToString(), "");
249-
}
250-
return s;
151+
Loader.OnLogError(message);
251152
}
252153
}
253154
}

src/ExplorerMelonMod.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/ExplorerStandalone.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Inspectors/Reflection/InstanceInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ internal void ConstructTextureViewerArea(GameObject parent)
251251
if (string.IsNullOrEmpty(name))
252252
name = "untitled";
253253

254-
var savePath = $@"{Config.ModConfig.Instance.Default_Output_Path}\{name}.png";
254+
var savePath = $@"{Config.ExplorerConfig.Instance.Default_Output_Path}\{name}.png";
255255
inputField.text = savePath;
256256

257257
saveBtn.onClick.AddListener(() =>

src/Inspectors/Reflection/InteractiveValue/InteractiveDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal readonly List<KeyValuePair<CachePaired, CachePaired>> m_entries
5959
= new List<KeyValuePair<CachePaired, CachePaired>>();
6060

6161
internal readonly KeyValuePair<CachePaired, CachePaired>[] m_displayedEntries
62-
= new KeyValuePair<CachePaired, CachePaired>[ModConfig.Instance.Default_Page_Limit];
62+
= new KeyValuePair<CachePaired, CachePaired>[ExplorerConfig.Instance.Default_Page_Limit];
6363

6464
internal bool m_recacheWanted = true;
6565

0 commit comments

Comments
 (0)