Skip to content

Commit

Permalink
Remove DIDEVTYPE_DEVICE to better replicate Win98
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jun 14, 2024
1 parent e3b5f65 commit 0e39c27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 58
#define BUILD_NUMBER 59
21 changes: 21 additions & 0 deletions IDirectInputX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,34 @@ 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;

DI.dwDevType = (lpddi->dwDevType & ~0xFFFF) | // Remove device type and sub type
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;
Expand Down

0 comments on commit 0e39c27

Please sign in to comment.