mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
improve hotpatching
This commit is contained in:
parent
11c103f36c
commit
63584509e2
24
src/hook.c
24
src/hook.c
@ -86,8 +86,30 @@ PROC Hook_HotPatch(PROC function, PROC newFunction)
|
||||
{
|
||||
PROC result = function;
|
||||
|
||||
if (!function)
|
||||
return result;
|
||||
|
||||
unsigned short *bytes = (unsigned short *)function;
|
||||
if (function && *bytes == 0xFF8B) // mov edi, edi
|
||||
|
||||
if (*bytes == 0x25FF) // JMP DWORD PTR
|
||||
{
|
||||
char *address = (char *)function;
|
||||
DWORD oldProtect;
|
||||
|
||||
if (VirtualProtect(address, 8, PAGE_EXECUTE_READWRITE, &oldProtect))
|
||||
{
|
||||
if (memcmp(address + 6, (const char[]) { 0xCC, 0xCC }, 2) == 0 ||
|
||||
memcmp(address + 6, (const char[]) { 0x90, 0x90 }, 2) == 0)
|
||||
{
|
||||
memmove(address + 2, address, 6);
|
||||
*((WORD *)(&address[0])) = 0xFF8B; // mov edi, edi
|
||||
}
|
||||
|
||||
VirtualProtect(address, 8, oldProtect, &oldProtect);
|
||||
}
|
||||
}
|
||||
|
||||
if (*bytes == 0xFF8B) // mov edi, edi
|
||||
{
|
||||
char *address = ((char *)function) - 5;
|
||||
DWORD oldProtect;
|
||||
|
@ -41,7 +41,7 @@ void Settings_Load()
|
||||
ddraw->noactivateapp = GetBool("noactivateapp", FALSE);
|
||||
ddraw->vhack = GetBool("vhack", FALSE);
|
||||
ddraw->accurateTimers = GetBool("accuratetimers", FALSE);
|
||||
ddraw->hotPatch = GetBool("hotPatch", FALSE);
|
||||
ddraw->hotPatch = GetBool("hotpatch", FALSE);
|
||||
ddraw->bnetHack = GetBool("bnetHack", TRUE);
|
||||
|
||||
WindowRect.right = GetInt("width", 0);
|
||||
@ -281,7 +281,8 @@ static void CreateSettingsIni()
|
||||
"\n"
|
||||
"; Use hotpatching rather than IAT hooking\n"
|
||||
"; Note: Can be used to fix issues related to new features added by cnc-ddraw such as windowed mode or stretching\n"
|
||||
"hotPatch=false\n"
|
||||
"hotpatch=false\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"; Workaround for battle.net on Diablo and Warcraft 2 BNE\n"
|
||||
"; Note: This hack as a negative side-effect, you can only play fullscreen with 'renderer=gdi' or via 'fullscreen=true'\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user