2020-10-23 19:55:02 +11:00
|
|
|
|
using System;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
using System.IO;
|
2021-01-20 17:22:36 +11:00
|
|
|
|
using System.Reflection;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.Config;
|
2021-02-26 17:54:00 +11:00
|
|
|
|
using UnityExplorer.Helpers;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.Input;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
using UnityExplorer.Inspectors;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.UI;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
using UnityExplorer.UI.Modules;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-11-03 20:59:13 +11:00
|
|
|
|
namespace UnityExplorer
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-27 22:04:23 +10:00
|
|
|
|
public class ExplorerCore
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-11-13 18:46:36 +11:00
|
|
|
|
public const string NAME = "UnityExplorer";
|
2021-03-11 18:32:57 +11:00
|
|
|
|
public const string VERSION = "3.2.1";
|
2020-10-28 06:39:26 +11:00
|
|
|
|
public const string AUTHOR = "Sinai";
|
2020-11-03 20:59:13 +11:00
|
|
|
|
public const string GUID = "com.sinai.unityexplorer";
|
2021-01-02 19:38:01 +01:00
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
public static ExplorerCore Instance { get; private set; }
|
|
|
|
|
|
|
|
|
|
private static IExplorerLoader s_loader;
|
|
|
|
|
public static IExplorerLoader Loader => s_loader
|
2021-01-02 19:38:01 +01:00
|
|
|
|
#if ML
|
2021-03-11 17:57:58 +11:00
|
|
|
|
?? (s_loader = ExplorerMelonMod.Instance);
|
2021-01-02 19:38:01 +01:00
|
|
|
|
#elif BIE
|
2021-03-11 17:57:58 +11:00
|
|
|
|
?? (s_loader = ExplorerBepInPlugin.Instance);
|
2021-01-20 17:22:36 +11:00
|
|
|
|
#elif STANDALONE
|
2021-03-11 17:57:58 +11:00
|
|
|
|
?? (s_loader = ExplorerStandalone.Instance);
|
2021-01-02 19:38:01 +01:00
|
|
|
|
#endif
|
2020-11-08 21:04:41 +11:00
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
public static string ExplorerFolder => Loader.ExplorerFolder;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
public ExplorerCore()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-10-11 22:57:46 +11:00
|
|
|
|
if (Instance != null)
|
|
|
|
|
{
|
|
|
|
|
Log("An instance of Explorer is already active!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 22:19:03 +10:00
|
|
|
|
Instance = this;
|
|
|
|
|
|
2020-11-19 16:47:18 +11:00
|
|
|
|
#if CPP
|
|
|
|
|
ReflectionHelpers.TryLoadGameModules();
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
if (!Directory.Exists(ExplorerFolder))
|
|
|
|
|
Directory.CreateDirectory(ExplorerFolder);
|
2020-11-08 21:04:41 +11:00
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
ExplorerConfig.OnLoad();
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
2020-10-03 20:19:44 +10:00
|
|
|
|
InputManager.Init();
|
2020-10-08 06:15:42 +11:00
|
|
|
|
ForceUnlockCursor.Init();
|
2020-08-27 18:05:55 +10:00
|
|
|
|
|
2020-11-13 18:46:36 +11:00
|
|
|
|
SetupEvents();
|
2020-10-27 00:54:08 +11:00
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
UIManager.ShowMenu = true;
|
2020-10-08 06:15:42 +11:00
|
|
|
|
|
2020-11-13 18:46:36 +11:00
|
|
|
|
Log($"{NAME} {VERSION} initialized.");
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Update()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2021-03-11 17:57:58 +11:00
|
|
|
|
UIManager.CheckUIInit();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-11-06 20:42:16 +11:00
|
|
|
|
if (MouseInspector.Enabled)
|
|
|
|
|
MouseInspector.UpdateInspect();
|
|
|
|
|
else
|
2021-03-11 17:57:58 +11:00
|
|
|
|
UIManager.Update();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 18:46:36 +11:00
|
|
|
|
private void SetupEvents()
|
|
|
|
|
{
|
|
|
|
|
#if CPP
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-11-13 21:39:25 +11:00
|
|
|
|
Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
2020-11-13 18:46:36 +11:00
|
|
|
|
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((Scene a, LoadSceneMode b) => { OnSceneLoaded(); }));
|
|
|
|
|
SceneManager.add_activeSceneChanged(new Action<Scene, Scene>((Scene a, Scene b) => { OnSceneLoaded(); }));
|
|
|
|
|
}
|
2021-03-11 18:40:04 +11:00
|
|
|
|
catch
|
2021-03-11 17:57:58 +11:00
|
|
|
|
{
|
2021-03-11 18:40:04 +11:00
|
|
|
|
// exceptions here are non-fatal, just ignore.
|
2021-03-11 17:57:58 +11:00
|
|
|
|
}
|
2020-11-13 18:46:36 +11:00
|
|
|
|
#else
|
2020-11-13 21:39:25 +11:00
|
|
|
|
Application.logMessageReceived += OnUnityLog;
|
2020-11-13 18:46:36 +11:00
|
|
|
|
SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); };
|
|
|
|
|
SceneManager.activeSceneChanged += (Scene a, Scene b) => { OnSceneLoaded(); };
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void OnSceneLoaded()
|
2020-09-27 22:04:23 +10:00
|
|
|
|
{
|
2020-10-23 01:50:33 +11:00
|
|
|
|
UIManager.OnSceneChange();
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 21:39:25 +11:00
|
|
|
|
private void OnUnityLog(string message, string stackTrace, LogType type)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
{
|
|
|
|
|
if (!DebugConsole.LogUnity)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
message = $"[UNITY] {message}";
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Assert:
|
|
|
|
|
case LogType.Log:
|
2020-11-08 21:04:41 +11:00
|
|
|
|
Log(message, true);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
|
|
|
|
case LogType.Warning:
|
2020-11-08 21:04:41 +11:00
|
|
|
|
LogWarning(message, true);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
|
|
|
|
case LogType.Exception:
|
|
|
|
|
case LogType.Error:
|
2020-11-08 21:04:41 +11:00
|
|
|
|
LogError(message, true);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Log(object message, bool unity = false)
|
2020-09-27 22:04:23 +10:00
|
|
|
|
{
|
2020-10-24 20:18:42 +11:00
|
|
|
|
DebugConsole.Log(message?.ToString());
|
2020-10-27 00:54:08 +11:00
|
|
|
|
|
|
|
|
|
if (unity)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
Loader.OnLogMessage(message);
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
public static void LogWarning(object message, bool unity = false)
|
2020-09-27 22:04:23 +10:00
|
|
|
|
{
|
2020-10-24 20:18:42 +11:00
|
|
|
|
DebugConsole.Log(message?.ToString(), "FFFF00");
|
2020-10-27 00:54:08 +11:00
|
|
|
|
|
|
|
|
|
if (unity)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
Loader.OnLogWarning(message);
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
public static void LogError(object message, bool unity = false)
|
2020-09-27 22:04:23 +10:00
|
|
|
|
{
|
2020-10-24 20:18:42 +11:00
|
|
|
|
DebugConsole.Log(message?.ToString(), "FF0000");
|
2020-10-27 00:54:08 +11:00
|
|
|
|
|
|
|
|
|
if (unity)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
Loader.OnLogError(message);
|
2020-11-12 20:31:08 +11:00
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|