DirectX Hooking Example, Along With Drawing Text On DirectX

c++ / delphi package - dll injection and api hooking
Ultimation
Posts: 11
Joined: Sat Apr 12, 2008 7:09 pm

DirectX Hooking Example, Along With Drawing Text On DirectX

Post by Ultimation »

This Is an example Project Showing You How To Hook DirectX Games And Draw Custom Text Onto The Games Screen.

Original Code By Madshi. Direct3DHooking Example

Edited By Ultimation To Include Drawing Text Onto DirectX Screens
http://rapidshare.com/files/106970336/M ... k.rar.html


More Examples

Drawing Text Ingame Via DLL Injection
Drawing Text Ingame Without DLL Injection (Proxying d3d9.dll)
Drawing Images Ingame Via DLL Injection
Drawing Images Ingame Without DLL Injection( Proxying d3d9.dll)

Download From Below!

http://rapidshare.com/files/115982431/D ... s.rar.html
Last edited by Ultimation on Sun May 25, 2008 10:32 pm, edited 1 time in total.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I like it - thanks! :)

May I use this for my demos?
Calandoriel
Posts: 25
Joined: Sun Oct 01, 2006 11:43 pm
Location: www.ipconfig.se

I might be wrong

Post by Calandoriel »

I might be wrong, but should not the code be like this:

function PresentCallback(const Self: IDirect3DDevice9;
const SourceRect, DestRect: PRect;
const DestWindowOverride: HWND;
DirtyRegion: PRgnData): HResult; stdcall;
var
Font: D3DX9.ID3DXFont;
rec: ^TRect;
begin
//Your Drawing Code Here. This Function Gets Called Everytime The Surface Needs Refreshing
D3DXCreateFontA(Self, 15, 0, FW_BOLD, 1, False, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH or FF_DONTCARE, 'Arial', Font);

GetMem(rec, 16);
SetRect(rec^, 200, 0, 900, 900);

Font.DrawTextA(nil, 'DirectX Drawing Text Example',
Length('DirectX Drawing Text Example'), rec^, DT_LEFT, $FFFFFFFF);

Result := PresentNext(self, SourceRect, DestRect, DestWindowOverride, DirtyRegion);

end;

?

And how do i get ridd of that annoying "need d3dx9.dll thingy" thing
Cause i asume you use the Direct3D9 and d3d9 libs from Jedi right?
Calandoriel
Posts: 25
Joined: Sun Oct 01, 2006 11:43 pm
Location: www.ipconfig.se

Post by Calandoriel »

never mind, found the correct library :)
Darkparasit
Posts: 3
Joined: Wed Nov 21, 2007 11:37 am

Post by Darkparasit »

can anyone post a little example how to use it?
it would be nice,

thx
Calandoriel
Posts: 25
Joined: Sun Oct 01, 2006 11:43 pm
Location: www.ipconfig.se

Hm

Post by Calandoriel »

Madshi

See anything weird in this code? I get General Protection errors with it

Code: Select all

 function PresentCallback(const Self: IDirect3DDevice9;
  const SourceRect, DestRect: PRect;
  const DestWindowOverride: HWND;
    DirtyRegion: PRgnData): HResult; stdcall;
  var
    Sprite: D3DX9.ID3DXSprite;
    //dxVector: D3DX9.TD3DXVector2;
    Texture: Direct3D9.IDirect3DTexture9;
    rec:  PRect;
    Vector: D3DX9.PD3DXVector3;
  begin
      //Your Drawing Code Here. This Function Gets Called Everytime The Surface Needs Refreshing
      D3DXCreateSprite(Self, Sprite);
      //D3DXCreateTexture(Self,200,200,nil,nil,nil,nil,nil,nil,nil,Texture);
      D3DXCreateTextureFromFile(Self,pchar('bitmap.bmp'),Texture);
      GetMem(rec, 32);
      SetRect(rec^, 1, 1, 200, 200);
      //Sprite._Begin(D3DXSPRITE_ALPHABLEND or D3DXSPRITE_BILLBOARD or
      //D3DXSPRITE_SORT_DEPTH_FRONTTOBACK);
      Vector.x := 1;
      Vector.y := 1;
      Vector.z := 0;
      Sprite.Draw(Texture,rec,nil,nil, D3DCOLOR_ARGB(255,255,255,0));
      //Font.DrawTextA(nil, 'This is text tra la la la',
      //Length('This is text tra la la la'), rec, DT_LEFT, $FFFFEF55);

    Result := PresentNext(self, SourceRect, DestRect, DestWindowOverride, DirtyRegion);

  end;
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: Hm

Post by madshi »

Calandoriel wrote:See anything weird in this code? I get General Protection errors with it
On a quick check I see 3 things which look wrong to me:

(1) You're not freeing that "rec" that you allocated -> memory leak.
(2) "TRect" is only 16 bytes long and not 32, I think?
(3) Vector looks like a pointer, but you're not allocating it. Try "Vector: D3DX9.D3DXVector3" instead. Or however the non-point type is named.
Calandoriel
Posts: 25
Joined: Sun Oct 01, 2006 11:43 pm
Location: www.ipconfig.se

hm

Post by Calandoriel »

Well
Sprite.Draw(Texture,rec,nil,nil, D3DCOLOR_ARGB(255,255,255,0));

Requires a PD3DXVector3 as argument.
If you are gonna use it.

Anyhow, i tried to take what you said into consideration and made this:

Code: Select all

