@@ -52,6 +52,7 @@ typedef struct GAMEINPUT_InternalDevice
52
52
SDL_GUID guid; // generated by SDL
53
53
SDL_JoystickID device_instance; // generated by SDL
54
54
const GameInputDeviceInfo *info;
55
+ int steam_virtual_gamepad_slot;
55
56
bool isAdded;
56
57
bool isDeleteRequested;
57
58
} GAMEINPUT_InternalDevice;
@@ -83,6 +84,16 @@ static bool GAMEINPUT_InternalIsGamepad(const GameInputDeviceInfo *info)
83
84
return false ;
84
85
}
85
86
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
+
86
97
static bool GAMEINPUT_InternalAddOrFind (IGameInputDevice *pDevice)
87
98
{
88
99
GAMEINPUT_InternalDevice **devicelist = NULL ;
@@ -162,6 +173,7 @@ static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
162
173
elem->guid = SDL_CreateJoystickGUID (bus, vendor, product, version, manufacturer_string, product_string, ' g' , 0 );
163
174
elem->device_instance = SDL_GetNextObjectID ();
164
175
elem->info = info;
176
+ elem->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot (info->pnpPath );
165
177
166
178
g_GameInputList.devices = devicelist;
167
179
g_GameInputList.devices [g_GameInputList.count ++] = elem;
@@ -349,7 +361,7 @@ static const char *GAMEINPUT_JoystickGetDevicePath(int device_index)
349
361
350
362
static int GAMEINPUT_JoystickGetDeviceSteamVirtualGamepadSlot (int device_index)
351
363
{
352
- return - 1 ;
364
+ return GAMEINPUT_InternalFindByIndex (device_index)-> steam_virtual_gamepad_slot ;
353
365
}
354
366
355
367
static int GAMEINPUT_JoystickGetDevicePlayerIndex (int device_index)
0 commit comments