diff --git a/minty/Utils/util.cpp b/minty/Utils/util.cpp index 9019064..6e2ea7b 100644 --- a/minty/Utils/util.cpp +++ b/minty/Utils/util.cpp @@ -1,23 +1,40 @@ #include "util.h" namespace util { - std::vector split(const std::string& content, const std::string& delimiter) { - std::vector tokens; - size_t pos = 0; - size_t prevPos = 0; - std::string token; + std::string getUAHash(std::string execPath) { + auto path = std::filesystem::path(execPath).parent_path() / "pkg_version"; + std::ifstream infile(path); + std::string line; + std::regex str_expr = std::regex("UserAssembly.dll.*\"([0-9a-f]{32})\""); + auto match = std::smatch(); - while ((pos = content.find(delimiter, prevPos)) != std::string::npos) { - token = content.substr(prevPos, pos - prevPos); - tokens.push_back(token); - prevPos = pos + delimiter.length(); + while (std::getline(infile, line)) { + std::regex_search(line, match, str_expr); + + if (match.size() == 2) { + return match[1].str(); + break; + } + } } - tokens.push_back(content.substr(prevPos)); - return tokens; - } + std::vector split(const std::string& content, const std::string& delimiter) { + std::vector tokens; + size_t pos = 0; + size_t prevPos = 0; + std::string token; + + while ((pos = content.find(delimiter, prevPos)) != std::string::npos) { + token = content.substr(prevPos, pos - prevPos); + tokens.push_back(token); + prevPos = pos + delimiter.length(); + } - int64_t GetCurrentTimeMillisec() { - return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - } + tokens.push_back(content.substr(prevPos)); + return tokens; + } + + int64_t GetCurrentTimeMillisec() { + return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + } } diff --git a/minty/Utils/util.h b/minty/Utils/util.h index 88c317d..4f02f1b 100644 --- a/minty/Utils/util.h +++ b/minty/Utils/util.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -16,14 +18,15 @@ #define SAFE_EEND() SAFE_ERROR(); SAFE_END(); namespace util { - std::vector split(const std::string& content, const std::string& delimiter); - int64_t GetCurrentTimeMillisec(); + std::string getUAHash(std::string execPath); + std::vector split(const std::string& content, const std::string& delimiter); + int64_t GetCurrentTimeMillisec(); - template - const char* get_ptr(const T& value) { - std::stringstream ss; - ss << std::hex << std::showbase << reinterpret_cast(value); - static std::string result = ss.str(); - return result.c_str(); - } + template + const char* get_ptr(const T& value) { + std::stringstream ss; + ss << std::hex << std::showbase << reinterpret_cast(value); + static std::string result = ss.str(); + return result.c_str(); + } } diff --git a/minty/il2cpp/il2cpp-init.hpp b/minty/il2cpp/il2cpp-init.hpp index 93cc883..13b3ff8 100644 --- a/minty/il2cpp/il2cpp-init.hpp +++ b/minty/il2cpp/il2cpp-init.hpp @@ -40,13 +40,20 @@ enum class GameVersion { }; GameVersion getGameVersion() { - std::string execPath = config::getValue("general", "execPath", "").getValue(); - - if (execPath.find("GenshinImpact.exe") != std::string::npos) - return GameVersion::GLOBAL; + // 4.3.0 (pkg_version -> md5) + std::array, 2> gameVersions = {{ + { GameVersion::GLOBAL, "218603b67495dab9f6ce28515451c231" }, + { GameVersion::CHINA, "9171a8aba135d881b082bcdd6174d812" } + }}; + std::string hash = util::getUAHash(config::getValue("general", "execPath", "").getValue()); + + for (const auto& [gameVersion, checksum] : gameVersions) { + if (checksum != hash) + continue; + + return gameVersion; + } - if (execPath.find("YuanShen.exe") != std::string::npos) - return GameVersion::CHINA; return GameVersion::NONE; } @@ -72,8 +79,6 @@ VOID init_il2cpp() { if (GetModuleHandleA("UserAssembly.dll") != nullptr) { baseAddress = (uint64_t) GetModuleHandleA("UserAssembly.dll"); unityPlayerAddress = (uint64_t) GetModuleHandleA("UnityPlayer.dll"); - //LOG_DEBUG("UserAssembly ptr: %p", baseAddress); - //LOG_DEBUG("UnityPlayer ptr: %p", unityPlayerAddress); #define DO_API(a, b, r, n, p) n = (r (*) p)(baseAddress + SELECT_VERSION(gameVersion, a, b)) #include "il2cpp-api-functions.h"