Implement il2cpp initialize method

This commit is contained in:
HolographicHat
2022-06-11 22:04:24 +08:00
parent 75c2f57cfa
commit 82ab5a316c
3 changed files with 59 additions and 1 deletions

45
lib/src/il2cpp-init.cpp Normal file
View File

@@ -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<ull>(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);
}

View File

@@ -7,10 +7,20 @@
#ifndef PCH_H
#define PCH_H
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
// Windows 头文件
#include <windows.h>
// 添加要在此处预编译的标头
typedef unsigned long long ull;
#include <map>
#include <vector>
#include <codecvt>
#include <cstdint>
#include <iostream>
#include "framework.h"
#include <detours.h>
#include "il2cpp-appdata.h"
#endif //PCH_H

View File

@@ -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)