rdsedmundo

wall pb

Nov 27th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.29 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3.  
  4. #include "stdafx.h"
  5. #include <windows.h>
  6.  
  7. #include <d3d8.h>
  8. #pragma comment(lib, "d3d8.lib")
  9.  
  10. typedef HRESULT (WINAPI* CreateDevice_Prototype) (LPDIRECT3D8, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE8*);
  11. typedef HRESULT (WINAPI* Reset_Prototype) (LPDIRECT3DDEVICE8, D3DPRESENT_PARAMETERS*);
  12. typedef HRESULT (WINAPI* EndScene_Prototype) (LPDIRECT3DDEVICE8);
  13. typedef HRESULT (WINAPI* DrawIndexedPrimitive_Prototype)(LPDIRECT3DDEVICE8, D3DPRIMITIVETYPE, UINT, UINT, UINT, UINT);
  14.  
  15. CreateDevice_Prototype CreateDevice_Pointer = NULL;
  16. Reset_Prototype Reset_Pointer = NULL;
  17. EndScene_Prototype EndScene_Pointer = NULL;
  18. DrawIndexedPrimitive_Prototype DrawIndexedPrimitive_Pointer = NULL;
  19.  
  20. HRESULT WINAPI Direct3DCreate8_VMTable (VOID);
  21. HRESULT WINAPI CreateDevice_Detour (LPDIRECT3D8, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE8*);
  22. HRESULT WINAPI Reset_Detour (LPDIRECT3DDEVICE8, D3DPRESENT_PARAMETERS*);
  23. HRESULT WINAPI EndScene_Detour (LPDIRECT3DDEVICE8);
  24. HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE8, D3DPRIMITIVETYPE, UINT, UINT, UINT, UINT);
  25.  
  26. PDWORD Direct3D_VMTable = NULL;
  27.  
  28. BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)
  29. {
  30. if(dwReason == DLL_PROCESS_ATTACH)
  31. {
  32. DisableThreadLibraryCalls(hinstModule);
  33.  
  34. if(Direct3DCreate8_VMTable() == D3D_OK)
  35. return TRUE;
  36. }
  37.  
  38. return Sucess;
  39. }
  40.  
  41. HRESULT WINAPI Direct3DCreate8_VMTable(VOID)
  42. {
  43. LPDIRECT3D8 Direct3D_Object = Direct3DCreate8(D3D_SDK_VERSION);
  44.  
  45. if(Direct3D_Object == NULL)
  46. return D3DERR_INVALIDCALL;
  47.  
  48. Direct3D_VMTable = (PDWORD)*(PDWORD)Direct3D_Object;
  49. Direct3D_Object->Release();
  50.  
  51. DWORD dwProtect;
  52.  
  53. if(VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
  54. {
  55. *(PDWORD)&CreateDevice_Pointer = Direct3D_VMTable[15];
  56. *(PDWORD)&Direct3D_VMTable[15] = (DWORD)CreateDevice_Detour;
  57.  
  58. if(VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), dwProtect, &dwProtect) == 0)
  59. return D3DERR_INVALIDCALL;
  60. }
  61. else
  62. return D3DERR_INVALIDCALL;
  63.  
  64. return D3D_OK;
  65. }
  66.  
  67. HRESULT WINAPI CreateDevice_Detour(LPDIRECT3D8 Direct3D_Object, UINT Adapter, D3DDEVTYPE DeviceType, HWND FocusWindow,
  68. DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* PresentationParameters,
  69. LPDIRECT3DDEVICE8* Returned_Device_Interface)
  70. {
  71. HRESULT Returned_Result = CreateDevice_Pointer(Direct3D_Object, Adapter, DeviceType, FocusWindow, BehaviorFlags,
  72. PresentationParameters, Returned_Device_Interface);
  73.  
  74. DWORD dwProtect;
  75.  
  76. if(VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
  77. {
  78. *(PDWORD)&Direct3D_VMTable[15] = *(PDWORD)&CreateDevice_Pointer;
  79. CreateDevice_Pointer = NULL;
  80.  
  81. if(VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), dwProtect, &dwProtect) == 0)
  82. return D3DERR_INVALIDCALL;
  83. }
  84. else
  85. return D3DERR_VALIDCALL;
  86.  
  87. if(Returned_Result == D3D_OK)
  88. {
  89. Direct3D_VMTable = (PDWORD)*(PDWORD)*Returned_Device_Interface;
  90.  
  91. *(PDWORD)&Reset_Pointer = (DWORD)Direct3D_VMTable[14];
  92. *(PDWORD)&EndScene_Pointer = (DWORD)Direct3D_VMTable[35];
  93. *(PDWORD)&DrawIndexedPrimitive_Pointer = (DWORD)Direct3D_VMTable[71];
  94.  
  95. *(PDWORD)&Direct3D_VMTable[14] = (DWORD)End_Detour;
  96. *(PDWORD)&Direct3D_VMTable[35] = (DWORD)EndScene_Detour;
  97. *(PDWORD)&Direct3D_VMTable[71] = (DWORD)DrawIndexedPrimitive_Detour;
  98. }
  99.  
  100. return Returned_Result;
  101. }
  102.  
  103. HRESULT WINAPI Reset_Detour(LPDIRECT3DDEVICE8 Device_Interface, D3DPRESENT_PARAMETERS* PresentationParameters)
  104. {
  105. return Reset_Pointer(Device_Interface, PresentationParameters);
  106. }
  107.  
  108. HRESULT WINAPI EndScene_Detour(LPDIRECT3DDEVICE8 Device_Interface)
  109. {
  110. return EndScene_Pointer(Device_Interface);
  111. }
  112.  
  113. HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE8 Device_Interface, D3DPRIMITIVETYPE Type,
  114. UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
  115. {
  116. LPDIRECT3DVERTEXBUFFER8 Stream_Data;
  117. UINT Stride = 0;
  118.  
  119. if(Device_Interface->GetStreamSource(0, &Stream_Data, &Stride) == D3D_OK)
  120. Stream_Data->Release();
  121. //code
  122. return DrawIndexedPrimitive_Pointer(Device_Interface, Type, MinIndex, NumVertices, StartIndex, PrimitiveCount);
  123. }bool wallhack;
  124. if(Stride == 400 && wallhack || Stride == 41 && wallhack)
  125. {
  126. Device_Interface->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
  127. }if ((GetAsyncKeyState(VK_NUMPAD1)&1) == 1) //Numpad 9 F1
  128. wallhack = !wallhack;//Start Wallhack
Add Comment
Please, Sign In to add comment