Refactor code & cleanup

This commit is contained in:
Grinch_ 2022-01-05 04:33:07 +06:00
parent 48b519af03
commit 6044deb156
19 changed files with 288 additions and 227 deletions

View File

@ -32,12 +32,12 @@ Be sure to check [here](https://github.com/user-grinch/Cheat-Menu/issues/48) to
## Incompatible Mods
### GTA SA
1. **ENB/ SA_DirectX 2.0** - **FIX:** disable Effect/ Enable water
2. **MSI Afterburner** - **FIX:** Enable Stealth mode in rivatuner
1. **ENB/ SA_DirectX 2.0** **FIX:** Disable Effect/ Enable water
2. **MSI Afterburner** **FIX:** Enable Stealth mode in rivatuner
3. **GTA Underground**
### GTA III
1. SilentPatch **ddraw.dll** component. Just delete it for now.
1. SilentPatch **ddraw.dll** component. **FIX:** Delete ddraw.dll file for now
Let me know if you mind more.

View File

@ -34,13 +34,18 @@ void CheatMenu::DrawWindow()
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200));
if (Updater::m_State == UPDATER_UPDATE_FOUND)
if (Updater::IsUpdateAvailable())
{
Updater::ShowUpdateScreen();
ShowUpdateScreen();
}
else
{
Ui::DrawHeaders(header);
if (Ui::m_HeaderId == -1)
{
ShowWelcomeScreen();
}
}
if (m_bSizeChangedExternal)
@ -113,6 +118,74 @@ CheatMenu::CheatMenu()
};
}
void CheatMenu::ShowWelcomeScreen()
{
ImGui::BeginChild("WelcomeScreen");
ImGui::NewLine();
Ui::CenterdText("Welcome to Cheat Menu");
Ui::CenterdText("Author: Grinch_");
ImGui::NewLine();
ImGui::TextWrapped("Please ensure you have the latest version from GitHub.");
ImGui::NewLine();
if (ImGui::Button("Discord server", ImVec2(Ui::GetSize(2))))
{
ShellExecute(nullptr, "open", DISCORD_INVITE, nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("GitHub repo", ImVec2(Ui::GetSize(2))))
{
ShellExecute(nullptr, "open", GITHUB_LINK, nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::NewLine();
ImGui::TextWrapped("If you find bugs or have suggestions, you can let me know on discord :)");
ImGui::Dummy(ImVec2(0, 30));
Ui::CenterdText("Copyright Grinch_ 2019-2022. All rights reserved.");
ImGui::EndChild();
}
void CheatMenu::ShowUpdateScreen()
{
ImGui::BeginChild("UPdateScreen");
std::string ver = Updater::GetUpdateVersion();
ImGui::Dummy(ImVec2(0, 20));
Ui::CenterdText("A new version of the mod is available.");
Ui::CenterdText(std::string("Current version: ") + MENU_VERSION);
Ui::CenterdText("Latest version: " + ver);
ImGui::Dummy(ImVec2(0, 10));
ImGui::TextWrapped("In order to keep using the menu, you need to update to the latest version."
" This is to ensure everything is using the most up-to-date version.");
ImGui::Dummy(ImVec2(0, 10));
ImGui::TextWrapped("To know what changes are made or to download, click on the \"Download page\" button."
" Follow the instructions there. If you're still having issues, let me know on discord.");
ImGui::Dummy(ImVec2(0, 5));
if (ImGui::Button("Discord server", ImVec2(Ui::GetSize(3))))
{
ShellExecute(NULL, "open", DISCORD_INVITE, NULL, NULL, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("Download page", Ui::GetSize(3)))
{
ShellExecute(NULL, "open", std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" +
ver).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("Hide page", Ui::GetSize(3)))
{
Updater::ResetUpdaterState();
}
ImGui::EndChild();
}
void CheatMenu::ApplyStyle()
{
ImGuiStyle* style = &ImGui::GetStyle();
@ -141,11 +214,11 @@ void CheatMenu::ApplyStyle()
style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.35f, 0.33f, 0.3f, 1.00f);
style->Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.05f, 0.06f, 0.95f);
style->Colors[ImGuiCol_ChildBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
style->Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 0.95f);
style->Colors[ImGuiCol_PopupBg] = ImVec4(0.06f, 0.05f, 0.06f, 0.95f);
style->Colors[ImGuiCol_Border] = ImVec4(0.12f, 0.12f, 0.12f, 1.0f);
style->Colors[ImGuiCol_BorderShadow] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_FrameBg] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f);
style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.17f, 0.17f, 0.17f, 1.00f);
style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_FrameBgActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_TitleBg] = ImVec4(0.12f, 0.12f, 0.12f, 0.94f);
style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
@ -160,16 +233,16 @@ void CheatMenu::ApplyStyle()
style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
style->Colors[ImGuiCol_Separator] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f);
style->Colors[ImGuiCol_Button] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f);
style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.17f, 0.17f, 0.17f, 1.00f);
style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f);
style->Colors[ImGuiCol_TabHovered] = ImVec4(0.17f, 0.17f, 0.17f, 1.00f);
style->Colors[ImGuiCol_TabHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_Header] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.17f, 0.17f, 0.17f, 1.00f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.12f, 0.12f, 0.12f, 0.00f);
style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.17f, 0.17f, 0.17f, 1.00f);
style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);

