diff --git a/thcrap/src/dialog.c b/thcrap/src/dialog.c index d4e3c439..184fa7c5 100644 --- a/thcrap/src/dialog.c +++ b/thcrap/src/dialog.c @@ -565,7 +565,8 @@ HWND WINAPI dialog_CreateDialogParamA( ); SAFE_FREE(dlg_trans); } else { - ret = CreateDialogParamU( + ret = (HWND)detour_next( + "user32.dll", "CreateDialogParamA", dialog_CreateDialogParamA, 5, hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam ); } @@ -588,7 +589,8 @@ INT_PTR WINAPI dialog_DialogBoxParamA( ); SAFE_FREE(dlg_trans); } else { - ret = DialogBoxParamU( + ret = detour_next( + "user32.dll", "DialogBoxParamA", dialog_DialogBoxParamA, 5, hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam ); } diff --git a/thcrap/src/exception.c b/thcrap/src/exception.c index ef2c272e..3d1518f9 100644 --- a/thcrap/src/exception.c +++ b/thcrap/src/exception.c @@ -70,7 +70,11 @@ LPTOP_LEVEL_EXCEPTION_FILTER WINAPI exception_SetUnhandledExceptionFilter( { // Don't return our own filter, since this might cause an infinite loop if // the game process caches it. - LPTOP_LEVEL_EXCEPTION_FILTER ret = SetUnhandledExceptionFilter(exception_filter); + LPTOP_LEVEL_EXCEPTION_FILTER ret = (LPTOP_LEVEL_EXCEPTION_FILTER)detour_next( + "kernel32.dll", "SetUnhandledExceptionFilter", + exception_SetUnhandledExceptionFilter, 1, + lpTopLevelExceptionFilter + ); lpOrigFilter = lpTopLevelExceptionFilter; return ret == exception_filter ? NULL : ret; } diff --git a/thcrap/src/init.c b/thcrap/src/init.c index ce24bb1e..06851cc6 100644 --- a/thcrap/src/init.c +++ b/thcrap/src/init.c @@ -401,7 +401,10 @@ void ExitDll(HMODULE hDll) DECLSPEC_NORETURN VOID WINAPI thcrap_ExitProcess(__in UINT uExitCode) { ExitDll(NULL); - ExitProcess(uExitCode); + detour_next( + "kernel32.dll", "ExitProcess", thcrap_ExitProcess, 1, + uExitCode + ); } // Yes, this _has_ to be included in every project. diff --git a/thcrap/src/inject.c b/thcrap/src/inject.c index 72b85af3..f8f90a88 100644 --- a/thcrap/src/inject.c +++ b/thcrap/src/inject.c @@ -829,7 +829,8 @@ BOOL WINAPI inject_CreateProcessU( __out LPPROCESS_INFORMATION lpPI ) { - BOOL ret = CreateProcessU( + BOOL ret = detour_next( + "kernel32.dll", "CreateProcessA", inject_CreateProcessU, 10, lpAppName, lpCmdLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpSI, lpPI @@ -853,7 +854,8 @@ BOOL WINAPI inject_CreateProcessW( __out LPPROCESS_INFORMATION lpPI ) { - BOOL ret = CreateProcessW( + BOOL ret = detour_next( + "kernel32.dll", "CreateProcessW", inject_CreateProcessW, 10, lpAppName, lpCmdLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpSI, lpPI @@ -909,7 +911,8 @@ __out_opt HANDLE WINAPI inject_CreateRemoteThread( hProcess, lpFunc, kernel32_LoadLibraryW, thcrap_dll, "inject_LoadLibraryW" ); - return CreateRemoteThread( + return (HANDLE)detour_next( + "kernel32.dll", "CreateRemoteThread", inject_CreateRemoteThread, 7, hProcess, lpThreadAttributes, dwStackSize, lpFunc, lpParameter, dwCreationFlags, lpThreadId ); @@ -919,7 +922,10 @@ HMODULE WINAPI inject_LoadLibraryU( __in LPCSTR lpLibFileName ) { - HMODULE ret = LoadLibraryU(lpLibFileName); + HMODULE ret = (HMODULE)detour_next( + "kernel32.dll", "LoadLibraryA", inject_LoadLibraryU, 1, + lpLibFileName + ); if(ret) { thcrap_detour(ret); } @@ -930,7 +936,10 @@ HMODULE WINAPI inject_LoadLibraryW( __in LPCWSTR lpLibFileName ) { - HMODULE ret = LoadLibraryW(lpLibFileName); + HMODULE ret = (HMODULE)detour_next( + "kernel32.dll", "LoadLibraryW", inject_LoadLibraryW, 1, + lpLibFileName + ); if(ret) { thcrap_detour(ret); } diff --git a/thcrap/src/strings.c b/thcrap/src/strings.c index 0cf083e5..b0ee63ee 100644 --- a/thcrap/src/strings.c +++ b/thcrap/src/strings.c @@ -242,7 +242,10 @@ int WINAPI strings_MessageBoxA( { lpText = strings_lookup(lpText, NULL); lpCaption = strings_lookup(lpCaption, NULL); - return MessageBoxU(hWnd, lpText, lpCaption, uType); + return detour_next( + "user32.dll", "MessageBoxA", strings_MessageBoxA, 4, + hWnd, lpText, lpCaption, uType + ); } /// ------------------- diff --git a/thcrap/src/textdisp.c b/thcrap/src/textdisp.c index acbd83be..7dd9f8ea 100644 --- a/thcrap/src/textdisp.c +++ b/thcrap/src/textdisp.c @@ -63,7 +63,8 @@ HFONT WINAPI textdisp_CreateFontA( "CreateFontA: %s%s %d (Weight %d, PitchAndFamily 0x%0x)\n", pszFaceName, replaced ? " (repl.)" : "", cHeight, cWeight, iPitchAndFamily ); - return CreateFont( + return (HFONT)detour_next( + "gdi32.dll", "CreateFontA", textdisp_CreateFontA, 14, cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName diff --git a/thcrap_tsa/src/layout.c b/thcrap_tsa/src/layout.c index 44697dfe..850bee4a 100644 --- a/thcrap_tsa/src/layout.c +++ b/thcrap_tsa/src/layout.c @@ -162,7 +162,10 @@ json_t* layout_tokenize(const char *str, size_t len) BOOL WINAPI layout_textout_raw(HDC hdc, int x, int y, const json_t *str) { - return TextOutU(hdc, x, y, json_string_value(str), json_string_length(str)); + return detour_next( + "gdi32.dll", "TextOutA", layout_TextOutU, 5, + hdc, x, y, json_string_value(str), json_string_length(str) + ); } /// Hooked functions @@ -173,7 +176,10 @@ BOOL WINAPI layout_textout_raw(HDC hdc, int x, int y, const json_t *str) HDC WINAPI layout_CreateCompatibleDC( __in_opt HDC hdc) { if(!text_dc) { - HDC ret = CreateCompatibleDC(hdc); + HDC ret = (HDC)detour_next( + "gdi32.dll", "CreateCompatibleDC", layout_CreateCompatibleDC, 1, + hdc + ); text_dc = ret; log_printf("CreateCompatibleDC(0x%8x) -> 0x%8x\n", hdc, ret); } @@ -194,7 +200,10 @@ HGDIOBJ WINAPI layout_SelectObject( if(h == GetStockObject(SYSTEM_FONT)) { return GetCurrentObject(hdc, OBJ_FONT); } else { - return SelectObject(hdc, h); + return (HGDIOBJ)detour_next( + "gdi32.dll", "SelectObject", layout_SelectObject, 2, + hdc, h + ); } } diff --git a/thcrap_tsa/src/win32_tsa.c b/thcrap_tsa/src/win32_tsa.c index 3b8161c2..f0ea48a5 100644 --- a/thcrap_tsa/src/win32_tsa.c +++ b/thcrap_tsa/src/win32_tsa.c @@ -121,7 +121,8 @@ HWND WINAPI tsa_CreateWindowExA( json_is_string(game_build) ? json_string_value(game_build) : ""); window_title = custom_title; } - ret = CreateWindowExU( + ret = (HWND)detour_next( + "user32.dll", "CreateWindowExA", tsa_CreateWindowExA, 12, dwExStyle, lpClassName, window_title, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam );