2020-08-07 22:19:03 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-08-27 18:05:55 +10:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Harmony;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
using MelonLoader;
|
2020-08-22 17:17:11 +10:00
|
|
|
|
using UnhollowerBaseLib;
|
2020-08-27 18:05:55 +10:00
|
|
|
|
using UnityEngine;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
namespace Explorer
|
|
|
|
|
{
|
|
|
|
|
public class CppExplorer : MelonMod
|
|
|
|
|
{
|
2020-08-27 18:05:55 +10:00
|
|
|
|
public const string GUID = "com.sinai.cppexplorer";
|
2020-08-31 23:28:44 +10:00
|
|
|
|
public const string VERSION = "1.5.0";
|
2020-08-07 22:19:03 +10:00
|
|
|
|
public const string AUTHOR = "Sinai";
|
|
|
|
|
|
2020-08-22 00:16:05 +10:00
|
|
|
|
public const string NAME = "CppExplorer"
|
2020-08-13 23:34:21 +10:00
|
|
|
|
#if Release_Unity2018
|
2020-08-18 17:11:58 +10:00
|
|
|
|
+ " (Unity 2018)"
|
2020-08-13 23:34:21 +10:00
|
|
|
|
#endif
|
2020-08-18 17:11:58 +10:00
|
|
|
|
;
|
2020-08-13 23:34:21 +10:00
|
|
|
|
|
2020-08-27 18:05:55 +10:00
|
|
|
|
public static CppExplorer Instance { get; private set; }
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-27 18:05:55 +10:00
|
|
|
|
public static bool ShowMenu
|
|
|
|
|
{
|
|
|
|
|
get => m_showMenu;
|
|
|
|
|
set => SetShowMenu(value);
|
|
|
|
|
}
|
|
|
|
|
private static bool m_showMenu;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-27 18:05:55 +10:00
|
|
|
|
public static bool ForceUnlockMouse
|
|
|
|
|
{
|
|
|
|
|
get => m_forceUnlock;
|
|
|
|
|
set => SetForceUnlock(value);
|
|
|
|
|
}
|
|
|
|
|
private static bool m_forceUnlock;
|
|
|
|
|
private static CursorLockMode m_lastLockMode;
|
|
|
|
|
private static bool m_lastVisibleState;
|
|
|
|
|
private static bool m_currentlySettingCursor = false;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-27 18:05:55 +10:00
|
|
|
|
public static bool ShouldForceMouse => ShowMenu && ForceUnlockMouse;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-27 18:05:55 +10:00
|
|
|
|
private static void SetShowMenu(bool show)
|
|
|
|
|
{
|
|
|
|
|
m_showMenu = show;
|
|
|
|
|
UpdateCursorControl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== MonoBehaviour methods ==========
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
public override void OnApplicationStart()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
|
|
|
|
|
new MainMenu();
|
|
|
|
|
new WindowManager();
|
|
|
|
|
|
2020-08-27 18:05:55 +10:00
|
|
|
|
// Get current cursor state and enable cursor
|
|
|
|
|
m_lastLockMode = Cursor.lockState;
|
|
|
|
|
m_lastVisibleState = Cursor.visible;
|
|
|
|
|
|
|
|
|
|
// Enable ShowMenu and ForceUnlockMouse
|
|
|
|
|
// (set m_showMenu to not call UpdateCursorState twice)
|
|
|
|
|
m_showMenu = true;
|
|
|
|
|
SetForceUnlock(true);
|
|
|
|
|
|
|
|
|
|
MelonLogger.Log($"CppExplorer {VERSION} initialized.");
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnLevelWasLoaded(int level)
|
|
|
|
|
{
|
2020-08-18 17:11:58 +10:00
|
|
|
|
ScenePage.Instance?.OnSceneChange();
|
|
|
|
|
SearchPage.Instance?.OnSceneChange();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnUpdate()
|
|
|
|
|
{
|
2020-08-27 18:05:55 +10:00
|
|
|
|
// Check main toggle key input
|
2020-08-07 22:19:03 +10:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.F7))
|
|
|
|
|
{
|
|
|
|
|
ShowMenu = !ShowMenu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ShowMenu)
|
|
|
|
|
{
|
2020-08-27 18:05:55 +10:00
|
|
|
|
// Check Force-Unlock input
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.LeftAlt))
|
2020-08-12 03:51:47 +10:00
|
|
|
|
{
|
2020-08-27 18:05:55 +10:00
|
|
|
|
ForceUnlockMouse = !ForceUnlockMouse;
|
2020-08-12 03:51:47 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 22:19:03 +10:00
|
|
|
|
MainMenu.Instance.Update();
|
|
|
|
|
WindowManager.Instance.Update();
|
2020-08-18 17:11:58 +10:00
|
|
|
|
InspectUnderMouse.Update();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnGUI()
|
|
|
|
|
{
|
|
|
|
|
MainMenu.Instance.OnGUI();
|
|
|
|
|
WindowManager.Instance.OnGUI();
|
2020-08-18 17:11:58 +10:00
|
|
|
|
InspectUnderMouse.OnGUI();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-27 18:05:55 +10:00
|
|
|
|
|
|
|
|
|
// =========== Cursor control ===========
|
|
|
|
|
|
|
|
|
|
private static void SetForceUnlock(bool unlock)
|
|
|
|
|
{
|
|
|
|
|
m_forceUnlock = unlock;
|
|
|
|
|
UpdateCursorControl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UpdateCursorControl()
|
|
|
|
|
{
|
|
|
|
|
m_currentlySettingCursor = true;
|
|
|
|
|
if (ShouldForceMouse)
|
|
|
|
|
{
|
|
|
|
|
Cursor.lockState = CursorLockMode.None;
|
|
|
|
|
Cursor.visible = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Cursor.lockState = m_lastLockMode;
|
|
|
|
|
Cursor.visible = m_lastVisibleState;
|
|
|
|
|
}
|
|
|
|
|
m_currentlySettingCursor = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Force mouse to stay unlocked and visible while UnlockMouse and ShowMenu are true.
|
|
|
|
|
// Also keep track of when anything else tries to set Cursor state, this will be the
|
|
|
|
|
// value that we set back to when we close the menu or disable force-unlock.
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Setter)]
|
|
|
|
|
public class Cursor_lockState
|
|
|
|
|
{
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
public static void Prefix(ref CursorLockMode value)
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentlySettingCursor)
|
|
|
|
|
{
|
|
|
|
|
m_lastLockMode = value;
|
|
|
|
|
|
|
|
|
|
if (ShouldForceMouse)
|
|
|
|
|
{
|
|
|
|
|
value = CursorLockMode.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Setter)]
|
|
|
|
|
public class Cursor_set_visible
|
|
|
|
|
{
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
public static void Prefix(ref bool value)
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentlySettingCursor)
|
|
|
|
|
{
|
|
|
|
|
m_lastVisibleState = value;
|
|
|
|
|
|
|
|
|
|
if (ShouldForceMouse)
|
|
|
|
|
{
|
|
|
|
|
value = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
// Make it appear as though UnlockMouse is disabled to the rest of the application.
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Getter)]
|
|
|
|
|
public class Cursor_get_visible
|
|
|
|
|
{
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void Postfix(ref bool __result)
|
|
|
|
|
{
|
|
|
|
|
if (ShouldForceMouse)
|
|
|
|
|
{
|
|
|
|
|
__result = m_lastVisibleState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Getter)]
|
|
|
|
|
public class Cursor_get_lockState
|
|
|
|
|
{
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void Postfix(ref CursorLockMode __result)
|
|
|
|
|
{
|
|
|
|
|
if (ShouldForceMouse)
|
|
|
|
|
{
|
|
|
|
|
__result = m_lastLockMode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|