Code cleanup

This commit is contained in:
Grinch_ 2021-09-21 14:00:26 +06:00
parent 0bd77dbf79
commit fcda4d500b
45 changed files with 60 additions and 57 deletions

View File

@ -9,16 +9,16 @@
*/ */
#pragma once #pragma once
#include "Animation.h" #include "animation.h"
#include "Hook.h" #include "hook.h"
#include "Menu.h" #include "menu.h"
#include "Teleport.h" #include "teleport.h"
#include "Player.h" #include "player.h"
#include "Ped.h" #include "ped.h"
#include "Vehicle.h" #include "vehicle.h"
#include "Weapon.h" #include "weapon.h"
#include "Game.h" #include "game.h"
#include "Visual.h" #include "visual.h"
class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon
{ {

View File

@ -6,17 +6,24 @@
void MenuThread(void* param) void MenuThread(void* param)
{ {
/*
Had to put this in place since some people put the folder in root
directory and the asi in modloader. Why??
TODO: Unlikely they'd even read the log so have to do something else
*/
if (!std::filesystem::is_directory(PLUGIN_PATH((char*)"CheatMenu"))) if (!std::filesystem::is_directory(PLUGIN_PATH((char*)"CheatMenu")))
{ {
gLog << "CheatMenu folder not found. You need to put both \"CheatMenu.asi\" & \"CheatMenu\" folder in the same directory" << std::endl; gLog << "CheatMenu folder not found. You need to put both \"CheatMenu.asi\" & \"CheatMenu\" folder in the same directory" << std::endl;
return; return;
} }
static bool bGameInit = false;
#ifdef GTASA #ifdef GTASA
Hook::ApplyMouseFix(); Hook::ApplyMouseFix();
#endif #endif
static bool bGameInit = false;
// Wait till game init // Wait till game init
Events::initRwEvent += [] Events::initRwEvent += []
{ {
@ -43,11 +50,13 @@ void MenuThread(void* param)
CFastman92limitAdjuster::Init(); CFastman92limitAdjuster::Init();
CheatMenu menu; CheatMenu menu;
// Checking for updates once a day
time_t now = time(0); time_t now = time(0);
struct tm tstruct = *localtime(&now); struct tm tstruct = *localtime(&now);
int last_check_date = gConfig.GetValue("config.last_update_checked", 0); int lastCheckDate = gConfig.GetValue("config.last_update_checked", 0);
if (last_check_date != tstruct.tm_mday) if (lastCheckDate != tstruct.tm_mday)
{ {
Updater::CheckForUpdate(); Updater::CheckForUpdate();
gConfig.SetValue("config.last_update_checked", tstruct.tm_mday); gConfig.SetValue("config.last_update_checked", tstruct.tm_mday);
@ -70,7 +79,7 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
{ {
uint gameVersion = GetGameVersion(); uint gameVersion = GetGameVersion();
#ifdef GTASA #ifdef GTASA
if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT) if (gameVersion == GAME_10US_HOODLUM)
{ {
CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr);
} }
@ -79,7 +88,6 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
MessageBox(HWND_DESKTOP, "Unknown game version. GTA SA v1.0 US is required.", "CheatMenu", MB_ICONERROR); MessageBox(HWND_DESKTOP, "Unknown game version. GTA SA v1.0 US is required.", "CheatMenu", MB_ICONERROR);
} }
#elif GTAVC #elif GTAVC
if (gameVersion == GAME_10EN) if (gameVersion == GAME_10EN)
{ {
CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr);

View File

@ -107,6 +107,7 @@ Game::Game()
CStats::SetStatValue(STAT_STAMINA, 0.0f); CStats::SetStatValue(STAT_STAMINA, 0.0f);
} }
static int m_nSolidWaterObj;
if (m_bSolidWater) if (m_bSolidWater)
{ {
CVector pos = pPlayer->GetPosition(); CVector pos = pPlayer->GetPosition();
@ -130,13 +131,13 @@ Game::Game()
Command<Commands::SET_OBJECT_COORDINATES>(m_nSolidWaterObj, pos.x, pos.y, waterHeight); Command<Commands::SET_OBJECT_COORDINATES>(m_nSolidWaterObj, pos.x, pos.y, waterHeight);
} }
} }
else }
else
{
if (m_nSolidWaterObj)
{ {
if (m_nSolidWaterObj != 0) Command<Commands::DELETE_OBJECT>(m_nSolidWaterObj);
{ m_nSolidWaterObj = 0;
Command<Commands::DELETE_OBJECT>(m_nSolidWaterObj);
m_nSolidWaterObj = 0;
}
} }
} }
@ -160,7 +161,8 @@ Game::Game()
#endif #endif
// improve this later // improve this later
if (m_bSyncTime && timer - m_nSyncTimer > 50) static uint syncTimer;
if (m_bSyncTime && timer - syncTimer > 50)
{ {
std::time_t t = std::time(nullptr); std::time_t t = std::time(nullptr);
std::tm* now = std::localtime(&t); std::tm* now = std::localtime(&t);
@ -168,7 +170,7 @@ Game::Game()
CClock::ms_nGameClockHours = now->tm_hour; CClock::ms_nGameClockHours = now->tm_hour;
CClock::ms_nGameClockMinutes = now->tm_min; CClock::ms_nGameClockMinutes = now->tm_min;
m_nSyncTimer = timer; syncTimer = timer;
} }
#ifdef GTASA #ifdef GTASA
@ -492,15 +494,8 @@ Lowers armour, health, stamina etc."))
Ui::CheckboxWithHint("Screenshot shortcut", &m_bScreenShot, Ui::CheckboxWithHint("Screenshot shortcut", &m_bScreenShot,
(("Take screenshot using ") + quickSceenShot.GetNameString() (("Take screenshot using ") + quickSceenShot.GetNameString()
+ "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str()); + "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str());
if (Ui::CheckboxWithHint("Solid water", &m_bSolidWater, Ui::CheckboxWithHint("Solid water", &m_bSolidWater,
"Player can walk on water\nTurn this off if you want to swim.")) "Player can walk on water\nTurn this off if you want to swim.");
{
if (!m_bSolidWater && m_nSolidWaterObj != 0)
{
Command<Commands::DELETE_OBJECT>(m_nSolidWaterObj);
m_nSolidWaterObj = 0;
}
}
#endif #endif
if (ImGui::Checkbox("Sync system time", &m_bSyncTime)) if (ImGui::Checkbox("Sync system time", &m_bSyncTime))
{ {
@ -652,7 +647,8 @@ Lowers armour, health, stamina etc."))
{ {
ImGui::Spacing(); ImGui::Spacing();
if (!m_bMissionLoaderWarningShown) static bool bMissionLoaderWarningShown;
if (!bMissionLoaderWarningShown)
{ {
ImGui::TextWrapped("Mission loader may cause,\n\ ImGui::TextWrapped("Mission loader may cause,\n\
1. Game crashes\n\ 1. Game crashes\n\
@ -662,7 +658,9 @@ Lowers armour, health, stamina etc."))
It's recommanded not to save after using the mission loader. Use it at your own risk!"); It's recommanded not to save after using the mission loader. Use it at your own risk!");
ImGui::Spacing(); ImGui::Spacing();
if (ImGui::Button("Show mission loader", ImVec2(Ui::GetSize()))) if (ImGui::Button("Show mission loader", ImVec2(Ui::GetSize())))
m_bMissionLoaderWarningShown = true; {
bMissionLoaderWarningShown = true;
}
} }
else else
{ {

View File

@ -5,11 +5,15 @@ class Game
public: public:
static inline ResourceStore m_MissionData{ "mission", eResourceType::TYPE_TEXT }; static inline ResourceStore m_MissionData{ "mission", eResourceType::TYPE_TEXT };
static inline bool m_bDisableCheats;
static inline bool m_bDisableReplay;
static inline bool m_bMissionTimer;
static inline bool m_bFreezeTime;
static inline bool m_bSyncTime;
#ifdef GTASA #ifdef GTASA
static inline bool m_bForbiddenArea = true; static inline bool m_bForbiddenArea = true; // wanted level when going outside playable aea
static inline bool m_bSolidWater; static inline bool m_bSolidWater; // walk on water hack
static inline bool m_bScreenShot; static inline bool m_bScreenShot;
static inline uint m_nSolidWaterObj;
static inline bool m_bKeepStuff; static inline bool m_bKeepStuff;
static inline ResourceStore m_StatData{ "stat", eResourceType::TYPE_TEXT }; static inline ResourceStore m_StatData{ "stat", eResourceType::TYPE_TEXT };
@ -50,19 +54,13 @@ public:
}; };
#endif #endif
static inline bool m_bDisableCheats;
static inline bool m_bDisableReplay;
static inline bool m_bMissionTimer;
static inline bool m_bFreezeTime;
static inline bool m_bSyncTime;
static inline uint m_nSyncTimer;
static inline bool m_bMissionLoaderWarningShown;
Game(); Game();
static void Draw(); static void Draw();
static void RealTimeClock(); static void RealTimeClock();
#ifdef GTASA #ifdef GTASA
// TODO: Update freecam with aap's code
static void FreeCam(); static void FreeCam();
static void ClearFreecamStuff(); static void ClearFreecamStuff();
#endif #endif

View File

@ -21,11 +21,16 @@ Visual::Visual()
Events::processScriptsEvent += [] Events::processScriptsEvent += []
{ {
// TODO: Needs improvement // TODO: Needs improvement
static short m_nBacWeatherType;
if (m_bLockWeather) if (m_bLockWeather)
{ {
CWeather::OldWeatherType = m_nBacWeatherType; CWeather::OldWeatherType = m_nBacWeatherType;
CWeather::NewWeatherType = m_nBacWeatherType; CWeather::NewWeatherType = m_nBacWeatherType;
} }
else
{
m_nBacWeatherType = CWeather::OldWeatherType;
}
}; };
} }
@ -320,11 +325,7 @@ void Visual::Draw()
} }
} }
} }
if (Ui::CheckboxWithHint("Lock weather", &m_bLockWeather)) Ui::CheckboxWithHint("Lock weather", &m_bLockWeather);
{
m_nBacWeatherType = CWeather::OldWeatherType;
}
if (Ui::CheckboxWithHint("No water", &m_bNoWater)) if (Ui::CheckboxWithHint("No water", &m_bNoWater))
{ {
if (m_bNoWater) if (m_bNoWater)
@ -357,10 +358,7 @@ void Visual::Draw()
Ui::CheckboxAddressEx("Unfog map", 0xBA372C, 0x50, 0x0); Ui::CheckboxAddressEx("Unfog map", 0xBA372C, 0x50, 0x0);
#elif GTAVC #elif GTAVC
Ui::CheckboxAddress("Hide radar", 0xA10AB6); Ui::CheckboxAddress("Hide radar", 0xA10AB6);
if (Ui::CheckboxWithHint("Lock weather", &m_bLockWeather)) Ui::CheckboxWithHint("Lock weather", &m_bLockWeather);
{
m_nBacWeatherType = CWeather::OldWeatherType;
}
Ui::CheckboxAddress("Show hud", 0x86963A); Ui::CheckboxAddress("Show hud", 0x86963A);
ImGui::NextColumn(); ImGui::NextColumn();

View File

@ -1,17 +1,18 @@
#pragma once #pragma once
#include "pch.h" #include "pch.h"
class Visual class Visual
{ {
private: private:
static inline bool m_bLockWeather; static inline bool m_bLockWeather;
static inline int m_nBacWeatherType;
#ifdef GTASA #ifdef GTASA
static inline bool m_bInvisibleWater; static inline bool m_bInvisibleWater;
static inline bool m_bNoWater; static inline bool m_bNoWater;
static inline bool m_bDisableHydrant; static inline bool m_bDisableHydrant;
#endif #endif
// Timecyc
// Timecyc stuff
static inline int m_nTimecycHour = 8; static inline int m_nTimecycHour = 8;
static inline std::vector<std::string> m_WeatherNames static inline std::vector<std::string> m_WeatherNames
{ {
@ -25,8 +26,7 @@ private:
static void GenerateTimecycFile(); static void GenerateTimecycFile();
static int CalcArrayIndex(); static int CalcArrayIndex();
static bool TimeCycColorEdit3(const char* label, uchar* r, uchar* g, uchar* b, ImGuiColorEditFlags flags = 0); static bool TimeCycColorEdit3(const char* label, uchar* r, uchar* g, uchar* b, ImGuiColorEditFlags flags = 0);
static bool TimeCycColorEdit4(const char* label, uchar* r, uchar* g, uchar* b, uchar* a, static bool TimeCycColorEdit4(const char* label, uchar* r, uchar* g, uchar* b, uchar* a, ImGuiColorEditFlags flags = 0);
ImGuiColorEditFlags flags = 0);
template <typename T> template <typename T>
static void TimecycSlider(const char* label, T* data, int min, int max); static void TimecycSlider(const char* label, T* data, int min, int max);
public: public:
@ -39,6 +39,7 @@ void Visual::TimecycSlider(const char* label, T* ptr, int min, int max)
{ {
int val = CalcArrayIndex(); int val = CalcArrayIndex();
#ifdef GTASA #ifdef GTASA
// Compatable with 24h TimeCyc
T* arr = static_cast<T*>(patch::GetPointer(int(ptr))); T* arr = static_cast<T*>(patch::GetPointer(int(ptr)));
#elif GTAVC #elif GTAVC
T* arr = static_cast<T*>(ptr); T* arr = static_cast<T*>(ptr);