diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index 4e4bd21..23451a0 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -4,18 +4,10 @@ #include "utils/widget.h" #include "utils/updater.h" #include "utils/d3dhook.h" -#include "utils/util.h" #include "utils/overlay.h" -#include "pages/scene.h" -#include "pages/game.h" -#include "pages/menu.h" -#include "pages/ped.h" -#include "pages/player.h" -#include "pages/teleport.h" -#include "pages/vehicle.h" -#include "pages/visual.h" -#include "pages/weapon.h" #include "interface/ipage.h" +#include "pages/teleport.h" +#include "pages/menu.h" static bool DrawTitleBar() { @@ -60,7 +52,7 @@ static bool DrawTitleBar() return pressed; } -void CheatMenu::Draw() +void CheatMenuMgr::Draw() { ImGuiIO& io = ImGui::GetIO(); static bool bRunning = true; @@ -110,29 +102,121 @@ void CheatMenu::Draw() Overlay::Draw(); } -void CheatMenu::Init() +CheatMenuMgr& CheatMenu = CheatMenuMgr::Get(); +CheatMenuMgr::CheatMenuMgr() { - if (!std::filesystem::exists(PLUGIN_PATH((char*)FILE_NAME))) + Events::initRwEvent += [this]() { - Log::Print("Failed to find CheatMenu directory!"); - return; - } + /* + 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; + } - if (!D3dHook::Init(Draw)) - { - 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); - // Load menu settings - 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); + if (msgID == IDOK) + { + OPEN_LINK("https://gtaforums.com/topic/669045-silentpatch/"); + }; + return; + } - ApplyStyle(); - Locale::Init(FILE_NAME "/locale/", "English", "English"); - Overlay::Init(); + Log::Print("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: " + DISCORD_INVITE "\nMore Info: " GITHUB_LINK); - Events::processScriptsEvent += []() + // date time + SYSTEMTIME st; + GetSystemTime(&st); + Log::Print("Date: {}-{}-{} Time: {}:{}\n", st.wYear, st.wMonth, st.wDay, + st.wHour, st.wMinute); + + /* + 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(RsGlobal.ps->window, "SAMP detected. Exiting...", FILE_NAME, MB_ICONERROR); + exit(EXIT_FAILURE); + } + 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(RsGlobal.ps->window, "VCMP detected. Exiting...", FILE_NAME, MB_ICONERROR); + exit(EXIT_FAILURE); + } + Log::Print("Game detected: GTA Vice City 1.0 EN"); +#else + Log::Print("Game detected: GTA III 1.0 EN"); +#endif + + 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"); + + // 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()); + } + + m_fSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); + if (!std::filesystem::exists(PLUGIN_PATH((char*)FILE_NAME))) + { + Log::Print("Failed to find CheatMenu directory!"); + return; + } + + if (!D3dHook::Init(fArgNoneWrapper(CheatMenu.Draw))) + { + return; + } + + ApplyStyle(); + Locale::Init(FILE_NAME "/locale/", "English", "English"); + Overlay::Init(); + + // Load menu settings + 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); + }; + + Events::processScriptsEvent += [this]() { if (!FrontEndMenuManager.m_bMenuActive) { @@ -165,12 +249,12 @@ void CheatMenu::Init() }; } -bool CheatMenu::IsVisible() +bool CheatMenuMgr::IsVisible() { return m_bVisible; } -void CheatMenu::ApplyStyle() +void CheatMenuMgr::ApplyStyle() { ImGuiStyle* style = &ImGui::GetStyle(); ImVec4* colors = style->Colors; @@ -236,7 +320,7 @@ void CheatMenu::ApplyStyle() style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.6f); } -void CheatMenu::ResetSize() +void CheatMenuMgr::ResetSize() { m_fSize.x = screen::GetScreenWidth() / 4.0f; m_fSize.y = screen::GetScreenHeight() / 1.2f; diff --git a/src/cheatmenu.h b/src/cheatmenu.h index 0a8bede..be498a1 100644 --- a/src/cheatmenu.h +++ b/src/cheatmenu.h @@ -1,33 +1,35 @@ #pragma once #include "pch.h" +#include "interface/ifeature.hpp" /* * Main CheatMenu Class * Handles rendering, resizing, page drawing etc. */ -class CheatMenu +class CheatMenuMgr : public IFeature { private: - 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 + ImVec2 m_fSize; + bool m_bVisible; // should the menu be drawn + bool m_bSizeUpdated; // Was menu size change requested + bool m_bIsOnline; // SAMP & VCMP flag + + friend class IFeature; + CheatMenuMgr(); + CheatMenuMgr(const CheatMenuMgr&); // Applies imgui theme to the menu - static void ApplyStyle(); + void ApplyStyle(); // Draws the window ui each frame - static void Draw(); + void Draw(); public: - CheatMenu() = delete; - CheatMenu(const CheatMenu&) = delete; - - // Initilizes the menu, page, hooks etc - static void Init(); - // Returns true if the menu is being shown - static bool IsVisible(); + bool IsVisible(); // Resets the menu height & width to default - static void ResetSize(); + void ResetSize(); }; + +extern CheatMenuMgr& CheatMenu; diff --git a/src/defines.h b/src/defines.h index 108667c..21d9340 100644 --- a/src/defines.h +++ b/src/defines.h @@ -10,7 +10,7 @@ #define MENU_NAME "Cheat Menu" #define MENU_VERSION_NUMBER "3.3" #define MENU_VERSION MENU_VERSION_NUMBER"-beta" -#define BUILD_NUMBER "20220820" +#define BUILD_NUMBER "20220821" #define MENU_TITLE MENU_NAME " v" MENU_VERSION #ifdef GTASA diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 62cfda9..4643d1c 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -1,104 +1,9 @@ #include "pch.h" -#include "menu.h" #include "utils/updater.h" #include "utils/rpc.h" -#include "pages/menu.h" void MenuThread(void* param) { - Events::initGameEvent +=[] - { - - /* - 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) - { - OPEN_LINK("https://gtaforums.com/topic/669045-silentpatch/"); - }; - return; - } - - Log::Print("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: " - DISCORD_INVITE "\nMore Info: " GITHUB_LINK); - - // date time - SYSTEMTIME st; - GetSystemTime(&st); - Log::Print("Date: {}-{}-{} Time: {}:{}\n", st.wYear, st.wMonth, st.wDay, - st.wHour, st.wMinute); - - /* - 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 - - 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::Process(); diff --git a/src/pages/menu.cpp b/src/pages/menu.cpp index b5a4bd2..dd0c4e6 100644 --- a/src/pages/menu.cpp +++ b/src/pages/menu.cpp @@ -61,7 +61,7 @@ void MenuPage::Draw() ImGui::Spacing(); if (ImGui::Button(TEXT("Menu.ResetSize"), ImVec2(Widget::CalcSize(2)))) { - CheatMenu::ResetSize(); + CheatMenu.ResetSize(); } ImGui::SameLine(); if (ImGui::Button(TEXT("Menu.ReloadFonts"), ImVec2(Widget::CalcSize(2)))) diff --git a/src/pages/vehicle.cpp b/src/pages/vehicle.cpp index 648abfe..e381094 100644 --- a/src/pages/vehicle.cpp +++ b/src/pages/vehicle.cpp @@ -25,7 +25,6 @@ VehiclePage::VehiclePage() m_Spawner.m_bInAir = gConfig.Get("Features.SpawnAircraftInAir", true); m_Spawner.m_bAsDriver = gConfig.Get("Features.SpawnInsideVehicle", true); }; - Events::processScriptsEvent += [this] { @@ -99,6 +98,9 @@ VehiclePage::VehiclePage() pVeh->m_nFlags.bMeleeProof = true; pVeh->m_nFlags.bImmuneToNonPlayerDamage = true; + // patch for bikes + patch::Nop(0x614E20, 6); + // no tyre burst patch::SetRaw(0x609F30, (void*)"\xC2\x08\x00", 3); patch::SetRaw(0x5886A0, (void*)"\xC2\x08\x00", 3); @@ -495,6 +497,7 @@ void VehiclePage::Draw() pVeh->m_nFlags.bCollisionProof = false; pVeh->m_nFlags.bMeleeProof = false; pVeh->m_nFlags.bImmuneToNonPlayerDamage = false; + patch::SetRaw(0x614E20, (void*)"\xD9\x9D\x04\x02\x00\x00", 6); // restore tyre burst patch::SetRaw(0x609F30, (void*)"\x53\x56\x57", 3); diff --git a/src/pages/visual.cpp b/src/pages/visual.cpp index d82fbf4..5d76c1a 100644 --- a/src/pages/visual.cpp +++ b/src/pages/visual.cpp @@ -138,6 +138,7 @@ VisualPage::VisualPage() : IPage(ePageID::Visual, "Window.VisualPage", true) { #ifdef GTASA + if (GetModuleHandle("timecycle24.asi")) { m_nTimecycHour = 24; diff --git a/src/utils/d3dhook.cpp b/src/utils/d3dhook.cpp index d0f9669..a601007 100644 --- a/src/utils/d3dhook.cpp +++ b/src/utils/d3dhook.cpp @@ -98,7 +98,7 @@ void D3dHook::ProcessFrame(void* ptr) if (pCallbackFunc != nullptr) { - ((void(*)())pCallbackFunc)(); + pCallbackFunc(); } ImGui::EndFrame(); @@ -253,7 +253,7 @@ void D3dHook::ProcessMouse() } } -bool D3dHook::Init(void *pCallback) +bool D3dHook::Init(std::function pCallback) { static bool hookInjected; if (hookInjected) diff --git a/src/utils/d3dhook.h b/src/utils/d3dhook.h index 85e4509..4c2c64f 100644 --- a/src/utils/d3dhook.h +++ b/src/utils/d3dhook.h @@ -17,7 +17,7 @@ private: static inline f_EndScene oEndScene; static inline f_Reset oReset; static inline bool mouseShown; - static inline void* pCallbackFunc = nullptr; + static inline std::function pCallbackFunc = nullptr; static void CALLBACK ProcessFrame(void* ptr); static LRESULT CALLBACK hkWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -40,7 +40,7 @@ public: static bool GetMouseState(); // Injects game hooks & stuff - static bool Init(void *pCallback); + static bool Init(std::function pCallback); // Sets the current mouse visibility state static void SetMouseState(bool state); diff --git a/src/utils/rpc.cpp b/src/utils/rpc.cpp index 02cec94..de865f3 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 "menu.h" +#include "cheatmenu.h" // discord server ids const char* id = BY_GAME("951199292981403669", "951448264195059712", "951457540573655080"); @@ -133,7 +133,7 @@ void RPC::Process() } - if (MenuMgr::IsBeingDrawn()) + if (CheatMenu.IsVisible()) { stateText = TEXT("RPC.BrowsingCheatMenu"); }