Fix errors

This commit is contained in:
Grinch_ 2022-08-20 15:34:15 +06:00
parent 6bd401afa0
commit 50c4e4235d
16 changed files with 172 additions and 144 deletions

View File

@ -60,7 +60,7 @@ static bool DrawTitleBar()
return pressed; return pressed;
} }
void CheatMenu::DrawWindow() void CheatMenu::Draw()
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
static bool bRunning = true; static bool bRunning = true;
@ -77,26 +77,30 @@ void CheatMenu::DrawWindow()
else else
{ {
bRunning = true; 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)) 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_WindowMinSize, ImVec2(250, 350));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200)); ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200));
PageHandler::DrawPages(); PageHandler::DrawPages();
if (m_bSizeChangedExternal) if (m_bSizeUpdated)
m_bSizeChangedExternal = false; {
m_bSizeUpdated = false;
}
else else
m_fMenuSize = ImGui::GetWindowSize(); {
m_fSize = ImGui::GetWindowSize();
}
gConfig.Set("Window.SizeX", m_fMenuSize.x); gConfig.Set("Window.SizeX", m_fSize.x);
gConfig.Set("Window.SizeY", m_fMenuSize.y); gConfig.Set("Window.SizeY", m_fSize.y);
ImGui::PopStyleVar(2); ImGui::PopStyleVar(2);
ImGui::End(); ImGui::End();
@ -114,15 +118,14 @@ void CheatMenu::Init()
return; return;
} }
if (!D3dHook::Init(DrawWindow)) if (!D3dHook::Init(Draw))
{ {
return; return;
} }
// Load menu settings // Load menu settings
// m_nMenuPage = (eMenuPages)gConfig.Get("Window.CurrentPage", (size_t)eMenuPages::WELCOME); m_fSize.x = gConfig.Get("Window.SizeX", screen::GetScreenWidth() / 4.0f);
m_fMenuSize.x = gConfig.Get("Window.SizeX", screen::GetScreenWidth() / 4.0f); m_fSize.y = gConfig.Get("Window.SizeY", screen::GetScreenHeight() / 1.2f);
m_fMenuSize.y = gConfig.Get("Window.SizeY", screen::GetScreenHeight() / 1.2f);
srand(CTimer::m_snTimeInMilliseconds); srand(CTimer::m_snTimeInMilliseconds);
ApplyStyle(); ApplyStyle();
@ -135,7 +138,7 @@ void CheatMenu::Init()
{ {
if (menuOpen.Pressed()) if (menuOpen.Pressed())
{ {
m_bShowMenu = !m_bShowMenu; m_bVisible = !m_bVisible;
} }
if (commandWindow.Pressed()) if (commandWindow.Pressed())
@ -144,14 +147,14 @@ void CheatMenu::Init()
} }
bool mouseState = D3dHook::GetMouseState(); bool mouseState = D3dHook::GetMouseState();
if (mouseState != m_bShowMenu) if (mouseState != m_bVisible)
{ {
if (mouseState) // Only write when the menu closes if (mouseState) // Only write when the menu closes
{ {
gConfig.Save(); gConfig.Save();
} }
D3dHook::SetMouseState(m_bShowMenu); D3dHook::SetMouseState(m_bVisible);
} }
if (teleportPage.IsQuickTeleportActive() && quickTeleport.PressedRealtime()) 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() void CheatMenu::ApplyStyle()
@ -235,7 +238,7 @@ void CheatMenu::ApplyStyle()
void CheatMenu::ResetSize() void CheatMenu::ResetSize()
{ {
m_fMenuSize.x = screen::GetScreenWidth() / 4.0f; m_fSize.x = screen::GetScreenWidth() / 4.0f;
m_fMenuSize.y = screen::GetScreenHeight() / 1.2f; m_fSize.y = screen::GetScreenHeight() / 1.2f;
m_bSizeChangedExternal = true; m_bSizeUpdated = true;
} }

View File

