From 68e63a7ccbda765b7037d59d128e08811384e9cc Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Fri, 11 Dec 2020 01:36:18 +0600 Subject: [PATCH] Refactored code, fixes --- .gitignore | 1 + CheatMenu/CheatMenu.cpp | 8 +++++--- CheatMenu/CheatMenu.h | 39 +++++++++++++++++++-------------------- CheatMenu/Hook.cpp | 5 +++++ CheatMenu/Vehicle.cpp | 17 ++++++++++++----- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 1f07415..608b26f 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ moonloader/lib/cheat-menu/json/config.json /CheatMenu.VC.db .vs/CheatMenu/v14/.suo ipch/CHEATMENU.VCXPROJ-daebb660/CHEATMENU-7e055069.ipch +/ipch/CHEATMENU.VCXPROJ-daebb660/CHEATMENU-ac659b63.ipch diff --git a/CheatMenu/CheatMenu.cpp b/CheatMenu/CheatMenu.cpp index ebe9749..30a28ec 100644 --- a/CheatMenu/CheatMenu.cpp +++ b/CheatMenu/CheatMenu.cpp @@ -58,9 +58,6 @@ CheatMenu::CheatMenu() if (Globals::init_done && !FrontEndMenuManager.m_bMenuActive && CTimer::m_snTimeInMilliseconds - Globals::last_key_timer > 250) { - CPlayerPed* player = FindPlayerPed(); - CPad *pad = player->GetPadFromPlayer(); - if (Ui::HotKeyPressed(hotkey::menu_open)) { Globals::show_menu = !Globals::show_menu; @@ -77,6 +74,11 @@ CheatMenu::CheatMenu() } }; + Events::drawMenuBackgroundEvent += [this] + { + Hook::show_mouse = false; + }; + Events::shutdownRwEvent += [] { // Save config data diff --git a/CheatMenu/CheatMenu.h b/CheatMenu/CheatMenu.h index 5af1f8b..6fd4746 100644 --- a/CheatMenu/CheatMenu.h +++ b/CheatMenu/CheatMenu.h @@ -34,28 +34,27 @@ class Launcher public: Launcher() { - bool launch = true; - - uint gameVersion = GetGameVersion(); - if (gameVersion != GAME_10US_HOODLUM && gameVersion != GAME_10US_COMPACT) { - MessageBox(HWND_DESKTOP, "CheatMenu requires v1.0 US of the game.", "CheatMenu", MB_ICONERROR); - flog << "Game version isn't 1.0" << std::endl; - launch = false; - } - else + Events::initRwEvent += []() { - Events::initRwEvent += [&launch]() - { - if (GetModuleHandleA("SAMP.dll")) { - MessageBox(HWND_DESKTOP, "SAMP detected. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); - flog << "SAMP detected. Exiting..." << std::endl; - launch = false; - } + bool launch = true; - if (launch) - static CheatMenu cheatmenu; - }; - } + uint gameVersion = GetGameVersion(); + if (gameVersion != GAME_10US_HOODLUM && gameVersion != GAME_10US_COMPACT) { + MessageBox(HWND_DESKTOP, "CheatMenu requires v1.0 US of the game.", "CheatMenu", MB_ICONERROR); + launch = false; + } + + if (GetModuleHandleA("SAMP.dll")) { + MessageBox(HWND_DESKTOP, "SAMP detected. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); + launch = false; + } + + if (launch) + { + flog << "Loading CheatMenu" << std::endl; + static CheatMenu cheatmenu; + } + }; } } launcher; diff --git a/CheatMenu/Hook.cpp b/CheatMenu/Hook.cpp index 36ba14c..fe592af 100644 --- a/CheatMenu/Hook.cpp +++ b/CheatMenu/Hook.cpp @@ -65,6 +65,7 @@ HRESULT Hook::PresentDx9(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDe ImGui::EndFrame(); ImGui::Render(); ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); + } else { @@ -121,6 +122,7 @@ HRESULT Hook::PresentDx11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl ImGui::EndFrame(); ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + } else { @@ -171,7 +173,10 @@ void Hook::ShowMouse(bool state) ImGui::GetIO().MouseDrawCursor = state; CPad::NewMouseControllerState.X = 0; CPad::NewMouseControllerState.Y = 0; + + // Broken in psdk Call<0x541BD0>(); // CPad::ClearMouseHistory + Call<0x53F1E0>(); // CPad::ClearKeyboardHistory Call<0x541DD0>(); // CPad::UpdatePads } diff --git a/CheatMenu/Vehicle.cpp b/CheatMenu/Vehicle.cpp index ec8c03e..d226454 100644 --- a/CheatMenu/Vehicle.cpp +++ b/CheatMenu/Vehicle.cpp @@ -474,18 +474,24 @@ void Vehicle::SpawnVehicle(std::string &smodel) if (spawner::license_text != "") Command(imodel, spawner::license_text); - if (!spawner::spawn_inside) - veh = CCheat::VehicleCheat(imodel); - else + if (spawner::spawn_inside) { int hveh = 0; - - Command(imodel, pos.x, pos.y, pos.z, &hveh); + Command(imodel, pos.x, pos.y, pos.z + 4.0f, &hveh); veh = CPools::GetVehicle(hveh); veh->SetHeading(player->GetHeading()); Command(hplayer, hveh); Command(hveh, speed); } + else + { + int hveh = 0; + player->TransformFromObjectSpace(pos, CVector(0, 10, 0)); + + Command(imodel, pos.x, pos.y, pos.z + 4.0f, &hveh); + veh = CPools::GetVehicle(hveh); + veh->SetHeading(player->GetHeading()+55.0f); + } CStreaming::SetModelIsDeletable(imodel); } @@ -830,6 +836,7 @@ void Vehicle::Main() ImGui::NextColumn(); Ui::CheckboxWithHint("Spawn aircraft in air", &spawner::spawn_in_air); ImGui::Columns(1); + ImGui::Spacing(); ImGui::SetNextItemWidth(ImGui::GetWindowContentRegionWidth() - 2.5);