Crash fix & improvements

1. Fixed crash when modloader.asi was installed but no modloader folder found
2. Code improvements
This commit is contained in:
Grinch_ 2022-02-21 14:33:57 +06:00
parent 3dd96c020f
commit 7c4e7fba14
24 changed files with 95 additions and 127 deletions

13
.github/FUNDING.yml vendored
View File

@ -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']

View File

@ -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,
...

View File

@ -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.

View File

@ -221,10 +221,10 @@ void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string&
#endif #endif
} }
Animation::Animation() void Animation::Init()
{ {
#ifdef GTASA #ifdef GTASA
Events::processScriptsEvent += [this] Events::processScriptsEvent += []
{ {
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
if (m_Cutscene::m_bRunning) if (m_Cutscene::m_bRunning)

View File

@ -57,6 +57,9 @@ private:
#endif #endif
public: public:
Animation(); Animation() = delete;
Animation(const Animation&) = delete;
static void Init();
static void ShowPage(); static void ShowPage();
}; };

View File

@ -1,5 +1,4 @@
#include "pch.h" #include "pch.h"
#include "cheatMenu.h"
#include "version.h" #include "version.h"
#include "ui.h" #include "ui.h"
#include "updater.h" #include "updater.h"
@ -7,6 +6,17 @@
#include "../depend/imgui/imgui_internal.h" #include "../depend/imgui/imgui_internal.h"
#include "util.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() void CheatMenu::DrawWindow()
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
@ -24,7 +34,7 @@ void CheatMenu::DrawWindow()
else else
{ {
bRunning = true; 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) if (m_bShowMenu)
{ {
@ -54,12 +64,12 @@ void CheatMenu::DrawWindow()
#ifdef GTASA #ifdef GTASA
else else
{ {
DrawShortcutsWindow(); Menu::DrawShortcutsWindow();
} }
#endif #endif
} }
} }
DrawOverlay(); Menu::DrawOverlay();
} }
void CheatMenu::ProcessPages() void CheatMenu::ProcessPages()
@ -164,7 +174,7 @@ void CheatMenu::ProcessPages()
} }
} }
CheatMenu::CheatMenu() void CheatMenu::Init()
{ {
if (!D3dHook::InjectHook(DrawWindow)) if (!D3dHook::InjectHook(DrawWindow))
{ {
@ -197,6 +207,17 @@ CheatMenu::CheatMenu()
{"Anniversary", &ShowAnniversaryPage, eMenuPages::ANNIVERSARY, true} {"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 += []() Events::processScriptsEvent += []()
{ {
if (!BY_GAME(FrontEndMenuManager.m_bMenuActive, FrontendMenuManager.m_bMenuVisible, FrontEndMenuManager.m_bMenuActive)) if (!BY_GAME(FrontEndMenuManager.m_bMenuActive, FrontendMenuManager.m_bMenuVisible, FrontEndMenuManager.m_bMenuActive))
@ -208,12 +229,12 @@ CheatMenu::CheatMenu()
if (commandWindow.Pressed()) if (commandWindow.Pressed())
{ {
if (m_Commands::m_bShowMenu) if (Menu::m_Commands::m_bShowMenu)
{ {
ProcessCommands(); Menu::ProcessCommands();
strcpy(m_Commands::m_nInputBuffer, ""); 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(); bool mouseState = D3dHook::GetMouseState();
@ -230,11 +251,6 @@ CheatMenu::CheatMenu()
}; };
} }
CheatMenu::~CheatMenu()
{
D3dHook::RemoveHook();
}
/* /*
* YIKES YOU AREN"T SUPPOSED TO FIND THIS YOU KNOW!!! * YIKES YOU AREN"T SUPPOSED TO FIND THIS YOU KNOW!!!
* Probably a good easter egg for the upcoming anniversary ;) * Probably a good easter egg for the upcoming anniversary ;)

View File

@ -9,17 +9,9 @@
*/ */
#pragma once #pragma once
#include "animation.h" #include "pch.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"
class CheatMenu : Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon class CheatMenu
{ {
private: private:
enum class eMenuPages enum class eMenuPages
@ -48,8 +40,9 @@ private:
static void ProcessPages(); static void ProcessPages();
public: public:
CheatMenu(); CheatMenu() = delete;
~CheatMenu(); CheatMenu(const CheatMenu&) = delete;
static void Init();
static void ResetMenuSize(); static void ResetMenuSize();
}; };

View File

@ -71,7 +71,7 @@ void MenuThread(void* param)
gLog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " gLog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: "
GITHUB_LINK "\n" << std::endl; GITHUB_LINK "\n" << std::endl;
CheatMenu menu; CheatMenu::Init();
// Checking for updates once a day // Checking for updates once a day
SYSTEMTIME st; SYSTEMTIME st;

View File

@ -34,7 +34,7 @@ void Game::RealTimeClock()
CClock::ms_nGameClockSeconds = now->tm_sec; CClock::ms_nGameClockSeconds = now->tm_sec;
} }
Game::Game() void Game::Init()
{ {
#ifdef GTASA #ifdef GTASA
// Generate enabled cheats vector // Generate enabled cheats vector

View File

@ -62,7 +62,9 @@ public:
static inline bool m_bFreezeTime; static inline bool m_bFreezeTime;
static inline bool m_bSyncTime; static inline bool m_bSyncTime;
Game(); Game() = delete;
static void ShowPage(); Game(const Game&) = delete;
static void Init();
static void ShowPage();
}; };

View File

@ -12,7 +12,7 @@
#include "vehicle.h" #include "vehicle.h"
#endif #endif
Menu::Menu() void Menu::Init()
{ {
// TODO: use structs // TODO: use structs
// Load config data // Load config data

View File

@ -45,7 +45,10 @@ public:
static inline char m_nInputBuffer[INPUT_BUFFER_SIZE] = ""; static inline char m_nInputBuffer[INPUT_BUFFER_SIZE] = "";
}; };
Menu(); Menu() = delete;
Menu(const Menu&) = delete;
static void Init();
static void ShowPage(); static void ShowPage();
static void DrawOverlay(); static void DrawOverlay();
static void DrawShortcutsWindow(); static void DrawShortcutsWindow();

View File

@ -9,7 +9,7 @@
#include <ePedBones.h> #include <ePedBones.h>
#endif #endif
Ped::Ped() void Ped::Init()
{ {
#ifdef GTASA #ifdef GTASA
if (GetModuleHandle("ExGangWars.asi")) if (GetModuleHandle("ExGangWars.asi"))
@ -52,15 +52,6 @@ Ped::Ped()
#endif #endif
} }
Ped::~Ped()
{
for (CPed* ped : m_SpawnPed::m_List)
{
CWorld::Remove(ped);
ped->Remove();
}
}
#ifdef GTASA #ifdef GTASA
void Ped::SpawnPed(std::string& model) void Ped::SpawnPed(std::string& model)
#else #else

View File

@ -57,7 +57,9 @@ public:
static inline ResourceStore m_PedData {"ped", eResourceType::TYPE_TEXT}; static inline ResourceStore m_PedData {"ped", eResourceType::TYPE_TEXT};
#endif #endif
Ped(); Ped() = delete;
~Ped(); Ped(const Ped&) = delete;
static void Init();
static void ShowPage(); static void ShowPage();
}; };

View File

@ -82,7 +82,7 @@ void Player::TopDownCameraView()
} }
#endif #endif
Player::Player() void Player::Init()
{ {
#ifdef GTASA #ifdef GTASA
// Fix player model being broken after rebuild // Fix player model being broken after rebuild
@ -91,27 +91,33 @@ Player::Player()
#endif #endif
// Custom skins setup // 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 #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") if (p.path().extension() == ".dff")
{ {
std::string file_name = p.path().stem().string(); std::string file_name = p.path().stem().string();
if (file_name.size() < 9) if (file_name.size() < 9)
{
m_CustomSkins::m_List.push_back(file_name); m_CustomSkins::m_List.push_back(file_name);
}
else else
{
gLog << "Custom Skin longer than 8 characters " << file_name << std::endl; gLog << "Custom Skin longer than 8 characters " << file_name << std::endl;
} }
} }
} }
}
else else
{ {
std::filesystem::create_directory(m_CustomSkins::m_Path); std::filesystem::create_directory(path);
} }
#endif #endif

