Some D3D hooking coding.

Results 1 to 6 of 6
  1. #1
    Alpha Member Justei is offline
    MemberRank
    Oct 2007 Join Date
    /f241Location
    1,904Posts

    Some D3D hooking coding.

    All of this is taken from my Elmo hackshield Project, if you use this please be nice enough to give me credit, and not in the source, in the actual files, cus no1 will ever see your source.

    Release by: Justei


    Well, I noticed no1 really released this, and since I kinda think it could be used to do a LOT of fun shit on kal, I'll just release my version of a d3d hook, with this you can manipulate the graphics etc ingame.

    What can this be used for?
    Well one example of what you COULD do with this is a REAL version of the new GUI. Shouldn't be very hard once u get the hang of it, just a few memcpy here and there to get the right info, learn how to handle clicks ingame and then just some dedication and you have yourself a real new GUI.

    You can also play around with the models if you are smart/dedicated enough, one thing that's very simple yet fun is to replace the shadows of the characters, I did that by mistake once and you guys should be able to do it very easily.

    And anything you can think of really.


    VARIABLES/FUNCTIONS YOU NEED TO DECLARE
    StartTime for the online time function.

    LogText(char); is a function to log text into a txt file, can replace with whatever function u want or just remove it...

    ServerName for the online time funtction, a char with the name of the server...



    Code:
    time_t seconds;
    time_t TimeLastClick = time (NULL);
    HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
    {	
    
          // Run your shit here...
    
    	__asm nop
    	return oEndScene(pDevice);
    }
    
    
    
    LRESULT CALLBACK MsgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){return DefWindowProc(hwnd, uMsg, wParam, lParam);} 
    void DX_Init(DWORD* table)
    {
    	WNDCLASSEX wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,"DX",NULL};
    	RegisterClassEx(&wc);
    	HWND hWnd = CreateWindow("DX",NULL,WS_OVERLAPPEDWINDOW,100,100,300,300,GetDesktopWindow(),NULL,wc.hInstance,NULL);
    	LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    	D3DPRESENT_PARAMETERS d3dpp; 
    	ZeroMemory( &d3dpp, sizeof(d3dpp) );
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    	LPDIRECT3DDEVICE9 pd3dDevice;
    	pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice);
    	DWORD* pVTable = (DWORD*)pd3dDevice;
    	pVTable = (DWORD*)pVTable[0];
    
    	table[ES]	= pVTable[42];
    
    	DestroyWindow(hWnd);
    }
    
    DWORD WINAPI MyThread(LPVOID)
    {
    	
    	DWORD VTable[1] = {0};
    
    	while(GetModuleHandle("d3d9.dll")==NULL){
    		Sleep(50);
    	}
    
    	DX_Init(VTable);
    	HOOK(EndScene,VTable[ES]);
    
    	return 0;
    }


    An example of what you can do with this, just a small example is a on screen game timer. Basically show how long you have been playing.

    Remember these steps:
    1. You need a proxy dll for this.
    2. You need to make a new thread for this in the engine.
    Code:
    CreateThread(0,0,MyThread,0,0,0);
    3. You need to try to understand this before asking for a bunch of help when you can easily google it etc.


    Now, assuming you have gotten this to run properly, you can do smth like this:


    Code:
    void GetOnlineTime(LPDIRECT3DDEVICE9 Device_t){
    
    
    ID3DXFont *m_font;
    
    D3DCOLOR fontColor = D3DCOLOR_ARGB(255,104,219,15);
    
    
    	// Create a rectangle to indicate where on the screen it should be drawn
    	RECT reect;
    	reect.left=100;
    	reect.right=780;
    	reect.top=150;
    	reect.bottom=reect.top+220;
    
    	// Create a D3DX font object
    	D3DXCreateFont( Device_t, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_font );
    
    	char Text[255];
    	time_t seconds2 = time (NULL);
    	
    		sprintf(Text, "You have played %s for: %d Minutes.", ServerName,(seconds2-StartTime)/60);
    		m_font->DrawText(NULL, Text, -1, &reect, 0, fontColor );
    
    	m_font->Release();
    
    }

    StartTime is a variable that is declared at the start of the engine. So just do that when your proxy dll starts.
    (You can do it like this:
    Code:
    time_t StartTime = time (NULL);
    )

    Then when you have made that function OVER the hkEndScene, you go INTO hkEndScene and add it:

    Code:
    GetOnlineTime(pDevice);

    An example of how to load a sprite:
    Code:
    void DrawElmoSprite(LPDIRECT3DDEVICE9 Device_t){
    
    LPD3DXSPRITE sprite=NULL;
    
    
    
        if(FAILED(D3DXCreateSprite(Device_t,&sprite)))//first parameter is our device, second is a empty sprite variable  
        {  
    		LogText("FAILED SPRITE"); //error pop-up for debug purpose  
        } 
    
    	// Draw sprite
    HRESULT Begin(DWORD flags);
    
    sprite->Begin(D3DXSPRITE_ALPHABLEND);
    
    HRESULT Draw(LPDIRECT3DTEXTURE9 pSrcTexture, CONST RECT *pSrcRect, D3DXVECTOR3 *center, CONST D3DXVECTOR3 *pTranslation,  D3DCOLOR Color ); 
    
    
    
    D3DXVECTOR3 pos;
    
    pos.x=0;
    pos.y=50;
    pos.z=0;
    
    
    D3DDEVICE_CREATION_PARAMETERS cparams;
    RECT WindowRect;
    
    Device_t->GetCreationParameters(&cparams);
    GetWindowRect(cparams.hFocusWindow, &WindowRect);
    
    
    
    IDirect3DTexture9 *texture=NULL;
    
    
       D3DXCreateTextureFromFile(Device_t,   //Direct3D Device
                                 "data/sesame/elmo.jpg",       //File Name
                                 &texture);    //Texture handle
    
        if(FAILED(D3DXCreateTextureFromFile(Device_t,"data/sesame/elmo.jpg",&texture)))//first parameter is our device,second is the path to our image, third is a texture variable to load the image into  
       {  
          LogText("Failed to laod the image"); //error pop-up for debug purpose  
       }  
    
    
    sprite->Begin(D3DXSPRITE_ALPHABLEND);
    
    // Texture being used is 64 by 64:
    D3DXVECTOR2 spriteCentre=D3DXVECTOR2(32.0f,32.0f);
    
    // Screen position of the sprite
    D3DXVECTOR2 trans=D3DXVECTOR2(WindowRect.right-300, WindowRect.bottom/2-100);
    
    // Rotate based on the time passed
    float rotation;
    
    // Build our matrix to rotate, scale and position our sprite
    D3DXMATRIX mat;
    
    D3DXVECTOR2 scaling(0.5f,0.7f);
    
    // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation
    D3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,&spriteCentre,rotation,&trans);
    
    // Tell the sprite about the matrix
    sprite->SetTransform(&mat);
    
    
    sprite->Draw(texture,NULL,NULL,&pos,0xFFFFFFFF);
    
    sprite->End();
    
    texture->Release();
    sprite->Release();
    Device_t->Release();
    
    }
    Then of course after you have done that you have to add it into hkEndScene like the previous function so it's being drawn...

    Code:
    DrawElmoSprite(pDevice);
    Easy... So, hopefully this will help sum1...
    Last edited by Justei; 05-05-11 at 02:54 PM.


  2. #2
    Alpha Member Zen is offline
    MemberRank
    Dec 2006 Join Date
    MelbourneLocation
    2,291Posts

    Re: Some D3D hooking coding.

    An awesome and extremely useful release my friend :)

    I will have a play with it when i'm at home

  3. #3
    Developer BeshoyFD is offline
    MemberRank
    Jul 2008 Join Date
    In World :)Location
    702Posts

    Re: Some D3D hooking coding.

    Thank you for released this useful thread

    Small Question.
    i didn't understand this :
    > You need to make a new thread for this in the engine. <

    how i add the thread in engine ??
    i think the only way the open engine is with hex editor program and i tried before to add , remove anything in engine but i failed and i got error

    can you explain me that, please ?

  4. #4
    Account Upgraded | Title Enabled! walid445200 is offline
    MemberRank
    Jan 2010 Join Date
    :DLocation
    461Posts

    Re: Some D3D hooking coding.

    hmmm i dont know much about that .. but thanks i will save them maybe i learn in some day

    10000 thanks to you (Justei)

  5. #5
    Alpha Member Justei is offline
    MemberRank
    Oct 2007 Join Date
    /f241Location
    1,904Posts

    Re: Some D3D hooking coding.

    Quote Originally Posted by The..DragoN View Post
    Thank you for released this useful thread

    Small Question.
    i didn't understand this :
    > You need to make a new thread for this in the engine. <

    how i add the thread in engine ??
    i think the only way the open engine is with hex editor program and i tried before to add , remove anything in engine but i failed and i got error

    can you explain me that, please ?
    Google for process threading. Has nothing to do with editing the engine.


    Quote Originally Posted by walid445200 View Post
    hmmm i dont know much about that .. but thanks i will save them maybe i learn in some day

    10000 thanks to you (Justei)
    Your welcome, it's not very hard if u start learning it..

  6. #6
    Account Upgraded | Title Enabled! walid445200 is offline
    MemberRank
    Jan 2010 Join Date
    :DLocation
    461Posts

    Re: Some D3D hooking coding.

    i have to give it a try ^^



Advertisement