diff --git a/lib/src/dllmain.cpp b/lib/src/dllmain.cpp index 1f0d6f3..b3eca62 100644 --- a/lib/src/dllmain.cpp +++ b/lib/src/dllmain.cpp @@ -1,10 +1,31 @@ #include "pch.h" #include "util.h" +#include "il2cpp-init.h" +#include "HookManager.h" + +HWND unityWnd = 0; + +std::string il2cppi_to_string(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); + std::string strTemp(buffer); + delete[] buffer; + return strTemp; +} + +void SetDispstchData(Genshin::ByteArray* data, MethodInfo* m) { + CALL_ORIGIN(SetDispstchData, data, m); + auto ilStr = Genshin::Convert_ToBase64String(data, nullptr); + auto cStr = il2cppi_to_string(reinterpret_cast(ilStr), CP_ACP); + ErrorDialog(cStr.c_str()); + return; +} void Run(HMODULE* phModule) { AllocConsole(); freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); - HWND unityWnd = 0; while ( GetModuleHandle("UserAssembly.dll") == nullptr || (unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0 @@ -12,24 +33,21 @@ void Run(HMODULE* phModule) { printf("Wait game initialize...\n"); Sleep(1000); } - MessageBox(unityWnd, "YaeAchievementLib injection test on 原神 Beta (CNCBWIN2.7.53)", "", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); - //init_il2cpp(); - //HookManager::install(app::Unity_RecordUserData, OnRecordUserData); - for (int i = 0; i < 4; i++) { - //app::Application_RecordUserData(i, nullptr); - } - HANDLE hPipe = CreateFile(R"(\\.\pipe\genshin-checksum)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); + InitIL2CPP(); + HookManager::install(Genshin::Packet_SetDispstchData, SetDispstchData); + /*HANDLE hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hPipe == INVALID_HANDLE_VALUE) { printf("Failed to open pipe: %d\n", GetLastError()); ExitProcess(0); return; - } - ConnectNamedPipe(hPipe, nullptr); - DWORD written; + }*/ + //ErrorDialog("Press ok to continue."); + //ConnectNamedPipe(hPipe, nullptr); + //DWORD written; //WriteFile(hPipe, (checksum + "\n").c_str(), checksum.length() + 1, &written, nullptr); - DisconnectNamedPipe(hPipe); - CloseHandle(hPipe); - ExitProcess(0); + //DisconnectNamedPipe(hPipe); + //CloseHandle(hPipe); + //ExitProcess(0); } // DLL entry point