Endscene Engine Hook

Posts 15 of 5 · Page 1 of 1
Endscene Engine Hook
Here is the current end scene engine hook.

Code:
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#define EndScene        0x570743

DWORD retEndScene = ( EndScene + 0x8 );

__declspec( naked ) HRESULT WINAPI EndSceneMidfunction( )
{
    static LPDIRECT3DDEVICE9 pDevice;

    __asm
    {
		MOV ECX, DWORD PTR DS:[EAX]
		MOV EDX, DWORD PTR DS:[ECX + 0xA8]
		MOV DWORD PTR DS:[pDevice], EAX
        PUSHAD
    }

    __asm
    {
        POPAD
        JMP retEndScene
    }
}

VOID *DetourCreate( BYTE *src, CONST BYTE *dst, CONST INT len )
{
    BYTE *jmp =( BYTE * ) malloc( len + 5 );
    DWORD dwBack;

    VirtualProtect( src, len, PAGE_READWRITE, &dwBack );
    memcpy( jmp, src, len );    
    jmp += len;
    jmp[0] = 0xE9;
    *( DWORD * )( jmp + 1 ) = ( DWORD )( src + len - jmp ) - 5;

    src[0] = 0xE9;
    *( DWORD * )( src + 1 ) = ( DWORD )( dst - src ) - 5;
    for( INT i = 5; i < len; i++ )
        src[i] = 0x90;
    VirtualProtect( src, len, dwBack, &dwBack );

    return( jmp - len );
}

DWORD WINAPI Hook( VOID )
{
    while( TRUE )
    {
        if( memcmp( ( VOID * )EndScene, ( VOID * )( PBYTE )"\x8B\x08", 2 ) == 0 )
        {
            Sleep( 100 );
            DetourCreate( ( PBYTE )EndScene, ( PBYTE )EndSceneMidfunction, 8 );
        }
        Sleep( 50 );
    }
 
    return 0;
}


BOOL WINAPI DllMain( HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{ 
    if( dwReason == DLL_PROCESS_ATTACH )
    {
        DisableThreadLibraryCalls( hDll );
        CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)Hook, 0, 0, 0 );
    }
 
    return TRUE;
}
Credits
Wellington
Thx for sharing
You got a very nice Copy Paste skills.
Quote Originally Posted by OwNAppLe View Post
You got a very nice Copy Paste skills.
All i did was update the adress's and redid the original asm cause it jumped 9 bytes from orignial address instead of 8, and changed where i call our device. i gave credits to the person who origanally posted the code.
Do you have updated addresses for DIPEngine and ResetEngine?
Posts 15 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?