Add update checker
This commit is contained in:
parent
1ec2899450
commit
54e9d8e9dd
1
.vscode/c_cpp_properties.json
vendored
1
.vscode/c_cpp_properties.json
vendored
@ -11,6 +11,7 @@
|
|||||||
"${PLUGIN_SDK_DIR}/shared/game"
|
"${PLUGIN_SDK_DIR}/shared/game"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
|
"CONSOLE=std::cout",
|
||||||
"GTASA",
|
"GTASA",
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
"UNICODE",
|
"UNICODE",
|
||||||
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -76,7 +76,10 @@
|
|||||||
"thread": "cpp",
|
"thread": "cpp",
|
||||||
"trampoline.h": "c",
|
"trampoline.h": "c",
|
||||||
"minhook.h": "c",
|
"minhook.h": "c",
|
||||||
"*.rh": "cpp"
|
"*.rh": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"stop_token": "cpp",
|
||||||
|
"iostream": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "Enabled",
|
"C_Cpp.errorSquiggles": "Enabled",
|
||||||
"C_Cpp.intelliSenseEngineFallback": "Enabled"
|
"C_Cpp.intelliSenseEngineFallback": "Enabled"
|
||||||
|
@ -52,6 +52,8 @@ set(src_files
|
|||||||
"src/Teleport.h"
|
"src/Teleport.h"
|
||||||
"src/Ui.cpp"
|
"src/Ui.cpp"
|
||||||
"src/Ui.h"
|
"src/Ui.h"
|
||||||
|
"src/Updater.h"
|
||||||
|
"src/Updater.cpp"
|
||||||
"src/Util.cpp"
|
"src/Util.cpp"
|
||||||
"src/Util.h"
|
"src/Util.h"
|
||||||
"src/Vehicle.cpp"
|
"src/Vehicle.cpp"
|
||||||
@ -175,6 +177,7 @@ d3dx9
|
|||||||
d3d11
|
d3d11
|
||||||
d3dx11
|
d3dx11
|
||||||
XInput9_1_0
|
XInput9_1_0
|
||||||
|
urlmon
|
||||||
Depend
|
Depend
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "CheatMenu.h"
|
#include "CheatMenu.h"
|
||||||
#include "MenuInfo.h"
|
#include "MenuInfo.h"
|
||||||
#include "Ui.h"
|
#include "Ui.h"
|
||||||
|
#include "Updater.h"
|
||||||
|
|
||||||
void CheatMenu::DrawWindow()
|
void CheatMenu::DrawWindow()
|
||||||
{
|
{
|
||||||
@ -184,7 +185,7 @@ void MenuThread(void* param)
|
|||||||
MessageBox(RsGlobal.ps->window, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR);
|
MessageBox(RsGlobal.ps->window, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl;
|
flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl;
|
||||||
CFastman92limitAdjuster::Init();
|
CFastman92limitAdjuster::Init();
|
||||||
CheatMenu *menu = new CheatMenu;
|
CheatMenu *menu = new CheatMenu;
|
||||||
@ -194,6 +195,12 @@ void MenuThread(void* param)
|
|||||||
Sleep(100);
|
Sleep(100);
|
||||||
if (KeyPressed(VK_LSHIFT) && KeyPressed(VK_BACK))
|
if (KeyPressed(VK_LSHIFT) && KeyPressed(VK_BACK))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (Updater::state == UPDATER_CHECKING)
|
||||||
|
{
|
||||||
|
Updater::CheckForUpdates();
|
||||||
|
Updater::state = UPDATER_IDLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete menu;
|
delete menu;
|
||||||
@ -212,7 +219,7 @@ void MenuThread(void* param)
|
|||||||
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
|
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
|
||||||
{
|
{
|
||||||
if (nReason == DLL_PROCESS_ATTACH)
|
if (nReason == DLL_PROCESS_ATTACH)
|
||||||
{
|
{
|
||||||
uint gameVersion = GetGameVersion();
|
uint gameVersion = GetGameVersion();
|
||||||
if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT)
|
if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT)
|
||||||
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, NULL, NULL, NULL);
|
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, NULL, NULL, NULL);
|
||||||
|
15
src/Menu.cpp
15
src/Menu.cpp
@ -6,6 +6,7 @@
|
|||||||
#include "Vehicle.h"
|
#include "Vehicle.h"
|
||||||
#include "Ui.h"
|
#include "Ui.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "Updater.h"
|
||||||
|
|
||||||
Menu::Menu()
|
Menu::Menu()
|
||||||
{
|
{
|
||||||
@ -433,12 +434,20 @@ void Menu::Draw()
|
|||||||
{
|
{
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
if (ImGui::Button("Discord server", ImVec2(Ui::GetSize(2))))
|
if (ImGui::Button("Check update", ImVec2(Ui::GetSize(3))))
|
||||||
|
{
|
||||||
|
if (Updater::state == UPDATER_IDLE)
|
||||||
|
Updater::state = UPDATER_CHECKING;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button("Discord server", ImVec2(Ui::GetSize(3))))
|
||||||
ShellExecute(NULL, "open", DISCORD_INVITE, NULL, NULL, SW_SHOWNORMAL);
|
ShellExecute(NULL, "open", DISCORD_INVITE, NULL, NULL, SW_SHOWNORMAL);
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
if (ImGui::Button("GitHub repo", ImVec2(Ui::GetSize(2))))
|
if (ImGui::Button("GitHub repo", ImVec2(Ui::GetSize(3))))
|
||||||
ShellExecute(NULL, "open", GITHUB_LINK, NULL, NULL, SW_SHOWNORMAL);
|
ShellExecute(NULL, "open", GITHUB_LINK, NULL, NULL, SW_SHOWNORMAL);
|
||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
@ -451,7 +460,7 @@ void Menu::Draw()
|
|||||||
ImGui::Text((std::string("Version: ") + MENU_VERSION).c_str());
|
ImGui::Text((std::string("Version: ") + MENU_VERSION).c_str());
|
||||||
|
|
||||||
ImGui::NextColumn();
|
ImGui::NextColumn();
|
||||||
ImGui::Text(std::string("Imgui: " + std::string(ImGui::GetVersion())).c_str());
|
ImGui::Text(std::string("ImGui: " + std::string(ImGui::GetVersion())).c_str());
|
||||||
ImGui::Text((std::string("Build: ") + BUILD_NUMBER).c_str());
|
ImGui::Text((std::string("Build: ") + BUILD_NUMBER).c_str());
|
||||||
|
|
||||||
ImGui::Columns(1);
|
ImGui::Columns(1);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#define MENU_NAME "Cheat Menu"
|
#define MENU_NAME "Cheat Menu"
|
||||||
#define MENU_VERSION "2.6-beta"
|
#define MENU_VERSION_NUMBER "2.3"
|
||||||
|
#define MENU_VERSION MENU_VERSION_NUMBER"-beta"
|
||||||
#define BUILD_NUMBER "20210308"
|
#define BUILD_NUMBER "20210308"
|
||||||
#define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")"
|
#define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")"
|
25
src/Updater.cpp
Normal file
25
src/Updater.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "Updater.h"
|
||||||
|
#include "pch.h"
|
||||||
|
#include "MenuInfo.h"
|
||||||
|
|
||||||
|
void Updater::CheckForUpdates()
|
||||||
|
{
|
||||||
|
LPCSTR link = "https://api.github.com/repos/user-grinch/Cheat-Menu/tags";
|
||||||
|
LPCSTR path = PLUGIN_PATH((char*)"CheatMenu\\json\\versioninfo.json");
|
||||||
|
HRESULT res = URLDownloadToFile(NULL, link, path, 0, NULL);
|
||||||
|
|
||||||
|
if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE)
|
||||||
|
{
|
||||||
|
CHud::SetHelpMessage("Failed to check for updates",false,false,false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CJson verinfo = CJson("versioninfo");
|
||||||
|
|
||||||
|
// fetch the version number
|
||||||
|
std::string latest_version = verinfo.data.items().begin().value()["name"].get<std::string>();
|
||||||
|
|
||||||
|
if (latest_version > MENU_VERSION_NUMBER)
|
||||||
|
CHud::SetHelpMessage("Update found",false,false,false);
|
||||||
|
else
|
||||||
|
CHud::SetHelpMessage("No update found.",false,false,false);
|
||||||
|
}
|
19
src/Updater.h
Normal file
19
src/Updater.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum UPDATER_STATE
|
||||||
|
{
|
||||||
|
UPDATER_IDLE,
|
||||||
|
UPDATER_CHECKING,
|
||||||
|
UPDATER_DOWNLOADING,
|
||||||
|
UPDATER_DOWNLOADED,
|
||||||
|
UPDATER_INSTALLING,
|
||||||
|
UPDATER_NO_UPDATE,
|
||||||
|
UPDATER_UPDATE_FOUND
|
||||||
|
};
|
||||||
|
|
||||||
|
class Updater
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline static UPDATER_STATE state = UPDATER_IDLE;
|
||||||
|
static void CheckForUpdates();
|
||||||
|
};
|
@ -11,25 +11,28 @@ template <class T>
|
|||||||
class VehExtender
|
class VehExtender
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
inline static std::vector<std::pair<CVehicle*,T>> data;
|
inline static std::vector<std::pair<CVehicle*,T>> data{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void RemoveVehEntry(CVehicle *pVeh)
|
static void RemoveVehEntry(CVehicle *pVeh)
|
||||||
{
|
{
|
||||||
for (auto it = data.begin(); it < data.end(); ++it)
|
for (auto it = data.begin(); it != data.end(); it++)
|
||||||
{
|
{
|
||||||
if (it->first == pVeh)
|
if (it->first == pVeh)
|
||||||
|
{
|
||||||
data.erase(it);
|
data.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VehExtender()
|
VehExtender()
|
||||||
{
|
{
|
||||||
plugin::Events::vehicleCtorEvent.after += RemoveVehEntry;
|
plugin::Events::vehicleDtorEvent.before += RemoveVehEntry;
|
||||||
}
|
}
|
||||||
~VehExtender()
|
~VehExtender()
|
||||||
{
|
{
|
||||||
plugin::Events::vehicleCtorEvent.after -= RemoveVehEntry;
|
plugin::Events::vehicleDtorEvent.before -= RemoveVehEntry;
|
||||||
}
|
}
|
||||||
VehExtender(const VehExtender&) = delete;
|
VehExtender(const VehExtender&) = delete;
|
||||||
|
|
||||||
|
@ -1 +1,3 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
std::ofstream flog = std::ofstream("CheatMenu.log");
|
||||||
|
CJson config = CJson("config");
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -87,8 +88,8 @@ struct Globals
|
|||||||
inline static void* device = nullptr;
|
inline static void* device = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline static std::ofstream flog = std::ofstream("CheatMenu.log");
|
extern std::ofstream flog;
|
||||||
inline static CJson config = CJson("config");
|
extern CJson config;
|
||||||
|
|
||||||
struct TextureStructure
|
struct TextureStructure
|
||||||
{
|
{
|
||||||
|
@ -1,31 +1,10 @@
|
|||||||
#include "plugin.h"
|
#include <windows.h>
|
||||||
#include "CHud.h"
|
|
||||||
|
|
||||||
using namespace plugin;
|
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
|
||||||
|
|
||||||
void DoStuff();
|
|
||||||
|
|
||||||
class Test
|
|
||||||
{
|
{
|
||||||
public:
|
if (nReason == DLL_PROCESS_ATTACH)
|
||||||
|
MessageBox(NULL, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR);
|
||||||
Test()
|
|
||||||
{
|
|
||||||
Events::processScriptsEvent += DoStuff;
|
|
||||||
}
|
|
||||||
~Test()
|
|
||||||
{
|
|
||||||
Events::processScriptsEvent -= DoStuff;
|
|
||||||
}
|
|
||||||
} test;
|
|
||||||
|
|
||||||
void DoStuff()
|
|
||||||
{
|
|
||||||
CHud::SetMessage((char*)"Test");
|
|
||||||
|
|
||||||
if (KeyPressed(VK_TAB))
|
|
||||||
{
|
|
||||||
test.~Test();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user