From f8634517779c1d7c865335f9790591b460bfbed4 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 20 Jun 2021 17:23:24 +0600 Subject: [PATCH] Bug fixes, removed silentpatch checks 1. Added a mouse fix ( no longer need silentpatch) 2. Fixed issues with the radio scroll --- CheatMenu/CheatMenu.cpp | 14 ++--- CheatMenu/Hook.cpp | 110 ++++++++++++++++++++++++++++++---------- CheatMenu/Hook.h | 4 +- CheatMenu/MenuInfo.h | 2 +- Depend/Depend.vcxproj | 2 +- README.md | 2 +- 6 files changed, 94 insertions(+), 40 deletions(-) diff --git a/CheatMenu/CheatMenu.cpp b/CheatMenu/CheatMenu.cpp index d211dc3..2cbb1de 100644 --- a/CheatMenu/CheatMenu.cpp +++ b/CheatMenu/CheatMenu.cpp @@ -159,15 +159,16 @@ void CheatMenu::ApplyStyle() void MenuThread(void* param) { - static bool game_init = false; + static bool bGameInit = false; + Hook::ApplyMouseFix(); // Wait till the game is initialized Events::initGameEvent += [] { - game_init = true; + bGameInit = true; }; - while (!game_init) + while (!bGameInit) Sleep(1000); if (GetModuleHandle("SAMP.dll")) @@ -176,13 +177,6 @@ void MenuThread(void* param) return; } - // SP fixes some mouse issues - if (!GetModuleHandle("SilentPatchSA.asi")) - { - MessageBox(RsGlobal.ps->window, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); - return; - } - flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl; CFastman92limitAdjuster::Init(); diff --git a/CheatMenu/Hook.cpp b/CheatMenu/Hook.cpp index 61093c2..88fcddf 100644 --- a/CheatMenu/Hook.cpp +++ b/CheatMenu/Hook.cpp @@ -146,44 +146,19 @@ HRESULT Hook::Dx11Handler(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl return oPresent11(pSwapChain, SyncInterval, Flags); } -// Thanks imring void Hook::ShowMouse(bool state) { - if (state) - { - CPad::NewMouseControllerState.X = 0; - CPad::NewMouseControllerState.Y = 0; - patch::SetUChar(0x6194A0, 0xC3); - - // Don't nop this, WindowedMode uses it - // patch::Nop(0x53F417, 5); // don't call CPad__getMouseState - patch::SetUChar(0x746ED0, 0xC3); - - patch::SetRaw(0x53F41F, (void*)"\x33\xC0\x0F\x84", 4); // disable camera mouse movement - } - else - { - if (m_bMouseVisibility != m_bShowMouse) - { - patch::SetUChar(0x6194A0, 0xE9); // jmp setup - patch::SetUChar(0x746ED0, 0xA1); - patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4); - // xor eax, eax -> test eax, eax , enable camera mouse movement - // jz loc_53F526 -> jl loc_53F526 - } - } - if (m_bMouseVisibility != m_bShowMouse) { CPad::ClearMouseHistory(); CPad::UpdatePads(); - // TODO: Replace this with windows cursor ImGui::GetIO().MouseDrawCursor = state; CPad::NewMouseControllerState.X = 0; CPad::NewMouseControllerState.Y = 0; m_bMouseVisibility = m_bShowMouse; + Hook::ApplyMouseFix(); // Reapply the patches } } @@ -216,3 +191,86 @@ Hook::~Hook() ImGui::DestroyContext(); kiero::shutdown(); } + +struct Mouse +{ + unsigned int x, y; + unsigned int wheelDelta; + char k1, k2, k3, k4, k5; +}; + +struct MouseInfo +{ + int x, y, wheelDelta; +} mouseInfo; + +static BOOL __stdcall _SetCursorPos(int X, int Y) +{ + if (Hook::m_bShowMouse || GetActiveWindow() != RsGlobal.ps->window) + return 1; + + mouseInfo.x = X; + mouseInfo.y = Y; + + return SetCursorPos(X, Y); +} + +int __cdecl _psMouseSetPos(RwV2d* pos) +{ + return _SetCursorPos(pos->x, pos->y); +} + +static LRESULT __stdcall _DispatchMessage(MSG* lpMsg) +{ + if (lpMsg->message == WM_MOUSEWHEEL && !Hook::m_bShowMouse) + { + mouseInfo.wheelDelta += *(int*)(&lpMsg->wParam); + } + + return DispatchMessageA(lpMsg); +} + +static int _cdecl _GetMouseState(Mouse* pMouse) +{ + if (Hook::m_bShowMouse) + return -1; + + 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 Hook::ApplyMouseFix() +{ + patch::ReplaceFunctionCall(0x53F417, _GetMouseState); + + patch::Nop(0x57C59B, 1); + patch::ReplaceFunctionCall(0x57C59C, _SetCursorPos); + patch::Nop(0x81E5D4, 1); + patch::ReplaceFunctionCall(0x81E5D5, _SetCursorPos); + patch::RedirectJump(0x6194A0, _psMouseSetPos); + + patch::Nop(0x748A7C, 1); + patch::ReplaceFunctionCall(0x748A7D, _DispatchMessage); + + patch::SetChar(0x746A08, 32); // diMouseOffset + patch::SetChar(0x746A58, 32); // diDeviceoffset +} diff --git a/CheatMenu/Hook.h b/CheatMenu/Hook.h index 16c922f..9a03b92 100644 --- a/CheatMenu/Hook.h +++ b/CheatMenu/Hook.h @@ -23,9 +23,11 @@ private: static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static void ShowMouse(bool state); -protected: +public: inline static bool m_bShowMouse = false; inline static std::function window_callback = nullptr; + static void ApplyMouseFix(); + Hook(); ~Hook(); }; diff --git a/CheatMenu/MenuInfo.h b/CheatMenu/MenuInfo.h index fd6b633..c74abc6 100644 --- a/CheatMenu/MenuInfo.h +++ b/CheatMenu/MenuInfo.h @@ -2,5 +2,5 @@ #define MENU_NAME "Cheat Menu" #define MENU_VERSION_NUMBER "2.7" #define MENU_VERSION MENU_VERSION_NUMBER"-beta" -#define BUILD_NUMBER "20210615" +#define BUILD_NUMBER "20210620" #define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" diff --git a/Depend/Depend.vcxproj b/Depend/Depend.vcxproj index 8d1c81f..1d8d92a 100644 --- a/Depend/Depend.vcxproj +++ b/Depend/Depend.vcxproj @@ -177,7 +177,7 @@ true - d3d9.lib;d3d11.lib;XInput9_1_0.lib + d3d9.lib;d3d11.lib diff --git a/README.md b/README.md index 95c6b32..d6a6e3a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Get stable binaries from [here](https://github.com/user-grinch/Cheat-Menu/releas 1. Install [DirectX9](https://www.microsoft.com/en-us/download/details.aspx?id=35) & [Visual C++ Redistributable 2019 x86](hhttps://aka.ms/vs/16/release/vc_redist.x86.exe) if not already installed. 2. If your game version isn't v1.0 then you'll need to [downgrade](https://gtaforums.com/topic/927016-san-andreas-downgrader/). -3. Install [asi loader](https://www.gtagarage.com/mods/show.php?id=21709) & [silent patch](https://gtaforums.com/topic/669045-silentpatch/) +3. Install [asi loader](https://www.gtagarage.com/mods/show.php?id=21709) 4. Download **CheatMenu.7z** and extract everything in game directory (replace if necessary). ## Building