New attempt at fixing conflicting EventSystem problems in IL2CPP

This commit is contained in:
sinaioutlander 2020-12-16 14:28:54 +11:00
parent 7386eca0c2
commit 852ca8e9eb
3 changed files with 20 additions and 29 deletions

View File

@ -16,7 +16,7 @@ namespace UnityExplorer
public class ExplorerCore public class ExplorerCore
{ {
public const string NAME = "UnityExplorer"; 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 AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer"; public const string GUID = "com.sinai.unityexplorer";
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer"; public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";

View File

@ -87,12 +87,6 @@ namespace UnityExplorer.UI
new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_visible))), new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_visible))),
true); 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), TryPatch(typeof(EventSystem),
"current", "current",
new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_EventSystem_set_current))), new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_EventSystem_set_current))),
@ -164,9 +158,22 @@ namespace UnityExplorer.UI
public static void SetEventSystem() public static void SetEventSystem()
{ {
// temp disabled for new InputSystem
if (InputManager.CurrentType == InputType.InputSystem) if (InputManager.CurrentType == InputType.InputSystem)
return; 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; m_settingEventSystem = true;
EventSystem.current = UIManager.EventSys; EventSystem.current = UIManager.EventSys;
InputManager.ActivateUIModule(); InputManager.ActivateUIModule();
@ -180,6 +187,9 @@ namespace UnityExplorer.UI
if (m_lastEventSystem) if (m_lastEventSystem)
{ {
m_lastEventSystem.enabled = true;
m_lastEventSystem.gameObject.SetActive(true);
m_settingEventSystem = true; m_settingEventSystem = true;
EventSystem.current = m_lastEventSystem; EventSystem.current = m_lastEventSystem;
m_lastInputModule?.ActivateModule(); m_lastInputModule?.ActivateModule();

View File

@ -45,10 +45,6 @@ namespace UnityExplorer.UI
SceneExplorer.Instance?.OnSceneChange(); SceneExplorer.Instance?.OnSceneChange();
SearchPage.Instance?.OnSceneChange(); SearchPage.Instance?.OnSceneChange();
} }
#if CPP
internal static float s_timeOfLastClick;
#endif
public static void Update() public static void Update()
{ {
MainMenu.Instance?.Update(); MainMenu.Instance?.Update();
@ -56,35 +52,20 @@ namespace UnityExplorer.UI
if (EventSys) if (EventSys)
{ {
if (EventSystem.current != EventSys) if (EventSystem.current != EventSys)
{
ForceUnlockCursor.SetEventSystem(); ForceUnlockCursor.SetEventSystem();
}
#if CPP #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; var evt = InputManager.InputPointerEvent;
if (evt != null) if (evt != null)
{ {
if (Time.realtimeSinceStartup - s_timeOfLastClick > 0.1f)
{
s_timeOfLastClick = Time.realtimeSinceStartup;
if (!evt.eligibleForClick && evt.selectedObject) if (!evt.eligibleForClick && evt.selectedObject)
evt.eligibleForClick = true; evt.eligibleForClick = true;
} }
else
{
if (evt.eligibleForClick)
evt.eligibleForClick = false;
}
}
#endif #endif
} }
if (PanelDragger.Instance != null) if (PanelDragger.Instance != null)
{
PanelDragger.Instance.Update(); PanelDragger.Instance.Update();
}
for (int i = 0; i < SliderScrollbar.Instances.Count; i++) for (int i = 0; i < SliderScrollbar.Instances.Count; i++)
{ {