Created
June 20, 2021 08:29
-
-
Save user-grinch/399ba5bba1580ab9e60f0e70fa44f4e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "plugin.h" | |
| #include <iostream> | |
| using namespace plugin; | |
| struct Mouse | |
| { | |
| unsigned int x, y; | |
| unsigned int wheelDelta; | |
| char k1, k2, k3, k4, k5; | |
| }; | |
| struct MouseInfo | |
| { | |
| int x, y, wheelDelta; | |
| } mouseInfo; | |
| BOOL __stdcall _SetCursorPos(int X, int Y) | |
| { | |
| mouseInfo.x = X; | |
| mouseInfo.y = Y; | |
| return SetCursorPos(X, Y); | |
| } | |
| LRESULT __stdcall _DispatchMessage(MSG* lpMsg) | |
| { | |
| if (lpMsg->message == WM_MOUSEWHEEL) | |
| { | |
| mouseInfo.wheelDelta += *(int*)(&lpMsg->wParam); | |
| } | |
| return DispatchMessageA(lpMsg); | |
| } | |
| int _cdecl ProcessMouse(Mouse* pMouse) | |
| { | |
| struct tagPOINT Point; | |
| pMouse->x = 0; | |
| pMouse->y = 0; | |
| pMouse->wheelDelta = mouseInfo.wheelDelta; | |
| GetCursorPos(&Point); | |
| if (mouseInfo.x >= 0) | |
| pMouse->x = int(Point.x - mouseInfo.x); | |
| if (mouseInfo.y >= 0) | |
| pMouse->y = int(Point.y - mouseInfo.y); | |
| mouseInfo.wheelDelta = 0; | |
| pMouse->k1 = (GetAsyncKeyState(1) >> 8); | |
| pMouse->k2 = (GetAsyncKeyState(2) >> 8); | |
| pMouse->k3 = (GetAsyncKeyState(4) >> 8); | |
| pMouse->k4 = (GetAsyncKeyState(5) >> 8); | |
| pMouse->k5 = (GetAsyncKeyState(6) >> 8); | |
| return 0; | |
| } | |
| void ApplyMouseFix() | |
| { | |
| char mouseState = patch::Get<BYTE>(0x53F417, true); | |
| if (mouseState == -24) | |
| { | |
| patch::ReplaceFunctionCall(0x53F417, ProcessMouse); | |
| } | |
| char cursorPos = patch::GetChar(0x57C59B); | |
| if (cursorPos == -1) | |
| { | |
| patch::Nop(0x57C59B, 1); | |
| patch::ReplaceFunctionCall(0x57C59C, _SetCursorPos); | |
| } | |
| char msgDispatch = patch::GetChar(0x748A7C); | |
| if (msgDispatch == -1) | |
| { | |
| patch::Nop(0x748A7C, 1); | |
| patch::ReplaceFunctionCall(0x748A7D, _DispatchMessage); | |
| } | |
| char diMouseOffset = patch::GetChar(0x746A08); | |
| if (diMouseOffset == 28) | |
| { | |
| patch::SetChar(0x746A08, 32); | |
| } | |
| char diDeviceoffset = patch::GetChar(0x746A58); | |
| if (diDeviceoffset == 28) | |
| { | |
| patch::SetChar(0x746A58, 32); | |
| } | |
| } | |
| BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) | |
| { | |
| switch (fdwReason) | |
| { | |
| case DLL_PROCESS_ATTACH: | |
| ApplyMouseFix(); | |
| } | |
| return TRUE; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment