forked from 00cpxxx/wine-xinput
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxinput_quigon.patch
768 lines (739 loc) · 26.1 KB
/
xinput_quigon.patch
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
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_1/Makefile.in wine-staging-2.18.0/dlls/xinput1_1/Makefile.in
--- wine-staging-2.18.0.orig/dlls/xinput1_1/Makefile.in 2017-10-06 09:02:37.762280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_1/Makefile.in 2017-10-06 16:08:19.258381219 +0800
@@ -1,7 +1,2 @@
MODULE = xinput1_1.dll
PARENTSRC = ../xinput1_3
-
-C_SRCS = \
- xinput_main.c
-
-RC_SRCS = version.rc
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_1/xinput1_1.spec wine-staging-2.18.0/dlls/xinput1_1/xinput1_1.spec
--- wine-staging-2.18.0.orig/dlls/xinput1_1/xinput1_1.spec 2017-10-06 09:02:37.762280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_1/xinput1_1.spec 2017-10-06 16:08:19.258381219 +0800
@@ -1,5 +1,5 @@
-@ stdcall XInputEnable(long)
-@ stdcall XInputGetCapabilities(long long ptr)
-@ stdcall XInputGetDSoundAudioDeviceGuids(long ptr ptr)
-@ stdcall XInputSetState(long ptr)
-@ stdcall XInputGetState(long ptr)
+@ stdcall XInputEnable(long) xinput1_3.Enable
+@ stdcall XInputGetCapabilities(long long ptr) xinput1_3.GetCapabilities
+@ stdcall XInputGetDSoundAudioDeviceGuids(long ptr ptr) xinput1_3.GetDSoundAudioDeviceGuids
+@ stdcall XInputSetState(long ptr) xinput1_3.SetState
+@ stdcall XInputGetState(long ptr) xinput1_3.GetState
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_2/Makefile.in wine-staging-2.18.0/dlls/xinput1_2/Makefile.in
--- wine-staging-2.18.0.orig/dlls/xinput1_2/Makefile.in 2017-10-06 09:02:37.762280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_2/Makefile.in 2017-10-06 16:08:19.270381219 +0800
@@ -1,7 +1,2 @@
MODULE = xinput1_2.dll
PARENTSRC = ../xinput1_3
-
-C_SRCS = \
- xinput_main.c
-
-RC_SRCS = version.rc
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_2/xinput1_2.spec wine-staging-2.18.0/dlls/xinput1_2/xinput1_2.spec
--- wine-staging-2.18.0.orig/dlls/xinput1_2/xinput1_2.spec 2017-10-06 09:02:37.762280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_2/xinput1_2.spec 2017-10-06 16:08:19.270381219 +0800
@@ -1,5 +1,5 @@
-@ stdcall XInputEnable(long)
-@ stdcall XInputGetCapabilities(long long ptr)
-@ stdcall XInputGetDSoundAudioDeviceGuids(long ptr ptr)
-@ stdcall XInputSetState(long ptr)
-@ stdcall XInputGetState(long ptr)
+@ stdcall XInputEnable(long) xinput1_3.Enable
+@ stdcall XInputGetCapabilities(long long ptr) xinput1_3.GetCapabilities
+@ stdcall XInputGetDSoundAudioDeviceGuids(long ptr ptr) xinput1_3.GetDSoundAudioDeviceGuids
+@ stdcall XInputSetState(long ptr) xinput1_3.SetState
+@ stdcall XInputGetState(long ptr) xinput1_3.GetState
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_3/Makefile.in wine-staging-2.18.0/dlls/xinput1_3/Makefile.in
--- wine-staging-2.18.0.orig/dlls/xinput1_3/Makefile.in 2017-10-06 09:02:37.762280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_3/Makefile.in 2017-10-06 16:08:19.278381219 +0800
@@ -1,5 +1,6 @@
MODULE = xinput1_3.dll
IMPORTLIB = xinput
+IMPORTS = uuid dxguid dinput dinput8 ole32
C_SRCS = \
xinput_main.c
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_3/xinput_main.c wine-staging-2.18.0/dlls/xinput1_3/xinput_main.c
--- wine-staging-2.18.0.orig/dlls/xinput1_3/xinput_main.c 2017-10-06 09:02:37.774280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_3/xinput_main.c 2017-10-06 16:08:19.282381219 +0800
@@ -1,6 +1,7 @@
/*
* The Wine project - Xinput Joystick Library
* Copyright 2008 Andrew Fenn
+ * Copyright 2016 Bruno Jesus
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,6 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#define COBJMACROS
#include "config.h"
#include <assert.h>
#include <stdarg.h>
@@ -27,18 +29,385 @@
#include "winbase.h"
#include "winerror.h"
+#include "guiddef.h"
#include "xinput.h"
+#include "dinput.h"
+#include "dinputd.h"
/* Not defined in the headers, used only by XInputGetStateEx */
#define XINPUT_GAMEPAD_GUIDE 0x0400
WINE_DEFAULT_DEBUG_CHANNEL(xinput);
-struct
+struct CapsFlags
{
- BOOL connected;
+ BOOL wireless, jedi, pov;
+ int axes, buttons;
+};
+
+static struct ControllerMap
+{
+ LPDIRECTINPUTDEVICE8A device;
+ BOOL connected, acquired;
+ struct CapsFlags caps;
+ XINPUT_STATE_EX state_ex;
+ XINPUT_VIBRATION vibration;
+ BOOL vibration_dirty;
+
+ DIEFFECT effect_data;
+ LPDIRECTINPUTEFFECT effect_instance;
} controllers[XUSER_MAX_COUNT];
+static struct
+{
+ LPDIRECTINPUT8A iface;
+ BOOL enabled;
+ int mapped;
+} dinput;
+
+#define STARTUP_DINPUT if (!dinput.iface) dinput_start();
+
+static const int xbox_buttons[] = {
+ XINPUT_GAMEPAD_A,
+ XINPUT_GAMEPAD_B,
+ XINPUT_GAMEPAD_X,
+ XINPUT_GAMEPAD_Y,
+ XINPUT_GAMEPAD_LEFT_SHOULDER,
+ XINPUT_GAMEPAD_RIGHT_SHOULDER,
+ XINPUT_GAMEPAD_BACK,
+ XINPUT_GAMEPAD_START,
+ XINPUT_GAMEPAD_GUIDE,
+ XINPUT_GAMEPAD_LEFT_THUMB,
+ XINPUT_GAMEPAD_RIGHT_THUMB
+};
+
+/* ========================= Internal functions ============================= */
+
+static BOOL dinput_is_good(const LPDIRECTINPUTDEVICE8A device, struct CapsFlags *caps)
+{
+ HRESULT hr;
+ DIPROPDWORD property;
+ DIDEVCAPS dinput_caps;
+ static const unsigned long wireless_products[] = {
+ MAKELONG(0x045e, 0x0291) /* microsoft receiver */,
+ MAKELONG(0x045e, 0x0719) /* microsoft controller */,
+ MAKELONG(0x0738, 0x4556) /* mad catz */,
+ MAKELONG(0x0e6f, 0x0003) /* logitech */,
+ MAKELONG(0x0e6f, 0x0005) /* eclipse */,
+ MAKELONG(0x0e6f, 0x0006) /* edge */,
+ MAKELONG(0x102c, 0xff0c) /* joytech */
+ };
+ int i;
+
+ dinput_caps.dwSize = sizeof(dinput_caps);
+ hr = IDirectInputDevice_GetCapabilities(device, &dinput_caps);
+ if (FAILED(hr))
+ return FALSE;
+
+ property.diph.dwSize = sizeof(property);
+ property.diph.dwHeaderSize = sizeof(property.diph);
+ property.diph.dwObj = 0;
+ property.diph.dwHow = DIPH_DEVICE;
+
+ hr = IDirectInputDevice_GetProperty(device, DIPROP_VIDPID, &property.diph);
+ if (FAILED(hr))
+ return FALSE;
+
+ if (dinput_caps.dwAxes < 2 || dinput_caps.dwButtons < 8)
+ return FALSE;
+
+ caps->axes = dinput_caps.dwAxes;
+ caps->buttons = dinput_caps.dwButtons;
+ caps->wireless = FALSE;
+ caps->jedi = !!(dinput_caps.dwFlags & DIDC_FORCEFEEDBACK);
+ caps->pov = !!dinput_caps.dwPOVs;
+
+ for (i = 0; i < sizeof(wireless_products) / sizeof(wireless_products[0]); i++)
+ if (property.dwData == wireless_products[i])
+ {
+ caps->wireless = TRUE;
+ break;
+ }
+
+ if (dinput_caps.dwAxes == 6 && dinput_caps.dwButtons == 11 && dinput_caps.dwPOVs == 1)
+ TRACE("This controller has the same number of buttons/axes from xbox 360, should work...\n");
+ else
+ FIXME("This is not a known xbox controller (%d %d %d), using anyway. Expect problems!\n",
+ dinput_caps.dwAxes, dinput_caps.dwButtons, dinput_caps.dwPOVs);
+
+ return TRUE;
+}
+
+static BOOL dinput_set_range(const LPDIRECTINPUTDEVICE8A device)
+{
+ HRESULT hr;
+ DIPROPRANGE property;
+
+ property.diph.dwSize = sizeof(property);
+ property.diph.dwHeaderSize = sizeof(property.diph);
+ property.diph.dwHow = DIPH_DEVICE;
+ property.diph.dwObj = 0;
+ property.lMin = -32767;
+ property.lMax = +32767;
+
+ hr = IDirectInputDevice_SetProperty(device, DIPROP_RANGE, &property.diph);
+ if (FAILED(hr))
+ {
+ WARN("Failed to set axis range (0x%x)\n", hr);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void dinput_joystate_to_xinput(DIJOYSTATE2 *js, XINPUT_GAMEPAD_EX *gamepad, struct CapsFlags *caps)
+{
+ int i, buttons;
+
+ gamepad->dwPaddingReserved = 0;
+ gamepad->wButtons = 0x0000;
+ /* First the D-Pad which is recognized as a POV in dinput */
+ if (caps->pov)
+ {
+ switch (js->rgdwPOV[0])
+ {
+ case 0 : gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_UP; break;
+ case 4500 : gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_UP; /* fall through */
+ case 9000 : gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT; break;
+ case 13500: gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT; /* fall through */
+ case 18000: gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN; break;
+ case 22500: gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN; /* fall through */
+ case 27000: gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT; break;
+ case 31500: gamepad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_DPAD_UP;
+ }
+ }
+
+ /* Buttons */
+ buttons = min(caps->buttons, sizeof(xbox_buttons) / sizeof(*xbox_buttons));
+ for (i = 0; i < buttons; i++)
+ if (js->rgbButtons[i] & 0x80)
+ gamepad->wButtons |= xbox_buttons[i];
+
+ /* Axes */
+ gamepad->sThumbLX = js->lX;
+ gamepad->sThumbLY = -js->lY;
+ if (caps->axes >= 4)
+ {
+ gamepad->sThumbRX = js->lRx;
+ gamepad->sThumbRY = -js->lRy;
+ }
+ else
+ gamepad->sThumbRX = gamepad->sThumbRY = 0;
+
+ /* Both triggers */
+ if (caps->axes >= 6)
+ {
+ gamepad->bLeftTrigger = (js->lZ + 32767) * 255 / 65534;
+ gamepad->bRightTrigger = (js->lRz + 32767) * 255 / 65534;
+ }
+ else
+ gamepad->bLeftTrigger = gamepad->bRightTrigger = 0;
+}
+
+static BOOL dinput_acquire(int index)
+{
+ HRESULT hr;
+
+ if (!controllers[index].acquired)
+ {
+ IDirectInputDevice8_SetDataFormat(controllers[index].device, &c_dfDIJoystick2);
+ hr = IDirectInputDevice8_Acquire(controllers[index].device);
+ if (FAILED(hr))
+ WARN("Failed to acquire game controller (0x%x)\n", hr);
+ else
+ controllers[index].acquired = TRUE;
+ }
+
+ return controllers[index].acquired;
+}
+
+static void dinput_fill_effect(DIEFFECT *effect)
+{
+ static DWORD axes[2] = {DIJOFS_X, DIJOFS_Y};
+ static LONG direction[2] = {0, 0};
+
+ effect->dwSize = sizeof(*effect);
+ effect->dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
+ effect->dwDuration = INFINITE;
+ effect->dwGain = 0;
+ effect->dwTriggerButton = DIEB_NOTRIGGER;
+ effect->cAxes = sizeof(axes) / sizeof(axes[0]);
+ effect->rgdwAxes = axes;
+ effect->rglDirection = direction;
+}
+
+static void dinput_send_effect(int index, int strength)
+{
+ HRESULT hr;
+ union
+ {
+ DICONSTANTFORCE constant;
+ DIPERIODIC periodic;
+ } u;
+ DIEFFECT *effect = &controllers[index].effect_data;
+ LPDIRECTINPUTEFFECT *instance = &controllers[index].effect_instance;
+
+ if (!dinput_acquire(index))
+ return;
+
+ if (!*instance)
+ dinput_fill_effect(effect);
+
+ u.periodic.dwMagnitude = strength; /* constant force uses this same value */
+ u.periodic.dwPeriod = DI_SECONDS; /* 1 second */
+ u.periodic.lOffset = 0;
+ u.periodic.dwPhase = 0;
+
+ effect->lpvTypeSpecificParams = &u.periodic;
+
+ if (!*instance)
+ {
+ static GUID types[2];
+ int i;
+
+ types[0] = GUID_Square;
+ types[1] = GUID_ConstantForce;
+ for (i = 0; i < 2; i++)
+ {
+ effect->cbTypeSpecificParams = !i ? sizeof(u.periodic) : sizeof(u.constant);
+
+ hr = IDirectInputDevice8_CreateEffect(controllers[index].device, &types[i],
+ effect, instance, NULL);
+ if (FAILED(hr))
+ continue;
+
+ if (!*instance)
+ continue;
+
+ hr = IDirectInputEffect_SetParameters(*instance, effect,
+ DIEP_AXES | DIEP_DIRECTION | DIEP_NODOWNLOAD | DIEP_TYPESPECIFICPARAMS);
+ if (FAILED(hr))
+ {
+ IUnknown_Release(*instance);
+ *instance = NULL;
+ continue;
+ }
+ TRACE("Using %s effect for vibration\n", i ? "square" : "constant");
+ break;
+ }
+ if (i == 2)
+ {
+ WARN("Failed to create effect (hr 0x%x, instance %p)\n", hr, *instance);
+ return;
+ }
+ }
+ else
+ {
+ GUID guid;
+
+ IDirectInputEffect_GetEffectGuid(*instance, &guid);
+ effect->cbTypeSpecificParams = IsEqualGUID(&GUID_Square, &guid) ? sizeof(u.periodic) : sizeof(u.constant);
+ }
+
+ hr = IDirectInputEffect_SetParameters(*instance, effect, DIEP_TYPESPECIFICPARAMS | DIEP_START);
+ if (FAILED(hr))
+ WARN("Failed to play effect (0x%x)\n", hr);
+}
+
+static BOOL CALLBACK dinput_enum_callback(const DIDEVICEINSTANCEA *instance, void *context)
+{
+ LPDIRECTINPUTDEVICE8A device;
+ HRESULT hr;
+
+ if (dinput.mapped == sizeof(controllers) / sizeof(*controllers))
+ return DIENUM_STOP;
+
+ hr = IDirectInput_CreateDevice(dinput.iface, &instance->guidInstance, &device, NULL);
+ if (FAILED(hr))
+ return DIENUM_CONTINUE;
+
+ if (!dinput_is_good(device, &controllers[dinput.mapped].caps))
+ {
+ IDirectInput_Release(device);
+ return DIENUM_CONTINUE;
+ }
+
+ if (!dinput_set_range(device))
+ {
+ IDirectInput_Release(device);
+ return DIENUM_CONTINUE;
+ }
+
+ controllers[dinput.mapped].connected = TRUE;
+ controllers[dinput.mapped].device = device;
+ dinput.mapped++;
+
+ return DIENUM_CONTINUE;
+}
+
+static void dinput_start(void)
+{
+ HRESULT hr;
+
+ hr = DirectInput8Create(GetModuleHandleA(NULL), 0x0800, &IID_IDirectInput8A,
+ (void **)&dinput.iface, NULL);
+ if (FAILED(hr))
+ {
+ ERR("Failed to create dinput8 interface, no xinput controller support (0x%x)\n", hr);
+ return;
+ }
+
+ hr = IDirectInput8_EnumDevices(dinput.iface, DI8DEVCLASS_GAMECTRL,
+ dinput_enum_callback, NULL, DIEDFL_ATTACHEDONLY);
+ if (FAILED(hr))
+ {
+ ERR("Failed to enumerate dinput8 devices, no xinput controller support (0x%x)\n", hr);
+ return;
+ }
+
+ dinput.enabled = TRUE;
+}
+
+static void dinput_update(int index)
+{
+ HRESULT hr;
+ DIJOYSTATE2 data;
+ XINPUT_GAMEPAD_EX gamepad;
+
+ if (dinput.enabled)
+ {
+ if (!dinput_acquire(index))
+ return;
+
+ hr = IDirectInputDevice_GetDeviceState(controllers[index].device, sizeof(data), &data);
+ if (FAILED(hr))
+ {
+ if (hr == DIERR_INPUTLOST)
+ controllers[index].acquired = FALSE;
+ WARN("Failed to get game controller state (0x%x)\n", hr);
+ return;
+ }
+ dinput_joystate_to_xinput(&data, &gamepad, &controllers[index].caps);
+ }
+ else
+ memset(&gamepad, 0, sizeof(gamepad));
+
+ if (memcmp(&controllers[index].state_ex.Gamepad, &gamepad, sizeof(gamepad)))
+ {
+ controllers[index].state_ex.Gamepad = gamepad;
+ controllers[index].state_ex.dwPacketNumber++;
+ TRACE("Buttons 0x%x, LT %d, RT %d, LX %d, LY %d, RX %d, RY %d\n",
+ gamepad.wButtons,
+ gamepad.bLeftTrigger,
+ gamepad.bRightTrigger,
+ gamepad.sThumbLX,
+ gamepad.sThumbLY,
+ gamepad.sThumbRX,
+ gamepad.sThumbRY);
+ }
+}
+
+/* ============================ Dll Functions =============================== */
+
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
{
switch(reason)
@@ -52,23 +421,54 @@
void WINAPI DECLSPEC_HOTPATCH XInputEnable(BOOL enable)
{
- /* Setting to false will stop messages from XInputSetState being sent
- to the controllers. Setting to true will send the last vibration
- value (sent to XInputSetState) to the controller and allow messages to
- be sent */
- FIXME("(enable %d) Stub!\n", enable);
+ TRACE("(%d)\n", enable);
+
+ STARTUP_DINPUT
+
+ if((dinput.enabled = enable))
+ {
+ int i;
+ /* Apply the last vibration status that was sent to the controller
+ * while xinput was disabled. */
+ for (i = 0; i < sizeof(controllers) / sizeof(*controllers); i++)
+ {
+ if (controllers[i].connected && controllers[i].vibration_dirty)
+ XInputSetState(i, &controllers[i].vibration);
+ }
+ }
}
DWORD WINAPI XInputSetState(DWORD index, XINPUT_VIBRATION* vibration)
{
- FIXME("(index %u, vibration %p) Stub!\n", index, vibration);
+ TRACE("(index %u, vibration %p)\n", index, vibration);
+
+ STARTUP_DINPUT
if (index >= XUSER_MAX_COUNT)
return ERROR_BAD_ARGUMENTS;
if (!controllers[index].connected)
return ERROR_DEVICE_NOT_CONNECTED;
- return ERROR_NOT_SUPPORTED;
+ /* Check if we really have to do all the process */
+ if (!controllers[index].vibration_dirty &&
+ controllers[index].vibration.wLeftMotorSpeed == vibration->wLeftMotorSpeed &&
+ controllers[index].vibration.wRightMotorSpeed == vibration->wRightMotorSpeed)
+ return ERROR_SUCCESS;
+
+ controllers[index].vibration = *vibration;
+ controllers[index].vibration_dirty = !dinput.enabled;
+
+ if (dinput.enabled && controllers[index].caps.jedi)
+ {
+ int strength;
+ /* FIXME: we can't set the speed of each motor so do an average */
+ strength = DI_FFNOMINALMAX * (vibration->wLeftMotorSpeed + vibration->wRightMotorSpeed) / 2 / 0xFFFF;
+
+ TRACE("Vibration left/right speed %d/%d translated to %d\n\n",
+ vibration->wLeftMotorSpeed, vibration->wRightMotorSpeed, strength);
+ dinput_send_effect(index, strength);
+ }
+ return ERROR_SUCCESS;
}
DWORD WINAPI DECLSPEC_HOTPATCH XInputGetState(DWORD index, XINPUT_STATE* state)
@@ -79,65 +479,113 @@
XINPUT_STATE_EX state_ex;
} xinput;
DWORD ret;
- static int warn_once;
-
- if (!warn_once++)
- FIXME("(index %u, state %p) Stub!\n", index, state);
+ TRACE("(index %u, state %p) Stub!\n", index, state);
ret = XInputGetStateEx(index, &xinput.state_ex);
if (ret != ERROR_SUCCESS)
return ret;
/* The main difference between this and the Ex version is the media guide button */
- xinput.state.Gamepad.wButtons &= ~XINPUT_GAMEPAD_GUIDE;
*state = xinput.state;
+ state->Gamepad.wButtons &= ~XINPUT_GAMEPAD_GUIDE;
return ERROR_SUCCESS;
}
DWORD WINAPI DECLSPEC_HOTPATCH XInputGetStateEx(DWORD index, XINPUT_STATE_EX* state_ex)
{
- static int warn_once;
-
- if (!warn_once++)
- FIXME("(index %u, state %p) Stub!\n", index, state_ex);
+ TRACE("(index %u, state %p) Stub!\n", index, state_ex);
+ STARTUP_DINPUT
if (index >= XUSER_MAX_COUNT)
return ERROR_BAD_ARGUMENTS;
if (!controllers[index].connected)
return ERROR_DEVICE_NOT_CONNECTED;
- return ERROR_NOT_SUPPORTED;
+ dinput_update(index);
+
+ /* Broforce does not pass a correct XINPUT_STATE_EX and crashes, so only
+ * copy the old struct size as the new parameter is reserved anyway */
+ state_ex->dwPacketNumber = controllers[index].state_ex.dwPacketNumber;
+ *(XINPUT_GAMEPAD *)&state_ex->Gamepad = *(XINPUT_GAMEPAD *)&controllers[index].state_ex.Gamepad;
+
+ return ERROR_SUCCESS;
}
DWORD WINAPI XInputGetKeystroke(DWORD index, DWORD reserved, PXINPUT_KEYSTROKE keystroke)
{
- static int warn_once;
-
- if (!warn_once++)
- FIXME("(index %u, reserved %u, keystroke %p) Stub!\n", index, reserved, keystroke);
+ TRACE("(index %u, reserved %u, keystroke %p) Stub!\n", index, reserved, keystroke);
- if (index >= XUSER_MAX_COUNT)
- return ERROR_BAD_ARGUMENTS;
- if (!controllers[index].connected)
- return ERROR_DEVICE_NOT_CONNECTED;
+ if (index != XUSER_INDEX_ANY)
+ {
+ if (index >= XUSER_MAX_COUNT)
+ return ERROR_BAD_ARGUMENTS;
+ if (!controllers[index].connected)
+ return ERROR_DEVICE_NOT_CONNECTED;
+ }
- return ERROR_NOT_SUPPORTED;
+ /* Pretend no keys are pressed */
+ return ERROR_EMPTY;
}
+/* Not defined anywhere ??? */
+#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
+#define XINPUT_CAPS_WIRELESS 0x0002
+#define XINPUT_CAPS_NO_NAVIGATION 0x0010
+
DWORD WINAPI XInputGetCapabilities(DWORD index, DWORD flags, XINPUT_CAPABILITIES* capabilities)
{
- static int warn_once;
-
- if (!warn_once++)
- FIXME("(index %u, flags 0x%x, capabilities %p) Stub!\n", index, flags, capabilities);
+ WORD bits = 0, i;
+ TRACE("(index %u, flags 0x%x, capabilities %p) Stub!\n", index, flags, capabilities);
+ STARTUP_DINPUT
if (index >= XUSER_MAX_COUNT)
return ERROR_BAD_ARGUMENTS;
if (!controllers[index].connected)
return ERROR_DEVICE_NOT_CONNECTED;
- return ERROR_NOT_SUPPORTED;
+ capabilities->Type = XINPUT_DEVTYPE_GAMEPAD;
+ capabilities->SubType = XINPUT_DEVSUBTYPE_GAMEPAD;
+
+ capabilities->Flags = 0;
+ if (controllers[index].caps.jedi)
+ {
+ capabilities->Flags |= XINPUT_CAPS_FFB_SUPPORTED;
+ capabilities->Vibration.wLeftMotorSpeed = 1;
+ capabilities->Vibration.wRightMotorSpeed = 1;
+ }
+ else
+ {
+ capabilities->Vibration.wLeftMotorSpeed = 0;
+ capabilities->Vibration.wRightMotorSpeed = 0;
+ }
+ if (controllers[index].caps.wireless)
+ capabilities->Flags |= XINPUT_CAPS_WIRELESS;
+ if (!controllers[index].caps.pov)
+ capabilities->Flags |= XINPUT_CAPS_NO_NAVIGATION;
+ else
+ bits = 0xF;
+
+ for (i = 0; i < controllers[index].caps.buttons &&
+ i < sizeof(xbox_buttons) / sizeof(*xbox_buttons); i++)
+ bits |= xbox_buttons[i];
+
+ bits &= ~XINPUT_GAMEPAD_GUIDE;
+ capabilities->Gamepad.wButtons = bits;
+
+ capabilities->Gamepad.sThumbLX = capabilities->Gamepad.sThumbLY = 1;
+
+ if (controllers[index].caps.axes >= 4)
+ capabilities->Gamepad.sThumbRX = capabilities->Gamepad.sThumbRY = 1;
+ else
+ capabilities->Gamepad.sThumbRX = capabilities->Gamepad.sThumbRY = 0;
+
+ if (controllers[index].caps.axes >= 6)
+ capabilities->Gamepad.bLeftTrigger = capabilities->Gamepad.bRightTrigger = 1;
+ else
+ capabilities->Gamepad.bLeftTrigger = capabilities->Gamepad.bRightTrigger = 0;
+
+ return ERROR_SUCCESS;
}
DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD index, GUID* render_guid, GUID* capture_guid)
@@ -149,17 +597,43 @@
if (!controllers[index].connected)
return ERROR_DEVICE_NOT_CONNECTED;
- return ERROR_NOT_SUPPORTED;
+ /* Tests show that it is more appropriate to return GUID_NULL and success,
+ * this means that a controller is connected but the headset is not. */
+ if (render_guid)
+ *render_guid = GUID_NULL;
+ if (capture_guid)
+ *capture_guid = GUID_NULL;
+
+ return ERROR_SUCCESS;
}
DWORD WINAPI XInputGetBatteryInformation(DWORD index, BYTE type, XINPUT_BATTERY_INFORMATION* battery)
{
- FIXME("(index %u, type %u, battery %p) Stub!\n", index, type, battery);
+ TRACE("(index %u, type %u, battery %p) Stub!\n", index, type, battery);
+
+ STARTUP_DINPUT
if (index >= XUSER_MAX_COUNT)
return ERROR_BAD_ARGUMENTS;
if (!controllers[index].connected)
return ERROR_DEVICE_NOT_CONNECTED;
+ if (type != BATTERY_DEVTYPE_GAMEPAD && type != BATTERY_DEVTYPE_HEADSET)
+ return ERROR_BAD_ARGUMENTS;
+
+ if (!controllers[index].caps.wireless)
+ {
+ battery->BatteryType = BATTERY_TYPE_WIRED;
+ battery->BatteryLevel = BATTERY_LEVEL_FULL;
+ }
+ else
+ {
+ static int once;
+ if (!once++)
+ FIXME("Reporting fake battery values\n");
+
+ battery->BatteryType = BATTERY_TYPE_NIMH;
+ battery->BatteryLevel = BATTERY_LEVEL_MEDIUM;
+ }
- return ERROR_NOT_SUPPORTED;
+ return ERROR_SUCCESS;
}
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_4/Makefile.in wine-staging-2.18.0/dlls/xinput1_4/Makefile.in
--- wine-staging-2.18.0.orig/dlls/xinput1_4/Makefile.in 2017-10-06 09:02:37.774280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_4/Makefile.in 2017-10-06 16:08:19.282381219 +0800
@@ -1,7 +1,2 @@
MODULE = xinput1_4.dll
PARENTSRC = ../xinput1_3
-
-C_SRCS = \
- xinput_main.c
-
-RC_SRCS = version.rc
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput1_4/xinput1_4.spec wine-staging-2.18.0/dlls/xinput1_4/xinput1_4.spec
--- wine-staging-2.18.0.orig/dlls/xinput1_4/xinput1_4.spec 2017-10-06 09:02:37.774280425 +0800
+++ wine-staging-2.18.0/dlls/xinput1_4/xinput1_4.spec 2017-10-06 17:02:10.402393970 +0800
@@ -1,9 +1,9 @@
1 stdcall -private DllMain(long long ptr)
-2 stdcall XInputGetState(long ptr)
-3 stdcall XInputSetState(long ptr)
-4 stdcall XInputGetCapabilities(long long ptr)
-5 stdcall XInputEnable(long)
-7 stdcall XInputGetBatteryInformation(long long ptr)
-8 stdcall XInputGetKeystroke(long long ptr)
+2 stdcall XInputGetState(long ptr) xinput1_3.GetState
+3 stdcall XInputSetState(long ptr) xinput1_3.SetState
+4 stdcall XInputGetCapabilities(long long ptr) xinput1_3.GetCapabilities
+5 stdcall XInputEnable(long) xinput1_3.Enable
+7 stdcall XInputGetBatteryInformation(long long ptr) xinput1_3.GetBatteryInformation
+8 stdcall XInputGetKeystroke(long long ptr) xinput1_3.GetKeystroke
10 stub XInputGetAudioDeviceIds(long ptr ptr ptr ptr)
-100 stdcall XInputGetStateEx(long ptr)
+100 stdcall XInputGetStateEx(long ptr) xinput1_3.GetStateEx
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput9_1_0/Makefile.in wine-staging-2.18.0/dlls/xinput9_1_0/Makefile.in
--- wine-staging-2.18.0.orig/dlls/xinput9_1_0/Makefile.in 2017-10-06 09:02:37.774280425 +0800
+++ wine-staging-2.18.0/dlls/xinput9_1_0/Makefile.in 2017-10-06 16:08:19.294381220 +0800
@@ -1,7 +1,2 @@
MODULE = xinput9_1_0.dll
PARENTSRC = ../xinput1_3
-
-C_SRCS = \
- xinput_main.c
-
-RC_SRCS = version.rc
diff -Nur -Nur wine-staging-2.18.0.orig/dlls/xinput9_1_0/xinput9_1_0.spec wine-staging-2.18.0/dlls/xinput9_1_0/xinput9_1_0.spec
--- wine-staging-2.18.0.orig/dlls/xinput9_1_0/xinput9_1_0.spec 2017-10-06 09:02:37.774280425 +0800
+++ wine-staging-2.18.0/dlls/xinput9_1_0/xinput9_1_0.spec 2017-10-06 16:08:19.294381220 +0800
@@ -1,4 +1,4 @@
-@ stdcall XInputGetCapabilities(long long ptr)
-@ stdcall XInputGetDSoundAudioDeviceGuids(long ptr ptr)
-@ stdcall XInputSetState(long ptr)
-@ stdcall XInputGetState(long ptr)
+@ stdcall XInputGetCapabilities(long long ptr) xinput1_3.XInputGetCapabilities
+@ stdcall XInputGetDSoundAudioDeviceGuids(long ptr ptr) xinput1_3.XInputGetDSoundAudioDeviceGuids
+@ stdcall XInputSetState(long ptr) xinput1_3.XInputSetState
+@ stdcall XInputGetState(long ptr) xinput1_3.XInputGetState