Add update checker

This commit is contained in:
Grinch_ 2021-03-11 03:10:59 +06:00
parent 1ec2899450
commit 54e9d8e9dd
12 changed files with 94 additions and 41 deletions

View File

@ -11,6 +11,7 @@
"${PLUGIN_SDK_DIR}/shared/game"
],
"defines": [
"CONSOLE=std::cout",
"GTASA",
"_DEBUG",
"UNICODE",

View File

@ -76,7 +76,10 @@
"thread": "cpp",
"trampoline.h": "c",
"minhook.h": "c",
"*.rh": "cpp"
"*.rh": "cpp",
"bit": "cpp",
"stop_token": "cpp",
"iostream": "cpp"
},
"C_Cpp.errorSquiggles": "Enabled",
"C_Cpp.intelliSenseEngineFallback": "Enabled"

View File

@ -52,6 +52,8 @@ set(src_files
"src/Teleport.h"
"src/Ui.cpp"
"src/Ui.h"
"src/Updater.h"
"src/Updater.cpp"
"src/Util.cpp"
"src/Util.h"
"src/Vehicle.cpp"
@ -175,6 +177,7 @@ d3dx9
d3d11
d3dx11
XInput9_1_0
urlmon
Depend
)

View File

@ -2,6 +2,7 @@
#include "CheatMenu.h"
#include "MenuInfo.h"
#include "Ui.h"
#include "Updater.h"
void CheatMenu::DrawWindow()
{
@ -184,7 +185,7 @@ void MenuThread(void* param)
MessageBox(RsGlobal.ps->window, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR);
return;
}
flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl;
CFastman92limitAdjuster::Init();
CheatMenu *menu = new CheatMenu;
@ -194,6 +195,12 @@ void MenuThread(void* param)
Sleep(100);
if (KeyPressed(VK_LSHIFT) && KeyPressed(VK_BACK))
break;
if (Updater::state == UPDATER_CHECKING)
{
Updater::CheckForUpdates();
Updater::state = UPDATER_IDLE;
}
}
delete menu;
@ -212,7 +219,7 @@ void MenuThread(void* param)
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
{
if (nReason == DLL_PROCESS_ATTACH)
{
{
uint gameVersion = GetGameVersion();
if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT)
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, NULL, NULL, NULL);

View File

@ -6,6 +6,7 @@
#include "Vehicle.h"
#include "Ui.h"
#include "Util.h"
#include "Updater.h"
Menu::Menu()
{
@ -433,12 +434,20 @@ void Menu::Draw()
{
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);
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);
ImGui::Spacing();
@ -451,7 +460,7 @@ void Menu::Draw()
ImGui::Text((std::string("Version: ") + MENU_VERSION).c_str());
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::Columns(1);

View File

@ -1,5 +1,6 @@
#pragma once
#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 MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")"

25
src/Updater.cpp Normal file
View 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
View 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();
};

View File

@ -11,25 +11,28 @@ template <class T>
class VehExtender
{
private:
inline static std::vector<std::pair<CVehicle*,T>> data;
inline static std::vector<std::pair<CVehicle*,T>> data{};
public:
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)
{
data.erase(it);
break;
}
}
}
VehExtender()
{
plugin::Events::vehicleCtorEvent.after += RemoveVehEntry;
plugin::Events::vehicleDtorEvent.before += RemoveVehEntry;
}
~VehExtender()
{
plugin::Events::vehicleCtorEvent.after -= RemoveVehEntry;
plugin::Events::vehicleDtorEvent.before -= RemoveVehEntry;
}
VehExtender(const VehExtender&) = delete;

View File

@ -1 +1,3 @@
#include "pch.h"
std::ofstream flog = std::ofstream("CheatMenu.log");
CJson config = CJson("config");

View File

@ -16,6 +16,7 @@
#include <fstream>
#include <functional>
#include <memory>
#include <iostream>
#include <sstream>
#include <vector>
#include <windows.h>
@ -87,8 +88,8 @@ struct Globals
inline static void* device = nullptr;
};
inline static std::ofstream flog = std::ofstream("CheatMenu.log");
inline static CJson config = CJson("config");
extern std::ofstream flog;
extern CJson config;
struct TextureStructure
{

View File

@ -1,31 +1,10 @@
#include "plugin.h"
#include "CHud.h"
#include <windows.h>
using namespace plugin;
void DoStuff();
class Test
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
{
public:
Test()
{
Events::processScriptsEvent += DoStuff;
}
~Test()
{
Events::processScriptsEvent -= DoStuff;
}
} test;
void DoStuff()
{
CHud::SetMessage((char*)"Test");
if (KeyPressed(VK_TAB))
{
test.~Test();
}
}
if (nReason == DLL_PROCESS_ATTACH)
MessageBox(NULL, "SilentPatch isn't installed. Exiting CheatMenu.", "CheatMenu", MB_ICONERROR);
return TRUE;
}