Reduced the number of trailing NOPs for MakeCall/Jump

* when the trailing length is longer than 4 bytes, it will use a mix of
5-byte long NOPs and single-byte NOPs.
This commit is contained in:
NovaRain
2026-05-29 09:19:09 +08:00
parent 48472bd4bc
commit 919b17efe1
2 changed files with 10 additions and 4 deletions
+1 -2
View File
@@ -555,8 +555,7 @@ static void DebugModePatch() {
// Fix to prevent crashes when there is a '%' character in the printed message
if (dbgMode > 1) {
MakeCall(0x4C703F, debug_log_hack);
BlockCall(0x4C7044); // just nop code
MakeCall(0x4C703F, debug_log_hack, 5);
}
// replace calling debug_printf_ with _debug_func, to avoid buffer overflow with messages longer than 260 bytes
MakeCall(0x45540F, op_display_msg_hack);
+9 -2
View File
@@ -22,9 +22,16 @@ static __declspec(noinline) void __stdcall SafeWriteFunc(BYTE code, DWORD addr,
*((BYTE*)addr) = code;
*((DWORD*)(addr + 1)) = data;
do {
while (len >= 5) {
*((DWORD*)addrMem) = 0x00441F0F; // 5-byte long NOP (0F1F4400-XX)
addrMem += 5;
len -= 5;
}
// Fill the remaining bytes (1-4 bytes) with single-byte NOPs
while (len > 0) {
*((BYTE*)addrMem++) = CodeType::Nop;
} while (--len);
len--;
}
VirtualProtect((void*)addr, protectLen, oldProtect, &oldProtect);
}