-
Notifications
You must be signed in to change notification settings - Fork 7
/
dllmain.cpp
2098 lines (1900 loc) · 76 KB
/
dllmain.cpp
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
// Need for Speed Underground & Underground 2 - Xtended Input plugin
// Bringing native XInput to NFS
// by Xan/Tenjoin
// TODO: BACKPORT STUFF FROM NFS_XtendedInput! Lots of stuff had been developed since this code was last updated!
// TODO: bring rumble/vibration function
// TODO: remapping? -- partially done, but only 1 event per key and 1 key per event
// TODO: kill DInput enough so that it doesn't detect XInput controllers but still detects wheels
// TODO: proper raw input for keyboard (and maybe non XInput gamepads?)
// TODO (UG 1/2): properly restore console FrontEnd objects (help messages, controller icons) -- partially done, HELP menu still needs to be restored
// TODO (UG): reassigned button textures -- so when you set Y button for BUTTON1 in FE, it should draw Y and not keep drawing X
// TODO (UG2): maybe button hash assignments and FE stuff
// TODO (UG2): ingame settings menu
// TODO (UG): maybe rewrite the drag steering handler, DPad input for steering is currently not possible with the analog steering at the same time!
#include "stdafx.h"
#include "stdio.h"
#include <windows.h>
#include "includes\injector\injector.hpp"
#include "includes\IniReader.h"
#ifdef XINPUT_OLD
#include <XInput.h>
#pragma comment(lib,"xinput9_1_0.lib")
#else
#include <XInput.h>
#pragma comment(lib,"xinput.lib")
#endif
#ifdef GAME_UG
#include "NFSU_ConsoleButtonHashes.h"
#include "NFSU_EventNames.h"
#include "NFSU_XtendedInput_FEng.h"
#include "NFSU_Addresses.h"
#include <timeapi.h>
#endif
#ifdef GAME_UG2
#include "NFSU2_EventNames.h"
#include "NFSU2_Addresses.h"
#include "NFSU2_FEng.h"
#endif
#include "NFSU_XtendedInput_XInputConfig.h"
#include "NFSU_XtendedInput_VKHash.h"
#define MAX_CONTROLLERS 4 // XInput handles up to 4 controllers
WORD INPUT_DEADZONE_LS = (0.24f * FLOAT(0x7FFF)); // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
WORD INPUT_DEADZONE_RS = (0.24f * FLOAT(0x7FFF)); // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
WORD INPUT_DEADZONE_LS_P2 = (0.24f * FLOAT(0x7FFF)); // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
WORD INPUT_DEADZONE_RS_P2 = (0.24f * FLOAT(0x7FFF)); // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
WORD SHIFT_ANALOG_THRESHOLD = (0.75f * FLOAT(0x7FFF)); // 75% for shifting
WORD FEUPDOWN_ANALOG_THRESHOLD = (0.50f * FLOAT(0x7FFF)); // 50% for analog sticks digital activation
WORD TRIGGER_ACTIVATION_THRESHOLD = (0.12f * FLOAT(0xFF)); // 12% for analog triggers digital activation
// for triggering the over-zelaous inputs once in a tick...
WORD bQuitButtonOldState = 0;
WORD bYButtonOldState = 0;
WORD bXButtonOldState = 0;
// steering axis & buttons
WORD SteerLeftButton = 0; // defaulting digital steer to 0 because of predefined functions
WORD SteerRightButton = 0;
WORD SteerLeftAxis = XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF;
WORD SteerRightAxis = XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF;
struct CONTROLLER_STATE
{
XINPUT_STATE state;
bool bConnected;
}g_Controllers[MAX_CONTROLLERS];
// KB Input declarations
//unbuffered -- calls GetAsyncKeyState during scanning process itself -- probably more taxing, but very good input latency (default)
#define KB_READINGMODE_UNBUFFERED_ASYNC 0
// buffered -- calls GetKeyboardState right after reading joypads, updates VKeyStates
#define KB_READINGMODE_BUFFERED 1
// unbuffered -- reads unbuffered raw input during WM_INPUT, updates VKeyStates, pretty slow but allows to differentiate between 2 different keyboard devices
#define KB_READINGMODE_UNBUFFERED_RAW 2
// TODO: buffered raw input
RAWINPUTDEVICE Rid;
BYTE VKeyStates[2][256];
bool KeyboardState = true; // connection status
bool bAllowTwoPlayerKB = false; // allow for 2 players to use their own KB devices (nothing to do with gamepads)
unsigned int KeyboardReadingMode = 0; // 0 = buffered synchronous, 1 = unbuffered asynchronous, 2 = unbuffered raw
HANDLE FirstKB = NULL;
HANDLE SecondKB = NULL;
USHORT SteerLeftVKey = VK_LEFT;
USHORT SteerRightVKey = VK_RIGHT;
// Input ScannerConfig - JoyEvent mapping
struct ScannerConfig
{
unsigned int JoyConfigType = 0xFF; // 0xFF default
unsigned int unk1; // not read
unsigned int JoyEvent;
unsigned int ScannerFunctionPointer;
uint16_t BitmaskStuff; // used to define which bits are read from the joypad buffer
uint16_t BitmaskStuff2; // used to define which bits are read from the joypad buffer
unsigned int unk5; // if prev value was 0x10000 = button texture hash, if 0x10001 = max value, hard to determine
unsigned int param;
unsigned int keycode; // normally unknown, we're reutilizing this value
}ScannerConfigs[MAX_JOY_EVENT]; // we're generating scanners for ALL JoyEvents - not something devs normally do
// we use this to track the state of each button for each event
WORD EventStates[2][MAX_JOY_EVENT];
bool EventStatesKB[2][MAX_JOY_EVENT];
unsigned int GameWndProcAddr = 0;
LRESULT(WINAPI* GameWndProc)(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI CustomWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INPUT:
if (KeyboardReadingMode == KB_READINGMODE_UNBUFFERED_RAW)
{
UINT dwSize;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize];
if (lpb == NULL)
{
KeyboardState = false;
return 0;
}
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
{
KeyboardState = false;
OutputDebugString(TEXT("GetRawInputData does not return correct size !\n"));
}
RAWINPUT* raw = (RAWINPUT*)lpb;
if (raw->header.dwType == RIM_TYPEKEYBOARD)
{
KeyboardState = true;
LastControlledDevice = LASTCONTROLLED_KB;
// going with first-come first-serve -- first KB is always the first used one
// this can catch a second virtual keyboard of a multi-device keyboard (the ones that use it for NKRO over USB), hence why it's optional
if ((FirstKB != NULL) && (FirstKB != raw->header.hDevice) && (SecondKB == NULL) && bAllowTwoPlayerKB)
{
SecondKB = raw->header.hDevice;
*(unsigned char*)JOYSTICKTYPE_P2_ADDR = 0;
}
if (FirstKB == NULL)
FirstKB = raw->header.hDevice;
//printf(" Kbd %p: make=%04x Flags:%04x Reserved:%04x ExtraInformation:%08x, msg=%04x VK=%04x \n",
// raw->header.hDevice,
//raw->data.keyboard.MakeCode,
// raw->data.keyboard.Flags,
// raw->data.keyboard.Reserved,
// raw->data.keyboard.ExtraInformation,
// raw->data.keyboard.Message,
// raw->data.keyboard.VKey);
if (raw->header.hDevice == SecondKB)
{
switch (raw->data.keyboard.VKey)
{
case VK_CONTROL:
if (raw->data.keyboard.Flags & RI_KEY_E0)
VKeyStates[1][VK_RCONTROL] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
else
VKeyStates[1][VK_LCONTROL] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
case VK_MENU:
if (raw->data.keyboard.Flags & RI_KEY_E0)
VKeyStates[1][VK_RMENU] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
else
VKeyStates[1][VK_LMENU] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
case VK_SHIFT:
if (raw->data.keyboard.MakeCode == 0x36)
VKeyStates[1][VK_RSHIFT] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
else
VKeyStates[1][VK_LSHIFT] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
default:
VKeyStates[1][raw->data.keyboard.VKey] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
}
return 0;
}
else if (raw->header.hDevice)
{
switch (raw->data.keyboard.VKey)
{
case VK_CONTROL:
if (raw->data.keyboard.Flags & RI_KEY_E0)
VKeyStates[0][VK_RCONTROL] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
else
VKeyStates[0][VK_LCONTROL] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
case VK_MENU:
if (raw->data.keyboard.Flags & RI_KEY_E0)
VKeyStates[0][VK_RMENU] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
else
VKeyStates[0][VK_LMENU] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
case VK_SHIFT:
if (raw->data.keyboard.MakeCode == 0x36)
VKeyStates[0][VK_RSHIFT] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
else
VKeyStates[0][VK_LSHIFT] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
default:
VKeyStates[0][raw->data.keyboard.VKey] = !(raw->data.keyboard.Flags & RI_KEY_BREAK);
break;
}
}
return 0;
}
delete[] lpb;
return 0;
}
break;
case WM_KEYDOWN:
if (KeyboardReadingMode != KB_READINGMODE_UNBUFFERED_RAW)
LastControlledDevice = LASTCONTROLLED_KB;
break;
// special cases for Win32 mouse on non-UG1
#ifndef GAME_UG
case WM_LBUTTONDOWN:
bMousePressedDown = true;
return 0;
case WM_LBUTTONUP:
bMousePressedDown = false;
return 0;
case WM_RBUTTONDOWN:
bMouse3PressedDown = true;
return 0;
case WM_RBUTTONUP:
bMouse3PressedDown = false;
return 0;
case WM_MBUTTONDOWN:
bMouse2PressedDown = true;
return 0;
case WM_MBUTTONUP:
bMouse2PressedDown = false;
return 0;
case WM_SETFOCUS:
// confine mouse within the game window
if (bConfineMouse)
{
GetWindowRect(*(HWND*)GAME_HWND_ADDR, &windowRect);
ClipCursor(&windowRect);
}
break;
#endif
default:
break;
}
return GameWndProc(hWnd, msg, wParam, lParam);
}
void(*InitJoystick)() = (void(*)())INITJOY_ADDR;
void DummyFunc()
{
return;
}
// UG1 uses fastcall and works without this so we won't apply it to UG1
#ifndef GAME_UG
ScannerConfig* FindScannerConfig_Custom(unsigned int inJoyEvent, int confignum, int unk)
{
for (unsigned int i = 0; i < MAX_JOY_EVENT; i++)
{
if (ScannerConfigs[i].JoyEvent == inJoyEvent)
return &(ScannerConfigs[i]);
}
return 0;
}
#endif
#ifdef GAME_UG
struct ActualJoypadData
{
uint32_t destructor;
char unkdata1[0x130];
uint32_t type;
char name[32];
char unkdata2[0xE4];
uint32_t config_index;
uint32_t secondary;
char unkdata3[0x2C];
}settings_controllers[3];
int settings_cave1_exit = 0x00413C1D;
int settings_cave1_exit_2 = 0x413AF1;
void __declspec(naked) settings_cave1()
{
_asm
{
cmp edx, 2
mov [esp+0x18], ebx
mov [esp+0x1C], eax
jnz settings_cont
jmp settings_cave1_exit
settings_cont:
jmp settings_cave1_exit_2;
}
}
uint32_t cur_setting_idx;
uint32_t cur_setting_idx_secondary;
// entry: 0x004141DF
int settings_cave2_exit = 0x00414217;
void __declspec(naked) settings_cave2()
{
_asm
{
mov [esi+0x84], eax
mov eax, ds:0x736344
mov byte ptr [esi+0x80], 1
mov cur_setting_idx, ecx
mov cur_setting_idx_secondary, edx
jmp settings_cave2_exit
}
}
// entry: 0x004144EC
int settings_cave3_exit = 0x00414507;
void __declspec(naked) settings_cave3()
{
_asm
{
//mov eax, ds:0x736344
mov esi, cur_setting_idx
jmp settings_cave3_exit
}
}
#pragma runtime_checks( "", off )
#define JOYCONFIG_EMPTYSTR "Not bindable"
// joy config menu
// entrypoint: 0x00414830
void __stdcall SetConfigButtonText(int JoyMapIndex, int Secondary)
{
unsigned int ObjHash = 0;
_asm mov ObjHash, ecx
char* FEngPkgName = "PC_JoyPad_Config.fng";
if (*(int*)CONFIG_JOY_INDEX_ADDR == 0)
FEngPkgName = "PC_Keyboard_Config.fng";
if (*(int*)CONFIG_JOY_INDEX_ADDR == 0)
{
// Keyboard config
if ((JoyMapIndex == 3) || (JoyMapIndex == 4))
{
if (JoyMapIndex == 3)
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ControlsTextsPC[SteerLeftVKey]);
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), JOYCONFIG_EMPTYSTR);
}
if (JoyMapIndex == 4)
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ControlsTextsPC[SteerRightVKey]);
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), JOYCONFIG_EMPTYSTR);
}
}
else
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ControlsTextsPC[ScannerConfigs[MapKeyboardConfigToEvent(JoyMapIndex)].keycode]);
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), JOYCONFIG_EMPTYSTR);
}
}
else
{
// JoyPad config
if ((JoyMapIndex >= 1) && (JoyMapIndex <= 4))
{
if (JoyMapIndex == 1)
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, ScannerConfigs[MapJoypadConfigToEvent(JoyMapIndex)].BitmaskStuff));
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, ScannerConfigs[MapSecondaryJoypadConfigToEvent(JoyMapIndex)].BitmaskStuff));
}
if (JoyMapIndex == 2)
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, ScannerConfigs[MapJoypadConfigToEvent(JoyMapIndex)].BitmaskStuff));
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, ScannerConfigs[MapSecondaryJoypadConfigToEvent(JoyMapIndex)].BitmaskStuff));
}
if (JoyMapIndex == 3)
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, SteerLeftAxis));
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, SteerLeftButton));
}
if (JoyMapIndex == 4)
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, SteerRightAxis));
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, SteerRightButton));
}
}
else
{
if (Secondary == 0)
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), ConvertBitmaskToControlString(ControllerIconMode, ScannerConfigs[MapJoypadConfigToEvent(JoyMapIndex)].BitmaskStuff));
else
FEPrintf((void*)FEngFindString(FEngPkgName, ObjHash), JOYCONFIG_EMPTYSTR);
}
}
}
#pragma runtime_checks( "", restore )
#endif
int bStringHash(char* a1)
{
char* v1; // edx@1
char v2; // cl@1
int result; // eax@1
v1 = a1;
v2 = *a1;
for (result = -1; v2; ++v1)
{
result = v2 + 33 * result;
v2 = v1[1];
}
return result;
}
bool bIsAnyAnalogActive()
{
return (g_Controllers[0].state.Gamepad.sThumbLX || g_Controllers[0].state.Gamepad.sThumbLY || g_Controllers[0].state.Gamepad.sThumbRX || g_Controllers[0].state.Gamepad.sThumbRY || g_Controllers[0].state.Gamepad.bRightTrigger || g_Controllers[0].state.Gamepad.bLeftTrigger);
}
float GetAnalogStickValue(int index, WORD bind)
{
float result = 0.0f;
int rdi = index;
switch (bind)
{
case XINPUT_GAMEPAD_LT_CONFIGDEF:
result = g_Controllers[rdi].state.Gamepad.bLeftTrigger / 255.0f;
break;
case XINPUT_GAMEPAD_RT_CONFIGDEF:
result = g_Controllers[rdi].state.Gamepad.bRightTrigger / 255.0f;
break;
case XINPUT_GAMEPAD_LS_X_CONFIGDEF:
result = g_Controllers[rdi].state.Gamepad.sThumbLX / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_RS_X_CONFIGDEF:
result = g_Controllers[rdi].state.Gamepad.sThumbRX / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_LS_Y_CONFIGDEF:
result = g_Controllers[rdi].state.Gamepad.sThumbLY / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_RS_Y_CONFIGDEF:
result = g_Controllers[rdi].state.Gamepad.sThumbRY / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_LS_UP_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbLY > 0)
result = g_Controllers[rdi].state.Gamepad.sThumbLY / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_LS_DOWN_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbLY < 0)
result = -g_Controllers[rdi].state.Gamepad.sThumbLY / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbLX < 0)
result = -g_Controllers[rdi].state.Gamepad.sThumbLX / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbLX > 0)
result = g_Controllers[rdi].state.Gamepad.sThumbLX / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_RS_UP_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbRY > 0)
result = g_Controllers[rdi].state.Gamepad.sThumbRY / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_RS_DOWN_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbRY < 0)
result = -g_Controllers[rdi].state.Gamepad.sThumbRY / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_RS_LEFT_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbRX < 0)
result = -g_Controllers[rdi].state.Gamepad.sThumbRX / (float)(0x7FFF);
break;
case XINPUT_GAMEPAD_RS_RIGHT_CONFIGDEF:
if (g_Controllers[rdi].state.Gamepad.sThumbRX > 0)
result = g_Controllers[rdi].state.Gamepad.sThumbRX / (float)(0x7FFF);
break;
default:
break;
}
return result;
}
uint16_t GetAnalogActivity()
{
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_LT_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_LT_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_RT_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_RT_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_LS_UP_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_LS_UP_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_LS_DOWN_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_LS_DOWN_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_RS_UP_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_RS_UP_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_RS_DOWN_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_RS_DOWN_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_RS_LEFT_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_RS_LEFT_CONFIGDEF;
if (GetAnalogStickValue(0, XINPUT_GAMEPAD_RS_RIGHT_CONFIGDEF) >= 1.0f)
return XINPUT_GAMEPAD_RS_RIGHT_CONFIGDEF;
return 0;
}
//////////////////////////////////////////////////////////////////
// Scanner functions
//////////////////////////////////////////////////////////////////
int Scanner_DigitalUpOrDown_XInput(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
int ci = 0;
if ((int)Joystick == JOY2_ADDR)
ci = 1;
WORD wButtons = g_Controllers[ci].state.Gamepad.wButtons;
//printf("Scanner: %x %x %x %x %x\n", EventNode, unk1, unk2, inScannerConfig, Joystick);
// throttle/brake is very time sensitive, so we return all the time
if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE))
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if ((wButtons & inScannerConfig->BitmaskStuff))
{
EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & inScannerConfig->BitmaskStuff);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(wButtons & inScannerConfig->BitmaskStuff))
{
EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & inScannerConfig->BitmaskStuff);
return inScannerConfig->JoyEvent;
}
}
// we're using BitmaskStuff to define which button is actually pressed
if ((wButtons & inScannerConfig->BitmaskStuff) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if ((wButtons & inScannerConfig->BitmaskStuff))
{
EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & inScannerConfig->BitmaskStuff);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(wButtons & inScannerConfig->BitmaskStuff))
{
EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & inScannerConfig->BitmaskStuff);
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalUpOrDown_RawKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
int ci = 0;
if ((int)Joystick == JOY2_ADDR)
ci = 1;
// throttle is very time sensitive, so we return all the time
if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE))
{
if (inScannerConfig->keycode && VKeyStates[ci][inScannerConfig->keycode])
{
EventStatesKB[ci][inScannerConfig->JoyEvent] = VKeyStates[ci][inScannerConfig->keycode];
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
if (inScannerConfig->keycode && !VKeyStates[ci][inScannerConfig->keycode])
{
EventStatesKB[ci][inScannerConfig->JoyEvent] = VKeyStates[ci][inScannerConfig->keycode];
return inScannerConfig->JoyEvent;
}
}
// we're using BitmaskStuff to define which button is actually pressed
if (inScannerConfig->keycode && ((VKeyStates[ci][inScannerConfig->keycode]) != EventStatesKB[ci][inScannerConfig->JoyEvent]))
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (inScannerConfig->keycode && VKeyStates[ci][inScannerConfig->keycode])
{
EventStatesKB[ci][inScannerConfig->JoyEvent] = VKeyStates[ci][inScannerConfig->keycode];
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (inScannerConfig->keycode && !VKeyStates[ci][inScannerConfig->keycode])
{
EventStatesKB[ci][inScannerConfig->JoyEvent] = VKeyStates[ci][inScannerConfig->keycode];
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalUpOrDown_SyncKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
bool bKeyState = false;
if (inScannerConfig->keycode)
bKeyState = VKeyStates[0][inScannerConfig->keycode] >> 7;
// throttle is very time sensitive, so we return all the time
if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE))
{
if (bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
if (!bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent;
}
}
// we're using BitmaskStuff to define which button is actually pressed
if ((bKeyState) != EventStatesKB[0][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalUpOrDown_AsyncKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
bool bKeyState = false;
if (inScannerConfig->keycode)
bKeyState = GetAsyncKeyState(inScannerConfig->keycode) >> 15;
// throttle/brake is very time sensitive, so we return all the time
if ((inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_THROTTLE_ANALOG_ALTERNATE) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG) || (inScannerConfig->JoyEvent == JOY_EVENT_BRAKE_ANALOG_ALTERNATE))
{
if (bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
if (!bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent;
}
}
// we're using BitmaskStuff to define which button is actually pressed
if (bKeyState != EventStatesKB[0][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!bKeyState)
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalUpOrDown_KB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
switch (KeyboardReadingMode)
{
case KB_READINGMODE_UNBUFFERED_RAW:
return Scanner_DigitalUpOrDown_RawKB(EventNode, unk1, unk2, inScannerConfig, Joystick);
case KB_READINGMODE_BUFFERED:
return Scanner_DigitalUpOrDown_SyncKB(EventNode, unk1, unk2, inScannerConfig, Joystick);
case KB_READINGMODE_UNBUFFERED_ASYNC:
default:
return Scanner_DigitalUpOrDown_AsyncKB(EventNode, unk1, unk2, inScannerConfig, Joystick);
}
}
int Scanner_DigitalUpOrDown(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
return Scanner_DigitalUpOrDown_XInput(EventNode, unk1, unk2, inScannerConfig, Joystick) | Scanner_DigitalUpOrDown_KB(EventNode, unk1, unk2, inScannerConfig, Joystick);
}
// same thing as DigitalUpOrDown except no KEY UP detection, only KEY DOWN
int Scanner_DigitalDown_XInput(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
int ci = 0;
if ((int)Joystick == JOY2_ADDR)
ci = 1;
WORD wButtons = g_Controllers[ci].state.Gamepad.wButtons;
// we're using BitmaskStuff to define which button is actually pressed
if ((wButtons & inScannerConfig->BitmaskStuff) != EventStates[ci][inScannerConfig->JoyEvent])
{
EventStates[ci][inScannerConfig->JoyEvent] = (wButtons & inScannerConfig->BitmaskStuff);
// on change to TRUE -- return event
if ((wButtons & inScannerConfig->BitmaskStuff))
{
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
// same thing as DigitalUpOrDown except no KEY UP detection, only KEY DOWN
int Scanner_DigitalDown_RawKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
int ci = 0;
if ((int)Joystick == JOY2_ADDR)
ci = 1;
// we're using BitmaskStuff to define which button is actually pressed
if (inScannerConfig->keycode && ((VKeyStates[ci][inScannerConfig->keycode]) != EventStatesKB[ci][inScannerConfig->JoyEvent]))
{
EventStatesKB[ci][inScannerConfig->JoyEvent] = (VKeyStates[ci][inScannerConfig->keycode]);
// on change to TRUE -- return event
if ((VKeyStates[ci][inScannerConfig->keycode]))
{
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalDown_SyncKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
bool bKeyState = false;
if (inScannerConfig->keycode)
bKeyState = VKeyStates[0][inScannerConfig->keycode] >> 7;
// we're using BitmaskStuff to define which button is actually pressed
if (bKeyState != EventStatesKB[0][inScannerConfig->JoyEvent])
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
// on change to TRUE -- return event
if (bKeyState)
{
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalDown_AsyncKB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
bool bKeyState = false;
if (inScannerConfig->keycode)
bKeyState = GetAsyncKeyState(inScannerConfig->keycode) >> 15;
// we're using BitmaskStuff to define which button is actually pressed
if (bKeyState != EventStatesKB[0][inScannerConfig->JoyEvent])
{
EventStatesKB[0][inScannerConfig->JoyEvent] = bKeyState;
// on change to TRUE -- return event
if (bKeyState)
{
return inScannerConfig->JoyEvent;
}
}
// otherwise just keep returning zero, we're only returning changes
return 0;
}
int Scanner_DigitalDown_KB(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
switch (KeyboardReadingMode)
{
case KB_READINGMODE_UNBUFFERED_RAW:
return Scanner_DigitalDown_RawKB(EventNode, unk1, unk2, inScannerConfig, Joystick);
case KB_READINGMODE_BUFFERED:
return Scanner_DigitalDown_SyncKB(EventNode, unk1, unk2, inScannerConfig, Joystick);
case KB_READINGMODE_UNBUFFERED_ASYNC:
default:
return Scanner_DigitalDown_AsyncKB(EventNode, unk1, unk2, inScannerConfig, Joystick);
}
}
int Scanner_DigitalDown(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
return Scanner_DigitalDown_XInput(EventNode, unk1, unk2, inScannerConfig, Joystick) | Scanner_DigitalDown_KB(EventNode, unk1, unk2, inScannerConfig, Joystick);
}
// when an analog axis is assigned to a digital-only function
int Scanner_DigitalAnalog_XInput(void* EventNode, unsigned int* unk1, unsigned int unk2, ScannerConfig* inScannerConfig, void* Joystick)
{
int ci = 0;
if ((int)Joystick == JOY2_ADDR)
ci = 1;
WORD threshold = FEUPDOWN_ANALOG_THRESHOLD;
if (inScannerConfig->JoyEvent == JOY_EVENT_SHIFTUP || inScannerConfig->JoyEvent == JOY_EVENT_SHIFTDOWN || inScannerConfig->JoyEvent == JOY_EVENT_SHIFTUP_ALTERNATE || inScannerConfig->JoyEvent == JOY_EVENT_SHIFTDOWN_ALTERNATE)
threshold = SHIFT_ANALOG_THRESHOLD;
// we're using BitmaskStuff to define which button is actually pressed
switch (inScannerConfig->BitmaskStuff)
{
case XINPUT_GAMEPAD_LT_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.bLeftTrigger > TRIGGER_ACTIVATION_THRESHOLD) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.bLeftTrigger > TRIGGER_ACTIVATION_THRESHOLD)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.bLeftTrigger > TRIGGER_ACTIVATION_THRESHOLD);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.bLeftTrigger > TRIGGER_ACTIVATION_THRESHOLD))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.bLeftTrigger > TRIGGER_ACTIVATION_THRESHOLD);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_RT_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.bRightTrigger > TRIGGER_ACTIVATION_THRESHOLD) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.bRightTrigger > TRIGGER_ACTIVATION_THRESHOLD)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.bRightTrigger > TRIGGER_ACTIVATION_THRESHOLD);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.bRightTrigger > TRIGGER_ACTIVATION_THRESHOLD))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.bRightTrigger > TRIGGER_ACTIVATION_THRESHOLD);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_LS_UP_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.sThumbLY > threshold) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.sThumbLY > threshold)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLY > threshold);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.sThumbLY > threshold))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLY > threshold);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_LS_DOWN_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.sThumbLY < -threshold) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.sThumbLY < -threshold)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLY < -threshold);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.sThumbLY < -threshold))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLY < -threshold);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_LS_LEFT_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.sThumbLX < -threshold) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.sThumbLX < -threshold)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLX < -threshold);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.sThumbLX < -threshold))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLX < -threshold);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_LS_RIGHT_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.sThumbLX > threshold) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.sThumbLX > threshold)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLX > threshold);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.sThumbLX > threshold))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbLX > threshold);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_RS_UP_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.sThumbRY > threshold) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.sThumbRY > threshold)
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbRY > threshold);
return inScannerConfig->JoyEvent + (inScannerConfig->param << 8);
}
// on change to FALSE -- return JoyEvent number
if (!(g_Controllers[ci].state.Gamepad.sThumbRY > threshold))
{
EventStates[ci][inScannerConfig->JoyEvent] = (g_Controllers[ci].state.Gamepad.sThumbRY > threshold);
return inScannerConfig->JoyEvent;
}
return 0;
}
break;
case XINPUT_GAMEPAD_RS_DOWN_CONFIGDEF:
if ((g_Controllers[ci].state.Gamepad.sThumbRY < -threshold) != EventStates[ci][inScannerConfig->JoyEvent])
{
// on change to TRUE -- return 0xFF + JoyEvent number (normally this is a number defined in scannerconfig)
if (g_Controllers[ci].state.Gamepad.sThumbRY < -threshold)