mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
improve hotpatching
This commit is contained in:
parent
822b5c5f32
commit
69b29ebac3
24
src/hook.c
24
src/hook.c
@ -86,8 +86,30 @@ PROC Hook_HotPatch(PROC function, PROC newFunction)
|
|||||||
{
|
{
|
||||||
PROC result = function;
|
PROC result = function;
|
||||||
|
|
||||||
|
if (!function)
|
||||||
|
return result;
|
||||||
|
|
||||||
unsigned short *bytes = (unsigned short *)function;
|
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;
|
char *address = ((char *)function) - 5;
|
||||||
DWORD oldProtect;
|
DWORD oldProtect;
|
||||||
|
@ -41,7 +41,7 @@ void Settings_Load()
|
|||||||
ddraw->noactivateapp = GetBool("noactivateapp", FALSE);
|
ddraw->noactivateapp = GetBool("noactivateapp", FALSE);
|
||||||
ddraw->vhack = GetBool("vhack", FALSE);
|
ddraw->vhack = GetBool("vhack", FALSE);
|
||||||
ddraw->accurateTimers = GetBool("accuratetimers", FALSE);
|
ddraw->accurateTimers = GetBool("accuratetimers", FALSE);
|
||||||
ddraw->hotPatch = GetBool("hotPatch", FALSE);
|
ddraw->hotPatch = GetBool("hotpatch", FALSE);
|
||||||
|
|
||||||
WindowRect.right = GetInt("width", 0);
|
WindowRect.right = GetInt("width", 0);
|
||||||
WindowRect.bottom = GetInt("height", 0);
|
WindowRect.bottom = GetInt("height", 0);
|
||||||
@ -277,7 +277,8 @@ static void CreateSettingsIni()
|
|||||||
"\n"
|
"\n"
|
||||||
"; Use hotpatching rather than IAT hooking\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"
|
"; 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"
|
"\n"
|
||||||
"\n"
|
"\n"
|
||||||
"; ### Game specific settings ###\n"
|
"; ### Game specific settings ###\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user