1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

try to use hook=3 by default

This commit is contained in:
FunkyFr3sh 2023-08-13 20:31:26 +02:00
parent b42c3e1d49
commit 97a81b67b5
3 changed files with 51 additions and 11 deletions

View File

@ -323,11 +323,6 @@ static void cfg_create_ini()
"; Note: Usually one of the following values will work: 60 / 30 / 25 / 20 / 15 (lower value = slower game speed)\n"
"maxgameticks=0\n"
"\n"
"; Windows API Hooking, Possible values: 0 = disabled, 1 = IAT Hooking, 2 = Microsoft Detours, 3 = IAT+GetProcAddress hook (All Modules), 4 = IAT Hooking (All Modules)\n"
"; Note: Change this value if windowed mode or upscaling isn't working properly\n"
"; Note: 'hook=3' will usually work for problematic games, if it doesn't then try 'hook=2' + 'renderer=gdi'\n"
"hook=4\n"
"\n"
"; Force minimum FPS, possible values: 0 = disabled, -1 = use 'maxfps=' value, -2 = same as -1 but force full redraw, 1-1000 = custom FPS\n"
"; Note: Set this to a low value such as 5 or 10 if some parts of the game are not being displayed (e.g. menus or loading screens)\n"
"minfps=0\n"
@ -356,6 +351,7 @@ static void cfg_create_ini()
"releasealt=false\n"
"game_handles_close=false\n"
"fixnotresponding=false\n"
"hook=4\n"
"guard_lines=200\n"
"max_resolutions=0\n"
"limit_bltfast=false\n"
@ -866,7 +862,6 @@ static void cfg_create_ini()
"; KKND2: Krossfire\n"
"[KKND2]\n"
"noactivateapp=true\n"
"hook=3\n"
"\n"
"; Lionheart\n"
"[Lionheart]\n"
@ -1064,10 +1059,6 @@ static void cfg_create_ini()
"height=0\n"
"resizable=false\n"
"\n"
"; Wizards and Warriors\n"
"[deep6]\n"
"hook=3\n"
"\n"
"; War Wind\n"
"[WW]\n"
"renderer=opengl\n"

View File

@ -105,7 +105,6 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
}
timeBeginPeriod(1);
g_hook_method = cfg_get_int("hook", 4);
hook_init(TRUE);
break;
}

View File

@ -364,6 +364,45 @@ void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks)
}
}
BOOL hook_got_ddraw_import()
{
__try
{
HMODULE hmod = GetModuleHandleA(NULL);
PIMAGE_DOS_HEADER dos_header = (PIMAGE_DOS_HEADER)hmod;
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
return FALSE;
PIMAGE_NT_HEADERS nt_headers = (PIMAGE_NT_HEADERS)((DWORD)dos_header + (DWORD)dos_header->e_lfanew);
if (nt_headers->Signature != IMAGE_NT_SIGNATURE)
return FALSE;
PIMAGE_IMPORT_DESCRIPTOR import_desc = (PIMAGE_IMPORT_DESCRIPTOR)((DWORD)dos_header +
(DWORD)(nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress));
if (import_desc == (PIMAGE_IMPORT_DESCRIPTOR)nt_headers)
return FALSE;
while (import_desc->FirstThunk)
{
char* imp_module_name = (char*)((DWORD)dos_header + (DWORD)(import_desc->Name));
if (_stricmp(imp_module_name, "ddraw.dll") == 0)
{
return TRUE;
}
import_desc++;
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
return FALSE;
}
void hook_create(HOOKLIST* hooks, BOOL initial_hook)
{
#ifdef _MSC_VER
@ -525,6 +564,17 @@ void hook_revert(HOOKLIST* hooks)
void hook_init(BOOL initial_hook)
{
if (initial_hook)
{
g_hook_method = cfg_get_int("hook", 4);
if (g_hook_method == 4 && hook_got_ddraw_import())
{
/* Switch to 3 if we can be sure that ddraw.dll will not be unloaded from the process */
g_hook_method = 3;
}
}
if (!g_hook_active || g_hook_method == 3 || g_hook_method == 4)
{
#if defined(_DEBUG) && defined(_MSC_VER)