View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# [C++] Direct3D hooking sample

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

32 replies to this topic

Posted 22 November 2005 - 11:55 PM

### #2Dave  Members

Posted 23 November 2005 - 12:02 AM

This is great and much needed since there have been so many "How do i's...".

PRAISE TO YAW!!!

### #3jollyjeffers  GDNet+

Posted 23 November 2005 - 02:11 AM

I've never had the time to look into API hooking in much detail, but I've always been curious how it actually worked. I shall be sure to have a look through your code as/when I get some time [smile]

Cheers!
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

### #4circlesoft  Members

Posted 24 November 2005 - 10:17 AM

Niiiiiice, this is quality work. If I only had a dollar for each time I answered a "hooking" question, I would be a BAZILIONIONAIRE!!! Gotta love the tediousness of inheriting IDirect3DDevice9...there are only like 14 trillion member functions.

Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

Posted 24 November 2005 - 05:42 PM

Quote:
 Original post by circlesoftNiiiiiice, this is quality work. If I only had a dollar for each time I answered a "hooking" question, I would be a BAZILIONIONAIRE!!!

No need to be modest, we all know you already are!

Quote:
 Gotta love the tediousness of inheriting IDirect3DDevice9...there are only like 14 trillion member functions.

Yes, seriously. I almost broke my fingers on this one.

Posted 27 November 2005 - 10:47 AM

I did something similar with IDirectPlay8Client. Took a while getting it to work but now i have nice send/recv sniffer for combat flight simulator 3 and all other games using directplay8client.

### #7Promit  Senior Moderators

Posted 27 November 2005 - 11:19 AM

Wow, this is awesome. I intend to have some fun with this. I enjoyed hooking OpenGL and writing wallhacks for HL1 and its mods*. Let's see what I can do with this. And, kudos for typing out all those functions. There sure are a lot...

* Of course I don't play publically with the hacks. I rather happen to enjoy writing them, is all.

### #8jollyjeffers  GDNet+

Posted 28 November 2005 - 06:02 AM

I'm wondering if there is some sort of image-analysis tool that can be built on top of this sort of technology.

If you could hook a commercial game and count the number of shaders used, number of passes, overdraw complexity and so on... would be an interesting thing to mess with if nothing else.

Make it work well and the hardware-nuts would love it - they spend enough time talking about clockspeeds and megahurtz that I'm sure they'll have good fun with a screenshot of the shader-complexity of a commercial game [lol]

Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

### #9circlesoft  Members

Posted 28 November 2005 - 06:46 AM

Quote:
 Original post by jollyjeffersI'm wondering if there is some sort of image-analysis tool that can be built on top of this sort of technology.If you could hook a commercial game and count the number of shaders used, number of passes, overdraw complexity and so on... would be an interesting thing to mess with if nothing else. Make it work well and the hardware-nuts would love it - they spend enough time talking about clockspeeds and megahurtz that I'm sure they'll have good fun with a screenshot of the shader-complexity of a commercial game [lol]Jack

That would be quite easy...just hook into IDirect3DDevice9::SetVertexShader() and IDirect3DDevice9::SetPixelShader(). Then count up how many changes you have per frame. You can do *all* kinds of performance analysis like that.

p.s. IIRC the effect framework still uses Set*Shader() in its underlying implementation

Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

### #10Promit  Senior Moderators

Posted 28 November 2005 - 06:57 AM

Maybe I'm missing something here, but isn't that exactly what PIX does?

### #11DirectXFreak  Members

Posted 28 November 2005 - 07:07 AM

Wow! This is really cool!
You should make this an article =P

[Edited by - DirectXFreak on November 28, 2005 5:07:07 PM]

### #12circlesoft  Members

Posted 28 November 2005 - 07:13 AM

Quote:
 Original post by PromitMaybe I'm missing something here, but isn't that exactly what PIX does?

D'oh...

I just tried that using PIX on GTA: San Andreas. Some sample stats:

