Advertisement
Guest User

Untitled

a guest
Nov 30th, 2010
4,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.49 KB | None | 0 0
  1. diff -pur wine-1.3.5/dlls/user32/Makefile.in wine-1.3.5-wot/dlls/user32/Makefile.in
  2. --- wine-1.3.5/dlls/user32/Makefile.in 2010-10-15 21:37:09.000000000 +0400
  3. +++ wine-1.3.5-wot/dlls/user32/Makefile.in 2010-10-18 22:44:01.000000000 +0400
  4. @@ -1,7 +1,7 @@
  5. EXTRADEFS = -D_USER32_ -D_WINABLE_
  6. MODULE = user32.dll
  7. IMPORTLIB = user32
  8. -IMPORTS = gdi32 version advapi32
  9. +IMPORTS = gdi32 version advapi32 ntdll dinput8 dinput dxguid
  10. DELAYIMPORTS = imm32
  11.  
  12. C_SRCS = \
  13. diff -pur wine-1.3.5/dlls/user32/input.c wine-1.3.5-wot/dlls/user32/input.c
  14. --- wine-1.3.5/dlls/user32/input.c 2010-10-15 21:37:09.000000000 +0400
  15. +++ wine-1.3.5-wot/dlls/user32/input.c 2010-10-18 22:49:57.000000000 +0400
  16. @@ -22,6 +22,14 @@
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  18. */
  19.  
  20. +/*
  21. + * Modififed by Reco 2009
  22. + * patch is based on
  23. + * http://win2kgaming.site90.com/phpBB2/viewtopic.php?f=6&t=7
  24. + * OldCigarettes Windows 2000 XP API Wrapper Pack
  25. + * Released under LGPL
  26. + */
  27. +
  28. #include "config.h"
  29. #include "wine/port.h"
  30.  
  31. @@ -46,10 +54,59 @@
  32. #include "wine/server.h"
  33. #include "wine/debug.h"
  34. #include "wine/unicode.h"
  35. +#include "dinput.h"
  36.  
  37. +DWORD WINAPI __pollInput(HWND) ;
  38. WINE_DEFAULT_DEBUG_CHANNEL(win);
  39. WINE_DECLARE_DEBUG_CHANNEL(keyboard);
  40.  
  41. +BOOL mouse_init = FALSE;
  42. +BOOL first_raw = TRUE;
  43. +LPDIRECTINPUT8A lpdi;
  44. +LPDIRECTINPUTDEVICE8A m_mouse;
  45. +
  46. +static DIMOUSESTATE2 mouse_state;
  47. +static DIMOUSESTATE2 mouse_state_prev;
  48. +
  49. +DWORD winCenterX, winCenterY;
  50. +DWORD winX, winY;
  51. +DWORD winR, winB;
  52. +LONG prevX, prevY;
  53. +#define arL 20
  54. +struct hist_data {
  55. + DWORD val;
  56. + int cnt;
  57. +};
  58. +int cntY1, cntY2;
  59. +
  60. +int prevCenterY = 0;
  61. +int wot_snipe = 0;
  62. +
  63. +#define MOUSE_INPUT 0xABC123
  64. +#define RIM_TYPEMOUSE 0
  65. +#define RIM_INPUT 0x00000000
  66. +#define MOUSE_MOVE_RELATIVE 0x00000000
  67. +#define MOUSE_MOVE_ABSOLUTE 0x00000001
  68. +#define MOUSE_VIRTUAL_DESKTOP 0x00000002
  69. +#define RI_MOUSE_LEFT_BUTTON_DOWN 0x0001
  70. +#define RI_MOUSE_LEFT_BUTTON_UP 0x0002
  71. +#define RI_MOUSE_RIGHT_BUTTON_DOWN 0x0004
  72. +#define RI_MOUSE_RIGHT_BUTTON_UP 0x0008
  73. +#define RI_MOUSE_MIDDLE_BUTTON_DOWN 0x0010
  74. +#define RI_MOUSE_MIDDLE_BUTTON_UP 0x0020
  75. +#define RI_MOUSE_BUTTON_1_DOWN RI_MOUSE_LEFT_BUTTON_DOWN
  76. +#define RI_MOUSE_BUTTON_1_UP RI_MOUSE_LEFT_BUTTON_UP
  77. +#define RI_MOUSE_BUTTON_2_DOWN RI_MOUSE_RIGHT_BUTTON_DOWN
  78. +#define RI_MOUSE_BUTTON_2_UP RI_MOUSE_RIGHT_BUTTON_UP
  79. +#define RI_MOUSE_BUTTON_3_DOWN RI_MOUSE_MIDDLE_BUTTON_DOWN
  80. +#define RI_MOUSE_BUTTON_3_UP RI_MOUSE_MIDDLE_BUTTON_UP
  81. +#define RI_MOUSE_BUTTON_4_DOWN 0x0040
  82. +#define RI_MOUSE_BUTTON_4_UP 0x0080
  83. +#define RI_MOUSE_BUTTON_5_DOWN 0x0100
  84. +#define RI_MOUSE_BUTTON_5_UP 0x0200
  85. +#define RI_MOUSE_WHEEL 0x0400
  86. +#define RIDEV_INPUTSINK 0x00000100
  87. +#define MOUSE_DEVICE_HANDLE 0x1337
  88.  
  89. /***********************************************************************
  90. * get_key_state
  91. @@ -384,10 +441,82 @@ UINT WINAPI GetRawInputDeviceList(PRAWIN
  92. /******************************************************************
  93. * RegisterRawInputDevices (USER32.@)
  94. */
  95. -BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
  96. +BOOL WINAPI RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
  97. {
  98. - FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
  99. + DWORD flags;
  100. + HWND hWnd;
  101. +
  102. + RECT rect;
  103. +
  104. + if(first_raw) {
  105. + FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
  106. + first_raw = FALSE;
  107. + return TRUE;
  108. + }
  109. +
  110. + WARN("Only mouse is supported.\n");
  111. + if(uiNumDevices != 1)
  112. + return FALSE;
  113. + if(pRawInputDevices->usUsagePage != 0x01 || pRawInputDevices->usUsage != 0x02)
  114. + return FALSE;
  115. +
  116. + TRACE("Get the window handle if we need to...\n");
  117. + hWnd = pRawInputDevices->hwndTarget;
  118. + if(!hWnd) hWnd = GetActiveWindow();
  119. + if(!hWnd) return FALSE;
  120. +
  121. + if(!GetWindowRect(hWnd, &rect))
  122. + return FALSE;
  123. + winCenterX = (rect.right - rect.left) / 2;
  124. + winCenterY = (rect.bottom - rect.top ) / 2;
  125. + winX = rect.left;
  126. + winY = rect.top ;
  127. + winR = rect.right;
  128. + winB = rect.bottom ;
  129. +
  130. + TRACE("Trying to map flags to DirectX...\n");
  131. + flags = 0;
  132. + if(pRawInputDevices->dwFlags & RIDEV_INPUTSINK)
  133. + flags |= DISCL_BACKGROUND;
  134. + else
  135. + flags |= DISCL_FOREGROUND;
  136. + flags |= DISCL_NONEXCLUSIVE;
  137. +
  138. + TRACE("Init mouse\n");
  139. + if (FAILED(DirectInput8Create(GetModuleHandleW(NULL),
  140. + DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&lpdi, NULL)))
  141. + {
  142. + ERR("DirectInput8Create failed.\n");
  143. + return FALSE;
  144. + }
  145. +
  146. + if (FAILED(lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysMouse, &m_mouse, NULL)))
  147. + {
  148. + ERR("CreateDevice failed.\n");
  149. + return FALSE;
  150. + }
  151. +
  152. + if (FAILED(m_mouse->lpVtbl->SetCooperativeLevel(m_mouse, hWnd, flags)))
  153. + {
  154. + ERR("SetCooperativeLevel failed.\n");
  155. + return FALSE;
  156. + }
  157. +
  158. + if (FAILED(m_mouse->lpVtbl->SetDataFormat(m_mouse, &c_dfDIMouse2)))
  159. + {
  160. + ERR("SetDataFormat failed.\n");
  161. + return FALSE;
  162. + }
  163.  
  164. + m_mouse->lpVtbl->Acquire(m_mouse); //OK if we don't acquire now
  165. +
  166. + if(!CreateThread(NULL, 0, __pollInput, hWnd, 0, NULL))
  167. + {
  168. + ERR("Failed to CreateThread for __pollInput.\n");
  169. + return FALSE;
  170. + }
  171. +
  172. + mouse_init = TRUE;
  173. return TRUE;
  174. }
  175.  
  176. @@ -397,12 +526,116 @@ BOOL WINAPI DECLSPEC_HOTPATCH RegisterRa
  177. */
  178. UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
  179. {
  180. - FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
  181. - hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
  182. + HRESULT hr;
  183. + RAWINPUT *raw;
  184. + POINT pos;
  185. + int i,j,cnt_max;
  186. + HWND hWnd;
  187. + RECT rect;
  188. + int diffY;
  189.  
  190. - return 0;
  191. -}
  192. + if(pData == NULL)
  193. + {
  194. + *pcbSize = sizeof(RAWINPUT);
  195. + return 0;
  196. + }
  197. +
  198. + raw = (RAWINPUT *)pData;
  199. + if(!mouse_init) return FALSE;
  200. +
  201. + raw->header.dwType = RIM_TYPEMOUSE;
  202. + raw->header.dwSize = sizeof(RAWINPUT);
  203. + raw->header.hDevice = MOUSE_DEVICE_HANDLE;
  204. + raw->header.wParam = RIM_INPUT;
  205. +
  206. + hr = m_mouse->lpVtbl->GetDeviceState(m_mouse, sizeof(DIMOUSESTATE2), (LPVOID)&mouse_state);
  207. + if(FAILED(hr))
  208. + {
  209. + TRACE("Re-acquiring input.\n");
  210. + m_mouse->lpVtbl->Acquire(m_mouse);
  211. + while(hr == DIERR_INPUTLOST)
  212. + {
  213. + hr = m_mouse->lpVtbl->Acquire(m_mouse);
  214. + }
  215. + if(FAILED(hr))
  216. + {
  217. + TRACE("Mouse re-acquire failed.\n");
  218. + return 0;
  219. + }
  220. + m_mouse->lpVtbl->GetDeviceState(m_mouse, sizeof(DIMOUSESTATE2), (LPVOID)&mouse_state);
  221. + }
  222.  
  223. + GetCursorPos(&pos);
  224. + if(!hWnd) hWnd = GetActiveWindow();
  225. + if(!GetWindowRect(hWnd, &rect)) return FALSE;
  226. + winCenterX = (rect.right - rect.left) / 2;
  227. + winCenterY = (rect.bottom - rect.top ) / 2;
  228. + winX = rect.left;
  229. + winY = rect.top ;
  230. + winR = rect.right;
  231. + winB = rect.bottom;
  232. +
  233. +////////////////Quite ugly World of Tanks-related hack///////////////////////
  234. + if ((abs(pos.y-prevY-0.15*winCenterY)<2)&&(abs(pos.x-prevX)<0.01*winCenterX)&&(!wot_snipe)) wot_snipe = 1;
  235. + else if ((abs(prevY-pos.y-0.15*winCenterY)<2)&&(abs(pos.x-prevX)<0.01*winCenterX)&&(wot_snipe)) wot_snipe = 0;
  236. +
  237. + if (!wot_snipe) diffY = round(0.15*winCenterY); // in WoT in normal mode ordinate of position deviates slightly
  238. + else diffY = 0; // in sniping/howitzer mode it's ok, no diff needed
  239. +
  240. + FIXME("PrevY %d, posy %d, diffY %d, snipe %d\n", prevY, pos.y, diffY, wot_snipe);
  241. +/////////////////////////////////////////////////////////////////////////////
  242. +
  243. +
  244. +
  245. + raw->data.mouse.usFlags = MOUSE_MOVE_RELATIVE;
  246. + raw->data.mouse.lLastX = pos.x - winCenterX;
  247. + raw->data.mouse.lLastY = pos.y - winCenterY + diffY;
  248. +
  249. + raw->data.mouse.usButtonData = mouse_state.lZ & 0xffff;
  250. + raw->data.mouse.usButtonFlags = 0;
  251. + raw->data.mouse.ulRawButtons = 0;
  252. +
  253. + if(raw->data.mouse.usButtonData != 0) raw->data.mouse.usButtonFlags |= RI_MOUSE_WHEEL;
  254. +
  255. + for(i = 0; i < 8; i++)
  256. + if(mouse_state.rgbButtons[i] & 0x80)
  257. + raw->data.mouse.ulRawButtons |= 1<<i;
  258. +
  259. + if(mouse_state.rgbButtons[0] & 0x80 && !(mouse_state_prev.rgbButtons[0] & 0x80))
  260. + raw->data.mouse.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_DOWN;
  261. +
  262. + if(!(mouse_state.rgbButtons[0] & 0x80) && mouse_state_prev.rgbButtons[0] & 0x80)
  263. + raw->data.mouse.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_UP;
  264. +
  265. + if(mouse_state.rgbButtons[1] & 0x80 && !(mouse_state_prev.rgbButtons[1] & 0x80))
  266. + raw->data.mouse.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_DOWN;
  267. +
  268. + if(!(mouse_state.rgbButtons[1] & 0x80) && mouse_state_prev.rgbButtons[1] & 0x80)
  269. + raw->data.mouse.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_UP;
  270. +
  271. + if(!(mouse_state.rgbButtons[2] & 0x80) && mouse_state_prev.rgbButtons[2] & 0x80)
  272. + raw->data.mouse.usButtonFlags |= RI_MOUSE_MIDDLE_BUTTON_UP;
  273. +
  274. + if(mouse_state.rgbButtons[3] & 0x80 && !(mouse_state_prev.rgbButtons[3] & 0x80))
  275. + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
  276. +
  277. + if(!(mouse_state.rgbButtons[3] & 0x80) && mouse_state_prev.rgbButtons[3] & 0x80)
  278. + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
  279. +
  280. + if(mouse_state.rgbButtons[4] & 0x80 && !(mouse_state_prev.rgbButtons[4] & 0x80))
  281. + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
  282. +
  283. + if(!(mouse_state.rgbButtons[4] & 0x80) && mouse_state_prev.rgbButtons[4] & 0x80)
  284. + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
  285. +
  286. + memcpy(&mouse_state_prev, &mouse_state, sizeof(DIMOUSESTATE2));
  287. + prevX = pos.x;
  288. + prevY = pos.y;
  289. + prevCenterY = winCenterY;
  290. +
  291. + return sizeof(RAWINPUT);
  292. +
  293. +}
  294.  
  295. /******************************************************************
  296. * GetRawInputBuffer (USER32.@)
  297. @@ -436,15 +669,88 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDL
  298. return 0;
  299. }
  300.  
  301. +DWORD WINAPI __pollInput(HWND hWnd)
  302. +{
  303. + for(;;)
  304. + {
  305. + Sleep(1000/60);
  306. + TRACE("SendMessageW(%p,%p,%p,%p)\n", hWnd, WM_INPUT, RIM_INPUT, MOUSE_INPUT);
  307. + SendMessageW(hWnd, WM_INPUT, RIM_INPUT, MOUSE_INPUT);
  308. + }
  309. + return 0;
  310. +}
  311.  
  312. /******************************************************************
  313. * GetRegisteredRawInputDevices (USER32.@)
  314. */
  315. UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
  316. {
  317. - FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
  318. -
  319. - return 0;
  320. + DWORD flags;
  321. + HWND hWnd;
  322. +
  323. + RECT rect;
  324. +
  325. + if(mouse_init) return 0;
  326. +
  327. + WARN("Only mouse is supported.\n");
  328. + if(puiNumDevices != 1)
  329. + return FALSE;
  330. + if(pRawInputDevices->usUsagePage != 0x01 || pRawInputDevices->usUsage != 0x02)
  331. + return FALSE;
  332. +
  333. + TRACE("Get the window handle if we need to...\n");
  334. + hWnd = pRawInputDevices->hwndTarget;
  335. + if(!hWnd) hWnd = GetActiveWindow();
  336. + if(!hWnd) return FALSE;
  337. +
  338. + if(!GetWindowRect(hWnd, &rect))
  339. + return FALSE;
  340. + winCenterX = (rect.right - rect.left) / 2;
  341. + winCenterY = (rect.bottom - rect.top ) / 2;
  342. +
  343. + TRACE("Trying to map flags to DirectX...\n");
  344. + flags = 0;
  345. + if(pRawInputDevices->dwFlags & RIDEV_INPUTSINK)
  346. + flags |= DISCL_BACKGROUND;
  347. + else
  348. + flags |= DISCL_FOREGROUND;
  349. + flags |= DISCL_NONEXCLUSIVE;
  350. +
  351. + TRACE("Init mouse\n");
  352. + if (FAILED(DirectInput8Create(GetModuleHandleW(NULL),
  353. + DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&lpdi, NULL)))
  354. + {
  355. + ERR("DirectInput8Create failed.\n");
  356. + return FALSE;
  357. + }
  358. +
  359. + if (FAILED(lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysMouse, &m_mouse, NULL)))
  360. + {
  361. + ERR("CreateDevice failed.\n");
  362. + return FALSE;
  363. + }
  364. +
  365. + if (FAILED(m_mouse->lpVtbl->SetCooperativeLevel(m_mouse, hWnd, flags)))
  366. + {
  367. + ERR("SetCooperativeLevel failed.\n");
  368. + return FALSE;
  369. + }
  370. +
  371. + if (FAILED(m_mouse->lpVtbl->SetDataFormat(m_mouse, &c_dfDIMouse2)))
  372. + {
  373. + ERR("SetDataFormat failed.\n");
  374. + return FALSE;
  375. + }
  376. +
  377. + m_mouse->lpVtbl->Acquire(m_mouse); //OK if we don't acquire now
  378. +
  379. + if(!CreateThread(NULL, 0, __pollInput, hWnd, 0, NULL))
  380. + {
  381. + ERR("Failed to CreateThread for __pollInput.\n");
  382. + return FALSE;
  383. + }
  384. +
  385. + mouse_init = TRUE;
  386. }
  387.  
  388.  
  389. diff -pur wine-1.3.5/include/winuser.h wine-1.3.5-wot/include/winuser.h
  390. --- wine-1.3.5/include/winuser.h 2010-10-15 21:37:09.000000000 +0400
  391. +++ wine-1.3.5-wot/include/winuser.h 2010-10-18 22:46:08.000000000 +0400
  392. @@ -491,8 +491,8 @@ typedef struct tagRAWMOUSE {
  393. struct {
  394. USHORT usButtonFlags;
  395. USHORT usButtonData;
  396. - } DUMMYSTRUCTNAME;
  397. - } DUMMYUNIONNAME;
  398. + };
  399. + };
  400. ULONG ulRawButtons;
  401. LONG lLastX;
  402. LONG lLastY;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement