From 7999a973f38b6417e2378dac54dc316bda26b20f Mon Sep 17 00:00:00 2001 From: uncavo-hdmi Date: Tue, 4 Feb 2025 14:51:48 +0100 Subject: [PATCH] update GetOrderedConfig to return if new controllers connected and conditionally update configuration --- src/Ryujinx/AutoAssignController.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx/AutoAssignController.cs b/src/Ryujinx/AutoAssignController.cs index 06c636dc2..78b35fd65 100644 --- a/src/Ryujinx/AutoAssignController.cs +++ b/src/Ryujinx/AutoAssignController.cs @@ -42,7 +42,7 @@ namespace Ryujinx.Ava List controllers = _inputManager.GamepadDriver.GetGamepads().ToList(); List oldConfig = _configurationState.Hid.InputConfig.Value.Where(x => x != null).ToList(); - List newConfig = GetOrderedConfig(controllers, oldConfig); + (List newConfig, bool hasNewControllersConnected) = GetOrderedConfig(controllers, oldConfig); int index = 0; foreach (var config in newConfig) @@ -53,9 +53,12 @@ namespace Ryujinx.Ava _viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse); - _configurationState.Hid.InputConfig.Value = newConfig; - - ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); + // update the configuration state only if there are more controllers than before + if(hasNewControllersConnected) + { + _configurationState.Hid.InputConfig.Value = newConfig; + ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); + } } private void HandleOnGamepadConnected(string id) @@ -70,9 +73,10 @@ namespace Ryujinx.Ava RefreshControllers(); } - private List GetOrderedConfig(List controllers, List oldConfig) + private (List, bool) GetOrderedConfig(List controllers, List oldConfig) { Dictionary playerIndexMap = new(); + int existingControllers = 0; // Convert oldConfig into a dictionary for quick lookup by controller Id Dictionary oldConfigMap = oldConfig.ToDictionary(x => x.Id, x => x); @@ -86,6 +90,8 @@ namespace Ryujinx.Ava { // Use the existing PlayerIndex from oldConfig and add it to the map playerIndexMap[(int)existingConfig.PlayerIndex] = existingConfig; + + existingControllers++; } else { @@ -106,8 +112,8 @@ namespace Ryujinx.Ava } } - // Return the sorted list of InputConfigs, ordered by PlayerIndex - return playerIndexMap.OrderBy(x => x.Key).Select(x => x.Value).ToList(); + // Return the sorted list of InputConfigs, ordered by PlayerIndex, and a bool indicating if new controllers were connected + return (playerIndexMap.OrderBy(x => x.Key).Select(x => x.Value).ToList(), controllers.Count > existingControllers); } private InputConfig CreateConfigFromController(IGamepad controller)