View File

@ -21,7 +21,6 @@ private:
static inline ResourceStore m_ClothData { "clothes", eResourceType::TYPE_IMAGE, ImVec2(70, 100)}; static inline ResourceStore m_ClothData { "clothes", eResourceType::TYPE_IMAGE, ImVec2(70, 100)};
struct m_CustomSkins struct m_CustomSkins
{ {
static inline std::string m_Path = paths::GetGameDirPathA() + std::string("\\modloader\\Custom Skins\\");;
static inline ImGuiTextFilter m_Filter; static inline ImGuiTextFilter m_Filter;
static inline std::vector<std::string> m_List; static inline std::vector<std::string> m_List;
}; };
@ -52,6 +51,9 @@ private:
#endif #endif
public: public:
Player(); Player() = delete;
Player(const Player&) = delete;
static void Init();
static void ShowPage(); static void ShowPage();
}; };

View File

@ -40,7 +40,7 @@ void Teleport::FetchRadarSpriteData()
} }
#endif #endif
Teleport::Teleport() void Teleport::Init()
{ {
m_bQuickTeleport = gConfig.GetValue("quick_teleport", false); m_bQuickTeleport = gConfig.GetValue("quick_teleport", false);

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include <vector>
#include "pch.h" #include "pch.h"
class Teleport class Teleport
@ -36,8 +35,10 @@ private:
static void RemoveTeleportEntry(std::string& rootkey, std::string& key, std::string& val); static void RemoveTeleportEntry(std::string& rootkey, std::string& key, std::string& val);
public: 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 TeleportPlayer(bool get_marker = false, CVector pos = CVector(0, 0, 0), int interior_id = 0);
static void ShowPage(); static void ShowPage();
}; };