View File

@ -4,7 +4,7 @@
Required:
DirectX 9 SDK
Plugin SDK
Build Tools 2019 (v142)
Build Tools 2022 (v143)
Windows SDK
*/
@ -36,6 +36,8 @@ private:
static void ApplyStyle();
static void DrawWindow();
static void ShowUpdateScreen();
static void ShowWelcomeScreen();
public:
CheatMenu();

View File

@ -72,18 +72,14 @@ void MenuThread(void* param)
if (lastCheckDate != tstruct.tm_mday)
{
Updater::CheckForUpdate();
Updater::CheckUpdate();
gConfig.SetValue("config.last_update_checked", tstruct.tm_mday);
}
while (true)
{
Sleep(5000);
if (Updater::m_State == UPDATER_CHECKING)
{
Updater::CheckForUpdate();
}
Updater::Process();
}
}
@ -97,8 +93,8 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
}
else
{
gLog << "Error: Unknown game version. GTA " << BY_GAME("SA v1.0 US Hoodlum", "GTA VC v1.0 EN", "GTA III v1.0 EN") << " is required." << std::endl;
MessageBox(HWND_DESKTOP, "Unknown game version. GTA " BY_GAME("SA v1.0 US Hoodlum", "GTA VC v1.0 EN", "GTA III v1.0 EN") " is required.", "CheatMenu", MB_ICONERROR);
gLog << "Error: Unknown game version. GTA " << BY_GAME("SA v1.0 US Hoodlum", "VC v1.0 EN", "III v1.0 EN") << " is required." << std::endl;
MessageBox(HWND_DESKTOP, "Unknown game version. GTA " BY_GAME("SA v1.0 US Hoodlum", "VC v1.0 EN", "III v1.0 EN") " is required.", "CheatMenu", MB_ICONERROR);
}
}

View File

@ -1,6 +1,5 @@
#include "pch.h"
#include "filehandler.h"
#include "visual.h"
// TODO: Clean up this mess, use structures instead?
void FileHandler::GenerateHandlingFile(int pHandling, std::map<int, std::string>& storeMap)

View File

