This commit is contained in:
Sinai committed 2021-03-11 17:57:58 +11:00
1 parent 5c588e5a03
commit ade7539fde
22 files changed
+700 -609

No files matched your search

+24 -123
View File
@@ -19,39 +19,19 @@ namespace UnityExplorer
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer";
#if ML
public static string EXPLORER_FOLDER = Path.Combine("Mods", NAME);
#elif BIE
public static string EXPLORER_FOLDER = Path.Combine(BepInEx.Paths.ConfigPath, NAME);
#elif STANDALONE
public static string EXPLORER_FOLDER
{
get
{
if (s_explorerFolder == null)
{
s_explorerFolder = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
s_explorerFolder = Uri.UnescapeDataString(s_explorerFolder);
s_explorerFolder = Path.GetDirectoryName(s_explorerFolder);
}
return s_explorerFolder;
}
}
private static string s_explorerFolder;
#endif
public static ExplorerCore Instance { get; private set; }
public static bool ShowMenu
{
get => s_showMenu;
set => SetShowMenu(value);
}
public static bool s_showMenu;
private static IExplorerLoader s_loader;
public static IExplorerLoader Loader => s_loader
#if ML
?? (s_loader = ExplorerMelonMod.Instance);
#elif BIE
?? (s_loader = ExplorerBepInPlugin.Instance);
#elif STANDALONE
?? (s_loader = ExplorerStandalone.Instance);
#endif
private static bool s_doneUIInit;
private static float s_timeSinceStartup;
public static string ExplorerFolder => Loader.ExplorerFolder;
public ExplorerCore()
{
@@ -67,60 +47,29 @@ namespace UnityExplorer
ReflectionHelpers.TryLoadGameModules();
#endif
if (!Directory.Exists(EXPLORER_FOLDER))
Directory.CreateDirectory(EXPLORER_FOLDER);
if (!Directory.Exists(ExplorerFolder))
Directory.CreateDirectory(ExplorerFolder);
ModConfig.OnLoad();
ExplorerConfig.OnLoad();
InputManager.Init();
ForceUnlockCursor.Init();
SetupEvents();
ShowMenu = true;
UIManager.ShowMenu = true;
Log($"{NAME} {VERSION} initialized.");
}
public static void Update()
{
if (!s_doneUIInit)
CheckUIInit();
UIManager.CheckUIInit();
if (MouseInspector.Enabled)
MouseInspector.UpdateInspect();
else
{
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
ShowMenu = !ShowMenu;
if (ShowMenu && s_doneUIInit)
UIManager.Update();
}
}
private static void CheckUIInit()
{
s_timeSinceStartup += Time.deltaTime;
if (s_timeSinceStartup > 0.1f)
{
s_doneUIInit = true;
try
{
UIManager.Init();
Log("Initialized UnityExplorer UI.");
if (ModConfig.Instance.Hide_On_Startup)
ShowMenu = false;
// InspectorManager.Instance.Inspect(Tests.TestClass.Instance);
}
catch (Exception e)
{
LogWarning($"Exception setting up UI: {e}");
}
}
UIManager.Update();
}
private void SetupEvents()
@@ -129,10 +78,14 @@ namespace UnityExplorer
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 { }
catch (Exception ex)
{
LogWarning($"Exception setting up Unity event listeners!\r\n{ex}");
}
#else
Application.logMessageReceived += OnUnityLog;
SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); };
@@ -145,23 +98,6 @@ namespace UnityExplorer
UIManager.OnSceneChange();
}
private static void SetShowMenu(bool show)
{
s_showMenu = show;
if (UIManager.CanvasRoot)
{
UIManager.CanvasRoot.SetActive(show);
if (show)
ForceUnlockCursor.SetEventSystem();
else
ForceUnlockCursor.ReleaseEventSystem();
}
ForceUnlockCursor.UpdateCursorControl();
}
private void OnUnityLog(string message, string stackTrace, LogType type)
{
if (!DebugConsole.LogUnity)
@@ -185,12 +121,6 @@ namespace UnityExplorer
}
}
#if STANDALONE
public static Action<string> OnLogMessage;
public static Action<string> OnLogWarning;
public static Action<string> OnLogError;
#endif
public static void Log(object message, bool unity = false)
{
DebugConsole.Log(message?.ToString());
@@ -198,13 +128,7 @@ namespace UnityExplorer
if (unity)
return;
#if ML
MelonLoader.MelonLogger.Msg(message?.ToString());
#elif BIE
ExplorerBepInPlugin.Logging?.LogMessage(message?.ToString());
#elif STANDALONE
OnLogMessage?.Invoke(message?.ToString());
#endif
Loader.OnLogMessage(message);
}
public static void LogWarning(object message, bool unity = false)
@@ -214,13 +138,7 @@ namespace UnityExplorer
if (unity)
return;
#if ML
MelonLoader.MelonLogger.Msg(message?.ToString());
#elif BIE
ExplorerBepInPlugin.Logging?.LogWarning(message?.ToString());
#elif STANDALONE
OnLogWarning?.Invoke(message?.ToString());
#endif
Loader.OnLogWarning(message);
}
public static void LogError(object message, bool unity = false)
@@ -230,24 +148,7 @@ namespace UnityExplorer
if (unity)
return;
#if ML
MelonLoader.MelonLogger.Msg(message?.ToString());
#elif BIE
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
#elif STANDALONE
OnLogError?.Invoke(message?.ToString());
#endif
}
public static string RemoveInvalidFilenameChars(string s)
{
var invalid = System.IO.Path.GetInvalidFileNameChars();
foreach (var c in invalid)
{
s = s.Replace(c.ToString(), "");
}
return s;
Loader.OnLogError(message);
}
}
}