From 180ab8bab7aa3b47713e1696bf55b86436314cfc Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Sun, 12 Jun 2022 15:59:43 +0800 Subject: [PATCH] update --- lib/src/il2cpp-functions.h | 6 +++--- lib/src/il2cpp-init.cpp | 20 +++----------------- lib/src/pch.h | 2 -- lib/src/util.cpp | 20 ++++++++++++++++++++ lib/src/util.h | 17 +++++++++++++++++ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/lib/src/il2cpp-functions.h b/lib/src/il2cpp-functions.h index dbd403f..3064a62 100644 --- a/lib/src/il2cpp-functions.h +++ b/lib/src/il2cpp-functions.h @@ -1,5 +1,5 @@ using namespace Genshin; -DO_APP_FUNC(0x02BC1930, ByteArray*, MessageExtensions_ToByteArray, (IMessage msg, MethodInfo* method)); -DO_APP_FUNC(0x04E9B3F0, String*, Convert_ToBase64String, (ByteArray* arr, MethodInfo* method)); -DO_APP_FUNC(0x01591250, void, Packet_SetDispstchData, (ByteArray* data, MethodInfo* method)); +DO_APP_FUNC(0x04E9B3F0, String*, Convert_ToBase64String, (ByteArray* value, MethodInfo* method)); +DO_APP_FUNC(0x0517DD30, String*, BitConverter_ToString, (ByteArray* value, INT32 start, INT32 length, MethodInfo* method)); +DO_APP_FUNC(0x015913C0, void, Packet_Xor, (ByteArray** data, INT32 length, MethodInfo* method)); diff --git a/lib/src/il2cpp-init.cpp b/lib/src/il2cpp-init.cpp index 910eb9e..06e07be 100644 --- a/lib/src/il2cpp-init.cpp +++ b/lib/src/il2cpp-init.cpp @@ -14,32 +14,18 @@ namespace Genshin { using std::string; -ull GetAddressByExports(HMODULE base, const char* name) { - ull funcAddr = reinterpret_cast(GetProcAddress(base, name)); +UINT64 GetAddressByExports(HMODULE base, const char* name) { + UINT64 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; + auto bAddr = (UINT64)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 c1cd9d0..092e81d 100644 --- a/lib/src/pch.h +++ b/lib/src/pch.h @@ -13,8 +13,6 @@ // 添加要在此处预编译的标头 -typedef unsigned long long ull; - #include #include #include diff --git a/lib/src/util.cpp b/lib/src/util.cpp index beb0ebf..9f53dd8 100644 --- a/lib/src/util.cpp +++ b/lib/src/util.cpp @@ -1,6 +1,26 @@ #include "pch.h" #include "util.h" +#pragma region StringConvert + +string IlStringToString(Il2CppString* str, UINT codePage) { + auto chars = reinterpret_cast(str->chars); + auto len = WideCharToMultiByte(codePage, 0, chars, -1, nullptr, 0, nullptr, nullptr); + auto buffer = new char[len]; + WideCharToMultiByte(codePage, 0, chars, -1, buffer, len, nullptr, nullptr); + return string(buffer); +} + +#pragma endregion + +#pragma region ByteUtils +bool IsLittleEndian() { + UINT i = 1; + char* c = (char*)&i; + return (*c); +} +#pragma endregion + #pragma region FindMainWindowByPID struct HandleData { diff --git a/lib/src/util.h b/lib/src/util.h index e93e901..5329111 100644 --- a/lib/src/util.h +++ b/lib/src/util.h @@ -1,6 +1,23 @@ #pragma once +using std::string; + +bool IsLittleEndian(); HWND FindMainWindowByPID(DWORD pid); +string IlStringToString(Il2CppString* str, UINT codePage = CP_ACP); #define ErrorDialogT(title, msg) MessageBox(unityWnd, msg, title, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); #define ErrorDialog(msg) ErrorDialogT("YaeAchievement", msg) + +template +static T ReadMapped(void* data, int offset, bool littleEndian = false) { + char* cData = (char*)data; + T result = {}; + if (IsLittleEndian() != littleEndian) { + for (int i = 0; i < sizeof(T); i++) + ((char*)&result)[i] = cData[offset + sizeof(T) - i - 1]; + return result; + } + memcpy(&result, cData + offset, sizeof(result)); + return result; +}