

void PlaceJMP(BYTE *pAddress, DWORD dwJumpTo, DWORD dwLen){
DWORD dwOldProtect, dwBkup, dwRelAddr;
// Basic VirtualProtect... y'all should know this
VirtualProtect(pAddress, dwLen, PAGE_EXECUTE_READWRITE, &dwOldProtect);
// Calculate the "distance" we're gonna have to jump - the size of the JMP instruction
dwRelAddr = (DWORD) (dwJumpTo - (DWORD) pAddress) - 5;
// Write the JMP opcode @ our jump position...
*pAddress = 0xE9;
// Write the offset to where we're gonna jump
*((DWORD *)(pAddress + 0x1)) = dwRelAddr;
// Overwrite the rest of the bytes with NOPs
for(DWORD x = 0x5; x < dwLen; x++)
*(pAddress + x) = 0x90;
// Restore the default permissions
VirtualProtect(pAddress, dwLen, dwOldProtect, &dwBkup);
}


push esi mov esi, [esp + 4 + arg_0] push esi
PlaceJMP((BYTE*)0x430430, (DWORD)hkDraw2D, 6);


DWORD dwJMPback = 0x430436; //The Jump Back address is where we're gonna return after our hooked function ends.
//0x430430 is where we're gonna hook... 6 is the length. 0x430430 + 6 = 0x430436
__declspec(naked) void hkDraw2D(){
__asm PUSHAD //Push general registers onto the stack
__asm PUSHFD //Push EFLAGS Register onto the stack
//Do ya Hax magicz here :P
__asm POPFD //Pop EFLAGS Register off the stack
__asm POPAD //Pop registers off the stack
//Here we have to write the intructions we have overwritten with our JMP
__asm PUSH ESI
__asm MOV ESI, [ESP + 8]
__asm PUSH ESI
//Now we jump back to the rest of the function
//So the game can keep executing without issues :D
__asm JMP [dwJMPback]
}

