SDL: joystick: fixup for Wireless Xbox 360 Controller VID/PID detection in WGI backend.

From 0ab13f2498357af799ff8a4c7d4619674079e353 Mon Sep 17 00:00:00 2001
From: Dimitriy Ryazantcev <[EMAIL REDACTED]>
Date: Fri, 15 Dec 2023 17:36:17 +0200
Subject: [PATCH] joystick: fixup for Wireless Xbox 360 Controller VID/PID
 detection in WGI backend.

It turns out that returned PID is zero in this case and it breaks SDL_IsXInputDevice/HIDAPI_IsDevicePresent checks
---
 .../windows/SDL_windows_gaming_input.c        | 29 ++++++++++++-------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c
index ca86f707c760..6ffbf8d976e8 100644
--- a/src/joystick/windows/SDL_windows_gaming_input.c
+++ b/src/joystick/windows/SDL_windows_gaming_input.c
@@ -385,6 +385,23 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
         __x_ABI_CWindows_CGaming_CInput_CIRawGameController_get_HardwareVendorId(controller, &vendor);
         __x_ABI_CWindows_CGaming_CInput_CIRawGameController_get_HardwareProductId(controller, &product);
 
+        hr = __x_ABI_CWindows_CGaming_CInput_CIRawGameController_QueryInterface(controller, &IID___x_ABI_CWindows_CGaming_CInput_CIGameController, (void **)&game_controller);
+        if (SUCCEEDED(hr)) {
+            boolean wireless = 0;
+            hr = __x_ABI_CWindows_CGaming_CInput_CIGameController_get_IsWireless(game_controller, &wireless);
+            if (SUCCEEDED(hr) && wireless) {
+                bus = SDL_HARDWARE_BUS_BLUETOOTH;
+
+                /* Fixup for Wireless Xbox 360 Controller */
+                if (product == 0) {
+                    vendor = USB_VENDOR_MICROSOFT;
+                    product = USB_PRODUCT_XBOX360_XUSB_CONTROLLER;
+                }
+            }
+
+            __x_ABI_CWindows_CGaming_CInput_CIGameController_Release(game_controller);
+        }
+
         hr = __x_ABI_CWindows_CGaming_CInput_CIRawGameController_QueryInterface(controller, &IID___x_ABI_CWindows_CGaming_CInput_CIRawGameController2, (void **)&controller2);
         if (SUCCEEDED(hr)) {
             HSTRING hString;
@@ -423,18 +440,8 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
         }
 
         if (!ignore_joystick) {
-            hr = __x_ABI_CWindows_CGaming_CInput_CIRawGameController_QueryInterface(controller, &IID___x_ABI_CWindows_CGaming_CInput_CIGameController, (void **)&game_controller);
-            if (SUCCEEDED(hr)) {
-                boolean wireless;
-
+            if (game_controller) {
                 type = GetGameControllerType(game_controller);
-
-                hr = __x_ABI_CWindows_CGaming_CInput_CIGameController_get_IsWireless(game_controller, &wireless);
-                if (SUCCEEDED(hr) && wireless) {
-                    bus = SDL_HARDWARE_BUS_BLUETOOTH;
-                }
-
-                __x_ABI_CWindows_CGaming_CInput_CIGameController_Release(game_controller);
             }
 
             guid = SDL_CreateJoystickGUID(bus, vendor, product, version, name, 'w', (Uint8)type);