@ -8,15 +8,15 @@
class CheatMenu class CheatMenu
{ {
private: private:
static inline ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); static inline ImVec2 m_fSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2);
static inline bool m_bShowMenu = false; // should the menu be drawn static inline bool m_bVisible = false; // should the menu be drawn
static inline bool m_bSizeChangedExternal = false; // Was menu size change requested static inline bool m_bSizeUpdated = false; // Was menu size change requested
// Applies imgui theme to the menu // Applies imgui theme to the menu
static void ApplyStyle(); static void ApplyStyle();
// Draws the window ui each frame // Draws the window ui each frame
static void DrawWindow(); static void Draw();
public: public:
CheatMenu() = delete; CheatMenu() = delete;
@ -26,7 +26,7 @@ public:
static void Init(); static void Init();
// Returns true if the menu is being shown // Returns true if the menu is being shown
static bool IsBeingDrawn(); static bool IsVisible();
// Resets the menu height & width to default // Resets the menu height & width to default
static void ResetSize(); static void ResetSize();

View File

@ -1,26 +1,13 @@
#include "pch.h" #include "pch.h"
#include "cheatmenu.h" #include "menu.h"
#include "utils/updater.h" #include "utils/updater.h"
#include "utils/rpc.h" #include "utils/rpc.h"
#include "pages/menu.h" #include "pages/menu.h"
void MenuThread(void* param) void MenuThread(void* param)
{ {
/* Events::initGameEvent +=[]
Wait for game init
// Sleep(3000);
Doing it like this doesn't prevent from attaching a debugger
*/
static bool gameStarted = false;
Events::processScriptsEvent +=[]
{ {
gameStarted = true;
};
while (!gameStarted)
{
Sleep(500);
}
/* /*
Had to put this in place since some people put the folder in root Had to put this in place since some people put the folder in root
@ -63,7 +50,7 @@ void MenuThread(void* param)
TODO: Find a better way TODO: Find a better way
Since you could still name it something else Since you could still name it something else
*/ */
#ifdef GTASA #ifdef GTASA
if (GetModuleHandle("SAMP.dll") || GetModuleHandle("SAMP.asi")) if (GetModuleHandle("SAMP.dll") || GetModuleHandle("SAMP.asi"))
{ {
Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support SAMP"); Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support SAMP");
@ -72,7 +59,7 @@ void MenuThread(void* param)
} }
CFastman92limitAdjuster::Init(); CFastman92limitAdjuster::Init();
Log::Print<eLogLevel::None>("Game detected: GTA San Andreas 1.0 US"); Log::Print<eLogLevel::None>("Game detected: GTA San Andreas 1.0 US");
#elif GTAVC #elif GTAVC
if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi")) if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi"))
{ {
Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support VCMP"); Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support VCMP");
@ -80,9 +67,9 @@ void MenuThread(void* param)
return; return;
} }
Log::Print<eLogLevel::None>("Game detected: GTA Vice City 1.0 EN"); Log::Print<eLogLevel::None>("Game detected: GTA Vice City 1.0 EN");
#else #else
Log::Print<eLogLevel::None>("Game detected: GTA III 1.0 EN"); Log::Print<eLogLevel::None>("Game detected: GTA III 1.0 EN");
#endif #endif
bool modloader = GetModuleHandle("modloader.asi"); bool modloader = GetModuleHandle("modloader.asi");
const char *path = PLUGIN_PATH((char*)""); const char *path = PLUGIN_PATH((char*)"");
@ -97,7 +84,7 @@ void MenuThread(void* param)
Log::Print<eLogLevel::None>("Renderhook installed: {}", GetModuleHandle("_gtaRenderHook.asi") ? "True" : "False"); Log::Print<eLogLevel::None>("Renderhook installed: {}", GetModuleHandle("_gtaRenderHook.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Widescreen Fix installed: {}\n", GetModuleHandle("GTASA.WidescreenFix.asi") ? "True" : "False"); Log::Print<eLogLevel::None>("Widescreen Fix installed: {}\n", GetModuleHandle("GTASA.WidescreenFix.asi") ? "True" : "False");
CheatMenu::Init(); MenuMgr::Init();
// Checking for updates once a day // Checking for updates once a day
if (menuPage.m_bAutoCheckUpdate && gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay) if (menuPage.m_bAutoCheckUpdate && gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay)
@ -110,12 +97,13 @@ void MenuThread(void* param)
{ {
Log::Print<eLogLevel::Info>("New update available: %s", Updater::GetUpdateVersion().c_str()); Log::Print<eLogLevel::Info>("New update available: %s", Updater::GetUpdateVersion().c_str());
} }
};
while (true) while (true)
{ {
FontMgr::DrawPages(); FontMgr::Process();
RPC::DrawPages(); RPC::Process();
Updater::DrawPages(); Updater::Process();
Sleep(1000); Sleep(1000);
} }
} }

