Update to spice2x-25-04-25 (pre-apply)

> broken commit
This commit is contained in:
[ ]
2025-05-07 00:25:31 +09:00
parent 04dee88276
commit c94de456b5
543 changed files with 78491 additions and 91698 deletions
+64 -6
View File
@@ -6,6 +6,8 @@
#include "util/detour.h"
#include "util/utils.h"
#include <tlhelp32.h>
// std::min
#ifdef min
#undef min
@@ -117,6 +119,12 @@ int MITMHandle::device_io(DWORD dwIoControlCode, LPVOID lpInBuffer,
}
}
size_t MITMHandle::bytes_available() {
COMSTAT status;
ClearCommError_orig(handle, NULL, &status);
return status.cbInQue;
}
bool MITMHandle::close() {
return CloseHandle_orig(handle);
}
@@ -385,8 +393,10 @@ static BOOL WINAPI ClearCommError_hook(HANDLE hFile, LPDWORD lpErrors, LPCOMSTAT
* Some games may check the input queue size.
* QMA does not even attempt to read if this is set to 0.
* We just set this to 255 and hope games do not rely on this for buffer sizes.
*
* Message from the future: As it turned out, some games (CCJ) do in fact rely on this value.
*/
lpStat->cbInQue = 255;
lpStat->cbInQue = custom_handle->bytes_available();
}
return TRUE;
@@ -489,6 +499,38 @@ static BOOL WINAPI CloseHandle_hook(HANDLE hObject) {
return CloseHandle_orig(hObject);
}
static void suspend_or_resume_other_threads(bool suspending) {
HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hThreadSnap == INVALID_HANDLE_VALUE) {
return;
}
THREADENTRY32 te32;
te32.dwSize = sizeof(THREADENTRY32);
if (Thread32First(hThreadSnap, &te32)) {
do {
if (te32.th32OwnerProcessID == GetCurrentProcessId()) {
if(te32.th32ThreadID == GetCurrentThreadId()) {
continue;
}
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
if (hThread) {
if (suspending) {
SuspendThread(hThread);
} else {
ResumeThread(hThread);
}
CloseHandle(hThread);
}
}
} while (Thread32Next(hThreadSnap, &te32));
}
CloseHandle(hThreadSnap);
}
void devicehook_init(HMODULE module) {
if (!hooks::device::ENABLE) {
return;
@@ -513,6 +555,8 @@ void devicehook_init(HMODULE module) {
log_info("devicehook", "init");
suspend_or_resume_other_threads(true);
// IAT hooks
STORE(ClearCommBreak_orig, detour::iat_try("ClearCommBreak", ClearCommBreak_hook, module));
STORE(ClearCommError_orig, detour::iat_try("ClearCommError", ClearCommError_hook, module));
@@ -535,8 +579,22 @@ void devicehook_init(HMODULE module) {
STORE(SetCommTimeouts_orig, detour::iat_try("SetCommTimeouts", SetCommTimeouts_hook, module));
STORE(WriteFile_orig, detour::iat_try("WriteFile", WriteFile_hook, module));
// global trampolines
/*
suspend_or_resume_other_threads(false);
#undef STORE
}
void devicehook_init_trampoline() {
// initialize only once
static bool initialized = false;
if (initialized) {
return;
} else {
initialized = true;
}
suspend_or_resume_other_threads(true);
detour::trampoline_try("kernel32.dll", "ClearCommBreak", ClearCommBreak_hook, &ClearCommBreak_orig);
detour::trampoline_try("kernel32.dll", "ClearCommError", ClearCommError_hook, &ClearCommError_orig);
detour::trampoline_try("kernel32.dll", "CloseHandle", CloseHandle_hook, &CloseHandle_orig);
@@ -548,7 +606,7 @@ void devicehook_init(HMODULE module) {
detour::trampoline_try("kernel32.dll", "GetFileSize", GetFileSize_hook, &GetFileSize_orig);
detour::trampoline_try("kernel32.dll", "GetFileSizeEx", GetFileSizeEx_hook, &GetFileSizeEx_orig);
detour::trampoline_try("kernel32.dll", "GetFileInformationByHandle",
GetFileInformationByHandle_hook, &GetFileInformationByHandle_orig);
GetFileInformationByHandle_hook, &GetFileInformationByHandle_orig);
detour::trampoline_try("kernel32.dll", "GetCommState", GetCommState_hook, &GetCommState_orig);
detour::trampoline_try("kernel32.dll", "PurgeComm", PurgeComm_hook, &PurgeComm_orig);
detour::trampoline_try("kernel32.dll", "ReadFile", ReadFile_hook, &ReadFile_orig);
@@ -557,8 +615,8 @@ void devicehook_init(HMODULE module) {
detour::trampoline_try("kernel32.dll", "SetCommMask", SetCommMask_hook, &SetCommMask_orig);
detour::trampoline_try("kernel32.dll", "SetCommState", SetCommState_hook, &SetCommState_orig);
detour::trampoline_try("kernel32.dll", "SetCommTimeouts", SetCommTimeouts_hook, &SetCommTimeouts_orig);
*/
#undef STORE
suspend_or_resume_other_threads(false);
}
void devicehook_add(CustomHandle *device_handle) {