Add keybind for mouse unlock, and aggressive unlock mode

This commit is contained in:
Sinai 2021-04-16 18:24:31 +10:00
parent 0f69833283
commit 9bdcccaaa1
7 changed files with 62 additions and 6 deletions

View File

@ -18,6 +18,8 @@ namespace UnityExplorer.Core.Config
public static ConfigElement<KeyCode> Main_Menu_Toggle;
public static ConfigElement<bool> Force_Unlock_Mouse;
public static ConfigElement<KeyCode> Force_Unlock_Keybind;
public static ConfigElement<bool> Aggressive_Force_Unlock;
//public static ConfigElement<MenuPages> Default_Tab;
public static ConfigElement<int> Default_Page_Limit;
public static ConfigElement<string> Default_Output_Path;
@ -76,6 +78,18 @@ namespace UnityExplorer.Core.Config
"Should UnityExplorer be hidden on startup?",
false);
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
true);
Force_Unlock_Keybind = new ConfigElement<KeyCode>("Force Unlock Keybind",
"The keybind to toggle the 'Force Unlock Mouse' setting. Only usable when UnityExplorer is open.",
KeyCode.F6);
Aggressive_Force_Unlock = new ConfigElement<bool>("Aggressive Mouse Unlock",
"Use Camera.onPostRender callback to aggressively force the Mouse to be unlocked (requires game restart).",
false);
//Default_Tab = new ConfigElement<MenuPages>("Default Tab",
// "The default menu page when starting the game.",
// MenuPages.Home);
@ -84,10 +98,6 @@ namespace UnityExplorer.Core.Config
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
false);
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
true);
Default_Page_Limit = new ConfigElement<int>("Default Page Limit",
"The default maximum number of elements per 'page' in UnityExplorer.",
25);

View File

@ -41,6 +41,9 @@ namespace UnityExplorer.Core.Input
public static void Init()
{
if (ConfigManager.Aggressive_Force_Unlock.Value)
RuntimeProvider.Instance.SetupCameraDelegate();
SetupPatches();
UpdateCursorControl();
@ -49,6 +52,20 @@ namespace UnityExplorer.Core.Input
ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; };
}
public static void OnCameraPostRender(Camera _)
{
if (!UIManager.ShowMenu)
return;
UpdateIfNeeded();
}
public static void UpdateIfNeeded()
{
if ((!ShouldActuallyUnlock && (Cursor.visible || Cursor.lockState == CursorLockMode.None))
|| (ShouldActuallyUnlock && (!Cursor.visible || Cursor.lockState != CursorLockMode.None)))
UpdateCursorControl();
}
public static void UpdateCursorControl()
{
try

View File

@ -26,6 +26,24 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
TextureUtil = new Il2CppTextureUtil();
}
public override void SetupCameraDelegate()
{
try
{
var action = new Action<Camera>(CursorUnlocker.OnCameraPostRender);
var _delegate = DelegateSupport.ConvertDelegate<Camera.CameraCallback>(action);
if (Camera.onPostRender == null)
Camera.onPostRender = _delegate;
else
Camera.onPostRender = Camera.onPostRender.CombineImpl(_delegate).TryCast<Camera.CameraCallback>();
}
catch (Exception ex)
{
ExplorerCore.LogWarning($"Exception setting up Camera.onPostRender callback: {ex}");
}
}
public override void SetupEvents()
{
try

View File

@ -12,6 +12,7 @@ using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityExplorer.Core;
using UnityExplorer.Core.CSharp;
using UnityExplorer.Core.Input;
namespace UnityExplorer.Core.Runtime.Mono
{
@ -26,6 +27,11 @@ namespace UnityExplorer.Core.Runtime.Mono
DummyBehaviour.Setup();
}
public override void SetupCameraDelegate()
{
Camera.onPostRender += CursorUnlocker.OnCameraPostRender;
}
public override void SetupEvents()
{
Application.logMessageReceived += Application_logMessageReceived;

View File

@ -35,6 +35,8 @@ namespace UnityExplorer
public abstract void Initialize();
public abstract void SetupCameraDelegate();
public abstract void SetupEvents();
public abstract void StartCoroutine(IEnumerator routine);

View File

@ -80,7 +80,7 @@ namespace UnityExplorer
UIManager.Update();
}
#region LOGGING
#region LOGGING
public static void Log(object message)
=> Log(message, LogType.Log, false);
@ -119,6 +119,6 @@ namespace UnityExplorer
}
}
#endregion
#endregion
}
}

View File

@ -83,6 +83,9 @@ namespace UnityExplorer.UI
if (!ShowMenu)
return;
if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Keybind.Value))
CursorUnlocker.Unlock = !CursorUnlocker.Unlock;
UIBehaviourModel.UpdateInstances();
if (EventSystem.current != EventSys)