From 3e51f2ff1bf0384347133958694547bf2b92c4d5 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Thu, 14 Jan 2021 00:25:28 +0600 Subject: [PATCH] Bug fixes 1. Fixed teleport & animation changes not being saved 2. Fixed crash with renderhook 3. Refactored code --- .vscode/c_cpp_properties.json | 1 + src/Animation.cpp | 1 + src/CheatMenu.h | 1 - src/Game.cpp | 5 +++-- src/Hook.cpp | 21 ++++++++++++++------- src/Hook.h | 4 +++- src/MenuInfo.h | 2 +- src/Player.cpp | 8 ++++---- src/Teleport.cpp | 1 + src/Vehicle.cpp | 2 +- 10 files changed, 29 insertions(+), 17 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 655de58..79c095a 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -5,6 +5,7 @@ "includePath": [ "${workspaceFolder}/src/", "${DIRECTX9_SDK_DIR}/Include", + "C:/Program Files (x86)/DirectXSDK/Include", "${PLUGIN_SDK_DIR}/plugin_sa", "${PLUGIN_SDK_DIR}/plugin_sa/game_sa", "${PLUGIN_SDK_DIR}/shared", diff --git a/src/Animation.cpp b/src/Animation.cpp index 7da422a..84b9ab4 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -138,6 +138,7 @@ void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string if (ifp == "Custom") { json.data["Custom"].erase(anim); + json.WriteToDisk(); CHud::SetHelpMessage("Animation removed", false, false, false); }else CHud::SetHelpMessage("You can only remove custom anims", false, false, false); diff --git a/src/CheatMenu.h b/src/CheatMenu.h index 3871c4c..8653efc 100644 --- a/src/CheatMenu.h +++ b/src/CheatMenu.h @@ -39,7 +39,6 @@ public: Events::initRwEvent += []() { 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); diff --git a/src/Game.cpp b/src/Game.cpp index dff10a1..a3c467b 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -287,7 +287,7 @@ void Game::Main() Ui::CheckboxAddress("Faster clock", 0x96913B); - if (Ui::CheckboxWithHint("Forbidden area wl", &forbidden_area_wl, "Wanted levels that appears outside\ + if (Ui::CheckboxWithHint("Forbidden area wl", &forbidden_area_wl, "Wanted levels that appears outside \ of LS without completing missions")) { if (forbidden_area_wl) @@ -308,7 +308,8 @@ of LS without completing missions")) Command(keep_stuff); Command(keep_stuff); } - Ui::CheckboxWithHint("Screenshot shortcut", &ss_shortcut, (("Take screenshot using ") + Ui::GetHotKeyNameString(Menu::hotkey::quick_ss)).c_str()); + Ui::CheckboxWithHint("Screenshot shortcut", &ss_shortcut, (("Take screenshot using ") + Ui::GetHotKeyNameString(Menu::hotkey::quick_ss) + + "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str()); if (Ui::CheckboxWithHint("Solid water", &solid_water, "Player can walk on water")) { if (!solid_water && solid_water_object != 0) diff --git a/src/Hook.cpp b/src/Hook.cpp index bbe3438..6399901 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -41,7 +41,7 @@ HRESULT Hook::Reset(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS * pPresent return oReset9(pDevice, pPresentationParameters); } -HRESULT Hook::Present(void *ptr, int u1, int u2, int u3, int u4) +void Hook::Present(void *ptr) { ImGuiIO& io = ImGui::GetIO(); @@ -121,11 +121,18 @@ HRESULT Hook::Present(void *ptr, int u1, int u2, int u3, int u4) style.WindowTitleAlign = ImVec2(0.5, 0.5); oWndProc = (WNDPROC)SetWindowLongPtr(RsGlobal.ps->window, GWL_WNDPROC, (LRESULT)InputProc); } +} - if (Globals::renderer == Render_DirectX9) - return oPresent9((IDirect3DDevice9*)ptr, (RECT*)u1, (RECT*)u2, (HWND)u3, (RGNDATA*)u4); - else - return oPresent11((IDXGISwapChain*)ptr, u1, u2); +HRESULT Hook::PresentDx9Handler(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion) +{ + Present(pDevice); + return oPresent9(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);; +} + +HRESULT Hook::PresentDx11Handler(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) +{ + Present(pSwapChain); + return oPresent11(pSwapChain, SyncInterval, Flags); } // Thanks imring @@ -164,7 +171,7 @@ Hook::Hook() { Globals::renderer = Render_DirectX9; if (kiero::bind(16, (void**)&oReset9, Reset) == kiero::Status::Success - && kiero::bind(17, (void**)&oPresent9, Present) == kiero::Status::Success) + && kiero::bind(17, (void**)&oPresent9, PresentDx9Handler) == kiero::Status::Success) flog << "Successfully hooked dx9 device." << std::endl; } else @@ -173,7 +180,7 @@ Hook::Hook() if (kiero::init(kiero::RenderType::D3D11) == kiero::Status::Success) { Globals::renderer = Render_DirectX11; - if (kiero::bind(8, (void**)&oPresent11, Present) == kiero::Status::Success) + if (kiero::bind(8, (void**)&oPresent11, PresentDx11Handler) == kiero::Status::Success) flog << "Successfully hooked dx11 device." << std::endl; } else diff --git a/src/Hook.h b/src/Hook.h index 12a8c43..93d9741 100644 --- a/src/Hook.h +++ b/src/Hook.h @@ -15,7 +15,9 @@ private: static f_Reset oReset9; static bool mouse_visibility; - static HRESULT CALLBACK Present(void *ptr, int u1, int u2, int u3 = NULL, int u4 = NULL); + static void CALLBACK Present(void *ptr); + static HRESULT CALLBACK PresentDx9Handler(IDirect3DDevice9 *pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion); + static HRESULT CALLBACK PresentDx11Handler(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags); static HRESULT CALLBACK Reset(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS * pPresentationParameters); static LRESULT CALLBACK InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static void ShowMouse(bool state); diff --git a/src/MenuInfo.h b/src/MenuInfo.h index 462bce8..384bc18 100644 --- a/src/MenuInfo.h +++ b/src/MenuInfo.h @@ -1,5 +1,5 @@ #pragma once #define MENU_NAME "Cheat Menu" #define MENU_VERSION "2.5-beta" -#define BUILD_NUMBER "20210110" +#define BUILD_NUMBER "20210114" #define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" \ No newline at end of file diff --git a/src/Player.cpp b/src/Player.cpp index 3820a86..54d1bdf 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -303,22 +303,22 @@ void Player::Main() if (ImGui::CollapsingHeader("Wanted level")) { int val = player->m_pPlayerData->m_pWanted->m_nWantedLevel; + int max_wl = player->m_pPlayerData->m_pWanted->MaximumWantedLevel; ImGui::Columns(3, 0, false); ImGui::Text("Min: 0"); ImGui::NextColumn(); ImGui::Text("Def: 0"); ImGui::NextColumn(); - ImGui::Text("Max: 6"); + ImGui::Text("Max: %d",max_wl); ImGui::Columns(1); ImGui::Spacing(); if (ImGui::InputInt("Set value##Wanted level", &val)) player->CheatWantedLevel(val); - + ImGui::Spacing(); - if (ImGui::Button("Minimum##Wanted level", Ui::GetSize(3))) player->CheatWantedLevel(0); @@ -330,7 +330,7 @@ void Player::Main() ImGui::SameLine(); if (ImGui::Button("Maximum##Wanted level", Ui::GetSize(3))) - player->CheatWantedLevel(6); + player->CheatWantedLevel(max_wl); ImGui::Spacing(); ImGui::Separator(); diff --git a/src/Teleport.cpp b/src/Teleport.cpp index c1fd612..f2be523 100644 --- a/src/Teleport.cpp +++ b/src/Teleport.cpp @@ -176,6 +176,7 @@ void Teleport::RemoveTeleportEntry(std::string& category, std::string& key, std: { json.data["Custom"].erase(key); CHud::SetHelpMessage("Location removed", false, false, false); + json.WriteToDisk(); } else CHud::SetHelpMessage("You can only remove custom location", false, false, false); } diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index 93cf8a0..0b020aa 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -187,7 +187,7 @@ void Vehicle::AddComponent(const std::string& component, const bool display_mess int hveh = CPools::GetVehicleRef(player->m_pVehicle); CStreaming::RequestModel(icomp,eStreamingFlags::PRIORITY_REQUEST); - CStreaming::LoadAllRequestedModels(false); + CStreaming::LoadAllRequestedModels(true); player->m_pVehicle->AddVehicleUpgrade(icomp); CStreaming::SetModelIsDeletable(icomp);