From 0e39c27dcd2a701992cdaa02d28a6958de0753bd Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Fri, 14 Jun 2024 12:49:38 -0700 Subject: [PATCH] Remove DIDEVTYPE_DEVICE to better replicate Win98 #27 --- BuildNo.rc | 2 +- IDirectInputX.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/BuildNo.rc b/BuildNo.rc index 6f89cc6..603b7f4 100644 --- a/BuildNo.rc +++ b/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 58 +#define BUILD_NUMBER 59 diff --git a/IDirectInputX.cpp b/IDirectInputX.cpp index 0aef59e..bff2377 100644 --- a/IDirectInputX.cpp +++ b/IDirectInputX.cpp @@ -93,6 +93,7 @@ HRESULT m_IDirectInputX::EnumDevicesX(DWORD dwDevType, V lpCallback, LPVOID pvRe D DI = {}; CopyMemory(&DI, lpddi, lpddi->dwSize); + // Prevent DInput3 games from encountering a structure bigger than they might expect. DI.dwSize = self->dwStructSize; @@ -100,6 +101,26 @@ HRESULT m_IDirectInputX::EnumDevicesX(DWORD dwDevType, V lpCallback, LPVOID pvRe ConvertDevSubTypeTo7(lpddi->dwDevType & 0xFF, (lpddi->dwDevType & 0xFF00) >> 8) << 8 | // Add converted sub type dwConvertedDevType; // Add converted device type + if ((DI.dwDevType & DIDEVTYPE_DEVICE) && (DI.dwDevType & DIDEVTYPE_HID) && DI.wUsagePage == 0x01) + { + // For usage see here: https://github.com/MysteriousJ/Joystick-Input-Examples?tab=readme-ov-file#hid + switch (DI.wUsage) + { + case 0x02: // Mouse + DI.dwDevType = (DI.dwDevType & ~DIDEVTYPE_DEVICE) | DIDEVTYPE_MOUSE; + break; + case 0x04: // Joystick + case 0x05: // Game pad + DI.dwDevType = (DI.dwDevType & ~DIDEVTYPE_DEVICE) | DIDEVTYPE_JOYSTICK; + break; + case 0x06: // Keyboard + DI.dwDevType = (DI.dwDevType & ~DIDEVTYPE_DEVICE) | DIDEVTYPE_KEYBOARD; + break; + default: + break; + } + } + return self->lpCallback(&DI, self->pvRef); } } CallbackContext;