diff --git a/src/Core/Config/ConfigManager.cs b/src/Core/Config/ConfigManager.cs index 44d1ee0..8ab401a 100644 --- a/src/Core/Config/ConfigManager.cs +++ b/src/Core/Config/ConfigManager.cs @@ -19,6 +19,7 @@ namespace UnityExplorer.Core.Config public static ConfigElement Main_Menu_Toggle; public static ConfigElement Force_Unlock_Mouse; + public static ConfigElement Aggressive_Force_Unlock; public static ConfigElement Default_Tab; public static ConfigElement Default_Page_Limit; public static ConfigElement Default_Output_Path; @@ -78,6 +79,10 @@ namespace UnityExplorer.Core.Config "Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.", true); + Aggressive_Force_Unlock = new ConfigElement("Aggressive Mouse Unlock", + "Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked (requires game restart).", + false); + Default_Page_Limit = new ConfigElement("Default Page Limit", "The default maximum number of elements per 'page' in UnityExplorer.", 25); diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs index ab5dc9a..d5733e7 100644 --- a/src/Core/Input/CursorUnlocker.cs +++ b/src/Core/Input/CursorUnlocker.cs @@ -7,6 +7,7 @@ using BF = System.Reflection.BindingFlags; using UnityExplorer.Core.Config; using UnityExplorer.Core; using UnityExplorer.UI; +using System.Collections; #if ML using Harmony; #else @@ -48,6 +49,36 @@ namespace UnityExplorer.Core.Input Unlock = ConfigManager.Force_Unlock_Mouse.Value; ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; }; + + if (ConfigManager.Aggressive_Force_Unlock.Value) + SetupAggressiveUnlock(); + } + + public static void SetupAggressiveUnlock() + { + try + { + RuntimeProvider.Instance.StartCoroutine(AggressiveUnlockCoroutine()); + } + catch (Exception ex) + { + ExplorerCore.LogWarning($"Exception setting up Camera.onPostRender callback: {ex}"); + } + } + + private static readonly WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame(); + + private static IEnumerator AggressiveUnlockCoroutine() + { + while (true) + { + ExplorerCore.Log("Yielding end of frame"); + yield return _waitForEndOfFrame; + ExplorerCore.Log("Yielded"); + + if (UIManager.ShowMenu) + UpdateCursorControl(); + } } public static void UpdateCursorControl() diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 47b7cff..e72dfd4 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -14,7 +14,7 @@ namespace UnityExplorer public class ExplorerCore { public const string NAME = "UnityExplorer"; - public const string VERSION = "3.3.12"; + public const string VERSION = "3.3.13"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.unityexplorer";