From 338fa3d38d42eaf111780c46b807fe86aa8ea213 Mon Sep 17 00:00:00 2001 From: ByteCorum <164874887+ByteCorum@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:48:18 +0300 Subject: [PATCH] added game version check --- DragonBurn/Core/Init.h | 98 ++++++++++++++++++++----------------- DragonBurn/Helpers/Logger.h | 2 + DragonBurn/main.cpp | 34 ++++++++++++- 3 files changed, 89 insertions(+), 45 deletions(-) diff --git a/DragonBurn/Core/Init.h b/DragonBurn/Core/Init.h index b14dcaf..4a6db79 100644 --- a/DragonBurn/Core/Init.h +++ b/DragonBurn/Core/Init.h @@ -89,50 +89,60 @@ namespace Init // return rate; //} - // Checks cs2 version - //static int CheckCS2Version() - //{ - // DWORD pid = ProcessMgr.GetProcessID("cs2.exe"); - // long long curVer = -1; - // std::string processPath; - // HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); - // if (hProcess) - // { - // wchar_t buffer[MAX_PATH]; - // if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH)) - // processPath = WStringToString(buffer); - // else - // return 0; - // CloseHandle(hProcess); - // } - // else - // return 0; - - // int pos = processPath.rfind("bin"); - // if (pos != std::string::npos) - // processPath = processPath.substr(0, pos + 3); - // else - // return 0; - // processPath += "\\built_from_cl.txt"; - - // std::ifstream file(processPath); - // if (file.is_open()) - // { - // std::string line; - // if (std::getline(file, line)) - // curVer = stoi(line); - // else - // return 0; - // file.close(); - // } - // else - // return 0; - - // if (Offset.CS2ver == curVer) - // return 2; - // else - // return 1; - //} + static int CheckCS2Version() + { + DWORD pid = ProcessMgr.GetProcessID("cs2.exe"); + long curVer; + const std::string cloudVersionUrl = "https://raw.githubusercontent.com/ByteCorum/DragonBurn/data/cs2-version"; + long cloudVersion; + std::string processPath; + std::string buff; + + if (!Web::Get(cloudVersionUrl, buff)) + return 2; + cloudVersion = stoi(buff); + if (cloudVersion == -1) + return 3; + + HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); + if (hProcess) + { + wchar_t buffer[MAX_PATH]; + if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH)) + processPath = WStringToString(buffer); + else + return 0; + CloseHandle(hProcess); + } + else + return 0; + + int pos = processPath.rfind("bin"); + if (pos != std::string::npos) + processPath = processPath.substr(0, pos + 3); + else + return 0; + + processPath += "\\built_from_cl.txt"; + + std::ifstream file(processPath); + if (file.is_open()) + { + std::string line; + if (std::getline(file, line)) + curVer = stoi(line); + else + return 0; + file.close(); + } + else + return 0; + + if (cloudVersion == curVer) + return 3; + else + return 1; + } // Check if the game window is activated static bool isGameWindowActive() { diff --git a/DragonBurn/Helpers/Logger.h b/DragonBurn/Helpers/Logger.h index 1041f7a..78a8940 100644 --- a/DragonBurn/Helpers/Logger.h +++ b/DragonBurn/Helpers/Logger.h @@ -19,6 +19,7 @@ namespace Log std::cout << "[!]" << ctx << '\n'; if (pause) + SetConsoleTextAttribute(hConsole, 8); system("pause"); } @@ -26,6 +27,7 @@ namespace Log { SetConsoleTextAttribute(hConsole, 12); std::cout << "[X]" << ctx << '\n'; + SetConsoleTextAttribute(hConsole, 8); system("pause"); if(fatal) exit(0); diff --git a/DragonBurn/main.cpp b/DragonBurn/main.cpp index 9a464d2..dfcd89f 100644 --- a/DragonBurn/main.cpp +++ b/DragonBurn/main.cpp @@ -121,6 +121,38 @@ void Cheat() Sleep(20000); } + Log::PreviousLine(); + Log::Fine("Connected to CS2"); + Log::Info("Linking to CS2"); + +#if DEBUG == false + switch (Init::Client::CheckCS2Version()) + { + case 0: + Log::PreviousLine(); + Log::Error("Failed to get the current game version"); + break; + + case 1: + Log::PreviousLine(); + Log::Warning("Offsets are outdated, we'll update them asap. With current offsets, cheat may work unstable", true); + break; + + case 2: + Log::PreviousLine(); + Log::Error("Failed to get cloud version"); + break; + + case 3: + break; + + default: + Log::PreviousLine(); + Log::Error("Failed to get the current game version"); + break; + } +#endif + auto ProcessStatus = ProcessMgr.Attach("cs2.exe"); switch (ProcessStatus) { @@ -150,7 +182,7 @@ void Cheat() } Log::PreviousLine(); - Log::Fine("Connected to CS2"); + Log::Fine("Linked to CS2"); char documentsPath[MAX_PATH]; if (SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, documentsPath) != S_OK)