From 769d163e4abe7a6770639df5a61b3e43fa07f69f Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Wed, 9 Dec 2020 23:39:01 +0600 Subject: [PATCH] Enabled player movement while the menu is open --- .gitignore | 1 + CheatMenu/CheatMenu.cpp | 49 +++-------------------------------------- CheatMenu/Hook.cpp | 36 ++++++++++++++++++++++++++++-- CheatMenu/Hook.h | 4 +++- CheatMenu/pch.cpp | 4 ---- CheatMenu/pch.h | 5 ----- 6 files changed, 41 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 6bd9e70..1f07415 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ moonloader/lib/cheat-menu/json/config.json /CheatMenu.VC.VC.opendb /CheatMenu.VC.db .vs/CheatMenu/v14/.suo +ipch/CHEATMENU.VCXPROJ-daebb660/CHEATMENU-7e055069.ipch diff --git a/CheatMenu/CheatMenu.cpp b/CheatMenu/CheatMenu.cpp index 14feef3..ebe9749 100644 --- a/CheatMenu/CheatMenu.cpp +++ b/CheatMenu/CheatMenu.cpp @@ -29,39 +29,11 @@ void CheatMenu::ProcessWindow() if (!FrontEndMenuManager.m_bMenuActive && (Globals::show_menu || Menu::commands::show_menu)) { - CPlayerPed* player = FindPlayerPed(); - CPad *pad = player->GetPadFromPlayer(); - pad->bPlayerSafe = 1; - if (Globals::show_menu) - { ProcessMenu(); - - if (Globals::show_menu) - patch::PutRetn(0x6194A0); - else - { - patch::SetUChar(0x6194A0, 0xE9); - pad->bPlayerSafe = 0; - } - - io.MouseDrawCursor = true; - } - else - { - io.MouseDrawCursor = false; - } - - if (Menu::commands::show_menu) - { + else Menu::ProcessShortcutsWindow(); - - if (!Menu::commands::show_menu) - pad->bPlayerSafe = 0; - } } - else - io.MouseDrawCursor = false; Menu::ProcessOverlay(); } @@ -83,7 +55,6 @@ CheatMenu::CheatMenu() Events::processScriptsEvent += [this] { - Hook::disable_controls = ImGui::GetIO().WantCaptureKeyboard || Menu::commands::show_menu; if (Globals::init_done && !FrontEndMenuManager.m_bMenuActive && CTimer::m_snTimeInMilliseconds - Globals::last_key_timer > 250) { @@ -93,30 +64,16 @@ CheatMenu::CheatMenu() if (Ui::HotKeyPressed(hotkey::menu_open)) { Globals::show_menu = !Globals::show_menu; - - if (Globals::show_menu) - Util::ClearCharTasksVehCheck(player); - - pad->bPlayerSafe = Globals::show_menu; Globals::last_key_timer = CTimer::m_snTimeInMilliseconds; } if (Ui::HotKeyPressed(hotkey::command_window)) { Menu::commands::show_menu = !Menu::commands::show_menu; - - if (Menu::commands::show_menu) - Util::ClearCharTasksVehCheck(player); - else - { - Menu::ProcessCommands(); - strcpy(Menu::commands::input_buffer, ""); - } - - pad->bPlayerSafe = Menu::commands::show_menu; - Globals::last_key_timer = CTimer::m_snTimeInMilliseconds; } + + Hook::show_mouse = Globals::show_menu || Menu::commands::show_menu; } }; diff --git a/CheatMenu/Hook.cpp b/CheatMenu/Hook.cpp index 82e942d..36ba14c 100644 --- a/CheatMenu/Hook.cpp +++ b/CheatMenu/Hook.cpp @@ -8,14 +8,16 @@ f_Reset Hook::oReset9 = NULL; f_Present11 Hook::oPresent11 = NULL; f_Present9 Hook::oPresent9 = NULL; -bool Hook::disable_controls = false; +bool Hook::mouse_visibility = false; +bool Hook::show_mouse = false; + std::function Hook::window_func = NULL; LRESULT Hook::InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); - if (disable_controls) + if (ImGui::GetIO().WantCaptureKeyboard) return 1; else return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam); @@ -34,6 +36,12 @@ HRESULT Hook::PresentDx9(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDe if (Globals::init_done) { + if (mouse_visibility != show_mouse) + { + Hook::ShowMouse(show_mouse); + mouse_visibility = show_mouse; + } + // Change font size if the game resolution changes if (Globals::font_screen_size.x != screen::GetScreenWidth() && Globals::font_screen_size.y != screen::GetScreenHeight()) @@ -143,6 +151,30 @@ HRESULT Hook::PresentDx11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl return oPresent11(pSwapChain, SyncInterval, Flags); } +void Hook::ShowMouse(bool state) +{ + if (state) + { + patch::PutRetn(0x6194A0); + patch::Nop(0x53F417, 5); // don't call CPad__getMouseState + patch::SetRaw(0x53F41F, "\x33\xC0\x0F\x84", 4); + } + else + { + patch::SetRaw(0x541DF5, "\xE8\x46\xF3\xFE\xFF", 5); // call CControllerConfigManager::AffectPadFromKeyBoard + patch::SetRaw(0x53F417, "\xE8\xB4\x7A\x20\x00", 5); // call CPad__getMouseState + patch::SetRaw(0x53F41F, "\x85\xC0\x0F\x8C", 4); // xor eax, eax -> test eax, eax + // jz loc_53F526 -> jl loc_53F526 + patch::SetUChar(0x6194A0, 0xE9); // jmp setup + } + + ImGui::GetIO().MouseDrawCursor = state; + CPad::NewMouseControllerState.X = 0; + CPad::NewMouseControllerState.Y = 0; + Call<0x541BD0>(); // CPad::ClearMouseHistory + Call<0x541DD0>(); // CPad::UpdatePads +} + Hook::Hook() { ImGui::CreateContext(); diff --git a/CheatMenu/Hook.h b/CheatMenu/Hook.h index 3d32f02..dc08cd6 100644 --- a/CheatMenu/Hook.h +++ b/CheatMenu/Hook.h @@ -13,6 +13,7 @@ private: static f_Reset oReset9; static f_Present11 oPresent11; static f_Present9 oPresent9; + static bool mouse_visibility; static HRESULT CALLBACK ResetDx9(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters); static HRESULT CALLBACK PresentDx9(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion); @@ -20,8 +21,9 @@ private: static LRESULT CALLBACK InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); protected: - static bool disable_controls; + static bool show_mouse; static std::function window_func; + static void ShowMouse(bool state); public: Hook(); diff --git a/CheatMenu/pch.cpp b/CheatMenu/pch.cpp index c87450d..b86bd2e 100644 --- a/CheatMenu/pch.cpp +++ b/CheatMenu/pch.cpp @@ -12,7 +12,3 @@ ID3D11Device *Globals::device11 = nullptr; CJson config = CJson("config", true); std::ofstream flog = std::ofstream("CheatMenu.log"); -// -//std::random_device rd; -//std::mt19937 gen(rd()); -//std::uniform_int_distribution<> cheat_id(0, 91); diff --git a/CheatMenu/pch.h b/CheatMenu/pch.h index 0ef19cd..108d0da 100644 --- a/CheatMenu/pch.h +++ b/CheatMenu/pch.h @@ -97,10 +97,5 @@ struct TextureStructure extern CJson config; extern std::ofstream flog; -// Random cheats -//extern std::random_device rd; -//extern std::mt19937 gen; -//extern std::uniform_int_distribution<> cheat_id; - #include "Ui.h" #include "Util.h" \ No newline at end of file