From 1a26623080e263f9f9d1943aff965bbc927ba605 Mon Sep 17 00:00:00 2001 From: Sinai Date: Wed, 26 May 2021 18:02:10 +1000 Subject: [PATCH] Add option to disable EventSystem override --- src/Core/Config/ConfigManager.cs | 7 ++++++- src/Core/Input/CursorUnlocker.cs | 36 ++++++++++++++------------------ src/UI/UIManager.cs | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Core/Config/ConfigManager.cs b/src/Core/Config/ConfigManager.cs index 8489f7c..819c7b2 100644 --- a/src/Core/Config/ConfigManager.cs +++ b/src/Core/Config/ConfigManager.cs @@ -21,6 +21,7 @@ namespace UnityExplorer.Core.Config public static ConfigElement Force_Unlock_Mouse; public static ConfigElement Force_Unlock_Toggle; public static ConfigElement Aggressive_Mouse_Unlock; + public static ConfigElement Disable_EventSystem_Override; public static ConfigElement Default_Output_Path; public static ConfigElement Log_Unity_Debug; public static ConfigElement Hide_On_Startup; @@ -93,7 +94,11 @@ namespace UnityExplorer.Core.Config KeyCode.None); Aggressive_Mouse_Unlock = new ConfigElement("Aggressive Mouse Unlock", - "Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked (requires game restart).", + "Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked.\nRequires restart to take effect.", + false); + + Disable_EventSystem_Override = new ConfigElement("Disable EventSystem override", + "If enabled, UnityExplorer will not override the EventSystem from the game.\nMay require restart to take effect.", false); Log_Unity_Debug = new ConfigElement("Log Unity Debug", diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs index 2ea255f..f4fa575 100644 --- a/src/Core/Input/CursorUnlocker.cs +++ b/src/Core/Input/CursorUnlocker.cs @@ -37,12 +37,15 @@ namespace UnityExplorer.Core.Input lastVisibleState = Cursor.visible; SetupPatches(); - UpdateCursorControl(); + // Hook up config values + + // Force Unlock Mouse Unlock = ConfigManager.Force_Unlock_Mouse.Value; ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; }; + // Aggressive Mouse Unlock if (ConfigManager.Aggressive_Mouse_Unlock.Value) SetupAggressiveUnlock(); } @@ -83,7 +86,7 @@ namespace UnityExplorer.Core.Input Cursor.lockState = CursorLockMode.None; Cursor.visible = true; - if (UIManager.EventSys) + if (!ConfigManager.Disable_EventSystem_Override.Value && UIManager.EventSys) SetEventSystem(); } else @@ -91,7 +94,7 @@ namespace UnityExplorer.Core.Input Cursor.lockState = lastLockMode; Cursor.visible = lastVisibleState; - if (UIManager.EventSys) + if (!ConfigManager.Disable_EventSystem_Override.Value && UIManager.EventSys) ReleaseEventSystem(); } @@ -160,26 +163,19 @@ namespace UnityExplorer.Core.Input public static void Prefix_EventSystem_set_current(ref EventSystem value) { - if (!UIManager.EventSys) - { - if (value) - { - lastEventSystem = value; - lastInputModule = value.currentInputModule; - } - return; - } - - if (!settingEventSystem && value != UIManager.EventSys) + if (!settingEventSystem && value) { lastEventSystem = value; - lastInputModule = value?.currentInputModule; + lastInputModule = value.currentInputModule; + } - if (ShouldActuallyUnlock) - { - value = UIManager.EventSys; - value.enabled = true; - } + if (!UIManager.EventSys) + return; + + if (!settingEventSystem && ShouldActuallyUnlock && !ConfigManager.Disable_EventSystem_Override.Value) + { + value = UIManager.EventSys; + value.enabled = true; } } diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index caec768..80e3a01 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -145,7 +145,7 @@ namespace UnityExplorer.UI if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Toggle.Value)) CursorUnlocker.Unlock = !CursorUnlocker.Unlock; - if (EventSystem.current != EventSys) + if (!ConfigManager.Disable_EventSystem_Override.Value && EventSystem.current != EventSys) CursorUnlocker.SetEventSystem(); UIPanel.UpdateFocus();