-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathIDirectInputDevice8.cpp
More file actions
780 lines (642 loc) · 22.1 KB
/
Copy pathIDirectInputDevice8.cpp
File metadata and controls
780 lines (642 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
/**
* Copyright (C) 2026 Elisha Riedlinger
*
* This software is provided 'as-is', without any express or implied warranty. In no event will the
* authors be held liable for any damages arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
* original software. If you use this software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
* being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include "dinput8.h"
#include "ScopeGuard.h"
#include "GDI\WndProc.h"
HRESULT m_IDirectInputDevice8::QueryInterface(REFIID riid, LPVOID* ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
if (!ppvObj)
{
return E_POINTER;
}
*ppvObj = nullptr;
if (riid == IID_GetRealInterface)
{
*ppvObj = ProxyInterface;
return DI_OK;
}
if (riid == IID_GetInterfaceX)
{
*ppvObj = this;
return DI_OK;
}
if (riid == IID_IUnknown || riid == IID_IDirectInputDevice8W)
{
*ppvObj = static_cast<IDirectInputDevice8W*>(this);
}
else if (riid == IID_IDirectInputDevice8A)
{
*ppvObj = static_cast<IDirectInputDevice8A*>(this);
}
else
{
return ProxyInterface->QueryInterface(riid, ppvObj);
}
AddRef();
return S_OK;
}
ULONG m_IDirectInputDevice8::AddRef()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return InterlockedIncrement(&RefCount);
}
ULONG m_IDirectInputDevice8::Release()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
ULONG ref = InterlockedDecrement(&RefCount);
if (ref == 0)
{
delete this;
}
return ref;
}
HRESULT m_IDirectInputDevice8::GetCapabilities(LPDIDEVCAPS lpDIDevCaps)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->GetCapabilities(lpDIDevCaps);
}
template HRESULT m_IDirectInputDevice8::EnumObjectsT<IDirectInputDevice8A, LPDIENUMDEVICEOBJECTSCALLBACKA>(IDirectInputDevice8A*, LPDIENUMDEVICEOBJECTSCALLBACKA, LPVOID, DWORD);
template HRESULT m_IDirectInputDevice8::EnumObjectsT<IDirectInputDevice8W, LPDIENUMDEVICEOBJECTSCALLBACKW>(IDirectInputDevice8W*, LPDIENUMDEVICEOBJECTSCALLBACKW, LPVOID, DWORD);
template <class T, class V>
HRESULT m_IDirectInputDevice8::EnumObjectsT(T* ProxyInterfaceT, V lpCallback, LPVOID pvRef, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->EnumObjects(lpCallback, pvRef, dwFlags);
}
HRESULT m_IDirectInputDevice8::GetProperty(REFGUID rguidProp, LPDIPROPHEADER pdiph)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
HRESULT hr = ProxyInterface->GetProperty(rguidProp, pdiph);
if (SUCCEEDED(hr))
{
// Handle mouse input buffer size
if (IsMouse && Config.FixHighFrequencyMouse)
{
if ((DWORD)&rguidProp == (DWORD)&DIPROP_BUFFERSIZE && RequestedMouseBufferSize)
{
if (pdiph && pdiph->dwSize == sizeof(DIPROPDWORD))
{
DIPROPDWORD* pOut = reinterpret_cast<DIPROPDWORD*>(pdiph);
pOut->dwData = RequestedMouseBufferSize;
}
}
}
}
return hr;
}
HRESULT m_IDirectInputDevice8::SetProperty(REFGUID rguidProp, LPCDIPROPHEADER pdiph)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
// Handle mouse input
if (IsMouse && Config.FixHighFrequencyMouse)
{
const DWORD dwMinBufferSize = 128;
// Verify buffer is large enough
if ((DWORD)&rguidProp == (DWORD)&DIPROP_BUFFERSIZE)
{
if (pdiph && pdiph->dwSize == sizeof(DIPROPDWORD))
{
const DIPROPDWORD* pIn = reinterpret_cast<const DIPROPDWORD*>(pdiph);
DIPROPDWORD dipdw = *pIn;
DWORD requested = dipdw.dwData ? dipdw.dwData : RequestedMouseBufferSize;
dipdw.dwData = max(dipdw.dwData, dwMinBufferSize);
if (requested == 0)
{
DIPROPDWORD r_dipdw = {};
r_dipdw.diph.dwSize = sizeof(DIPROPDWORD);
r_dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
r_dipdw.diph.dwObj = 0;
r_dipdw.diph.dwHow = DIPH_DEVICE;
if (SUCCEEDED(ProxyInterface->GetProperty(DIPROP_BUFFERSIZE, &r_dipdw.diph)))
{
requested = r_dipdw.dwData;
}
}
HRESULT hr = ProxyInterface->SetProperty(rguidProp, &dipdw.diph);
if (SUCCEEDED(hr))
{
if (dipdw.dwData > MouseBufferSize)
{
SentBufferOverflow = false; // Send buffer overflow message again once buffer size is increased
}
RequestedMouseBufferSize = requested;
MouseBufferSize = dipdw.dwData;
}
return hr;
}
}
// Override deadzone for mice
if ((DWORD)&rguidProp == (DWORD)&DIPROP_DEADZONE)
{
return DI_OK;
}
}
return ProxyInterface->SetProperty(rguidProp, pdiph);
}
HRESULT m_IDirectInputDevice8::Acquire()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->Acquire();
}
HRESULT m_IDirectInputDevice8::Unacquire()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->Unacquire();
}
HRESULT m_IDirectInputDevice8::GetDeviceState(DWORD cbData, LPVOID lpvData)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
HRESULT hr = ProxyInterface->GetDeviceState(cbData, lpvData);
if (SUCCEEDED(hr) && lpvData)
{
if (IsMouse && Config.FixHighFrequencyMouse)
{
// Apply movement adjustment using stored offsets
if (Ofs.x >= 0)
{
AdjustMouseAxis(*((LONG*)((BYTE*)lpvData + Ofs.x)), false);
}
if (Ofs.y >= 0)
{
AdjustMouseAxis(*((LONG*)((BYTE*)lpvData + Ofs.y)), true);
}
}
}
return hr;
}
template <class T>
HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags, std::vector<T>& dod)
{
// Check arguments
if (!pdwInOut || (rgdod && *pdwInOut == 0))
{
return DIERR_INVALIDPARAM;
}
if (cbObjectData != sizeof(T))
{
*pdwInOut = 0;
return DIERR_INVALIDPARAM;
}
const bool isPeek = (dwFlags == DIGDD_PEEK);
const bool isFlushingData = (rgdod == nullptr && *pdwInOut == INFINITE && !isPeek);
const bool isRequestingOverflow = (rgdod == nullptr && *pdwInOut == 0);
// Lock for concurrency
ScopedCriticalSection ThreadLock(&dics);
bool isBufferOverflow = false;
DWORD dwItems = INFINITE;
// Determine number of records to store
HRESULT hr = ProxyInterface->GetDeviceData(cbObjectData, nullptr, &dwItems, DIGDD_PEEK);
if (hr == DI_BUFFEROVERFLOW)
{
isBufferOverflow = true;
}
else if (FAILED(hr))
{
*pdwInOut = 0;
return hr;
}
if (dwItems == INFINITE)
{
dwItems = MouseBufferSize ? MouseBufferSize : 32; // Resonable default
}
// Ensure buffer is large enough
const DWORD requiredBytes = dwItems * cbObjectData;
if (tmp_dod.size() < requiredBytes)
{
tmp_dod.resize(requiredBytes);
}
// Pointer to first record
LPDIDEVICEOBJECTDATA lpdod = reinterpret_cast<LPDIDEVICEOBJECTDATA>(tmp_dod.data());
// Get device data from buffer
hr = ProxyInterface->GetDeviceData(cbObjectData, lpdod, &dwItems, 0);
if (hr == DI_BUFFEROVERFLOW)
{
isBufferOverflow = true;
}
else if (FAILED(hr))
{
*pdwInOut = 0;
return hr;
}
// Merge and store device object data
if (!isFlushingData && dwItems)
{
bool isSet[3] = { false };
DWORD Loc[3] = { 0 };
if (SequenceCounter == 0)
{
SequenceCounter = lpdod->dwSequence;
}
// Loop through buffer and merge like data
for (UINT x = 0; x < dwItems; x++)
{
bool InsertNewRecord = true;
// Handle movement data
if (lpdod->dwOfs == Ofs.x || lpdod->dwOfs == Ofs.y || lpdod->dwOfs == Ofs.z)
{
const int v = lpdod->dwOfs == Ofs.x ? 0 : lpdod->dwOfs == Ofs.y ? 1 : 2;
// Merge data only
if (isSet[v])
{
InsertNewRecord = false;
dod[Loc[v]].lData += (LONG)lpdod->dwData;
}
// Storing new movement data
else
{
isSet[v] = true;
Loc[v] = dod.size();
}
}
// Store data
if (InsertNewRecord)
{
if constexpr (std::is_same_v<T, MOUSECACHEDATA_DX3>)
{
dod.push_back({ lpdod->dwOfs, (LONG)lpdod->dwData, lpdod->dwTimeStamp, SequenceCounter++ });
}
else
{
dod.push_back({ lpdod->dwOfs, (LONG)lpdod->dwData, lpdod->dwTimeStamp, SequenceCounter++, lpdod->uAppData });
}
}
lpdod = (LPDIDEVICEOBJECTDATA)((BYTE*)lpdod + cbObjectData);
}
// Update data for mouse factor and padding
for (DWORD item : { Ofs.x, Ofs.y })
{
const int v = item == Ofs.x ? 0 : item == Ofs.y ? 1 : 2;
if (isSet[v])
{
AdjustMouseAxis(dod[Loc[v]].lData, (item == Ofs.y));
}
}
}
// Check buffer size
if (MouseBufferSize == 0)
{
DIPROPDWORD dipdw = {};
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);
}
DWORD dwOut = 0;
// Checking for device object data
if (rgdod == nullptr)
{
// Flush buffer
if (isFlushingData)
{
dod.clear();
}
// Get number of records in the buffer
else
{
dwOut = dod.size();
}
}
// Fill device object data
else if (*pdwInOut)
{
DWORD requested = *pdwInOut;
if (requested == INFINITE && RequestedMouseBufferSize)
{
requested = RequestedMouseBufferSize;
}
dwOut = min(dod.size(), requested);
// Check for buffer overflow (attempt to handle buffer starvation case)
if (dwOut < dod.size() && (!RequestedMouseBufferSize || RequestedMouseBufferSize < dod.size()))
{
isBufferOverflow = true;
}
memcpy(rgdod, dod.data(), sizeof(T) * dwOut);
// Remove used entries from buffer
if (dwOut && !isPeek)
{
if (dwOut < dod.size())
{
dod.erase(dod.begin(), dod.begin() + dwOut);
}
else
{
dod.clear();
}
}
}
*pdwInOut = dwOut;
if (isBufferOverflow)
{
SequenceCounter += 5; // Simulate overflow
if (isRequestingOverflow || !SentBufferOverflow)
{
SentBufferOverflow = true;
return DI_BUFFEROVERFLOW;
}
}
return DI_OK;
}
HRESULT m_IDirectInputDevice8::GetDeviceData(DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
if (Config.FilterNonActiveInput && pdwInOut)
{
// Check foreground window's process and don't copy device data if process is not active
HWND hfgwnd = GetForegroundWindow();
if (hfgwnd)
{
DWORD fgwndprocid = 0;
GetWindowThreadProcessId(hfgwnd, &fgwndprocid);
if (ProcessID != fgwndprocid)
{
// Foreground window belongs to another process, don't copy the device data
*pdwInOut = 0;
}
}
}
if (IsMouse && Config.FixHighFrequencyMouse)
{
if (rgdod && cbObjectData != sizeof(DIDEVICEOBJECTDATA_DX3) && cbObjectData != sizeof(DIDEVICEOBJECTDATA))
{
if (pdwInOut)
{
*pdwInOut = 0;
}
return DIERR_INVALIDPARAM;
}
if (cbObjectData == sizeof(DIDEVICEOBJECTDATA_DX3) || cbObjectData == sizeof(DIDEVICEOBJECTDATA))
{
LastObjectSize = cbObjectData;
}
else
{
cbObjectData = LastObjectSize ? LastObjectSize : sizeof(DIDEVICEOBJECTDATA);
}
if (cbObjectData == sizeof(DIDEVICEOBJECTDATA_DX3))
{
if (dod_dx8.size())
{
// Lock for concurrency
ScopedCriticalSection ThreadLock(&dics);
for (auto& item : dod_dx8)
{
dod_dx3.push_back({ item.dwOfs, item.lData, item.dwTimeStamp, item.dwSequence });
}
dod_dx8.clear();
}
return GetMouseDeviceData<MOUSECACHEDATA_DX3>(sizeof(DIDEVICEOBJECTDATA_DX3), rgdod, pdwInOut, dwFlags, dod_dx3);
}
else
{
return GetMouseDeviceData<MOUSECACHEDATA>(sizeof(DIDEVICEOBJECTDATA), rgdod, pdwInOut, dwFlags, dod_dx8);
}
}
return ProxyInterface->GetDeviceData(cbObjectData, rgdod, pdwInOut, dwFlags);
}
HRESULT m_IDirectInputDevice8::SetDataFormat(LPCDIDATAFORMAT lpdf)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
HRESULT hr = ProxyInterface->SetDataFormat(lpdf);
if (SUCCEEDED(hr))
{
if (IsMouse && lpdf && lpdf->rgodf && lpdf->dwNumObjs)
{
for (DWORD i = 0; i < lpdf->dwNumObjs; i++)
{
const DIOBJECTDATAFORMAT& obj = lpdf->rgodf[i];
// Check if this object is an axis (relative)
if (DIDFT_GETTYPE(obj.dwType) & DIDFT_RELAXIS)
{
if (obj.pguid && IsEqualGUID(GUID_XAxis, *obj.pguid))
{
Ofs.x = obj.dwOfs;
}
else if (obj.pguid && IsEqualGUID(GUID_YAxis, *obj.pguid))
{
Ofs.y = obj.dwOfs;
}
else if (obj.pguid && IsEqualGUID(GUID_ZAxis, *obj.pguid))
{
Ofs.z = obj.dwOfs;
}
}
}
}
}
return hr;
}
HRESULT m_IDirectInputDevice8::SetEventNotification(HANDLE hEvent)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->SetEventNotification(hEvent);
}
HRESULT m_IDirectInputDevice8::SetCooperativeLevel(HWND hwnd, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
WndProc::AddWndProc(hwnd);
return ProxyInterface->SetCooperativeLevel(hwnd, dwFlags);
}
template HRESULT m_IDirectInputDevice8::GetObjectInfoT<IDirectInputDevice8A, LPDIDEVICEOBJECTINSTANCEA>(IDirectInputDevice8A*, LPDIDEVICEOBJECTINSTANCEA, DWORD, DWORD);
template HRESULT m_IDirectInputDevice8::GetObjectInfoT<IDirectInputDevice8W, LPDIDEVICEOBJECTINSTANCEW>(IDirectInputDevice8W*, LPDIDEVICEOBJECTINSTANCEW, DWORD, DWORD);
template <class T, class V>
HRESULT m_IDirectInputDevice8::GetObjectInfoT(T* ProxyInterfaceT, V pdidoi, DWORD dwObj, DWORD dwHow)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->GetObjectInfo(pdidoi, dwObj, dwHow);
}
template HRESULT m_IDirectInputDevice8::GetDeviceInfoT<IDirectInputDevice8A, LPDIDEVICEINSTANCEA>(IDirectInputDevice8A*, LPDIDEVICEINSTANCEA);
template HRESULT m_IDirectInputDevice8::GetDeviceInfoT<IDirectInputDevice8W, LPDIDEVICEINSTANCEW>(IDirectInputDevice8W*, LPDIDEVICEINSTANCEW);
template <class T, class V>
HRESULT m_IDirectInputDevice8::GetDeviceInfoT(T* ProxyInterfaceT, V pdidi)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->GetDeviceInfo(pdidi);
}
HRESULT m_IDirectInputDevice8::RunControlPanel(HWND hwndOwner, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->RunControlPanel(hwndOwner, dwFlags);
}
HRESULT m_IDirectInputDevice8::Initialize(HINSTANCE hinst, DWORD dwVersion, REFGUID rguid)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->Initialize(hinst, dwVersion, rguid);
}
HRESULT m_IDirectInputDevice8::CreateEffect(REFGUID rguid, LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT* ppdeff, LPUNKNOWN punkOuter)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
DIEFFECT eff = {};
DICONSTANTFORCE constantForce = {};
// Fixes a force feedback issue with 'The Real Car Simulator R'
if (Config.InvertForceDirection
&& lpeff
&& rguid == GUID_ConstantForce
&& lpeff->lpvTypeSpecificParams
&& lpeff->cbTypeSpecificParams == sizeof(DICONSTANTFORCE))
{
eff = *lpeff;
constantForce = *static_cast<DICONSTANTFORCE*>(lpeff->lpvTypeSpecificParams);
constantForce.lMagnitude = -(constantForce.lMagnitude);
LOG_LIMIT(3, __FUNCTION__ << " Inverting ConstantForce magnitude: " << constantForce.lMagnitude << " -> " << -(constantForce.lMagnitude));
eff.lpvTypeSpecificParams = &constantForce;
lpeff = &eff;
}
HRESULT hr = ProxyInterface->CreateEffect(rguid, lpeff, ppdeff, punkOuter);
if (SUCCEEDED(hr) && ppdeff)
{
m_IDirectInputEffect8* pEffect = new m_IDirectInputEffect8(*ppdeff);
pEffect->SetGUID(rguid);
*ppdeff = pEffect;
}
return hr;
}
template HRESULT m_IDirectInputDevice8::EnumEffectsT<IDirectInputDevice8A, LPDIENUMEFFECTSCALLBACKA>(IDirectInputDevice8A*, LPDIENUMEFFECTSCALLBACKA, LPVOID, DWORD);
template HRESULT m_IDirectInputDevice8::EnumEffectsT<IDirectInputDevice8W, LPDIENUMEFFECTSCALLBACKW>(IDirectInputDevice8W*, LPDIENUMEFFECTSCALLBACKW, LPVOID, DWORD);
template <class T, class V>
HRESULT m_IDirectInputDevice8::EnumEffectsT(T* ProxyInterfaceT, V lpCallback, LPVOID pvRef, DWORD dwEffType)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->EnumEffects(lpCallback, pvRef, dwEffType);
}
template HRESULT m_IDirectInputDevice8::GetEffectInfoT<IDirectInputDevice8A, LPDIEFFECTINFOA>(IDirectInputDevice8A*, LPDIEFFECTINFOA, REFGUID);
template HRESULT m_IDirectInputDevice8::GetEffectInfoT<IDirectInputDevice8W, LPDIEFFECTINFOW>(IDirectInputDevice8W*, LPDIEFFECTINFOW, REFGUID);
template <class T, class V>
HRESULT m_IDirectInputDevice8::GetEffectInfoT(T* ProxyInterfaceT, V pdei, REFGUID rguid)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->GetEffectInfo(pdei, rguid);
}
HRESULT m_IDirectInputDevice8::GetForceFeedbackState(LPDWORD pdwOut)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->GetForceFeedbackState(pdwOut);
}
HRESULT m_IDirectInputDevice8::SendForceFeedbackCommand(DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->SendForceFeedbackCommand(dwFlags);
}
HRESULT m_IDirectInputDevice8::EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID pvRef, DWORD fl)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
if (!lpCallback)
{
return DIERR_INVALIDPARAM;
}
struct EffectEnumerator
{
LPVOID pvRef = nullptr;
LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback = nullptr;
static BOOL CALLBACK EnumEffectCallback(LPDIRECTINPUTEFFECT pdeff, LPVOID pvRef)
{
EffectEnumerator* self = static_cast<EffectEnumerator*>(pvRef);
if (pdeff)
{
m_IDirectInputEffect8* WrapperEffect = ProxyAddressLookupTableDinput8.FindAddress<m_IDirectInputEffect8>(pdeff);
if (WrapperEffect == nullptr)
{
WrapperEffect = new m_IDirectInputEffect8(pdeff);
}
pdeff = WrapperEffect;
}
return self->lpCallback(pdeff, self->pvRef);
}
} CallbackContext;
CallbackContext.pvRef = pvRef;
CallbackContext.lpCallback = lpCallback;
return ProxyInterface->EnumCreatedEffectObjects(EffectEnumerator::EnumEffectCallback, &CallbackContext, fl);
}
HRESULT m_IDirectInputDevice8::Escape(LPDIEFFESCAPE pesc)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->Escape(pesc);
}
HRESULT m_IDirectInputDevice8::Poll()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->Poll();
}
HRESULT m_IDirectInputDevice8::SendDeviceData(DWORD cbObjectData, LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD fl)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterface->SendDeviceData(cbObjectData, rgdod, pdwInOut, fl);
}
template HRESULT m_IDirectInputDevice8::EnumEffectsInFileT<IDirectInputDevice8A, LPCSTR>(IDirectInputDevice8A*, LPCSTR, LPDIENUMEFFECTSINFILECALLBACK, LPVOID, DWORD);
template HRESULT m_IDirectInputDevice8::EnumEffectsInFileT<IDirectInputDevice8W, LPCWSTR>(IDirectInputDevice8W*, LPCWSTR, LPDIENUMEFFECTSINFILECALLBACK, LPVOID, DWORD);
template <class T, class V>
HRESULT m_IDirectInputDevice8::EnumEffectsInFileT(T* ProxyInterfaceT, V lpszFileName, LPDIENUMEFFECTSINFILECALLBACK pec, LPVOID pvRef, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->EnumEffectsInFile(lpszFileName, pec, pvRef, dwFlags);
}
template HRESULT m_IDirectInputDevice8::WriteEffectToFileT<IDirectInputDevice8A, LPCSTR>(IDirectInputDevice8A*, LPCSTR, DWORD, LPDIFILEEFFECT, DWORD);
template HRESULT m_IDirectInputDevice8::WriteEffectToFileT<IDirectInputDevice8W, LPCWSTR>(IDirectInputDevice8W*, LPCWSTR, DWORD, LPDIFILEEFFECT, DWORD);
template <class T, class V>
HRESULT m_IDirectInputDevice8::WriteEffectToFileT(T* ProxyInterfaceT, V lpszFileName, DWORD dwEntries, LPDIFILEEFFECT rgDiFileEft, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->WriteEffectToFile(lpszFileName, dwEntries, rgDiFileEft, dwFlags);
}
template HRESULT m_IDirectInputDevice8::BuildActionMapT<IDirectInputDevice8A, LPDIACTIONFORMATA, LPCSTR>(IDirectInputDevice8A*, LPDIACTIONFORMATA, LPCSTR, DWORD);
template HRESULT m_IDirectInputDevice8::BuildActionMapT<IDirectInputDevice8W, LPDIACTIONFORMATW, LPCWSTR>(IDirectInputDevice8W*, LPDIACTIONFORMATW, LPCWSTR, DWORD);
template <class T, class V, class W>
HRESULT m_IDirectInputDevice8::BuildActionMapT(T* ProxyInterfaceT, V lpdiaf, W lpszUserName, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->BuildActionMap(lpdiaf, lpszUserName, dwFlags);
}
template HRESULT m_IDirectInputDevice8::SetActionMapT<IDirectInputDevice8A, LPDIACTIONFORMATA, LPCSTR>(IDirectInputDevice8A*, LPDIACTIONFORMATA, LPCSTR, DWORD);
template HRESULT m_IDirectInputDevice8::SetActionMapT<IDirectInputDevice8W, LPDIACTIONFORMATW, LPCWSTR>(IDirectInputDevice8W*, LPDIACTIONFORMATW, LPCWSTR, DWORD);
template <class T, class V, class W>
HRESULT m_IDirectInputDevice8::SetActionMapT(T* ProxyInterfaceT, V lpdiActionFormat, W lptszUserName, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->SetActionMap(lpdiActionFormat, lptszUserName, dwFlags);
}
template HRESULT m_IDirectInputDevice8::GetImageInfoT<IDirectInputDevice8A, LPDIDEVICEIMAGEINFOHEADERA>(IDirectInputDevice8A*, LPDIDEVICEIMAGEINFOHEADERA);
template HRESULT m_IDirectInputDevice8::GetImageInfoT<IDirectInputDevice8W, LPDIDEVICEIMAGEINFOHEADERW>(IDirectInputDevice8W*, LPDIDEVICEIMAGEINFOHEADERW);
template <class T, class V>
HRESULT m_IDirectInputDevice8::GetImageInfoT(T* ProxyInterfaceT, V lpdiDevImageInfoHeader)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
return ProxyInterfaceT->GetImageInfo(lpdiDevImageInfoHeader);
}
// Helper functions
void m_IDirectInputDevice8::AdjustMouseAxis(LONG& value, bool isY)
{
if (value == 0)
{
return;
}
const double factor = isY ?
Config.MouseMovementFactorY :
Config.MouseMovementFactorX;
const LONG padding = isY ?
static_cast<LONG>(Config.MouseMovementPaddingY) :
static_cast<LONG>(Config.MouseMovementPaddingX);
const LONG baseMovement =
static_cast<LONG>(std::round(value * factor));
if (std::abs(baseMovement) < padding)
{
value = (value < 0) ? -padding : padding;
}
else
{
value = baseMovement;
}
}