From 7c4e7fba14cf692b807cd28354f9e01e2f5ef5b7 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Mon, 21 Feb 2022 14:33:57 +0600 Subject: [PATCH] Crash fix & improvements 1. Fixed crash when modloader.asi was installed but no modloader folder found 2. Code improvements --- .github/FUNDING.yml | 13 ------- .github/ISSUE_TEMPLATE/bug_report.md | 20 ----------- .github/ISSUE_TEMPLATE/feature_request.md | 20 ----------- src/animation.cpp | 4 +-- src/animation.h | 5 ++- src/cheatmenu.cpp | 44 +++++++++++++++-------- src/cheatmenu.h | 17 +++------ src/dllmain.cpp | 2 +- src/game.cpp | 2 +- src/game.h | 6 ++-- src/menu.cpp | 2 +- src/menu.h | 5 ++- src/ped.cpp | 11 +----- src/ped.h | 6 ++-- src/player.cpp | 20 +++++++---- src/player.h | 6 ++-- src/teleport.cpp | 2 +- src/teleport.h | 5 +-- src/vehicle.cpp | 11 ++---- src/vehicle.h | 7 ++-- src/visual.cpp | 2 +- src/visual.h | 5 ++- src/weapon.cpp | 2 +- src/weapon.h | 5 ++- 24 files changed, 95 insertions(+), 127 deletions(-) delete mode 100644 .github/FUNDING.yml delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 59d4dc4..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,13 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry -custom: ['https://paypal.me/NOTGrinch'] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index e258e9c..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Bug report -about: Help us improve by reporting a bug -title: '' -labels: bug -assignees: user-grinch - ---- - -**Describe the bug** -A clear and concise description of what the bug is & steps to reproduce it. Screenshots or videos are helpful. - -**Info** -Cheat Menu version (with build number): -Game Version (v1.0 required): -Windows Version (7/8/10): -Have you read the installation instructions? (Yes/No): -Have you installed the menu using modloader? (Yes/No) (Provide log if installed): -List of mods you have installed, -... diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index ff9d7d8..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: enhancement -assignees: user-grinch - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/src/animation.cpp b/src/animation.cpp index 7f39f4c..88a8a28 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -221,10 +221,10 @@ void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& #endif } -Animation::Animation() +void Animation::Init() { #ifdef GTASA - Events::processScriptsEvent += [this] + Events::processScriptsEvent += [] { CPlayerPed* pPlayer = FindPlayerPed(); if (m_Cutscene::m_bRunning) diff --git a/src/animation.h b/src/animation.h index 1ba7044..ada0dfb 100644 --- a/src/animation.h +++ b/src/animation.h @@ -57,6 +57,9 @@ private: #endif public: - Animation(); + Animation() = delete; + Animation(const Animation&) = delete; + + static void Init(); static void ShowPage(); }; \ No newline at end of file diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index d823ef5..4326d16 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -1,5 +1,4 @@ #include "pch.h" -#include "cheatMenu.h" #include "version.h" #include "ui.h" #include "updater.h" @@ -7,6 +6,17 @@ #include "../depend/imgui/imgui_internal.h" #include "util.h" +#include "animation.h" +#include "cheatmenu.h" +#include "game.h" +#include "menu.h" +#include "ped.h" +#include "player.h" +#include "teleport.h" +#include "vehicle.h" +#include "visual.h" +#include "weapon.h" + void CheatMenu::DrawWindow() { ImGuiIO& io = ImGui::GetIO(); @@ -24,7 +34,7 @@ void CheatMenu::DrawWindow() else { bRunning = true; - if (m_bShowMenu || BY_GAME(m_Commands::m_bShowMenu, true, true)) + if (m_bShowMenu || BY_GAME(Menu::m_Commands::m_bShowMenu, true, true)) { if (m_bShowMenu) { @@ -54,12 +64,12 @@ void CheatMenu::DrawWindow() #ifdef GTASA else { - DrawShortcutsWindow(); + Menu::DrawShortcutsWindow(); } #endif } } - DrawOverlay(); + Menu::DrawOverlay(); } void CheatMenu::ProcessPages() @@ -164,7 +174,7 @@ void CheatMenu::ProcessPages() } } -CheatMenu::CheatMenu() +void CheatMenu::Init() { if (!D3dHook::InjectHook(DrawWindow)) { @@ -197,6 +207,17 @@ CheatMenu::CheatMenu() {"Anniversary", &ShowAnniversaryPage, eMenuPages::ANNIVERSARY, true} }; + // Init menu parts + Animation::Init(); + Game::Init(); + Menu::Init(); + Player::Init(); + Ped::Init(); + Teleport::Init(); + Vehicle::Init(); + Visual::Init(); + Weapon::Init(); + Events::processScriptsEvent += []() { if (!BY_GAME(FrontEndMenuManager.m_bMenuActive, FrontendMenuManager.m_bMenuVisible, FrontEndMenuManager.m_bMenuActive)) @@ -208,12 +229,12 @@ CheatMenu::CheatMenu() if (commandWindow.Pressed()) { - if (m_Commands::m_bShowMenu) + if (Menu::m_Commands::m_bShowMenu) { - ProcessCommands(); - strcpy(m_Commands::m_nInputBuffer, ""); + Menu::ProcessCommands(); + strcpy(Menu::m_Commands::m_nInputBuffer, ""); } - m_Commands::m_bShowMenu = !m_Commands::m_bShowMenu; + Menu::m_Commands::m_bShowMenu = !Menu::m_Commands::m_bShowMenu; } bool mouseState = D3dHook::GetMouseState(); @@ -230,11 +251,6 @@ CheatMenu::CheatMenu() }; } -CheatMenu::~CheatMenu() -{ - D3dHook::RemoveHook(); -} - /* * YIKES YOU AREN"T SUPPOSED TO FIND THIS YOU KNOW!!! * Probably a good easter egg for the upcoming anniversary ;) diff --git a/src/cheatmenu.h b/src/cheatmenu.h index 46efa00..62b0369 100644 --- a/src/cheatmenu.h +++ b/src/cheatmenu.h @@ -9,17 +9,9 @@ */ #pragma once -#include "animation.h" -#include "game.h" -#include "menu.h" -#include "ped.h" -#include "player.h" -#include "teleport.h" -#include "vehicle.h" -#include "visual.h" -#include "weapon.h" +#include "pch.h" -class CheatMenu : Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon +class CheatMenu { private: enum class eMenuPages @@ -48,8 +40,9 @@ private: static void ProcessPages(); public: - CheatMenu(); - ~CheatMenu(); + CheatMenu() = delete; + CheatMenu(const CheatMenu&) = delete; + static void Init(); static void ResetMenuSize(); }; diff --git a/src/dllmain.cpp b/src/dllmain.cpp index adf6e9e..1057bcc 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -71,7 +71,7 @@ void MenuThread(void* param) gLog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl; - CheatMenu menu; + CheatMenu::Init(); // Checking for updates once a day SYSTEMTIME st; diff --git a/src/game.cpp b/src/game.cpp index 1e86e06..7690e7b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -34,7 +34,7 @@ void Game::RealTimeClock() CClock::ms_nGameClockSeconds = now->tm_sec; } -Game::Game() +void Game::Init() { #ifdef GTASA // Generate enabled cheats vector diff --git a/src/game.h b/src/game.h index ae73f72..9b38d3d 100644 --- a/src/game.h +++ b/src/game.h @@ -62,7 +62,9 @@ public: static inline bool m_bFreezeTime; static inline bool m_bSyncTime; - Game(); - static void ShowPage(); + Game() = delete; + Game(const Game&) = delete; + static void Init(); + static void ShowPage(); }; diff --git a/src/menu.cpp b/src/menu.cpp index 8df79fe..8f51545 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -12,7 +12,7 @@ #include "vehicle.h" #endif -Menu::Menu() +void Menu::Init() { // TODO: use structs // Load config data diff --git a/src/menu.h b/src/menu.h index a890409..5c7f18c 100644 --- a/src/menu.h +++ b/src/menu.h @@ -45,7 +45,10 @@ public: static inline char m_nInputBuffer[INPUT_BUFFER_SIZE] = ""; }; - Menu(); + Menu() = delete; + Menu(const Menu&) = delete; + + static void Init(); static void ShowPage(); static void DrawOverlay(); static void DrawShortcutsWindow(); diff --git a/src/ped.cpp b/src/ped.cpp index 4d7e21f..60eba8b 100644 --- a/src/ped.cpp +++ b/src/ped.cpp @@ -9,7 +9,7 @@ #include #endif -Ped::Ped() +void Ped::Init() { #ifdef GTASA if (GetModuleHandle("ExGangWars.asi")) @@ -52,15 +52,6 @@ Ped::Ped() #endif } -Ped::~Ped() -{ - for (CPed* ped : m_SpawnPed::m_List) - { - CWorld::Remove(ped); - ped->Remove(); - } -} - #ifdef GTASA void Ped::SpawnPed(std::string& model) #else diff --git a/src/ped.h b/src/ped.h index 08e68d6..490ce5e 100644 --- a/src/ped.h +++ b/src/ped.h @@ -57,7 +57,9 @@ public: static inline ResourceStore m_PedData {"ped", eResourceType::TYPE_TEXT}; #endif - Ped(); - ~Ped(); + Ped() = delete; + Ped(const Ped&) = delete; + + static void Init(); static void ShowPage(); }; diff --git a/src/player.cpp b/src/player.cpp index b489ff6..4717ac7 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -82,7 +82,7 @@ void Player::TopDownCameraView() } #endif -Player::Player() +void Player::Init() { #ifdef GTASA // Fix player model being broken after rebuild @@ -91,27 +91,33 @@ Player::Player() #endif // Custom skins setup - if (GetModuleHandle("modloader.asi")) + std::string path = GAME_PATH((char*)"modloader/"); + if (GetModuleHandle("modloader.asi") && std::filesystem::is_directory(path)) { #ifdef GTASA - if (std::filesystem::is_directory(m_CustomSkins::m_Path)) + path += "CustomSkins/"; + if (std::filesystem::is_directory(path)) { - for (auto& p : std::filesystem::recursive_directory_iterator(m_CustomSkins::m_Path)) + for (auto& p : std::filesystem::recursive_directory_iterator(path)) { if (p.path().extension() == ".dff") { std::string file_name = p.path().stem().string(); if (file_name.size() < 9) + { m_CustomSkins::m_List.push_back(file_name); + } else + { gLog << "Custom Skin longer than 8 characters " << file_name << std::endl; + } } } } else { - std::filesystem::create_directory(m_CustomSkins::m_Path); + std::filesystem::create_directory(path); } #endif @@ -805,7 +811,7 @@ void Player::ShowPage() Ui::FilterWithHint("Search", m_ClothData.m_Filter, std::string("Total skins: " + std::to_string(m_CustomSkins::m_List.size())) .c_str()); - Ui::ShowTooltip("Place your dff & txd files inside 'modloader/Custom Skins'"); + Ui::ShowTooltip("Place your dff & txd files inside 'modloader/CustomSkins'"); ImGui::Spacing(); ImGui::TextWrapped( "Note: Your txd & dff names can't exceed 8 characters. Don't change names while the game is running."); @@ -827,7 +833,7 @@ void Player::ShowPage() "Custom skin allows to change player skins without replacing any existing game ped skins.\n\ Steps to enable 'Custom Skins',\n\n\ 1. Download & install modloader\n\ -2. Create a folder inside 'modloader' folder with the name 'Custom Skins'\n\ +2. Create a folder inside 'modloader' folder with the name 'CustomSkins'\n\ 3. Download ped skins online ( .dff & .txd files) and put them inside.\n\ 4. Restart your game.\n\n\n\ Limitations:\n\ diff --git a/src/player.h b/src/player.h index 35f61b2..b3ffc71 100644 --- a/src/player.h +++ b/src/player.h @@ -21,7 +21,6 @@ private: static inline ResourceStore m_ClothData { "clothes", eResourceType::TYPE_IMAGE, ImVec2(70, 100)}; struct m_CustomSkins { - static inline std::string m_Path = paths::GetGameDirPathA() + std::string("\\modloader\\Custom Skins\\");; static inline ImGuiTextFilter m_Filter; static inline std::vector m_List; }; @@ -52,6 +51,9 @@ private: #endif public: - Player(); + Player() = delete; + Player(const Player&) = delete; + + static void Init(); static void ShowPage(); }; diff --git a/src/teleport.cpp b/src/teleport.cpp index 4961654..d77d964 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -40,7 +40,7 @@ void Teleport::FetchRadarSpriteData() } #endif -Teleport::Teleport() +void Teleport::Init() { m_bQuickTeleport = gConfig.GetValue("quick_teleport", false); diff --git a/src/teleport.h b/src/teleport.h index a9839f5..75ea69a 100644 --- a/src/teleport.h +++ b/src/teleport.h @@ -1,5 +1,4 @@ #pragma once -#include #include "pch.h" class Teleport @@ -36,8 +35,10 @@ private: static void RemoveTeleportEntry(std::string& rootkey, std::string& key, std::string& val); public: - Teleport(); + Teleport() = delete; + Teleport(const Teleport&) = delete; + static void Init(); static void TeleportPlayer(bool get_marker = false, CVector pos = CVector(0, 0, 0), int interior_id = 0); static void ShowPage(); }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 5f56ba7..2b8b200 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -14,7 +14,7 @@ #include "paint.h" #endif -Vehicle::Vehicle() +void Vehicle::Init() { #ifdef GTASA FileHandler::FetchHandlingID(m_VehicleIDE); @@ -24,7 +24,7 @@ Vehicle::Vehicle() FileHandler::FetchColorData(m_CarcolsColorData); - Events::processScriptsEvent += [this] + Events::processScriptsEvent += [] { uint timer = CTimer::m_snTimeInMilliseconds; CPlayerPed* pPlayer = FindPlayerPed(); @@ -192,13 +192,6 @@ Vehicle::Vehicle() }; } -Vehicle::~Vehicle() -{ -#ifdef GTASA - Neon::RemoveHooks(); -#endif -} - #ifdef GTASA void Vehicle::AddComponent(const std::string& component, const bool display_message) { diff --git a/src/vehicle.h b/src/vehicle.h index efe75c3..0c1e98d 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -90,13 +90,16 @@ private: #endif public: - Vehicle(); - ~Vehicle(); + Vehicle() = delete; + Vehicle(const Vehicle&) = delete; + #ifdef GTASA static void SpawnVehicle(std::string& name); #else static void SpawnVehicle(std::string& rootkey, std::string& vehName, std::string& model); #endif + + static void Init(); static std::string GetNameFromModel(int model); static int GetModelFromName(const char* name); static void ShowPage(); diff --git a/src/visual.cpp b/src/visual.cpp index 1978de9..b919b40 100644 --- a/src/visual.cpp +++ b/src/visual.cpp @@ -17,7 +17,7 @@ #define TOTAL_WEATHERS 4 #endif -Visual::Visual() +void Visual::Init() { #ifdef GTASA if (GetModuleHandle("timecycle24.asi")) diff --git a/src/visual.h b/src/visual.h index 45e31e1..f79f21d 100644 --- a/src/visual.h +++ b/src/visual.h @@ -40,6 +40,9 @@ private: static void TimecycSlider(const char* label, T* data, int min, int max); public: - Visual(); + Visual() = delete; + Visual(const Visual&) = delete; + + static void Init(); static void ShowPage(); }; \ No newline at end of file diff --git a/src/weapon.cpp b/src/weapon.cpp index efe8567..64eab08 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -4,7 +4,7 @@ #include "util.h" #include "CWeaponInfo.h" -Weapon::Weapon() +void Weapon::Init() { Events::processScriptsEvent += [] { diff --git a/src/weapon.h b/src/weapon.h index 6c853d9..856b9ea 100644 --- a/src/weapon.h +++ b/src/weapon.h @@ -52,6 +52,9 @@ public: static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); #endif - Weapon(); + Weapon() = delete; + Weapon(const Weapon&) = delete; + + static void Init(); static void ShowPage(); };