Reversing and injecting some D3D9 code

Started by
3 comments, last by vika 7 years, 4 months ago

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:

FxAsTD1.jpg

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 !

Advertisement

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

Thanks ! This worked perfectly !

Last question:

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

Ej1WYN6.png

Knowing that the Vertex Declaration is this :

ugsDD07.png

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 !

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

This topic is closed to new replies.

Advertisement