DrawPrim............32DrawIndexedPrim.....160VB Locks............45IB Locks............13SetRenderState......163SetTexture..........190SetVertexShader.....6SetPixelShader......0SetRenderTarget.....12

Considering that this was a really simple scene (just inside the main characters house, very low complexity) I think those numbers are high.

### #13jollyjeffers  GDNet+

Posted 28 November 2005 - 08:32 AM

Quote:
 Original post by PromitMaybe I'm missing something here, but isn't that exactly what PIX does?

Yeah, essentially... I have to admit I haven't tried it, but you can't get PIX to generate an overdraw of the image, can you? deep pixel analysis yes, but not shader complexity and so on..?

The idea came from this thread. It'd be pretty awesome if you could somehow display the number of pixel shader arithmetic or texture instruction count per-pixel. Could make for a great performance debugging tool - the brighter the colours the more fill-rate related work you're doing etc...

Then again, hacking that in via hooking stands as much chance of breaking things as it does working [lol]

Oh, and the obvious advantage is that it'd be overlayed - giving immediate feedback rather than the capture full stream then analyse the data.

Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

### #14DrGUI  Members

Posted 02 December 2005 - 04:09 AM

Why might you need that many VB and IB locks per frame?
Was there a legendary particle system in the house or something?

### #15circlesoft  Members

Posted 02 December 2005 - 05:43 AM

Quote:
 Original post by DrGUIWhy might you need that many VB and IB locks per frame?Was there a legendary particle system in the house or something?

Yea, and this is inside a really simple house. I did some more investigating, and profiled a complex scene outside:

DIP Calls:  1300 - 2300 (:O !!!)VB Locks: 120-145IB Locks: 50-75New VBs: 1-5New IBs: 1-7FPS: 10-20

Yea...so I wonder really what the frick is going on. Looks like someone at Rockstar needs to read the renown instancing slidedeck...

Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

### #16Person  Members

Posted 27 December 2005 - 09:02 AM

If I use that sample than AOE 3 hangs.
And nothing happened in COD 2.

### #17Jason Z  Members

Posted 27 December 2005 - 12:21 PM

Oh my. This could be used for some serious hacking of applications. Really, you could trace exactly how the api is used - frankly I think it is pretty cool but I am surprised that MS allows this type of thing to be done.

I think I am going to try a few experiments with my own engine and see if this can be used for some type of runtime analysis of my rendering calls. Great work, I appreciate your effort (and typing abilities!).

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #18circlesoft  Members

Posted 27 December 2005 - 01:33 PM

Quote:
 Original post by Jason ZOh my. This could be used for some serious hacking of applications. Really, you could trace exactly how the api is used - frankly I think it is pretty cool but I am surprised that MS allows this type of thing to be done.

I think so, since they full support the ultimate "hacking" application - PIX. PIX makes it easy to analyze exactly what an application is doing, D3D-wise. IMO, after doing some trials on commercial games, it is more helpful than the hooking approach for profiling.

### #19Jason Z  Members

Posted 27 December 2005 - 02:24 PM

Holy Crap!

I just ran a test run of PIX on the latest build of my game. I tried using PIX long ago when it first came out and wasn't very impressed, but it has really evolved quite a bit from what I remember.

The object window alone is worth using, not to mention the frame rendering stream. So this will work with any D3D9 commercial application? I guess once you ship something you are essentially allowing everyone to see what you are doing - it kind of opens up the doors to smaller developers (like me!) to see what the big boys are doing.

Thats pretty cool.

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #20circlesoft  Members

Posted 27 December 2005 - 02:53 PM

Quote:
 Original post by Jason ZThe object window alone is worth using, not to mention the frame rendering stream. So this will work with any D3D9 commercial application? I guess once you ship something you are essentially allowing everyone to see what you are doing - it kind of opens up the doors to smaller developers (like me!) to see what the big boys are doing.

Yea pretty much - they have worked on all commercial games I have tried it on (HL2, Farcry, GTA:SA). If you read a few posts above, I show some figures about GTA that are a little disturbing [crying]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.