diff --git a/.vscode/settings.json b/.vscode/settings.json index 88ce727..c419bd5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -73,6 +73,7 @@ "xstring": "cpp", "xtr1common": "cpp", "xtree": "cpp", - "xutility": "cpp" + "xutility": "cpp", + "*.rh": "cpp" } } \ No newline at end of file diff --git a/src/Animation.cpp b/src/Animation.cpp index 77ceaa7..34ef63f 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -1,8 +1,8 @@ #include "pch.h" -#include "Animation.h" +#include "animation.h" #ifdef GTASA -#include "Ui.h" -#include "Util.h" +#include "ui.h" +#include "util.h" Animation::Animation() { @@ -42,6 +42,7 @@ void Animation::PlayCutscene(std::string& rootKey, std::string& cutsceneId, std: SetHelpMessage("Another cutscene is running", false, false, false); return; } + CPlayerPed* pPlayer = FindPlayerPed(); if (!pPlayer) { diff --git a/src/Animation.h b/src/Animation.h index 1024095..5a0786e 100644 --- a/src/Animation.h +++ b/src/Animation.h @@ -5,22 +5,28 @@ class Animation { private: - inline static char m_nAnimBuffer[INPUT_BUFFER_SIZE]; - inline static ResourceStore m_AnimData{ "animation", eResourceType::TYPE_TEXT }; + + // Animation player + static inline ResourceStore m_AnimData{ "animation", eResourceType::TYPE_TEXT }; + static inline char m_nAnimBuffer[INPUT_BUFFER_SIZE]; + static inline char m_nIfpBuffer[INPUT_BUFFER_SIZE]; + static inline bool m_Loop; // loop animation + static inline bool m_bSecondary; // play animation as secondary + + // Cutscene player struct m_Cutscene { - inline static ResourceStore m_Data{ "cutscene", eResourceType::TYPE_TEXT }; - inline static std::string m_SceneName; - inline static int m_nInterior; - inline static bool m_bRunning; + static inline ResourceStore m_Data{ "cutscene", eResourceType::TYPE_TEXT }; + static inline std::string m_SceneName; + static inline int m_nInterior; // player interior backup + static inline bool m_bRunning; }; - inline static int m_nFightingStyle; - inline static char m_nIfpBuffer[INPUT_BUFFER_SIZE]; - inline static bool m_Loop; - inline static bool m_bSecondary; - inline static std::string m_nWalkingStyle = "default"; - inline static std::vector m_FightingStyleList = { "Default", "Boxing", "Kung fu", "Kick Boxing", "Punch Kick" }; - inline static std::vector m_WalkingStyleList = + + static inline int m_nFightingStyle; + static inline std::string m_nWalkingStyle = "default"; + static inline std::vector m_FightingStyleList = + { "Default", "Boxing", "Kung fu", "Kick Boxing", "Punch Kick" }; + static inline std::vector m_WalkingStyleList = { "default", "man", "shuffle", "oldman", "gang1", "gang2", "oldfatman", "fatman", "jogger", "drunkman", "blindman", "swat", "woman", "shopping", "busywoman", diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index cd828c9..3a5a47d 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -1,8 +1,8 @@ #include "pch.h" -#include "CheatMenu.h" -#include "MenuInfo.h" -#include "Ui.h" -#include "Updater.h" +#include "cheatMenu.h" +#include "menuinfo.h" +#include "ui.h" +#include "updater.h" void CheatMenu::DrawWindow() { @@ -13,7 +13,7 @@ void CheatMenu::DrawWindow() { if (bRunning) { - config.WriteToDisk(); + gConfig.WriteToDisk(); bRunning = false; m_bShowMouse = false; } @@ -21,12 +21,21 @@ void CheatMenu::DrawWindow() else { bRunning = true; - if (Globals::m_bShowMenu || BY_GAME(m_Commands::m_bShowMenu, true)) + if (m_bShowMenu || BY_GAME(m_Commands::m_bShowMenu, true)) { - if (Globals::m_bShowMenu) + if (m_bShowMenu) { - ImGui::SetNextWindowSize(Globals::m_fMenuSize); - if (ImGui::Begin(MENU_TITLE, &Globals::m_bShowMenu, ImGuiWindowFlags_NoCollapse)) + static ImVec2 fScreenSize = ImVec2(-1, -1); + ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight()); + + if (fScreenSize.x != -1 && fScreenSize.y != -1) + { + m_fMenuSize.x += (size.x - fScreenSize.x) / 4.0f; + m_fMenuSize.y += (size.y - fScreenSize.y) / 1.2f; + } + ImGui::SetNextWindowSize(m_fMenuSize); + + if (ImGui::Begin(MENU_TITLE, &m_bShowMenu, ImGuiWindowFlags_NoCollapse)) { ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(250, 350)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, @@ -37,9 +46,9 @@ void CheatMenu::DrawWindow() else Ui::DrawHeaders(header); - Globals::m_fMenuSize = ImGui::GetWindowSize(); - config.SetValue("window.sizeX", Globals::m_fMenuSize.x); - config.SetValue("window.sizeY", Globals::m_fMenuSize.y); + m_fMenuSize = ImGui::GetWindowSize(); + gConfig.SetValue("window.sizeX", m_fMenuSize.x); + gConfig.SetValue("window.sizeY", m_fMenuSize.y); ImGui::PopStyleVar(2); ImGui::End(); @@ -62,27 +71,21 @@ CheatMenu::CheatMenu() windowCallback = std::bind(&DrawWindow); // Load menu settings - Globals::m_HeaderId = config.GetValue("window.id", std::string("")); - Globals::m_fMenuSize.x = config.GetValue("window.sizeX", screen::GetScreenWidth() / 4.0f); - Globals::m_fMenuSize.y = config.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f); + Ui::m_HeaderId = gConfig.GetValue("window.id", std::string("")); + m_fMenuSize.x = gConfig.GetValue("window.sizeX", screen::GetScreenWidth() / 4.0f); + m_fMenuSize.y = gConfig.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f); srand(CTimer::m_snTimeInMilliseconds); Events::processScriptsEvent += []() { - if (Globals::m_bInit && -#ifdef GTASA - !FrontEndMenuManager.m_bMenuActive -#elif GTAVC - !FrontendMenuManager.m_bMenuVisible -#endif - ) + if (!BY_GAME(FrontEndMenuManager.m_bMenuActive, FrontendMenuManager.m_bMenuVisible)) { - if (Ui::HotKeyPressed(Menu::m_HotKeys::menuOpen)) + if (menuOpen.Pressed()) { - Globals::m_bShowMenu = !Globals::m_bShowMenu; + m_bShowMenu = !m_bShowMenu; } - if (Ui::HotKeyPressed(Menu::m_HotKeys::commandWindow)) + if (commandWindow.Pressed()) { if (m_Commands::m_bShowMenu) { @@ -92,14 +95,14 @@ CheatMenu::CheatMenu() m_Commands::m_bShowMenu = !m_Commands::m_bShowMenu; } - if (m_bShowMouse != Globals::m_bShowMenu) + if (m_bShowMouse != m_bShowMenu) { if (m_bShowMouse) // Only write when the menu closes { - config.WriteToDisk(); + gConfig.WriteToDisk(); } - m_bShowMouse = Globals::m_bShowMenu; + m_bShowMouse = m_bShowMenu; } } }; @@ -178,89 +181,3 @@ void CheatMenu::ApplyStyle() colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); } - -void MenuThread(void* param) -{ - if (!fs::is_directory(PLUGIN_PATH((char*)"CheatMenu"))) - { - flog << "CheatMenu folder not found. You need to put both \"CheatMenu.asi\" & \"CheatMenu\" folder in the same directory" << std::endl; - return; - } - - static bool bGameInit = false; -#ifdef GTASA - Hook::ApplyMouseFix(); -#endif - - // Wait till game init - Events::initRwEvent += [] - { - bGameInit = true; - }; - - while (!bGameInit) - { - Sleep(1000); - } - - if (GetModuleHandle("SAMP.dll")) - { - MessageBox(RsGlobal.ps->window, "SAMP detected. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); - return; - } - - flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " - GITHUB_LINK "\n" << std::endl; - CFastman92limitAdjuster::Init(); - CheatMenu menu; - - time_t now = time(0); - struct tm tstruct = *localtime(&now); - int last_check_date = config.GetValue("config.last_update_checked", 0); - - if (last_check_date != tstruct.tm_mday) - { - Updater::CheckForUpdate(); - config.SetValue("config.last_update_checked", tstruct.tm_mday); - } - - while (true) - { - Sleep(5000); - - if (Updater::m_State == UPDATER_CHECKING) - { - Updater::CheckForUpdate(); - } - } -} - -BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) -{ - if (nReason == DLL_PROCESS_ATTACH) - { - uint gameVersion = GetGameVersion(); -#ifdef GTASA - if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT) - { - CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); - } - else - { - MessageBox(HWND_DESKTOP, "Unknown game version. GTA SA v1.0 US is required.", "CheatMenu", MB_ICONERROR); - } -#elif GTAVC - - if (gameVersion == GAME_10EN) - { - CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); - } - else - { - MessageBox(HWND_DESKTOP, "Unknown game version. GTA VC v1.0 EN is required.", "CheatMenu", MB_ICONERROR); - } -#endif - } - - return TRUE; -} diff --git a/src/CheatMenu.h b/src/CheatMenu.h index 65c02b6..980cfb0 100644 --- a/src/CheatMenu.h +++ b/src/CheatMenu.h @@ -23,7 +23,10 @@ class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon { private: - inline static CallbackTable header + static inline bool m_bShowMenu = false; + static inline ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); + + static inline CallbackTable header { {"Teleport", &Teleport::Draw}, {"Player", &Player::Draw}, {"Ped", &Ped::Draw}, #ifdef GTASA diff --git a/src/FileHandler.cpp b/src/FileHandler.cpp index 1b62961..630f94b 100644 --- a/src/FileHandler.cpp +++ b/src/FileHandler.cpp @@ -1,6 +1,6 @@ #include "pch.h" -#include "FileHandler.h" -#include "Visual.h" +#include "filehandler.h" +#include "visual.h" // TODO: Clean up this mess, use structures instead? void FileHandler::GenerateHandlingFile(int pHandling, std::map& storeMap) @@ -126,7 +126,7 @@ void FileHandler::FetchColorData(std::vector>& storeVec, } catch (...) { - flog << "Error parsing carcols.dat, " << line << std::endl; + gLog << "Error parsing carcols.dat, " << line << std::endl; } } @@ -156,7 +156,7 @@ void FileHandler::FetchColorData(std::vector>& storeVec, } catch (...) { - flog << "Error parsing carcols.dat, " << line << std::endl; + gLog << "Error parsing carcols.dat, " << line << std::endl; } } } @@ -166,7 +166,7 @@ void FileHandler::FetchColorData(std::vector>& storeVec, } else { - flog << "Carcols.dat not found"; + gLog << "Carcols.dat not found"; } } @@ -212,7 +212,7 @@ void FileHandler::FetchHandlingID(std::map& storeMap) } catch (...) { - flog << "Error parsing vehicles.ide, " << line << std::endl; + gLog << "Error parsing vehicles.ide, " << line << std::endl; } } @@ -220,6 +220,6 @@ void FileHandler::FetchHandlingID(std::map& storeMap) } else { - flog << "Vehicle.ide not found"; + gLog << "Vehicle.ide not found"; } } \ No newline at end of file diff --git a/src/Game.cpp b/src/Game.cpp index e161f7a..c8ac8e1 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,8 +1,8 @@ #include "pch.h" -#include "Menu.h" -#include "Game.h" -#include "Ui.h" -#include "Util.h" +#include "menu.h" +#include "game.h" +#include "ui.h" +#include "util.h" #ifdef GTASA #include #include @@ -90,7 +90,7 @@ Game::Game() #ifdef GTASA if (m_bScreenShot) { - if (Ui::HotKeyPressed(Menu::m_HotKeys::quickSceenShot)) + if (quickSceenShot.Pressed()) { Command(); SetHelpMessage("Screenshot taken", false, false, false); @@ -140,7 +140,7 @@ Game::Game() } } - if (Ui::HotKeyPressed(Menu::m_HotKeys::freeCam)) + if (freeCam.Pressed()) { if (m_Freecam::m_bEnabled) { @@ -267,7 +267,7 @@ void Game::FreeCam() m_Freecam::m_fTotalMouse.y = -150; } - if (Ui::HotKeyPressed(Menu::m_HotKeys::freeCamTeleportPlayer)) + if (freeCamTeleportPlayer.Pressed()) { CPlayerPed* player = FindPlayerPed(-1); CVector pos = m_Freecam::m_pPed->GetPosition(); @@ -490,7 +490,7 @@ Lowers armour, health, stamina etc.")) Command(m_bKeepStuff); } Ui::CheckboxWithHint("Screenshot shortcut", &m_bScreenShot, - (("Take screenshot using ") + Ui::GetHotKeyNameString(Menu::m_HotKeys::quickSceenShot) + (("Take screenshot using ") + quickSceenShot.GetNameString() + "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str()); if (Ui::CheckboxWithHint("Solid water", &m_bSolidWater, "Player can walk on water\nTurn this off if you want to swim.")) diff --git a/src/Game.h b/src/Game.h index 1c5d8c7..bbbd6dd 100644 --- a/src/Game.h +++ b/src/Game.h @@ -3,60 +3,60 @@ class Game { public: - inline static ResourceStore m_MissionData{ "mission", eResourceType::TYPE_TEXT }; + static inline ResourceStore m_MissionData{ "mission", eResourceType::TYPE_TEXT }; #ifdef GTASA - inline static bool m_bForbiddenArea = true; - inline static bool m_bSolidWater; - inline static bool m_bScreenShot; - inline static uint m_nSolidWaterObj; - inline static bool m_bKeepStuff; - inline static ResourceStore m_StatData{ "stat", eResourceType::TYPE_TEXT }; + static inline bool m_bForbiddenArea = true; + static inline bool m_bSolidWater; + static inline bool m_bScreenShot; + static inline uint m_nSolidWaterObj; + static inline bool m_bKeepStuff; + static inline ResourceStore m_StatData{ "stat", eResourceType::TYPE_TEXT }; - inline static std::vector m_DayNames = + static inline std::vector m_DayNames = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; struct m_RandomCheats { - inline static bool m_bEnabled; - inline static bool m_bProgressBar = true; - inline static std::string m_EnabledCheats[92][2]; - inline static int m_nInterval = 10; - inline static CJson m_Json = CJson("cheat name"); - inline static uint m_nTimer; + static inline bool m_bEnabled; + static inline bool m_bProgressBar = true; + static inline std::string m_EnabledCheats[92][2]; + static inline int m_nInterval = 10; + static inline CJson m_Json = CJson("cheat name"); + static inline uint m_nTimer; }; struct m_Freecam { - inline static bool m_bEnabled; - inline static float m_fSpeed = 0.08f; - inline static float m_fFOV = 60.0f; - inline static bool m_bInitDone; - inline static CPed* m_pPed; - inline static int m_nPed = -1; - inline static CVector m_fMouse; - inline static CVector m_fTotalMouse; - inline static BYTE m_bHudState; - inline static BYTE m_bRadarState; + static inline bool m_bEnabled; + static inline float m_fSpeed = 0.08f; + static inline float m_fFOV = 60.0f; + static inline bool m_bInitDone; + static inline CPed* m_pPed; + static inline int m_nPed = -1; + static inline CVector m_fMouse; + static inline CVector m_fTotalMouse; + static inline BYTE m_bHudState; + static inline BYTE m_bRadarState; }; struct m_HardMode { - inline static bool m_bEnabled; - inline static float m_fBacHealth = 0.0f; - inline static float m_fBacMaxHealth = 0.0f; - inline static float m_fBacArmour = 0.0f; - inline static float m_fBacStamina = 0.0f; + static inline bool m_bEnabled; + static inline float m_fBacHealth = 0.0f; + static inline float m_fBacMaxHealth = 0.0f; + static inline float m_fBacArmour = 0.0f; + static inline float m_fBacStamina = 0.0f; }; #endif - inline static bool m_bDisableCheats; - inline static bool m_bDisableReplay; - inline static bool m_bMissionTimer; - inline static bool m_bFreezeTime; - inline static bool m_bSyncTime; - inline static uint m_nSyncTimer; - inline static bool m_bMissionLoaderWarningShown; + static inline bool m_bDisableCheats; + static inline bool m_bDisableReplay; + static inline bool m_bMissionTimer; + static inline bool m_bFreezeTime; + static inline bool m_bSyncTime; + static inline uint m_nSyncTimer; + static inline bool m_bMissionLoaderWarningShown; Game(); static void Draw(); diff --git a/src/Hook.cpp b/src/Hook.cpp index f4e8994..a1f6254 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -1,7 +1,10 @@ #include "pch.h" -#include "Hook.h" +#include "hook.h" #include "../depend/kiero/kiero.h" #include "../depend/kiero/minhook/MinHook.h" +#include "../depend/imgui/imgui_impl_dx9.h" +#include "../depend/imgui/imgui_impl_dx11.h" +#include "../depend/imgui/imgui_impl_win32.h" LRESULT Hook::WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -33,21 +36,23 @@ void Hook::RenderFrame(void* ptr) } ImGuiIO& io = ImGui::GetIO(); + static bool bInit = false; - if (Globals::m_bInit) + if (bInit) { ShowMouse(m_bShowMouse); // handle window scaling here + static ImVec2 fScreenSize = ImVec2(-1, -1); ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight()); - if (Globals::m_fScreenSize.x != size.x && Globals::m_fScreenSize.y != size.y) + if (fScreenSize.x != size.x && fScreenSize.y != size.y) { int fontSize = static_cast(size.y / 54.85f); // manually tested io.FontDefault = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/trebucbd.ttf", fontSize); io.Fonts->Build(); - if (Globals::renderer == Render_DirectX9) + if (gRenderer == Render_DirectX9) { ImGui_ImplDX9_InvalidateDeviceObjects(); } @@ -56,12 +61,6 @@ void Hook::RenderFrame(void* ptr) ImGui_ImplDX11_InvalidateDeviceObjects(); } - if (Globals::m_fScreenSize.x != -1 && Globals::m_fScreenSize.y != -1) - { - Globals::m_fMenuSize.x += (size.x - Globals::m_fScreenSize.x) / 4.0f; - Globals::m_fMenuSize.y += (size.y - Globals::m_fScreenSize.y) / 1.2f; - } - ImGuiStyle* style = &ImGui::GetStyle(); float scaleX = size.x / 1366.0f; float scaleY = size.y / 768.0f; @@ -72,11 +71,11 @@ void Hook::RenderFrame(void* ptr) style->IndentSpacing = 20 * scaleX; style->ItemInnerSpacing = ImVec2(4 * scaleX, 4 * scaleY); - Globals::m_fScreenSize = size; + fScreenSize = size; } ImGui_ImplWin32_NewFrame(); - if (Globals::renderer == Render_DirectX9) + if (gRenderer == Render_DirectX9) { ImGui_ImplDX9_NewFrame(); } @@ -95,7 +94,7 @@ void Hook::RenderFrame(void* ptr) ImGui::EndFrame(); ImGui::Render(); - if (Globals::renderer == Render_DirectX9) + if (gRenderer == Render_DirectX9) { ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); } @@ -106,7 +105,7 @@ void Hook::RenderFrame(void* ptr) } else { - Globals::m_bInit = true; + bInit = true; ImGui::CreateContext(); ImGuiStyle& style = ImGui::GetStyle(); @@ -114,23 +113,22 @@ void Hook::RenderFrame(void* ptr) ImGui_ImplWin32_Init(RsGlobal.ps->window); #ifdef GTASA -// shift trigger fix + // shift trigger fix patch::Nop(0x00531155, 5); #endif - if (Globals::renderer == Render_DirectX9) + if (gRenderer == Render_DirectX9) { - Globals::device = ptr; - ImGui_ImplDX9_Init(reinterpret_cast(Globals::device)); + ImGui_ImplDX9_Init(reinterpret_cast(ptr)); } else { // for dx11 device ptr is swapchain - reinterpret_cast(ptr)->GetDevice(__uuidof(ID3D11Device), &Globals::device); + reinterpret_cast(ptr)->GetDevice(__uuidof(ID3D11Device), &ptr); ID3D11DeviceContext* context; - reinterpret_cast(Globals::device)->GetImmediateContext(&context); + reinterpret_cast(ptr)->GetImmediateContext(&context); - ImGui_ImplDX11_Init(reinterpret_cast(Globals::device), context); + ImGui_ImplDX11_Init(reinterpret_cast(ptr), context); } ImGui_ImplWin32_EnableDpiAwareness(); @@ -192,7 +190,7 @@ Hook::Hook() // Nvidia Overlay crash fix if (init(kiero::RenderType::D3D9) == kiero::Status::Success) { - Globals::renderer = Render_DirectX9; + gRenderer = Render_DirectX9; kiero::bind(16, (void**)&oReset, Reset); kiero::bind(42, (void**)&oEndScene, Dx9Handler); } @@ -201,7 +199,7 @@ Hook::Hook() // gtaRenderHook if (init(kiero::RenderType::D3D11) == kiero::Status::Success) { - Globals::renderer = Render_DirectX11; + gRenderer = Render_DirectX11; kiero::bind(8, (void**)&oPresent11, Dx11Handler); } } diff --git a/src/Hook.h b/src/Hook.h index 0b950cc..128e0b8 100644 --- a/src/Hook.h +++ b/src/Hook.h @@ -10,11 +10,11 @@ extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg class Hook { private: - inline static WNDPROC oWndProc; - inline static f_Present11 oPresent11; - inline static f_EndScene oEndScene; - inline static f_Reset oReset; - inline static bool m_bMouseVisibility; + static inline WNDPROC oWndProc; + static inline f_Present11 oPresent11; + static inline f_EndScene oEndScene; + static inline f_Reset oReset; + static inline bool m_bMouseVisibility; static void CALLBACK RenderFrame(void* ptr); static HRESULT CALLBACK Dx9Handler(IDirect3DDevice9* pDevice); @@ -24,8 +24,8 @@ private: static void ShowMouse(bool state); public: - inline static bool m_bShowMouse = false; - inline static std::function windowCallback = nullptr; + static inline bool m_bShowMouse = false; + static inline std::function windowCallback = nullptr; #ifdef GTASA static void ApplyMouseFix(); diff --git a/src/Json.cpp b/src/Json.cpp index 1768ac7..6a6e5f9 100644 --- a/src/Json.cpp +++ b/src/Json.cpp @@ -1,16 +1,16 @@ #include "pch.h" -#include "Json.h" +#include "json.h" CJson::CJson(const char* name) { - if (name == "" || !fs::is_directory(PLUGIN_PATH((char*)"CheatMenu"))) + if (name == "" || !std::filesystem::is_directory(PLUGIN_PATH((char*)"CheatMenu"))) { return; } m_FilePath = PLUGIN_PATH((char*)"/CheatMenu/json/") + std::string(name) + ".json"; - if (fs::exists(m_FilePath)) + if (std::filesystem::exists(m_FilePath)) { try { @@ -20,7 +20,7 @@ CJson::CJson(const char* name) } catch (...) { - flog << "Error trying to read " << m_FilePath << std::endl; + gLog << "Error trying to read " << m_FilePath << std::endl; m_Data = "{}"_json; } } @@ -30,11 +30,11 @@ CJson::CJson(const char* name) if (m_FilePath.find("config")) { - flog << "Creating config.json file" << std::endl; + gLog << "Creating config.json file" << std::endl; } else { - flog << "Failed to locate file " << m_FilePath << std::endl; + gLog << "Failed to locate file " << m_FilePath << std::endl; } } } diff --git a/src/Json.h b/src/Json.h index eafcd71..579f10a 100644 --- a/src/Json.h +++ b/src/Json.h @@ -1,5 +1,5 @@ #pragma once -#include "../Depend/json.hpp" +#include "../depend/json.hpp" /* Wrapper class for nlohmann::json diff --git a/src/Menu.cpp b/src/Menu.cpp index ec95df5..cfe67fb 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1,68 +1,68 @@ #include "pch.h" -#include "MenuInfo.h" -#include "Menu.h" -#include "Ui.h" -#include "Util.h" -#include "Updater.h" +#include "menuinfo.h" +#include "menu.h" +#include "ui.h" +#include "util.h" +#include "updater.h" #ifdef GTASA -#include "Teleport.h" -#include "Weapon.h" -#include "Vehicle.h" +#include "teleport.h" +#include "weapon.h" +#include "vehicle.h" #endif Menu::Menu() { // TODO: use structs // Load config data - m_Overlay::bCoord = config.GetValue("overlay.coord", false); - m_Overlay::bCpuUsage = config.GetValue("overlay.cpu_usage", false); - m_Overlay::bFPS = config.GetValue("overlay.fps", false); - m_Overlay::bLocName = config.GetValue("overlay.loc_name", false); - m_Overlay::bTransparent = config.GetValue("overlay.transparent", false); - m_Overlay::bMemUsage = config.GetValue("overlay.mem_usage", false); - m_Overlay::bVehHealth = config.GetValue("overlay.veh_health", false); - m_Overlay::bVehSpeed = config.GetValue("overlay.veh_speed", false); - m_Overlay::mSelectedPos = (DISPLAY_POS)config.GetValue("overlay.selected_pos", (int)DISPLAY_POS::BOTTOM_RIGHT); - m_Overlay::fPosX = config.GetValue("overlay.pox", 0); - m_Overlay::fPosY = config.GetValue("overlay.posy", 0); + m_Overlay::bCoord = gConfig.GetValue("overlay.coord", false); + m_Overlay::bCpuUsage = gConfig.GetValue("overlay.cpu_usage", false); + m_Overlay::bFPS = gConfig.GetValue("overlay.fps", false); + m_Overlay::bLocName = gConfig.GetValue("overlay.loc_name", false); + m_Overlay::bTransparent = gConfig.GetValue("overlay.transparent", false); + m_Overlay::bMemUsage = gConfig.GetValue("overlay.mem_usage", false); + m_Overlay::bVehHealth = gConfig.GetValue("overlay.veh_health", false); + m_Overlay::bVehSpeed = gConfig.GetValue("overlay.veh_speed", false); + m_Overlay::mSelectedPos = (DISPLAY_POS)gConfig.GetValue("overlay.selected_pos", (int)DISPLAY_POS::BOTTOM_RIGHT); + m_Overlay::fPosX = gConfig.GetValue("overlay.pox", 0); + m_Overlay::fPosY = gConfig.GetValue("overlay.posy", 0); // Hotkeys - m_HotKeys::aimSkinChanger.m_key1 = config.GetValue("hotkey.aim_skin_changer.key1", VK_RETURN); - m_HotKeys::aimSkinChanger.m_key2 = config.GetValue("hotkey.aim_skin_changer.key2", VK_RETURN); + aimSkinChanger.m_key1 = gConfig.GetValue("hotkey.aim_skin_changer.key1", VK_RETURN); + aimSkinChanger.m_key2 = gConfig.GetValue("hotkey.aim_skin_changer.key2", VK_RETURN); - m_HotKeys::freeCam.m_key1 = config.GetValue("hotkey.freecam.key1", VK_F6); - m_HotKeys::freeCam.m_key2 = config.GetValue("hotkey.freecam.key2", VK_F6); + freeCam.m_key1 = gConfig.GetValue("hotkey.freecam.key1", VK_F6); + freeCam.m_key2 = gConfig.GetValue("hotkey.freecam.key2", VK_F6); - m_HotKeys::quickSceenShot.m_key1 = config.GetValue("hotkey.quick_screenshot.key1", VK_F5); - m_HotKeys::quickSceenShot.m_key2 = config.GetValue("hotkey.quick_screenshot.key2", VK_F5); + quickSceenShot.m_key1 = gConfig.GetValue("hotkey.quick_screenshot.key1", VK_F5); + quickSceenShot.m_key2 = gConfig.GetValue("hotkey.quick_screenshot.key2", VK_F5); - m_HotKeys::quickTeleport.m_key1 = config.GetValue("hotkey.quick_tp.key1", VK_KEY_X); - m_HotKeys::quickTeleport.m_key2 = config.GetValue("hotkey.quick_tp.key2", VK_KEY_Y); + quickTeleport.m_key1 = gConfig.GetValue("hotkey.quick_tp.key1", VK_KEY_X); + quickTeleport.m_key2 = gConfig.GetValue("hotkey.quick_tp.key2", VK_KEY_Y); - m_HotKeys::menuOpen.m_key1 = config.GetValue("hotkey.menu_open.key1", VK_LCONTROL); - m_HotKeys::menuOpen.m_key2 = config.GetValue("hotkey.menu_open.key2", VK_KEY_M); + menuOpen.m_key1 = gConfig.GetValue("hotkey.menu_open.key1", VK_LCONTROL); + menuOpen.m_key2 = gConfig.GetValue("hotkey.menu_open.key2", VK_KEY_M); - m_HotKeys::commandWindow.m_key1 = config.GetValue("hotkey.command_window.key1", VK_LMENU); - m_HotKeys::commandWindow.m_key2 = config.GetValue("hotkey.command_window.key2", VK_KEY_C); + commandWindow.m_key1 = gConfig.GetValue("hotkey.command_window.key1", VK_LMENU); + commandWindow.m_key2 = gConfig.GetValue("hotkey.command_window.key2", VK_KEY_C); - m_HotKeys::flipVeh.m_key1 = config.GetValue("hotkey.flip_veh.key1", VK_NONE); - m_HotKeys::flipVeh.m_key2 = config.GetValue("hotkey.flip_veh.key2", VK_NONE); + flipVeh.m_key1 = gConfig.GetValue("hotkey.flip_veh.key1", VK_NONE); + flipVeh.m_key2 = gConfig.GetValue("hotkey.flip_veh.key2", VK_NONE); - m_HotKeys::fixVeh.m_key1 = config.GetValue("hotkey.fix_veh.key1", VK_NONE); - m_HotKeys::fixVeh.m_key2 = config.GetValue("hotkey.fix_veh.key2", VK_NONE); + fixVeh.m_key1 = gConfig.GetValue("hotkey.fix_veh.key1", VK_NONE); + fixVeh.m_key2 = gConfig.GetValue("hotkey.fix_veh.key2", VK_NONE); - m_HotKeys::godMode.m_key1 = config.GetValue("hotkey.god_mode.key1", VK_NONE); - m_HotKeys::godMode.m_key2 = config.GetValue("hotkey.god_mode.key2", VK_NONE); + godMode.m_key1 = gConfig.GetValue("hotkey.god_mode.key1", VK_NONE); + godMode.m_key2 = gConfig.GetValue("hotkey.god_mode.key2", VK_NONE); - m_HotKeys::vehEngine.m_key1 = config.GetValue("hotkey.veh_engine.key1", VK_NONE); - m_HotKeys::vehEngine.m_key2 = config.GetValue("hotkey.veh_engine.key2", VK_NONE); + vehEngine.m_key1 = gConfig.GetValue("hotkey.veh_engine.key1", VK_NONE); + vehEngine.m_key2 = gConfig.GetValue("hotkey.veh_engine.key2", VK_NONE); - m_HotKeys::vehInstantStart.m_key1 = config.GetValue("hotkey.veh_instant_start.key1", VK_NONE); - m_HotKeys::vehInstantStart.m_key2 = config.GetValue("hotkey.veh_instant_start.key2", VK_NONE); + vehInstantStart.m_key1 = gConfig.GetValue("hotkey.veh_instant_start.key1", VK_NONE); + vehInstantStart.m_key2 = gConfig.GetValue("hotkey.veh_instant_start.key2", VK_NONE); - m_HotKeys::vehInstantStop.m_key1 = config.GetValue("hotkey.veh_instant_stop.key1", VK_NONE); - m_HotKeys::vehInstantStop.m_key2 = config.GetValue("hotkey.veh_instant_stop.key2", VK_NONE); + vehInstantStop.m_key1 = gConfig.GetValue("hotkey.veh_instant_stop.key1", VK_NONE); + vehInstantStop.m_key2 = gConfig.GetValue("hotkey.veh_instant_stop.key2", VK_NONE); Util::GetCPUUsageInit(); MEMORYSTATUSEX memInfo; @@ -74,122 +74,126 @@ Menu::Menu() void Menu::DrawOverlay() { - CPlayerPed* player = FindPlayerPed(); - bool m_bShowMenu = m_Overlay::bCoord || m_Overlay::bFPS || m_Overlay::bLocName || m_Overlay::bCpuUsage || m_Overlay::bMemUsage || - ((m_Overlay::bVehHealth || m_Overlay::bVehSpeed) && player && player->m_pVehicle && player->m_pVehicle->IsDriver(player)); - - const float offset = 10.0f; - ImGuiIO& io = ImGui::GetIO(); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; - - if (m_Overlay::mSelectedPos == DISPLAY_POS::CUSTOM) + CPlayerPed* pPlayer = FindPlayerPed(); + if (pPlayer) { - if (m_Overlay::fPosX != NULL && m_Overlay::fPosY != NULL) + bool m_bShowMenu = m_Overlay::bCoord || m_Overlay::bFPS || m_Overlay::bLocName || m_Overlay::bCpuUsage || m_Overlay::bMemUsage || + ((m_Overlay::bVehHealth || m_Overlay::bVehSpeed) && pPlayer && pPlayer->m_pVehicle && pPlayer->m_pVehicle->IsDriver(pPlayer)); + + const float offset = 10.0f; + ImGuiIO& io = ImGui::GetIO(); + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; + + if (m_Overlay::mSelectedPos == DISPLAY_POS::CUSTOM) { - config.SetValue("overlay.posx", m_Overlay::fPosX); - config.SetValue("overlay.posy", m_Overlay::fPosY); - ImGui::SetNextWindowPos(ImVec2(m_Overlay::fPosX, m_Overlay::fPosY), ImGuiCond_Once); - } - } - else - { - window_flags |= ImGuiWindowFlags_NoMove; - ImVec2 pos, pivot; - - if (m_Overlay::mSelectedPos == DISPLAY_POS::TOP_LEFT) - { - pos = ImVec2(offset, offset); - pivot = ImVec2(0.0f, 0.0f); - } - - if (m_Overlay::mSelectedPos == DISPLAY_POS::TOP_RIGHT) - { - pos = ImVec2(io.DisplaySize.x - offset, offset); - pivot = ImVec2(1.0f, 0.0f); - } - - if (m_Overlay::mSelectedPos == DISPLAY_POS::BOTTOM_LEFT) - { - pos = ImVec2(offset, io.DisplaySize.y - offset); - pivot = ImVec2(0.0f, 1.0f); - } - - if (m_Overlay::mSelectedPos == DISPLAY_POS::BOTTOM_RIGHT) - { - pos = ImVec2(io.DisplaySize.x - offset, io.DisplaySize.y - offset); - pivot = ImVec2(1.0f, 1.0f); - } - - ImGui::SetNextWindowPos(pos, ImGuiCond_Always, pivot); - } - - ImGui::SetNextWindowBgAlpha(m_Overlay::bTransparent ? 0.0f : 0.5f); - - if (m_bShowMenu && ImGui::Begin("Overlay", nullptr, window_flags)) - { - CVector pos{0,0,0}; - if (player) - { - pos = player->GetPosition(); - } - - size_t game_ms = CTimer::m_snTimeInMilliseconds; - - if (game_ms - m_Overlay::mLastInterval > m_Overlay::mInterval) - { - m_Overlay::fCpuUsage = static_cast(Util::GetCurrentCPUUsage()); - - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&memInfo); - int mUsedRam = static_cast((memInfo.ullTotalPhys - memInfo.ullAvailPhys) * 1e-6); - m_Overlay::fMemUsage = 100.0f * (static_cast(mUsedRam) / static_cast(m_Overlay::mTotalRam)); - - m_Overlay::mFPS = static_cast - ( - #ifdef GTASA - CTimer::game_FPS - #elif GTAVC - io.Framerate - #endif - ); - - m_Overlay::mLastInterval = game_ms; - } - - if (m_Overlay::bCoord) - ImGui::Text("Coord: %.2f, %.2f, %.2f", pos.x, pos.y, pos.z); - - if (m_Overlay::bCpuUsage) - ImGui::Text("CPU usage: %.2f%%", m_Overlay::fCpuUsage); - - if (m_Overlay::bFPS) - ImGui::Text("Frames: %d", m_Overlay::mFPS); - - if (m_Overlay::bLocName) - ImGui::Text("Location: %s", Util::GetLocationName(&pos).c_str()); - - if (m_Overlay::bMemUsage) - ImGui::Text("RAM usage: %.2f%%", m_Overlay::fMemUsage); - - if (player && player->m_pVehicle && player->m_pVehicle->IsDriver(player)) - { - if (m_Overlay::bVehHealth) - ImGui::Text("Veh Health: %.f", player->m_pVehicle->m_fHealth); - - if (m_Overlay::bVehSpeed) + if (m_Overlay::fPosX != NULL && m_Overlay::fPosY != NULL) { - int speed = player->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50.0f; // 02E3 - GET_CAR_SPEED - ImGui::Text("Veh Speed: %d", speed); + gConfig.SetValue("overlay.posx", m_Overlay::fPosX); + gConfig.SetValue("overlay.posy", m_Overlay::fPosY); + ImGui::SetNextWindowPos(ImVec2(m_Overlay::fPosX, m_Overlay::fPosY), ImGuiCond_Once); } } + else + { + window_flags |= ImGuiWindowFlags_NoMove; + ImVec2 pos, pivot; - ImVec2 windowPos = ImGui::GetWindowPos(); - m_Overlay::fPosX = windowPos.x; - m_Overlay::fPosY = windowPos.y; + if (m_Overlay::mSelectedPos == DISPLAY_POS::TOP_LEFT) + { + pos = ImVec2(offset, offset); + pivot = ImVec2(0.0f, 0.0f); + } - ImGui::End(); + if (m_Overlay::mSelectedPos == DISPLAY_POS::TOP_RIGHT) + { + pos = ImVec2(io.DisplaySize.x - offset, offset); + pivot = ImVec2(1.0f, 0.0f); + } + + if (m_Overlay::mSelectedPos == DISPLAY_POS::BOTTOM_LEFT) + { + pos = ImVec2(offset, io.DisplaySize.y - offset); + pivot = ImVec2(0.0f, 1.0f); + } + + if (m_Overlay::mSelectedPos == DISPLAY_POS::BOTTOM_RIGHT) + { + pos = ImVec2(io.DisplaySize.x - offset, io.DisplaySize.y - offset); + pivot = ImVec2(1.0f, 1.0f); + } + + ImGui::SetNextWindowPos(pos, ImGuiCond_Always, pivot); + } + + ImGui::SetNextWindowBgAlpha(m_Overlay::bTransparent ? 0.0f : 0.5f); + + if (m_bShowMenu && ImGui::Begin("Overlay", nullptr, window_flags)) + { + CVector pos{0,0,0}; + pos = pPlayer->GetPosition(); + + size_t game_ms = CTimer::m_snTimeInMilliseconds; + + if (game_ms - m_Overlay::mLastInterval > m_Overlay::mInterval) + { + m_Overlay::fCpuUsage = static_cast(Util::GetCurrentCPUUsage()); + + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&memInfo); + int mUsedRam = static_cast((memInfo.ullTotalPhys - memInfo.ullAvailPhys) * 1e-6); + m_Overlay::fMemUsage = 100.0f * (static_cast(mUsedRam) / static_cast(m_Overlay::mTotalRam)); + + m_Overlay::mFPS = static_cast(BY_GAME(CTimer::game_FPS, io.Framerate)); + m_Overlay::mLastInterval = game_ms; + } + + if (m_Overlay::bCoord) + { + ImGui::Text("Coord: %.2f, %.2f, %.2f", pos.x, pos.y, pos.z); + } + + if (m_Overlay::bCpuUsage) + { + ImGui::Text("CPU usage: %.2f%%", m_Overlay::fCpuUsage); + } + + if (m_Overlay::bFPS) + { + ImGui::Text("Frames: %d", m_Overlay::mFPS); + } + + if (m_Overlay::bLocName) + { + ImGui::Text("Location: %s", Util::GetLocationName(&pos).c_str()); + } + + if (m_Overlay::bMemUsage) + { + ImGui::Text("RAM usage: %.2f%%", m_Overlay::fMemUsage); + } + + if (pPlayer->m_pVehicle && pPlayer->m_pVehicle->IsDriver(pPlayer)) + { + if (m_Overlay::bVehHealth) + { + ImGui::Text("Veh Health: %.f", pPlayer->m_pVehicle->m_fHealth); + } + + if (m_Overlay::bVehSpeed) + { + int speed = pPlayer->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50.0f; // 02E3 - GET_CAR_SPEED + ImGui::Text("Veh Speed: %d", speed); + } + } + + ImVec2 windowPos = ImGui::GetWindowPos(); + m_Overlay::fPosX = windowPos.x; + m_Overlay::fPosY = windowPos.y; + + ImGui::End(); + } } } @@ -345,36 +349,36 @@ void Menu::Draw() ImGui::Spacing(); ImGui::SameLine(); if (Ui::ListBox("Overlay", m_Overlay::posNames, (int&)m_Overlay::mSelectedPos)) - config.SetValue("overlay.selected_pos", m_Overlay::mSelectedPos); + gConfig.SetValue("overlay.selected_pos", m_Overlay::mSelectedPos); ImGui::Spacing(); ImGui::Columns(2, nullptr, false); if (ImGui::Checkbox("No background", &m_Overlay::bTransparent)) - config.SetValue("overlay.transparent", m_Overlay::bTransparent); + gConfig.SetValue("overlay.transparent", m_Overlay::bTransparent); if (ImGui::Checkbox("Show coordinates", &m_Overlay::bCoord)) - config.SetValue("overlay.coord", m_Overlay::bCoord); + gConfig.SetValue("overlay.coord", m_Overlay::bCoord); if (ImGui::Checkbox("Show CPU usage", &m_Overlay::bCpuUsage)) - config.SetValue("overlay.cpu_usage", m_Overlay::bCpuUsage); + gConfig.SetValue("overlay.cpu_usage", m_Overlay::bCpuUsage); if (ImGui::Checkbox("Show FPS", &m_Overlay::bFPS)) - config.SetValue("overlay.fps", m_Overlay::bFPS); + gConfig.SetValue("overlay.fps", m_Overlay::bFPS); ImGui::NextColumn(); if (ImGui::Checkbox("Show location", &m_Overlay::bLocName)) - config.SetValue("overlay.loc_name", m_Overlay::bLocName); + gConfig.SetValue("overlay.loc_name", m_Overlay::bLocName); if (ImGui::Checkbox("Show RAM usage", &m_Overlay::bMemUsage)) - config.SetValue("overlay.mem_usage", m_Overlay::bMemUsage); + gConfig.SetValue("overlay.mem_usage", m_Overlay::bMemUsage); if (ImGui::Checkbox("Show veh health", &m_Overlay::bVehHealth)) - config.SetValue("overlay.veh_health", m_Overlay::bVehHealth); + gConfig.SetValue("overlay.veh_health", m_Overlay::bVehHealth); if (ImGui::Checkbox("Show veh speed", &m_Overlay::bVehSpeed)) - config.SetValue("overlay.veh_speed", m_Overlay::bVehSpeed); + gConfig.SetValue("overlay.veh_speed", m_Overlay::bVehSpeed); ImGui::Columns(1); @@ -388,76 +392,76 @@ void Menu::Draw() "\nRight click disables hotkey."); ImGui::Spacing(); ImGui::BeginChild("Hotkeys"); - if (Ui::HotKey("Open/ close cheat menu", m_HotKeys::menuOpen)) + if (menuOpen.DrawUI("Open/ close cheat menu")) { - config.SetValue("hotkey.menu_open.key1", m_HotKeys::menuOpen.m_key1); - config.SetValue("hotkey.menu_open.key2", m_HotKeys::menuOpen.m_key2); + gConfig.SetValue("hotkey.menu_open.key1", menuOpen.m_key1); + gConfig.SetValue("hotkey.menu_open.key2", menuOpen.m_key2); } - if (Ui::HotKey("Open/ close command window", m_HotKeys::commandWindow)) + if (commandWindow.DrawUI("Open/ close command window")) { - config.SetValue("hotkey.command_window.key1", m_HotKeys::commandWindow.m_key1); - config.SetValue("hotkey.command_window.key2", m_HotKeys::commandWindow.m_key2); + gConfig.SetValue("hotkey.command_window.key1", commandWindow.m_key1); + gConfig.SetValue("hotkey.command_window.key2", commandWindow.m_key2); } ImGui::Dummy(ImVec2(0, 10)); - if (Ui::HotKey("Activate aim skin changer", m_HotKeys::aimSkinChanger)) + if (aimSkinChanger.DrawUI("Activate aim skin changer")) { - config.SetValue("hotkey.aim_skin_changer.key1", m_HotKeys::aimSkinChanger.m_key1); - config.SetValue("hotkey.aim_skin_changer.key2", m_HotKeys::aimSkinChanger.m_key2); + gConfig.SetValue("hotkey.aim_skin_changer.key1", aimSkinChanger.m_key1); + gConfig.SetValue("hotkey.aim_skin_changer.key2", aimSkinChanger.m_key2); } - if (Ui::HotKey("Freecam", m_HotKeys::freeCam)) + if (freeCam.DrawUI("Freecam")) { - config.SetValue("hotkey.freecam.key1", m_HotKeys::freeCam.m_key1); - config.SetValue("hotkey.freecam.key2", m_HotKeys::freeCam.m_key2); + gConfig.SetValue("hotkey.freecam.key1", freeCam.m_key1); + gConfig.SetValue("hotkey.freecam.key2", freeCam.m_key2); } - if (Ui::HotKey("Take quick screenshot", m_HotKeys::quickSceenShot)) + if (quickSceenShot.DrawUI("Take quick screenshot")) { - config.SetValue("hotkey.quick_screenshot.key1", m_HotKeys::quickSceenShot.m_key1); - config.SetValue("hotkey.quick_screenshot.key2", m_HotKeys::quickSceenShot.m_key2); + gConfig.SetValue("hotkey.quick_screenshot.key1", quickSceenShot.m_key1); + gConfig.SetValue("hotkey.quick_screenshot.key2", quickSceenShot.m_key2); } - if (Ui::HotKey("Toggle quick teleport", m_HotKeys::quickTeleport)) + if (quickTeleport.DrawUI("Toggle quick teleport")) { - config.SetValue("hotkey.quick_tp.key1", m_HotKeys::quickTeleport.m_key1); - config.SetValue("hotkey.quick_tp.key2", m_HotKeys::quickTeleport.m_key2); + gConfig.SetValue("hotkey.quick_tp.key1", quickTeleport.m_key1); + gConfig.SetValue("hotkey.quick_tp.key2", quickTeleport.m_key2); } ImGui::Dummy(ImVec2(0, 10)); - if (Ui::HotKey("Fix current vehicle", m_HotKeys::fixVeh)) + if (fixVeh.DrawUI("Fix current vehicle")) { - config.SetValue("hotkey.fix_veh.key1", m_HotKeys::fixVeh.m_key1); - config.SetValue("hotkey.fix_veh.key2", m_HotKeys::fixVeh.m_key2); + gConfig.SetValue("hotkey.fix_veh.key1", fixVeh.m_key1); + gConfig.SetValue("hotkey.fix_veh.key2", fixVeh.m_key2); } - if (Ui::HotKey("Flip current vehicle", m_HotKeys::flipVeh)) + if (flipVeh.DrawUI("Flip current vehicle")) { - config.SetValue("hotkey.flip_veh.key1", m_HotKeys::flipVeh.m_key1); - config.SetValue("hotkey.flip_veh.key2", m_HotKeys::flipVeh.m_key2); + gConfig.SetValue("hotkey.flip_veh.key1", flipVeh.m_key1); + gConfig.SetValue("hotkey.flip_veh.key2", flipVeh.m_key2); } - if (Ui::HotKey("Toggle god mode", m_HotKeys::godMode)) + if (godMode.DrawUI("Toggle god mode")) { - config.SetValue("hotkey.god_mode.key1", m_HotKeys::godMode.m_key1); - config.SetValue("hotkey.god_mode.key2", m_HotKeys::godMode.m_key2); + gConfig.SetValue("hotkey.god_mode.key1", godMode.m_key1); + gConfig.SetValue("hotkey.god_mode.key2", godMode.m_key2); } - if (Ui::HotKey("Toggle veh engine", m_HotKeys::vehEngine)) + if (vehEngine.DrawUI("Toggle veh engine")) { - config.SetValue("hotkey.veh_engine.key1", m_HotKeys::vehEngine.m_key1); - config.SetValue("hotkey.veh_engine.key2", m_HotKeys::vehEngine.m_key2); + gConfig.SetValue("hotkey.veh_engine.key1", vehEngine.m_key1); + gConfig.SetValue("hotkey.veh_engine.key2", vehEngine.m_key2); } - if (Ui::HotKey("Vehicle instant start", m_HotKeys::vehInstantStart)) + if (vehInstantStart.DrawUI("Vehicle instant start")) { - config.SetValue("hotkey.veh_instant_start.key1", m_HotKeys::vehInstantStart.m_key1); - config.SetValue("hotkey.veh_instant_start.key2", m_HotKeys::vehInstantStart.m_key2); + gConfig.SetValue("hotkey.veh_instant_start.key1", vehInstantStart.m_key1); + gConfig.SetValue("hotkey.veh_instant_start.key2", vehInstantStart.m_key2); } - if (Ui::HotKey("Vehicle instant stop", m_HotKeys::vehInstantStop)) + if (vehInstantStop.DrawUI("Vehicle instant stop")) { - config.SetValue("hotkey.veh_instant_stop.key1", m_HotKeys::vehInstantStop.m_key1); - config.SetValue("hotkey.veh_instant_stop.key2", m_HotKeys::vehInstantStop.m_key2); + gConfig.SetValue("hotkey.veh_instant_stop.key1", vehInstantStop.m_key1); + gConfig.SetValue("hotkey.veh_instant_stop.key2", vehInstantStop.m_key2); } ImGui::Dummy(ImVec2(0, 10)); @@ -469,10 +473,7 @@ void Menu::Draw() { if (ImGui::BeginChild("CommandsChild")) { - ImGui::TextWrapped( - std::string( - "Open or close command window using " + Ui::GetHotKeyNameString(m_HotKeys::commandWindow)). - c_str()); + ImGui::TextWrapped("Open or close command window using %s", commandWindow.GetNameString()); ImGui::Spacing(); if (ImGui::CollapsingHeader("Set health")) { @@ -515,7 +516,9 @@ void Menu::Draw() if (ImGui::Button("Check update", ImVec2(Ui::GetSize(3)))) { if (Updater::m_State == UPDATER_IDLE) + { Updater::m_State = UPDATER_CHECKING; + } } ImGui::SameLine(); diff --git a/src/Menu.h b/src/Menu.h index 60c3248..7cc3383 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -15,50 +15,33 @@ private: struct m_Overlay { - inline static bool bCoord = false; - inline static bool bFPS = false; - inline static int mFPS = 0; - inline static bool bLocName = false; - inline static bool bTransparent = false; - inline static bool bVehHealth = false; - inline static bool bVehSpeed = false; - inline static bool bCpuUsage = false; - inline static float fCpuUsage = 0.0f; - inline static bool bMemUsage = false; - inline static float fMemUsage = 0.0f; - inline static std::vector posNames = { + static inline bool bCoord = false; + static inline bool bFPS = false; + static inline int mFPS = 0; + static inline bool bLocName = false; + static inline bool bTransparent = false; + static inline bool bVehHealth = false; + static inline bool bVehSpeed = false; + static inline bool bCpuUsage = false; + static inline float fCpuUsage = 0.0f; + static inline bool bMemUsage = false; + static inline float fMemUsage = 0.0f; + static inline std::vector posNames = { "Custom", "Top left", "Top right", "Bottom left", "Bottom right" }; - inline static DISPLAY_POS mSelectedPos = DISPLAY_POS::BOTTOM_RIGHT; - inline static float fPosX = 0.0f; - inline static float fPosY = 0.0f; - inline static size_t mInterval = 1000; - inline static size_t mLastInterval = 0; - inline static int mTotalRam = 0; + static inline DISPLAY_POS mSelectedPos = DISPLAY_POS::BOTTOM_RIGHT; + static inline float fPosX = 0.0f; + static inline float fPosY = 0.0f; + static inline size_t mInterval = 1000; + static inline size_t mLastInterval = 0; + static inline int mTotalRam = 0; }; public: - struct m_HotKeys - { - inline static HotKeyData aimSkinChanger; - inline static HotKeyData freeCam; - inline static HotKeyData commandWindow; - inline static HotKeyData fixVeh; - inline static HotKeyData flipVeh; - inline static HotKeyData freeCamTeleportPlayer{VK_RETURN,VK_RETURN}; - inline static HotKeyData godMode; - inline static HotKeyData menuOpen; - inline static HotKeyData quickSceenShot; - inline static HotKeyData quickTeleport; - inline static HotKeyData vehEngine; - inline static HotKeyData vehInstantStart; - inline static HotKeyData vehInstantStop; - }; - struct m_Commands { - inline static bool m_bShowMenu = false; - inline static char m_nInputBuffer[INPUT_BUFFER_SIZE] = ""; + static inline bool m_bShowMenu = false; + static inline char m_nInputBuffer[INPUT_BUFFER_SIZE] = ""; }; Menu(); diff --git a/src/MenuInfo.h b/src/MenuInfo.h index 1f04f73..27f896c 100644 --- a/src/MenuInfo.h +++ b/src/MenuInfo.h @@ -2,5 +2,5 @@ #define MENU_NAME "Cheat Menu" #define MENU_VERSION_NUMBER "3.0" #define MENU_VERSION MENU_VERSION_NUMBER"-beta" -#define BUILD_NUMBER "20210913" +#define BUILD_NUMBER "20210920" #define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" diff --git a/src/MoreEvents.cpp b/src/MoreEvents.cpp deleted file mode 100644 index 19f912a..0000000 --- a/src/MoreEvents.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "pch.h" -#include "Events.h" - -namespace plugin::Events -{ - decltype(vehicleResetAfterRender) vehicleResetAfterRender; -} diff --git a/src/MoreEvents.h b/src/MoreEvents.h deleted file mode 100644 index 980a9cb..0000000 --- a/src/MoreEvents.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace plugin::Events -{ - extern ThiscallEvent, PRIORITY_BEFORE, ArgPickN, void(CVehicle*)> - vehicleResetAfterRender; -} diff --git a/src/Neon.cpp b/src/Neon.cpp index 1c7e548..27f3863 100644 --- a/src/Neon.cpp +++ b/src/Neon.cpp @@ -1,7 +1,8 @@ #include "pch.h" -#include "Neon.h" -#include "Util.h" +#include "neon.h" +#include "util.h" +// Neon sprite const unsigned char neon_mask[1689] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, @@ -160,57 +161,60 @@ const unsigned char neon_mask[1689] = 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 }; -void Neon::RenderEvent(CVehicle* pVeh) -{ - NeonData* data = &m_VehNeon.Get(pVeh); - if (data->m_bNeonInstalled && !pVeh->IsUpsideDown()) - { - CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin; - CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); - CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->m_fVal, 0.0f)) - center; - CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->m_fVal, 0.0f, 0.0f)) - center; - CShadows::StoreShadowToBeRendered(5, m_pNeonTexture, ¢er, up.x, up.y, right.x, right.y, 180, data->m_Color.r, - data->m_Color.g, data->m_Color.b, 2.0f, false, 1.0f, 0, true); - - if (CTimer::m_snTimeInMilliseconds - data->m_nTimer > 150) - { - data->m_nTimer = CTimer::m_snTimeInMilliseconds; - - if (data->m_bPulsing) - { - if (data->m_fVal < 0.0f) - data->m_bIncrement = true; - - if (data->m_fVal > 0.3f) - data->m_bIncrement = false; - - if (data->m_bIncrement) - data->m_fVal += 0.1f; - else - data->m_fVal -= 0.1f; - } - } - } -} - Neon::Neon() { Events::processScriptsEvent += [this] { - if (!m_bMaskLoaded) + if (!m_pNeonTexture) { m_pNeonTexture = Util::LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask)); - m_bMaskLoaded = true; } }; - Events::vehicleRenderEvent += RenderEvent; + Events::vehicleRenderEvent += [](CVehicle* pVeh) + { + NeonData* data = &m_VehNeon.Get(pVeh); + if (data->m_bNeonInstalled && !pVeh->IsUpsideDown()) + { + CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin; + CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); + CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->m_fVal, 0.0f)) - center; + CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->m_fVal, 0.0f, 0.0f)) - center; + CShadows::StoreShadowToBeRendered(5, m_pNeonTexture, ¢er, up.x, up.y, right.x, right.y, 180, data->m_Color.r, + data->m_Color.g, data->m_Color.b, 2.0f, false, 1.0f, 0, true); + + if (CTimer::m_snTimeInMilliseconds - data->m_nTimer > 150) + { + data->m_nTimer = CTimer::m_snTimeInMilliseconds; + + if (data->m_bPulsing) + { + if (data->m_fVal < 0.0f) + { + data->m_bIncrement = true; + } + + if (data->m_fVal > 0.3f) + { + data->m_bIncrement = false; + } + + if (data->m_bIncrement) + { + data->m_fVal += 0.1f; + } + else + { + data->m_fVal -= 0.1f; + } + } + } + } + }; } Neon::~Neon() { - Events::vehicleRenderEvent -= RenderEvent; - if (m_pNeonTexture) { RwTextureDestroy(m_pNeonTexture); diff --git a/src/Neon.h b/src/Neon.h index 4a5e0d7..8829433 100644 --- a/src/Neon.h +++ b/src/Neon.h @@ -23,9 +23,8 @@ private: } }; - inline static bool m_bMaskLoaded = false; - inline static RwTexture* m_pNeonTexture = nullptr; - inline static VehicleExtendedData m_VehNeon; + static inline RwTexture* m_pNeonTexture = nullptr; // pointer to the neon mask texture + static inline VehicleExtendedData m_VehNeon; public: Neon(); @@ -35,5 +34,4 @@ public: static bool IsPulsingEnabled(CVehicle* veh); static void SetPulsing(CVehicle* veh, bool state); static void RemoveNeon(CVehicle* veh); - static void RenderEvent(CVehicle* veh); }; diff --git a/src/Paint.cpp b/src/Paint.cpp index 437906b..6df54e9 100644 --- a/src/Paint.cpp +++ b/src/Paint.cpp @@ -23,76 +23,68 @@ // SOFTWARE. #include "pch.h" -#include "Paint.h" +#include "paint.h" #include "NodeName.h" -#include "Util.h" - -void Paint::RenderEvent(CVehicle* pVeh) -{ - VehData& data = m_VehData.Get(pVeh); - - // reset custom color if color id changed - if (pVeh->m_nPrimaryColor != data.primary_color - || pVeh->m_nSecondaryColor != data.secondary_color) - { - for (auto& it : data.materialProperties) - data.resetMaterialColor(it.first); - - data.primary_color = pVeh->m_nPrimaryColor; - data.secondary_color = pVeh->m_nSecondaryColor; - } - - for (auto& it : data.materialProperties) - { - if (it.second._recolor) - { - it.second._originalColor = it.first->color; - it.first->color = it.second._color; - it.second._originalGeometryFlags = it.second._geometry->flags; - it.second._geometry->flags |= rpGEOMETRYMODULATEMATERIALCOLOR; - } - if (it.second._retexture) - { - auto tex = it.second._texture; - if (tex) - { - it.second._originalTexture = it.first->texture; - it.first->texture = tex; - } - else - { - it.second._retexture = false; - } - } - } -} - -void Paint::ResetAfterRenderEvent(CVehicle* pVeh) -{ - for (auto& it : m_VehData.Get(pVeh).materialProperties) - { - if (it.second._recolor) - { - it.first->color = it.second._originalColor; - it.second._geometry->flags = it.second._originalGeometryFlags; - } - if (it.second._retexture) - { - it.first->texture = it.second._originalTexture; - } - } -} +#include "util.h" Paint::Paint() { - Events::vehicleRenderEvent.before += RenderEvent; - Events::vehicleResetAfterRender += ResetAfterRenderEvent; -} + Events::vehicleRenderEvent.before += [](CVehicle* pVeh) + { + VehData& data = m_VehData.Get(pVeh); -Paint::~Paint() -{ - Events::vehicleRenderEvent.before -= RenderEvent; - Events::vehicleResetAfterRender -= ResetAfterRenderEvent; + // reset custom color if color id changed + if (pVeh->m_nPrimaryColor != data.primary_color + || pVeh->m_nSecondaryColor != data.secondary_color) + { + for (auto& it : data.materialProperties) + data.resetMaterialColor(it.first); + + data.primary_color = pVeh->m_nPrimaryColor; + data.secondary_color = pVeh->m_nSecondaryColor; + } + + for (auto& it : data.materialProperties) + { + if (it.second._recolor) + { + it.second._originalColor = it.first->color; + it.first->color = it.second._color; + it.second._originalGeometryFlags = it.second._geometry->flags; + it.second._geometry->flags |= rpGEOMETRYMODULATEMATERIALCOLOR; + } + if (it.second._retexture) + { + auto tex = it.second._texture; + if (tex) + { + it.second._originalTexture = it.first->texture; + it.first->texture = tex; + } + else + { + it.second._retexture = false; + } + } + } + }; + + ThiscallEvent, PRIORITY_BEFORE, ArgPickN, void(CVehicle*)> vehicleResetAfterRender; + vehicleResetAfterRender += [](CVehicle* pVeh) + { + for (auto& it : m_VehData.Get(pVeh).materialProperties) + { + if (it.second._recolor) + { + it.first->color = it.second._originalColor; + it.second._geometry->flags = it.second._originalGeometryFlags; + } + if (it.second._retexture) + { + it.first->texture = it.second._originalTexture; + } + } + }; } void Paint::VehData::setMaterialColor(RpMaterial* material, RpGeometry* geometry, RwRGBA color, bool filter_mat) diff --git a/src/Paint.h b/src/Paint.h index 4d4fee8..fe4552d 100644 --- a/src/Paint.h +++ b/src/Paint.h @@ -1,5 +1,4 @@ // Portion of this source is taken from MoonAdditions https://github.com/THE-FYP/MoonAdditions -// To keep the licensing simple this file would go under MIT License, GPLv3 won't apply // Copyright (c) 2012 DK22Pac // Copyright (c) 2017 FYP @@ -70,25 +69,22 @@ private: void resetMaterialColor(RpMaterial* material); void resetMaterialTexture(RpMaterial* material); }; - inline static VehicleExtendedData m_VehData; + static inline VehicleExtendedData m_VehData; protected: - inline static ResourceStore m_TextureData { "textures", eResourceType::TYPE_IMAGE, ImVec2(100, 80) }; + static inline ResourceStore m_TextureData { "textures", eResourceType::TYPE_IMAGE, ImVec2(100, 80) }; struct veh_nodes { - inline static std::vector names_vec{"Default"}; - inline static std::string selected = "Default"; + static inline std::vector names_vec{"Default"}; + static inline std::string selected = "Default"; }; Paint(); - ~Paint(); static void UpdateNodeListRecursive(CVehicle* pVeh); static void NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function func); static void SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, bool filter_mat = false); static void SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string texturename, bool filter_mat = false); static void ResetNodeColor(CVehicle* veh, std::string node_name); static void ResetNodeTexture(CVehicle* pVeh, std::string node_name); - static void RenderEvent(CVehicle* pVeh); - static void ResetAfterRenderEvent(CVehicle* pVeh); }; diff --git a/src/Ped.cpp b/src/Ped.cpp index 9fc6d2d..bc8461c 100644 --- a/src/Ped.cpp +++ b/src/Ped.cpp @@ -1,9 +1,9 @@ #include "pch.h" -#include "Ped.h" -#include "Ui.h" -#include "Util.h" +#include "ped.h" +#include "ui.h" +#include "util.h" +#include "weapon.h" #include -#include "Weapon.h" #ifdef GTASA #include diff --git a/src/Ped.h b/src/Ped.h index d18f919..8bfcbe0 100644 --- a/src/Ped.h +++ b/src/Ped.h @@ -1,34 +1,35 @@ #pragma once #include "pch.h" -#include "Player.h" +#include "player.h" #ifdef GTASA -#include "Weapon.h" +#include "weapon.h" #endif + class Ped { private: #ifdef GTASA - inline static bool m_bBigHead; - inline static bool m_bThinBody; - inline static CJson m_SpecialPedJson = CJson("ped special"); - inline static ResourceStore m_PedData{"ped", eResourceType::TYPE_BOTH, ImVec2(65, 110)}; + static inline bool m_bBigHead; + static inline bool m_bThinBody; + static inline CJson m_SpecialPedJson = CJson("ped special"); + static inline ResourceStore m_PedData{"ped", eResourceType::TYPE_BOTH, ImVec2(65, 110)}; #elif GTAVC - inline static ResourceStore m_PedData{"ped", eResourceType::TYPE_TEXT}; + static inline ResourceStore m_PedData{"ped", eResourceType::TYPE_TEXT}; #endif - inline static bool m_bImagesLoaded; - inline static bool m_bExGangWarsInstalled; - inline static int m_nPedRemoveRadius = 5; + static inline bool m_bImagesLoaded; + static inline bool m_bExGangWarsInstalled; + static inline int m_nPedRemoveRadius = 5; struct m_SpawnPed { - inline static std::vector m_List; - inline static int m_nAccuracy = 50; - inline static int m_nPedHealth = 100; - inline static bool m_bPedMove; - inline static bool m_bPedBleed; - inline static int m_nSelectedPedType; - inline static int m_nWeaponId; - inline static std::string m_nWeaponName = "None"; - inline static std::vector m_PedTypeList = + static inline std::vector m_List; + static inline int m_nAccuracy = 50; + static inline int m_nPedHealth = 100; + static inline bool m_bPedMove; + static inline bool m_bPedBleed; + static inline int m_nSelectedPedType; + static inline int m_nWeaponId; + static inline std::string m_nWeaponName = "None"; + static inline std::vector m_PedTypeList = { #ifdef GTASA "Civ Male", "Civ Female", "Cop", "Ballas", "Grove Street Families", "Los Santos Vagos", @@ -41,7 +42,7 @@ private: #endif }; }; - inline static std::vector m_GangNames = + static inline std::vector m_GangNames = { "Ballas", "Grove street families", "Los santos vagos", "San fierro rifa", "Da nang boys", "Mafia", "Mountain cloud triad", "Varrio los aztecas", "Gang9", "Gang10" @@ -51,6 +52,7 @@ private: #ifdef GTASA friend class Weapon; #endif + public: Ped(); ~Ped(); diff --git a/src/Player.cpp b/src/Player.cpp index 7aef9cb..ffd4579 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -1,10 +1,10 @@ #include "pch.h" -#include "Player.h" -#include "Menu.h" -#include "Ui.h" -#include "Util.h" +#include "player.h" +#include "menu.h" +#include "ui.h" +#include "util.h" #ifdef GTASA -#include "Ped.h" +#include "ped.h" // hardcoded cloth category names const char* cloth_category[18] = @@ -29,7 +29,7 @@ const char* cloth_category[18] = "Extras" }; -inline static void PlayerModelBrokenFix() +static inline void PlayerModelBrokenFix() { CPlayerPed* pPlayer = FindPlayerPed(); @@ -109,16 +109,16 @@ Player::Player() #ifdef GTASA // Fix player model being broken after rebuild patch::RedirectCall(0x5A834D, &PlayerModelBrokenFix); - m_bAimSkinChanger = config.GetValue("aim_skin_changer", false); + m_bAimSkinChanger = gConfig.GetValue("aim_skin_changer", false); #endif // Custom skins setup if (GetModuleHandle("modloader.asi")) { #ifdef GTASA - if (fs::is_directory(m_CustomSkins::m_Path)) + if (std::filesystem::is_directory(m_CustomSkins::m_Path)) { - for (auto& p : fs::recursive_directory_iterator(m_CustomSkins::m_Path)) + for (auto& p : std::filesystem::recursive_directory_iterator(m_CustomSkins::m_Path)) { if (p.path().extension() == ".dff") { @@ -127,13 +127,13 @@ Player::Player() if (file_name.size() < 9) m_CustomSkins::m_List.push_back(file_name); else - flog << "Custom Skin longer than 8 characters " << file_name << std::endl; + gLog << "Custom Skin longer than 8 characters " << file_name << std::endl; } } } else { - fs::create_directory(m_CustomSkins::m_Path); + std::filesystem::create_directory(m_CustomSkins::m_Path); } #endif @@ -195,7 +195,7 @@ Player::Player() TopDownCameraView(); } - if (m_bAimSkinChanger && Ui::HotKeyPressed(Menu::m_HotKeys::aimSkinChanger)) + if (m_bAimSkinChanger && aimSkinChanger.Pressed()) { CPed* targetPed = player->m_pPlayerTargettedPed; if (targetPed) @@ -206,7 +206,7 @@ Player::Player() } #endif - if (Ui::HotKeyPressed(Menu::m_HotKeys::godMode)) + if (godMode.Pressed()) { if (m_bGodMode) { @@ -646,8 +646,8 @@ void Player::Draw() if (Ui::CheckboxWithHint("Aim skin changer", &m_bAimSkinChanger, (("Changes to the ped, player is targeting with a weapon.\nTo use aim a ped with a weapon and press ") - + Ui::GetHotKeyNameString(Menu::m_HotKeys::aimSkinChanger)).c_str())) - config.SetValue("aim_skin_changer", m_bAimSkinChanger); + + aimSkinChanger.Pressed()))) + gConfig.SetValue("aim_skin_changer", m_bAimSkinChanger); if (ImGui::BeginTabBar("AppearanceTabBar")) { if (ImGui::BeginTabItem("Clothes")) diff --git a/src/Player.h b/src/Player.h index c060410..d2bb26e 100644 --- a/src/Player.h +++ b/src/Player.h @@ -4,34 +4,34 @@ class Player { private: - inline static bool m_bGodMode; - inline static bool m_bModloaderInstalled; + static inline bool m_bGodMode; + static inline bool m_bModloaderInstalled; struct m_KeepPosition { - inline static bool m_bEnabled = false; - inline static CVector m_fPos; + static inline bool m_bEnabled = false; + static inline CVector m_fPos; }; #ifdef GTASA - inline static bool m_bAimSkinChanger; - inline static bool m_bDrunkEffect; - inline static bool m_bFastSprint; - inline static int m_nUiBodyState; - inline static ResourceStore m_ClothData { "clothes" , eResourceType::TYPE_IMAGE, ImVec2(70, 100)}; + static inline bool m_bAimSkinChanger; + static inline bool m_bDrunkEffect; + static inline bool m_bFastSprint; + static inline int m_nUiBodyState; + static inline ResourceStore m_ClothData { "clothes" , eResourceType::TYPE_IMAGE, ImVec2(70, 100)}; struct m_CustomSkins { - inline static std::string m_Path = paths::GetGameDirPathA() + std::string("\\modloader\\Custom Skins\\");; - inline static ImGuiTextFilter m_Filter; - inline static std::vector m_List; + static inline std::string m_Path = paths::GetGameDirPathA() + std::string("\\modloader\\Custom Skins\\");; + static inline ImGuiTextFilter m_Filter; + static inline std::vector m_List; }; struct m_TopDownCamera { - inline static bool m_bEnabled = false; - inline static float m_fOffset = 40.0f; + static inline bool m_bEnabled = false; + static inline float m_fOffset = 40.0f; }; #elif GTAVC - inline static ResourceStore skinData{ "skin", eResourceType::TYPE_TEXT }; + static inline ResourceStore skinData{ "skin", eResourceType::TYPE_TEXT }; #endif public: diff --git a/src/ResourceStore.h b/src/ResourceStore.h index 282f4c6..df4975c 100644 --- a/src/ResourceStore.h +++ b/src/ResourceStore.h @@ -1,6 +1,6 @@ #include #include -#include "Json.h" +#include "json.h" #include "../depend/imgui/imgui.h" #include "d3d9.h" diff --git a/src/Teleport.cpp b/src/Teleport.cpp index 76f782c..f5f385c 100644 --- a/src/Teleport.cpp +++ b/src/Teleport.cpp @@ -1,8 +1,8 @@ #include "pch.h" -#include "Teleport.h" -#include "Menu.h" -#include "Ui.h" -#include "Util.h" +#include "teleport.h" +#include "menu.h" +#include "ui.h" +#include "util.h" #ifdef GTASA // FlA @@ -43,7 +43,7 @@ void Teleport::FetchRadarSpriteData() Teleport::Teleport() { - m_bQuickTeleport = config.GetValue("quick_teleport", false); + m_bQuickTeleport = gConfig.GetValue("quick_teleport", false); Events::processScriptsEvent += [] { @@ -78,7 +78,7 @@ Teleport::Teleport() if (m_bQuickTeleport) { - if (Ui::HotKeyPressed(Menu::m_HotKeys::quickTeleport) + if (quickTeleport.Pressed() && ((CTimer::m_snTimeInMilliseconds - m_nQuickTeleportTimer) > 500)) { m_nQuickTeleportTimer = CTimer::m_snTimeInMilliseconds; @@ -195,10 +195,10 @@ void Teleport::Draw() ImGui::NextColumn(); #ifdef GTASA if (Ui::CheckboxWithHint("Quick teleport", &m_bQuickTeleport, - (std::string("Teleport to the location of your radar\ntarget blip using ") - + Ui::GetHotKeyNameString(Menu::m_HotKeys::quickTeleport)).c_str())) + std::string(std::string("Teleport to the location of your radar\ntarget blip using ") + + quickTeleport.GetNameString()).c_str())) { - config.SetValue("quick_teleport", m_bQuickTeleport); + gConfig.SetValue("quick_teleport", m_bQuickTeleport); } #endif ImGui::Columns(1); diff --git a/src/Teleport.h b/src/Teleport.h index 9a6bb7a..07533b9 100644 --- a/src/Teleport.h +++ b/src/Teleport.h @@ -5,22 +5,22 @@ class Teleport { private: - inline static bool m_bInsertCoord; - inline static bool m_bQuickTeleport; - inline static char m_nInputBuffer[INPUT_BUFFER_SIZE]; - inline static ResourceStore m_tpData{ "teleport", eResourceType::TYPE_TEXT }; - inline static char m_nLocationBuffer[INPUT_BUFFER_SIZE]; - inline static uint m_nQuickTeleportTimer; + static inline bool m_bInsertCoord; + static inline bool m_bQuickTeleport; + static inline char m_nInputBuffer[INPUT_BUFFER_SIZE]; + static inline ResourceStore m_tpData{ "teleport", eResourceType::TYPE_TEXT }; + static inline char m_nLocationBuffer[INPUT_BUFFER_SIZE]; + static inline uint m_nQuickTeleportTimer; #ifdef GTASA - inline static CJson m_SpriteJson = CJson("radar sprite"); + static inline CJson m_SpriteJson = CJson("radar sprite"); #endif struct m_Teleport { - inline static bool m_bEnabled; - inline static CVector m_fPos = { -1, -1, -1 }; - inline static uint m_nTimer; + static inline bool m_bEnabled; + static inline CVector m_fPos = { -1, -1, -1 }; + static inline uint m_nTimer; }; diff --git a/src/Ui.cpp b/src/Ui.cpp index bbaf3a8..0a1e647 100644 --- a/src/Ui.cpp +++ b/src/Ui.cpp @@ -1,6 +1,6 @@ #include "pch.h" -#include "Util.h" -#include "Ui.h" +#include "util.h" +#include "ui.h" bool Ui::ListBox(const char* label, std::vector& all_items, int& selected) { @@ -108,7 +108,7 @@ void Ui::DrawHeaders(CallbackTable& data) { const char* btn_text = it->first.c_str(); - if (btn_text == Globals::m_HeaderId) + if (btn_text == m_HeaderId) { colors[ImGuiCol_Button] = colors[ImGuiCol_ButtonActive]; func = it->second; @@ -117,8 +117,8 @@ void Ui::DrawHeaders(CallbackTable& data) if (ImGui::Button(btn_text, GetSize(3, false))) { - Globals::m_HeaderId = btn_text; - config.SetValue("window.id", Globals::m_HeaderId); + m_HeaderId = btn_text; + gConfig.SetValue("window.id", m_HeaderId); func = it->second; } @@ -131,7 +131,7 @@ void Ui::DrawHeaders(CallbackTable& data) ImGui::PopStyleVar(); ImGui::Dummy(ImVec2(0, 10)); - if (Globals::m_HeaderId == "") + if (m_HeaderId == "") { // Show Welcome page ImGui::NewLine(); @@ -541,7 +541,7 @@ void Ui::DrawImages(ResourceStore &store, std::function onLe Couldn't figure out how to laod images for Dx11 Using texts for now */ - if (Globals::renderer == Render_DirectX11) + if (gRenderer == Render_DirectX11) { if (ImGui::MenuItem(modelName.c_str())) { @@ -563,7 +563,7 @@ void Ui::DrawImages(ResourceStore &store, std::function onLe imgPopup.value = modelName; } - if (Globals::renderer != Render_DirectX11) + if (gRenderer != Render_DirectX11) { if (ImGui::IsItemHovered()) { @@ -853,109 +853,6 @@ void Ui::EditFloat(const char* label, const int address, const float min, const } } -bool Ui::HotKey(const char* label, HotKeyData& key_data) -{ - bool active = m_CurrentHotkey == label; - bool state = false; - - if (active) - { - ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]); - - for (int key = 3; key != 135; ++key) - { - if (KeyPressed(key)) - { - key_data.m_key1 = key; - break; - } - } - - for (int key = 135; key != 3; --key) - { - if (KeyPressed(key)) - { - key_data.m_key2 = key; - break; - } - } - } - - - std::string text; - - if (key_data.m_key1 != VK_NONE) - text = key_names[key_data.m_key1 - 1]; - else - text = "None"; - - if (key_data.m_key1 != key_data.m_key2) - text += (" + " + key_names[key_data.m_key2 - 1]); - - if (ImGui::Button((text + std::string("##") + std::string(label)).c_str(), - ImVec2(ImGui::GetWindowContentRegionWidth() / 3.5, ImGui::GetFrameHeight()))) - if (!active) - m_CurrentHotkey = label; - - if (active && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) - { - m_CurrentHotkey = ""; - state = true; - } - - if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) - { - if (ImGui::IsItemHovered()) - { - key_data.m_key1 = VK_NONE; - key_data.m_key2 = VK_NONE; - } - else - m_CurrentHotkey = ""; - - state = true; - } - - ImGui::SameLine(); - ImGui::Text(label); - - if (active) - ImGui::PopStyleColor(2); - - return state; -} - -bool Ui::HotKeyPressed(HotKeyData& hotkey) -{ - if (KeyPressed(hotkey.m_key1) && KeyPressed(hotkey.m_key2)) - hotkey.m_bPressed = true; - else - { - if (hotkey.m_bPressed) - { - hotkey.m_bPressed = false; - return m_CurrentHotkey == ""; - } - } - return false; -} - -std::string Ui::GetHotKeyNameString(HotKeyData& hotkey) -{ - std::string text; - - if (hotkey.m_key1 != VK_NONE) - text = key_names[hotkey.m_key1 - 1]; - else - text = "None"; - - if (hotkey.m_key1 != hotkey.m_key2) - text += (" + " + key_names[hotkey.m_key2 - 1]); - - return text; -} - bool Ui::ColorButton(int color_id, std::vector& color, ImVec2 size) { bool rtn = false; diff --git a/src/Ui.h b/src/Ui.h index c1a094e..aa6b9b7 100644 --- a/src/Ui.h +++ b/src/Ui.h @@ -3,9 +3,6 @@ class Ui { -private: - inline static std::string m_CurrentHotkey; - public: struct NamedMemory { @@ -32,9 +29,13 @@ public: std::function function; std::string value; }; + static inline std::string m_HeaderId; + static inline JsonPopUpData jsonPopup; + static inline ImgPopUpData imgPopup; - inline static JsonPopUpData jsonPopup; - inline static ImgPopUpData imgPopup; + + Ui() = delete; + Ui(Ui&) = delete; static void CenterdText(const std::string& text); static bool ColorButton(int color_id, std::vector& color, ImVec2 size); @@ -74,10 +75,6 @@ public: static ImVec2 GetSize(short count = 1, bool spacing = true); - static bool HotKey(const char* label, HotKeyData& key_data); - static bool HotKeyPressed(HotKeyData& hotkey); - static std::string GetHotKeyNameString(HotKeyData& hotkey); - static bool ListBox(const char* label, std::vector& all_items, int& selected); static bool ListBoxStr(const char* label, std::vector& all_items, std::string& selected); static bool ListBoxCustomNames(const char* label, std::vector& all_items, std::string& selected, const char* custom_names[] = nullptr, size_t length = 0); diff --git a/src/Updater.cpp b/src/Updater.cpp index f376087..1a7ed1f 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -1,8 +1,8 @@ #include "pch.h" -#include "Updater.h" -#include "Ui.h" -#include "MenuInfo.h" -#include "Util.h" +#include "updater.h" +#include "ui.h" +#include "menuinfo.h" +#include "util.h" void Updater::CheckForUpdate() { diff --git a/src/Updater.h b/src/Updater.h index da8c671..19466d1 100644 --- a/src/Updater.h +++ b/src/Updater.h @@ -11,8 +11,8 @@ enum UPDATER_STATE class Updater { public: - inline static UPDATER_STATE m_State = UPDATER_IDLE; - inline static std::string m_LatestVersion; + static inline UPDATER_STATE m_State = UPDATER_IDLE; + static inline std::string m_LatestVersion; static void CheckForUpdate(); static void ShowUpdateScreen(); diff --git a/src/Util.cpp b/src/Util.cpp index aedbb35..181d00e 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1,5 +1,5 @@ #include "pch.h" -#include "Util.h" +#include "util.h" #include "psapi.h" std::string Util::GetLocationName(CVector* pos) diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index 99162bb..d19e19b 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -1,9 +1,9 @@ #include "pch.h" -#include "Vehicle.h" -#include "Menu.h" -#include "Ui.h" -#include "Util.h" -#include "FileHandler.h" +#include "vehicle.h" +#include "menu.h" +#include "ui.h" +#include "util.h" +#include "filehandler.h" #include #include @@ -47,7 +47,7 @@ Vehicle::Vehicle() int hveh = CPools::GetVehicleRef(pVeh); #ifdef GTASA - if (Ui::HotKeyPressed(Menu::m_HotKeys::flipVeh)) + if (flipVeh.Pressed()) { int roll = 0; Command(hveh, &roll); @@ -57,13 +57,13 @@ Vehicle::Vehicle() } #endif - if (Ui::HotKeyPressed(Menu::m_HotKeys::fixVeh)) + if (fixVeh.Pressed()) { FixVehicle(pVeh); SetHelpMessage("Vehicle fixed", false, false, false); } - if (Ui::HotKeyPressed(Menu::m_HotKeys::vehEngine)) + if (vehEngine.Pressed()) { bool state = BY_GAME(!pVeh->m_nVehicleFlags.bEngineBroken, true) || pVeh->m_nVehicleFlags.bEngineOn; @@ -81,10 +81,10 @@ Vehicle::Vehicle() pVeh->m_nVehicleFlags.bEngineOn = !state; } - if (Ui::HotKeyPressed(Menu::m_HotKeys::vehInstantStart)) + if (vehInstantStart.Pressed()) Command(hveh, 40.0f); - if (Ui::HotKeyPressed(Menu::m_HotKeys::vehInstantStop)) + if (vehInstantStop.Pressed()) Command(hveh, 0); if (m_bNoDamage) @@ -219,7 +219,7 @@ void Vehicle::AddComponent(const std::string& component, const bool display_mess } catch (...) { - flog << "Failed to component to vehicle " << component << std::endl; + gLog << "Failed to component to vehicle " << component << std::endl; } } @@ -241,7 +241,7 @@ void Vehicle::RemoveComponent(const std::string& component, const bool display_m } catch (...) { - flog << "Failed to remove component from vehicle " << component << std::endl; + gLog << "Failed to remove component from vehicle " << component << std::endl; } } @@ -1048,7 +1048,7 @@ void Vehicle::Draw() ImGui::EndTabItem(); } #ifdef GTASA - if (Globals::renderer != Render_DirectX11) + if (gRenderer != Render_DirectX11) { if (ImGui::BeginTabItem("Neons")) { diff --git a/src/Vehicle.h b/src/Vehicle.h index 44b0b0e..3ba6af8 100644 --- a/src/Vehicle.h +++ b/src/Vehicle.h @@ -1,8 +1,8 @@ #pragma once #include "pch.h" #ifdef GTASA -#include "Neon.h" -#include "Paint.h" +#include "neon.h" +#include "paint.h" #endif #ifdef GTASA @@ -12,60 +12,60 @@ class Vehicle #endif { private: - inline static bool m_bBikeFly; - inline static bool m_bDontFallBike; - inline static bool m_bVehHeavy; - inline static bool m_bVehWatertight; - inline static bool m_bNoDamage; - inline static int m_nDoorMenuButton; - inline static std::string m_DoorNames[6] = + static inline bool m_bBikeFly; + static inline bool m_bDontFallBike; + static inline bool m_bVehHeavy; + static inline bool m_bVehWatertight; + static inline bool m_bNoDamage; + static inline int m_nDoorMenuButton; + static inline std::string m_DoorNames[6] = { "Hood", "Boot", "Front left door", "Front right door", "Rear left door", "Rear right door" }; - inline static int m_nVehRemoveRadius; - inline static bool m_bLockSpeed; - inline static float m_fLockSpeed; - inline static std::vector> m_CarcolsColorData; - inline static std::map> m_CarcolsCarData; + static inline int m_nVehRemoveRadius; + static inline bool m_bLockSpeed; + static inline float m_fLockSpeed; + static inline std::vector> m_CarcolsColorData; + static inline std::map> m_CarcolsCarData; struct m_Color { - inline static bool m_bMatFilter = true; - inline static int m_nRadioButton = 1; - inline static bool bShowAll; - inline static float m_fColorPicker[3]{ 0, 0, 0 }; + static inline bool m_bMatFilter = true; + static inline int m_nRadioButton = 1; + static inline bool bShowAll; + static inline float m_fColorPicker[3]{ 0, 0, 0 }; }; #ifdef GTASA - inline static bool m_bDisableColDetection; - inline static std::map m_VehicleIDE; + static inline bool m_bDisableColDetection; + static inline std::map m_VehicleIDE; struct m_Neon { - inline static float m_fColorPicker[3]{ 0, 0, 0 }; - inline static bool m_bRainbowEffect; - inline static uint m_nRainbowTimer; - inline static bool m_bApplyOnTraffic; - inline static uint m_bTrafficTimer; + static inline float m_fColorPicker[3]{ 0, 0, 0 }; + static inline bool m_bRainbowEffect; + static inline uint m_nRainbowTimer; + static inline bool m_bApplyOnTraffic; + static inline uint m_bTrafficTimer; }; - inline static ResourceStore m_TuneData { "components", eResourceType::TYPE_IMAGE, ImVec2(100, 80) }; + static inline ResourceStore m_TuneData { "components", eResourceType::TYPE_IMAGE, ImVec2(100, 80) }; #endif struct m_Spawner { #ifdef GTASA - inline static ResourceStore m_VehData { "vehicles", eResourceType::TYPE_IMAGE, ImVec2(100, 75)}; + static inline ResourceStore m_VehData { "vehicles", eResourceType::TYPE_IMAGE, ImVec2(100, 75)}; #elif GTAVC - inline static ResourceStore m_VehData{"vehicle", eResourceType::TYPE_TEXT}; + static inline ResourceStore m_VehData{"vehicle", eResourceType::TYPE_TEXT}; #endif - inline static bool m_bSpawnInside = true; - inline static bool m_bSpawnInAir = true; - inline static char m_nLicenseText[9]; + static inline bool m_bSpawnInside = true; + static inline bool m_bSpawnInAir = true; + static inline char m_nLicenseText[9]; }; struct m_UnlimitedNitro { - inline static bool m_bEnabled; - inline static bool m_bCompAdded; + static inline bool m_bEnabled; + static inline bool m_bCompAdded; }; #ifdef GTASA - inline static std::vector(m_HandlingFlagNames) = // 32 flags + static inline std::vector(m_HandlingFlagNames) = // 32 flags { "1G_BOOST", "2G_BOOST", "NPC_ANTI_ROLL", "NPC_NEUTRAL_HANDL", "NO_HANDBRAKE", "STEER_REARWHEELS", "HB_REARWHEEL_STEER", "ALT_STEER_OPT", @@ -77,7 +77,7 @@ private: "Unused 4" }; - inline static std::vector(m_ModelFlagNames) = // 32 flags + static inline std::vector(m_ModelFlagNames) = // 32 flags { "IS_VAN", "IS_BUS", "IS_LOW", "IS_BIG", "REVERSE_BONNET", "HANGING_BOOT", "TAILGATE_BOOT", "NOSWING_BOOT", "NO_DOORS", "TANDEM_SEATS", diff --git a/src/Visual.cpp b/src/Visual.cpp index b21f373..dfec33b 100644 --- a/src/Visual.cpp +++ b/src/Visual.cpp @@ -1,9 +1,9 @@ #include "pch.h" -#include "Visual.h" -#include "Ui.h" -#include "Util.h" -#include "Game.h" -#include "TimeCycle.h" +#include "visual.h" +#include "ui.h" +#include "util.h" +#include "game.h" +#include "timecycle.h" #ifdef GTASA #include "CHudColours.h" @@ -531,11 +531,7 @@ void Visual::Draw() int hour = CClock::ms_nGameClockHours; int minute = CClock::ms_nGameClockMinutes; - if (Game::m_bSyncTime) - { - ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); - ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); - } + ImGui::BeginDisabled(Game::m_bSyncTime); if (ImGui::InputInt("Hour", &hour) & !Game::m_bSyncTime) { @@ -553,8 +549,7 @@ void Visual::Draw() if (Game::m_bSyncTime) { - ImGui::PopStyleVar(); - ImGui::PopItemFlag(); + ImGui::EndDisabled(); Ui::ShowTooltip("Sync system time is enabled.\n(Game/Sync system time)"); } diff --git a/src/Visual.h b/src/Visual.h index 8ab1f6f..66a04e2 100644 --- a/src/Visual.h +++ b/src/Visual.h @@ -3,17 +3,17 @@ class Visual { private: - inline static bool m_bLockWeather; - inline static int m_nBacWeatherType; + static inline bool m_bLockWeather; + static inline int m_nBacWeatherType; #ifdef GTASA - inline static bool m_bInvisibleWater; - inline static bool m_bNoWater; - inline static bool m_bDisableHydrant; + static inline bool m_bInvisibleWater; + static inline bool m_bNoWater; + static inline bool m_bDisableHydrant; #endif // Timecyc - inline static int m_nTimecycHour = 8; - inline static std::vector m_WeatherNames + static inline int m_nTimecycHour = 8; + static inline std::vector m_WeatherNames { "EXTRASUNNY LA", "SUNNY LA", "EXTRASUNNY SMOG LA", "SUNNY SMOG LA", "CLOUDY LA", "SUNNY SF", "EXTRASUNNY SF", "CLOUDY SF", "RAINY SF", "FOGGY SF", diff --git a/src/Weapon.cpp b/src/Weapon.cpp index 9c8283a..32acc93 100644 --- a/src/Weapon.cpp +++ b/src/Weapon.cpp @@ -1,8 +1,8 @@ #include "pch.h" -#include "Weapon.h" -#include "Ui.h" -#include "Util.h" -#include "Ped.h" +#include "weapon.h" +#include "ui.h" +#include "util.h" +#include "ped.h" #include "CWeaponInfo.h" Weapon::Weapon() diff --git a/src/Weapon.h b/src/Weapon.h index df2f0b4..296e892 100644 --- a/src/Weapon.h +++ b/src/Weapon.h @@ -5,27 +5,27 @@ class Weapon { public: #ifdef GTASA - inline static ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_BOTH, ImVec2(65, 65) }; + static inline ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_BOTH, ImVec2(65, 65) }; - inline static bool m_bAutoAim; - inline static bool m_bRapidFire; - inline static bool m_bDualWeild; - inline static bool m_bMoveAim; - inline static bool m_bMoveFire; - inline static int m_nSelectedGang; + static inline bool m_bAutoAim; + static inline bool m_bRapidFire; + static inline bool m_bDualWeild; + static inline bool m_bMoveAim; + static inline bool m_bMoveFire; + static inline int m_nSelectedGang; #elif GTAVC - inline static ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_TEXT }; - inline static bool m_bInfiniteAmmo; + static inline ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_TEXT }; + static inline bool m_bInfiniteAmmo; #endif - inline static bool m_bFastReload; - inline static bool m_bHugeDamage; - inline static bool m_bLongRange; - inline static int m_nAmmoCount = 99999; - inline static uchar m_nCurrentWeaponSlot = -1; - inline static int m_nSelectedWeapon; + static inline bool m_bFastReload; + static inline bool m_bHugeDamage; + static inline bool m_bLongRange; + static inline int m_nAmmoCount = 99999; + static inline uchar m_nCurrentWeaponSlot = -1; + static inline int m_nSelectedWeapon; #ifdef GTASA - inline static int m_nGangWeaponList[10][3] = + static inline int m_nGangWeaponList[10][3] = { {WEAPON_PISTOL, WEAPON_MICRO_UZI, WEAPON_UNARMED}, // Ballas {WEAPON_PISTOL, WEAPON_UNARMED, WEAPON_UNARMED}, // Grove diff --git a/src/dllmain.cpp b/src/dllmain.cpp new file mode 100644 index 0000000..bd9233a --- /dev/null +++ b/src/dllmain.cpp @@ -0,0 +1,95 @@ +#include "pch.h" +#include "hook.h" +#include "cheatmenu.h" +#include "updater.h" +#include "menuinfo.h" + +void MenuThread(void* param) +{ + if (!std::filesystem::is_directory(PLUGIN_PATH((char*)"CheatMenu"))) + { + gLog << "CheatMenu folder not found. You need to put both \"CheatMenu.asi\" & \"CheatMenu\" folder in the same directory" << std::endl; + return; + } + + static bool bGameInit = false; +#ifdef GTASA + Hook::ApplyMouseFix(); +#endif + + // Wait till game init + Events::initRwEvent += [] + { + bGameInit = true; + }; + + while (!bGameInit) + { + Sleep(1000); + } + + /* + TODO: Find a better way + Since you could still name it something else + */ + if (GetModuleHandle("SAMP.dll") || GetModuleHandle("SAMP.asi")) + { + MessageBox(RsGlobal.ps->window, "SAMP detected. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR); + return; + } + + gLog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " + GITHUB_LINK "\n" << std::endl; + CFastman92limitAdjuster::Init(); + CheatMenu menu; + + time_t now = time(0); + struct tm tstruct = *localtime(&now); + int last_check_date = gConfig.GetValue("config.last_update_checked", 0); + + if (last_check_date != tstruct.tm_mday) + { + Updater::CheckForUpdate(); + gConfig.SetValue("config.last_update_checked", tstruct.tm_mday); + } + + while (true) + { + Sleep(5000); + + if (Updater::m_State == UPDATER_CHECKING) + { + Updater::CheckForUpdate(); + } + } +} + +BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) +{ + if (nReason == DLL_PROCESS_ATTACH) + { + uint gameVersion = GetGameVersion(); +#ifdef GTASA + if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT) + { + CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); + } + else + { + MessageBox(HWND_DESKTOP, "Unknown game version. GTA SA v1.0 US is required.", "CheatMenu", MB_ICONERROR); + } +#elif GTAVC + + if (gameVersion == GAME_10EN) + { + CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); + } + else + { + MessageBox(HWND_DESKTOP, "Unknown game version. GTA VC v1.0 EN is required.", "CheatMenu", MB_ICONERROR); + } +#endif + } + + return TRUE; +} \ No newline at end of file diff --git a/src/header_includes.h b/src/header_includes.h deleted file mode 100644 index 89a5ecd..0000000 --- a/src/header_includes.h +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "plugin.h" -#include "CBike.h" -#include "CCamera.h" -#include "CClock.h" -#include "CCivilianPed.h" -#include "CGangs.h" -#include "cHandlingDataMgr.h" -#include "CHud.h" -#include "CMenuManager.h" -#include "CModelInfo.h" -#include "RenderWare.h" -#include "CStats.h" -#include "CStreaming.h" -#include "CTheScripts.h" -#include "CTheZones.h" -#include "CTimer.h" -#include "CTimeCycle.h" -#include "CTrain.h" -#include "CWeather.h" -#include "CWorld.h" -#include "extensions/ScriptCommands.h" -#include "extensions/Screen.h" -#include "extensions/Paths.h" - -#ifdef GTASA -#include "CCheat.h" -#include "CClothes.h" -#include "CCutsceneMgr.h" -#include "CRadar.h" -#include "CShadows.h" -#include "eVehicleClass.h" -#include "CGangWars.h" -#endif - -#include "../Depend/fla/IDaccess.h" -#include "../Depend/imgui/imgui.h" -#include "../Depend/imgui/imgui_internal.h" -#include "../Depend/imgui/imgui_impl_dx9.h" -#include "../Depend/imgui/imgui_impl_dx11.h" -#include "../Depend/imgui/imgui_impl_win32.h" - -#include "MoreEvents.h" -#include "Json.h" -#include "VKeys.h" -#include "ResourceStore.h" \ No newline at end of file diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp new file mode 100644 index 0000000..59de7ea --- /dev/null +++ b/src/hotkeys.cpp @@ -0,0 +1,138 @@ +#include "pch.h" +#include "hotkeys.h" + +Hotkey aimSkinChanger(VK_KEY_N, VK_KEY_N); +Hotkey freeCam(VK_LCONTROL, VK_KEY_C); +Hotkey commandWindow(VK_LCONTROL, VK_KEY_V); +Hotkey fixVeh(VK_DELETE, VK_DELETE); +Hotkey flipVeh(VK_KEY_Z, VK_KEY_Z); +Hotkey freeCamTeleportPlayer(VK_LCONTROL, VK_TAB); +Hotkey godMode(VK_KEY_E, VK_KEY_E); +Hotkey menuOpen(VK_KEY_E, VK_KEY_E); +Hotkey quickSceenShot(VK_KEY_E, VK_KEY_E); +Hotkey quickTeleport(VK_KEY_E, VK_KEY_E); +Hotkey vehEngine(VK_KEY_E, VK_KEY_E); +Hotkey vehInstantStart(VK_KEY_E, VK_KEY_E); +Hotkey vehInstantStop(VK_KEY_E, VK_KEY_E); + +bool Hotkey::DrawUI(const char* label) +{ + bool active = m_CurrentHotkey == label; + bool state = false; + + if (active) + { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyle().Colors[ImGuiCol_ButtonActive]); + + for (int key = 3; key != 135; ++key) + { + if (KeyPressed(key)) + { + m_key1 = key; + break; + } + } + + for (int key = 135; key != 3; --key) + { + if (KeyPressed(key)) + { + m_key2 = key; + break; + } + } + } + + std::string text; + + if (m_key1 != VK_NONE) + { + text = key_names[m_key1 - 1]; + } + else + { + text = "None"; + } + + if (m_key1 != m_key2) + { + text += (" + " + key_names[m_key2 - 1]); + } + + if (ImGui::Button((text + std::string("##") + std::string(label)).c_str(), + ImVec2(ImGui::GetWindowContentRegionWidth() / 3.5, ImGui::GetFrameHeight()))) + { + if (!active) + { + m_CurrentHotkey = label; + } + } + + if (active && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) + { + m_CurrentHotkey = ""; + state = true; + } + + if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) + { + if (ImGui::IsItemHovered()) + { + m_key1 = VK_NONE; + m_key2 = VK_NONE; + } + else + { + m_CurrentHotkey = ""; + } + + state = true; + } + + ImGui::SameLine(); + ImGui::Text(label); + + if (active) + { + ImGui::PopStyleColor(2); + } + + return state; +} + +bool Hotkey::Pressed() +{ + if (KeyPressed(m_key1) && KeyPressed(m_key2)) + m_bPressed = true; + else + { + if (m_bPressed) + { + m_bPressed = false; + return m_CurrentHotkey == ""; + } + } + return false; +} + +std::string Hotkey::GetNameString() +{ + std::string text; + + if (m_key1 != VK_NONE) + { + text = key_names[m_key1 - 1]; + } + else + { + text = "None"; + } + + if (m_key1 != m_key2) + { + text += (" + " + key_names[m_key2 - 1]); + } + + return text; +} \ No newline at end of file diff --git a/src/hotkeys.h b/src/hotkeys.h new file mode 100644 index 0000000..f58e834 --- /dev/null +++ b/src/hotkeys.h @@ -0,0 +1,36 @@ +#pragma once +#include + +class Hotkey +{ +private: + static inline std::string m_CurrentHotkey; + bool m_bPressed; + +public: + int m_key1; + int m_key2; + + Hotkey(int key1, int key2) + : m_key1(key1), m_key2(key2) + {} + + // Draws ui to change the hotkeys from frontend + bool DrawUI(const char* label); + bool Pressed(); + std::string GetNameString(); +}; + +extern Hotkey aimSkinChanger; +extern Hotkey freeCam; +extern Hotkey commandWindow; +extern Hotkey fixVeh; +extern Hotkey flipVeh; +extern Hotkey freeCamTeleportPlayer; +extern Hotkey godMode; +extern Hotkey menuOpen; +extern Hotkey quickSceenShot; +extern Hotkey quickTeleport; +extern Hotkey vehEngine; +extern Hotkey vehInstantStart; +extern Hotkey vehInstantStop; diff --git a/src/pch.cpp b/src/pch.cpp index 15c3143..4cf4fc9 100644 --- a/src/pch.cpp +++ b/src/pch.cpp @@ -1,3 +1,2 @@ #include "pch.h" -std::ofstream flog = std::ofstream("CheatMenu.log"); -CJson config = CJson("config"); +CJson gConfig = CJson("config"); \ No newline at end of file diff --git a/src/pch.h b/src/pch.h index 2e89e68..4ea2894 100644 --- a/src/pch.h +++ b/src/pch.h @@ -12,42 +12,77 @@ #define BY_GAME(sa, vc) vc #endif -#include "header_includes.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "plugin.h" +#include "CBike.h" +#include "CCamera.h" +#include "CClock.h" +#include "CCivilianPed.h" +#include "CGangs.h" +#include "cHandlingDataMgr.h" +#include "CHud.h" +#include "CMenuManager.h" +#include "CModelInfo.h" +#include "RenderWare.h" +#include "CStats.h" +#include "CStreaming.h" +#include "CTheScripts.h" +#include "CTheZones.h" +#include "CTimer.h" +#include "CTimeCycle.h" +#include "CTrain.h" +#include "CWeather.h" +#include "CWorld.h" +#include "extensions/ScriptCommands.h" +#include "extensions/Screen.h" +#include "extensions/Paths.h" + +#ifdef GTASA +#include "CCheat.h" +#include "CClothes.h" +#include "CCutsceneMgr.h" +#include "CRadar.h" +#include "CShadows.h" +#include "eVehicleClass.h" +#include "CGangWars.h" +#endif + +#include "../depend/fla/IDaccess.h" +#include "../depend/imgui/imgui.h" + +#include "json.h" +#include "hotkeys.h" +#include "vKeys.h" +#include "resourcestore.h" -// Globals using CallbackTable = std::vector>; using namespace plugin; -namespace fs = std::filesystem; -enum Renderer +enum eRenderer { Render_DirectX9, Render_DirectX11, Render_Unknown }; -struct Globals -{ - inline static std::string m_HeaderId; - inline static ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); - inline static ImVec2 m_fScreenSize = ImVec2(-1, -1); - inline static bool m_bShowMenu = false; - inline static bool m_bInit; - inline static Renderer renderer = Render_Unknown; - inline static void* device; -}; +static eRenderer gRenderer = Render_Unknown; +static std::ofstream gLog = std::ofstream("CheatMenu.log"); +// why doesn't this work? +// inline CJson gConfig = CJson("config"); +extern CJson gConfig; -extern std::ofstream flog; -extern CJson config; - -struct HotKeyData -{ - int m_key1; - int m_key2; - bool m_bPressed; -}; - -// Common defines +// Fix function clashes static void SetHelpMessage(const char *message, bool b1, bool b2, bool b3) { #if GTAVC