@ -1,8 +1,11 @@
#pragma once
#include <map>
#include <vector>
#include <string>
/*
FileHandler class
Handles files IO and processing
*/
class FileHandler
{
public:

View File

@ -24,7 +24,7 @@ Menu::Menu()
m_Overlay::bMemUsage = gConfig.GetValue("overlay.mem_usage", false);
m_Overlay::bVehHealth = gConfig.GetValue("overlay.veh_health", false);
m_Overlay::bVehSpeed = gConfig.GetValue("overlay.veh_speed", false);
m_Overlay::mSelectedPos = (DISPLAY_POS)gConfig.GetValue("overlay.selected_pos", (int)DISPLAY_POS::BOTTOM_RIGHT);
m_Overlay::mSelectedPos = (DisplayPos)gConfig.GetValue("overlay.selected_pos", (int)DisplayPos::BOTTOM_RIGHT);
m_Overlay::fPosX = gConfig.GetValue("overlay.pox", 0);
m_Overlay::fPosY = gConfig.GetValue("overlay.posy", 0);
m_Overlay::textColor[0] = gConfig.GetValue("overlay.text_color.r", 1.0f);
@ -91,7 +91,7 @@ void Menu::DrawOverlay()
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
if (m_Overlay::mSelectedPos == DISPLAY_POS::CUSTOM)
if (m_Overlay::mSelectedPos == DisplayPos::CUSTOM)
{
if (m_Overlay::fPosX != NULL && m_Overlay::fPosY != NULL)
{
@ -105,25 +105,25 @@ void Menu::DrawOverlay()
window_flags |= ImGuiWindowFlags_NoMove;
ImVec2 pos, pivot;
if (m_Overlay::mSelectedPos == DISPLAY_POS::TOP_LEFT)
if (m_Overlay::mSelectedPos == DisplayPos::TOP_LEFT)
{
pos = ImVec2(offset, offset);
pivot = ImVec2(0.0f, 0.0f);
}
if (m_Overlay::mSelectedPos == DISPLAY_POS::TOP_RIGHT)
if (m_Overlay::mSelectedPos == DisplayPos::TOP_RIGHT)
{
pos = ImVec2(io.DisplaySize.x - offset, offset);
pivot = ImVec2(1.0f, 0.0f);
}
if (m_Overlay::mSelectedPos == DISPLAY_POS::BOTTOM_LEFT)
if (m_Overlay::mSelectedPos == DisplayPos::BOTTOM_LEFT)
{
pos = ImVec2(offset, io.DisplaySize.y - offset);
pivot = ImVec2(0.0f, 1.0f);
}
if (m_Overlay::mSelectedPos == DISPLAY_POS::BOTTOM_RIGHT)
if (m_Overlay::mSelectedPos == DisplayPos::BOTTOM_RIGHT)
{
pos = ImVec2(io.DisplaySize.x - offset, io.DisplaySize.y - offset);
pivot = ImVec2(1.0f, 1.0f);
@ -573,10 +573,7 @@ void Menu::Draw()
if (ImGui::Button("Check update", ImVec2(Ui::GetSize(3))))
{
if (Updater::m_State == UPDATER_IDLE)
{
Updater::m_State = UPDATER_CHECKING;
}
Updater::CheckUpdate();
}
ImGui::SameLine();

View File

@ -4,7 +4,7 @@ class Menu
{
private:
enum DISPLAY_POS
enum class DisplayPos
{
CUSTOM,
TOP_LEFT,
@ -30,7 +30,7 @@ private:
{
"Custom", "Top left", "Top right", "Bottom left", "Bottom right"
};
static inline DISPLAY_POS mSelectedPos = DISPLAY_POS::BOTTOM_RIGHT;
static inline DisplayPos mSelectedPos = DisplayPos::BOTTOM_RIGHT;
static inline float fPosX;
static inline float fPosY;
static inline int mTotalRam = 0;

View File

@ -1,6 +1,5 @@
#include "pch.h"
#include "neon.h"
#include "util.h"
// Neon sprite
const unsigned char neon_mask[1689] =
@ -161,13 +160,36 @@ const unsigned char neon_mask[1689] =
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
Neon::Neon()
// Thanks DKPac22
static RwTexture* LoadTextureFromMemory(char* data, unsigned int size)
{
Events::processScriptsEvent += [this]
patch::SetChar(0x7CF9CA, rwSTREAMMEMORY);
RwMemory memoryImage;
RwInt32 width, height, depth, flags;
memoryImage.start = (RwUInt8*)data;
memoryImage.length = size;
RwImage* image = RtPNGImageRead((char*)&memoryImage);
RwImageFindRasterFormat(image, 4, &width, &height, &depth, &flags);
RwRaster* raster = RwRasterCreate(width, height, depth, flags);
RwRasterSetFromImage(raster, image);
RwImageDestroy(image);
patch::SetChar(0x7CF9CA, rwSTREAMFILENAME);
return RwTextureCreate(raster);
}
void Neon::InitHooks()
{
if (m_bInit)
{
return;
}
Events::processScriptsEvent += []
{
if (!m_pNeonTexture)
{
m_pNeonTexture = Util::LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask));
m_pNeonTexture = LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask));
}
};
@ -208,9 +230,11 @@ Neon::Neon()
}
}
};
m_bInit = true;
}
Neon::~Neon()
void Neon::RemoveHooks()
{
if (m_pNeonTexture)
{
@ -219,7 +243,7 @@ Neon::~Neon()
}
}
bool Neon::IsNeonInstalled(CVehicle* pVeh)
bool Neon::IsInstalled(CVehicle* pVeh)
{
return m_VehNeon.Get(pVeh).m_bNeonInstalled;
}
@ -234,7 +258,7 @@ void Neon::SetPulsing(CVehicle* pVeh, bool state)
m_VehNeon.Get(pVeh).m_bPulsing = state;
}
void Neon::InstallNeon(CVehicle* pVeh, int red, int green, int blue)
void Neon::Install(CVehicle* pVeh, int red, int green, int blue)
{
CRGBA& color = m_VehNeon.Get(pVeh).m_Color;
@ -246,7 +270,7 @@ void Neon::InstallNeon(CVehicle* pVeh, int red, int green, int blue)
m_VehNeon.Get(pVeh).m_bNeonInstalled = true;
}
void Neon::RemoveNeon(CVehicle* pVeh)
void Neon::Remove(CVehicle* pVeh)
{
m_VehNeon.Get(pVeh).m_bNeonInstalled = false;
}

