Code:
struct line_vertex {
float x, y, z, rhw; // The transformed(screen space) position for the vertex.
DWORD colour; // The vertex colour.
};
HRESULT WINAPI EndScene_Hook(IDirect3DDevice9 *thisPtr)
{
if (bRunning) {
std::lock_guard<std::mutex> guard(objManager.mutexObjectList);
for (std::vector<UnitObject*>::iterator iter = objManager.unitObjectList.begin(); iter != objManager.unitObjectList.end(); iter++) {
D3DXVECTOR3 in;
D3DXVECTOR3 inTop;
D3DXVECTOR3 out;
D3DXVECTOR3 outTop;
in.x = (*iter)->pos.x;
in.y = (*iter)->pos.y;
in.z = (*iter)->pos.z;
inTop.x = (*iter)->pos.x;
inTop.y = (*iter)->pos.y;
inTop.z = (*iter)->pos.z + 2.0f;
if (WorldToScreen(thisPtr, in, &out)) {
WorldToScreen(thisPtr, inTop, &outTop);
float height = abs(out.y - outTop.y);
float width = height / 2.0f;
DrawBox(thisPtr, out.x - width / 2.0f, out.y - height, width, height, D3DCOLOR_ARGB(0, 255, 0, 0));
}
}
//Draw generated path
if (pathLength != 0) {
D3DXVECTOR3* outPath = new D3DXVECTOR3[pathLength];
for (int i = 0; i < pathLength; i++) {
D3DXVECTOR3 inPath;
inPath.x = path[i].x;
inPath.y = path[i].y;
inPath.z = path[i].z;
if (WorldToScreen(thisPtr, inPath, &outPath[i])) {
DrawLineH(thisPtr, outPath[i].x, outPath[i].x + 5, outPath[i].y, 5, D3DCOLOR_ARGB(0, 0, 255, 0));
}
}
line_vertex* vertData = new line_vertex[pathLength];
for (int i = 0; i < pathLength; i++) {
vertData[i].x = outPath[i].x;
vertData[i].y = outPath[i].y;
vertData[i].z = 0.0f;
vertData[i].rhw = 1.0f;
vertData[i].colour = D3DCOLOR_ARGB(0, 0, 0, 255);
}
IDirect3DStateBlock9* pStateBlock;
thisPtr->CreateStateBlock(D3DSBT_ALL, &pStateBlock);
pStateBlock->Capture();
IDirect3DVertexBuffer9* vertexBuffer;
thisPtr->CreateVertexBuffer(sizeof(line_vertex) * pathLength, D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vertexBuffer, NULL);
VOID* pVoid;
vertexBuffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertData, sizeof(line_vertex) * pathLength);
vertexBuffer->Unlock();
thisPtr->SetRenderState(D3DRS_LIGHTING, FALSE);
thisPtr->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
thisPtr->SetVertexShader(NULL);
thisPtr->SetPixelShader(NULL);
thisPtr->SetTexture(0, NULL);
thisPtr->SetFVF((D3DFVF_XYZRHW | D3DFVF_DIFFUSE));
thisPtr->SetStreamSource(0, vertexBuffer, 0, sizeof(line_vertex));
thisPtr->DrawPrimitive(D3DPT_LINELIST, 0, pathlength - 1); //S_OK
if (vertexBuffer != NULL)
vertexBuffer->Release();
pStateBlock->Apply();
}
}
return origEndScene(thisPtr);
}
Thanks for taking a look! maybe after some more sleep I'll find the issue.