# Reversing and injecting some D3D9 code

This topic is 667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello !

First, thanks for this forum, as I got my answers here very often.

I'm trying to make some graphic modifications to an old 2D game, and because the .exe is not easily reverse-engineerable (nor the game data file) I succeeded by creating a d3d9.dll proxy.

The modifications were simple so far (removing some elements, adjusting screen size), I've done that by hooking the SetViewport function and the DrawIndexedPrimitiveUP (and checking textures of elements I wanted to remove).

Now what I wanted is to rotate some letters elements (drew by a DrawPrimitiveUP call).

I tried SetTransform methods with no luck.

Checking when letters are drawn gives this inside PIX:

I think I read somewhere that using a vertex shader may avoid SetTransform to work ? Is this correct ?

So I thought that I could create a new VertexShader that is the same as the disassembled one (as it is not too complex, I think I can do that) that also adds the rotation, and applying it in a proxy DrawPrimitiveUP method before drawing the letter.

Am I going in the right direction ?

How should I override the VertexShader ?

I've never done this before (directx programming, custom dll injection), so I'm maybe missing something obvious here.

Thanks for any help !

##### Share on other sites

I guess you could hook the dx function they use to set uniform variables (transformation) and change the transformation matrix to yours.

##### Share on other sites

Thanks ! This worked perfectly !

##### Share on other sites

Last question:

I want to get the D3DCOLOR_ARGB value in the "mesh" tab of PIX (here FF00DCFF):

Knowing that the Vertex Declaration is this :

I tried to do something like this but cannot to get the correct color value in the DrawPrimitiveUP proxy function:

HRESULT myIDirect3DDevice9::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
char buff[256];
unsigned int color = 0;
if (PrimitiveCount == 2 && VertexStreamZeroStride == 24) {
// [0], [1], [2] are the floats, [3] is the color
color = ((unsigned int *)pVertexStreamZeroData)[3] & 0xFFFFFF00 >> 8; // removing alpha value
sprintf_s(buff, "color:  hex:%08x - int:%u", color, color);
DEBUG_LOG(buff);
}
... etc ...


Can this work that way ? Thanks !

##### Share on other sites

Was a code typo, fixed it (and fixed the code example)

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 73
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009578
• ### Who's Online (See full list)

There are no registered users currently online

×