View File

@ -30,13 +30,17 @@ private:
static inline RwTexture* m_pNeonTexture = nullptr; // pointer to the neon mask texture
static inline VehicleExtendedData<NeonData> m_VehNeon;
static inline bool m_bInit;
public:
Neon();
~Neon();
static void InstallNeon(CVehicle* veh, int red, int green, int blue);
static bool IsNeonInstalled(CVehicle* veh);
Neon() = delete;
Neon(Neon&) = delete;
static void InitHooks();
static void Install(CVehicle* veh, int red, int green, int blue);
static bool IsInstalled(CVehicle* veh);
static bool IsPulsingEnabled(CVehicle* veh);
static void SetPulsing(CVehicle* veh, bool state);
static void RemoveNeon(CVehicle* veh);
static void RemoveHooks();
static void Remove(CVehicle* veh);
};

View File

@ -27,7 +27,7 @@
#include "NodeName.h"
#include "util.h"
Paint::Paint()
void Paint::InitHooks()
{
Events::vehicleRenderEvent.before += [](CVehicle* pVeh)
{
@ -142,16 +142,16 @@ void Paint::NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function<v
return;
}
void Paint::UpdateNodeListRecursive(CVehicle* pVeh)
void Paint::GenerateNodeList(CVehicle* pVeh, std::vector<std::string>& names_vec)
{
RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent;
NodeWrapperRecursive(frame, pVeh, [](RwFrame* frame)
NodeWrapperRecursive(frame, pVeh, [&](RwFrame* frame)
{
const std::string name = GetFrameNodeName(frame);
if (!(std::find(veh_nodes::names_vec.begin(), veh_nodes::names_vec.end(), name) != veh_nodes::names_vec.end()))
veh_nodes::names_vec.push_back(name);
if (!(std::find(names_vec.begin(), names_vec.end(), name) != names_vec.end()))
names_vec.push_back(name);
});
}

View File

@ -23,6 +23,7 @@
// SOFTWARE.
#pragma once
#include <vector>
class Paint
{
@ -70,19 +71,13 @@ private:
void resetMaterialTexture(RpMaterial* material);
};
static inline VehicleExtendedData<VehData> m_VehData;
static void NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function<void(RwFrame*)> func);
protected:
public:
static inline ResourceStore m_TextureData { "textures", eResourceType::TYPE_IMAGE, ImVec2(100, 80) };
struct veh_nodes
{
static inline std::vector<std::string> names_vec{"Default"};
static inline std::string selected = "Default";
};
Paint();
static void UpdateNodeListRecursive(CVehicle* pVeh);
static void NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function<void(RwFrame*)> func);
static void InitHooks();
static void GenerateNodeList(CVehicle* pVeh, std::vector<std::string>& names_vec);
static void SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, bool filter_mat = false);
static void SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string texturename, bool filter_mat = false);
static void ResetNodeColor(CVehicle* veh, std::string node_name);

View File

