Enabled player movement while the menu is open

This commit is contained in:
Grinch_ 2020-12-09 23:39:01 +06:00
parent bbbd30b8b1
commit 769d163e4a
6 changed files with 41 additions and 58 deletions

1
.gitignore vendored
View File

@ -42,3 +42,4 @@ moonloader/lib/cheat-menu/json/config.json
/CheatMenu.VC.VC.opendb /CheatMenu.VC.VC.opendb
/CheatMenu.VC.db /CheatMenu.VC.db
.vs/CheatMenu/v14/.suo .vs/CheatMenu/v14/.suo
ipch/CHEATMENU.VCXPROJ-daebb660/CHEATMENU-7e055069.ipch

View File

@ -29,39 +29,11 @@ void CheatMenu::ProcessWindow()
if (!FrontEndMenuManager.m_bMenuActive && (Globals::show_menu || Menu::commands::show_menu)) 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) if (Globals::show_menu)
{
ProcessMenu(); ProcessMenu();
else
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)
{
Menu::ProcessShortcutsWindow(); Menu::ProcessShortcutsWindow();
if (!Menu::commands::show_menu)
pad->bPlayerSafe = 0;
}
} }
else
io.MouseDrawCursor = false;
Menu::ProcessOverlay(); Menu::ProcessOverlay();
} }
@ -83,7 +55,6 @@ CheatMenu::CheatMenu()
Events::processScriptsEvent += [this] 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) 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)) if (Ui::HotKeyPressed(hotkey::menu_open))
{ {
Globals::show_menu = !Globals::show_menu; 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; Globals::last_key_timer = CTimer::m_snTimeInMilliseconds;
} }
if (Ui::HotKeyPressed(hotkey::command_window)) if (Ui::HotKeyPressed(hotkey::command_window))
{ {
Menu::commands::show_menu = !Menu::commands::show_menu; 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; Globals::last_key_timer = CTimer::m_snTimeInMilliseconds;
} }
Hook::show_mouse = Globals::show_menu || Menu::commands::show_menu;
} }
}; };

View File

@ -8,14 +8,16 @@ f_Reset Hook::oReset9 = NULL;
f_Present11 Hook::oPresent11 = NULL; f_Present11 Hook::oPresent11 = NULL;
f_Present9 Hook::oPresent9 = NULL; f_Present9 Hook::oPresent9 = NULL;
bool Hook::disable_controls = false; bool Hook::mouse_visibility = false;
bool Hook::show_mouse = false;
std::function<void()> Hook::window_func = NULL; std::function<void()> Hook::window_func = NULL;
LRESULT Hook::InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT Hook::InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);
if (disable_controls) if (ImGui::GetIO().WantCaptureKeyboard)
return 1; return 1;
else else
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam); 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 (Globals::init_done)
{ {
if (mouse_visibility != show_mouse)
{
Hook::ShowMouse(show_mouse);
mouse_visibility = show_mouse;
}
// Change font size if the game resolution changes // Change font size if the game resolution changes
if (Globals::font_screen_size.x != screen::GetScreenWidth() if (Globals::font_screen_size.x != screen::GetScreenWidth()
&& Globals::font_screen_size.y != screen::GetScreenHeight()) && 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); 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() Hook::Hook()
{ {
ImGui::CreateContext(); ImGui::CreateContext();

View File

@ -13,6 +13,7 @@ private:
static f_Reset oReset9; static f_Reset oReset9;
static f_Present11 oPresent11; static f_Present11 oPresent11;
static f_Present9 oPresent9; static f_Present9 oPresent9;
static bool mouse_visibility;
static HRESULT CALLBACK ResetDx9(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters); static HRESULT CALLBACK ResetDx9(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
static HRESULT CALLBACK PresentDx9(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion); 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); static LRESULT CALLBACK InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
protected: protected:
static bool disable_controls; static bool show_mouse;
static std::function<void()> window_func; static std::function<void()> window_func;
static void ShowMouse(bool state);
public: public:
Hook(); Hook();

View File

@ -12,7 +12,3 @@ ID3D11Device *Globals::device11 = nullptr;
CJson config = CJson("config", true); CJson config = CJson("config", true);
std::ofstream flog = std::ofstream("CheatMenu.log"); std::ofstream flog = std::ofstream("CheatMenu.log");
//
//std::random_device rd;
//std::mt19937 gen(rd());
//std::uniform_int_distribution<> cheat_id(0, 91);

View File

@ -97,10 +97,5 @@ struct TextureStructure
extern CJson config; extern CJson config;
extern std::ofstream flog; 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 "Ui.h"
#include "Util.h" #include "Util.h"