function PresentCallback(const Self: IDirect3DDevice9;
  const SourceRect, DestRect: PRect;
  const DestWindowOverride: HWND;
    DirtyRegion: PRgnData): HResult; stdcall;
  var
    Sprite: D3DX9.ID3DXSprite;
    //dxVector: D3DX9.TD3DXVector2;
    Texture: Direct3D9.IDirect3DTexture9;
    rec:  PRect;
    Vector: D3DX9.PD3DXVector3;
  begin
      //Your Drawing Code Here. This Function Gets Called Everytime The Surface Needs Refreshing
      D3DXCreateSprite(Self, Sprite);
      D3DXCreateTextureFromFile(Self,pchar('bitmap.bmp'),Texture);
      GetMem(rec, 16);
      SetRect(rec^, 1, 1, 200, 200);
      GetMem(Vector,16);
      Vector.x := 1;
      Vector.y := 1;
      Vector.z := 1;
      Sprite.Draw(Texture,rec,Vector,Vector, D3DCOLOR_ARGB(255,255,255,0));
//Free      
FreeMem(rec);
      FreeMem(Vector);
    Result := PresentNext(self, SourceRect, DestRect, DestWindowOverride, DirtyRegion);
  end;

It does not crash, but it does not show a picture either.
Calandoriel
Posts: 25
Joined: Sun Oct 01, 2006 11:43 pm
Location: www.ipconfig.se

Post by Calandoriel »

Solved the pussle :)
Thanks for your help Madshi.

Code: Select all

 function PresentCallback(const Self: IDirect3DDevice9;
  const SourceRect, DestRect: PRect;
  const DestWindowOverride: HWND;
    DirtyRegion: PRgnData): HResult; stdcall;
  var
    Sprite: D3DX9.ID3DXSprite;
    Texture: Direct3D9.IDirect3DTexture9;
    rec:  PRect;
    Vector: D3DX9.PD3DXVector3;
  begin
      //Your Drawing Code Here. This Function Gets Called Everytime The Surface Needs Refreshing
      D3DXCreateSprite(Self, Sprite);
      //D3DXCreateTexture(Self,200,200,nil,nil,nil,nil,nil,nil,nil,Texture);
      D3DXCreateTextureFromFile(Self,'bitmap.bmp',Texture);
      GetMem(rec, 16);
      SetRect(rec^, 1, 1, 200, 200);
      GetMem(Vector,16);
      Vector.x := 1;
      Vector.y := 1;
      Vector.z := 1;
      Self.BeginScene;
      Sprite._Begin(0);
      Sprite.Draw(Texture,rec,Vector,Vector, D3DCOLOR_ARGB(255,255,255,0));
      Sprite._End;
      Self.EndScene;
      FreeMem(rec);
      FreeMem(Vector);
    Result := PresentNext(self, SourceRect, DestRect, DestWindowOverride, DirtyRegion);
  end;
Will draw a sprite :)

If you just want it to draw everything "as it is" do:

Code: Select all

 function PresentCallback(const Self: IDirect3DDevice9;
  const SourceRect, DestRect: PRect;
  const DestWindowOverride: HWND;
    DirtyRegion: PRgnData): HResult; stdcall;
  var
    Sprite: D3DX9.ID3DXSprite;
    Texture: Direct3D9.IDirect3DTexture9;
  begin
      //Your Drawing Code Here. This Function Gets Called Everytime The Surface Needs Refreshing
      D3DXCreateSprite(Self, Sprite);
      D3DXCreateTextureFromFile(Self,'sprite.jpg',Texture);
      Self.BeginScene;
      Sprite._Begin(0);
      Sprite.Draw(Texture,nil,nil,nil, $AAFFFFFF);
      Sprite._End;
      Self.EndScene;
    Result := PresentNext(self, SourceRect, DestRect, DestWindowOverride, DirtyRegion);
  end;
Ultimation
Posts: 11
Joined: Sat Apr 12, 2008 7:09 pm

Post by Ultimation »

i didnt mean to add the drawing texture part that was me messing around, and yes i 4got freememory and the rect is only 16 bytes! sorry.

yes you may use this in demos. i have recently made some progress and built a ingame msn messenger! wich will soon be avaliable for people to use.

here is its progress!

Image
Calandoriel
Posts: 25
Joined: Sun Oct 01, 2006 11:43 pm
Location: www.ipconfig.se

Cool!

Post by Calandoriel »

Cool dude, if you want to, i'd like to work on some theories with you.
PM me if you could possible come around adding me to your msn.
Ultimation
Posts: 11
Joined: Sat Apr 12, 2008 7:09 pm

Post by Ultimation »

sure you can add me at ultimatehaker@hotmail.com (msn)

Regards

Ultimation
Ultimation
Posts: 11
Joined: Sat Apr 12, 2008 7:09 pm

Post by Ultimation »

you will find when drawing textures ingame you and you minimize the game your game will fail to restore and most likely crash. to correct this you need to add 2 more hooks to the directx device one on the OnLostDevices and antoher on OnRestoreDevices

in the OnLostDevices hook, do mysprite._LostDevice()

and on the RestoreDevice hook do mysprite._OnRestore()


Update------

Something Else Came To My Attention. Please make sure you are using the correct header files for your delphi version, otherwise you may need useless dll files like d3dx9.dll

here are the appropriate header files.

Delphi 4 And Delphi 5
http://rapidshare.com/files/114333479/B ... 5.rar.html
Delphi 6 And Delphi 7
http://rapidshare.com/files/114333666/B ... 7.rar.html
Delphi 2005 - 2007
http://rapidshare.com/files/114333985/B ... 0.rar.html

Regards

Ultimation
Darkparasit
Posts: 3
Joined: Wed Nov 21, 2007 11:37 am

Post by Darkparasit »

thx Ultimation, for the example and the help :)
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Nice! Would you mind uploading a new demo with the OnLost/RestoreDevices code in it? I'm not so good with Direct3D hooking/programming... :oops:
Post Reply