OldSchoolHack

Register / Login English

Polygon in Welt zeichnen


icon Polygon in Welt zeichnen #1

Join Date: Sep 2013

Posts: 5

User-Rating:

1 positive
0 negative
Moin Leute,

hat mal jemand "echte" Polygone in die CoD2-Welt eingefügt? Ich habe cuBot und Tatnium in Visual Studio kombiniert, sodass ich jetzt D3D-Funktionen hooken kann, aber wenn ich DirectX Tutorials folge, kann ich keine Polygone zeichen. Das Fenster bleibt dann einfach schwarz. Diesen Code verwende ich bisher:

TEXT Code:
  1.  
  2. HRESULT APIENTRY hkIDirect3DDevice9::EndScene()
  3. {
  4.     #if 1
  5.     struct CUSTOMVERTEX
  6.     {
  7.     FLOAT x, y, z, rhw;    // from the D3DFVF_XYZRHW flag
  8.     DWORD color;    // from the D3DFVF_DIFFUSE flag
  9.     };
  10.  
  11.     static int first = 1;
  12.     static LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
  13.  
  14.     printf("HRESULT APIENTRY hkIDirect3DDevice9::EndScene(%d)\n", first);
  15.     if (first)
  16.     {
  17.         first = 0;
  18.  
  19.         #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
  20.  
  21.         CUSTOMVERTEX vertices[] =
  22.         {
  23.         { 1551.0f+320, 2663.0f+ 50, 415.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
  24.         { 1551.0f+520, 2663.0f+400, 415.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
  25.         { 1551.0f+120, 2663.0f+400, 415.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
  26.         };
  27.  
  28.         m_pD3Ddev->CreateVertexBuffer(3*sizeof(struct CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);
  29.  
  30.         VOID* pVoid;    // the void pointer
  31.  
  32.         v_buffer->Lock(0, 0, (void**)&pVoid, 0);
  33.         memcpy(pVoid, vertices, sizeof(vertices));
  34.         v_buffer->Unlock();
  35.     }
  36.  
  37.     LPDIRECT3DSTATEBLOCK9 pStateBlock = NULL;
  38.     m_pD3Ddev->CreateStateBlock( D3DSBT_ALL, &pStateBlock );  
  39.     pStateBlock->Capture();
  40.  
  41.         //m_pD3Ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  42.         //m_pD3Ddev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);//<-
  43.         //m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
  44.         //m_pD3Ddev->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
  45.         //m_pD3Ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
  46.         //m_pD3Ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
  47.  
  48.     //D3DVECTOR vEyePt    = {0.0f, 0.0f, -10.0f };
  49.     //D3DVECTOR vLookatPt = {0.0f, 0.0f,   0.0f };
  50.     //D3DVECTOR vUpVec    = {0.0f, 1.0f,   0.0f };
  51.     //D3DMATRIX matWorld, matView, matProj;
  52.     //
  53.     //
  54.     //D3DUtil_SetIdentityMatrix( matWorld );
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.     //m_pD3Ddev->SetFVF(CUSTOMFVF); // select which vertex format we are using
  62.     m_pD3Ddev->SetStreamSource(0, v_buffer, 0, sizeof(struct CUSTOMVERTEX)); // select the vertex buffer to display
  63.     m_pD3Ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); // copy the vertex buffer to the back buffer
  64.  
  65.     pStateBlock->Apply();
  66.     pStateBlock->Release();
  67.     #endif
  68.  
  69.     return m_pD3Ddev->EndScene();
  70. }
  71.  

Ich hoffe, hier gibt's noch ein paar fähige Leute.

Das ganze soll eine CoD2-Erweiterung werden, mit der bullet physics engine.


Viele Grüße,
kung foo man

icon #2

Join Date: Sep 2013

Posts: 5

User-Rating:

1 positive
0 negative
Ich habe jetzt herausgefunden, warum alles schwarz geworden ist (Crash). Die Engine lädt beim Map-Beginn D3D neu und alle gespeicherten Vertices etc. sind dann natürlich ungültig. Nachdem ich die jetzt immer reinitialisiere, funktionert es ohne Crash, jedoch kann ich noch kein Polygon sehen.

Ich muss wahrscheinlich noch eine Matrix setzen, aber das muss ich morgen ausprobieren.
icon #3

Join Date: May 2011

Posts: 419

User-Rating:

199 positive
8 negative
Ich kann dir da leider nich helfen, da ich mich noch nie mit
D3D groß beschäftigt habe, aber ich geb dir den Tipp,
mal im IRC oder auf dem TS vorbei zu schauen,
da sind meistens leute online, die sich mit D3D / hooking
auskennen.

mfg Dr_Pepper

__________________

http://abload.de/img/signaturmitoshlogos2ufb.jpg
http://abload.de/img/pfeila4uzk.png Da unten ist ein Like-Button, benutze ihn doch
Last edited by Dr_Pepper (Mon 9. Sep 2013, 15:30)

Reason: no reason given

icon #4

Join Date: Aug 2007

Posts: 8646

User-Rating:

199 positive
33 negative
mit Polygon meinst du sowas wie die Sphere hier links oder?

http://i1.ytimg.com/vi/XlaEOtnlnUo/maxresdefault.jpg

__________________

Hallo
icon #5

Join Date: Sep 2013

Posts: 5

User-Rating:

1 positive
0 negative
Jo genau, nur weiß ich nicht, ob es sich bei der Sphere um eine "echte" Sphere handelt. Also ob D3D die Sphere per Projektionsmatrix erzeugt oder ob der Programmierer jede einzelne Linie durch eine world2screen-Funktion gejagd hat und dann nur 2D auf der Oberfläche zeichnet.

In OpenGL wäre das einfach:
glPushMatrix()
glLoadIdentity()
glTransform(Position von Objekt)
glRotate(...)
glBegin()
glVertex(Fixe Objekt-Koordinaten)
glEnd()
glPopMatrix()

Mit D3D komme ich nicht klar. :S
icon #6

Join Date: Aug 2007

Posts: 8646

User-Rating:

199 positive
33 negative
Und so ähnlich gehts in D3D auch. (Ungetestet weil noch nie gemacht)

CPP Code:
  1. //1. Device vorbereiten
  2. device->SetVertexShader(nullptr);
  3. device->SetPixelShader(nullptr);
  4. device->SetTexture(0, nullptr);
  5. device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
  6.  
  7. device->SetRenderState(D3DRS_ZENABLE, TRUE);
  8. device->SetRenderState(D3DRS_LIGHTING, FALSE);
  9. device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
  10. device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  11. device->SetRenderState(D3DRS_CLIPPING, FALSE);
  12. device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
  13. device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
  14. device->SetRenderState(D3DRS_SRCBLEND , D3DBLEND_SRCALPHA);
  15. device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTA_TEXTURE);
  16. device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTA_DIFFUSE);
  17.  
  18. //2. Sphere mit D3DXCreateSphere erzeugen
  19.  
  20. //3. Sphere rendern
  21. void DrawMesh(ID3DXMesh *mesh, Vector position, float scale, Color color)
  22. {
  23. LPDIRECT3DVERTEXBUFFER9 temp;
  24. if (SUCCEEDED(mesh->GetVertexBuffer(&temp)))
  25. {
  26. Vertex *vertices;
  27. if (SUCCEEDED(temp->Lock(0, 0, (void**)&vertices, 0)));
  28. {
  29. auto verticesCount = mesh->GetNumVertices();
  30. for (auto i = 0; i < verticesCount; ++i)
  31. {
  32. vertices[i].color = color;
  33. }
  34.  
  35. temp->Unlock();
  36. }
  37.  
  38. temp->Release();
  39. }
  40.  
  41. D3DXMATRIX world;
  42. D3DXMATRIX scaling;
  43.  
  44. D3DXMatrixTranslation(&world, position.x, position.y, position.z);
  45. D3DXMatrixScaling(&scaling, scale, scale, scale);
  46.  
  47. auto transform = scaling * world;
  48. device->SetTransform(D3DTS_WORLD, &transform);
  49.  
  50. mesh->DrawSubset(0);
  51. }

Wie genau du die anderen Matrizen setzen musst (Projection und View) kann ich dir grad nicht sagen und ist sicher spielabhängig.

__________________

Hallo
Last edited by KN4CK3R (Tue 10. Sep 2013, 18:52)

Reason: no reason given

icon #7

Join Date: Sep 2013

Posts: 5

User-Rating:

1 positive
0 negative
Quote from KN4CK3R

Wie genau du die anderen Matrizen setzen musst (Projection und View) kann ich dir grad nicht sagen und ist sicher spielabhängig.

Der FOV für die Projektion ist natürlich cvar-Abhängig, aber genau diesen Code brauche ich. Egal was ich probiere, ich kann die Matrizen nicht ändern.

TEXT Code:
  1.  
  2. D3DXMATRIXA16 matView;
  3. D3DXMATRIXA16 matProj;
  4. matView._41 = matView._42 = matView._43 = 0.0f;
  5. D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/2, 1.0f, 0.5f, 10000.0f );
  6. m_pD3Ddev->SetTransform( D3DTS_PROJECTION, &matProj );
  7. m_pD3Ddev->SetTransform( D3DTS_VIEW,       &matView );
  8. m_pD3Ddev->SetRenderState( D3DRS_ZENABLE,  FALSE );
  9.  
  10. m_pD3Ddev->SetStreamSource(0, v_buffer, 0, sizeof(struct CUSTOMVERTEX)); // select the vertex buffer to display
  11. m_pD3Ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); // copy the vertex buffer to the back buffer
  12.  

Das Polygon bleibt einfach links/oben orthogonal sitzen...

Edit: Die Methode setTransform() im Tatnium Basehook funktioniert einfach nicht! Ich habe diese Code geschrieben und nichts wird ausgegeben:

TEXT Code:
  1.  
  2. HRESULT APIENTRY hkIDirect3DDevice9::SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX *pMatrix)
  3. {
  4.     printf("Set Transform!\n");
  5.     if (State == D3DTS_PROJECTION)
  6.     {
  7.         printf("Set Projection!\n");
  8.         return NULL;
  9.     }
  10.     return m_pD3Ddev->SetTransform(State, pMatrix);
  11.  

Weiß jemand, wie man setTransform in Tatnium funktionsfähig macht? Das wäre ultimativ.
Last edited by kung foo man (Wed 11. Sep 2013, 02:51)

Reason: no reason given

icon #8

Join Date: Aug 2007

Posts: 8646

User-Rating:

199 positive
33 negative
schau doch im Debugger wo dich dein Code hinführt, dann kannstes sicher fixen

__________________

Hallo