kernel32/tests: Add a test to check some fields in fake dlls.
[wine.git] / dlls / xinput1_3 / xinput_main.c
blobc412887ad7a535374dda1b4e33beff49ee55b1e9
1 /*
2 * The Wine project - Xinput Joystick Library
3 * Copyright 2008 Andrew Fenn
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
25 #include "wine/debug.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
30 #include "xinput.h"
31 #include "xinput_private.h"
33 /* Not defined in the headers, used only by XInputGetStateEx */
34 #define XINPUT_GAMEPAD_GUIDE 0x0400
36 WINE_DEFAULT_DEBUG_CHANNEL(xinput);
38 xinput_controller controllers[XUSER_MAX_COUNT];
40 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
42 switch(reason)
44 case DLL_PROCESS_ATTACH:
45 DisableThreadLibraryCalls(inst);
46 break;
47 case DLL_PROCESS_DETACH:
48 if (reserved) break;
49 HID_destroy_gamepads(controllers);
50 break;
52 return TRUE;
55 void WINAPI DECLSPEC_HOTPATCH XInputEnable(BOOL enable)
57 int index;
59 TRACE("(enable %d)\n", enable);
61 /* Setting to false will stop messages from XInputSetState being sent
62 to the controllers. Setting to true will send the last vibration
63 value (sent to XInputSetState) to the controller and allow messages to
64 be sent */
65 HID_find_gamepads(controllers);
67 for (index = 0; index < XUSER_MAX_COUNT; index ++)
69 if (!controllers[index].connected) continue;
70 HID_enable(&controllers[index], enable);
74 DWORD WINAPI DECLSPEC_HOTPATCH XInputSetState(DWORD index, XINPUT_VIBRATION* vibration)
76 TRACE("(index %u, vibration %p)\n", index, vibration);
78 HID_find_gamepads(controllers);
80 if (index >= XUSER_MAX_COUNT)
81 return ERROR_BAD_ARGUMENTS;
82 if (!controllers[index].connected)
83 return ERROR_DEVICE_NOT_CONNECTED;
85 return HID_set_state(&controllers[index], vibration);
88 /* Some versions of SteamOverlayRenderer hot-patch XInputGetStateEx() and call
89 * XInputGetState() in the hook, so we need a wrapper. */
90 static DWORD xinput_get_state(DWORD index, XINPUT_STATE *state)
92 HID_find_gamepads(controllers);
94 if (index >= XUSER_MAX_COUNT)
95 return ERROR_BAD_ARGUMENTS;
96 if (!controllers[index].connected)
97 return ERROR_DEVICE_NOT_CONNECTED;
99 HID_update_state(&controllers[index]);
100 memcpy(state, &controllers[index].state, sizeof(XINPUT_STATE));
102 return ERROR_SUCCESS;
106 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetState(DWORD index, XINPUT_STATE* state)
108 DWORD ret;
110 TRACE("(index %u, state %p)!\n", index, state);
112 ret = xinput_get_state(index, state);
113 if (ret != ERROR_SUCCESS)
114 return ret;
116 /* The main difference between this and the Ex version is the media guide button */
117 state->Gamepad.wButtons &= ~XINPUT_GAMEPAD_GUIDE;
119 return ERROR_SUCCESS;
122 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetStateEx(DWORD index, XINPUT_STATE* state)
124 TRACE("(index %u, state %p)!\n", index, state);
126 return xinput_get_state(index, state);
129 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetKeystroke(DWORD index, DWORD reserved, PXINPUT_KEYSTROKE keystroke)
131 static int warn_once;
133 if (!warn_once++)
134 FIXME("(index %u, reserved %u, keystroke %p) Stub!\n", index, reserved, keystroke);
136 if (index >= XUSER_MAX_COUNT)
137 return ERROR_BAD_ARGUMENTS;
138 if (!controllers[index].connected)
139 return ERROR_DEVICE_NOT_CONNECTED;
141 return ERROR_NOT_SUPPORTED;
144 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetCapabilities(DWORD index, DWORD flags, XINPUT_CAPABILITIES* capabilities)
146 TRACE("(index %u, flags 0x%x, capabilities %p)\n", index, flags, capabilities);
148 HID_find_gamepads(controllers);
150 if (index >= XUSER_MAX_COUNT)
151 return ERROR_BAD_ARGUMENTS;
152 if (!controllers[index].connected)
153 return ERROR_DEVICE_NOT_CONNECTED;
154 if (flags & XINPUT_FLAG_GAMEPAD && controllers[index].caps.SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
155 return ERROR_DEVICE_NOT_CONNECTED;
157 memcpy(capabilities, &controllers[index].caps, sizeof(*capabilities));
159 return ERROR_SUCCESS;
162 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetDSoundAudioDeviceGuids(DWORD index, GUID* render_guid, GUID* capture_guid)
164 FIXME("(index %u, render guid %p, capture guid %p) Stub!\n", index, render_guid, capture_guid);
166 if (index >= XUSER_MAX_COUNT)
167 return ERROR_BAD_ARGUMENTS;
168 if (!controllers[index].connected)
169 return ERROR_DEVICE_NOT_CONNECTED;
171 return ERROR_NOT_SUPPORTED;
174 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetBatteryInformation(DWORD index, BYTE type, XINPUT_BATTERY_INFORMATION* battery)
176 static int once;
178 if (!once++)
179 FIXME("(index %u, type %u, battery %p) Stub!\n", index, type, battery);
181 if (index >= XUSER_MAX_COUNT)
182 return ERROR_BAD_ARGUMENTS;
183 if (!controllers[index].connected)
184 return ERROR_DEVICE_NOT_CONNECTED;
186 return ERROR_NOT_SUPPORTED;