Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 23rd, 2012  |  syntax: None  |  size: 6.73 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <fstream>
  4. #include "cDetours.h"
  5. #include <d3d9.h>
  6. #include <d3dx9.h>
  7. #pragma comment(lib, "d3d9.lib")
  8. #pragma comment(lib, "d3dx9.lib")
  9. /******************************************************************************/
  10. #define HOOK(func,addy) o##func = (t##func)CreateDetour((DWORD)hk##func,(DWORD)addy,Detour_Type_0xB8,7)//Quick Hook using CreateDetour *********
  11. #define UNHOOK(func,addy) o##func = (t##func)CreateDetour((DWORD)o##func,(DWORD)addy,Detour_Type_0xB8,7)//Quick Unook using CreateDetour *********
  12. /********************************************************************************/
  13. typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
  14. tEndScene oEndScene = NULL;
  15.  
  16. typedef HRESULT (WINAPI* tDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
  17. tDrawIndexedPrimitive oDrawIndexedPrimitive = NULL;
  18.  
  19. typedef HRESULT(WINAPI* tReset)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
  20. tReset oReset = NULL;
  21. /********************************************************************************/
  22. LPDIRECT3DDEVICE9 npDevice;
  23.  
  24. LPD3DXLINE g_pLine = NULL;
  25. D3DVIEWPORT9 g_ViewPort;
  26.  
  27. LPDIRECT3DVERTEXBUFFER9 Stream_Data;
  28. UINT Offset = 0;
  29. UINT Stride = 0;
  30. bool WallHack = true;
  31. bool chams = true;
  32. int m_stride;
  33.  
  34. LPDIRECT3DDEVICE9 g_pDevice = 0;
  35.  
  36. int b = 0;
  37.  
  38. LPDIRECT3DTEXTURE9 g_Blue = NULL;
  39. const BYTE Blue [60] =
  40. {
  41. 0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
  43. 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  44. 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00
  48. };
  49.  
  50. LPDIRECT3DTEXTURE9 g_Oren = NULL;
  51. const BYTE oren[ 58 ] = {
  52. 0x42, 0x4D, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
  53. 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0xFF, 0x00
  56. };
  57.  
  58. LPDIRECT3DTEXTURE9 g_Muda = NULL;
  59. const BYTE muda[60] =
  60. {
  61. 0x42, 0x4D, 0x3C, 0x00,0x00, 0x00,
  62. 0x00, 0x00, 0x00, 0x00, 0x36, 0x00,
  63. 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
  64. 0x01, 0x00, 0x00, 0x00, 0x01,0x00,
  65. 0x00, 0x00, 0x01, 0x00, 0x20, 0x00,
  66. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00,
  68. 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00,
  69. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00
  71. };
  72.  
  73. void ReFont(LPDIRECT3DDEVICE9 pDevice)
  74. {
  75. if (g_pDevice != pDevice)
  76. {
  77. g_pDevice = pDevice;
  78. }
  79. }
  80.  
  81. PBYTE HookVTableFunction( PDWORD* dwVTable, PBYTE dwHook, INT Index )
  82. {
  83. DWORD dwOld = 0;
  84. PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
  85. (*dwVTable)[Index] = (DWORD)dwHook;
  86. return pOrig;
  87. }
  88. HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
  89. {
  90.  
  91. while(!npDevice) {
  92. npDevice = pDevice;
  93. }
  94.  
  95. if(g_Oren == NULL) D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&oren, sizeof(oren), &g_Oren);
  96. if(g_Blue == NULL) D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&Blue, sizeof(Blue), &g_Blue);
  97. if(g_Muda == NULL) D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&muda, sizeof(muda), &g_Muda);
  98.  
  99. if(g_pLine == NULL) D3DXCreateLine(pDevice, &g_pLine);
  100.  
  101. pDevice->GetViewport(&g_ViewPort);
  102. if(g_Blue == NULL) D3DXCrea[Maaf Saya Kasar]xtureFromFileInMemory(pDevice, (LPCVOID)&Blue, sizeof(Blue), &g_Blue);
  103. if(g_pLine != NULL){
  104. }
  105. return oEndScene(pDevice);
  106. }
  107. HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
  108. {
  109. if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
  110. Stream_Data->Release();
  111.  
  112. if(WallHack)
  113. {
  114. if(m_stride==52)
  115. {
  116.  
  117. DWORD dwOldZEnable;
  118. pDevice-> GetRenderState (D3DRS_ZENABLE, & dwOldZEnable);
  119. pDevice-> SetRenderState (D3DRS_ZENABLE, D3DZB_FALSE);
  120. oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  121. }
  122. }
  123.  
  124. if(chams)
  125. {
  126. if(m_stride==44)
  127. {
  128. DWORD dwOldZEnable;
  129. pDevice-> GetRenderState (D3DRS_ZENABLE, & dwOldZEnable);
  130. pDevice-> SetRenderState (D3DRS_ZENABLE, D3DZB_FALSE);
  131. pDevice->SetRenderState( D3DRS_FILLMODE,D3DFILL_SOLID );
  132. pDevice->SetTexture( 0, g_Oren);
  133. oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  134. pDevice-> SetRenderState (D3DRS_ZENABLE, dwOldZEnable);
  135. }
  136. }
  137.  
  138. return oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  139.  
  140. }
  141. HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
  142. {
  143. if( g_pLine )
  144. g_pLine->OnLostDevice();
  145.  
  146. HRESULT iReturnValue = oReset(pDevice, pPresentationParameters);
  147.  
  148. if(iReturnValue == D3D_OK) {
  149.  
  150. if( g_pLine )
  151. g_pLine->OnResetDevice();
  152. }
  153. HRESULT hRet = oReset(pDevice, pPresentationParameters);
  154. return iReturnValue;
  155. }
  156. /********************************************************************************/
  157. DWORD CreateDetour(DWORD dwThread,DWORD dwAdress,DWORD dwType,DWORD dwSize)
  158. {
  159. DWORD dwDetour,dwProtect,i;
  160. if (dwAdress&&dwThread&&dwSize>= dwSize)
  161. {
  162. dwDetour = (DWORD)VirtualAlloc(0,dwSize+dwSize,0x1000,0x40);
  163. if (dwDetour&&VirtualProtect((VOID*)dwAdress,dwSize,0x40,&dwProtect))
  164. {
  165. for (i=0;i<dwSize;i++)
  166. {
  167. *(BYTE*)(dwDetour+i)=*(BYTE*)(dwAdress+i);
  168. }
  169. switch (dwType)
  170. {
  171. case Detour_Type_0xE9:
  172. {
  173. *(BYTE*)(dwDetour+dwSize+0)=0xE9;
  174. *(DWORD*)(dwDetour+dwSize+1)=(dwAdress-dwDetour-dwSize);
  175. *(BYTE*)(dwAdress+0)=0xE9;
  176. *(DWORD*)(dwAdress+1)=(dwThread-dwAdress-dwSize);
  177. }
  178. break;
  179. case Detour_Type_0xB8:
  180. {
  181. *(BYTE*)(dwDetour+dwSize+0)=0xB8;
  182. *(DWORD*)(dwDetour+dwSize+1)=(dwAdress+dwSize);
  183. *(WORD*)(dwDetour+dwSize+5)=0xE0FF;
  184. *(BYTE*)(dwAdress+0)=0xB8;
  185. *(DWORD*)(dwAdress+1)=(dwThread);
  186. *(WORD*)(dwAdress+5)=0xE0FF;
  187. }
  188. break;
  189. case Detour_Type_0x68:
  190. {
  191. *(BYTE*)(dwDetour+dwSize+0)=0x68;
  192. *(DWORD*)(dwDetour+dwSize+1)=(dwAdress+dwSize);
  193. *(WORD*)(dwDetour+dwSize+5)=0xC3;
  194. *(BYTE*)(dwAdress+0)=0x68;
  195. *(DWORD*)(dwAdress+1)=(dwThread);
  196. *(WORD*)(dwAdress+5)=0xC3;
  197. }
  198. break;
  199. }
  200. VirtualProtect((VOID*)dwAdress,dwSize,dwProtect,&dwProtect);
  201. VirtualProtect((VOID*)dwDetour,dwSize+dwSize,0x20,&dwProtect);
  202. return dwDetour;
  203. }
  204. }
  205. Sleep(15);
  206. return (0);
  207. }
  208. //------------------------- [ Hook in Here ]-------------------------//
  209. BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
  210. {
  211. if(dwReason == DLL_PROCESS_ATTACH){
  212. Beep(100,1000);
  213.  
  214. CreateThread(0, 0, LoopFunction, 0, 0, 0);
  215. }
  216. return TRUE;
  217. }