فهرست منبع

Added Steam Virtual Gamepad support to the GameInput driver

(cherry picked from commit 66dad9c21f62db17bfde2a8b6f3debb18f6e1e79)
Sam Lantinga 11 ماه پیش
والد
کامیت
ebba656bdb
1فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 13 1
      src/joystick/gdk/SDL_gameinputjoystick.c

+ 13 - 1
src/joystick/gdk/SDL_gameinputjoystick.c

@@ -46,6 +46,7 @@ typedef struct GAMEINPUT_InternalDevice
     SDL_GUID guid;          // generated by SDL
     SDL_JoystickID device_instance; // generated by SDL
     const GameInputDeviceInfo *info;
+    int steam_virtual_gamepad_slot;
     bool isAdded;
     bool isDeleteRequested;
 } GAMEINPUT_InternalDevice;
@@ -77,6 +78,16 @@ static bool GAMEINPUT_InternalIsGamepad(const GameInputDeviceInfo *info)
     return false;
 }
 
+static int GetSteamVirtualGamepadSlot(const char *device_path)
+{
+    int slot = -1;
+
+    // The format for the raw input device path is documented here:
+    // https://partner.steamgames.com/doc/features/steam_controller/steam_input_gamepad_emulation_bestpractices
+    (void)SDL_sscanf(device_path, "\\\\.\\pipe\\HID#VID_045E&PID_028E&IG_00#%*X&%*X&%*X#%d#%*u", &slot);
+    return slot;
+}
+
 static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
 {
     GAMEINPUT_InternalDevice **devicelist = NULL;
@@ -147,6 +158,7 @@ static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
     elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, manufacturer_string, product_string, 'g', 0);
     elem->device_instance = SDL_GetNextObjectID();
     elem->info = info;
+    elem->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot(info->pnpPath);
 
     g_GameInputList.devices = devicelist;
     g_GameInputList.devices[g_GameInputList.count++] = elem;
@@ -333,7 +345,7 @@ static const char *GAMEINPUT_JoystickGetDevicePath(int device_index)
 
 static int GAMEINPUT_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
 {
-    return -1;
+    return GAMEINPUT_InternalFindByIndex(device_index)->steam_virtual_gamepad_slot;
 }
 
 static int GAMEINPUT_JoystickGetDevicePlayerIndex(int device_index)