Skip to content

Commit

Permalink
improved version game detect
Browse files Browse the repository at this point in the history
  • Loading branch information
EtoShinya committed Jan 11, 2024
1 parent 05fd1b6 commit f85c01d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
47 changes: 32 additions & 15 deletions minty/Utils/util.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
#include "util.h"

namespace util {
std::vector<std::string> split(const std::string& content, const std::string& delimiter) {
std::vector<std::string> 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<std::string> split(const std::string& content, const std::string& delimiter) {
std::vector<std::string> 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::milliseconds>(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::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
}
21 changes: 12 additions & 9 deletions minty/Utils/util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <regex>
#include <filesystem>
#include <string>
#include <vector>
#include <fstream>
Expand All @@ -16,14 +18,15 @@
#define SAFE_EEND() SAFE_ERROR(); SAFE_END();

namespace util {
std::vector<std::string> split(const std::string& content, const std::string& delimiter);
int64_t GetCurrentTimeMillisec();
std::string getUAHash(std::string execPath);
std::vector<std::string> split(const std::string& content, const std::string& delimiter);
int64_t GetCurrentTimeMillisec();

template <typename T>
const char* get_ptr(const T& value) {
std::stringstream ss;
ss << std::hex << std::showbase << reinterpret_cast<const void*>(value);
static std::string result = ss.str();
return result.c_str();
}
template <typename T>
const char* get_ptr(const T& value) {
std::stringstream ss;
ss << std::hex << std::showbase << reinterpret_cast<const void*>(value);
static std::string result = ss.str();
return result.c_str();
}
}
21 changes: 13 additions & 8 deletions minty/il2cpp/il2cpp-init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ enum class GameVersion {
};

GameVersion getGameVersion() {
std::string execPath = config::getValue<std::string>("general", "execPath", "").getValue();

if (execPath.find("GenshinImpact.exe") != std::string::npos)
return GameVersion::GLOBAL;
// 4.3.0 (pkg_version -> md5)
std::array<std::pair<GameVersion, std::string>, 2> gameVersions = {{
{ GameVersion::GLOBAL, "218603b67495dab9f6ce28515451c231" },
{ GameVersion::CHINA, "9171a8aba135d881b082bcdd6174d812" }
}};
std::string hash = util::getUAHash(config::getValue<std::string>("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;
}

Expand All @@ -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"
Expand Down

0 comments on commit f85c01d

Please sign in to comment.