From 852ca8e9eb3abe313c8c3003a56467db708edc72 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:28:54 +1100 Subject: [PATCH] New attempt at fixing conflicting EventSystem problems in IL2CPP --- src/ExplorerCore.cs | 2 +- src/UI/ForceUnlockCursor.cs | 22 ++++++++++++++++------ src/UI/UIManager.cs | 25 +++---------------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index adb050b..4194b97 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -16,7 +16,7 @@ namespace UnityExplorer public class ExplorerCore { public const string NAME = "UnityExplorer"; - public const string VERSION = "3.1.1"; + public const string VERSION = "3.1.2"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.unityexplorer"; public const string EXPLORER_FOLDER = @"Mods\UnityExplorer"; diff --git a/src/UI/ForceUnlockCursor.cs b/src/UI/ForceUnlockCursor.cs index c09c1fa..67631ba 100644 --- a/src/UI/ForceUnlockCursor.cs +++ b/src/UI/ForceUnlockCursor.cs @@ -87,12 +87,6 @@ namespace UnityExplorer.UI new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_visible))), true); -#if BIE -#if CPP - // temporarily disabling this patch in BepInEx il2cpp as it's causing a crash in some games. - return; -#endif -#endif TryPatch(typeof(EventSystem), "current", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_EventSystem_set_current))), @@ -164,9 +158,22 @@ namespace UnityExplorer.UI public static void SetEventSystem() { + // temp disabled for new InputSystem if (InputManager.CurrentType == InputType.InputSystem) return; + // Disable current event system object + if (m_lastEventSystem || EventSystem.current) + { + if (!m_lastEventSystem) + m_lastEventSystem = EventSystem.current; + + //ExplorerCore.Log("Disabling current event system..."); + m_lastEventSystem.enabled = false; + m_lastEventSystem.gameObject.SetActive(false); + } + + // Set to our current system m_settingEventSystem = true; EventSystem.current = UIManager.EventSys; InputManager.ActivateUIModule(); @@ -180,6 +187,9 @@ namespace UnityExplorer.UI if (m_lastEventSystem) { + m_lastEventSystem.enabled = true; + m_lastEventSystem.gameObject.SetActive(true); + m_settingEventSystem = true; EventSystem.current = m_lastEventSystem; m_lastInputModule?.ActivateModule(); diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 104d4ba..cf4a826 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -45,10 +45,6 @@ namespace UnityExplorer.UI SceneExplorer.Instance?.OnSceneChange(); SearchPage.Instance?.OnSceneChange(); } - -#if CPP - internal static float s_timeOfLastClick; -#endif public static void Update() { MainMenu.Instance?.Update(); @@ -56,35 +52,20 @@ namespace UnityExplorer.UI if (EventSys) { if (EventSystem.current != EventSys) - { ForceUnlockCursor.SetEventSystem(); - } - #if CPP - // Fix for games which override the InputModule pointer events (eg, VRChat) + // Some IL2CPP games behave weird with multiple UI Input Systems, some fixes for them. var evt = InputManager.InputPointerEvent; if (evt != null) { - if (Time.realtimeSinceStartup - s_timeOfLastClick > 0.1f) - { - s_timeOfLastClick = Time.realtimeSinceStartup; - - if (!evt.eligibleForClick && evt.selectedObject) - evt.eligibleForClick = true; - } - else - { - if (evt.eligibleForClick) - evt.eligibleForClick = false; - } + if (!evt.eligibleForClick && evt.selectedObject) + evt.eligibleForClick = true; } #endif } if (PanelDragger.Instance != null) - { PanelDragger.Instance.Update(); - } for (int i = 0; i < SliderScrollbar.Instances.Count; i++) {