I'm trying to add some models to an existing game. I'm injected into the game, and i've hooked the direct3d device succesfully. I tested this by setting the fill mode to wire frame and the game indeed changes to wire frame(I did have to add a clear to an endscene detour or else the wire-frames would leave "tracers").
I'm having a couple issues. One, for some reason my device is working kind of strange. For example, for me to turn the wireframe on, I have to do the following:
IDirect3DDevice9* Device = 0;
Device = (IDirect3DDevice9*)DeviceAddress;
//i have to use:
Device->lpVtbl->SetRenderState(Device,D3DRS_FILLMODE,3);
//instead of
Device->SetRenderState(D3DRS_FILLMODE,3);
Thats one of the minor problems, and I don't mind passing the "this" to the function manually, but it's kind of strange.
The real issue is, I've hooked the games EndScene(), and halt it momentarily so that I can read some vertices in but it isn't showing up in the game. When I click out of the game window and it goes into background mode and gets all choppy I can see my cube show up in flashes... When I toggle to wireframe mode I can see my cubes triangles... but for some reason in filled mode it just doesnt get seen.
#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE )
IDirect3DDevice9* Device = 0;
LPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;
struct Vertex
{
float x, y, z;
DWORD color;
};
Vertex g_cubeVertices[] =
{
{-1.0f, 1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f, 1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f,-1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f,-1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f,-1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f,-1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f, 1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f, 1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f,-1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f,-1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f,-1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f,-1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f, 1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f,-1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{ 1.0f,-1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f, 1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f,-1.0f,-1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) },
{-1.0f,-1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255) }
};
VOID enter()
{
hookdevice();
Device->lpVtbl->CreateVertexBuffer(Device, 24*sizeof(Vertex),0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL );
void *pVertices = NULL;
g_pVertexBuffer->lpVtbl->Lock(g_pVertexBuffer, 0, sizeof(g_cubeVertices), (void**)&pVertices, 0 );
memcpy( pVertices, g_cubeVertices, sizeof(g_cubeVertices) );
g_pVertexBuffer->lpVtbl->Unlock(g_pVertexBuffer);
}
VOID MyDevice::Detour_EndScene(VOID)
{
Device->lpVtbl->SetStreamSource(Device, 0, g_pVertexBuffer, 0, sizeof(Vertex) );
Device->lpVtbl->SetFVF(Device, D3DFVF_CUSTOMVERTEX );
Device->lpVtbl->DrawPrimitive(Device, D3DPT_TRIANGLESTRIP, 0, 2 );
Device->lpVtbl->DrawPrimitive(Device, D3DPT_TRIANGLESTRIP, 4, 2 );
Device->lpVtbl->DrawPrimitive(Device, D3DPT_TRIANGLESTRIP, 8, 2 );
Device->lpVtbl->DrawPrimitive(Device, D3DPT_TRIANGLESTRIP, 12, 2 );
Device->lpVtbl->DrawPrimitive(Device, D3DPT_TRIANGLESTRIP, 16, 2 );
Device->lpVtbl->DrawPrimitive(Device, D3DPT_TRIANGLESTRIP, 20, 2 );
Real_EndScene();
}
I'd google, but i'm really not even sure what to look for... anyone have an guesses? I'll gladly give more details, I did dozens of attempts over the last 24hrs with slightly different outcomes.