mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
hook SetUnhandledExceptionFilter for debug build
This commit is contained in:
parent
f352aedc59
commit
087f41ce11
@ -27,6 +27,7 @@ char* dbg_mes_to_str(int id);
|
||||
|
||||
extern double g_dbg_frame_time;
|
||||
extern DWORD g_dbg_frame_count;
|
||||
extern LPTOP_LEVEL_EXCEPTION_FILTER g_dbg_exception_filter;
|
||||
|
||||
//#define _DEBUG 1
|
||||
|
||||
|
@ -55,6 +55,7 @@ typedef HMODULE(WINAPI* LOADLIBRARYEXAPROC)(LPCSTR, HANDLE, DWORD);
|
||||
typedef HMODULE(WINAPI* LOADLIBRARYEXWPROC)(LPCWSTR, HANDLE, DWORD);
|
||||
typedef BOOL(WINAPI* GETDISKFREESPACEAPROC)(LPCSTR, LPDWORD, LPDWORD, LPDWORD, LPDWORD);
|
||||
typedef HRESULT(WINAPI* COCREATEINSTANCEPROC)(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID*);
|
||||
typedef LPTOP_LEVEL_EXCEPTION_FILTER(WINAPI* SETUNHANDLEDEXCEPTIONFILTERPROC)(LPTOP_LEVEL_EXCEPTION_FILTER);
|
||||
|
||||
extern GETCURSORPOSPROC real_GetCursorPos;
|
||||
extern CLIPCURSORPROC real_ClipCursor;
|
||||
@ -93,6 +94,7 @@ extern LOADLIBRARYEXAPROC real_LoadLibraryExA;
|
||||
extern LOADLIBRARYEXWPROC real_LoadLibraryExW;
|
||||
extern GETDISKFREESPACEAPROC real_GetDiskFreeSpaceA;
|
||||
extern COCREATEINSTANCEPROC real_CoCreateInstance;
|
||||
extern SETUNHANDLEDEXCEPTIONFILTERPROC real_SetUnhandledExceptionFilter;
|
||||
|
||||
extern int g_hook_method;
|
||||
extern BOOL g_hook_dinput;
|
||||
|
@ -61,4 +61,7 @@ HWND WINAPI fake_CreateWindowExA(
|
||||
HRESULT WINAPI fake_CoCreateInstance(
|
||||
REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID* ppv);
|
||||
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI fake_SetUnhandledExceptionFilter(
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
double g_dbg_frame_time = 0;
|
||||
DWORD g_dbg_frame_count = 0;
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER g_dbg_exception_filter;
|
||||
|
||||
static LONGLONG g_dbg_counter_start_time = 0;
|
||||
static double g_dbg_counter_freq = 0.0;
|
||||
@ -74,6 +75,9 @@ int dbg_exception_handler(EXCEPTION_POINTERS* exception)
|
||||
filename);
|
||||
}
|
||||
|
||||
if (g_dbg_exception_filter)
|
||||
return g_dbg_exception_filter(exception);
|
||||
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
#endif
|
||||
|
@ -25,10 +25,10 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
#if _DEBUG
|
||||
#ifdef _DEBUG
|
||||
dbg_init();
|
||||
TRACE("cnc-ddraw = %p\n", hDll);
|
||||
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
|
||||
g_dbg_exception_filter = SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
|
||||
#endif
|
||||
g_ddraw_module = hDll;
|
||||
|
||||
|
20
src/hook.c
20
src/hook.c
@ -54,6 +54,7 @@ LOADLIBRARYEXAPROC real_LoadLibraryExA = LoadLibraryExA;
|
||||
LOADLIBRARYEXWPROC real_LoadLibraryExW = LoadLibraryExW;
|
||||
GETDISKFREESPACEAPROC real_GetDiskFreeSpaceA = GetDiskFreeSpaceA;
|
||||
COCREATEINSTANCEPROC real_CoCreateInstance = CoCreateInstance;
|
||||
SETUNHANDLEDEXCEPTIONFILTERPROC real_SetUnhandledExceptionFilter = SetUnhandledExceptionFilter;
|
||||
|
||||
static HOOKLIST g_hooks[] =
|
||||
{
|
||||
@ -567,12 +568,14 @@ void hook_init()
|
||||
|
||||
void hook_early_init()
|
||||
{
|
||||
/*
|
||||
#ifdef _DEBUG && _MSC_VER
|
||||
hook_patch_iat(GetModuleHandle(NULL), FALSE, "kernel32.dll", "SetUnhandledExceptionFilter", (PROC)fake_SetUnhandledExceptionFilter);
|
||||
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach((PVOID*)&real_CoCreateInstance, (PVOID)fake_CoCreateInstance);
|
||||
DetourAttach((PVOID*)&real_SetUnhandledExceptionFilter, (PVOID)fake_SetUnhandledExceptionFilter);
|
||||
DetourTransactionCommit();
|
||||
*/
|
||||
#endif
|
||||
|
||||
hook_patch_iat(GetModuleHandle(NULL), FALSE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance);
|
||||
hook_patch_iat(GetModuleHandle("XIIIGame.dll"), FALSE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance); //Hooligans
|
||||
@ -633,6 +636,17 @@ void hook_exit()
|
||||
hook_revert((HOOKLIST*)&g_hooks);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG && _MSC_VER
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach((PVOID*)&real_SetUnhandledExceptionFilter, (PVOID)fake_SetUnhandledExceptionFilter);
|
||||
DetourTransactionCommit();
|
||||
|
||||
hook_patch_iat(GetModuleHandle(NULL), TRUE, "kernel32.dll", "SetUnhandledExceptionFilter", (PROC)fake_SetUnhandledExceptionFilter);
|
||||
|
||||
real_SetUnhandledExceptionFilter(g_dbg_exception_filter);
|
||||
#endif
|
||||
|
||||
hook_patch_iat(GetModuleHandle(NULL), TRUE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance);
|
||||
hook_patch_iat(GetModuleHandle("XIIIGame.dll"), TRUE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance); //Hooligans
|
||||
hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateA", (PROC)fake_DirectInputCreateA);
|
||||
|
@ -1076,3 +1076,13 @@ HRESULT WINAPI fake_CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD
|
||||
|
||||
return real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
|
||||
}
|
||||
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI fake_SetUnhandledExceptionFilter(
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
|
||||
{
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER old = g_dbg_exception_filter;
|
||||
g_dbg_exception_filter = lpTopLevelExceptionFilter;
|
||||
|
||||
return old;
|
||||
//return real_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user