Skip to content

Commit

Permalink
Force-unblock Rewired keyboard when ConfigManager closes
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktwerner committed Nov 17, 2020
1 parent a7e43da commit 1c58a38
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down

0 comments on commit 1c58a38

Please sign in to comment.