Refactor code, [VC] Fix no damage for bikes

This commit is contained in:
Grinch_ 2022-08-21 01:30:13 +06:00
parent 352ab77388
commit 442c70a6e3
10 changed files with 144 additions and 149 deletions

View File

@ -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<eLogLevel::Error>("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<eLogLevel::Error>(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<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);
// 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<eLogLevel::None>("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: "
DISCORD_INVITE "\nMore Info: " GITHUB_LINK);
Events::processScriptsEvent += []()
// date time
SYSTEMTIME st;
GetSystemTime(&st);
Log::Print<eLogLevel::None>("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<eLogLevel::Error>(FILE_NAME " doesn't support SAMP");
MessageBox(RsGlobal.ps->window, "SAMP detected. Exiting...", FILE_NAME, MB_ICONERROR);
exit(EXIT_FAILURE);
}
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(RsGlobal.ps->window, "VCMP detected. Exiting...", FILE_NAME, MB_ICONERROR);
exit(EXIT_FAILURE);
}
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
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");
// 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());
}
m_fSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2);
if (!std::filesystem::exists(PLUGIN_PATH((char*)FILE_NAME)))
{
Log::Print<eLogLevel::Error>("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;

View File

@ -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<CheatMenuMgr>
{
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;

View File

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

View File

@ -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<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)
{
OPEN_LINK("https://gtaforums.com/topic/669045-silentpatch/");
};
return;
}
Log::Print<eLogLevel::None>("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: "
DISCORD_INVITE "\nMore Info: " GITHUB_LINK);
// date time
SYSTEMTIME st;
GetSystemTime(&st);
Log::Print<eLogLevel::None>("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<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
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");
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::Process();

View File

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

View File

@ -26,7 +26,6 @@ VehiclePage::VehiclePage()
m_Spawner.m_bAsDriver = gConfig.Get("Features.SpawnInsideVehicle", true);
};
Events::processScriptsEvent += [this]
{
uint timer = CTimer::m_snTimeInMilliseconds;
@ -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);

View File

@ -138,6 +138,7 @@ VisualPage::VisualPage()
: IPage<VisualPage>(ePageID::Visual, "Window.VisualPage", true)
{
#ifdef GTASA
if (GetModuleHandle("timecycle24.asi"))
{
m_nTimecycHour = 24;

View File

@ -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<void()> pCallback)
{
static bool hookInjected;
if (hookInjected)

View File

@ -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<void()> 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<void()> pCallback);
// Sets the current mouse visibility state
static void SetMouseState(bool state);

View File

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