-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
GPDInput.inl
2330 lines (2187 loc) · 117 KB
/
GPDInput.inl
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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Gamepad Phoenix
* Copyright (c) 2021-2023 Bernhard Schelling
*
* Gamepad Phoenix is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* Gamepad Phoenix is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Gamepad Phoenix.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <ole2.h>
#include <dbt.h>
namespace GPDInput {
enum : unsigned int
{
GPDI_VERSION_5 = 0x0500,
GPDI_VERSION_6 = 0x0600,
GPDI_VERSION_8 = 0x0800,
GPDI8DEVCLASS_ALL = 0,
GPDI8DEVCLASS_DEVICE = 1,
GPDI8DEVCLASS_POINTER = 2,
GPDI8DEVCLASS_KEYBOARD = 3,
GPDI8DEVCLASS_GAMECTRL = 4,
GPDIDEVTYPE_MASK = 0xFF,
GPDI1DEVTYPE_DEVICE = 1,
GPDI1DEVTYPE_MOUSE = 2,
GPDI1DEVTYPE_KEYBOARD = 3,
GPDI1DEVTYPE_JOYSTICK = 4,
GPDIDEVTYPE_HID = 0x00010000,
GPDIDEVTYPE_NOHID = 0,
GPDI8DEVTYPE_DEVICE = 0x11,
GPDI8DEVTYPE_MOUSE = 0x12,
GPDI8DEVTYPE_KEYBOARD = 0x13,
GPDI8DEVTYPE_JOYSTICK = 0x14,
GPDI8DEVTYPE_GAMEPAD = 0x15,
GPDI8DEVTYPE_DRIVING = 0x16,
GPDI8DEVTYPE_FLIGHT = 0x17,
GPDI8DEVTYPE_1STPERSON = 0x18,
GPDI8DEVTYPE_DEVICECTRL = 0x19,
GPDI8DEVTYPE_SCREENPOINTER = 0x1A,
GPDI8DEVTYPE_REMOTE = 0x1B,
GPDI8DEVTYPE_SUPPLEMENTAL = 0x1C,
GPDI8DEVTYPE_OVERRIDE_MIN = GPDI8DEVTYPE_JOYSTICK,
GPDI8DEVTYPE_OVERRIDE_MAX = 0xFF, // hide everything that isn't mouse or keyboard
GPDI8SUBDEVTYPE_JOYSTICK_UNKNOWN = 1,
GPDI8SUBDEVTYPE_JOYSTICK_TRADITIONAL = 2,
GPDI8SUBDEVTYPE_JOYSTICK_FLIGHTSTICK = 3,
GPDI8SUBDEVTYPE_JOYSTICK_GAMEPAD = 4,
GPDI8SUBDEVTYPE_JOYSTICK_RUDDER = 5,
GPDI8SUBDEVTYPE_JOYSTICK_WHEEL = 6,
GPDI8SUBDEVTYPE_JOYSTICK_HEADTRACKER = 7,
GPDI8SUBDEVTYPE_JOYSTICK_LIMITED = 1,
GPDI8SUBDEVTYPE_JOYSTICK_STANDARD = 2,
GPDI8SUBDEVTYPE_GAMEPAD_LIMITED = 1,
GPDI8SUBDEVTYPE_GAMEPAD_STANDARD = 2,
GPDI8SUBDEVTYPE_GAMEPAD_TILT = 3,
GPDI8SUBDEVTYPE_DRIVING_LIMITED = 1,
GPDI8SUBDEVTYPE_DRIVING_COMBINEDPEDALS = 2,
GPDI8SUBDEVTYPE_DRIVING_DUALPEDALS = 3,
GPDI8SUBDEVTYPE_DRIVING_THREEPEDALS = 4,
GPDI8SUBDEVTYPE_DRIVING_HANDHELD = 5,
GPDI8SUBDEVTYPE_FLIGHT_LIMITED = 1,
GPDI8SUBDEVTYPE_FLIGHT_STICK = 2,
GPDI8SUBDEVTYPE_FLIGHT_YOKE = 3,
GPDI8SUBDEVTYPE_FLIGHT_RC = 4,
GPDI8SUBDEVTYPE_1STPERSON_LIMITED = 1,
GPDI8SUBDEVTYPE_1STPERSON_UNKNOWN = 2,
GPDI8SUBDEVTYPE_1STPERSON_SIXDOF = 3,
GPDI8SUBDEVTYPE_1STPERSON_SHOOTER = 4,
GPDIENUM_STOP = 0,
GPDIENUM_CONTINUE = 1,
GPDIEDFL_ALLDEVICES = 0x00000000,
GPDIEDFL_ATTACHEDONLY = 0x00000001,
GPDIEDFL_FORCEFEEDBACK = 0x00000100,
GPDIEDFL_INCLUDEALIASES = 0x00010000,
GPDIEDFL_INCLUDEPHANTOMS = 0x00020000,
GPDIEDFL_INCLUDEHIDDEN = 0x00040000,
GPDIPROP_BUFFERSIZE = 1,
GPDIPROP_AXISMODE = 2,
GPDIPROPAXISMODE_ABS = 0,
GPDIPROPAXISMODE_REL = 1,
GPDIPROP_GRANULARITY = 3,
GPDIPROP_RANGE = 4,
GPDIPROP_DEADZONE = 5,
GPDIPROP_SATURATION = 6,
GPDIPROP_FFGAIN = 7,
GPDIPROP_FFLOAD = 8,
GPDIPROP_AUTOCENTER = 9,
GPDIPROPAUTOCENTER_OFF = 0,
GPDIPROPAUTOCENTER_ON = 1,
GPDIPROP_CALIBRATIONMODE = 10,
GPDIPROPCALIBRATIONMODE_COOKED = 0,
GPDIPROPCALIBRATIONMODE_RAW = 1,
GPDI5PROP_CALIBRATION = 11,
GPDI5PROP_GUIDANDPATH = 12,
GPDI5PROP_INSTANCENAME = 13,
GPDI5PROP_PRODUCTNAME = 14,
GPDI5PROP_JOYSTICKID = 15,
GPDI5PROP_GETPORTDISPLAYNAME = 16,
GPDI7PROP_PHYSICALRANGE = 18,
GPDI7PROP_LOGICALRANGE = 19,
GPDI8PROP_KEYNAME = 20,
GPDI8PROP_CPOINTS = 21,
GPDI8PROP_APPDATA = 22,
GPDI8PROP_SCANCODE = 23,
GPDI8PROP_VIDPID = 24,
GPDI8PROP_USERNAME = 25,
GPDI8PROP_TYPENAME = 26,
GPDIODFGUID_XAxis = 0xA36D02E0,
GPDIODFGUID_YAxis = 0xA36D02E1,
GPDIODFGUID_ZAxis = 0xA36D02E2,
GPDIODFGUID_RzAxis = 0xA36D02E3,
GPDIODFGUID_Slider = 0xA36D02E4,
GPDIODFGUID_Button = 0xA36D02F0,
GPDIODFGUID_POV = 0xA36D02F2,
GPDIODFGUID_Unknown = 0xA36D02F3,
GPDIODFGUID_RxAxis = 0xA36D02F4,
GPDIODFGUID_RyAxis = 0xA36D02F5,
GPDIODFGUID_Key = 0x55728220,
GPDIDFT_ALL = 0x00000000,
GPDIDFT_RELAXIS = 0x00000001,
GPDIDFT_ABSAXIS = 0x00000002,
GPDIDFT_AXIS = 0x00000003,
GPDIDFT_PSHBUTTON = 0x00000004,
GPDIDFT_TGLBUTTON = 0x00000008,
GPDIDFT_BUTTON = 0x0000000C,
GPDIDFT_POV = 0x00000010,
GPDIDFT_COLLECTION = 0x00000040,
GPDIDFT_NODATA = 0x00000080,
GPDIDFT_TYPEMASK = 0x000000FF,
GPDIDFT_ANYINSTANCE = 0x00FFFF00,
GPDIDFT_FFACTUATOR = 0x01000000,
GPDIDFT_FFEFFECTTRIGGER = 0x02000000,
GPDIDFT5_OUTPUT = 0x10000000,
GPDIDFT5_VENDORDEFINED = 0x04000000,
GPDIDFT5_ALIAS = 0x08000000,
GPDIDFT_OPTIONAL = 0x80000000,
GPDIDOI_FFACTUATOR = 0x00000001,
GPDIDOI_FFEFFECTTRIGGER = 0x00000002,
GPDIDOI_ASPECTPOSITION = 0x00000100,
GPDIDOI_ASPECTVELOCITY = 0x00000200,
GPDIDOI_ASPECTACCEL = 0x00000300,
GPDIDOI_ASPECTFORCE = 0x00000400,
GPDIDOI_ASPECTMASK = 0x00000F00,
GPDIDOI_POLLED = 0x00008000,
GPDIDOI5_GUIDISUSAGE = 0x00010000,
GPDISCL_EXCLUSIVE = 0x00000001,
GPDISCL_NONEXCLUSIVE = 0x00000002,
GPDISCL_FOREGROUND = 0x00000004,
GPDISCL_BACKGROUND = 0x00000008,
GPDISCL_NOWINKEY = 0x00000010,
GPDIDF_ABSAXIS = 0x00000001,
GPDIDF_RELAXIS = 0x00000002,
GPDIGDD_PEEK = 0x00000001,
GPDI_MAX_KEYBOARD = 256,
GPDIPH_DEVICE = 0,
GPDIPH_BYOFFSET = 1,
GPDIPH_BYID = 2,
GPDIPH_BYUSAGE = 3,
GPDI_IID_IDirectInput8A = 0xBF798030, //bf798030-483a-4da2-aa99-5d64ed369700
GPDI_IID_IDirectInput8W = 0xBF798031, //bf798031-483a-4da2-aa99-5d64ed369700
GPDI_IID_IDirectInput7A = 0x9A4CB684, //9a4cb684-236d-11d3-8e9d-00c04f6844ae
GPDI_IID_IDirectInput7W = 0x9A4CB685, //9a4cb685-236d-11d3-8e9d-00c04f6844ae
GPDI_IID_IDirectInput2A = 0x5944E662, //5944e662-aa8a-11cf-bfc7-444553540000
GPDI_IID_IDirectInput2W = 0x5944E663, //5944e663-aa8a-11cf-bfc7-444553540000
GPDI_IID_IDirectInputA = 0x89521360, //89521360-aa8a-11cf-bfc7-444553540000
GPDI_IID_IDirectInputW = 0x89521361, //89521361-aa8a-11cf-bfc7-444553540000
GPDI_IID_IDirectInputJoyConfig = 0xEB0D7DFA, //eb0d7dfa-1990-4f27-b4d6-edf2eec4a44c
GPDI_IID_IWbemLocator = 0xDC12A687, //dc12a687-737f-11cf-884d-00aa004b2e24
GPDI_CLSID_DirectInput8 = 0x25E609E4, //25e609e4-b259-11cf-bfc7-444553540000
GPDI_CLSID_DirectInput = 0x25E609E0, //25e609e0-b259-11cf-bfc7-444553540000
GPDIEDBSFL_ATTACHEDONLY = 0x00000000,
GPDIEDBSFL_THISUSER = 0x00000010,
GPDIEDBSFL_FORCEFEEDBACK = GPDIEDFL_FORCEFEEDBACK,
GPDIEDBSFL_AVAILABLEDEVICES = 0x00001000,
GPDIEDBSFL_MULTIMICEKEYBOARDS = 0x00002000,
GPDIEDBSFL_NONGAMINGDEVICES = 0x00004000,
GPDIEDBSFL_VALID = 0x00007110,
//GPDIERR_OLDDIRECTINPUTVERSION = 0x8007047E,
//GPDIERR_BETADIRECTINPUTVERSION = 0x80070481,
//GPDIERR_BADDRIVERVER = 0x80070077,
GPDIERR_DEVICENOTREG = 0x80040154,
//GPDIERR_NOTFOUND = 0x80070002,
GPDIERR_OBJECTNOTFOUND = 0x80070002,
GPDIERR_INVALIDPARAM = 0x80070057,
//GPDIERR_NOINTERFACE = 0x80004002,
//GPDIERR_GENERIC = 0x80004005,
//GPDIERR_OUTOFMEMORY = 0x8007000E,
//GPDIERR_UNSUPPORTED = 0x80004001,
GPDIERR_NOTINITIALIZED = 0x80070015,
//GPDIERR_ALREADYINITIALIZED = 0x800704DF,
//GPDIERR_NOAGGREGATION = 0x80040110,
//GPDIERR_OTHERAPPHASPRIO = 0x80070005,
//GPDIERR_INPUTLOST = 0x8007001E,
//GPDIERR_ACQUIRED = 0x800700AA,
//GPDIERR_NOTACQUIRED = 0x8007000C,
//GPDIERR_READONLY = 0x80070005,
//GPDIERR_HANDLEEXISTS = 0x80070005,
//GPDIERR_PENDING = 0x8000000A,
//GPDIERR_INSUFFICIENTPRIVS = 0x80040200,
//GPDIERR_DEVICEFULL = 0x80040201,
//GPDIERR_MOREDATA = 0x80040202,
//GPDIERR_NOTDOWNLOADED = 0x80040203,
//GPDIERR_HASEFFECTS = 0x80040204,
//GPDIERR_NOTEXCLUSIVEACQUIRED = 0x80040205,
//GPDIERR_INCOMPLETEEFFECT = 0x80040206,
//GPDIERR_NOTBUFFERED = 0x80040207,
//GPDIERR_EFFECTPLAYING = 0x80040208,
//GPDIERR_UNPLUGGED = 0x80040209,
//GPDIERR_REPORTFULL = 0x8004020A,
//GPDIERR_MAPFILEFAIL = 0x8004020B,
};
#define GPDIDFT_MAKEINSTANCE(n) ((DWORD)(((DWORD)((n) & 0xffff)) << 8))
#define GPDIDFT_GETINSTANCE(n) ((DWORD)(((DWORD)((n) >> 8)) & 0xffff))
#define GPDIMAKEDEVTYPE(DEVTYPE, SUBDEVTYPE, HIDFLAG) ((DEVTYPE) | ((SUBDEVTYPE)<<8) | (HIDFLAG))
struct GPDIDEVCAPS
{
DWORD dwSize, dwFlags, dwDevType, dwAxes, dwButtons, dwPOVs;
//DIRECTINPUT_VERSION >= GPDI_VERSION_5
DWORD dwFFSamplePeriod, dwFFMinTimeResolution, dwFirmwareRevision, dwHardwareRevision, dwFFDriverVersion;
};
struct GPDIDeviceInstance
{
DWORD dwSize;
GUID guidInstance, guidProduct;
DWORD dwDevType;
union { struct { WCHAR tszInstanceName[MAX_PATH], tszProductName[MAX_PATH]; }; struct { char tszInstanceNameA[MAX_PATH], tszProductNameA[MAX_PATH]; }; };
struct Extra
{
// DIRECTINPUT_VERSION >= GPDI_VERSION_5
GUID guidFFDriver;
WORD wUsagePage, wUsage;
};
Extra* GetExtra(bool isW) const { return (Extra*)((char*)&extra - (isW ? 0 : MAX_PATH+MAX_PATH)); }
DWORD GetSize(bool isW) const { return (DWORD)sizeof(*this) - (DWORD)(isW ? 0 : MAX_PATH+MAX_PATH); }
void SetStrings(bool isW, const WCHAR* instanceName, const WCHAR* productName)
{
if (isW) { wcscpy(tszInstanceName, instanceName); wcscpy(tszProductName, productName); }
else { WideCharToMultiByte(CP_ACP, 0, instanceName, -1, tszInstanceNameA, MAX_PATH, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, productName, -1, tszProductNameA, MAX_PATH, NULL, NULL); }
}
private: Extra extra;
};
GPSTATIC_ASSERT(sizeof(GPDIDeviceInstance) == 580+260+260);
struct GPDIDeviceObjectInstance
{
DWORD dwSize;
GUID guidType;
DWORD dwOfs, dwType, dwFlags;
union { WCHAR tszName[MAX_PATH]; char tszNameA[MAX_PATH]; };
struct Extra
{
//DIRECTINPUT_VERSION >= GPDI_VERSION_5
DWORD dwFFMaxForce, dwFFForceResolution;
WORD wCollectionNumber, wDesignatorIndex, wUsagePage, wUsage;
DWORD dwDimension;
WORD wExponent, wReserved;
};
Extra* GetExtra(bool isW) const { return (Extra*)((char*)&extra - (isW ? 0 : MAX_PATH)); }
DWORD GetSize(bool isW) const { return (DWORD)sizeof(*this) - (DWORD)(isW ? 0 : MAX_PATH); }
void SetStrings(bool isW, const WCHAR* name)
{
if (isW) { wcscpy(tszName, name); }
else { WideCharToMultiByte(CP_ACP, 0, name, -1, tszNameA, MAX_PATH, NULL, NULL); }
}
private: Extra extra;
};
GPSTATIC_ASSERT(sizeof(GPDIDeviceObjectInstance) == 316+260);
struct GPDIEffectInfo
{
DWORD dwSize;
GUID guid;
DWORD dwEffType, dwStaticParams, dwDynamicParams;
union { WCHAR tszName[MAX_PATH]; char tszNameA[MAX_PATH]; };
void SetStrings(bool isW, const WCHAR* name)
{
if (isW) { wcscpy(tszName, name); }
else { WideCharToMultiByte(CP_ACP, 0, name, -1, tszNameA, MAX_PATH, NULL, NULL); }
}
};
GPSTATIC_ASSERT(sizeof(GPDIEffectInfo) == 32+260+260);
struct GPDIAction
{
UINT_PTR uAppData;
DWORD dwSemantic, dwFlags;
union UAction { const WCHAR* lptszActionName; const char* lptszActionNameA; UINT uResIdString; } u;
GUID guidInstance;
DWORD dwObjID, dwHow;
};
struct GPDIActionFormat
{
DWORD dwSize, dwActionSize, dwDataSize, dwNumActions;
GPDIAction* rgoAction;
GUID guidActionMap;
DWORD dwGenre, dwBufferSize;
LONG lAxisMin, lAxisMax;
HINSTANCE hInstString;
FILETIME ftTimeStamp;
DWORD dwCRC;
union { WCHAR tszActionMap[MAX_PATH]; char tszActionMapA[MAX_PATH]; };
void SetStrings(bool isW, const WCHAR* map)
{
if (isW) { wcscpy(tszActionMap, map); }
else { WideCharToMultiByte(CP_ACP, 0, map, -1, tszActionMapA, MAX_PATH, NULL, NULL); }
}
};
struct GPDIDeviceImageInfo
{
union { WCHAR tszImagePath[MAX_PATH]; char tszImagePathA[MAX_PATH]; };
struct Extra
{
DWORD dwFlags;
DWORD dwViewID;
RECT rcOverlay;
DWORD dwObjID, dwcValidPts;
POINT rgptCalloutLine[5];
RECT rcCalloutRect;
DWORD dwTextAlign;
};
Extra* GetExtra(bool isW) const { return (Extra*)((char*)&extra - (isW ? 0 : MAX_PATH)); }
DWORD GetSize(bool isW) const { return (DWORD)sizeof(*this) - (DWORD)(isW ? 0 : MAX_PATH); }
void SetStrings(bool isW, const WCHAR* path)
{
if (isW) { wcscpy(tszImagePath, path); }
else { WideCharToMultiByte(CP_ACP, 0, path, -1, tszImagePathA, MAX_PATH, NULL, NULL); }
}
private: Extra extra;
};
GPSTATIC_ASSERT(sizeof(GPDIDeviceImageInfo) == 352+260);
struct GPDIDeviceImageInfoHeader
{
DWORD dwSize, dwSizeImageInfo, dwcViews, dwcButtons, dwcAxes, dwcPOVs, dwBufferSize, dwBufferUsed;
GPDIDeviceImageInfo* lprgImageInfoArray; // Can't be accessed as array, needs pointer arithmetic with GetSize(isW)
};
struct GPDIColorSet { DWORD dwSize, cTextFore, cTextHighlight, cCalloutLine, cCalloutHighlight, cBorder, cControlFill, cHighlightFill, cAreaFill; };
struct GPDIConfigureDevicesParams
{
DWORD dwSize, dwcUsers;
LPWSTR lptszUserNames;
DWORD dwcFormats;
GPDIActionFormat* lprgFormats;
HWND hwnd;
GPDIColorSet dics;
void* lpUnkDDSTarget;
};
struct GPDIDeviceObjectData
{
DWORD dwOfs, dwData, dwTimeStamp, dwSequence;
//DIRECTINPUT_VERSION >= GPDI_VERSION_8
UINT_PTR uAppData;
};
struct GPDIObjectDataFormat
{
const GUID *pguid;
DWORD dwOfs, dwType, dwFlags;
};
struct GPDIDataFormat
{
DWORD dwSize, dwObjSize, dwFlags, dwDataSize, dwNumObjs;
GPDIObjectDataFormat* rgodf;
};
struct GPDIEnvelope { DWORD dwSize, dwAttackLevel, dwAttackTime, dwFadeLevel, dwFadeTime; };
struct GPDIEffect
{
DWORD dwSize, dwFlags, dwDuration, dwSamplePeriod, dwGain, dwTriggerButton, dwTriggerRepeatInterval, cAxes;
LPDWORD rgdwAxes;
LPLONG rglDirection;
GPDIEnvelope* lpEnvelope;
DWORD cbTypeSpecificParams;
LPVOID lpvTypeSpecificParams;
//DIRECTINPUT_VERSION >= GPDI_VERSION_6
DWORD dwStartDelay;
};
struct GPDIPropHeader { DWORD dwSize, dwHeaderSize, dwObj, dwHow; };
struct GPDIPropDWord { GPDIPropHeader diph; DWORD dwData; };
struct GPDIPropRange { GPDIPropHeader diph; LONG lMin, lMax; }; // DIPROPRANGE_NOMIN = 0x80000000 / DIPROPRANGE_NOMAX = 0x7FFFFFFF
struct GPDIPropCal { GPDIPropHeader diph; LONG lMin, lCenter, lMax; };
struct GPDIPropCalPOV { GPDIPropHeader diph; LONG lMin[5], lMax[5]; };
struct GPDIPropGUIDAndPath { GPDIPropHeader diph; GUID guidClass; WCHAR wszPath[MAX_PATH]; };
struct GPDIPropString { GPDIPropHeader diph; WCHAR wsz[MAX_PATH]; };
struct GPDIPropPointer { GPDIPropHeader diph; UINT_PTR uData; };
struct GPDIEffectEscape { DWORD dwSize, dwCommand; LPVOID lpvInBuffer; DWORD cbInBuffer; LPVOID lpvOutBuffer; DWORD cbOutBuffer; };
struct GPDIFileEffect { DWORD dwSize; GUID GuidEffect; const GPDIEffect* lpDiEffect; CHAR szFriendlyName[MAX_PATH]; };
struct GPIDirectInputEffect
{
/*** IUnknown methods ***/
HRESULT (STDMETHODCALLTYPE *QueryInterface)(GPIDirectInputEffect** self, REFIID riid, void** ppvObject);
ULONG (STDMETHODCALLTYPE *AddRef)(GPIDirectInputEffect** self);
ULONG (STDMETHODCALLTYPE *Release)(GPIDirectInputEffect** self);
/*** IDirectInputEffect methods ***/
HRESULT (STDMETHODCALLTYPE *Initialize)(GPIDirectInputEffect** self, HINSTANCE, DWORD, GUID*);
HRESULT (STDMETHODCALLTYPE *GetEffectGuid)(GPIDirectInputEffect** self, LPGUID);
HRESULT (STDMETHODCALLTYPE *GetParameters)(GPIDirectInputEffect** self, GPDIEffect*, DWORD);
HRESULT (STDMETHODCALLTYPE *SetParameters)(GPIDirectInputEffect** self, const GPDIEffect*, DWORD);
HRESULT (STDMETHODCALLTYPE *Start)(GPIDirectInputEffect** self, DWORD, DWORD);
HRESULT (STDMETHODCALLTYPE *Stop)(GPIDirectInputEffect** self);
HRESULT (STDMETHODCALLTYPE *GetEffectStatus)(GPIDirectInputEffect** self, LPDWORD);
HRESULT (STDMETHODCALLTYPE *Download)(GPIDirectInputEffect** self);
HRESULT (STDMETHODCALLTYPE *Unload)(GPIDirectInputEffect** self);
HRESULT (STDMETHODCALLTYPE *Escape)(GPIDirectInputEffect** self, GPDIEffectEscape*);
};
typedef BOOL (CALLBACK *GPDIEnumEffectsInFileCB)(const GPDIFileEffect*, LPVOID);
typedef BOOL (CALLBACK *GPDIConfigureDevicesCB)(void* pUnk, LPVOID);
typedef BOOL (CALLBACK *GPDIEnumDeviceObjectsCB)(const GPDIDeviceObjectInstance* doi, LPVOID);
typedef BOOL (CALLBACK *GPDIEnumDevicesCB)(const GPDIDeviceInstance* di, LPVOID);
typedef BOOL (CALLBACK *GPDIEnumDevicesBySemanticsCB)(const GPDIDeviceInstance* di, struct GPDirectInputDevice*, DWORD, DWORD, LPVOID);
typedef BOOL (CALLBACK *GPDIEnumEffectsCB)(const GPDIEffectInfo* ei, LPVOID);
typedef BOOL (CALLBACK *GPDIEnumCreatedEffectObjectsCB)(GPIDirectInputEffect*, LPVOID);
static const GUID GPDI_GUID_FirstProduct = { 0x20002000, 0x3414, 0x442D, { 0x9A, 0x2F, 0x7F, 0xC2, 0xC6, 0x1A, 0xDE, 0xFB } };
static const GUID GPDI_GUID_FirstInstance = { 0x60000000, 0xC1BD, 0x47DB, { 0x83, 0xDB, 0x26, 0x73, 0x67, 0x65, 0x0D, 0x07 } };
static const GUID GPDI_GUID_IDirectInput8A = { 0xBF798030, 0x483A, 0x4DA2, { 0xAA, 0x99, 0x5D, 0x64, 0xED, 0x36, 0x97, 0x00 } };
static const GUID GPDI_GUID_IDirectInput8W = { 0xBF798031, 0x483A, 0x4DA2, { 0xAA, 0x99, 0x5D, 0x64, 0xED, 0x36, 0x97, 0x00 } };
static const GUID GPDI_GUID_ObjXAxis = { 0xA36D02E0, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjYAxis = { 0xA36D02E1, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjZAxis = { 0xA36D02E2, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjRxAxis = { 0xA36D02F4, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjRyAxis = { 0xA36D02F5, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjRzAxis = { 0xA36D02E3, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjSlider = { 0xA36D02E4, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjButton = { 0xA36D02F0, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjKey = { 0x55728220, 0xD33C, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjPOV = { 0xA36D02F2, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_ObjUnknown = { 0xA36D02F3, 0xC9F3, 0x11CF, { 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } };
static const GUID GPDI_GUID_DevIntfHID = { 0x4D1E55B2, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
static const GUID GPDI_GUID_XBOXProduct = { 0x028E045E, 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
static const wchar_t XBOXProductName[] = L"Controller (XBOX 360 For Windows)";
static const wchar_t XBOXDeviceInstance[] = L"HID\\VID_045E&PID_028E&IG_00\\2&11111111&0&0000";
static const char XBOXDevicePath[] = "\\\\?\\HID#VID_045E&PID_028E&IG_00#2&1111111&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}";
static bool ForceXInputDeviceId, Logged[GPData::NUM_GAMEPADS];
static volatile unsigned int InDirectInputCall;
static void EnterDirectInputCall() { GPInterlockedAdd(&InDirectInputCall, 1); }
static void LeaveDirectInputCall() { GPInterlockedAdd(&InDirectInputCall, -1); }
static void Hook(bool forceLoad = false);
struct GPDIJoyState
{
enum { AXIS_COUNT = 8, POV_COUNT = 4, BUTTON_COUNT = 64 };
union { DWORD axes[AXIS_COUNT]; struct { DWORD lX, lY, lZ, rX, rY, rZ, sliders[2]; }; };
DWORD pov[POV_COUNT];
BYTE buttons[BUTTON_COUNT];
static const GPDIDataFormat* GetDataFormat()
{
static GPDIDataFormat dfJoy;
if (!dfJoy.dwSize)
{
const GUID* axisGuids[6] = { &GPDI_GUID_ObjXAxis, &GPDI_GUID_ObjYAxis, &GPDI_GUID_ObjZAxis, &GPDI_GUID_ObjRxAxis, &GPDI_GUID_ObjRyAxis, &GPDI_GUID_ObjRzAxis };
static GPDIObjectDataFormat dfJoyObjs[3+3+2+4+GPDIJoyState::BUTTON_COUNT];
for (int i = 0; i != 6; i++) dfJoyObjs[i] = { axisGuids[i], (DWORD)FIELD_OFFSET(GPDIJoyState, axes[i]), GPDIDFT_AXIS | GPDIDFT_ANYINSTANCE | GPDIDFT_OPTIONAL, 0, };
for (int i = 0; i != 2; i++) dfJoyObjs[3+3+i] = { &GPDI_GUID_ObjSlider, (DWORD)FIELD_OFFSET(GPDIJoyState, sliders[i]), GPDIDFT_AXIS | GPDIDFT_ANYINSTANCE | GPDIDFT_OPTIONAL, 0, };
for (int i = 0; i != 4; i++) dfJoyObjs[3+3+2+i] = { &GPDI_GUID_ObjPOV, (DWORD)FIELD_OFFSET(GPDIJoyState, pov[i]), GPDIDFT_POV | GPDIDFT_ANYINSTANCE | GPDIDFT_OPTIONAL, 0, };
for (int i = 0; i != GPDIJoyState::BUTTON_COUNT; i++) dfJoyObjs[3+3+2+4+i] = { NULL, (DWORD)FIELD_OFFSET(GPDIJoyState, buttons[i]), GPDIDFT_PSHBUTTON | GPDIDFT_TGLBUTTON | GPDIDFT_ANYINSTANCE | GPDIDFT_OPTIONAL, 0, };
dfJoy = { sizeof(GPDIDataFormat), sizeof(GPDIObjectDataFormat), GPDIDF_ABSAXIS, sizeof(GPDIJoyState), 3+3+2+4+GPDIJoyState::BUTTON_COUNT, dfJoyObjs };
}
return &dfJoy;
}
};
struct GPDIKeyboardState
{
BYTE keys[GPDI_MAX_KEYBOARD];
static const GPDIDataFormat* GetDataFormat()
{
static GPDIDataFormat dfKey;
static GPDIObjectDataFormat dfKeyObjs[GPDI_MAX_KEYBOARD];
for (int i = 0; i != GPDI_MAX_KEYBOARD; i++) dfKeyObjs[i] = { &GPDI_GUID_ObjKey, (DWORD)FIELD_OFFSET(GPDIKeyboardState, keys[i]), GPDIDFT_OPTIONAL|GPDIDFT_BUTTON|GPDIDFT_MAKEINSTANCE(i), 0 };
dfKey = { sizeof(GPDIDataFormat), sizeof(GPDIObjectDataFormat), GPDIDF_RELAXIS, sizeof(GPDIKeyboardState), GPDI_MAX_KEYBOARD, dfKeyObjs };
return &dfKey;
}
};
struct GPDIMouseState
{
enum { AXIS_COUNT = 3, BUTTON_COUNT = 8, EXCESS_SIZE = (BUTTON_COUNT*sizeof(BYTE)) };
union { LONG axes[AXIS_COUNT]; struct { LONG x, y, z; }; };
BYTE buttons[BUTTON_COUNT], held[BUTTON_COUNT];
static const GPDIDataFormat* GetDataFormat()
{
static GPDIDataFormat dfMouse;
static GPDIObjectDataFormat dfMouseObjs[AXIS_COUNT+BUTTON_COUNT];
const GUID* axisGuids[AXIS_COUNT] = { &GPDI_GUID_ObjXAxis, &GPDI_GUID_ObjYAxis, &GPDI_GUID_ObjZAxis };
for (int i = 0; i != AXIS_COUNT; i++) dfMouseObjs[i] = { axisGuids[i], (DWORD)FIELD_OFFSET(GPDIMouseState, axes[i]), GPDIDFT_AXIS | GPDIDFT_ANYINSTANCE | (i >= 2 ? GPDIDFT_OPTIONAL : 0), 0, };
for (int i = 0; i != BUTTON_COUNT; i++) dfMouseObjs[AXIS_COUNT+i] = { &GPDI_GUID_ObjButton, (DWORD)FIELD_OFFSET(GPDIMouseState, buttons[i]), GPDIDFT_BUTTON | GPDIDFT_ANYINSTANCE | (i >= 1 ? GPDIDFT_OPTIONAL : 0), 0, };
dfMouse = { sizeof(GPDIDataFormat), sizeof(GPDIObjectDataFormat), GPDIDF_RELAXIS, sizeof(GPDIMouseState)-EXCESS_SIZE, AXIS_COUNT+BUTTON_COUNT, dfMouseObjs };
return &dfMouse;
}
};
struct GPDIObj
{
enum EMap : unsigned char { NONE, AXIS_STICK, AXIS_MERGELSTICKANDDPAD, AXIS_PAIR, AXIS_SINGLE, BUTTON, DPAD, UNMAPPED_AXIS, UNMAPPED_DPAD };
const WCHAR* Name;
const GUID* Guid;
WORD Type, Flags, CollectionNumber, UsagePage, Usage, Dimension;
LONG RangeMin, RangeMax;
EMap Map;
unsigned char ValIdx;
LONG RangeCenter;
float FactorToNeg, FactorToPos;
DWORD HwOfs, dwOfs;
UINT_PTR appdata;
};
struct GPDirectInputDevice
{
bool IsW;
DWORD Version;
ULONG Refs;
GPGamepad& GP;
unsigned short PrevVals[_GPIDX_MAX];
GPVector<GPDIObj> Objs;
HANDLE Event, EventThread;
static void SwapObj(GPDIObj& a, GPDIObj& b) { GPDIObj c = a; a = b; b = c; }
GPDirectInputDevice(bool isW, DWORD version, GPGamepad& gp) : IsW(isW), Version(version), Refs(1), GP(gp), Event(NULL), EventThread(NULL)
{
memset(&PrevVals, 0, sizeof(PrevVals));
bool isXInputPad = (GameUsesXInput && !ForceVirtualDevices && !(pGPData->Options & OPTION_Disable_XInput));
bool usePOVtoButtons = (!isXInputPad && (pGPData->Options & OPTION_DI_POVtoButtons));
bool useTriggersToButtons = (!isXInputPad && (pGPData->Options & OPTION_DI_TriggersToButtons));
int gpidx_btn_a = ((pGPData->Options & OPTION_SwapAandB) ? GPIDX_BTN_B : GPIDX_BTN_A);
int gpidx_btn_b = ((pGPData->Options & OPTION_SwapAandB) ? GPIDX_BTN_A : GPIDX_BTN_B);
int gpidx_trigger_l = ((pGPData->Options & OPTION_SwapL1R1andL2R2) ? GPIDX_BTN_L : GPIDX_TRIGGER_L);
int gpidx_trigger_r = ((pGPData->Options & OPTION_SwapL1R1andL2R2) ? GPIDX_BTN_R : GPIDX_TRIGGER_R);
int gpidx_btn_l = ((pGPData->Options & OPTION_SwapL1R1andL2R2) ? GPIDX_TRIGGER_L : GPIDX_BTN_L);
int gpidx_btn_r = ((pGPData->Options & OPTION_SwapL1R1andL2R2) ? GPIDX_TRIGGER_R : GPIDX_BTN_R);
Objs.push_back({ L"X Axis", &GPDI_GUID_ObjXAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 1, 1, 48, 0, 0, 0xFFFF, GPDIObj::AXIS_STICK, GPIDX_LSTICK_L });
Objs.push_back({ L"Y Axis", &GPDI_GUID_ObjYAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 1, 1, 49, 0, 0, 0xFFFF, GPDIObj::AXIS_STICK, GPIDX_LSTICK_U });
if (isXInputPad)
Objs.push_back({ L"Z Axis", &GPDI_GUID_ObjZAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 3, 1, 50, 0, 0xFFFF, 0, GPDIObj::AXIS_PAIR, gpidx_trigger_l });
if (!isXInputPad && !useTriggersToButtons)
Objs.push_back({ L"Z Axis", &GPDI_GUID_ObjZAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 3, 1, 50, 0, 0, 0xFFFF, GPDIObj::AXIS_SINGLE, gpidx_trigger_l });
Objs.push_back({ L"X Rotation", &GPDI_GUID_ObjRxAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 2, 1, 51, 0, 0, 0xFFFF, GPDIObj::AXIS_STICK, GPIDX_RSTICK_L });
Objs.push_back({ L"Y Rotation", &GPDI_GUID_ObjRyAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 2, 1, 52, 0, 0, 0xFFFF, GPDIObj::AXIS_STICK, GPIDX_RSTICK_U });
if (!isXInputPad && !useTriggersToButtons)
Objs.push_back({ L"Z Rotation", &GPDI_GUID_ObjRzAxis, GPDIDFT_ABSAXIS, GPDIDOI_ASPECTPOSITION, 3, 1, 53, 0, 0, 0xFFFF, GPDIObj::AXIS_SINGLE, gpidx_trigger_r });
if (!usePOVtoButtons)
Objs.push_back({ L"Hat Switch", &GPDI_GUID_ObjPOV, GPDIDFT_POV, 0, 0, 1, 57, 14, 0, 35999, GPDIObj::DPAD, GPIDX_DPAD_U });
Objs.push_back({ L"Button 0", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 1, 0, 0, 128, GPDIObj::BUTTON, gpidx_btn_a });
Objs.push_back({ L"Button 1", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 2, 0, 0, 128, GPDIObj::BUTTON, gpidx_btn_b });
Objs.push_back({ L"Button 2", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 3, 0, 0, 128, GPDIObj::BUTTON, GPIDX_BTN_X });
Objs.push_back({ L"Button 3", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 4, 0, 0, 128, GPDIObj::BUTTON, GPIDX_BTN_Y });
Objs.push_back({ L"Button 4", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 5, 0, 0, 128, GPDIObj::BUTTON, gpidx_btn_l });
Objs.push_back({ L"Button 5", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 6, 0, 0, 128, GPDIObj::BUTTON, gpidx_btn_r });
Objs.push_back({ L"Button 6", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 7, 0, 0, 128, GPDIObj::BUTTON, GPIDX_BTN_BACK });
Objs.push_back({ L"Button 7", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 8, 0, 0, 128, GPDIObj::BUTTON, GPIDX_BTN_START });
Objs.push_back({ L"Button 8", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 9, 0, 0, 128, GPDIObj::BUTTON, GPIDX_BTN_LSTICK });
Objs.push_back({ L"Button 9", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 10, 0, 0, 128, GPDIObj::BUTTON, GPIDX_BTN_RSTICK });
if (usePOVtoButtons)
{
Objs.push_back({ L"Button 10", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 11, 0, 0, 128, GPDIObj::BUTTON, GPIDX_DPAD_U });
Objs.push_back({ L"Button 11", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 12, 0, 0, 128, GPDIObj::BUTTON, GPIDX_DPAD_D });
Objs.push_back({ L"Button 12", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 13, 0, 0, 128, GPDIObj::BUTTON, GPIDX_DPAD_L });
Objs.push_back({ L"Button 13", &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 14, 0, 0, 128, GPDIObj::BUTTON, GPIDX_DPAD_R });
}
if (useTriggersToButtons)
{
Objs.push_back({ (usePOVtoButtons ? L"Button 14" : L"Button 10"), &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 11, 0, 0, 128, GPDIObj::AXIS_SINGLE, gpidx_trigger_l });
Objs.push_back({ (usePOVtoButtons ? L"Button 15" : L"Button 11"), &GPDI_GUID_ObjButton, GPDIDFT_PSHBUTTON, 0, 0, 9, 12, 0, 0, 128, GPDIObj::AXIS_SINGLE, gpidx_trigger_r });
}
Objs.push_back({ L"Collection 0 - Game Pad" , &GPDI_GUID_ObjUnknown, GPDIDFT_COLLECTION|GPDIDFT_NODATA, 0, 0, 1, 5 });
Objs.push_back({ L"Collection 1" , &GPDI_GUID_ObjUnknown, GPDIDFT_COLLECTION|GPDIDFT_NODATA, 0, 0, 1, 0 });
Objs.push_back({ L"Collection 2" , &GPDI_GUID_ObjUnknown, GPDIDFT_COLLECTION|GPDIDFT_NODATA, 0, 0, 1, 0 });
Objs.push_back({ L"Collection 3" , &GPDI_GUID_ObjUnknown, GPDIDFT_COLLECTION|GPDIDFT_NODATA, 0, 0, 1, 0 });
DWORD ofs = 0, countAxis = 0, countPov = 0, countButton = 0, countCollection = 0;
for (GPDIObj& o : Objs)
{
o.HwOfs = ofs;
o.dwOfs = (DWORD)-1;
switch (o.Type)
{
case GPDIDFT_ABSAXIS: ofs += 4; o.Type |= GPDIDFT_MAKEINSTANCE(countAxis++); break;
case GPDIDFT_POV: ofs += 4; o.Type |= GPDIDFT_MAKEINSTANCE(countPov++); break;
case GPDIDFT_PSHBUTTON: ofs += 1; o.Type |= GPDIDFT_MAKEINSTANCE(countButton++); break;
case GPDIDFT_COLLECTION|GPDIDFT_NODATA: o.HwOfs = 0; o.Type |= GPDIDFT_MAKEINSTANCE(countCollection++); break;
}
o.RangeCenter = o.RangeMin + ((o.RangeMax - o.RangeMin + 1) / 2);
o.FactorToNeg = (o.RangeCenter - o.RangeMin + 0.5f) / -65535.0f;
o.FactorToPos = (o.RangeMax - o.RangeCenter + 0.5f) / 65535.0f;
}
if (isXInputPad)
{
// Make layout match a real XInput controller
SwapObj(Objs[0], Objs[1]); // Swap X and Y (keep instance numbers)
SwapObj(Objs[2], Objs[4]); // Swap Z and RY (keep instance numbers)
Objs.insert(&Objs[16], Objs[5]); // Copy Hat to after Buttons (no change in HwOfs!)
Objs.erase(&Objs[5]); // Remove old Hat
Objs[0].HwOfs = 0; // X has offset 0
Objs[1].HwOfs = 4; // Y has offset 4
Objs[2].HwOfs = 8; // Ry has offset 8
Objs[4].HwOfs = 16; // Z has offset 16
}
if (pGPData->Options & OPTION_DPadToLStick)
{
Objs[0].Map = Objs[1].Map = GPDIObj::AXIS_MERGELSTICKANDDPAD;
}
if (!Logged[&gp - pGPData->Gamepads])
{
Logged[&gp - pGPData->Gamepads] = true;
WriteLog("Application started reading input for %s %s %d%s\n", "DirectInput", "joystick", (int)(&gp - pGPData->Gamepads) + 1, (isXInputPad ? " (simulating XInput gamepad because XInput was also loaded)" : ""));
}
}
~GPDirectInputDevice() { SetEventNotification(NULL); }
static DWORD WINAPI EventThreadFunc(GPDirectInputDevice* self)
{
Sleep(1000); // wait a bit before starting up to let main thread finish up more of the controller setup
for (DWORD dwInOut;;)
{
self->GetDeviceData(0, NULL, &dwInOut, GPDIGDD_PEEK);
if (dwInOut)
SetEvent(self->Event);
Sleep(10);
}
return 0;
}
virtual HRESULT STDMETHODCALLTYPE QueryInterface(const GUID& riid, void** ppvObject) { *ppvObject = this; AddRef(); return S_OK; }
virtual ULONG STDMETHODCALLTYPE AddRef() { return ++Refs; }
virtual ULONG STDMETHODCALLTYPE Release() { if (!--Refs) { delete this; return 0; } return Refs; }
virtual HRESULT STDMETHODCALLTYPE GetCapabilities(GPDIDEVCAPS* lpDIDevCaps)
{
lpDIDevCaps->dwFlags = 5;
lpDIDevCaps->dwDevType = (Version >= GPDI_VERSION_8 ? GPDIMAKEDEVTYPE(GPDI8DEVTYPE_GAMEPAD, GPDI8SUBDEVTYPE_GAMEPAD_STANDARD, GPDIDEVTYPE_HID) : GPDI1DEVTYPE_JOYSTICK);
lpDIDevCaps->dwAxes = lpDIDevCaps->dwButtons = lpDIDevCaps->dwPOVs = 0;
for (GPDIObj& o : Objs)
{
if (o.Type & GPDIDFT_AXIS) lpDIDevCaps->dwAxes++;
if (o.Type & GPDIDFT_BUTTON) lpDIDevCaps->dwButtons++;
if (o.Type & GPDIDFT_POV) lpDIDevCaps->dwPOVs++;
}
if (lpDIDevCaps->dwSize >= sizeof(*lpDIDevCaps))
{
lpDIDevCaps->dwFFSamplePeriod = 0;
lpDIDevCaps->dwFFMinTimeResolution = 0;
lpDIDevCaps->dwFirmwareRevision = 0;
lpDIDevCaps->dwHardwareRevision = 0;
lpDIDevCaps->dwFFDriverVersion = 0;
}
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE EnumObjects(GPDIEnumDeviceObjectsCB lpCallback, LPVOID pvRef, DWORD dwFlags)
{
GPDIDeviceObjectInstance i;
auto e = i.GetExtra(IsW);
memset(&i, 0, sizeof(i));
i.dwSize = i.GetSize(IsW);
for (GPDIObj& o : Objs)
{
if (dwFlags && !(o.Type & dwFlags)) continue;
i.guidType = *o.Guid;
i.dwOfs = o.HwOfs;
i.dwType = o.Type;
i.dwFlags = o.Flags;
i.SetStrings(IsW, o.Name);
e->wCollectionNumber = o.CollectionNumber;
e->wUsagePage = o.UsagePage;
e->wUsage = o.Usage;
e->dwDimension = o.Dimension;
lpCallback(&i, pvRef);
}
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE GetProperty(const GUID& rguidProp, GPDIPropHeader* pdiph)
{
for (GPDIObj& o : Objs)
{
switch (pdiph->dwHow)
{
case GPDIPH_DEVICE: if (pdiph->dwObj == 0) break; else return E_FAIL;
case GPDIPH_BYOFFSET: if (o.dwOfs == pdiph->dwObj) break; else continue;
case GPDIPH_BYID: if (o.Type == pdiph->dwObj) break; else continue;
case GPDIPH_BYUSAGE: if (o.Usage == pdiph->dwObj) break; else continue;
default: return E_FAIL;
}
switch ((size_t)(void*)&rguidProp)
{
case GPDIPROP_BUFFERSIZE:
((GPDIPropDWord*)pdiph)->dwData = 0;
return S_OK;
case GPDIPROP_AXISMODE:
if (o.Type != GPDIDFT_ABSAXIS) return E_FAIL;
((GPDIPropDWord*)pdiph)->dwData = GPDIPROPAXISMODE_ABS;
return S_OK;
case GPDIPROP_GRANULARITY:
((GPDIPropDWord*)pdiph)->dwData = 1;
return S_OK;
case GPDIPROP_RANGE:
if (o.RangeMin < o.RangeMax) { ((GPDIPropRange*)pdiph)->lMin = o.RangeMin; ((GPDIPropRange*)pdiph)->lMax = o.RangeMax; }
else { ((GPDIPropRange*)pdiph)->lMin = o.RangeMax; ((GPDIPropRange*)pdiph)->lMax = o.RangeMin; }
return S_OK;
case GPDIPROP_DEADZONE:
((GPDIPropDWord*)pdiph)->dwData = 0;
return S_OK;
case GPDIPROP_SATURATION:
((GPDIPropDWord*)pdiph)->dwData = 10000;
case GPDIPROP_FFGAIN:
((GPDIPropDWord*)pdiph)->dwData = 0;
return S_OK;
case GPDIPROP_FFLOAD:
((GPDIPropDWord*)pdiph)->dwData = 0;
return S_OK;
case GPDIPROP_AUTOCENTER:
((GPDIPropDWord*)pdiph)->dwData = GPDIPROPAUTOCENTER_ON;
return S_OK;
case GPDIPROP_CALIBRATIONMODE:
((GPDIPropDWord*)pdiph)->dwData = GPDIPROPCALIBRATIONMODE_COOKED;
return S_OK;
case GPDI5PROP_CALIBRATION:
((GPDIPropCal*)pdiph)->lMin = 0;
((GPDIPropCal*)pdiph)->lCenter = 0x8000;
((GPDIPropCal*)pdiph)->lMax = 0xFFFF;
return S_OK;
case GPDI5PROP_GUIDANDPATH:
((GPDIPropGUIDAndPath*)pdiph)->guidClass = GPDI_GUID_DevIntfHID;
MultiByteToWideChar(CP_ACP, 0, XBOXDevicePath, sizeof(XBOXDevicePath), ((GPDIPropGUIDAndPath*)pdiph)->wszPath, MAX_PATH);
return S_OK;
//case GPDI5PROP_INSTANCENAME: // unsupported
//case GPDI5PROP_PRODUCTNAME: // unsupported
case GPDI5PROP_JOYSTICKID:
((GPDIPropDWord*)pdiph)->dwData = (DWORD)(1 + (&GP - pGPData->Gamepads));
return S_OK;
case GPDI5PROP_GETPORTDISPLAYNAME:
wcscpy(((GPDIPropString*)pdiph)->wsz, XBOXProductName);
return S_FALSE; // real device does this, too
case GPDI7PROP_PHYSICALRANGE:
case GPDI7PROP_LOGICALRANGE:
((GPDIPropRange*)pdiph)->lMin = 0;
((GPDIPropRange*)pdiph)->lMax = 0xFFFF;
return S_OK;
case GPDI8PROP_APPDATA:
((GPDIPropPointer*)pdiph)->uData = o.appdata;
return S_OK;
case GPDI8PROP_VIDPID:
((GPDIPropDWord*)pdiph)->dwData = GPDI_GUID_XBOXProduct.Data1;
return S_OK;
case GPDI8PROP_USERNAME:
return S_FALSE; // no user set
case GPDI8PROP_TYPENAME:
MultiByteToWideChar(CP_ACP, 0, "VID_045E&PID_028E", sizeof("VID_045E&PID_028E"), ((GPDIPropGUIDAndPath*)pdiph)->wszPath, MAX_PATH);
return S_OK;
}
}
return GPDIERR_OBJECTNOTFOUND;
}
virtual HRESULT STDMETHODCALLTYPE SetProperty(const GUID& rguidProp, const GPDIPropHeader* pdiph)
{
for (GPDIObj& o : Objs)
{
switch (pdiph->dwHow)
{
case GPDIPH_DEVICE: if (pdiph->dwObj == 0) break; else return E_FAIL;
case GPDIPH_BYOFFSET: if (o.dwOfs == pdiph->dwObj) break; else continue;
case GPDIPH_BYID: if (o.Type == pdiph->dwObj) break; else continue;
case GPDIPH_BYUSAGE: if (o.Usage == pdiph->dwObj) break; else continue;
default: return E_FAIL;
}
switch ((size_t)&rguidProp)
{
case GPDIPROP_RANGE:
if (((const GPDIPropRange*)pdiph)->lMin >= ((const GPDIPropRange*)pdiph)->lMax) return E_FAIL;
if (o.RangeMin > o.RangeMax) { o.RangeMin = ((const GPDIPropRange*)pdiph)->lMax; o.RangeMax = ((const GPDIPropRange*)pdiph)->lMin; }
else { o.RangeMin = ((const GPDIPropRange*)pdiph)->lMin; o.RangeMax = ((const GPDIPropRange*)pdiph)->lMax; }
o.RangeCenter = o.RangeMin + ((o.RangeMax - o.RangeMin + 1) / 2);
o.FactorToNeg = (o.RangeCenter - o.RangeMin + 0.5f) / -65535.0f;
o.FactorToPos = (o.RangeMax - o.RangeCenter + 0.5f) / 65535.0f;
break;
case GPDIPROP_DEADZONE: // todo
case GPDIPROP_SATURATION: // todo
case GPDIPROP_FFGAIN: // todo
//case GPDI5PROP_INSTANCENAME: // unsupported
//case GPDI5PROP_PRODUCTNAME: // unsupported
case GPDI8PROP_CPOINTS:
case GPDI8PROP_APPDATA:
o.appdata = ((GPDIPropPointer*)pdiph)->uData;
break;
}
}
return S_OK; //accept all setprop
}
virtual HRESULT STDMETHODCALLTYPE Acquire()
{
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE Unacquire()
{
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE GetDeviceState(DWORD cbData, LPVOID lpvData)
{
if (!lpvData) return E_FAIL;
RunInputUpdaters(GP);
DWORD val;
memset(lpvData, 0, cbData);
for (const GPDIObj& o : Objs)
{
switch (o.Map)
{
case GPDIObj::AXIS_STICK:
val = (DWORD)(o.RangeCenter
+ (LONG)(GP.Axis(o.ValIdx) * o.FactorToNeg)
+ (LONG)(GP.Axis(o.ValIdx+1) * o.FactorToPos));
goto write_val;
case GPDIObj::AXIS_MERGELSTICKANDDPAD:
val = (DWORD)(o.RangeCenter
+ (LONG)(GP.Axis(o.ValIdx, true) * o.FactorToNeg)
+ (LONG)(GP.Axis(o.ValIdx+1, true) * o.FactorToPos));
goto write_val;
case GPDIObj::AXIS_PAIR:
val = (DWORD)(o.RangeCenter
+ (LONG)(GP.Vals[o.ValIdx] * o.FactorToNeg)
+ (LONG)(GP.Vals[o.ValIdx+1] * o.FactorToPos));
goto write_val;
case GPDIObj::AXIS_SINGLE:
val = (DWORD)(o.RangeCenter
+ (LONG)(GP.Vals[o.ValIdx] * o.FactorToPos));
goto write_val;
case GPDIObj::BUTTON:
val = ((GP.Vals[o.ValIdx] & 0x8000u) ? (DWORD)o.RangeMax : (DWORD)o.RangeMin);
goto write_val;
case GPDIObj::UNMAPPED_AXIS:
val = (DWORD)o.RangeCenter;
goto write_val;
case GPDIObj::UNMAPPED_DPAD:
val = 0xFFFFFFFF;
goto write_val;
case GPDIObj::DPAD:
unsigned int mask =
((GP.Vals[o.ValIdx ] & 0x8000u) >> 15) | // 1 UP
((GP.Vals[o.ValIdx+1] & 0x8000u) >> 14) | // 2 DOWN
((GP.Vals[o.ValIdx+2] & 0x8000u) >> 13) | // 4 LEFT
((GP.Vals[o.ValIdx+3] & 0x8000u) >> 12); // 8 RIGHT
static const DWORD DPADDatas[] = { 0xFFFFFFFF, 0, 18000, 0xFFFFFFFF, 27000, 31500, 22500, 27000, 9000, 4500, 13500, 9000, 0xFFFFFFFF, 0, 18000, 0xFFFFFFFF };
val = DPADDatas[mask];
if (val != 0xFFFFFFFF && (o.RangeMin != 0 || o.RangeMax != 35999))
val = o.RangeMin + (DWORD)((val / 35999.0) * (o.RangeMax - o.RangeMin));
goto write_val;
write_val:
if (o.Type & GPDIDFT_BUTTON) { if (o.dwOfs < cbData) *((BYTE*)lpvData + o.dwOfs) = (BYTE)(val & 0x80); }
else { if (o.dwOfs + sizeof(DWORD) <= cbData) memcpy((char*)lpvData + o.dwOfs, &val, sizeof(DWORD)); }
}
}
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE GetDeviceData(DWORD cbObjectData, GPDIDeviceObjectData* rgdod, LPDWORD pdwInOut, DWORD dwFlags)
{
if (!pdwInOut) return E_FAIL;
RunInputUpdaters(GP);
DWORD wantNum = (rgdod && !(dwFlags & GPDIGDD_PEEK) ? *pdwInOut : 0), haveNum = 0;
for (const GPDIObj& o : Objs)
{
switch (o.Map)
{
case GPDIObj::AXIS_STICK:
{
unsigned short v0 = GP.Axis(o.ValIdx), v1 = GP.Axis(o.ValIdx+1);
if (PrevVals[o.ValIdx] == v0 && PrevVals[o.ValIdx+1] == v1) continue;
haveNum++;
if (!wantNum) continue;
rgdod->dwData = o.RangeCenter
+ (DWORD)((PrevVals[o.ValIdx ] = v0) * o.FactorToNeg)
+ (DWORD)((PrevVals[o.ValIdx+1] = v1) * o.FactorToPos);
goto write_want;
}
case GPDIObj::AXIS_MERGELSTICKANDDPAD:
{
unsigned short v0 = GP.Axis(o.ValIdx, true), v1 = GP.Axis(o.ValIdx+1, true);
if (PrevVals[o.ValIdx] == v0 && PrevVals[o.ValIdx+1] == v1) continue;
haveNum++;
if (!wantNum) continue;
rgdod->dwData = o.RangeCenter
+ (DWORD)((PrevVals[o.ValIdx ] = v0) * o.FactorToNeg)
+ (DWORD)((PrevVals[o.ValIdx+1] = v1) * o.FactorToPos);
goto write_want;
}
case GPDIObj::AXIS_PAIR:
if (PrevVals[o.ValIdx] == GP.Vals[o.ValIdx] && PrevVals[o.ValIdx+1] == GP.Vals[o.ValIdx+1]) continue;
haveNum++;
if (!wantNum) continue;
rgdod->dwData = o.RangeCenter
+ (DWORD)((PrevVals[o.ValIdx ] = GP.Vals[o.ValIdx ]) * o.FactorToNeg)
+ (DWORD)((PrevVals[o.ValIdx+1] = GP.Vals[o.ValIdx+1]) * o.FactorToPos);
goto write_want;
case GPDIObj::AXIS_SINGLE:
if (PrevVals[o.ValIdx] == GP.Vals[o.ValIdx]) continue;
haveNum++;
if (!wantNum) continue;
rgdod->dwData = o.RangeCenter
+ (DWORD)((PrevVals[o.ValIdx ] = GP.Vals[o.ValIdx ]) * o.FactorToPos);
goto write_want;
case GPDIObj::BUTTON:
if ((PrevVals[o.ValIdx] & 0x8000u) == (GP.Vals[o.ValIdx] & 0x8000u)) continue;
haveNum++;
if (!wantNum) continue;
rgdod->dwData = (((PrevVals[o.ValIdx] = GP.Vals[o.ValIdx]) & 0x8000u) ? o.RangeMax : o.RangeMin);
goto write_want;
case GPDIObj::DPAD:
if ( (PrevVals[o.ValIdx ] & 0x8000u) == (GP.Vals[o.ValIdx ] & 0x8000u)
&& (PrevVals[o.ValIdx+1] & 0x8000u) == (GP.Vals[o.ValIdx+1] & 0x8000u)
&& (PrevVals[o.ValIdx+2] & 0x8000u) == (GP.Vals[o.ValIdx+2] & 0x8000u)
&& (PrevVals[o.ValIdx+3] & 0x8000u) == (GP.Vals[o.ValIdx+3] & 0x8000u)) continue;
haveNum++;
if (!wantNum) continue;
unsigned int mask =
(((PrevVals[o.ValIdx ] = GP.Vals[o.ValIdx ]) & 0x8000u) >> 15) | // 1 UP
(((PrevVals[o.ValIdx+1] = GP.Vals[o.ValIdx+1]) & 0x8000u) >> 14) | // 2 DOWN
(((PrevVals[o.ValIdx+2] = GP.Vals[o.ValIdx+2]) & 0x8000u) >> 13) | // 4 LEFT
(((PrevVals[o.ValIdx+3] = GP.Vals[o.ValIdx+3]) & 0x8000u) >> 12); // 8 RIGHT
static const DWORD DPADDatas[] = { 0xFFFFFFFF, 0, 18000, 0xFFFFFFFF, 27000, 31500, 22500, 27000, 9000, 4500, 13500, 9000, 0xFFFFFFFF, 0, 18000, 0xFFFFFFFF };
rgdod->dwData = DPADDatas[mask];
if (rgdod->dwData != 0xFFFFFFFF && (o.RangeMin != 0 || o.RangeMax != 35999))
rgdod->dwData = o.RangeMin + (DWORD)((rgdod->dwData / 35999.0) * (o.RangeMax - o.RangeMin));
goto write_want;
write_want:
static DWORD seq = 133147;
if (haveNum == 1) seq += 2;
rgdod->dwTimeStamp = GP.TimeStamp;
rgdod->dwOfs = o.dwOfs;
rgdod->dwSequence = seq;
if (cbObjectData == sizeof(*rgdod)) rgdod->uAppData = (UINT_PTR)-1;
rgdod = (GPDIDeviceObjectData*)((char*)rgdod + cbObjectData);
wantNum--;
continue;
}
}
*pdwInOut = haveNum;
return S_OK;