@ -234,7 +234,7 @@ void Ui::DrawHeaders(CallbackTable& data)
ImGui::PushFont(FontMgr::GetFont("header"));
ImDrawList *pDrawList = ImGui::GetWindowDrawList();
for (int i = 0; i < data.size(); ++i)
for (size_t i = 0; i < data.size(); ++i)
{
const char* btn_text = data[i].first.c_str();
@ -283,35 +283,7 @@ void Ui::DrawHeaders(CallbackTable& data)
ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0, 10));
if (m_HeaderId == -1)
{
// Show Welcome page
ImGui::NewLine();
CenterdText("Welcome to Cheat Menu");
CenterdText("Author: Grinch_");
ImGui::NewLine();
ImGui::TextWrapped("Please ensure you have the latest version from GitHub.");
ImGui::NewLine();
if (ImGui::Button("Discord server", ImVec2(GetSize(2))))
{
ShellExecute(nullptr, "open", DISCORD_INVITE, nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("GitHub repo", ImVec2(GetSize(2))))
{
ShellExecute(nullptr, "open", GITHUB_LINK, nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::NewLine();
ImGui::TextWrapped("If you find bugs or have suggestions, you can let me know on discord :)");
ImGui::Dummy(ImVec2(0, 30));
CenterdText("Copyright Grinch_ 2019-2022. All rights reserved.");
}
else
if (m_HeaderId != -1)
{
if (pCallback != nullptr && ImGui::BeginChild("TABSBAR"))
{

View File

@ -1,11 +1,37 @@
#include "pch.h"
#include "updater.h"
#include "ui.h"
#include "menuinfo.h"
#include "util.h"
void Updater::CheckForUpdate()
bool Updater::IsUpdateAvailable()
{
return Updater::curState == States::FOUND;
}
void Updater::ResetUpdaterState()
{
Updater::curState = States::IDLE;
}
std::string Updater::GetUpdateVersion()
{
return Updater::latestVer;
}
void Updater::CheckUpdate()
{
if (Updater::curState == States::IDLE)
{
Updater::curState = States::CHECKING;
}
}
void Updater::Process()
{
if (Updater::curState != States::CHECKING)
{
return;
}
const char* link = "https://api.github.com/repos/user-grinch/Cheat-Menu/tags";
char* path = PLUGIN_PATH((char*)"CheatMenu/json/versioninfo.json");
HRESULT res = URLDownloadToFile(NULL, link, path, 0, NULL);
@ -21,56 +47,21 @@ void Updater::CheckForUpdate()
// fetch the version number
if (verinfo.m_Data.empty())
{
m_LatestVersion = MENU_VERSION_NUMBER;
latestVer = MENU_VERSION_NUMBER;
}
else
{
m_LatestVersion = verinfo.m_Data.items().begin().value()["name"].get<std::string>();
latestVer = verinfo.m_Data.items().begin().value()["name"].get<std::string>();
}
if (m_LatestVersion > MENU_VERSION_NUMBER)
if (latestVer > MENU_VERSION_NUMBER)
{
SetHelpMessage("Update found", false, false, false);
m_State = UPDATER_UPDATE_FOUND;
curState = States::FOUND;
}
else
{
SetHelpMessage("No update found.", false, false, false);
Updater::m_State = UPDATER_IDLE;
}
}
void Updater::ShowUpdateScreen()
{
ImGui::Dummy(ImVec2(0, 20));
Ui::CenterdText("A new version of the mod is available.");
Ui::CenterdText(std::string("Current version: ") + MENU_VERSION);
Ui::CenterdText("Latest version: " + Updater::m_LatestVersion);
ImGui::Dummy(ImVec2(0, 10));
ImGui::TextWrapped("In order to keep using the menu, you need to update to the latest version."
" This is to ensure everything is using the most up-to-date version.");
ImGui::Dummy(ImVec2(0, 10));
ImGui::TextWrapped("To know what changes are made or to download, click on the \"Download page\" button."
" Follow the instructions there. If you're still having issues, let me know on discord.");
ImGui::Dummy(ImVec2(0, 5));
if (ImGui::Button("Discord server", ImVec2(Ui::GetSize(3))))
{
ShellExecute(NULL, "open", DISCORD_INVITE, NULL, NULL, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("Download page", Ui::GetSize(3)))
{
ShellExecute(NULL, "open", std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" +
Updater::m_LatestVersion).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("Hide page", Ui::GetSize(3)))
{
Updater::m_State = UPDATER_IDLE;
Updater::curState = States::IDLE;
}
}

View File

@ -1,19 +1,31 @@
#pragma once
#include <string>
enum UPDATER_STATE
{
UPDATER_IDLE,
UPDATER_CHECKING,
UPDATER_UPDATE_FOUND
};
/*
Update class
Checks for menu updates and provides a way to update the menu.
*/
class Updater
{
public:
static inline UPDATER_STATE m_State = UPDATER_IDLE;
static inline std::string m_LatestVersion;
static void CheckForUpdate();
static void ShowUpdateScreen();
private:
enum class States
{
IDLE,
CHECKING,
FOUND
};
static inline States curState = States::IDLE;
static inline std::string latestVer;
public:
Updater() = delete;
Updater(const Updater&) = delete;
static void CheckUpdate();
static std::string GetUpdateVersion();
static bool IsUpdateAvailable();
// Needs to run in it's own thread to prevent the game from freezing
static void Process();
static void ResetUpdaterState();
};

View File

@ -4,9 +4,9 @@
std::string Util::GetLocationName(CVector* pos)
{
CPlayerPed *pPlayer = FindPlayerPed();
#ifdef GTASA
CPlayerPed *pPlayer = FindPlayerPed();
int hplayer = CPools::GetPedRef(pPlayer);
int interior = 0;
@ -39,38 +39,13 @@ std::string Util::GetLocationName(CVector* pos)
return std::string("Interior ") + std::to_string(interior) + ", " + town;
#elif GTAVC
if (pPlayer)
{
return std::to_string(pPlayer->m_nInterior) + ", Vice City" ;
}
else
{
return "Vice City";
}
#else
return "Liberty City";
#endif
}
#ifdef GTASA
// Thanks DKPac22
RwTexture* Util::LoadTextureFromMemory(char* data, unsigned int size)
{
patch::SetChar(0x7CF9CA, rwSTREAMMEMORY);
RwMemory memoryImage;
RwInt32 width, height, depth, flags;
memoryImage.start = (RwUInt8*)data;
memoryImage.length = size;
RwImage* image = RtPNGImageRead((char*)&memoryImage);
RwImageFindRasterFormat(image, 4, &width, &height, &depth, &flags);
RwRaster* raster = RwRasterCreate(width, height, depth, flags);
RwRasterSetFromImage(raster, image);
RwImageDestroy(image);
patch::SetChar(0x7CF9CA, rwSTREAMFILENAME);
return RwTextureCreate(raster);
}
void Util::ClearCharTasksVehCheck(CPed* ped)
{
uint hped = CPools::GetPedRef(ped);
@ -97,8 +72,7 @@ void Util::ClearCharTasksVehCheck(CPed* ped)
bool Util::IsOnMission()
{
return FindPlayerPed()->CanPlayerStartMission() && !*(patch::Get<char*>(0x5D5380, false) +
CTheScripts::OnAMissionFlag);
return FindPlayerPed()->CanPlayerStartMission() && !*(patch::Get<char*>(0x5D5380, false) + CTheScripts::OnAMissionFlag);
}
int Util::GetLargestGangInZone()

View File

@ -2,28 +2,30 @@
#include "tchar.h"
#include "pdh.h"
static PDH_HQUERY cpuQuery;
static PDH_HCOUNTER cpuTotal;
static ULARGE_INTEGER lastCPU, lastSysCPU, lastUserCPU;
static int numProcessors;
static HANDLE self;
class Util
{
private:
static inline PDH_HQUERY cpuQuery;
static inline PDH_HCOUNTER cpuTotal;
static inline ULARGE_INTEGER lastCPU, lastSysCPU, lastUserCPU;
static inline int numProcessors;
static inline HANDLE self;
public:
Util() = delete;
Util(Util&) = delete;
#ifdef GTASA
static void ClearCharTasksVehCheck(CPed* ped);
static int GetLargestGangInZone();
static RwTexture* LoadTextureFromMemory(char* data, unsigned int size);
#endif
static CPed* GetClosestPed();
static CVehicle* GetClosestVehicle();
static std::string GetLocationName(CVector* pos);
static bool IsOnMission();
static bool IsOnCutscene();
static void RainbowValues(int& r, int& g, int& b, float speed);
static void GetCPUUsageInit();
static double GetCurrentCPUUsage();
static std::string GetLocationName(CVector* pos);
static bool IsOnCutscene();
static bool IsOnMission();
static void RainbowValues(int& r, int& g, int& b, float speed);
};

View File

@ -7,6 +7,11 @@
#include <CPopulation.h>
#include <CDamageManager.h>
#ifdef GTASA
#include "neon.h"
#include "paint.h"
#endif
void Vehicle::FixVehicle(CVehicle *pVeh)
{
#ifdef GTASA
@ -68,7 +73,10 @@ Vehicle::Vehicle()
{
#ifdef GTASA
FileHandler::FetchHandlingID(m_VehicleIDE);
Neon::InitHooks();
Paint::InitHooks();
#endif
FileHandler::FetchColorData(m_CarcolsColorData);
Events::processScriptsEvent += [this]
@ -184,7 +192,7 @@ Vehicle::Vehicle()
int red, green, blue;
Util::RainbowValues(red, green, blue, 0.25);
InstallNeon(pVeh, red, green, blue);
Neon::Install(pVeh, red, green, blue);
m_Neon::m_nRainbowTimer = timer;
}
#endif
@ -213,9 +221,9 @@ Vehicle::Vehicle()
chance = Random(1, 3);
}
if (chance == 1 && !IsNeonInstalled(veh) && veh->m_pDriver != pPlayer)
if (chance == 1 && !Neon::IsInstalled(veh) && veh->m_pDriver != pPlayer)
{
InstallNeon(veh, Random(0, 255), Random(0, 255), Random(0, 255));
Neon::Install(veh, Random(0, 255), Random(0, 255), Random(0, 255));
}
}
m_Neon::m_bTrafficTimer = timer;
@ -239,6 +247,13 @@ Vehicle::Vehicle()
};
}
Vehicle::~Vehicle()
{
#ifdef GTASA
Neon::RemoveHooks();
#endif
}
#ifdef GTASA
void Vehicle::AddComponent(const std::string& component, const bool display_message)
{
@ -1055,24 +1070,24 @@ void Vehicle::Draw()
if (ImGui::BeginTabItem("Color"))
{
#ifdef GTASA
Paint::UpdateNodeListRecursive(veh);
Paint::GenerateNodeList(veh, m_Paint::m_vecNames);
ImGui::Spacing();
if (ImGui::Button("Reset color", ImVec2(Ui::GetSize())))
{
Paint::ResetNodeColor(veh, Paint::veh_nodes::selected);
Paint::ResetNodeColor(veh, m_Paint::m_Selected);
SetHelpMessage("Color reset", false, false, false);
}
ImGui::Spacing();
Ui::ListBoxStr("Component", Paint::veh_nodes::names_vec, Paint::veh_nodes::selected);
Ui::ListBoxStr("Component", m_Paint::m_vecNames, m_Paint::m_Selected);
if (ImGui::ColorEdit3("Color picker", m_Color::m_fColorPicker))
if (ImGui::ColorEdit3("Color picker", m_Paint::m_fColorPicker))
{
uchar r = m_Color::m_fColorPicker[0] * 255;
uchar g = m_Color::m_fColorPicker[1] * 255;
uchar b = m_Color::m_fColorPicker[2] * 255;
Paint::SetNodeColor(veh, Paint::veh_nodes::selected, { r, g, b, 255 }, m_Color::m_bMatFilter);
uchar r = m_Paint::m_fColorPicker[0] * 255;
uchar g = m_Paint::m_fColorPicker[1] * 255;
uchar b = m_Paint::m_fColorPicker[2] * 255;
Paint::SetNodeColor(veh, m_Paint::m_Selected, { r, g, b, 255 }, m_Paint::m_bMatFilter);
}
#endif
@ -1080,13 +1095,13 @@ void Vehicle::Draw()
ImGui::Columns(2, NULL, false);
#ifdef GTASA
ImGui::Checkbox("Material filter", &m_Color::m_bMatFilter);
ImGui::RadioButton("Primary", &m_Color::m_nRadioButton, 1);
ImGui::RadioButton("Secondary", &m_Color::m_nRadioButton, 2);
ImGui::Checkbox("Material filter", &m_Paint::m_bMatFilter);
ImGui::RadioButton("Primary", &m_Paint::m_nRadioButton, 1);
ImGui::RadioButton("Secondary", &m_Paint::m_nRadioButton, 2);
ImGui::NextColumn();
ImGui::NewLine();
ImGui::RadioButton("Tertiary", &m_Color::m_nRadioButton, 3);
ImGui::RadioButton("Quaternary", &m_Color::m_nRadioButton, 4);
ImGui::RadioButton("Tertiary", &m_Paint::m_nRadioButton, 3);
ImGui::RadioButton("Quaternary", &m_Paint::m_nRadioButton, 4);
#else // GTA3 & GTAVC
ImGui::RadioButton("Primary", &m_Color::m_nRadioButton, 1);
ImGui::NextColumn();
@ -1110,7 +1125,7 @@ void Vehicle::Draw()
{
if (Ui::ColorButton(colorId, m_CarcolsColorData[colorId], ImVec2(btnSize, btnSize)))
{
*(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F, 0x19B) + m_Color::m_nRadioButton) = colorId;
*(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F, 0x19B) + m_Paint::m_nRadioButton) = colorId;
}
if ((colorId + 1) % btnsInRow != 0)
@ -1130,16 +1145,18 @@ void Vehicle::Draw()
ImGui::Spacing();
if (ImGui::Button("Remove neon", ImVec2(Ui::GetSize())))
{
RemoveNeon(veh);
Neon::Remove(veh);
SetHelpMessage("Neon removed", false, false, false);
}
ImGui::Spacing();
ImGui::Columns(2, NULL, false);
bool pulsing = IsPulsingEnabled(veh);
bool pulsing = Neon::IsPulsingEnabled(veh);
if (Ui::CheckboxWithHint("Pulsing neons", &pulsing))
SetPulsing(veh, pulsing);
{
Neon::SetPulsing(veh, pulsing);
}
Ui::CheckboxWithHint("Rainbow neons", &m_Neon::m_bRainbowEffect, "Rainbow effect to neon lights");
ImGui::NextColumn();
@ -1150,8 +1167,11 @@ void Vehicle::Draw()
ImGui::Spacing();
if (ImGui::ColorEdit3("Color picker", m_Neon::m_fColorPicker))
InstallNeon(veh, m_Neon::m_fColorPicker[0] * 255, m_Neon::m_fColorPicker[1] * 255,
{
Neon::Install(veh, m_Neon::m_fColorPicker[0] * 255, m_Neon::m_fColorPicker[1] * 255,
m_Neon::m_fColorPicker[2] * 255);
}
ImGui::Spacing();
ImGui::Text("Select neon preset:");
@ -1169,29 +1189,31 @@ void Vehicle::Draw()
if (Ui::ColorButton(color_id, m_CarcolsColorData[color_id], ImVec2(btnSize, btnSize)))
{
std::vector<float>& color = m_CarcolsColorData[color_id];
InstallNeon(veh, color[0] * 255, color[1] * 255, color[2] * 255);
Neon::Install(veh, color[0] * 255, color[1] * 255, color[2] * 255);
}
if ((color_id + 1) % btnsInRow != 0)
{
ImGui::SameLine(0.0, 4.0);
}
}
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Textures"))
{
Paint::UpdateNodeListRecursive(veh);
Paint::GenerateNodeList(veh, m_Paint::m_vecNames);
ImGui::Spacing();
if (ImGui::Button("Reset texture", ImVec2(Ui::GetSize())))
{
Paint::ResetNodeTexture(veh, Paint::veh_nodes::selected);
Paint::ResetNodeTexture(veh, m_Paint::m_Selected);
SetHelpMessage("Texture reset", false, false, false);
}
ImGui::Spacing();
Ui::ListBoxStr("Component", Paint::veh_nodes::names_vec, Paint::veh_nodes::selected);
Ui::ListBoxStr("Component", m_Paint::m_vecNames, m_Paint::m_Selected);
ImGui::Spacing();
int maxpjob, curpjob;
@ -1216,13 +1238,13 @@ void Vehicle::Draw()
ImGui::Spacing();
ImGui::SameLine();
ImGui::Checkbox("Material filter", &m_Color::m_bMatFilter);
ImGui::Checkbox("Material filter", &m_Paint::m_bMatFilter);
ImGui::Spacing();
Ui::DrawImages(m_TextureData,
Ui::DrawImages(Paint::m_TextureData,
[](std::string& str)
{
Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, Paint::veh_nodes::selected, str,
m_Color::m_bMatFilter);
Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, m_Paint::m_Selected, str,
m_Paint::m_bMatFilter);
},
nullptr,
[](std::string& str)

View File

@ -1,15 +1,7 @@
#pragma once
#include "pch.h"
#ifdef GTASA
#include "neon.h"
#include "paint.h"
#endif
#ifdef GTASA
class Vehicle : public Paint, public Neon
#else // GTA3 & GTAVC
class Vehicle
#endif
{
private:
static inline bool m_bBikeFly;
@ -24,11 +16,13 @@ private:
static inline bool m_bLockSpeed;
static inline float m_fLockSpeed;
static inline std::vector<std::vector<float>> m_CarcolsColorData;
struct m_Color
struct m_Paint
{
static inline bool m_bMatFilter = true;
static inline int m_nRadioButton = 1;
static inline float m_fColorPicker[3]{ 0, 0, 0 };
static inline std::vector<std::string> m_vecNames{"Default"};
static inline std::string m_Selected = "Default";
};
#ifdef GTASA
@ -106,4 +100,5 @@ public:
static int GetModelFromName(const char* name);
static void Draw();
Vehicle();
~Vehicle();
};