-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGPViGEm.inl
3141 lines (2641 loc) · 84.9 KB
/
GPViGEm.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
/*
MIT License
Copyright (c) 2017-2023 Nefarius Software Solutions e.U. and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
//#define VIGEM_ASYNC_FUNCTIONS
//#define VIGEM_DS4
//
// WinAPI
//
//#include <Windows.h>
#include <SetupAPI.h>
//#include <initguid.h>
//#include <strsafe.h>
//
// Driver shared
//
#include <winioctl.h>
//
// STL
//
//#include <cstdlib>
//#include <climits>
//#include <thread>
//#include <functional>
//#include <string>
//#include <iostream>
namespace GPViGEm {
namespace std { typedef size_t size; };
//
// Driver shared
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#include "ViGEm/Common.h"
/*
MIT License
Copyright (c) 2017-2023 Nefarius Software Solutions e.U. and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
//
// Represents the desired target type for the emulated device.
//
typedef enum _VIGEM_TARGET_TYPE
{
//
// Microsoft Xbox 360 Controller (wired)
//
Xbox360Wired = 0,
#ifdef VIGEM_DS4
//
// Sony DualShock 4 (wired)
//
DualShock4Wired = 2 // NOTE: 1 skipped on purpose to maintain compatibility
#endif // VIGEM_DS4
} VIGEM_TARGET_TYPE, *PVIGEM_TARGET_TYPE;
//
// Possible XUSB report buttons.
//
typedef enum _XUSB_BUTTON
{
XUSB_GAMEPAD_DPAD_UP = 0x0001,
XUSB_GAMEPAD_DPAD_DOWN = 0x0002,
XUSB_GAMEPAD_DPAD_LEFT = 0x0004,
XUSB_GAMEPAD_DPAD_RIGHT = 0x0008,
XUSB_GAMEPAD_START = 0x0010,
XUSB_GAMEPAD_BACK = 0x0020,
XUSB_GAMEPAD_LEFT_THUMB = 0x0040,
XUSB_GAMEPAD_RIGHT_THUMB = 0x0080,
XUSB_GAMEPAD_LEFT_SHOULDER = 0x0100,
XUSB_GAMEPAD_RIGHT_SHOULDER = 0x0200,
XUSB_GAMEPAD_GUIDE = 0x0400,
XUSB_GAMEPAD_A = 0x1000,
XUSB_GAMEPAD_B = 0x2000,
XUSB_GAMEPAD_X = 0x4000,
XUSB_GAMEPAD_Y = 0x8000
} XUSB_BUTTON, *PXUSB_BUTTON;
//
// Represents an XINPUT_GAMEPAD-compatible report structure.
//
typedef struct _XUSB_REPORT
{
USHORT wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
} XUSB_REPORT, *PXUSB_REPORT;
//
// Initializes a _XUSB_REPORT structure.
//
VOID FORCEINLINE XUSB_REPORT_INIT(
_Out_ PXUSB_REPORT Report
)
{
RtlZeroMemory(Report, sizeof(XUSB_REPORT));
}
//
// Values set by output reports on XINPUT_GAMEPAD
//
typedef struct _XUSB_OUTPUT_DATA
{
UCHAR LargeMotor;
UCHAR SmallMotor;
UCHAR LedNumber;
} XUSB_OUTPUT_DATA, *PXUSB_OUTPUT_DATA;
#ifdef VIGEM_DS4
//
// The color value (RGB) of a DualShock 4 Lightbar
//
typedef struct _DS4_LIGHTBAR_COLOR
{
//
// Red part of the Lightbar (0-255).
//
UCHAR Red;
//
// Green part of the Lightbar (0-255).
//
UCHAR Green;
//
// Blue part of the Lightbar (0-255).
//
UCHAR Blue;
} DS4_LIGHTBAR_COLOR, *PDS4_LIGHTBAR_COLOR;
//
// DualShock 4 digital buttons
//
typedef enum _DS4_BUTTONS
{
DS4_BUTTON_THUMB_RIGHT = 1 << 15,
DS4_BUTTON_THUMB_LEFT = 1 << 14,
DS4_BUTTON_OPTIONS = 1 << 13,
DS4_BUTTON_SHARE = 1 << 12,
DS4_BUTTON_TRIGGER_RIGHT = 1 << 11,
DS4_BUTTON_TRIGGER_LEFT = 1 << 10,
DS4_BUTTON_SHOULDER_RIGHT = 1 << 9,
DS4_BUTTON_SHOULDER_LEFT = 1 << 8,
DS4_BUTTON_TRIANGLE = 1 << 7,
DS4_BUTTON_CIRCLE = 1 << 6,
DS4_BUTTON_CROSS = 1 << 5,
DS4_BUTTON_SQUARE = 1 << 4
} DS4_BUTTONS, *PDS4_BUTTONS;
//
// DualShock 4 special buttons
//
typedef enum _DS4_SPECIAL_BUTTONS
{
DS4_SPECIAL_BUTTON_PS = 1 << 0,
DS4_SPECIAL_BUTTON_TOUCHPAD = 1 << 1
} DS4_SPECIAL_BUTTONS, *PDS4_SPECIAL_BUTTONS;
//
// DualShock 4 directional pad (HAT) values
//
typedef enum _DS4_DPAD_DIRECTIONS
{
DS4_BUTTON_DPAD_NONE = 0x8,
DS4_BUTTON_DPAD_NORTHWEST = 0x7,
DS4_BUTTON_DPAD_WEST = 0x6,
DS4_BUTTON_DPAD_SOUTHWEST = 0x5,
DS4_BUTTON_DPAD_SOUTH = 0x4,
DS4_BUTTON_DPAD_SOUTHEAST = 0x3,
DS4_BUTTON_DPAD_EAST = 0x2,
DS4_BUTTON_DPAD_NORTHEAST = 0x1,
DS4_BUTTON_DPAD_NORTH = 0x0
} DS4_DPAD_DIRECTIONS, *PDS4_DPAD_DIRECTIONS;
//
// DualShock 4 HID Input report
//
typedef struct _DS4_REPORT
{
BYTE bThumbLX;
BYTE bThumbLY;
BYTE bThumbRX;
BYTE bThumbRY;
USHORT wButtons;
BYTE bSpecial;
BYTE bTriggerL;
BYTE bTriggerR;
} DS4_REPORT, *PDS4_REPORT;
//
// Sets the current state of the D-PAD on a DualShock 4 report.
//
VOID FORCEINLINE DS4_SET_DPAD(
_Out_ PDS4_REPORT Report,
_In_ DS4_DPAD_DIRECTIONS Dpad
)
{
Report->wButtons &= ~0xF;
Report->wButtons |= (USHORT)Dpad;
}
VOID FORCEINLINE DS4_REPORT_INIT(
_Out_ PDS4_REPORT Report
)
{
RtlZeroMemory(Report, sizeof(DS4_REPORT));
Report->bThumbLX = 0x80;
Report->bThumbLY = 0x80;
Report->bThumbRX = 0x80;
Report->bThumbRY = 0x80;
DS4_SET_DPAD(Report, DS4_BUTTON_DPAD_NONE);
}
//
// Values set by output reports on DualShock 4
//
typedef struct _DS4_OUTPUT_DATA
{
UCHAR LargeMotor;
UCHAR SmallMotor;
DS4_LIGHTBAR_COLOR LightbarColor;
} DS4_OUTPUT_DATA, *PDS4_OUTPUT_DATA;
#include <pshpack1.h> // pack structs tightly
//
// DualShock 4 HID Touchpad structure
//
typedef struct _DS4_TOUCH
{
BYTE bPacketCounter; // timestamp / packet counter associated with touch event
BYTE bIsUpTrackingNum1; // 0 means down; active low
// unique to each finger down, so for a lift and repress the value is incremented
BYTE bTouchData1[3]; // Two 12 bits values (for X and Y)
// middle byte holds last 4 bits of X and the starting 4 bits of Y
BYTE bIsUpTrackingNum2; // second touch data immediately follows data of first touch
BYTE bTouchData2[3]; // resolution is 1920x943
} DS4_TOUCH, * PDS4_TOUCH;
//
// DualShock 4 v1 complete HID Input report
//
typedef struct _DS4_REPORT_EX
{
union
{
struct
{
BYTE bThumbLX;
BYTE bThumbLY;
BYTE bThumbRX;
BYTE bThumbRY;
USHORT wButtons;
BYTE bSpecial;
BYTE bTriggerL;
BYTE bTriggerR;
USHORT wTimestamp;
BYTE bBatteryLvl;
SHORT wGyroX;
SHORT wGyroY;
SHORT wGyroZ;
SHORT wAccelX;
SHORT wAccelY;
SHORT wAccelZ;
BYTE _bUnknown1[5];
BYTE bBatteryLvlSpecial;
// really should have a enum to show everything that this can represent (USB charging, battery level; EXT, headset, microphone connected)
BYTE _bUnknown2[2];
BYTE bTouchPacketsN; // 0x00 to 0x03 (USB max)
DS4_TOUCH sCurrentTouch;
DS4_TOUCH sPreviousTouch[2];
} Report;
UCHAR ReportBuffer[63];
};
} DS4_REPORT_EX, *PDS4_REPORT_EX;
typedef struct _DS4_OUTPUT_BUFFER
{
//
// The output report buffer
//
_Out_ UCHAR Buffer[64];
} DS4_OUTPUT_BUFFER, *PDS4_OUTPUT_BUFFER;
#include <poppack.h>
#endif // VIGEM_DS4
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#include "ViGEm/km/BusShared.h"
/*
MIT License
Copyright (c) 2016-2019 Nefarius Software Solutions e.U. and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
//
// GUID identifying the bus device. Used by client library to detect and communicate.
//
// IMPORTANT: make sure to change this value if you fork it or introduce
// breaking changes!
//
// {96E42B22-F5E9-42F8-B043-ED0F932F014F}
//DEFINE_GUID(GUID_DEVINTERFACE_BUSENUM_VIGEM,
// 0x96E42B22, 0xF5E9, 0x42F8, 0xB0, 0x43, 0xED, 0x0F, 0x93, 0x2F, 0x01, 0x4F);
const GUID /*DECLSPEC_SELECTANY*/ GUID_DEVINTERFACE_BUSENUM_VIGEM
= { 0x96E42B22, 0xF5E9, 0x42F8, { 0xB0, 0x43, 0xED, 0x0F, 0x93, 0x2F, 0x01, 0x4F } };
#pragma once
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#include "ViGEm/Common.h"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Common version for user-mode library and driver compatibility
//
// On initialization, the user-mode library has this number embedded
// and sends it to the bus on its enumeration. The bus compares this
// number to the one it was compiled with. If they match, the bus
// access is permitted and success reported. If they mismatch, an
// error is reported and the user-mode library skips this instance.
//
#define VIGEM_COMMON_VERSION 0x0001
#define FILE_DEVICE_BUSENUM FILE_DEVICE_BUS_EXTENDER
#define BUSENUM_IOCTL(_index_) CTL_CODE(FILE_DEVICE_BUSENUM, _index_, METHOD_BUFFERED, FILE_READ_DATA)
#define BUSENUM_W_IOCTL(_index_) CTL_CODE(FILE_DEVICE_BUSENUM, _index_, METHOD_BUFFERED, FILE_WRITE_DATA)
#define BUSENUM_R_IOCTL(_index_) CTL_CODE(FILE_DEVICE_BUSENUM, _index_, METHOD_BUFFERED, FILE_READ_DATA)
#define BUSENUM_RW_IOCTL(_index_) CTL_CODE(FILE_DEVICE_BUSENUM, _index_, METHOD_BUFFERED, FILE_WRITE_DATA | FILE_READ_DATA)
#define IOCTL_VIGEM_BASE 0x801
//
// IO control codes
//
#define IOCTL_VIGEM_PLUGIN_TARGET BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x000)
#define IOCTL_VIGEM_UNPLUG_TARGET BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x001)
#define IOCTL_VIGEM_CHECK_VERSION BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x002)
#define IOCTL_VIGEM_WAIT_DEVICE_READY BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x003)
#define IOCTL_XUSB_REQUEST_NOTIFICATION BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x200)
#define IOCTL_XUSB_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x201)
#ifdef VIGEM_DS4
#define IOCTL_DS4_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x202)
#define IOCTL_DS4_REQUEST_NOTIFICATION BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x203)
#endif // VIGEM_DS4
//#define IOCTL_XGIP_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x204)
//#define IOCTL_XGIP_SUBMIT_INTERRUPT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x205)
#define IOCTL_XUSB_GET_USER_INDEX BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x206)
#ifdef VIGEM_DS4
#define IOCTL_DS4_AWAIT_OUTPUT_AVAILABLE BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x207)
#endif // VIGEM_DS4
//
// Data structure used in PlugIn and UnPlug ioctls
//
#pragma region Plugin
//
// Data structure used in IOCTL_VIGEM_PLUGIN_TARGET requests.
//
typedef struct _VIGEM_PLUGIN_TARGET
{
//
// sizeof (struct _BUSENUM_HARDWARE)
//
IN ULONG Size;
//
// Serial number of target device.
//
IN ULONG SerialNo;
//
// Type of the target device to emulate.
//
VIGEM_TARGET_TYPE TargetType;
//
// If set, the vendor ID the emulated device is reporting
//
USHORT VendorId;
//
// If set, the product ID the emulated device is reporting
//
USHORT ProductId;
} VIGEM_PLUGIN_TARGET, *PVIGEM_PLUGIN_TARGET;
//
// Initializes a VIGEM_PLUGIN_TARGET structure.
//
VOID FORCEINLINE VIGEM_PLUGIN_TARGET_INIT(
_Out_ PVIGEM_PLUGIN_TARGET PlugIn,
_In_ ULONG SerialNo,
_In_ VIGEM_TARGET_TYPE TargetType
)
{
RtlZeroMemory(PlugIn, sizeof(VIGEM_PLUGIN_TARGET));
PlugIn->Size = sizeof(VIGEM_PLUGIN_TARGET);
PlugIn->SerialNo = SerialNo;
PlugIn->TargetType = TargetType;
}
#pragma endregion
#pragma region Unplug
//
// Data structure used in IOCTL_VIGEM_UNPLUG_TARGET requests.
//
typedef struct _VIGEM_UNPLUG_TARGET
{
//
// sizeof (struct _REMOVE_HARDWARE)
//
IN ULONG Size;
//
// Serial number of target device.
//
ULONG SerialNo;
} VIGEM_UNPLUG_TARGET, *PVIGEM_UNPLUG_TARGET;
//
// Initializes a VIGEM_UNPLUG_TARGET structure.
//
VOID FORCEINLINE VIGEM_UNPLUG_TARGET_INIT(
_Out_ PVIGEM_UNPLUG_TARGET UnPlug,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(UnPlug, sizeof(VIGEM_UNPLUG_TARGET));
UnPlug->Size = sizeof(VIGEM_UNPLUG_TARGET);
UnPlug->SerialNo = SerialNo;
}
#pragma endregion
#pragma region Check version
typedef struct _VIGEM_CHECK_VERSION
{
IN ULONG Size;
IN ULONG Version;
} VIGEM_CHECK_VERSION, *PVIGEM_CHECK_VERSION;
VOID FORCEINLINE VIGEM_CHECK_VERSION_INIT(
_Out_ PVIGEM_CHECK_VERSION CheckVersion,
_In_ ULONG Version
)
{
RtlZeroMemory(CheckVersion, sizeof(VIGEM_CHECK_VERSION));
CheckVersion->Size = sizeof(VIGEM_CHECK_VERSION);
CheckVersion->Version = Version;
}
#pragma endregion
#pragma region Wait device ready
typedef struct _VIGEM_WAIT_DEVICE_READY
{
IN ULONG Size;
IN ULONG SerialNo;
} VIGEM_WAIT_DEVICE_READY, * PVIGEM_WAIT_DEVICE_READY;
VOID FORCEINLINE VIGEM_WAIT_DEVICE_READY_INIT(
_Out_ PVIGEM_WAIT_DEVICE_READY WaitReady,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(WaitReady, sizeof(VIGEM_WAIT_DEVICE_READY));
WaitReady->Size = sizeof(VIGEM_WAIT_DEVICE_READY);
WaitReady->SerialNo = SerialNo;
}
#pragma endregion
#pragma region XUSB (aka Xbox 360 device) section
//
// Data structure used in IOCTL_XUSB_REQUEST_NOTIFICATION requests.
//
typedef struct _XUSB_REQUEST_NOTIFICATION
{
//
// sizeof(struct _XUSB_REQUEST_NOTIFICATION)
//
ULONG Size;
//
// Serial number of target device.
//
ULONG SerialNo;
//
// Vibration intensity value of the large motor (0-255).
//
UCHAR LargeMotor;
//
// Vibration intensity value of the small motor (0-255).
//
UCHAR SmallMotor;
//
// Index number of the slot/LED that XUSB.sys has assigned.
//
UCHAR LedNumber;
} XUSB_REQUEST_NOTIFICATION, *PXUSB_REQUEST_NOTIFICATION;
//
// Initializes a XUSB_REQUEST_NOTIFICATION structure.
//
VOID FORCEINLINE XUSB_REQUEST_NOTIFICATION_INIT(
_Out_ PXUSB_REQUEST_NOTIFICATION Request,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Request, sizeof(XUSB_REQUEST_NOTIFICATION));
Request->Size = sizeof(XUSB_REQUEST_NOTIFICATION);
Request->SerialNo = SerialNo;
}
//
// Data structure used in IOCTL_XUSB_SUBMIT_REPORT requests.
//
typedef struct _XUSB_SUBMIT_REPORT
{
//
// sizeof(struct _XUSB_SUBMIT_REPORT)
//
ULONG Size;
//
// Serial number of target device.
//
ULONG SerialNo;
//
// Report to submit to the target device.
//
XUSB_REPORT Report;
} XUSB_SUBMIT_REPORT, *PXUSB_SUBMIT_REPORT;
//
// Initializes an XUSB report.
//
VOID FORCEINLINE XUSB_SUBMIT_REPORT_INIT(
_Out_ PXUSB_SUBMIT_REPORT Report,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Report, sizeof(XUSB_SUBMIT_REPORT));
Report->Size = sizeof(XUSB_SUBMIT_REPORT);
Report->SerialNo = SerialNo;
}
typedef struct _XUSB_GET_USER_INDEX
{
//
// sizeof(struct _XUSB_GET_USER_INDEX)
//
ULONG Size;
//
// Serial number of target device.
//
ULONG SerialNo;
//
// User index of target device.
//
OUT ULONG UserIndex;
} XUSB_GET_USER_INDEX, *PXUSB_GET_USER_INDEX;
//
// Initializes XUSB_GET_USER_INDEX structure.
//
VOID FORCEINLINE XUSB_GET_USER_INDEX_INIT(
_Out_ PXUSB_GET_USER_INDEX GetRequest,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(GetRequest, sizeof(XUSB_GET_USER_INDEX));
GetRequest->Size = sizeof(XUSB_GET_USER_INDEX);
GetRequest->SerialNo = SerialNo;
}
#pragma endregion
#ifdef VIGEM_DS4
#pragma region DualShock 4 section
typedef struct _DS4_OUTPUT_REPORT
{
//
// Vibration intensity value of the small motor (0-255).
//
UCHAR SmallMotor;
//
// Vibration intensity value of the large motor (0-255).
//
UCHAR LargeMotor;
//
// Color values of the Lightbar.
//
DS4_LIGHTBAR_COLOR LightbarColor;
} DS4_OUTPUT_REPORT, *PDS4_OUTPUT_REPORT;
//
// Data structure used in IOCTL_DS4_REQUEST_NOTIFICATION requests.
//
typedef struct _DS4_REQUEST_NOTIFICATION
{
//
// sizeof(struct _XUSB_REQUEST_NOTIFICATION)
//
ULONG Size;
//
// Serial number of target device.
//
ULONG SerialNo;
//
// The HID output report
//
DS4_OUTPUT_REPORT Report;
} DS4_REQUEST_NOTIFICATION, *PDS4_REQUEST_NOTIFICATION;
//
// Initializes a DS4_REQUEST_NOTIFICATION structure.
//
VOID FORCEINLINE DS4_REQUEST_NOTIFICATION_INIT(
_Out_ PDS4_REQUEST_NOTIFICATION Request,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Request, sizeof(DS4_REQUEST_NOTIFICATION));
Request->Size = sizeof(DS4_REQUEST_NOTIFICATION);
Request->SerialNo = SerialNo;
}
//
// DualShock 4 request data
//
typedef struct _DS4_SUBMIT_REPORT
{
//
// sizeof(struct _DS4_SUBMIT_REPORT)
//
ULONG Size;
//
// Serial number of target device.
//
ULONG SerialNo;
//
// HID Input report
//
DS4_REPORT Report;
} DS4_SUBMIT_REPORT, *PDS4_SUBMIT_REPORT;
//
// Initializes a DualShock 4 report.
//
VOID FORCEINLINE DS4_SUBMIT_REPORT_INIT(
_Out_ PDS4_SUBMIT_REPORT Report,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Report, sizeof(DS4_SUBMIT_REPORT));
Report->Size = sizeof(DS4_SUBMIT_REPORT);
Report->SerialNo = SerialNo;
DS4_REPORT_INIT(&Report->Report);
}
#include <pshpack1.h>
//
// DualShock 4 extended report request
//
typedef struct _DS4_SUBMIT_REPORT_EX
{
//
// sizeof(struct _DS4_SUBMIT_REPORT_EX)
//
_In_ ULONG Size;
//
// Serial number of target device.
//
_In_ ULONG SerialNo;
//
// Full size HID report excluding fixed Report ID.
//
_In_ DS4_REPORT_EX Report;
} DS4_SUBMIT_REPORT_EX, * PDS4_SUBMIT_REPORT_EX;
#include <poppack.h>
//
// Initializes a DualShock 4 extended report.
//
VOID FORCEINLINE DS4_SUBMIT_REPORT_EX_INIT(
_Out_ PDS4_SUBMIT_REPORT_EX Report,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Report, sizeof(DS4_SUBMIT_REPORT_EX));
Report->Size = sizeof(DS4_SUBMIT_REPORT_EX);
Report->SerialNo = SerialNo;
}
#pragma endregion
#pragma region DS4 Await Output
#include <pshpack1.h>
typedef struct _DS4_AWAIT_OUTPUT
{
//
// sizeof(struct _DS4_AWAIT_OUTPUT)
//
_In_ ULONG Size;
//
// Serial number of target device.
//
_Inout_ ULONG SerialNo;
//
// The payload
//
_Out_ DS4_OUTPUT_BUFFER Report;
} DS4_AWAIT_OUTPUT, * PDS4_AWAIT_OUTPUT;
#include <poppack.h>
VOID FORCEINLINE DS4_AWAIT_OUTPUT_INIT(
_Out_ PDS4_AWAIT_OUTPUT Output,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Output, sizeof(DS4_AWAIT_OUTPUT));
Output->Size = sizeof(DS4_AWAIT_OUTPUT);
Output->SerialNo = SerialNo;
}
#pragma endregion
#endif // VIGEM_DS4
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#include "ViGEm/Client.h"
/*
MIT License
Copyright (c) 2017-2023 Nefarius Software Solutions e.U. and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef ViGEmClient_h__
#define ViGEmClient_h__
#ifdef __cplusplus
extern "C" {
#endif
//#include "ViGEm/Common.h"
#ifdef VIGEM_DYNAMIC
#ifdef VIGEM_EXPORTS
#define VIGEM_API __declspec(dllexport)
#else
#define VIGEM_API __declspec(dllimport)
#endif
#else
#define VIGEM_API
#endif
#if defined(_MSC_VER)
#define VIGEM_DEPRECATED __declspec(deprecated)
#elif defined(__GNUC__)
#define VIGEM_DEPRECATED __attribute__ ((deprecated))
#endif
/** Values that represent ViGEm errors */
typedef enum _VIGEM_ERRORS
{
//
// API succeeded.
//
VIGEM_ERROR_NONE = 0x20000000,
//
// A compatible bus driver wasn't found on the system.
//
VIGEM_ERROR_BUS_NOT_FOUND = 0xE0000001,
//
// All device slots are occupied, no new device can be spawned.
//
VIGEM_ERROR_NO_FREE_SLOT = 0xE0000002,
VIGEM_ERROR_INVALID_TARGET = 0xE0000003,
VIGEM_ERROR_REMOVAL_FAILED = 0xE0000004,
//
// An attempt has been made to plug in an already connected device.
//
VIGEM_ERROR_ALREADY_CONNECTED = 0xE0000005,
//
// The target device is not initialized.
//
VIGEM_ERROR_TARGET_UNINITIALIZED = 0xE0000006,
//
// The target device is not plugged in.
//
VIGEM_ERROR_TARGET_NOT_PLUGGED_IN = 0xE0000007,
//
// It's been attempted to communicate with an incompatible driver version.
//
VIGEM_ERROR_BUS_VERSION_MISMATCH = 0xE0000008,
//
// Bus driver found but failed to open a handle.
//
VIGEM_ERROR_BUS_ACCESS_FAILED = 0xE0000009,
VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED = 0xE0000010,
VIGEM_ERROR_CALLBACK_NOT_FOUND = 0xE0000011,
VIGEM_ERROR_BUS_ALREADY_CONNECTED = 0xE0000012,
VIGEM_ERROR_BUS_INVALID_HANDLE = 0xE0000013,
VIGEM_ERROR_XUSB_USERINDEX_OUT_OF_RANGE = 0xE0000014,
VIGEM_ERROR_INVALID_PARAMETER = 0xE0000015,
//
// The API is not supported by the driver.
//
VIGEM_ERROR_NOT_SUPPORTED = 0xE0000016,
//
// An unexpected Win32 API error occurred. Call GetLastError() for details.
//
VIGEM_ERROR_WINAPI = 0xE0000017,
//
// The specified timeout has been reached.
//
VIGEM_ERROR_TIMED_OUT = 0xE0000018,
VIGEM_ERROR_IS_DISPOSING = 0xE0000019,
} VIGEM_ERROR;
/**
* A macro that defines if the API succeeded
*
* @author Benjamin "Nefarius" Höglinger-Stelzer
* @date 01.09.2020
*
* @param _val_ The error value.
*/
#define VIGEM_SUCCESS(_val_) (_val_ == VIGEM_ERROR_NONE)
/** Defines an alias representing a driver connection object */
typedef struct _VIGEM_CLIENT_T *PVIGEM_CLIENT;
/** Defines an alias representing a target device object */
typedef struct _VIGEM_TARGET_T *PVIGEM_TARGET;
typedef _Function_class_(EVT_VIGEM_TARGET_ADD_RESULT)
VOID CALLBACK