Rémi Bernon : xinput1_3: Introduce a new override registry mechanism to force dinput.

Alexandre Julliard julliard at winehq.org
Fri Sep 24 15:32:01 CDT 2021


Module: wine
Branch: master
Commit: 4ba54cb44833cd38964718ac7e33692416ad3ab9
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=4ba54cb44833cd38964718ac7e33692416ad3ab9

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Fri Sep 24 10:10:34 2021 +0200

xinput1_3: Introduce a new override registry mechanism to force dinput.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/xinput1_1/Makefile.in   |  2 +-
 dlls/xinput1_2/Makefile.in   |  2 +-
 dlls/xinput1_3/Makefile.in   |  2 +-
 dlls/xinput1_3/main.c        | 48 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/xinput1_4/Makefile.in   |  2 +-
 dlls/xinput9_1_0/Makefile.in |  2 +-
 6 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/dlls/xinput1_1/Makefile.in b/dlls/xinput1_1/Makefile.in
index a07b0c7c8b6..328435a110f 100644
--- a/dlls/xinput1_1/Makefile.in
+++ b/dlls/xinput1_1/Makefile.in
@@ -1,6 +1,6 @@
 MODULE    = xinput1_1.dll
 PARENTSRC = ../xinput1_3
-DELAYIMPORTS = hid setupapi
+DELAYIMPORTS = hid setupapi advapi32
 
 C_SRCS = \
 	main.c
diff --git a/dlls/xinput1_2/Makefile.in b/dlls/xinput1_2/Makefile.in
index 4a624521498..e66b6e67261 100644
--- a/dlls/xinput1_2/Makefile.in
+++ b/dlls/xinput1_2/Makefile.in
@@ -1,6 +1,6 @@
 MODULE    = xinput1_2.dll
 PARENTSRC = ../xinput1_3
-DELAYIMPORTS = hid setupapi
+DELAYIMPORTS = hid setupapi advapi32
 
 C_SRCS = \
 	main.c
diff --git a/dlls/xinput1_3/Makefile.in b/dlls/xinput1_3/Makefile.in
index 7786838b5e7..15ce3a691dd 100644
--- a/dlls/xinput1_3/Makefile.in
+++ b/dlls/xinput1_3/Makefile.in
@@ -1,6 +1,6 @@
 MODULE    = xinput1_3.dll
 IMPORTLIB = xinput
-DELAYIMPORTS = hid setupapi
+DELAYIMPORTS = hid setupapi advapi32
 
 C_SRCS = \
 	main.c
diff --git a/dlls/xinput1_3/main.c b/dlls/xinput1_3/main.c
index 2881a370534..81d11e5d38f 100644
--- a/dlls/xinput1_3/main.c
+++ b/dlls/xinput1_3/main.c
@@ -394,6 +394,52 @@ failed:
     return FALSE;
 }
 
+static void get_registry_keys(HKEY *defkey, HKEY *appkey)
+{
+    WCHAR buffer[MAX_PATH + 26], *name = buffer, *tmp;
+    DWORD len;
+    HKEY hkey;
+
+    *appkey = 0;
+    if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Wine\\DirectInput\\Joysticks", defkey))
+        *defkey = 0;
+
+    if (!(len = GetModuleFileNameW(0, buffer, MAX_PATH)) || len >= MAX_PATH)
+        return;
+
+    if (!RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Wine\\AppDefaults", &hkey))
+    {
+        if ((tmp = wcsrchr(name, '/'))) name = tmp + 1;
+        if ((tmp = wcsrchr(name, '\\'))) name = tmp + 1;
+        wcscat(name, L"\\DirectInput\\Joysticks");
+        if (RegOpenKeyW(hkey, name, appkey)) *appkey = 0;
+        RegCloseKey(hkey);
+    }
+}
+
+static BOOL device_is_overriden(HANDLE device)
+{
+    WCHAR name[MAX_PATH], buffer[MAX_PATH];
+    DWORD size = sizeof(buffer);
+    BOOL disable = FALSE;
+    HKEY defkey, appkey;
+
+    if (!HidD_GetProductString(device, name, MAX_PATH)) return FALSE;
+
+    get_registry_keys(&defkey, &appkey);
+    if (!defkey && !appkey) return FALSE;
+    if ((appkey && !RegQueryValueExW(appkey, name, 0, NULL, (LPBYTE)buffer, &size)) ||
+        (defkey && !RegQueryValueExW(defkey, name, 0, NULL, (LPBYTE)buffer, &size)))
+    {
+        if ((disable = !wcscmp(buffer, L"override")))
+            TRACE("Disabling gamepad '%s' based on registry key.\n", debugstr_w(name));
+    }
+
+    if (appkey) RegCloseKey(appkey);
+    if (defkey) RegCloseKey(defkey);
+    return disable;
+}
+
 static void update_controller_list(void)
 {
     char buffer[sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W) + MAX_PATH * sizeof(WCHAR)];
@@ -437,6 +483,8 @@ static void update_controller_list(void)
         else if (caps.Usage != HID_USAGE_GENERIC_GAMEPAD && caps.Usage != HID_USAGE_GENERIC_JOYSTICK &&
                  caps.Usage != HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER)
             WARN("ignoring HID device, unsupported usage %04x:%04x\n", caps.UsagePage, caps.Usage);
+        else if (device_is_overriden(device))
+            WARN("ignoring HID device, overriden for dinput\n");
         else if (!controller_init(&controllers[i], preparsed, &caps, device, detail->DevicePath))
             WARN("ignoring HID device, failed to initialize\n");
         else
diff --git a/dlls/xinput1_4/Makefile.in b/dlls/xinput1_4/Makefile.in
index 5e4ab8969e2..b21a3d3ce53 100644
--- a/dlls/xinput1_4/Makefile.in
+++ b/dlls/xinput1_4/Makefile.in
@@ -1,6 +1,6 @@
 MODULE    = xinput1_4.dll
 PARENTSRC = ../xinput1_3
-DELAYIMPORTS = hid setupapi
+DELAYIMPORTS = hid setupapi advapi32
 
 C_SRCS = \
 	main.c
diff --git a/dlls/xinput9_1_0/Makefile.in b/dlls/xinput9_1_0/Makefile.in
index 6c9e9016537..f014e67dea3 100644
--- a/dlls/xinput9_1_0/Makefile.in
+++ b/dlls/xinput9_1_0/Makefile.in
@@ -1,6 +1,6 @@
 MODULE    = xinput9_1_0.dll
 PARENTSRC = ../xinput1_3
-DELAYIMPORTS = hid setupapi
+DELAYIMPORTS = hid setupapi advapi32
 
 C_SRCS = \
 	main.c




More information about the wine-cvs mailing list