View File

@ -135,3 +135,16 @@ void PageHandler::DrawPages()
ImGui::EndChild(); ImGui::EndChild();
} }
} }
PagePtr PageHandler::FindPagePtr(ePageID id)
{
for (void* ptr : m_PageList)
{
IPageStatic* page = reinterpret_cast<IPageStatic*>(ptr);
if (page->GetPageID() == id)
{
return reinterpret_cast<PagePtr>(page);
}
}
return nullptr;
}

View File

@ -42,7 +42,9 @@ public:
// Add a new page // Add a new page
static void AddPage(PagePtr page, size_t index); static void AddPage(PagePtr page, size_t index);
static PagePtr FindPagePtr(ePageID id);
static void SetCurrentPage(PagePtr page); static void SetCurrentPage(PagePtr page);
}; };
/* /*
@ -84,4 +86,5 @@ public:
{ {
return m_NameKey; return m_NameKey;
} }
}; };

View File

@ -11,9 +11,12 @@ MenuPage& menuPage = MenuPage::Get();
MenuPage::MenuPage() MenuPage::MenuPage()
: IPage<MenuPage>(ePageID::Menu, "Window.MenuPage", true) : IPage<MenuPage>(ePageID::Menu, "Window.MenuPage", true)
{ {
Events::initGameEvent += [this]()
{
m_bDiscordRPC = gConfig.Get("Menu.DiscordRPC", false); m_bDiscordRPC = gConfig.Get("Menu.DiscordRPC", false);
m_bAutoCheckUpdate = gConfig.Get("Menu.AutoCheckUpdate", true); m_bAutoCheckUpdate = gConfig.Get("Menu.AutoCheckUpdate", true);
m_bTextOnlyMode = gConfig.Get("Menu.TextOnlyMode", false); m_bTextOnlyMode = gConfig.Get("Menu.TextOnlyMode", false);
};
if (m_bDiscordRPC) if (m_bDiscordRPC)
{ {

View File

@ -36,7 +36,10 @@ PlayerPage::PlayerPage()
#ifdef GTASA #ifdef GTASA
// Fix player model being broken after rebuild // Fix player model being broken after rebuild
patch::RedirectCall(0x5A834D, &PlayerModelBrokenFix); patch::RedirectCall(0x5A834D, &PlayerModelBrokenFix);
Events::initGameEvent += [this]()
{
m_bAimSkinChanger = gConfig.Get("Features.AimSkinChanger", false); m_bAimSkinChanger = gConfig.Get("Features.AimSkinChanger", false);
};
#endif #endif
Events::processScriptsEvent += [this] Events::processScriptsEvent += [this]

View File

@ -45,10 +45,13 @@ TeleportPage& teleportPage = TeleportPage::Get();
TeleportPage::TeleportPage() TeleportPage::TeleportPage()
: IPage<TeleportPage>(ePageID::Teleport, "Window.TeleportPage", true) : IPage<TeleportPage>(ePageID::Teleport, "Window.TeleportPage", true)
{ {
Events::initGameEvent += [this]()
{
m_bTeleportMarker = gConfig.Get("Features.TeleportMarker", false); m_bTeleportMarker = gConfig.Get("Features.TeleportMarker", false);
m_bQuickTeleport = gConfig.Get("Features.QuickTeleport", false); m_bQuickTeleport = gConfig.Get("Features.QuickTeleport", false);
m_fMapSize.x = gConfig.Get("Game.MapSizeX", 6000.0f); m_fMapSize.x = gConfig.Get("Game.MapSizeX", 6000.0f);
m_fMapSize.y = gConfig.Get("Game.MapSizeY", 6000.0f); m_fMapSize.y = gConfig.Get("Game.MapSizeY", 6000.0f);
};
Events::drawingEvent += [this] Events::drawingEvent += [this]
{ {

View File

@ -20,8 +20,12 @@ VehiclePage::VehiclePage()
: IPage<VehiclePage>(ePageID::Vehicle, "Window.VehiclePage", true) : IPage<VehiclePage>(ePageID::Vehicle, "Window.VehiclePage", true)
{ {
// Get config data // Get config data
Events::initGameEvent += [this]()
{
m_Spawner.m_bInAir = gConfig.Get("Features.SpawnAircraftInAir", true); m_Spawner.m_bInAir = gConfig.Get("Features.SpawnAircraftInAir", true);
m_Spawner.m_bAsDriver = gConfig.Get("Features.SpawnInsideVehicle", true); m_Spawner.m_bAsDriver = gConfig.Get("Features.SpawnInsideVehicle", true);
};
Events::processScriptsEvent += [this] Events::processScriptsEvent += [this]
{ {

View File

@ -8,7 +8,15 @@ private:
friend class IFeature; friend class IFeature;
WelcomePage() : IPage<WelcomePage>(ePageID::Welcome, "Welcome", false) WelcomePage() : IPage<WelcomePage>(ePageID::Welcome, "Welcome", false)
{ {
PageHandler::SetCurrentPage(this); Events::initGameEvent += [this]()
{
ePageID pageID = static_cast<ePageID>(gConfig.Get("Window.CurrentPage", static_cast<size_t>(ePageID::Welcome)));
PagePtr ptr = PageHandler::FindPagePtr(pageID);
if (ptr)
{
PageHandler::SetCurrentPage(ptr);
}
};
} }
WelcomePage(const WelcomePage&); WelcomePage(const WelcomePage&);

View File

@ -71,7 +71,7 @@ void FontMgr::ReloadAll()
m_bFontReloadRequired = false; m_bFontReloadRequired = false;
} }
void FontMgr::DrawPages() void FontMgr::Process()
{ {
if (curState == eStates::Idle) if (curState == eStates::Idle)
{ {

View File

@ -45,7 +45,7 @@ public:
static ImFont* Load(const char* fontID, const char* path = 0, float fontMul = 1.0f); static ImFont* Load(const char* fontID, const char* path = 0, float fontMul = 1.0f);
// Handles font downloading // Handles font downloading
static void DrawPages(); static void Process();
// Reloads all the fonts // Reloads all the fonts
static void ReloadAll(); static void ReloadAll();

View File

@ -3,7 +3,7 @@
#include "utils/util.h" #include "utils/util.h"
#include "pages/menu.h" #include "pages/menu.h"
#include "pages/vehicle.h" #include "pages/vehicle.h"
#include "cheatmenu.h" #include "menu.h"
// discord server ids // discord server ids
const char* id = BY_GAME("951199292981403669", "951448264195059712", "951457540573655080"); 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)) if (!(menuPage.m_bDiscordRPC && bInit))
{ {
@ -133,7 +133,7 @@ void RPC::DrawPages()
} }
if (CheatMenu::IsBeingDrawn()) if (MenuMgr::IsBeingDrawn())
{ {
stateText = TEXT("RPC.BrowsingCheatMenu"); stateText = TEXT("RPC.BrowsingCheatMenu");
} }

View File

@ -36,6 +36,6 @@ public:
RPC(RPC&) = delete; RPC(RPC&) = delete;
static void Init(); static void Init();
static void DrawPages(); static void Process();
static void Shutdown(); static void Shutdown();
}; };

View File

@ -24,7 +24,7 @@ void Updater::CheckUpdate()
} }
} }
void Updater::DrawPages() void Updater::Process()
{ {
if (Updater::curState != States::CHECKING) if (Updater::curState != States::CHECKING)
{ {

View File

@ -32,7 +32,7 @@ public:
static bool IsUpdateAvailable(); static bool IsUpdateAvailable();
// Needs to run in it's own thread to prevent the game from freezing // 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 // Resets updater state to IDLE
static void ResetUpdaterState(); static void ResetUpdaterState();