From 82ab5a316c77693da5b13168b2cd051411cc5332 Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Sat, 11 Jun 2022 22:04:24 +0800 Subject: [PATCH] Implement il2cpp initialize method --- lib/src/il2cpp-init.cpp | 45 +++++++++++++++++++++++++++++++++++++++++ lib/src/pch.h | 12 ++++++++++- lib/src/util.h | 3 +++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/src/il2cpp-init.cpp diff --git a/lib/src/il2cpp-init.cpp b/lib/src/il2cpp-init.cpp new file mode 100644 index 0000000..910eb9e --- /dev/null +++ b/lib/src/il2cpp-init.cpp @@ -0,0 +1,45 @@ +#include "pch.h" + +#include "il2cpp-init.h" + +#define DO_API(r, n, p) r (*n) p +#include "il2cpp-api-functions.h" +#undef DO_API + +#define DO_APP_FUNC(a, r, n, p) r (*n) p +namespace Genshin { +#include "il2cpp-functions.h" +} +#undef DO_APP_FUNC + +using std::string; + +ull GetAddressByExports(HMODULE base, const char* name) { + ull funcAddr = reinterpret_cast(GetProcAddress(base, name)); + return funcAddr == 0 ? 0 : funcAddr; +} + +ull milliseconds_now() { + static LARGE_INTEGER s_frequency; + static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency); + if (s_use_qpc) { + LARGE_INTEGER now; + QueryPerformanceCounter(&now); + return (1000LL * now.QuadPart) / s_frequency.QuadPart; + } else { + return GetTickCount64(); + } +} + +void InitIL2CPP() { + auto start = milliseconds_now(); + auto hBase = GetModuleHandle("UserAssembly.dll"); + auto bAddr = (ull)hBase; + #define DO_API(r, n, p) n = (r (*) p) GetAddressByExports(hBase, #n); + #include "il2cpp-api-functions.h" + #undef DO_API + #define DO_APP_FUNC(a, r, n, p) n = (r (*) p)(bAddr + a) + #include "il2cpp-functions.h" + #undef DO_APP_FUNC + printf("Initialized in %llu ms.\n", milliseconds_now() - start); +} diff --git a/lib/src/pch.h b/lib/src/pch.h index 3136437..c1cd9d0 100644 --- a/lib/src/pch.h +++ b/lib/src/pch.h @@ -7,10 +7,20 @@ #ifndef PCH_H #define PCH_H +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include + // 添加要在此处预编译的标头 + +typedef unsigned long long ull; + #include #include +#include +#include #include -#include "framework.h" +#include +#include "il2cpp-appdata.h" #endif //PCH_H diff --git a/lib/src/util.h b/lib/src/util.h index dc42037..e93e901 100644 --- a/lib/src/util.h +++ b/lib/src/util.h @@ -1,3 +1,6 @@ #pragma once HWND FindMainWindowByPID(DWORD pid); + +#define ErrorDialogT(title, msg) MessageBox(unityWnd, msg, title, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); +#define ErrorDialog(msg) ErrorDialogT("YaeAchievement", msg)