OldSchoolHack

Register / Login English

D3D-Chams Problem

icon Thread: D3D-Chams Problem

Join Date: Dec 2009

Posts: 10

Hallo liebe Forumuser,
Nachdem ich schon Probleme mit der EndScene-Funktion hatte, die ich aber erfolgreich lösen konnte, habe ich wieder ein Problem mit meinen D3D Chams .In SetStreamSource wird irgendwie nichts in m_Stride geschrieben, ich weiß aber nicht warum und ob es wirklich der Grund ist das es nicht funktioniert.  Ich hoffe jemand kann mir auf die "Sprünge" helfen

Hier der Code:
TEXT Code:
  1. #include <windows.h>
  2. #include <cstdio>
  3. #include <d3d9.h>
  4. #include <d3dx9.h>
  5. #include <iostream>
  6.  
  7. #pragma comment (lib, "user32.lib")
  8. #pragma comment (lib, "d3d9.lib")
  9. #pragma comment (lib, "d3dx9.lib")
  10.  
  11.  
  12.  
  13. //LPDIRECT3DDEVICE9 pDevice;
  14. const D3DCOLOR txtPink = D3DCOLOR_ARGB(255, 0, 0, 255); // Alpha, Rot, Grün, Blau
  15. const D3DCOLOR txtBlue = D3DCOLOR_ARGB(255, 0, 25, 255);
  16. const D3DCOLOR txtBlack = D3DCOLOR_ARGB(255,0,0,0);
  17. const D3DCOLOR txtOrange = D3DCOLOR_ARGB(200,255,128,0);
  18. LPDIRECT3DTEXTURE9 Pink;
  19. LPDIRECT3DTEXTURE9 Red;
  20. LPDIRECT3DTEXTURE9 Green;
  21.  
  22. unsigned int m_Stride;
  23. bool truecheck=true;
  24. bool truecheck2=true;
  25. bool draw=true;
  26.  
  27. void InitHook();
  28. void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
  29. void DrawRect (LPDIRECT3DDEVICE9 pDevice, int X, int Y, int L, int H, D3DCOLOR color);
  30.  
  31. typedef HRESULT (__stdcall* SetStreamSource_t)(LPDIRECT3DDEVICE9 pDevice,UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
  32. SetStreamSource_t pSetStreamSource;
  33. typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
  34. EndScene_t pEndScene;
  35. typedef HRESULT (__stdcall* DrawIndexedPrimitive_t)(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE Type,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
  36. DrawIndexedPrimitive_t pDrawIndexedPrimitive;
  37.  
  38. ID3DXFont *pFont;
  39. ID3DXFont *pFont2;
  40.  
  41.  
  42. void DrawFont (int X, int Y, D3DCOLOR Color, char *format, ...)
  43. {
  44. char buffer[256];
  45. va_list args;
  46. va_start (args, format);
  47. vsprintf (buffer,format, args);
  48. RECT FontRect = { X, Y, X + 120, Y + 16 };
  49. pFont->DrawText( NULL, buffer, -1, &FontRect, DT_NOCLIP , Color );
  50. va_end (args);
  51. }
  52.  
  53. void DrawFont2 (int X, int Y, D3DCOLOR Color, char *format, ...)
  54. {
  55. char buffer[256];
  56. va_list args;
  57. va_start (args, format);
  58. vsprintf (buffer,format, args);
  59. RECT FontRect = { X, Y, X + 120, Y + 16 };
  60. pFont2->DrawText( NULL, buffer, -1, &FontRect, DT_NOCLIP , Color );
  61. va_end (args);
  62. }
  63.  
  64.  
  65. HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32){
  66. if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED,
  67. ppD3Dtex, NULL)) )
  68. return E_FAIL;
  69. WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
  70. |(WORD)(((colour32>>20)&0xF)<<8)
  71. |(WORD)(((colour32>>12)&0xF)<<4)
  72. |(WORD)(((colour32>>4)&0xF)<<0);
  73. D3DLOCKED_RECT d3dlr;
  74. (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
  75. WORD *pDst16 = (WORD*)d3dlr.pBits;
  76. for(int xy=0; xy < 8*8; xy++)
  77. *pDst16++ = colour16;
  78. (*ppD3Dtex)->UnlockRect(0);
  79. return S_OK;
  80. }
  81.  
  82. HRESULT __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)
  83. {
  84. if(truecheck2){
  85. D3DXCreateFont(pDevice, 29, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "IrisUPC", &pFont );
  86. D3DXCreateFont(pDevice, 15, 0, FW_NORMAL, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &pFont2 );
  87. truecheck2=false;
  88. }
  89. //Das nicht ferige Menu
  90. if(draw){
  91. DrawRect (pDevice, 10, 10, 205, 75, txtBlue);
  92. DrawRect (pDevice, 15,35,195,2, txtOrange);
  93.  
  94. DrawFont(15,10,txtBlack,"SiZeXtreme VIP-Hook v0.1a");
  95. DrawFont2(15, 43, txtBlack, "WallHack (Chams)");
  96. DrawFont2(150,43,txtBlack, "False");
  97. DrawFont2(15, 58, txtBlack, "Crosshair-Hack");
  98. DrawFont2(150,58, txtBlack, "Crosshair1");
  99. }
  100. if(GetAsyncKeyState(VK_INSERT)){
  101. draw=!draw;
  102. Sleep(100);
  103. }
  104.  
  105. return pEndScene(pDevice);
  106. }
  107.  
  108.  
  109. HRESULT __stdcall hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE Type,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount){
  110. if(truecheck){
  111. GenerateTexture(pDevice, &Green,D3DCOLOR_ARGB (255 , 0 , 255 , 0 ));
  112. GenerateTexture(pDevice, &Red, D3DCOLOR_ARGB (255 , 255 , 0 , 0 ));
  113. truecheck=false;
  114. }
  115.  
  116. HRESULT hRet = pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  117. //Counterstrike Source
  118. if(m_Stride==64){
  119. pDevice->SetRenderState(D3DRS_ZENABLE,false);
  120. pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
  121. pDevice->SetTexture(0,Green);
  122. pDevice->DrawIndexedPrimitive(Type,BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  123. pDevice->SetRenderState(D3DRS_ZENABLE,true);
  124. pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
  125. pDevice->SetTexture(0,Red);
  126. //pDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); NoFog
  127. }
  128.  
  129. return pDrawIndexedPrimitive(pDevice, Type,BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  130. }
  131.  
  132.  
  133. HRESULT __stdcall hkSetStreamSource(LPDIRECT3DDEVICE9 pDevice,UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride)
  134. {
  135. if( StreamNumber == 0 ){m_Stride = Stride;}
  136.  
  137. return pSetStreamSource(pDevice, StreamNumber, pStreamData,OffsetInBytes, Stride);
  138. }
  139.  
  140.  
  141. int WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved)
  142. {
  143. switch(reason)
  144. {
  145. case DLL_PROCESS_ATTACH:
  146. CreateThread(0, 0, (LPTHREAD_START_ROUTINE) InitHook, 0, 0, 0);
  147. break;
  148. }
  149. return true;
  150. }
  151.  
  152.  
  153. bool bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
  154. {
  155. for(;*szMask;++szMask,++pData,++bMask)
  156. if(*szMask=='x' && *pData!=*bMask )
  157. return false;
  158. return (*szMask) == NULL;
  159. }
  160.  
  161.  
  162. DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
  163. {
  164. for(DWORD i=0; i < dwLen; i++)
  165. if( bDataCompare( (BYTE*)( dwAddress+i ),bMask,szMask) )
  166. return (DWORD)(dwAddress+i);
  167. return 0;
  168. }
  169.  
  170.  
  171. void InitHook()
  172. { HMODULE hModule = NULL;
  173. while( !hModule )
  174. {
  175. hModule = GetModuleHandleA( "d3d9.dll" ); // Handle zur DLL holen
  176. Sleep( 100 );
  177. }
  178. DWORD dwEndScene;
  179. DWORD dwDrawIndexedPrimitive;
  180. DWORD dwSetStreamSource;
  181. DWORD* VTableStart = 0;
  182. DWORD FoundByGordon = dwFindPattern((DWORD)hModule, 0x128000,
  183. (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
  184. memcpy(&VTableStart, (void*)(FoundByGordon+2), 4);
  185. dwDrawIndexedPrimitive = (DWORD)VTableStart[82];
  186. dwEndScene = (DWORD)VTableStart[42];
  187. dwSetStreamSource =(DWORD)VTableStart[100];
  188.  
  189.  
  190. pEndScene = ( EndScene_t )DetourFunc((PBYTE)dwEndScene,(PBYTE)hkEndScene, 5);
  191. pDrawIndexedPrimitive = ( DrawIndexedPrimitive_t )DetourFunc((PBYTE)dwDrawIndexedPrimitive, (PBYTE)hkDrawIndexedPrimitive,5);
  192. pSetStreamSource = ( SetStreamSource_t )DetourFunc((PBYTE)dwSetStreamSource,(PBYTE)hkSetStreamSource,5);
  193.  
  194. }
  195.  
  196.  
  197. void DrawRect (LPDIRECT3DDEVICE9 pDevice, int X, int Y, int L, int H, D3DCOLOR color)
  198. {
  199. D3DRECT rect = {X, Y, X+L, Y+H};
  200. pDevice->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0);
  201. }
  202.  
  203.  
  204. void *DetourFunc(BYTE *src, const BYTE *dst, const int len) // credits to gamedeception
  205. {
  206. BYTE *jmp = (BYTE*)malloc(len+5);
  207. DWORD dwback;
  208. VirtualProtect(src, len, PAGE_READWRITE, &dwback);
  209. memcpy(jmp, src, len); jmp += len;
  210. jmp[0] = 0xE9;
  211. *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
  212. src[0] = 0xE9;
  213. *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
  214. VirtualProtect(src, len, dwback, &dwback);
  215. return (jmp-5);
  216. }
  217.  
Der Stride stimmt zu 100%, da ich ihn mit einem Stride-Logger selbst geloggt habe.

Danke schonmal im vorraus

Mfg SiZeXtreme

__________________

Wer zuerst malt, malt zuerst.