diff --git a/src/Animation.h b/src/Animation.h index 79e9b22..02c9600 100644 --- a/src/Animation.h +++ b/src/Animation.h @@ -22,7 +22,6 @@ private: protected: Animation(); - ~Animation() {}; public: static void Draw(); diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index 72e225d..621cb8d 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -22,33 +22,9 @@ void CheatMenu::DrawWindow() ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200)); if (Updater::state == UPDATER_UPDATE_FOUND) - { - ImGui::Button("New version is available",Ui::GetSize()); - - if (ImGui::Button("Changelog",Ui::GetSize(3))) - ShellExecute(NULL, "open", - std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" + - Updater::latest_version).c_str(), NULL, NULL, SW_SHOWNORMAL); - - ImGui::SameLine(); - if (ImGui::Button("Download",Ui::GetSize(3))) - Updater::state = UPDATER_DOWNLOADING; - - ImGui::SameLine(); - if (ImGui::Button("Hide",Ui::GetSize(3))) - Updater::state = UPDATER_IDLE; - } - - if (Updater::state == UPDATER_DOWNLOADING) - ImGui::Button("Downloading update...",Ui::GetSize()); - - if (Updater::state == UPDATER_DOWNLOADED) - { - if (ImGui::Button("Update downloaded. Click to install.",Ui::GetSize())) - Updater::state = UPDATER_INSTALLING; - } - - Ui::DrawHeaders(header); + Updater::ShowUpdateScreen(); + else + Ui::DrawHeaders(header); Globals::menu_size = ImGui::GetWindowSize(); config.SetValue("window.sizeX", Globals::menu_size.x); @@ -216,44 +192,47 @@ void MenuThread(void* param) flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl; CFastman92limitAdjuster::Init(); CheatMenu *menu = new CheatMenu; - + Updater::CheckForUpdate(); + while (true) { - Sleep(100); - if (KeyPressed(VK_LSHIFT) && KeyPressed(VK_BACK)) - break; + Sleep(5000); + // if (KeyPressed(VK_LSHIFT) && KeyPressed(VK_BACK)) + // break; if (Updater::state == UPDATER_CHECKING) Updater::CheckForUpdate(); - if (Updater::state == UPDATER_DOWNLOADING) - Updater::DownloadUpdate(); + // if (Updater::state == UPDATER_DOWNLOADING) + // Updater::DownloadUpdate(); - if (Updater::state == UPDATER_INSTALLING) - { - Updater::InstallUpdate(); - break; - } + // if (Updater::state == UPDATER_INSTALLING) + // { + // Updater::InstallUpdate(); + // break; + // } } - delete menu; + // Globals::menu_closing = true; + // Sleep(500); + // delete menu; - // reset mouse patches - patch::SetUChar(0x6194A0, 0xE9); - patch::SetUChar(0x746ED0, 0xA1); - patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4); + // // reset mouse patches + // patch::SetUChar(0x6194A0, 0xE9); + // patch::SetUChar(0x746ED0, 0xA1); + // patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4); - if (Updater::state == UPDATER_INSTALLING) - { - CHud::SetHelpMessage("Install complete, restarting menu!",false,false,false); - Updater::FinishUpdate(); - } - else - { - CHud::SetHelpMessage("CheatMenu unloaded",false,false,false); - FreeLibraryAndExitThread(GetModuleHandle("CheatMenu.asi"),0); - FreeLibraryAndExitThread(GetModuleHandle("CheatMenuNew.asi"),0); - } + // if (Updater::state == UPDATER_INSTALLING) + // { + // CHud::SetHelpMessage("Install complete, restarting menu!",false,false,false); + // Updater::FinishUpdate(); + // } + // else + // { + // CHud::SetHelpMessage("CheatMenu unloaded",false,false,false); + // FreeLibraryAndExitThread(GetModuleHandle("CheatMenu.asi"),0); + // FreeLibraryAndExitThread(GetModuleHandle("CheatMenuNew.asi"),0); + // } } BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) diff --git a/src/Hook.cpp b/src/Hook.cpp index 8ad70da..e8e52a9 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -35,7 +35,7 @@ HRESULT Hook::Reset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentat void Hook::Present(void* ptr) { - if (!ImGui::GetCurrentContext()) + if (!ImGui::GetCurrentContext() || Globals::menu_closing) return; ImGuiIO& io = ImGui::GetIO(); diff --git a/src/Json.h b/src/Json.h index bd3287a..e78d6fe 100644 --- a/src/Json.h +++ b/src/Json.h @@ -1,5 +1,5 @@ #pragma once -#include "json.hpp" +#include "../deps/json.hpp" class CJson { diff --git a/src/MenuInfo.h b/src/MenuInfo.h index 610fa40..c6e0e69 100644 --- a/src/MenuInfo.h +++ b/src/MenuInfo.h @@ -1,6 +1,6 @@ #pragma once #define MENU_NAME "Cheat Menu" -#define MENU_VERSION_NUMBER "2.4" +#define MENU_VERSION_NUMBER "2.3" #define MENU_VERSION MENU_VERSION_NUMBER"-beta" #define BUILD_NUMBER "20210311" #define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" \ No newline at end of file diff --git a/src/Neon.cpp b/src/Neon.cpp index 643dd38..69be9b4 100644 --- a/src/Neon.cpp +++ b/src/Neon.cpp @@ -46,7 +46,12 @@ Neon::Neon() Neon::~Neon() { Events::vehicleRenderEvent -= RenderEvent; - RwTextureDestroy(neon_texture); + + if (neon_texture) + { + RwTextureDestroy(neon_texture); + neon_texture = nullptr; + } } bool Neon::IsNeonInstalled(CVehicle* pVeh) diff --git a/src/Ped.cpp b/src/Ped.cpp index 6ad3439..6469129 100644 --- a/src/Ped.cpp +++ b/src/Ped.cpp @@ -20,6 +20,7 @@ Ped::Ped() Ped::~Ped() { + Util::ReleaseTextures(peds_vec); for (CPed* ped : spawn_ped::list) { CWorld::Remove(ped); diff --git a/src/Player.cpp b/src/Player.cpp index aea3e0e..2188ade 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -116,6 +116,11 @@ Player::Player() }; } +Player::~Player() +{ + Util::ReleaseTextures(clothes_vec); +} + void Player::ChangePlayerCloth(std::string& name) { std::stringstream ss(name); diff --git a/src/Player.h b/src/Player.h index 094e9e3..adf27a6 100644 --- a/src/Player.h +++ b/src/Player.h @@ -26,6 +26,7 @@ private: public: Player(); + ~Player(); static void ChangePlayerCloth(std::string& model); static void ChangePlayerModel(std::string& model); static void Draw(); diff --git a/src/Updater.cpp b/src/Updater.cpp index 5665e0c..bd299c0 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -1,5 +1,6 @@ #include "Updater.h" #include "pch.h" +#include "Ui.h" #include "MenuInfo.h" #include "..\deps\zip\zip.h" @@ -31,59 +32,92 @@ void Updater::CheckForUpdate() } } -void Updater::DownloadUpdate() -{ - std::string link = "https://github.com/user-grinch/Cheat-Menu/releases/download/" + latest_version + "/CheatMenu.zip"; - char* path = PLUGIN_PATH((char*)"update.zip"); - HRESULT res = URLDownloadToFile(NULL, link.c_str(), path, 0, NULL); +// void Updater::DownloadUpdate() +// { +// std::string link = "https://github.com/user-grinch/Cheat-Menu/releases/download/" + latest_version + "/CheatMenu.zip"; +// char* path = PLUGIN_PATH((char*)"update.zip"); +// HRESULT res = S_OK;//URLDownloadToFile(NULL, link.c_str(), path, 0, NULL); - if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE) - { - CHud::SetHelpMessage("Failed download update",false,false,false); - state = UPDATER_IDLE; - return; - } - CHud::SetHelpMessage("Update downloaded successfully.",false,false,false); - state = UPDATER_DOWNLOADED; -} +// if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE) +// { +// CHud::SetHelpMessage("Failed download update",false,false,false); +// state = UPDATER_IDLE; +// return; +// } +// CHud::SetHelpMessage("Update downloaded successfully.",false,false,false); +// state = UPDATER_DOWNLOADED; +// } -void Updater::InstallUpdate() -{ - CHud::SetHelpMessage("Updating in progress. Do not pause/close the game.",false,false,false); - Sleep(100); - // delete the old menu - std::remove(PLUGIN_PATH((char*)"CheatMenu.asi.old")); - std::string new_name = PLUGIN_PATH((char*)"CheatMenu.asi.old"); - std::string old_name = PLUGIN_PATH((char*)"CheatMenu.asi"); - std::rename(old_name.c_str(),new_name.c_str()); - fs::remove_all(PLUGIN_PATH((char*)"CheatMenu")); +// void Updater::InstallUpdate() +// { +// CHud::SetHelpMessage("Update in progress. Do not pause/close the game.",false,false,false); +// Sleep(100); +// // delete the old menu +// std::remove(PLUGIN_PATH((char*)"CheatMenu.asi.old")); +// std::string new_name = PLUGIN_PATH((char*)"CheatMenu.asi.old"); +// std::string old_name = PLUGIN_PATH((char*)"CheatMenu.asi"); +// std::rename(old_name.c_str(),new_name.c_str()); +// fs::remove_all(PLUGIN_PATH((char*)"CheatMenu")); - std::string dir = PLUGIN_PATH((char*)""); - std::string file = PLUGIN_PATH((char*)"update.zip"); - zip_extract(file.c_str(),dir.c_str(),NULL,NULL); -} +// std::string dir = PLUGIN_PATH((char*)""); +// std::string file = PLUGIN_PATH((char*)"update.zip"); +// zip_extract(file.c_str(),dir.c_str(),NULL,NULL); +// } -static bool menu_loaded = false; -static void LoadUpdatedMenu() -{ - std::string new_name = PLUGIN_PATH((char*)"CheatMenuNew.asi"); - LoadLibrary(new_name.c_str()); - menu_loaded = true; -} +// static bool menu_loaded = false; +// static void LoadUpdatedMenu() +// { +// std::string new_name = PLUGIN_PATH((char*)"CheatMenuNew.asi"); +// LoadLibrary(new_name.c_str()); +// menu_loaded = true; +// } -void Updater::FinishUpdate() -{ - // kinda hacky - std::string new_name = PLUGIN_PATH((char*)"CheatMenuNew.asi"); - std::string old_name = PLUGIN_PATH((char*)"CheatMenu.asi"); - std::rename(old_name.c_str(),new_name.c_str()); +// void Updater::FinishUpdate() +// { +// // kinda hacky, can't update twice on same instance ( should be unlikely anyways?) +// std::string new_name = PLUGIN_PATH((char*)"CheatMenuNew.asi"); +// std::string old_name = PLUGIN_PATH((char*)"CheatMenu.asi"); +// std::rename(old_name.c_str(),new_name.c_str()); - Events::processScriptsEvent += LoadUpdatedMenu; +// Events::processScriptsEvent += LoadUpdatedMenu; - while (!menu_loaded) - Sleep(1000); +// while (!menu_loaded) +// Sleep(1000); - Events::processScriptsEvent -= LoadUpdatedMenu; +// Events::processScriptsEvent -= LoadUpdatedMenu; - std::rename(new_name.c_str(),old_name.c_str()); +// std::rename(new_name.c_str(),old_name.c_str()); +// } + +void Updater::ShowUpdateScreen() +{ + ImGui::Dummy(ImVec2(0,20)); + Ui::CenterdText("A new version of the mod is available."); + Ui::CenterdText(std::string("Current version: ") + MENU_VERSION); + Ui::CenterdText("Latest version: " + Updater::latest_version); + ImGui::Dummy(ImVec2(0,10)); + ImGui::TextWrapped("In order to keep using the menu, you need to update to the latest version." + " This is to ensure everything is using the most up-to-date version."); + ImGui::Dummy(ImVec2(0,10)); + ImGui::TextWrapped("To know what changes are made or to download, click on the \"Download page\" button." + " Follow the instructions there. If you're still having issues, let me know on discord."); + + ImGui::Dummy(ImVec2(0,5)); + if (ImGui::Button("Discord server", ImVec2(Ui::GetSize(2)))) + ShellExecute(NULL, "open", DISCORD_INVITE, NULL, NULL, SW_SHOWNORMAL); + + ImGui::SameLine(); + + if (ImGui::Button("Download page",Ui::GetSize(2))) + ShellExecute(NULL, "open", std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" + + Updater::latest_version).c_str(), NULL, NULL, SW_SHOWNORMAL); + + // if (Updater::state == UPDATER_DOWNLOADING) + // ImGui::Button("Downloading update...",Ui::GetSize()); + + // if (Updater::state == UPDATER_DOWNLOADED) + // { + // if (ImGui::Button("Update downloaded. Click to install.",Ui::GetSize())) + // Updater::state = UPDATER_INSTALLING; + // } } \ No newline at end of file diff --git a/src/Updater.h b/src/Updater.h index 84b833a..a8dea46 100644 --- a/src/Updater.h +++ b/src/Updater.h @@ -15,9 +15,10 @@ class Updater public: inline static UPDATER_STATE state = UPDATER_IDLE; inline static std::string latest_version = ""; - // TODO: fix memory leak + static void CheckForUpdate(); - static void DownloadUpdate(); - static void InstallUpdate(); - static void FinishUpdate(); + // static void DownloadUpdate(); + // static void InstallUpdate(); + // static void FinishUpdate(); + static void ShowUpdateScreen(); }; diff --git a/src/Util.cpp b/src/Util.cpp index c456397..11c8abb 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1,6 +1,6 @@ #include "pch.h" #include "Util.h" -#include "imgui/stb_image.h" +#include "../deps/imgui/stb_image.h" void Util::ClearCharTasksVehCheck(CPed* ped) { @@ -23,6 +23,20 @@ void Util::ClearCharTasksVehCheck(CPed* ped) } } +void Util::ReleaseTextures(std::vector> &store_vec) +{ + // for (auto &it : store_vec) + // { + // if (Globals::renderer == Render_DirectX9) + // { + // reinterpret_cast(it->texture)->Release(); + // it->texture = nullptr; + // } + // else + // reinterpret_cast(it->texture)->Release(); + // } +} + void Util::LoadTexturesInDirRecursive(const char* path, const char* file_ext, std::vector& category_vec, std::vector>& store_vec) { std::string folder = ""; @@ -32,10 +46,10 @@ void Util::LoadTexturesInDirRecursive(const char* path, const char* file_ext, st { store_vec.push_back(std::make_unique()); HRESULT hr = -1; + if (Globals::renderer == Render_DirectX9) hr = D3DXCreateTextureFromFileA(GetD3DDevice(), p.path().string().c_str(), reinterpret_cast(&store_vec.back().get()->texture)); - - if (Globals::renderer == Render_DirectX11) + else { if (LoadTextureFromFileDx11(p.path().string().c_str(), reinterpret_cast(&store_vec.back().get()->texture))) hr = S_OK; @@ -236,11 +250,4 @@ RwTexture* Util::LoadTextureFromPngFile(fs::path path) RwTexture* texture = CreateRwTextureFromRwImage(image); path.stem().string().copy(texture->name, sizeof(texture->name) - 1); return texture; -} - -void Util::UnloadTexture(RwTexture* texture) -{ - if (!texture) - return; - RwTextureDestroy(texture); } \ No newline at end of file diff --git a/src/Util.h b/src/Util.h index ace8d36..a006ed9 100644 --- a/src/Util.h +++ b/src/Util.h @@ -11,10 +11,10 @@ public: static CVehicle *GetClosestVehicle(); static int GetLargestGangInZone(); static void LoadTexturesInDirRecursive(const char * path, const char * file_ext, std::vector& category_vec, std::vector> &store_vec); + static void ReleaseTextures(std::vector> &store_vec); static bool IsOnMission(); static std::string GetLocationName(CVector *pos); static void RainbowValues(int &r, int&g, int &b, float speed); static RwTexture* LoadTextureFromPngFile(fs::path path); - static void UnloadTexture(RwTexture* texture9); }; diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index 42b7f97..ded320e 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -152,6 +152,13 @@ Vehicle::Vehicle() }; } +Vehicle::~Vehicle() +{ + Util::ReleaseTextures(spawner::image_vec); + Util::ReleaseTextures(tune::image_vec); + Util::ReleaseTextures(texture9::image_vec); +} + void Vehicle::AddComponent(const std::string& component, const bool display_message) { try { @@ -503,11 +510,6 @@ int Vehicle::GetModelFromName(const char* name) return 0; } -Vehicle::~Vehicle() -{ -} - - void Vehicle::GenerateHandlingDataFile(int phandling) { FILE* fp = fopen("handling.txt", "w"); diff --git a/src/Weapon.cpp b/src/Weapon.cpp index 3f0685c..93bbcb4 100644 --- a/src/Weapon.cpp +++ b/src/Weapon.cpp @@ -63,6 +63,7 @@ Weapon::Weapon() Weapon::~Weapon() { + Util::ReleaseTextures(Weapon::weapon_vec); } void Weapon::SetGangWeapon(std::string& weapon_type) diff --git a/src/pch.h b/src/pch.h index dce5955..25e9051 100644 --- a/src/pch.h +++ b/src/pch.h @@ -52,12 +52,12 @@ #include "eVehicleClass.h" #include "extensions/Paths.h" -#include "fla/IDaccess.h" -#include "imgui/imgui.h" -#include "imgui/imgui_internal.h" -#include "imgui/imgui_impl_dx9.h" -#include "imgui/imgui_impl_dx11.h" -#include "imgui/imgui_impl_win32.h" +#include "../deps/fla/IDaccess.h" +#include "../deps/imgui/imgui.h" +#include "../deps/imgui/imgui_internal.h" +#include "../deps/imgui/imgui_impl_dx9.h" +#include "../deps/imgui/imgui_impl_dx11.h" +#include "../deps/imgui/imgui_impl_win32.h" #include "MoreEvents.h" #include "Json.h" @@ -84,6 +84,7 @@ struct Globals inline static bool show_menu = false; inline static bool init_done = false; inline static bool game_init = false; + inline static bool menu_closing = false; inline static Renderer renderer = Render_Unknown; inline static void* device = nullptr; };