[Wine] HUNK #N Problems When Applying A Patch For Wine 1.3.15

3246251196 wineforum-user at winehq.org
Mon Mar 14 19:13:44 CDT 2011


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







More information about the wine-users mailing list