Created
September 19, 2022 22:35
-
-
Save LemonHaze420/ff4d94bafac334058c69be63fdbd11e2 to your computer and use it in GitHub Desktop.
some SH2 PC patches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#define UNK2_DebugLog_offs 0x005657C0 | |
#define ADX_DebugLog_offs 0x0055F030 | |
#define UNK_DebugLog_offs 0x005670E0 | |
#define MH_Call(x) status = x; \ | |
if (status != MH_OK) \ | |
return | |
__declspec(dllexport) void func(void) {} | |
int __stdcall printfHook(char const* _Format, ...) { | |
va_list args; | |
va_start(args, _Format); | |
vprintf(_Format, args); | |
va_end(args); | |
return 0; | |
} | |
int (__cdecl* UNK_DebugLog_orig) (int a1, const char* src); | |
int __cdecl UNK_DebugLog_hook(int a1, const char* src) { | |
printf("[DBG] %s\n", src); | |
return UNK_DebugLog_orig(a1, src); | |
} | |
void (__cdecl* ADX_DebugLog_orig) (const char* source); | |
void __cdecl ADX_DebugLog_hook(const char* source) { | |
printf("[DBG] %s\n", source); | |
ADX_DebugLog_orig(source); | |
} | |
void OutputDebugStringA_hook(LPCSTR lpOutputString) { | |
printf("[DBG] %s\n", lpOutputString); | |
} | |
void main_thread() { | |
// Initiailize MinHook | |
MH_STATUS status = MH_Initialize(); | |
if (status != MH_OK) | |
return; | |
// Re-enable ADX debug logging | |
MH_Call(MH_CreateHook(reinterpret_cast<LPVOID>(ADX_DebugLog_offs), &ADX_DebugLog_hook, reinterpret_cast<LPVOID*>(&ADX_DebugLog_orig))); | |
MH_Call(MH_EnableHook(reinterpret_cast<LPVOID>(ADX_DebugLog_offs))); | |
// Re-enable unknown debug logging | |
MH_Call(MH_CreateHook(reinterpret_cast<LPVOID>(UNK_DebugLog_offs), &UNK_DebugLog_hook, reinterpret_cast<LPVOID*>(&UNK_DebugLog_orig))); | |
MH_Call(MH_EnableHook(reinterpret_cast<LPVOID>(UNK_DebugLog_offs))); | |
// Re-enable developer debug logging | |
PVOID pOldProc; | |
if (!HookIAT("MSVCR70.DLL", "printf", (PVOID)printfHook, &pOldProc)) | |
printf("error;%ld\n", GetLastError()); | |
if (!HookIAT("KERNEL32.DLL", "OutputDebugStringA", (PVOID)OutputDebugStringA_hook, &pOldProc)) | |
printf("error;%ld\n", GetLastError()); | |
// Fix sound looping issue by setting the process to use a single core. | |
SetProcessAffinityMask(GetCurrentProcess(), 1 << 0); | |
} | |
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) | |
{ | |
DisableThreadLibraryCalls(hModule); | |
// Steal stdout/stderr/stdin | |
AllocConsole(); | |
freopen("CONOUT$", "w", stdout); | |
freopen("CONOUT$", "w", stderr); | |
freopen("CONIN$", "r", stdin); | |
SetConsoleTitle("Silent Hill 2 PC Tools"); | |
// Set codepage so that we can properly display shift-jis output | |
SetConsoleOutputCP(932); | |
// Setup our main thread | |
if (dwReason == DLL_PROCESS_ATTACH) | |
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&main_thread, NULL, 0, NULL); | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment