From 1c58a38800460090f23322011dd516bcf60979ce Mon Sep 17 00:00:00 2001 From: Benedikt Werner <1benediktwerner@gmail.com> Date: Tue, 17 Nov 2020 16:20:47 +0100 Subject: [PATCH] Force-unblock Rewired keyboard when ConfigManager closes --- src/Plugin.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Plugin.cs b/src/Plugin.cs index 0686a27..7dc6333 100644 --- a/src/Plugin.cs +++ b/src/Plugin.cs @@ -30,7 +30,8 @@ void Awake() } - void Start() { + void Start() + { var configManagerAssembly = AppDomain.CurrentDomain .GetAssemblies() .SingleOrDefault(assembly => assembly.GetName().Name.Equals(CONFIG_MANAGER_ASSEMBLY_NAME, StringComparison.OrdinalIgnoreCase)); @@ -55,23 +56,30 @@ void SetupClickBlocker() } Logger.LogInfo("Found BepInEx.ConfigurationManager. Setting up mouse input block when opened."); - configManager.DisplayingWindowChanged += (_, displayWindow) => BlockClicks(displayWindow.NewValue); + configManager.DisplayingWindowChanged += (_, displayWindow) => + { + BlockClicks(displayWindow.NewValue); + if (hasRewired && !displayWindow.NewValue) + { + GUIUtility.keyboardControl = 0; + BlockKeyboard(false); + } + }; } void OnGUI() { if (!hasRewired) return; - PerformBlock(); + BlockKeyboard(GUIUtility.keyboardControl != 0); } // Leave this in a separate method to avoid problems if Rewired is not loaded - static void PerformBlock() + static void BlockKeyboard(bool block) { - var canBeEnabled = GUIUtility.keyboardControl == 0; var keyboard = Rewired.ReInput.controllers.Keyboard; - if (keyboard.enabled == canBeEnabled) return; + if (keyboard.enabled != block) return; if (keyboard.enabled) { keyboard.enabled = false;