View File

@ -14,7 +14,7 @@
#include "paint.h" #include "paint.h"
#endif #endif
Vehicle::Vehicle() void Vehicle::Init()
{ {
#ifdef GTASA #ifdef GTASA
FileHandler::FetchHandlingID(m_VehicleIDE); FileHandler::FetchHandlingID(m_VehicleIDE);
@ -24,7 +24,7 @@ Vehicle::Vehicle()
FileHandler::FetchColorData(m_CarcolsColorData); FileHandler::FetchColorData(m_CarcolsColorData);
Events::processScriptsEvent += [this] Events::processScriptsEvent += []
{ {
uint timer = CTimer::m_snTimeInMilliseconds; uint timer = CTimer::m_snTimeInMilliseconds;
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
@ -192,13 +192,6 @@ Vehicle::Vehicle()
}; };
} }
Vehicle::~Vehicle()
{
#ifdef GTASA
Neon::RemoveHooks();
#endif
}
#ifdef GTASA #ifdef GTASA
void Vehicle::AddComponent(const std::string& component, const bool display_message) void Vehicle::AddComponent(const std::string& component, const bool display_message)
{ {

View File

@ -90,13 +90,16 @@ private:
#endif #endif
public: public:
Vehicle(); Vehicle() = delete;
~Vehicle(); Vehicle(const Vehicle&) = delete;
#ifdef GTASA #ifdef GTASA
static void SpawnVehicle(std::string& name); static void SpawnVehicle(std::string& name);
#else #else
static void SpawnVehicle(std::string& rootkey, std::string& vehName, std::string& model); static void SpawnVehicle(std::string& rootkey, std::string& vehName, std::string& model);
#endif #endif
static void Init();
static std::string GetNameFromModel(int model); static std::string GetNameFromModel(int model);
static int GetModelFromName(const char* name); static int GetModelFromName(const char* name);
static void ShowPage(); static void ShowPage();

View File

@ -17,7 +17,7 @@
#define TOTAL_WEATHERS 4 #define TOTAL_WEATHERS 4
#endif #endif
Visual::Visual() void Visual::Init()
{ {
#ifdef GTASA #ifdef GTASA
if (GetModuleHandle("timecycle24.asi")) if (GetModuleHandle("timecycle24.asi"))

View File

@ -40,6 +40,9 @@ private:
static void TimecycSlider(const char* label, T* data, int min, int max); static void TimecycSlider(const char* label, T* data, int min, int max);
public: public:
Visual(); Visual() = delete;
Visual(const Visual&) = delete;
static void Init();
static void ShowPage(); static void ShowPage();
}; };

View File

@ -4,7 +4,7 @@
#include "util.h" #include "util.h"
#include "CWeaponInfo.h" #include "CWeaponInfo.h"
Weapon::Weapon() void Weapon::Init()
{ {
Events::processScriptsEvent += [] Events::processScriptsEvent += []
{ {

View File

@ -52,6 +52,9 @@ public:
static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name);
#endif #endif
Weapon(); Weapon() = delete;
Weapon(const Weapon&) = delete;
static void Init();
static void ShowPage(); static void ShowPage();
}; };