lib update

This commit is contained in:
HolographicHat
2022-06-11 00:35:25 +08:00
parent 12348a3941
commit 3917f3e6c7
10 changed files with 1421 additions and 2 deletions

View File

@@ -1,8 +1,43 @@
#include "pch.h"
#include "util.h"
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
void Run(HMODULE* phModule) {
AllocConsole();
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
HWND unityWnd = 0;
while (
GetModuleHandle("UserAssembly.dll") == nullptr ||
(unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0
) {
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);
if (hPipe == INVALID_HANDLE_VALUE) {
printf("Failed to open pipe: %d\n", GetLastError());
ExitProcess(0);
return;
}
ConnectNamedPipe(hPipe, nullptr);
DWORD written;
//WriteFile(hPipe, (checksum + "\n").c_str(), checksum.length() + 1, &written, nullptr);
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
ExitProcess(0);
}
// DLL entry point
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) {
switch (ulReasonForCall) {
case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Run, new HMODULE(hModule), 0, NULL);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:

View File

@@ -8,6 +8,9 @@
#define PCH_H
// 添加要在此处预编译的标头
#include <map>
#include <vector>
#include <iostream>
#include "framework.h"
#endif //PCH_H

37
lib/src/util.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "pch.h"
#include "util.h"
#pragma region FindMainWindowByPID
struct HandleData {
DWORD pid;
HWND hwnd;
};
BOOL IsMainWindow(HWND handle) {
return GetWindow(handle, GW_OWNER) == (HWND)0 && IsWindowVisible(handle) == TRUE;
}
BOOL IsUnityWindow(HWND handle) {
TCHAR name[256];
GetClassName(handle, name, 256);
return _strcmpi(name, "UnityWndClass") == 0;
}
BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam) {
HandleData& data = *(HandleData*)lParam;
DWORD pid = 0;
GetWindowThreadProcessId(handle, &pid);
if (data.pid != pid || !IsMainWindow(handle) || !IsUnityWindow(handle))
return TRUE;
data.hwnd = handle;
return FALSE;
}
HWND FindMainWindowByPID(DWORD pid) {
HandleData data = { pid, 0 };
EnumWindows(EnumWindowsCallback, (LPARAM)&data);
return data.hwnd;
}
#pragma endregion

3
lib/src/util.h Normal file
View File

@@ -0,0 +1,3 @@
#pragma once
HWND FindMainWindowByPID(DWORD pid);