Skip to content

Commit 66dad9c

Browse files
committed
Added Steam Virtual Gamepad support to the GameInput driver
1 parent 6babade commit 66dad9c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/joystick/gdk/SDL_gameinputjoystick.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct GAMEINPUT_InternalDevice
5252
SDL_GUID guid; // generated by SDL
5353
SDL_JoystickID device_instance; // generated by SDL
5454
const GameInputDeviceInfo *info;
55+
int steam_virtual_gamepad_slot;
5556
bool isAdded;
5657
bool isDeleteRequested;
5758
} GAMEINPUT_InternalDevice;
@@ -83,6 +84,16 @@ static bool GAMEINPUT_InternalIsGamepad(const GameInputDeviceInfo *info)
8384
return false;
8485
}
8586

87+
static int GetSteamVirtualGamepadSlot(const char *device_path)
88+
{
89+
int slot = -1;
90+
91+
// The format for the raw input device path is documented here:
92+
// https://partner.steamgames.com/doc/features/steam_controller/steam_input_gamepad_emulation_bestpractices
93+
(void)SDL_sscanf(device_path, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%*X&%*X&%*X#%d#%*u", &slot);
94+
return slot;
95+
}
96+
8697
static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
8798
{
8899
GAMEINPUT_InternalDevice **devicelist = NULL;
@@ -162,6 +173,7 @@ static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
162173
elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, manufacturer_string, product_string, 'g', 0);
163174
elem->device_instance = SDL_GetNextObjectID();
164175
elem->info = info;
176+
elem->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot(info->pnpPath);
165177

166178
g_GameInputList.devices = devicelist;
167179
g_GameInputList.devices[g_GameInputList.count++] = elem;
@@ -349,7 +361,7 @@ static const char *GAMEINPUT_JoystickGetDevicePath(int device_index)
349361

350362
static int GAMEINPUT_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
351363
{
352-
return -1;
364+
return GAMEINPUT_InternalFindByIndex(device_index)->steam_virtual_gamepad_slot;
353365
}
354366

355367
static int GAMEINPUT_JoystickGetDevicePlayerIndex(int device_index)

0 commit comments

Comments
 (0)