diff --git a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index ca7f316176..2a56072e53 100644 --- a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -165,7 +165,8 @@ namespace BizHawk.Emulation.Common List list = new List(FloatControls); list.AddRange(BoolButtons); - List[] ret = new List[9]; + // starts with console buttons, then each plasyer's buttons individually + List[] ret = new List[PlayerCount + 1]; for (int i = 0; i < ret.Length; i++) { ret[i] = new List(); @@ -182,16 +183,18 @@ namespace BizHawk.Emulation.Common public int PlayerNumber(string buttonName) { - int player = 0; - if (buttonName.Length > 3 && buttonName.StartsWith("P") && char.IsNumber(buttonName[1])) + var match = PlayerRegex.Match(buttonName); + if (match.Success) { - player = buttonName[1] - '0'; + return int.Parse(match.Groups[1].Value); + } + else + { + return 0; } - - return player; } - private static readonly Regex PlayerRegex = new Regex("^P(\\d) "); + private static readonly Regex PlayerRegex = new Regex("^P(\\d+) "); public int PlayerCount { @@ -199,9 +202,7 @@ namespace BizHawk.Emulation.Common { var allNames = FloatControls.Concat(BoolButtons).ToList(); var player = allNames - .Select(s => PlayerRegex.Match(s).Groups[1]) - .Where(group => group.Success) - .Select(group => group.Value[0] - '0') + .Select(PlayerNumber) .DefaultIfEmpty(0) .Max();