diff --git a/BizHawk.Client.EmuHawk/Input/GamePad.cs b/BizHawk.Client.EmuHawk/Input/GamePad.cs index a743ed2ec7..76cc1355cc 100644 --- a/BizHawk.Client.EmuHawk/Input/GamePad.cs +++ b/BizHawk.Client.EmuHawk/Input/GamePad.cs @@ -37,7 +37,7 @@ namespace BizHawk.Client.EmuHawk } joystick.Acquire(); - GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick); + GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick, _devices.Count); _devices.Add(p); } } @@ -90,11 +90,12 @@ namespace BizHawk.Client.EmuHawk readonly Joystick joystick; JoystickState state = new JoystickState(); - GamePad(string name, Guid guid, Joystick joystick) + GamePad(string name, Guid guid, Joystick joystick, int index) { this.name = name; this.guid = guid; this.joystick = joystick; + PlayerNumber = index + 1; Update(); InitializeCallbacks(); } @@ -134,7 +135,7 @@ namespace BizHawk.Client.EmuHawk public string Name { get { return name; } } public Guid Guid { get { return guid; } } - + public int PlayerNumber { get; private set; } public string ButtonName(int index) { diff --git a/BizHawk.Client.EmuHawk/Input/GamePad360.cs b/BizHawk.Client.EmuHawk/Input/GamePad360.cs index cff607802e..65ae025514 100644 --- a/BizHawk.Client.EmuHawk/Input/GamePad360.cs +++ b/BizHawk.Client.EmuHawk/Input/GamePad360.cs @@ -14,7 +14,7 @@ namespace BizHawk.Client.EmuHawk private static readonly object _syncObj = new object(); private static readonly List _devices = new List(); - private static readonly bool _isAvailable = IsAvailable(); + private static readonly bool _isAvailable; [DllImport("kernel32", SetLastError = true, EntryPoint = "GetProcAddress")] static extern IntPtr GetProcAddressOrdinal(IntPtr hModule, IntPtr procName); @@ -42,7 +42,7 @@ namespace BizHawk.Client.EmuHawk public XINPUT_GAMEPAD Gamepad; } - private static bool IsAvailable() + static GamePad360() { try { @@ -68,12 +68,10 @@ namespace BizHawk.Client.EmuHawk //don't remove this code. it's important to catch errors on systems with broken xinput installs. //(probably, checking for the library was adequate, but lets not get rid of this anyway) var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected; - return true; + _isAvailable = true; } } catch { } - - return false; } public static void Initialize() diff --git a/BizHawk.Client.EmuHawk/Input/Input.cs b/BizHawk.Client.EmuHawk/Input/Input.cs index 286689cb5c..67c88793aa 100644 --- a/BizHawk.Client.EmuHawk/Input/Input.cs +++ b/BizHawk.Client.EmuHawk/Input/Input.cs @@ -348,7 +348,7 @@ namespace BizHawk.Client.EmuHawk //analyze xinput foreach (var pad in GamePad360.EnumerateDevices()) { - string xname = "X" + (pad.PlayerNumber) + " "; + string xname = "X" + pad.PlayerNumber + " "; for (int b = 0; b < pad.NumButtons; b++) HandleButton(xname + pad.ButtonName(b), pad.Pressed(b)); foreach (var sv in pad.GetFloats()) @@ -362,11 +362,9 @@ namespace BizHawk.Client.EmuHawk } //analyze joysticks - foreach (var item in GamePad.EnumerateDevices().Select((n, i) => new { Device = n, Index = i })) + foreach (var pad in GamePad.EnumerateDevices()) { - var pad = item.Device; - string jname = "J" + (item.Index + 1) + " "; - + string jname = "J" + pad.PlayerNumber + " "; for (int b = 0; b < pad.NumButtons; b++) HandleButton(jname + pad.ButtonName(b), pad.Pressed(b)); foreach (var sv in pad.GetFloats())