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
|
* You should have received a copy of the GNU Lesser General Public License
* version 3.0 along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#import "OFGameController.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFSet.h"
#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"
#include <xinput.h>
@interface OFGameController ()
- (instancetype)of_initWithIndex: (DWORD)index OF_METHOD_FAMILY(init);
@end
struct XInputCapabilitiesEx {
XINPUT_CAPABILITIES capabilities;
WORD vendorID;
WORD productID;
WORD versionNumber;
WORD unknown1;
DWORD unknown2;
};
static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *);
static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD,
struct XInputCapabilitiesEx *);
static const char *XInputVersion;
@implementation OFGameController
@synthesize vendorID = _vendorID, productID = _productID;
@synthesize leftAnalogStickPosition = _leftAnalogStickPosition;
@synthesize rightAnalogStickPosition = _rightAnalogStickPosition;
+ (void)initialize
{
HMODULE module;
if (self != [OFGameController class])
return;
if ((module = LoadLibraryA("xinput1_4.dll")) != NULL) {
XInputGetStateFuncPtr =
(WINAPI DWORD (*)(DWORD, XINPUT_STATE *))
GetProcAddress(module, "XInputGetState");
XInputGetCapabilitiesExFuncPtr = (WINAPI DWORD (*)(DWORD, DWORD,
|
|
<
<
<
<
|
|
|
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
|
* You should have received a copy of the GNU Lesser General Public License
* version 3.0 along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#import "OFXInputGameController.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFSet.h"
#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"
#include <xinput.h>
struct XInputCapabilitiesEx {
XINPUT_CAPABILITIES capabilities;
WORD vendorID;
WORD productID;
WORD versionNumber;
WORD unknown1;
DWORD unknown2;
};
static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *);
static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD,
struct XInputCapabilitiesEx *);
static const char *XInputVersion;
@implementation OFXInputGameController
@synthesize vendorID = _vendorID, productID = _productID;
@synthesize leftAnalogStickPosition = _leftAnalogStickPosition;
@synthesize rightAnalogStickPosition = _rightAnalogStickPosition;
+ (void)initialize
{
HMODULE module;
if (self != [OFXInputGameController class])
return;
if ((module = LoadLibraryA("xinput1_4.dll")) != NULL) {
XInputGetStateFuncPtr =
(WINAPI DWORD (*)(DWORD, XINPUT_STATE *))
GetProcAddress(module, "XInputGetState");
XInputGetCapabilitiesExFuncPtr = (WINAPI DWORD (*)(DWORD, DWORD,
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
if (XInputGetStateFuncPtr != NULL) {
void *pool = objc_autoreleasePoolPush();
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) {
OFGameController *controller;
@try {
controller = [[[OFGameController alloc]
of_initWithIndex: i] autorelease];
} @catch (OFInitializationFailedException *e) {
/* Controller does not exist. */
continue;
}
[controllers addObject: controller];
|
|
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
if (XInputGetStateFuncPtr != NULL) {
void *pool = objc_autoreleasePoolPush();
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) {
OFGameController *controller;
@try {
controller = [[[OFXInputGameController alloc]
of_initWithIndex: i] autorelease];
} @catch (OFInitializationFailedException *e) {
/* Controller does not exist. */
continue;
}
[controllers addObject: controller];
|