OldSchoolHack

Register / Login English

CSSTriggerbot

icon Thread: [Release] CSSTriggerbot

Join Date: Aug 2007

Posts: 8643

User-Rating:

199 positive
33 negative
CPP Code:
  1. //---------------------------------------------------------------------------------------------------------------------------------
  2. // File: main.cpp
  3. //---------------------------------------------------------------------------------------------------------------------------------
  4. #include <windows.h>
  5. #include <assert.h>
  6. #include <iostream>
  7. #include <d3d9.h>
  8. #include <d3dx9.h>
  9. #include <detours.h>
  10. #pragma comment (lib, "d3dx9.lib")
  11. #pragma comment (lib, "d3d9.lib")
  12. #pragma comment( lib, "winmm.lib" )
  13.  
  14. //---------------------------------------------------------------------------------------------------------------------------------
  15. using namespace std;
  16. //---------------------------------------------------------------------------------------------------------------------------------
  17. #define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func)
  18. #define ES 0
  19. #define DIP 1
  20. #define RES 2
  21.  
  22. #define Terrorist (( NumVertices == 1588 && primCount == 2013 ) || ( NumVertices == 911 && primCount == 996 ) || ( NumVertices == 526 && primCount == 594 ) || ( NumVertices == 389 && primCount == 386 ) || ( NumVertices == 1510 && primCount == 1871 ) || ( NumVertices == 873 && primCount == 986 ) || ( NumVertices == 563 && primCount == 590 ) || ( NumVertices == 368 && primCount == 377 ) || ( NumVertices == 1311 && primCount == 1812 ) || ( NumVertices == 735 && primCount == 899 ) || ( NumVertices == 454 && primCount == 519 ) || ( NumVertices == 323 && primCount == 338 ) || ( NumVertices == 1488 && primCount == 1819 ) || ( NumVertices == 835 && primCount == 899 ) || ( NumVertices == 554 && primCount == 509 ) || ( NumVertices == 408 && primCount == 344 ))
  23. #define CounterTerrorist (( NumVertices == 1609 && primCount == 1794 ) || ( NumVertices == 899 && primCount == 910 ) || ( NumVertices == 513 && primCount == 451 ) || ( NumVertices == 369 && primCount == 297 ) || ( NumVertices == 1424 && primCount == 1858 ) || ( NumVertices == 814 && primCount == 945 ) || ( NumVertices == 475 && primCount == 510 ) || ( NumVertices == 343 && primCount == 344 ) || ( NumVertices == 1498 && primCount == 1822 ) || ( NumVertices == 929 && primCount == 1007 ) || ( NumVertices == 499 && primCount == 533 ) || ( NumVertices == 409 && primCount == 433 ) || ( NumVertices == 1404 && primCount == 1919 ) || ( NumVertices == 811 && primCount == 989 ) || ( NumVertices == 466 && primCount == 550 ) || ( NumVertices == 324 && primCount == 372 ))
  24.  
  25. //---------------------------------------------------------------------------------------------------------------------------------
  26. typedef HRESULT (WINAPI* tReset)( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters );
  27. tReset oReset;
  28. typedef HRESULT (WINAPI* tEndScene)( LPDIRECT3DDEVICE9 pDevice );
  29. tEndScene oEndScene;
  30. typedef HRESULT (WINAPI* tDrawIndexedPrimitive)( LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount );
  31. tDrawIndexedPrimitive oDrawIndexedPrimitive;
  32. #define SAFE_RELEASE(x) if (x) { x->Release(); x = NULL; }
  33. LPDIRECT3DPIXELSHADER9 sGreen, sRed, sBlue,sYellow;
  34. LPDIRECT3DSURFACE9 pBackBuffer = NULL;
  35. LPDIRECT3DSURFACE9 pSurface = NULL;
  36. LPDIRECT3DDEVICE9 pd3dDevice;
  37. D3DVIEWPORT9 pViewport;
  38. D3DLOCKED_RECT pLockedRect;
  39. D3DCOLOR myColor;
  40. DWORD gametick = timeGetTime();
  41.  
  42. //---------------------------------------------------------------------------------------------------------------------------------
  43. HRESULT PixelGetColor( D3DCOLOR *color, int x, int y )
  44. {
  45. BYTE red, green, blue;
  46. if(pSurface==NULL) pd3dDevice->CreateOffscreenPlainSurface( pViewport.Width, pViewport.Height,
  47. D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pSurface, NULL );
  48. pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
  49. pd3dDevice->GetRenderTargetData( pBackBuffer, pSurface );
  50. pSurface->LockRect(&pLockedRect,0,D3DLOCK_READONLY);
  51. BYTE *pBits = (BYTE*)pLockedRect.pBits;
  52. blue = pBits[y*pLockedRect.Pitch+x*4];
  53. green = pBits[y*pLockedRect.Pitch+x*4+1];
  54. red = pBits[y*pLockedRect.Pitch+x*4+2];
  55. *color = D3DCOLOR_XRGB(red, green, blue);
  56. pSurface->UnlockRect();
  57. SAFE_RELEASE(pSurface);
  58. return S_OK;
  59. }
  60.  
  61. //-----------------------------------------------------------------------------------------------------------------------------------
  62. HRESULT CreateMyShader(IDirect3DDevice9 *pD3Ddev, IDirect3DPixelShader9 **pShader, float r, float g, float b)
  63. {
  64. char szShader[ 256 ];
  65. ID3DXBuffer *pShaderBuf = NULL;
  66. sprintf_s( szShader, "ps.1.1\ndef c0, %f, %f, %f, %f\nmov r0,c0", r, g, b, 1.0f );
  67. D3DXAssembleShader( szShader, (strlen(szShader)+1), NULL, NULL, 0, &pShaderBuf, NULL );
  68. if( FAILED( pD3Ddev->CreatePixelShader((const DWORD*)pShaderBuf->GetBufferPointer(), pShader)) )return E_FAIL;
  69. return S_OK;
  70. }
  71.  
  72. //---------------------------------------------------------------------------------------------------------------------------------
  73. bool bInitShaders = false;
  74. HRESULT WINAPI hkEndScene( LPDIRECT3DDEVICE9 pDevice )
  75. {
  76. HRESULT hRet = oEndScene( pDevice );
  77. if (pd3dDevice == NULL){
  78. pd3dDevice = pDevice;
  79. }
  80. if( bInitShaders == false )
  81. {
  82. CreateMyShader(pDevice, &sBlue, 0, 0, 255);
  83. CreateMyShader(pDevice, &sGreen, 0, 255, 0);
  84. CreateMyShader(pDevice, &sRed, 255, 0, 0);
  85. CreateMyShader(pDevice, &sYellow, 255, 255, 0);
  86. bInitShaders = true;
  87. }
  88.  
  89. pDevice->GetViewport( &pViewport );
  90. if ( timeGetTime() - gametick > 100 )
  91. {
  92. PixelGetColor( &myColor, pViewport.Width/2, pViewport.Height/2 );
  93. gametick = timeGetTime();
  94. }
  95. if (myColor == 0xFF00FF00){
  96. mouse_event( MOUSEEVENTF_LEFTDOWN,0,0,NULL,NULL );
  97. if (GetAsyncKeyState(VK_LBUTTON) < 0)
  98. mouse_event( MOUSEEVENTF_LEFTUP,0,0,NULL,NULL );
  99. }
  100. if (myColor == 0xFFFFFF00){
  101. mouse_event( MOUSEEVENTF_LEFTDOWN,0,0,NULL,NULL );
  102. if (GetAsyncKeyState(VK_LBUTTON) < 0)
  103. mouse_event( MOUSEEVENTF_LEFTUP,0,0,NULL,NULL );
  104. }
  105. return hRet;
  106. }
  107.  
  108. //---------------------------------------------------------------------------------------------------------------------------------
  109. HRESULT WINAPI hkDrawIndexedPrimitive( LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount )
  110. {
  111. HRESULT hRet = oDrawIndexedPrimitive( pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount );
  112. LPDIRECT3DPIXELSHADER9 pShader = NULL;
  113. LPDIRECT3DVERTEXBUFFER9 Stream_Data;
  114. UINT Offset = 0;
  115. UINT Stride = 0;
  116. if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
  117. Stream_Data->Release();
  118. if (CounterTerrorist)
  119. {
  120. pDevice->SetPixelShader(sGreen);
  121. pDevice->SetRenderState(D3DRS_ZENABLE,false);
  122. oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  123. pDevice->SetRenderState(D3DRS_ZENABLE,true);
  124. oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  125. }
  126. if (Terrorist)
  127. {
  128. pDevice->SetPixelShader(sYellow);
  129. pDevice->SetRenderState(D3DRS_ZENABLE,false);
  130. oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  131. pDevice->SetRenderState(D3DRS_ZENABLE,true);
  132. oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  133. }
  134. return hRet;
  135. }
  136.  
  137. //---------------------------------------------------------------------------------------------------------------------------------
  138. HRESULT WINAPI hkReset( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
  139. {
  140. HRESULT hRet = oReset( pDevice, pPresentationParameters );
  141. myColor = 0x00;
  142. return hRet;
  143. }
  144.  
  145. //---------------------------------------------------------------------------------------------------------------------------------
  146. LRESULT CALLBACK MsgProc( HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){return DefWindowProc(hwnd, uMsg, wParam, lParam );}
  147. void InitD3D( DWORD* table )
  148. {
  149. WNDCLASSEX wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,L"DX",NULL};
  150. RegisterClassEx( &wc );
  151. HWND hWnd = CreateWindow( L"DX",NULL,WS_OVERLAPPEDWINDOW,100,100,300,300,GetDesktopWindow(),NULL,wc.hInstance,NULL );
  152. LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION );
  153. D3DPRESENT_PARAMETERS d3dpp;
  154. ZeroMemory( &d3dpp, sizeof(d3dpp) );
  155. d3dpp.Windowed = TRUE;
  156. d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  157. d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
  158. LPDIRECT3DDEVICE9 pd3dDevice;
  159. pD3D->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice );
  160. DWORD* pVTable = (DWORD*)pd3dDevice;
  161. pVTable = (DWORD*)pVTable[0];
  162. table[ES] = pVTable[42];
  163. table[DIP] = pVTable[82];
  164. table[RES] = pVTable[16];
  165. DestroyWindow( hWnd );
  166. }
  167.  
  168. //---------------------------------------------------------------------------------------------------------------------------------
  169. DWORD WINAPI MyThread( LPVOID )
  170. {
  171. DWORD VTable[3] = {0};
  172. while( GetModuleHandle(L"d3d9.dll")==NULL ){
  173. Sleep( 250 );
  174. }
  175. InitD3D( VTable );
  176. HOOK( EndScene,VTable[ES] );
  177. HOOK( DrawIndexedPrimitive,VTable[DIP] );
  178. HOOK( Reset,VTable[RES] );
  179. return 0;
  180. }
  181.  
  182. //---------------------------------------------------------------------------------------------------------------------------------
  183. BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
  184. {
  185. if( dwReason == DLL_PROCESS_ATTACH ){
  186. CreateThread( 0,0,MyThread,0,0,0 );
  187. }
  188. return TRUE;
  189. }

Credits:
by myself /SirHackAlot[SOH]

Thanks:
UnKnoWnCheaTs Tutorials
gamedev.net Tutorials
MSDN References
Autoit Getpixel/PixelSearch Sourcecode
AutoHotKey MouseClick Sourcecode

Special Thanks:
[UC]JoshRose...etc vTable D3D9 base
[UC]Strife Modelrec logger
[UC]CallMeEclipse Pixelshaders
[SOH]Zoom D3DAimbot2013
[AutoIt]shanesloan Triggerbot
Download CSSTriggerbot

__________________

Hallo