From 50c4e4235d0f8fd1583ee319536d061d930532a8 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sat, 20 Aug 2022 15:34:15 +0600 Subject: [PATCH] Fix errors --- src/cheatmenu.cpp | 45 +++++----- src/cheatmenu.h | 10 +-- src/dllmain.cpp | 186 +++++++++++++++++++--------------------- src/interface/ipage.cpp | 13 +++ src/interface/ipage.h | 3 + src/pages/menu.cpp | 9 +- src/pages/player.cpp | 5 +- src/pages/teleport.cpp | 11 ++- src/pages/vehicle.cpp | 8 +- src/pages/welcome.h | 10 ++- src/utils/fontmgr.cpp | 2 +- src/utils/fontmgr.h | 2 +- src/utils/rpc.cpp | 6 +- src/utils/rpc.h | 2 +- src/utils/updater.cpp | 2 +- src/utils/updater.h | 2 +- 16 files changed, 172 insertions(+), 144 deletions(-) diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index f3cbe8b..4e4bd21 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -60,7 +60,7 @@ static bool DrawTitleBar() return pressed; } -void CheatMenu::DrawWindow() +void CheatMenu::Draw() { ImGuiIO& io = ImGui::GetIO(); static bool bRunning = true; @@ -77,26 +77,30 @@ void CheatMenu::DrawWindow() else { bRunning = true; - if (m_bShowMenu) + if (m_bVisible) { - ImGui::SetNextWindowSize(m_fMenuSize); + ImGui::SetNextWindowSize(m_fSize); if (ImGui::Begin(MENU_TITLE, NULL, ImGuiWindowFlags_NoCollapse || ImGuiWindowFlags_NoTitleBar)) { - m_bShowMenu = !DrawTitleBar(); + m_bVisible = !DrawTitleBar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(250, 350)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200)); PageHandler::DrawPages(); - if (m_bSizeChangedExternal) - m_bSizeChangedExternal = false; + if (m_bSizeUpdated) + { + m_bSizeUpdated = false; + } else - m_fMenuSize = ImGui::GetWindowSize(); + { + m_fSize = ImGui::GetWindowSize(); + } - gConfig.Set("Window.SizeX", m_fMenuSize.x); - gConfig.Set("Window.SizeY", m_fMenuSize.y); + gConfig.Set("Window.SizeX", m_fSize.x); + gConfig.Set("Window.SizeY", m_fSize.y); ImGui::PopStyleVar(2); ImGui::End(); @@ -114,15 +118,14 @@ void CheatMenu::Init() return; } - if (!D3dHook::Init(DrawWindow)) + if (!D3dHook::Init(Draw)) { return; } // Load menu settings - // m_nMenuPage = (eMenuPages)gConfig.Get("Window.CurrentPage", (size_t)eMenuPages::WELCOME); - m_fMenuSize.x = gConfig.Get("Window.SizeX", screen::GetScreenWidth() / 4.0f); - m_fMenuSize.y = gConfig.Get("Window.SizeY", screen::GetScreenHeight() / 1.2f); + m_fSize.x = gConfig.Get("Window.SizeX", screen::GetScreenWidth() / 4.0f); + m_fSize.y = gConfig.Get("Window.SizeY", screen::GetScreenHeight() / 1.2f); srand(CTimer::m_snTimeInMilliseconds); ApplyStyle(); @@ -135,7 +138,7 @@ void CheatMenu::Init() { if (menuOpen.Pressed()) { - m_bShowMenu = !m_bShowMenu; + m_bVisible = !m_bVisible; } if (commandWindow.Pressed()) @@ -144,14 +147,14 @@ void CheatMenu::Init() } bool mouseState = D3dHook::GetMouseState(); - if (mouseState != m_bShowMenu) + if (mouseState != m_bVisible) { if (mouseState) // Only write when the menu closes { gConfig.Save(); } - D3dHook::SetMouseState(m_bShowMenu); + D3dHook::SetMouseState(m_bVisible); } if (teleportPage.IsQuickTeleportActive() && quickTeleport.PressedRealtime()) @@ -162,9 +165,9 @@ void CheatMenu::Init() }; } -bool CheatMenu::IsBeingDrawn() +bool CheatMenu::IsVisible() { - return m_bShowMenu; + return m_bVisible; } void CheatMenu::ApplyStyle() @@ -235,7 +238,7 @@ void CheatMenu::ApplyStyle() void CheatMenu::ResetSize() { - m_fMenuSize.x = screen::GetScreenWidth() / 4.0f; - m_fMenuSize.y = screen::GetScreenHeight() / 1.2f; - m_bSizeChangedExternal = true; + m_fSize.x = screen::GetScreenWidth() / 4.0f; + m_fSize.y = screen::GetScreenHeight() / 1.2f; + m_bSizeUpdated = true; } diff --git a/src/cheatmenu.h b/src/cheatmenu.h index 83ca8f1..0a8bede 100644 --- a/src/cheatmenu.h +++ b/src/cheatmenu.h @@ -8,15 +8,15 @@ class CheatMenu { private: - static inline ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); - static inline bool m_bShowMenu = false; // should the menu be drawn - static inline bool m_bSizeChangedExternal = false; // Was menu size change requested + static inline ImVec2 m_fSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); + static inline bool m_bVisible = false; // should the menu be drawn + static inline bool m_bSizeUpdated = false; // Was menu size change requested // Applies imgui theme to the menu static void ApplyStyle(); // Draws the window ui each frame - static void DrawWindow(); + static void Draw(); public: CheatMenu() = delete; @@ -26,7 +26,7 @@ public: static void Init(); // Returns true if the menu is being shown - static bool IsBeingDrawn(); + static bool IsVisible(); // Resets the menu height & width to default static void ResetSize(); diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 40e1205..62cfda9 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -1,121 +1,109 @@ #include "pch.h" -#include "cheatmenu.h" +#include "menu.h" #include "utils/updater.h" #include "utils/rpc.h" #include "pages/menu.h" void MenuThread(void* param) { - /* - Wait for game init - // Sleep(3000); - Doing it like this doesn't prevent from attaching a debugger - */ - static bool gameStarted = false; - Events::processScriptsEvent +=[] + Events::initGameEvent +=[] { - gameStarted = true; - }; - - while (!gameStarted) - { - Sleep(500); - } - /* - Had to put this in place since some people put the folder in root - directory and the asi in modloader. Why?? - */ - if (!std::filesystem::is_directory(PLUGIN_PATH((char*)FILE_NAME))) - { - std::string msg = std::format("{} folder not found. You need to put both '{}.asi' & '{}' folder in the same directory", FILE_NAME, FILE_NAME, FILE_NAME); - Log::Print(msg.c_str()); - MessageBox(NULL, msg.c_str(), FILE_NAME, MB_ICONERROR); - return; - } - - /* - Need SilentPatch since all gta games have issues with mouse input - Implementing mouse fix is a headache anyway - */ - if (!GetModuleHandle(BY_GAME("SilentPatchSA.asi","SilentPatchVC.asi","SilentPatchIII.asi"))) - { - Log::Print("SilentPatch not found. Please install it from here https://gtaforums.com/topic/669045-silentpatch/"); - int msgID = MessageBox(NULL, "SilentPatch not found. Do you want to install Silent Patch? (Game restart required)", FILE_NAME, MB_OKCANCEL | MB_DEFBUTTON1); - - if (msgID == IDOK) + /* + Had to put this in place since some people put the folder in root + directory and the asi in modloader. Why?? + */ + if (!std::filesystem::is_directory(PLUGIN_PATH((char*)FILE_NAME))) { - OPEN_LINK("https://gtaforums.com/topic/669045-silentpatch/"); - }; - return; - } + std::string msg = std::format("{} folder not found. You need to put both '{}.asi' & '{}' folder in the same directory", FILE_NAME, FILE_NAME, FILE_NAME); + Log::Print(msg.c_str()); + MessageBox(NULL, msg.c_str(), FILE_NAME, MB_ICONERROR); + return; + } - Log::Print("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: " - DISCORD_INVITE "\nMore Info: " GITHUB_LINK); + /* + Need SilentPatch since all gta games have issues with mouse input + Implementing mouse fix is a headache anyway + */ + if (!GetModuleHandle(BY_GAME("SilentPatchSA.asi","SilentPatchVC.asi","SilentPatchIII.asi"))) + { + Log::Print("SilentPatch not found. Please install it from here https://gtaforums.com/topic/669045-silentpatch/"); + int msgID = MessageBox(NULL, "SilentPatch not found. Do you want to install Silent Patch? (Game restart required)", FILE_NAME, MB_OKCANCEL | MB_DEFBUTTON1); - // date time - SYSTEMTIME st; - GetSystemTime(&st); - Log::Print("Date: {}-{}-{} Time: {}:{}\n", st.wYear, st.wMonth, st.wDay, - st.wHour, st.wMinute); + if (msgID == IDOK) + { + OPEN_LINK("https://gtaforums.com/topic/669045-silentpatch/"); + }; + return; + } - /* - TODO: Find a better way - Since you could still name it something else - */ -#ifdef GTASA - if (GetModuleHandle("SAMP.dll") || GetModuleHandle("SAMP.asi")) - { - Log::Print(FILE_NAME " doesn't support SAMP"); - MessageBox(NULL, "SAMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR); - return; - } - CFastman92limitAdjuster::Init(); - Log::Print("Game detected: GTA San Andreas 1.0 US"); -#elif GTAVC - if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi")) - { - Log::Print(FILE_NAME " doesn't support VCMP"); - MessageBox(NULL, "VCMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR); - return; - } - Log::Print("Game detected: GTA Vice City 1.0 EN"); -#else - Log::Print("Game detected: GTA III 1.0 EN"); -#endif + Log::Print("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: " + DISCORD_INVITE "\nMore Info: " GITHUB_LINK); - bool modloader = GetModuleHandle("modloader.asi"); - const char *path = PLUGIN_PATH((char*)""); - Log::Print("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory"); - Log::Print("Font support package: {}", FontMgr::IsSupportPackageInstalled() ? "True" : "False"); - Log::Print("\nCLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False"); - Log::Print("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False"); - Log::Print("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False"); - Log::Print("Modloader installed: {}", modloader ? "True" : "False"); - Log::Print("OLA installed: {}", GetModuleHandle("III.VC.SA.LimitAdjuster.asi") ? "True" : "False"); - Log::Print("ProjectProps installed: {}", GetModuleHandle("ProjectProps.asi") ? "True" : "False"); - Log::Print("Renderhook installed: {}", GetModuleHandle("_gtaRenderHook.asi") ? "True" : "False"); - Log::Print("Widescreen Fix installed: {}\n", GetModuleHandle("GTASA.WidescreenFix.asi") ? "True" : "False"); + // date time + SYSTEMTIME st; + GetSystemTime(&st); + Log::Print("Date: {}-{}-{} Time: {}:{}\n", st.wYear, st.wMonth, st.wDay, + st.wHour, st.wMinute); - CheatMenu::Init(); + /* + TODO: Find a better way + Since you could still name it something else + */ + #ifdef GTASA + if (GetModuleHandle("SAMP.dll") || GetModuleHandle("SAMP.asi")) + { + Log::Print(FILE_NAME " doesn't support SAMP"); + MessageBox(NULL, "SAMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR); + return; + } + CFastman92limitAdjuster::Init(); + Log::Print("Game detected: GTA San Andreas 1.0 US"); + #elif GTAVC + if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi")) + { + Log::Print(FILE_NAME " doesn't support VCMP"); + MessageBox(NULL, "VCMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR); + return; + } + Log::Print("Game detected: GTA Vice City 1.0 EN"); + #else + Log::Print("Game detected: GTA III 1.0 EN"); + #endif - // Checking for updates once a day - if (menuPage.m_bAutoCheckUpdate && gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay) - { - Updater::CheckUpdate(); - gConfig.Set("Menu.LastUpdateChecked", st.wDay); - } - - if (Updater::IsUpdateAvailable()) - { - Log::Print("New update available: %s", Updater::GetUpdateVersion().c_str()); - } + bool modloader = GetModuleHandle("modloader.asi"); + const char *path = PLUGIN_PATH((char*)""); + Log::Print("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory"); + Log::Print("Font support package: {}", FontMgr::IsSupportPackageInstalled() ? "True" : "False"); + Log::Print("\nCLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False"); + Log::Print("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False"); + Log::Print("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False"); + Log::Print("Modloader installed: {}", modloader ? "True" : "False"); + Log::Print("OLA installed: {}", GetModuleHandle("III.VC.SA.LimitAdjuster.asi") ? "True" : "False"); + Log::Print("ProjectProps installed: {}", GetModuleHandle("ProjectProps.asi") ? "True" : "False"); + Log::Print("Renderhook installed: {}", GetModuleHandle("_gtaRenderHook.asi") ? "True" : "False"); + Log::Print("Widescreen Fix installed: {}\n", GetModuleHandle("GTASA.WidescreenFix.asi") ? "True" : "False"); + + MenuMgr::Init(); + + // Checking for updates once a day + if (menuPage.m_bAutoCheckUpdate && gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay) + { + Updater::CheckUpdate(); + gConfig.Set("Menu.LastUpdateChecked", st.wDay); + } + + if (Updater::IsUpdateAvailable()) + { + Log::Print("New update available: %s", Updater::GetUpdateVersion().c_str()); + } + }; while (true) { - FontMgr::DrawPages(); - RPC::DrawPages(); - Updater::DrawPages(); + FontMgr::Process(); + RPC::Process(); + Updater::Process(); Sleep(1000); } } diff --git a/src/interface/ipage.cpp b/src/interface/ipage.cpp index e992662..ba9ed68 100644 --- a/src/interface/ipage.cpp +++ b/src/interface/ipage.cpp @@ -134,4 +134,17 @@ void PageHandler::DrawPages() reinterpret_cast(m_pCurrentPage)->Draw(); ImGui::EndChild(); } +} + +PagePtr PageHandler::FindPagePtr(ePageID id) +{ + for (void* ptr : m_PageList) + { + IPageStatic* page = reinterpret_cast(ptr); + if (page->GetPageID() == id) + { + return reinterpret_cast(page); + } + } + return nullptr; } \ No newline at end of file diff --git a/src/interface/ipage.h b/src/interface/ipage.h index acbb5c9..ccbb867 100644 --- a/src/interface/ipage.h +++ b/src/interface/ipage.h @@ -42,7 +42,9 @@ public: // Add a new page static void AddPage(PagePtr page, size_t index); + static PagePtr FindPagePtr(ePageID id); static void SetCurrentPage(PagePtr page); + }; /* @@ -84,4 +86,5 @@ public: { return m_NameKey; } + }; \ No newline at end of file diff --git a/src/pages/menu.cpp b/src/pages/menu.cpp index 01065ca..b5a4bd2 100644 --- a/src/pages/menu.cpp +++ b/src/pages/menu.cpp @@ -11,9 +11,12 @@ MenuPage& menuPage = MenuPage::Get(); MenuPage::MenuPage() : IPage(ePageID::Menu, "Window.MenuPage", true) { - m_bDiscordRPC = gConfig.Get("Menu.DiscordRPC", false); - m_bAutoCheckUpdate = gConfig.Get("Menu.AutoCheckUpdate", true); - m_bTextOnlyMode = gConfig.Get("Menu.TextOnlyMode", false); + Events::initGameEvent += [this]() + { + m_bDiscordRPC = gConfig.Get("Menu.DiscordRPC", false); + m_bAutoCheckUpdate = gConfig.Get("Menu.AutoCheckUpdate", true); + m_bTextOnlyMode = gConfig.Get("Menu.TextOnlyMode", false); + }; if (m_bDiscordRPC) { diff --git a/src/pages/player.cpp b/src/pages/player.cpp index 604e1bc..3100360 100644 --- a/src/pages/player.cpp +++ b/src/pages/player.cpp @@ -36,7 +36,10 @@ PlayerPage::PlayerPage() #ifdef GTASA // Fix player model being broken after rebuild patch::RedirectCall(0x5A834D, &PlayerModelBrokenFix); - m_bAimSkinChanger = gConfig.Get("Features.AimSkinChanger", false); + Events::initGameEvent += [this]() + { + m_bAimSkinChanger = gConfig.Get("Features.AimSkinChanger", false); + }; #endif Events::processScriptsEvent += [this] diff --git a/src/pages/teleport.cpp b/src/pages/teleport.cpp index 25ea20e..f7312aa 100644 --- a/src/pages/teleport.cpp +++ b/src/pages/teleport.cpp @@ -45,10 +45,13 @@ TeleportPage& teleportPage = TeleportPage::Get(); TeleportPage::TeleportPage() : IPage(ePageID::Teleport, "Window.TeleportPage", true) { - m_bTeleportMarker = gConfig.Get("Features.TeleportMarker", false); - m_bQuickTeleport = gConfig.Get("Features.QuickTeleport", false); - m_fMapSize.x = gConfig.Get("Game.MapSizeX", 6000.0f); - m_fMapSize.y = gConfig.Get("Game.MapSizeY", 6000.0f); + Events::initGameEvent += [this]() + { + m_bTeleportMarker = gConfig.Get("Features.TeleportMarker", false); + m_bQuickTeleport = gConfig.Get("Features.QuickTeleport", false); + m_fMapSize.x = gConfig.Get("Game.MapSizeX", 6000.0f); + m_fMapSize.y = gConfig.Get("Game.MapSizeY", 6000.0f); + }; Events::drawingEvent += [this] { diff --git a/src/pages/vehicle.cpp b/src/pages/vehicle.cpp index 0953b11..648abfe 100644 --- a/src/pages/vehicle.cpp +++ b/src/pages/vehicle.cpp @@ -20,8 +20,12 @@ VehiclePage::VehiclePage() : IPage(ePageID::Vehicle, "Window.VehiclePage", true) { // Get config data - m_Spawner.m_bInAir = gConfig.Get("Features.SpawnAircraftInAir", true); - m_Spawner.m_bAsDriver = gConfig.Get("Features.SpawnInsideVehicle", true); + Events::initGameEvent += [this]() + { + m_Spawner.m_bInAir = gConfig.Get("Features.SpawnAircraftInAir", true); + m_Spawner.m_bAsDriver = gConfig.Get("Features.SpawnInsideVehicle", true); + }; + Events::processScriptsEvent += [this] { diff --git a/src/pages/welcome.h b/src/pages/welcome.h index d9f8fba..1d60a9f 100644 --- a/src/pages/welcome.h +++ b/src/pages/welcome.h @@ -8,7 +8,15 @@ private: friend class IFeature; WelcomePage() : IPage(ePageID::Welcome, "Welcome", false) { - PageHandler::SetCurrentPage(this); + Events::initGameEvent += [this]() + { + ePageID pageID = static_cast(gConfig.Get("Window.CurrentPage", static_cast(ePageID::Welcome))); + PagePtr ptr = PageHandler::FindPagePtr(pageID); + if (ptr) + { + PageHandler::SetCurrentPage(ptr); + } + }; } WelcomePage(const WelcomePage&); diff --git a/src/utils/fontmgr.cpp b/src/utils/fontmgr.cpp index cd39eac..6586d36 100644 --- a/src/utils/fontmgr.cpp +++ b/src/utils/fontmgr.cpp @@ -71,7 +71,7 @@ void FontMgr::ReloadAll() m_bFontReloadRequired = false; } -void FontMgr::DrawPages() +void FontMgr::Process() { if (curState == eStates::Idle) { diff --git a/src/utils/fontmgr.h b/src/utils/fontmgr.h index fa1fa64..fd873c4 100644 --- a/src/utils/fontmgr.h +++ b/src/utils/fontmgr.h @@ -45,7 +45,7 @@ public: static ImFont* Load(const char* fontID, const char* path = 0, float fontMul = 1.0f); // Handles font downloading - static void DrawPages(); + static void Process(); // Reloads all the fonts static void ReloadAll(); diff --git a/src/utils/rpc.cpp b/src/utils/rpc.cpp index ab05a50..02cec94 100644 --- a/src/utils/rpc.cpp +++ b/src/utils/rpc.cpp @@ -3,7 +3,7 @@ #include "utils/util.h" #include "pages/menu.h" #include "pages/vehicle.h" -#include "cheatmenu.h" +#include "menu.h" // discord server ids const char* id = BY_GAME("951199292981403669", "951448264195059712", "951457540573655080"); @@ -66,7 +66,7 @@ void RPC::Init() } } -void RPC::DrawPages() +void RPC::Process() { if (!(menuPage.m_bDiscordRPC && bInit)) { @@ -133,7 +133,7 @@ void RPC::DrawPages() } - if (CheatMenu::IsBeingDrawn()) + if (MenuMgr::IsBeingDrawn()) { stateText = TEXT("RPC.BrowsingCheatMenu"); } diff --git a/src/utils/rpc.h b/src/utils/rpc.h index ffb65fb..d85ad75 100644 --- a/src/utils/rpc.h +++ b/src/utils/rpc.h @@ -36,6 +36,6 @@ public: RPC(RPC&) = delete; static void Init(); - static void DrawPages(); + static void Process(); static void Shutdown(); }; \ No newline at end of file diff --git a/src/utils/updater.cpp b/src/utils/updater.cpp index e307f76..ba7af7a 100644 --- a/src/utils/updater.cpp +++ b/src/utils/updater.cpp @@ -24,7 +24,7 @@ void Updater::CheckUpdate() } } -void Updater::DrawPages() +void Updater::Process() { if (Updater::curState != States::CHECKING) { diff --git a/src/utils/updater.h b/src/utils/updater.h index 1613534..71e4514 100644 --- a/src/utils/updater.h +++ b/src/utils/updater.h @@ -32,7 +32,7 @@ public: static bool IsUpdateAvailable(); // Needs to run in it's own thread to prevent the game from freezing - static void DrawPages(); + static void Process(); // Resets updater state to IDLE static void ResetUpdaterState();