3246251196
2011-Mar-15 00:13 UTC
[Wine] HUNK #N Problems When Applying A Patch For Wine 1.3.15
Anarchy Online is running great through WINE. However, I need to apply this patch in order for the right mouse button to do extra functionality == Code: diff --git a/dlls/user32/Makefile.in b/dlls/user32/Makefile.in index 3dbde26..d1ebfe8 100644 --- a/dlls/user32/Makefile.in +++ b/dlls/user32/Makefile.in @@ -1,7 +1,7 @@ EXTRADEFS = -D_USER32_ -D_WINABLE_ MODULE = user32.dll IMPORTLIB = user32 -IMPORTS = gdi32 version advapi32 +IMPORTS = gdi32 version advapi32 dinput8 dinput dxguid DELAYIMPORTS = imm32 C_SRCS = \ diff --git a/dlls/user32/input.c b/dlls/user32/input.c index 6e1e459..c0a3b42 100644 --- a/dlls/user32/input.c +++ b/dlls/user32/input.c @@ -22,6 +22,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +/* + * Modififed by Reco 2009 + * patch is based on + * http://win2kgaming.site90.com/phpBB2/viewtopic.php?f=6&t=7 + * OldCigarettes Windows 2000 XP API Wrapper Pack + * Released under LGPL + */ + #include "config.h" #include "wine/port.h" @@ -48,12 +56,46 @@ #include "wine/server.h" #include "wine/debug.h" #include "wine/unicode.h" +#include "dinput.h" +DWORD WINAPI __pollInput(LPVOID) ; WINE_DEFAULT_DEBUG_CHANNEL(win); WINE_DECLARE_DEBUG_CHANNEL(keyboard); static DWORD last_mouse_event; +BOOL mouse_init = FALSE; +LPDIRECTINPUT8A lpdi; +LPDIRECTINPUTDEVICE8A m_mouse; + +static DIMOUSESTATE2 mouse_state; +static DIMOUSESTATE2 mouse_state_prev; + +#define MOUSE_INPUT 0xABC123 +#define RIM_TYPEMOUSE 0 +#define RIM_INPUT 0x00000000 +#define MOUSE_MOVE_RELATIVE 0x00000000 +#define MOUSE_MOVE_ABSOLUTE 0x00000001 +#define RI_MOUSE_LEFT_BUTTON_DOWN 0x0001 +#define RI_MOUSE_LEFT_BUTTON_UP 0x0002 +#define RI_MOUSE_RIGHT_BUTTON_DOWN 0x0004 +#define RI_MOUSE_RIGHT_BUTTON_UP 0x0008 +#define RI_MOUSE_MIDDLE_BUTTON_DOWN 0x0010 +#define RI_MOUSE_MIDDLE_BUTTON_UP 0x0020 +#define RI_MOUSE_BUTTON_1_DOWN RI_MOUSE_LEFT_BUTTON_DOWN +#define RI_MOUSE_BUTTON_1_UP RI_MOUSE_LEFT_BUTTON_UP +#define RI_MOUSE_BUTTON_2_DOWN RI_MOUSE_RIGHT_BUTTON_DOWN +#define RI_MOUSE_BUTTON_2_UP RI_MOUSE_RIGHT_BUTTON_UP +#define RI_MOUSE_BUTTON_3_DOWN RI_MOUSE_MIDDLE_BUTTON_DOWN +#define RI_MOUSE_BUTTON_3_UP RI_MOUSE_MIDDLE_BUTTON_UP +#define RI_MOUSE_BUTTON_4_DOWN 0x0040 +#define RI_MOUSE_BUTTON_4_UP 0x0080 +#define RI_MOUSE_BUTTON_5_DOWN 0x0100 +#define RI_MOUSE_BUTTON_5_UP 0x0200 +#define RI_MOUSE_WHEEL 0x0400 +#define RIDEV_INPUTSINK 0x00000100 +#define MOUSE_DEVICE_HANDLE (HANDLE)0x1337 + /*********************************************************************** * get_key_state */ @@ -384,10 +425,66 @@ UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT /****************************************************************** * RegisterRawInputDevices (USER32.@) */ -BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize) +BOOL WINAPI RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize) { - FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize); + DWORD flags; + HWND hWnd; + + if(mouse_init) return FALSE; + + WARN("Only mouse is supported.\n"); + if(uiNumDevices != 1) + return FALSE; + if(pRawInputDevices->usUsagePage != 0x01 || pRawInputDevices->usUsage != 0x02) + return FALSE; + + hWnd = pRawInputDevices->hwndTarget; + if(!hWnd) hWnd = GetActiveWindow(); + if(!hWnd) return FALSE; + + TRACE("Trying to map flags to DirectX...\n"); + flags = 0; + if(pRawInputDevices->dwFlags & RIDEV_INPUTSINK) + flags |= DISCL_BACKGROUND; + else + flags |= DISCL_FOREGROUND; + flags |= DISCL_NONEXCLUSIVE; + + TRACE("Init mouse\n"); + if (FAILED(DirectInput8Create(GetModuleHandleW(NULL), + DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&lpdi, NULL))) + { + ERR("DirectInput8Create failed.\n"); + return FALSE; + } + + if (FAILED(lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysMouse, &m_mouse, NULL))) + { + ERR("CreateDevice failed.\n"); + return FALSE; + } + if (FAILED(m_mouse->lpVtbl->SetCooperativeLevel(m_mouse, hWnd, flags))) + { + ERR("SetCooperativeLevel failed.\n"); + return FALSE; + } + + if (FAILED(m_mouse->lpVtbl->SetDataFormat(m_mouse, &c_dfDIMouse2))) + { + ERR("SetDataFormat failed.\n"); + return FALSE; + } + + m_mouse->lpVtbl->Acquire(m_mouse); //OK if we don't acquire now + + if(!CreateThread(NULL, 0, __pollInput, hWnd, 0, NULL)) + { + ERR("Failed to CreateThread for __pollInput.\n"); + return FALSE; + } + + mouse_init = TRUE; return TRUE; } @@ -397,12 +494,86 @@ BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputD */ UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader) { - FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", - hRawInput, uiCommand, pData, pcbSize, cbSizeHeader); + HRESULT hr; + RAWINPUT *raw; + int i; - return 0; -} + if(!mouse_init) return -1; + + if(pData == NULL) + { + *pcbSize = sizeof(RAWINPUT); + return 0; + } + + raw = pData; + raw->header.dwType = RIM_TYPEMOUSE; + raw->header.dwSize = sizeof(RAWINPUT); + raw->header.hDevice = MOUSE_DEVICE_HANDLE; + raw->header.wParam = RIM_INPUT; + + hr = m_mouse->lpVtbl->GetDeviceState(m_mouse, sizeof(DIMOUSESTATE2), (LPVOID)&mouse_state); + if(FAILED(hr)) + { + TRACE("Re-acquiring input.\n"); + m_mouse->lpVtbl->Acquire(m_mouse); + while(hr == DIERR_INPUTLOST) + { + hr = m_mouse->lpVtbl->Acquire(m_mouse); + } + if(FAILED(hr)) + { + TRACE("Mouse re-acquire failed.\n"); + return -1; + } + m_mouse->lpVtbl->GetDeviceState(m_mouse, sizeof(DIMOUSESTATE2), (LPVOID)&mouse_state); + } + + raw->data.mouse.usFlags = MOUSE_MOVE_RELATIVE; + raw->data.mouse.lLastX = mouse_state.lX; + raw->data.mouse.lLastY = mouse_state.lY; + raw->data.mouse.usButtonData = mouse_state.lZ & 0xffff; + raw->data.mouse.usButtonFlags = 0; + raw->data.mouse.ulRawButtons = 0; + + if(raw->data.mouse.usButtonData != 0) raw->data.mouse.usButtonFlags |= RI_MOUSE_WHEEL; + + for(i = 0; i < 8; i++) + if(mouse_state.rgbButtons[i] & 0x80) + raw->data.mouse.ulRawButtons |= 1<<i; + if(mouse_state.rgbButtons[0] & 0x80 && !(mouse_state_prev.rgbButtons[0] & 0x80)) + raw->data.mouse.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_DOWN; + + if(!(mouse_state.rgbButtons[0] & 0x80) && mouse_state_prev.rgbButtons[0] & 0x80) + raw->data.mouse.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_UP; + + if(mouse_state.rgbButtons[1] & 0x80 && !(mouse_state_prev.rgbButtons[1] & 0x80)) + raw->data.mouse.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_DOWN; + + if(!(mouse_state.rgbButtons[1] & 0x80) && mouse_state_prev.rgbButtons[1] & 0x80) + raw->data.mouse.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_UP; + + if(!(mouse_state.rgbButtons[2] & 0x80) && mouse_state_prev.rgbButtons[2] & 0x80) + raw->data.mouse.usButtonFlags |= RI_MOUSE_MIDDLE_BUTTON_UP; + + if(mouse_state.rgbButtons[3] & 0x80 && !(mouse_state_prev.rgbButtons[3] & 0x80)) + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN; + + if(!(mouse_state.rgbButtons[3] & 0x80) && mouse_state_prev.rgbButtons[3] & 0x80) + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_4_UP; + + if(mouse_state.rgbButtons[4] & 0x80 && !(mouse_state_prev.rgbButtons[4] & 0x80)) + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN; + + if(!(mouse_state.rgbButtons[4] & 0x80) && mouse_state_prev.rgbButtons[4] & 0x80) + raw->data.mouse.usButtonFlags |= RI_MOUSE_BUTTON_5_UP; + + memcpy(&mouse_state_prev, &mouse_state, sizeof(DIMOUSESTATE2)); + + return sizeof(RAWINPUT); + +} /****************************************************************** * GetRawInputBuffer (USER32.@) @@ -436,14 +607,80 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, return 0; } - +DWORD WINAPI __pollInput(LPVOID hWnd) +{ + for(;;) + { + Sleep(1000/60); + TRACE("SendMessageW(%p,%d,%d,%d)\n", hWnd, WM_INPUT, RIM_INPUT, MOUSE_INPUT); + SendMessageW(hWnd, WM_INPUT, RIM_INPUT, MOUSE_INPUT); + } + return 0; +} /****************************************************************** * GetRegisteredRawInputDevices (USER32.@) */ UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize) { - FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize); + DWORD flags; + HWND hWnd; + + if(mouse_init) return FALSE; + + WARN("Only mouse is supported.\n"); + if(puiNumDevices != 1) + return FALSE; + if(pRawInputDevices->usUsagePage != 0x01 || pRawInputDevices->usUsage != 0x02) + return FALSE; + + TRACE("Get the window handle if we need to...\n"); + hWnd = pRawInputDevices->hwndTarget; + if(!hWnd) hWnd = GetActiveWindow(); + if(!hWnd) return FALSE; + + TRACE("Trying to map flags to DirectX...\n"); + flags = 0; + if(pRawInputDevices->dwFlags & RIDEV_INPUTSINK) + flags |= DISCL_BACKGROUND; + else + flags |= DISCL_FOREGROUND; + flags |= DISCL_NONEXCLUSIVE; + + TRACE("Init mouse\n"); + if (FAILED(DirectInput8Create(GetModuleHandleW(NULL), + DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&lpdi, NULL))) + { + ERR("DirectInput8Create failed.\n"); + return FALSE; + } + + if (FAILED(lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysMouse, &m_mouse, NULL))) + { + ERR("CreateDevice failed.\n"); + return FALSE; + } + + if (FAILED(m_mouse->lpVtbl->SetCooperativeLevel(m_mouse, hWnd, flags))) + { + ERR("SetCooperativeLevel failed.\n"); + return FALSE; + } + + if (FAILED(m_mouse->lpVtbl->SetDataFormat(m_mouse, &c_dfDIMouse2))) + { + ERR("SetDataFormat failed.\n"); + return FALSE; + } + + m_mouse->lpVtbl->Acquire(m_mouse); //OK if we don't acquire now + + if(!CreateThread(NULL, 0, __pollInput, hWnd, 0, NULL)) + { + ERR("Failed to CreateThread for __pollInput.\n"); + return FALSE; + } + mouse_init = TRUE; return 0; } diff --git a/include/winuser.h b/include/winuser.h index 9d07ef6..6554386 100644 --- a/include/winuser.h +++ b/include/winuser.h @@ -491,8 +491,8 @@ typedef struct tagRAWMOUSE { struct { USHORT usButtonFlags; USHORT usButtonData; - } DUMMYSTRUCTNAME; - } DUMMYUNIONNAME; + }; + }; ULONG ulRawButtons; LONG lLastX; LONG lLastY; == saved as mousePatch.patch I then run -patch -p0 < mousePatch.patch and the terminal produces: == Code: patching file b/dlls/user32/Makefile.in Hunk #1 FAILED at 1. 1 out of 1 hunk FAILED -- saving rejects to file b/dlls/user32/Makefile.in.rej patching file b/dlls/user32/input.c Hunk #1 FAILED at 22. Hunk #2 FAILED at 48. Hunk #3 FAILED at 384. Hunk #4 FAILED at 397. Hunk #5 FAILED at 436. 5 out of 5 hunks FAILED -- saving rejects to file b/dlls/user32/input.c.rej patching file b/include/winuser.h Hunk #1 FAILED at 491. 1 out of 1 hunk FAILED -- saving rejects to file b/include/winuser.h.rej rjd at 3246251196:~/Downloads$ wine -version wine: cannot find L"C:\\windows\\system32\\-version.exe" rjd at 3246251196:~/Downloads$ wine --version wine-1.3.15 == I have never applied a patch before, so I am very, very new to this. Sorry for the spam, but any help would be appreciated! == Ubuntu 10.10
3246251196
2011-Mar-15 00:20 UTC
[Wine] Re: HUNK #N Problems When Applying A Patch For Wine 1.3.15
I also tried -p1 in the command.
James McKenzie
2011-Mar-15 04:26 UTC
[Wine] HUNK #N Problems When Applying A Patch For Wine 1.3.15
On 3/14/11 5:13 PM, 3246251196 wrote:> Anarchy Online is running great through WINE. However, I need to apply this patch in order for the right mouse button to do extra functionality >You don't state what version the patch is for and yes -p1 was correct for using patch against patches created with git diff. Can you tell us where this patch is located? Is it in the Wine Bugzilla or in the Wine Applications Database? James McKenzie
3246251196
2011-Mar-15 23:02 UTC
[Wine] Re: HUNK #N Problems When Applying A Patch For Wine 1.3.15
http://bugs.winehq.org/show_bug.cgi?id=25654 I copy and paste the code from this patch into a new file, then name the file mousePatch.patch. This file is stored in my Downloads directory. This is the latest patch on there: 2011-03-05 12:12:26 CST (Comment 14); I have the latest version of AO, Ubuntu1010 and Wine 1.3.15; I do not know anything about patching and I have never done it before. People are claiming that this has solved there problems, and I have a feeling that I am doing something silly. Maybe I am trying to patch from the wrong directory. For instance, I cannot even find the DLLs folder it is talking about; I am still getting HUNK errors but still trying. Thankyou for your input so far, community! I am sure I will get there.
James McKenzie
2011-Mar-16 17:16 UTC
[Wine] HUNK #N Problems When Applying A Patch For Wine 1.3.15
On Tue, Mar 15, 2011 at 4:02 PM, 3246251196 <wineforum-user at winehq.org> wrote:> http://bugs.winehq.org/show_bug.cgi?id=25654 > > > I copy and paste the code from this patch into a new file, then name the file mousePatch.patch. This file is stored in my Downloads directory. This is > the latest patch on there: 2011-03-05 12:12:26 CST (Comment 14); I have the latest version of AO, Ubuntu1010 and Wine 1.3.15; > > I do not know anything about patching and I have never done it before. > > People are claiming that this has solved there problems, and I have a feeling that I am doing something silly. Maybe I am trying to patch from the > wrong directory. For instance, I cannot even find the DLLs folder it is talking about; > > I am still getting HUNK errors but still trying. > > Thank you for your input so far, community! I am sure I will get there. >Try following the instructions in the FAQ on building Wine from source and how to apply patches. http://wiki.winehq.org/FAQ#head-7ed3c3163e2b932ee2030a48f9c5e553dc41817b is where these instructions are located at. James McKenzie