YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Ticket: #180792 - Support for more XInput controllers #3338

Open iampremo opened 1 year ago

iampremo commented 1 year ago

Ticket: [Ticket #180792]

Description: Xinput has apparently been updated (as of the release of the Xbox One, actually) to support more than 4 controllers, up to 8. Windows itself now detects more than 4 Xinput controllers and I can confirm this myself. Game Maker however only detects 4 Xinput controllers on slots 0-3 with 4-11 being reserved for the (now far less supported and more variable) Direct Input. I would like for Game Maker to be able to detect more than 4 controllers.

Benefit: Making multiplayer games with more than 4 players is hype. Playing with lots of friends is fun. I wanted to make a game for 8 or even more players but could not get GMS to detect more controllers.

andrew171717 commented 1 year ago

The XInput library is still limited to 4 devices, however, Microsoft has released a new library that supports 8 XInput devices. This would require GameMaker to port from the XInput library to the GameInput library. Microsoft has documentation on some of the process (see link below). They have stated the port process should not be too difficult, but this doesn’t take into account GameMaker’s long development history or how GameMaker currently allocates 0-3 to XInput devices and 4-11 to DirectInput. In a perfect world, GameMaker could implement this logic making 0-7 be for XInput and 8-15 be for DirectInput. This should be easy to implement for the Windows export platform, but I’m unsure if this would be usable for other export platforms.

Quote from their documentation: “The value of XUSER_MAX_COUNT has been increased from 4 to 8 to match the number of supported devices on Xbox One. This should generally be transparent to most legacy XInput code. However, be sure to carefully review any use of the XInputGetKeystroke function in your code to help ensure that nothing is hard-coded to assume a maximum value of 4 being returned in the UserIndex member of the XINPUT_KEYSTROKE structure. Otherwise, a buffer overrun could occur.”

https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/input/porting/input-porting-xinput

Alternatively, there is an open source project for XInput that allows for more than 4 XInput devices. This might be easier for GameMaker to implement for every export platform over the port mentioned above. https://github.com/Nemirtingas/OpenXinput

andrew171717 commented 1 year ago

I setup a proof of concept extension for GameMaker that allows for button polling of 8 XInput devices. https://github.com/andrew171717/OpenXInputExtension/

My extension is currently heavily lacking in features, but I was able to use over 4 Xinput devices on Windows 10 and plan on adding more functionality over time. I created a forum post to discuss it https://forum.gamemaker.io/index.php?threads/openxinputextension-allows-for-more-than-4-xinput-devices-to-be-used-on-windows-game-exports.104823/

Edit: Just a little update, my extension mentioned above is now fully functioning and has replacement functions for a majority of GameMaker gamepad functions to allow support of 8 XInput devices.