Results 1 to 1 of 1
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,221
    Thanks
    211
    Thanked 2,224 Times in 289 Posts
    Rep Power
    10

    Simple drawing text and rect for any d3d9 game

    Here is everything you need for drawing text or rect.
    d3dhooks.h
    class DXGH
    {
    public:
    void DrawFillRect(IDirect3DDevice9* dev, int x, int y, int w, int h,unsigned char r, unsigned char g, unsigned char b);
    static HRESULT WINAPI h_EndScene(LPDIRECT3DDEVICE9 pDevice); //End scene
    };

    int StartD3DHooks(); //call this later for our hooks

    typedef HRESULT(WINAPI *EndScene_t)(LPDIRECT3DDEVICE9 pDevice); //For our original
    extern DXGH DXGameHook;

    d3dhooks.cpp
    DXGH                                           DXGameHook;
    //Our end scene hook
    HRESULT WINAPI DXGH::h_EndScene(LPDIRECT3DDEVICE9 pDevice)
    {

    DXGameHook.DrawFillRect(pDevice,500,100,100,100,90 ,100,255);
    return org_EndScene(pDevice); //Return orig
    }

    /*
    Using D3D Clear To Create rectangle
    */
    void DXGH::DrawFillRect(IDirect3DDevice9* dev, int x, int y, int w, int h,unsigned char r, unsigned char g, unsigned char b)
    {
    D3DCOLOR rectColor = D3DCOLOR_XRGB(r,g,b); //No point in using alpha because clear & alpha dont work!
    D3DRECT BarRect = { x, y, x + w, y + h };

    dev->Clear(1,&BarRect, D3DCLEAR_TARGET | D3DCLEAR_TARGET ,rectColor,0,0);
    }

    int StartD3DHooks()
    {
    DWORD D3DPattern,*vTable, DXBase=NULL;
    DXBase = (DWORD)LoadLibraryA("d3d9.dll");

    while(!DXBase);
    {
    D3DPattern = GameHook->FindPattern(DXBase, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x 00\x00\x89\x86", "xx????xx????xx"); //Searching for the D3D Pattern
    }

    if(D3DPattern)
    {
    //if D3D Pattern is found. then do hooks
    memcpy(&vTable,(void *)(D3DTrue+2),4);
    org_EndScene = (EndScene_t)GameHook->DetourFunction((PBYTE)vTable[ENDSCENE],(PBYTE)DXGameHook.h_EndScene,5);
    }
    return 0;
    }

    And finally dllMain.cpp:
    BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved )
    {
    switch( fdwReason )
    {
    case DLL_PROCESS_ATTACH:
    {
    DisableThreadLibraryCalls(hinstDLL);
    // Do the call here
    StartD3DHooks()
    return true;
    break;
    }
    case DLL_PROCESS_DETACH:
    {

    break;
    }
    }
    return TRUE;
    }


    The outcome:


    Drawing text
    d3dhooks.h
    class DXGH
    {
    public:
    bool DrawMessage(LPD3DXFONT font, unsigned int x, unsigned int y, int alpha, unsigned char r, unsigned char g, unsigned char b, LPCSTR Message); //Draw message
    static HRESULT WINAPI h_EndScene(LPDIRECT3DDEVICE9 pDevice); //End scene
    };

    int StartD3DHooks(); //call this later for our hooks

    typedef HRESULT(WINAPI *EndScene_t)(LPDIRECT3DDEVICE9 pDevice); //For our original
    extern DXGH DXGameHook;

    d3dhooks.cpp
    DXGH                                           DXGameHook;
    LPD3DXFONT m_font = NULL;

    //Our end scene hook
    HRESULT WINAPI DXGH::h_EndScene(LPDIRECT3DDEVICE9 pDevice)
    {
    //First register our txt
    D3DXCreateFont( pDevice, 17, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_font );

    DXGameHook.DrawMessage(m_font,40,40,255,255,0,255, "pSBadCompany2 Test 1");
    DXGameHook.DrawMessage(m_font,40,60,255,255,255,25 5,"pSBadCompany2 Test 2");
    DXGameHook.DrawMessage(m_font,40,80,255,255,255,0, "pSBadCompany2 Test 3");
    DXGameHook.DrawMessage(m_font,40,100,255,255,200,1 55,"pSBadCompany2 Test 4");
    DXGameHook.DrawMessage(m_font,40,120,255,200,0,200 ,"pSBadCompany2 Test 5");
    //Draw our messages ^^


    return org_EndScene(pDevice); //Return orig
    }

    //Now for our Drawtext funciton:

    bool DXGH::DrawMessage(LPD3DXFONT font, unsigned int x, unsigned int y, int alpha, unsigned char r, unsigned char g, unsigned char b, LPCSTR Message)
    { // Create a colour for the text
    D3DCOLOR fontColor = D3DCOLOR_ARGB(alpha, r, g, b);
    RECT rct; //Font
    rct.left=x;
    rct.right=1680;
    rct.top=y;
    rct.bottom=rct.top+200;
    font->DrawTextA(NULL, Message, -1, &rct, 0, fontColor);
    return true;
    }

    int StartD3DHooks()
    {
    DWORD D3DPattern,*vTable, DXBase=NULL;
    DXBase = (DWORD)LoadLibraryA("d3d9.dll");

    while(!DXBase);
    {
    D3DPattern = GameHook->FindPattern(DXBase, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x 00\x00\x89\x86", "xx????xx????xx"); //Searching for the D3D Pattern
    }

    if(D3DPattern)
    {
    //if D3D Pattern is found. then do hooks
    memcpy(&vTable,(void *)(D3DTrue+2),4);
    org_EndScene = (EndScene_t)GameHook->DetourFunction((PBYTE)vTable[ENDSCENE],(PBYTE)DXGameHook.h_EndScene,5);
    org_DrawIndexedPrimitive = (DrawIndexedPrimitive_t)GameHook->DetourFunction((PBYTE)vTable[DRAWINDEXEDPRIMITIVE],(PBYTE)DXGameHook.h_DrawIndexedPrimitive,5);
    }
    return 0;
    }


    by Salt3r
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

Visitors found this page by searching for:

draw rectangle on d3d9 hook

d3d9 endscene

d3d9 draw text

d3d9 DrawText

d3d9 hook

d3d9 endscene hook

d3d9 draw rectangle

hook d3d9

DrawText d3d9

draw text d3d9

idirect3ddevice9 drawtextd3d9 textd3d9 findpatternSimple drawing text for any d3d9 gameendscene findpatternorg_EndScenesimple d3d9 hookhook directx drawtextd3d9 hookinghooking d3d9D3D9 vtable hookd3d9 RECTgamed3dd3d hook draw textd3d9 draw box

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •