2020-10-23 19:55:02 +11:00
|
|
|
|
using System;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.Config;
|
|
|
|
|
using UnityExplorer.Input;
|
|
|
|
|
using UnityExplorer.UI;
|
2020-11-05 17:33:04 +11:00
|
|
|
|
using UnityExplorer.UI.PageModel;
|
2020-10-08 06:15:42 +11:00
|
|
|
|
using UnityEngine;
|
2020-11-06 20:42:16 +11:00
|
|
|
|
using UnityExplorer.Inspectors;
|
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-03 20:59:13 +11:00
|
|
|
|
public const string NAME = "UnityExplorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")";
|
2020-10-28 20:52:40 +11:00
|
|
|
|
public const string VERSION = "3.0.0";
|
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";
|
2020-09-27 22:52:08 +10:00
|
|
|
|
|
|
|
|
|
public const string PLATFORM =
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#if CPP
|
2020-09-27 22:52:08 +10:00
|
|
|
|
"Il2Cpp";
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#else
|
2020-09-27 22:52:08 +10:00
|
|
|
|
"Mono";
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#endif
|
2020-10-01 18:57:28 +10:00
|
|
|
|
public const string MODLOADER =
|
|
|
|
|
#if ML
|
|
|
|
|
"MelonLoader";
|
|
|
|
|
#else
|
|
|
|
|
"BepInEx";
|
|
|
|
|
#endif
|
2020-08-13 23:34:21 +10:00
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
public static ExplorerCore Instance { get; private set; }
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-10-23 01:50:33 +11:00
|
|
|
|
public static bool ShowMenu
|
|
|
|
|
{
|
|
|
|
|
get => m_showMenu;
|
|
|
|
|
set => SetShowMenu(value);
|
|
|
|
|
}
|
|
|
|
|
public static bool m_showMenu;
|
|
|
|
|
|
|
|
|
|
private static bool m_doneUIInit;
|
2020-10-23 20:40:44 +11:00
|
|
|
|
private static float m_timeSinceStartup;
|
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-09-10 20:31:09 +10:00
|
|
|
|
ModConfig.OnLoad();
|
|
|
|
|
|
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-10-27 00:54:08 +11:00
|
|
|
|
#if CPP
|
|
|
|
|
Application.add_logMessageReceived(new Action<string, string, LogType>(LogCallback));
|
|
|
|
|
#else
|
|
|
|
|
Application.logMessageReceived += LogCallback;
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-10-08 06:15:42 +11:00
|
|
|
|
ShowMenu = true;
|
|
|
|
|
|
|
|
|
|
Log($"{NAME} initialized.");
|
2020-10-24 20:18:42 +11:00
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
private static void SetShowMenu(bool show)
|
|
|
|
|
{
|
|
|
|
|
m_showMenu = show;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-23 01:50:33 +11:00
|
|
|
|
if (UIManager.CanvasRoot)
|
|
|
|
|
{
|
|
|
|
|
UIManager.CanvasRoot.SetActive(show);
|
|
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
|
ForceUnlockCursor.SetEventSystem();
|
|
|
|
|
else
|
|
|
|
|
ForceUnlockCursor.ReleaseEventSystem();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 06:15:42 +11:00
|
|
|
|
ForceUnlockCursor.UpdateCursorControl();
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Update()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-10-23 20:40:44 +11:00
|
|
|
|
if (!m_doneUIInit)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
CheckUIInit();
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2020-11-06 20:42:16 +11:00
|
|
|
|
if (MouseInspector.Enabled)
|
|
|
|
|
{
|
|
|
|
|
MouseInspector.UpdateInspect();
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-11-06 20:42:16 +11:00
|
|
|
|
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
|
|
|
|
ShowMenu = !ShowMenu;
|
|
|
|
|
|
|
|
|
|
if (ShowMenu)
|
|
|
|
|
{
|
|
|
|
|
ForceUnlockCursor.Update();
|
|
|
|
|
UIManager.Update();
|
|
|
|
|
}
|
2020-10-11 20:49:14 +11:00
|
|
|
|
}
|
2020-08-30 01:08:48 +10:00
|
|
|
|
}
|
2020-09-27 22:04:23 +10:00
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
private static void CheckUIInit()
|
|
|
|
|
{
|
|
|
|
|
m_timeSinceStartup += Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
if (m_timeSinceStartup > 0.1f)
|
|
|
|
|
{
|
|
|
|
|
m_doneUIInit = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
UIManager.Init();
|
2020-11-03 20:59:13 +11:00
|
|
|
|
Log("Initialized UnityExplorer UI.");
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
LogWarning($"Exception setting up UI: {e}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
public static void OnSceneChange()
|
|
|
|
|
{
|
2020-10-23 01:50:33 +11:00
|
|
|
|
UIManager.OnSceneChange();
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
private void LogCallback(string message, string stackTrace, LogType type)
|
|
|
|
|
{
|
|
|
|
|
if (!DebugConsole.LogUnity)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
message = $"[UNITY] {message}";
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Assert:
|
|
|
|
|
case LogType.Log:
|
|
|
|
|
Log(message);
|
|
|
|
|
break;
|
|
|
|
|
case LogType.Warning:
|
|
|
|
|
LogWarning(message);
|
|
|
|
|
break;
|
|
|
|
|
case LogType.Exception:
|
|
|
|
|
case LogType.Error:
|
|
|
|
|
LogError(message);
|
|
|
|
|
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;
|
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#if ML
|
2020-10-12 20:15:41 +11:00
|
|
|
|
MelonLoader.MelonLogger.Log(message?.ToString());
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#else
|
2020-10-12 20:15:41 +11:00
|
|
|
|
ExplorerBepInPlugin.Logging?.LogMessage(message?.ToString());
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#if ML
|
2020-10-12 20:15:41 +11:00
|
|
|
|
MelonLoader.MelonLogger.LogWarning(message?.ToString());
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#else
|
2020-10-27 00:54:08 +11:00
|
|
|
|
ExplorerBepInPlugin.Logging?.LogWarning(message?.ToString());
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#if ML
|
2020-10-12 20:15:41 +11:00
|
|
|
|
MelonLoader.MelonLogger.LogError(message?.ToString());
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#else
|
2020-10-27 00:54:08 +11:00
|
|
|
|
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|