forked from PlexaryDamato/nrage-input
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathXInputController.h
160 lines (133 loc) · 6.08 KB
/
XInputController.h
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
/*
XInput Controller support for N-Rage`s Dinput8 Plugin
(C) 2002, 2006 Norbert Wladyka - N-Rage`s Dinput8 Plugin
(C) 2009 Daniel Rehren - XInput Controller support
N-Rage`s Dinput8 Plugin:
Author`s Email: [email protected]
Website: http://go.to/nrage
XInput Controller support:
Author's Email: [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _XINPUTCONTROLLER_H
#define _XINPUTCONTROLLER_H
//code from http://msdn.microsoft.com/en-us/library/ee417014(VS.85).aspx
#include <wbemidl.h>
#include <oleauto.h>
//#include <wmsstd.h> <-- only needed for SAFE_RELEASE(x)
#ifndef SAFE_RELEASE // when Windows Media Device M? is not present
#define SAFE_RELEASE(x) \
if(x != NULL) \
{ \
x->Release(); \
x = NULL; \
}
#endif
//-----------------------------------------------------------------------------
// Enum each PNP device using WMI and check each device ID to see if it contains
// "IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it's an XInput device
// Unfortunately this information can not be found by just using DirectInput
//-----------------------------------------------------------------------------
BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput );
//END conde from ...
/*
Xinput header for NRage Plugin, by tecnicors.
XInput Controller is going to take over the N64 control that matches its
number, ie. first XInput controller is first N64 player, etc.
*/
#include "commonIncludes.h"
#include <xinput.h>
//defines
#define N64_ANALOG_MAX 127
#define XC_ANALOG_MAX 32767
#define BUTTON_ANALOG_VALUE 107
//enums
namespace N64_BUTTONS
{
// Whith this we can asign buttons to the xinput struct
enum _N64_BUTTONS { A = 0x0080, B = 0x0040, Z = 0x0020, R = 0x1000, L = 0x2000, XAxis = 0x4000,
Start = 0x0010, DUp = 0x0008, DDown = 0x0004, DLeft = 0x0002, YAxis = 0x8000,
DRight = 0x0001, CUp = 0x0800, CDown = 0x0400, CLeft = 0x0200, CRight = 0x0100,
None = 0x0 };
}
//structures
typedef struct _XCONTROLLER // XInput controller struct
{
int nControl;
bool bConnected;
bool bConfigured;
struct _N64_BUTTONS // For button configurations
{
int iA, iB;
int iStart;
int iL, iR, iZ;
int iXAxis, iYAxis;
int iDUp, iDDown, iDLeft, iDRight;
int iCUp, iCDown, iCLeft, iCRight;
}stButtons;
struct _XINPUT_ANALOGS // For analog configurations
{
int iLeftTrigger, iRightTrigger;
unsigned int iRXAxis, iRYAxis, iLXAxis, iLYAxis;
}stAnalogs;
}XCONTROLLER;
typedef XCONTROLLER *LPXCONTROLLER;
// Sets the keys pressed for Xinput controller gController, into keys.
void GetXInputControllerKeys( const int indexController, LPDWORD Keys );
// Sets the default keys for Xinput controller gController.
void DefaultXInputControllerKeys( LPXCONTROLLER gController);
// Vibrates the XInput Control
void VibrateXInputController( DWORD nController, int LeftMotorVal = 65535, int RightMotorVal = 65535 );
// Initialize nControl XInput enabled controller
bool InitiateXInputController( LPXCONTROLLER gController, int nControl );
// XController dialog
#define XC_DPAD 1
#define XC_LTBS 2
#define XC_RTBS 3
// Reads current XInput controller key config, and shows it in the dialog.
bool ReadXInputControllerKeys( HWND hDlg, LPXCONTROLLER gController );
// Stores dialog's button configuration into the XCONTROLLER struct.
void StoreXInputControllerKeys( HWND hDlg, LPXCONTROLLER gController );
// Fills N64 button comobox with its buttons.
inline void FillN64ButtonComboBox( HWND hDlg, int ComboBox )
{
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "None" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "A" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "B" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Z" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "L" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "R" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Start" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Up" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Left" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Down" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Right" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Up" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Left" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Down" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Right" ));
SendDlgItemMessage( hDlg, ComboBox, CB_SETCURSEL, 0, ( LPARAM )0 );
}
inline void FillN64AnalogComboBox( HWND hDlg, int ComboBox )
{
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "None" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "DPad" ));
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C Buttons" ));
if( ComboBox != IDC_XC_DPAD )
SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Analog Stick" ));
SendDlgItemMessage( hDlg, ComboBox, CB_SETCURSEL, 0, ( LPARAM )0);
}
// Save/Load Keys from own config file
void SaveXInputConfigToFile( FILE *file, LPXCONTROLLER gController );
void LoadXInputConfigFromFile( FILE *file, LPXCONTROLLER gController );
#endif //_XINPUTCONTROLLER_H