Skip to content

Commit fde656c

Browse files
committed
Better mouse and axis detection
#481
1 parent 07d409f commit fde656c

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 8138
1+
#define BUILD_NUMBER 8139

dinput8/IDirectInput8.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,27 @@ HRESULT m_IDirectInput8::CreateDeviceT(REFGUID rguid, V lplpDirectInputDevice, L
7575

7676
*lplpDirectInputDevice = pAddressX;
7777

78-
if (IsEqualIID(GUID_SysMouse, rguid) || IsEqualIID(GUID_SysMouseEm, rguid) || IsEqualIID(GUID_SysMouseEm2, rguid))
78+
bool isMouse = false;
79+
80+
if (IsEqualGUID(GUID_SysMouse, rguid) || IsEqualIID(GUID_SysMouseEm, rguid) || IsEqualIID(GUID_SysMouseEm2, rguid))
81+
{
82+
isMouse = true;
83+
}
84+
else
85+
{
86+
DIDEVCAPS caps = {};
87+
caps.dwSize = sizeof(DIDEVCAPS);
88+
89+
if (SUCCEEDED(pAddressX->GetCapabilities(&caps)))
90+
{
91+
if (GET_DIDEVICE_TYPE(caps.dwDevType) == DI8DEVTYPE_MOUSE)
92+
{
93+
isMouse = true;
94+
}
95+
}
96+
}
97+
98+
if (isMouse)
7999
{
80100
pAddressX->SetAsMouse();
81101
}

dinput8/IDirectInputDevice8.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
176176
for (UINT x = 0; x < dod.size(); x++)
177177
{
178178
// Movement record exists
179-
if (dod[x].wasPeeked == false && (dod[x].dwOfs == DIMOFS_X || dod[x].dwOfs == DIMOFS_Y || dod[x].dwOfs == DIMOFS_Z))
179+
if (dod[x].wasPeeked == false && (dod[x].dwOfs == Ofs.x || dod[x].dwOfs == Ofs.y || dod[x].dwOfs == Ofs.z))
180180
{
181-
const int v = dod[x].dwOfs == DIMOFS_X ? 0 : dod[x].dwOfs == DIMOFS_Y ? 1 : 2;
181+
const int v = dod[x].dwOfs == Ofs.x ? 0 : dod[x].dwOfs == Ofs.y ? 1 : 2;
182182

183183
isSet[v] = true;
184184
Loc[v] = x;
@@ -196,9 +196,9 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
196196
for (UINT x = 0; x < dwItems; x++)
197197
{
198198
// Storing movement data
199-
if (lpdod->dwOfs == DIMOFS_X || lpdod->dwOfs == DIMOFS_Y || lpdod->dwOfs == DIMOFS_Z)
199+
if (lpdod->dwOfs == Ofs.x || lpdod->dwOfs == Ofs.y || lpdod->dwOfs == Ofs.z)
200200
{
201-
const int v = lpdod->dwOfs == DIMOFS_X ? 0 : lpdod->dwOfs == DIMOFS_Y ? 1 : 2;
201+
const int v = lpdod->dwOfs == Ofs.x ? 0 : lpdod->dwOfs == Ofs.y ? 1 : 2;
202202

203203
// Merge data only
204204
if (isSet[v])
@@ -254,9 +254,9 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
254254
if (dwOut < dod.size())
255255
{
256256
p_rgdod->dwOfs = dod[dwOut].dwOfs;
257-
if (dod[dwOut].lData != 0 && (p_rgdod->dwOfs == DIMOFS_X || p_rgdod->dwOfs == DIMOFS_Y))
257+
if (abs(dod[dwOut].lData) != 0 && (p_rgdod->dwOfs == Ofs.x || p_rgdod->dwOfs == Ofs.y))
258258
{
259-
double factor = (p_rgdod->dwOfs == DIMOFS_Y) ? Config.MouseMovementFactor : abs(Config.MouseMovementFactor);
259+
double factor = (p_rgdod->dwOfs == Ofs.y) ? Config.MouseMovementFactor : abs(Config.MouseMovementFactor);
260260
LONG baseMovement = (LONG)round(dod[dwOut].lData * factor);
261261
if (abs(baseMovement) < (LONG)Config.MouseMovementPadding)
262262
{
@@ -345,7 +345,37 @@ HRESULT m_IDirectInputDevice8::SetDataFormat(LPCDIDATAFORMAT lpdf)
345345
{
346346
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
347347

348-
return ProxyInterface->SetDataFormat(lpdf);
348+
HRESULT hr = ProxyInterface->SetDataFormat(lpdf);
349+
350+
if (SUCCEEDED(hr))
351+
{
352+
if (IsMouse && lpdf && lpdf->rgodf && lpdf->dwNumObjs)
353+
{
354+
for (DWORD i = 0; i < lpdf->dwNumObjs; i++)
355+
{
356+
const DIOBJECTDATAFORMAT& obj = lpdf->rgodf[i];
357+
358+
// Check if this object is an axis (relative)
359+
if (DIDFT_GETTYPE(obj.dwType) & DIDFT_RELAXIS)
360+
{
361+
if (obj.pguid && IsEqualGUID(GUID_XAxis, *obj.pguid))
362+
{
363+
Ofs.x = obj.dwOfs;
364+
}
365+
else if (obj.pguid && IsEqualGUID(GUID_YAxis, *obj.pguid))
366+
{
367+
Ofs.y = obj.dwOfs;
368+
}
369+
else if (obj.pguid && IsEqualGUID(GUID_ZAxis, *obj.pguid))
370+
{
371+
Ofs.z = obj.dwOfs;
372+
}
373+
}
374+
}
375+
}
376+
}
377+
378+
return hr;
349379
}
350380

351381
HRESULT m_IDirectInputDevice8::SetEventNotification(HANDLE hEvent)

dinput8/IDirectInputDevice8.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class m_IDirectInputDevice8 : public IDirectInputDevice8A, public IDirectInputDe
2121

2222
bool IsMouse = false;
2323
DWORD MouseBufferSize = 0;
24+
struct {
25+
DWORD x = DIMOFS_X;
26+
DWORD y = DIMOFS_Y;
27+
DWORD z = DIMOFS_Z;
28+
} Ofs;
29+
std::vector<DWORD> cachedAxisOffsets;
2430
std::vector<MOUSECACHEDATA> dod;
2531
std::vector<DIDEVICEOBJECTDATA_DX3> dod_dx3;
2632
std::vector<DIDEVICEOBJECTDATA> dod_dx8;

0 commit comments

Comments
 (0)