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;
}
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;
}

View File

@ -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();

View File

@ -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<eLogLevel::Error>(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<eLogLevel::Error>("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<eLogLevel::Error>(msg.c_str());
MessageBox(NULL, msg.c_str(), FILE_NAME, MB_ICONERROR);
return;
}
Log::Print<eLogLevel::None>("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<eLogLevel::Error>("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<eLogLevel::None>("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<eLogLevel::Error>(FILE_NAME " doesn't support SAMP");
MessageBox(NULL, "SAMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR);
return;
}
CFastman92limitAdjuster::Init();
Log::Print<eLogLevel::None>("Game detected: GTA San Andreas 1.0 US");
#elif GTAVC
if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi"))
{
Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support VCMP");
MessageBox(NULL, "VCMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR);
return;
}
Log::Print<eLogLevel::None>("Game detected: GTA Vice City 1.0 EN");
#else
Log::Print<eLogLevel::None>("Game detected: GTA III 1.0 EN");
#endif
Log::Print<eLogLevel::None>("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<eLogLevel::None>("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory");
Log::Print<eLogLevel::None>("Font support package: {}", FontMgr::IsSupportPackageInstalled() ? "True" : "False");
Log::Print<eLogLevel::None>("\nCLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Modloader installed: {}", modloader ? "True" : "False");
Log::Print<eLogLevel::None>("OLA installed: {}", GetModuleHandle("III.VC.SA.LimitAdjuster.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("ProjectProps installed: {}", GetModuleHandle("ProjectProps.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");
// date time
SYSTEMTIME st;
GetSystemTime(&st);
Log::Print<eLogLevel::None>("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<eLogLevel::Error>(FILE_NAME " doesn't support SAMP");
MessageBox(NULL, "SAMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR);
return;
}
CFastman92limitAdjuster::Init();
Log::Print<eLogLevel::None>("Game detected: GTA San Andreas 1.0 US");
#elif GTAVC
if (GetModuleHandle("vcmp-proxy.dll") || GetModuleHandle("vcmp-proxy.asi"))
{
Log::Print<eLogLevel::Error>(FILE_NAME " doesn't support VCMP");
MessageBox(NULL, "VCMP detected. Exiting " FILE_NAME, FILE_NAME, MB_ICONERROR);
return;
}
Log::Print<eLogLevel::None>("Game detected: GTA Vice City 1.0 EN");
#else
Log::Print<eLogLevel::None>("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);
}
bool modloader = GetModuleHandle("modloader.asi");
const char *path = PLUGIN_PATH((char*)"");
Log::Print<eLogLevel::None>("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory");
Log::Print<eLogLevel::None>("Font support package: {}", FontMgr::IsSupportPackageInstalled() ? "True" : "False");
Log::Print<eLogLevel::None>("\nCLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Modloader installed: {}", modloader ? "True" : "False");
Log::Print<eLogLevel::None>("OLA installed: {}", GetModuleHandle("III.VC.SA.LimitAdjuster.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("ProjectProps installed: {}", GetModuleHandle("ProjectProps.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");
if (Updater::IsUpdateAvailable())
{
Log::Print<eLogLevel::Info>("New update available: %s", Updater::GetUpdateVersion().c_str());
}
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<eLogLevel::Info>("New update available: %s", Updater::GetUpdateVersion().c_str());
}
};
while (true)
{
FontMgr::DrawPages();
RPC::DrawPages();
Updater::DrawPages();
FontMgr::Process();
RPC::Process();
Updater::Process();
Sleep(1000);
}
}

View File

@ -135,3 +135,16 @@ void PageHandler::DrawPages()
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
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;
}
};

View File

@ -11,9 +11,12 @@ MenuPage& menuPage = MenuPage::Get();
MenuPage::MenuPage()
: IPage<MenuPage>(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)
{

View File

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

View File

@ -45,10 +45,13 @@ TeleportPage& teleportPage = TeleportPage::Get();
TeleportPage::TeleportPage()
: IPage<TeleportPage>(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]
{

View File

@ -20,8 +20,12 @@ VehiclePage::VehiclePage()
: IPage<VehiclePage>(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]
{

View File

@ -8,7 +8,15 @@ private:
friend class IFeature;
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&);

View File

@ -71,7 +71,7 @@ void FontMgr::ReloadAll()
m_bFontReloadRequired = false;
}
void FontMgr::DrawPages()
void FontMgr::Process()
{
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);
// Handles font downloading
static void DrawPages();
static void Process();
// Reloads all the fonts
static void ReloadAll();

View File

@ -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");
}

View File

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

View File

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

View File

@ -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();