2022-03-29 22:36:17 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
using UnityEngine;
|
2022-01-17 19:42:05 +11:00
|
|
|
|
using UnityExplorer.Config;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.ObjectExplorer;
|
2022-01-17 19:42:05 +11:00
|
|
|
|
using UnityExplorer.Runtime;
|
2022-03-21 01:05:00 +11:00
|
|
|
|
using UnityExplorer.UI;
|
|
|
|
|
using UnityExplorer.UI.Panels;
|
2022-03-29 22:36:17 +11:00
|
|
|
|
using UniverseLib;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib.Input;
|
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
|
|
|
|
{
|
2021-04-28 20:47:48 +10:00
|
|
|
|
public static class ExplorerCore
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-11-13 18:46:36 +11:00
|
|
|
|
public const string NAME = "UnityExplorer";
|
2022-04-20 18:47:23 +10:00
|
|
|
|
public const string VERSION = "4.7.5";
|
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-30 19:50:04 +11:00
|
|
|
|
public static IExplorerLoader Loader { get; private set; }
|
2022-04-12 00:26:01 +10:00
|
|
|
|
public static string ExplorerFolder => Path.Combine(Loader.ExplorerFolderDestination, Loader.ExplorerFolderName);
|
|
|
|
|
public const string DEFAULT_EXPLORER_FOLDER_NAME = "sinai-dev-UnityExplorer";
|
2020-11-08 21:04:41 +11:00
|
|
|
|
|
2021-11-20 18:57:53 +11:00
|
|
|
|
public static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID);
|
2021-07-21 04:14:12 +10:00
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize UnityExplorer with the provided Loader implementation.
|
|
|
|
|
/// </summary>
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static void Init(IExplorerLoader loader)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2021-04-28 20:47:48 +10:00
|
|
|
|
if (Loader != null)
|
2022-03-29 22:36:17 +11:00
|
|
|
|
throw new Exception("UnityExplorer is already loaded.");
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Loader = loader;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2021-05-14 02:45:59 +10:00
|
|
|
|
Log($"{NAME} {VERSION} initializing...");
|
|
|
|
|
|
2022-04-12 00:26:01 +10:00
|
|
|
|
CheckLegacyExplorerFolder();
|
|
|
|
|
Directory.CreateDirectory(ExplorerFolder);
|
2021-03-30 19:50:04 +11:00
|
|
|
|
ConfigManager.Init(Loader.ConfigHandler);
|
2022-03-29 22:36:17 +11:00
|
|
|
|
|
|
|
|
|
Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
|
2021-12-02 18:35:46 +11:00
|
|
|
|
{
|
|
|
|
|
Disable_EventSystem_Override = ConfigManager.Disable_EventSystem_Override.Value,
|
|
|
|
|
Force_Unlock_Mouse = ConfigManager.Force_Unlock_Mouse.Value,
|
|
|
|
|
Unhollowed_Modules_Folder = loader.UnhollowedModulesFolder
|
|
|
|
|
});
|
2022-04-12 02:36:12 +10:00
|
|
|
|
|
|
|
|
|
UERuntimeHelper.Init();
|
|
|
|
|
ExplorerBehaviour.Setup();
|
|
|
|
|
UnityCrashPrevention.Init();
|
2021-04-11 20:45:02 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do a delayed setup so that objects aren't destroyed instantly.
|
|
|
|
|
// This can happen for a multitude of reasons.
|
|
|
|
|
// Default delay is 1 second which is usually enough.
|
2022-03-29 22:36:17 +11:00
|
|
|
|
static void LateInit()
|
2021-04-11 20:45:02 +10:00
|
|
|
|
{
|
2021-12-02 18:35:46 +11:00
|
|
|
|
SceneHandler.Init();
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-14 02:45:59 +10:00
|
|
|
|
Log($"Creating UI...");
|
2021-05-05 21:27:09 +10:00
|
|
|
|
|
2021-05-11 20:23:52 +10:00
|
|
|
|
UIManager.InitUI();
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2022-03-29 22:36:17 +11:00
|
|
|
|
Log($"{NAME} {VERSION} ({Universe.Context}) initialized.");
|
2022-04-14 01:25:59 +10:00
|
|
|
|
|
|
|
|
|
// InspectorManager.Inspect(typeof(Tests.TestClass));
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-29 22:36:17 +11:00
|
|
|
|
internal static void Update()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2021-12-02 18:35:46 +11:00
|
|
|
|
// check master toggle
|
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Master_Toggle.Value))
|
|
|
|
|
UIManager.ShowMenu = !UIManager.ShowMenu;
|
2022-04-12 00:26:01 +10:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 05:20:35 +10:00
|
|
|
|
|
|
|
|
|
#region LOGGING
|
|
|
|
|
|
|
|
|
|
public static void Log(object message)
|
|
|
|
|
=> Log(message, LogType.Log);
|
|
|
|
|
|
|
|
|
|
public static void LogWarning(object message)
|
|
|
|
|
=> Log(message, LogType.Warning);
|
|
|
|
|
|
|
|
|
|
public static void LogError(object message)
|
|
|
|
|
=> Log(message, LogType.Error);
|
|
|
|
|
|
|
|
|
|
public static void LogUnity(object message, LogType logType)
|
|
|
|
|
{
|
|
|
|
|
if (!ConfigManager.Log_Unity_Debug.Value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Log($"[Unity] {message}", logType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Log(object message, LogType logType)
|
|
|
|
|
{
|
|
|
|
|
string log = message?.ToString() ?? "";
|
|
|
|
|
|
|
|
|
|
LogPanel.Log(log, logType);
|
|
|
|
|
|
|
|
|
|
switch (logType)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Assert:
|
|
|
|
|
case LogType.Log:
|
|
|
|
|
Loader.OnLogMessage(log);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LogType.Warning:
|
|
|
|
|
Loader.OnLogWarning(log);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LogType.Error:
|
|
|
|
|
case LogType.Exception:
|
|
|
|
|
Loader.OnLogError(log);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region LEGACY FOLDER MIGRATION
|
|
|
|
|
|
2022-04-12 00:26:01 +10:00
|
|
|
|
// Can be removed eventually. For migration from <4.7.0
|
|
|
|
|
static void CheckLegacyExplorerFolder()
|
|
|
|
|
{
|
|
|
|
|
string legacyPath = Path.Combine(Loader.ExplorerFolderDestination, "UnityExplorer");
|
|
|
|
|
if (Directory.Exists(legacyPath))
|
|
|
|
|
{
|
|
|
|
|
LogWarning($"Attempting to migrate old 'UnityExplorer/' folder to 'sinai-dev-UnityExplorer/'...");
|
2022-04-12 05:20:35 +10:00
|
|
|
|
|
2022-04-12 00:26:01 +10:00
|
|
|
|
// If new folder doesn't exist yet, let's just use Move().
|
|
|
|
|
if (!Directory.Exists(ExplorerFolder))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.Move(legacyPath, ExplorerFolder);
|
|
|
|
|
Log("Migrated successfully.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogWarning($"Exception migrating folder: {ex}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // We have to merge
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CopyAll(new(legacyPath), new(ExplorerFolder));
|
|
|
|
|
Directory.Delete(legacyPath, true);
|
|
|
|
|
Log("Migrated successfully.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogWarning($"Exception migrating folder: {ex}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
|
|
|
|
|
{
|
2022-04-12 05:20:35 +10:00
|
|
|
|
Directory.CreateDirectory(target.FullName);
|
2022-04-12 00:26:01 +10:00
|
|
|
|
|
|
|
|
|
// Copy each file into it's new directory.
|
|
|
|
|
foreach (FileInfo fi in source.GetFiles())
|
|
|
|
|
fi.MoveTo(Path.Combine(target.ToString(), fi.Name));
|
|
|
|
|
|
|
|
|
|
// Copy each subdirectory using recursion.
|
|
|
|
|
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
|
|
|
|
|
CopyAll(diSourceSubDir, nextTargetSubDir);
|
|
|
|
|
}
|
2021-05-01 20:55:14 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-05 19:36:09 +10:00
|
|
|
|
#endregion
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|