Guest User

Untitled

a guest
Apr 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.92 KB | None | 0 0
  1. #include "cBase.h"
  2. #include "cDetour.h"
  3. #include "cMenu.h"
  4. #include "cHacks.h"
  5. #include "cSound.h"
  6. #include "cGuid.h"
  7. #include "cCrypt.h"
  8. #include "cPatch.h"
  9. #include <iostream>
  10. #include <fstream>
  11. #define D3DparamX , UINT paramx
  12. #define D3DparamvalX , paramx
  13. #pragma comment(lib, "d3d9.lib")
  14. #pragma comment(lib, "d3dx9.lib")
  15.  
  16. using namespace std;
  17.  
  18. cDetour *Detour;
  19. cBase Base;
  20. cMenu Menu;
  21. copt opt;
  22. cHacks Hacks;
  23. cSound Sound;
  24. cCrypt Crypt;
  25.  
  26. LPDIRECT3DTEXTURE9 texGreen, texOrange, texCyan, texRed;
  27.  
  28. bool Color = true;
  29. int Stridex = 0;
  30. int Numvertx = 0;
  31. int Primcountx = 0;
  32. int modelx = 0;
  33. int Strx = 0;
  34. int Numx = 0;
  35. int Primx = 0;
  36. static int incrementby = 1;
  37.  
  38. void PreReset( LPDIRECT3DDEVICE9 pDevice )
  39. {
  40. // Code here
  41. Menu.PreReset();
  42. return;
  43. }
  44.  
  45. void PostReset( LPDIRECT3DDEVICE9 pDevice )
  46. {
  47. // Code here
  48. Menu.PostReset(pDevice);
  49. return;
  50. }
  51.  
  52. HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
  53. {
  54. if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
  55. return E_FAIL;
  56.  
  57. WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
  58. |(WORD)(((colour32>>20)&0xF)<<8)
  59. |(WORD)(((colour32>>12)&0xF)<<4)
  60. |(WORD)(((colour32>>4)&0xF)<<0);
  61.  
  62. D3DLOCKED_RECT d3dlr;
  63. (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
  64. WORD *pDst16 = (WORD*)d3dlr.pBits;
  65.  
  66. for(int xy=0; xy < 8*8; xy++)
  67. *pDst16++ = colour16;
  68.  
  69. (*ppD3Dtex)->UnlockRect(0);
  70.  
  71. return S_OK;
  72. }
  73.  
  74. typedef HRESULT ( WINAPI* oReset )( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters );
  75. oReset pReset;
  76.  
  77. HRESULT APIENTRY myReset( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
  78. {
  79. _asm pushad;
  80. // Code here
  81. PreReset( pDevice );
  82. HRESULT hRet = pReset( pDevice, pPresentationParameters );
  83.  
  84. if( SUCCEEDED( hRet ) )
  85. {
  86. PostReset( pDevice );
  87. }
  88.  
  89. _asm popad;
  90. return hRet;
  91. }
  92.  
  93. typedef HRESULT (WINAPI* oPresent) (LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND
  94.  
  95. hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
  96. oPresent pPresent;
  97.  
  98. HRESULT APIENTRY myPresent(LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND
  99.  
  100. hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
  101. {
  102. _asm pushad;
  103. // Code here
  104. _asm popad;
  105. return pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
  106. }
  107.  
  108. typedef HRESULT ( WINAPI* oBeginScene )( LPDIRECT3DDEVICE9 pDevice );
  109. oBeginScene pBeginScene;
  110.  
  111. HRESULT APIENTRY myBeginScene( LPDIRECT3DDEVICE9 pDevice )
  112. {
  113. _asm pushad;
  114. _asm popad;
  115. return pBeginScene( pDevice );
  116. }
  117.  
  118. typedef HRESULT (WINAPI* oDrawIndexedPrimitive) (LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex,
  119.  
  120. UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);
  121. oDrawIndexedPrimitive pDrawIndexedPrimitive;
  122.  
  123. HRESULT WINAPI myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType D3DparamX ,UINT
  124.  
  125. nMinIndex, UINT nNumVertices, UINT nStartIndex, UINT nPrimitiveCount )
  126. {
  127. _asm pushad;
  128. LPDIRECT3DVERTEXBUFFER9 Stream_Data;
  129. UINT Offset = 0;
  130. UINT Stride = 0;
  131. if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
  132. Stream_Data->Release();
  133.  
  134. if(opt.logger.start){
  135. if(opt.legend.str){
  136. if(Stridex == Stride){
  137. pDevice->SetRenderState(D3DRS_ZENABLE, false);
  138. pDevice->SetTexture(0, texGreen);
  139. pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
  140. pDevice->SetTexture(0, texGreen);
  141. pDevice->SetRenderState(D3DRS_ZENABLE, true);}}
  142.  
  143. if(opt.legend.num){
  144. if(Numvertx == nNumVertices){
  145. pDevice->SetRenderState(D3DRS_ZENABLE, false);
  146. pDevice->SetTexture(0, texOrange);
  147. pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
  148. pDevice->SetTexture(0, texOrange);
  149. pDevice->SetRenderState(D3DRS_ZENABLE, true);}}
  150.  
  151. if(opt.legend.prim){
  152. if(Primcountx == nPrimitiveCount){
  153. pDevice->SetRenderState(D3DRS_ZENABLE, false);
  154. pDevice->SetTexture(0, texCyan);
  155. pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
  156. pDevice->SetTexture(0, texCyan);
  157. pDevice->SetRenderState(D3DRS_ZENABLE, true);}}}
  158. _asm popad;
  159. return pDrawIndexedPrimitive(pDevice,pType D3DparamvalX,nMinIndex,nNumVertices,nStartIndex,nPrimitiveCount);
  160. }
  161.  
  162. typedef HRESULT ( WINAPI* oEndScene )( LPDIRECT3DDEVICE9 pDevice );
  163. oEndScene pEndScene;
  164.  
  165. HRESULT APIENTRY myEndScene( LPDIRECT3DDEVICE9 pDevice )
  166. {
  167. _asm pushad;
  168. PostReset(pDevice);
  169. Menu.ShowMenu(pDevice);
  170. PreReset(pDevice);
  171. if(Color){
  172. GenerateTexture(pDevice, &texGreen , D3DCOLOR_ARGB(255,0,255,0));
  173. GenerateTexture(pDevice, &texOrange , D3DCOLOR_ARGB(255,255,165,0));
  174. GenerateTexture(pDevice, &texCyan , D3DCOLOR_ARGB(255,0,255,255));
  175. GenerateTexture(pDevice, &texRed , D3DCOLOR_ARGB(255,255,0,0));
  176. Color = false;}
  177.  
  178. if(opt.wire.str2){
  179. opt.wire.num2 = 0;
  180. opt.wire.prim2 = 0;
  181. if(GetAsyncKeyState(VK_PRIOR )&1) {Strx+=incrementby;}
  182. if(GetAsyncKeyState(VK_NEXT )&1) {Strx-=incrementby;}
  183. if(GetAsyncKeyState(VK_END )&1) {Strx = 0;}}
  184.  
  185. if(opt.wire.num2){
  186. opt.wire.str2 = 0;
  187. opt.wire.prim2 = 0;
  188. if(GetAsyncKeyState(VK_PRIOR )&1) {Numx+=incrementby;}
  189. if(GetAsyncKeyState(VK_NEXT )&1) {Numx-=incrementby;}
  190. if(GetAsyncKeyState(VK_END )&1) {Numx = 0;}}
  191.  
  192. if(opt.wire.prim2){
  193. opt.wire.str2 = 0;
  194. opt.wire.num2 = 0;
  195. if(GetAsyncKeyState(VK_PRIOR )&1) {Primx+=incrementby;}
  196. if(GetAsyncKeyState(VK_NEXT )&1) {Primx-=incrementby;}
  197. if(GetAsyncKeyState(VK_END )&1) {Primx = 0;}}
  198.  
  199. if(opt.logger.hotkey){
  200. if(GetAsyncKeyState(VK_NUMPAD4)&1) {Stridex+=incrementby;
  201. opt.legend.str = 1;
  202. opt.legend.num = 0;
  203. opt.legend.prim = 0;}
  204. if(GetAsyncKeyState(VK_NUMPAD1)&1) {Stridex-=incrementby;
  205. opt.legend.str = 1;
  206. opt.legend.num = 0;
  207. opt.legend.prim = 0;}
  208. if(GetAsyncKeyState(VK_NUMPAD7)&1) Stridex = 0;
  209.  
  210. if(GetAsyncKeyState(VK_NUMPAD5)&1) {Numvertx+=incrementby;
  211. opt.legend.str = 0;
  212. opt.legend.num = 1;
  213. opt.legend.prim = 0;}
  214. if(GetAsyncKeyState(VK_NUMPAD2)&1) {Numvertx-=incrementby;
  215. opt.legend.str = 0;
  216. opt.legend.num = 1;
  217. opt.legend.prim = 0;}
  218. if(GetAsyncKeyState(VK_NUMPAD8)&1) {Numvertx = 0;}
  219.  
  220. if(GetAsyncKeyState(VK_NUMPAD6)&1) {Primcountx+=incrementby;
  221. opt.legend.str = 0;
  222. opt.legend.num = 0;
  223. opt.legend.prim = 1;}
  224. if(GetAsyncKeyState(VK_NUMPAD3)&1) {Primcountx-=incrementby;
  225. opt.legend.str = 0;
  226. opt.legend.num = 0;
  227. opt.legend.prim = 1;}
  228. if(GetAsyncKeyState(VK_NUMPAD9)&1) {Primcountx = 0;}
  229.  
  230. if(GetAsyncKeyState(VK_SUBTRACT)&1){
  231. Stridex = 0;
  232. Numvertx = 0;
  233. Primcountx = 0;}}
  234.  
  235. if(opt.logger.log){
  236. if(GetAsyncKeyState(VK_ADD)&1){
  237. modelx +=1;
  238. Base.WriteFile(Base.LOG,"_______Model Recognition________");
  239. Base.WriteFile(Base.LOG,"_________Texture_Mode__________");
  240. Base.WriteFile(Base.LOG,"Model: %d", modelx);
  241. Base.WriteFile(Base.LOG,"Stride: %d", Stridex);
  242. Base.WriteFile(Base.LOG,"Numvert: %d", Numvertx);
  243. Base.WriteFile(Base.LOG,"Primcount: %d", Primcountx);
  244. Base.WriteFile(Base.LOG,"_______________________________");}}
  245.  
  246. opt.logger.main = 1;
  247. opt.info.main = 1;
  248. opt.options.main = 1;
  249. _asm popad;
  250. return pEndScene( pDevice );
  251. }
  252.  
  253. template <typename C,typename VF >
  254. DWORD* VirtualFuncResolver(C obj, VF fun)
  255. {
  256. DWORD ofs_vfun = (DWORD)(((*(DWORD***)((DWORD*)((DWORD)*(DWORD**)&fun + 0x8)))));
  257. if(ofs_vfun>=0xA0000000)ofs_vfun = ofs_vfun & 0xFF;
  258. DWORD adr_obj = (DWORD)(**(DWORD****)&obj);
  259. DWORD* ENTRY = (DWORD*)(*(DWORD**)(adr_obj+ofs_vfun));
  260. return ENTRY;
  261. }
  262.  
  263. DWORD* FindDevice(DWORD Base) // Credits to Croner at WarHax.com Simple Pattern Scan Function
  264. {
  265. for(long i= 0,n = 0; i < 0x128000; i++ )
  266. {
  267. if(*(BYTE *)(Base+i+0x00)==0xC7)n++;
  268. if(*(BYTE *)(Base+i+0x01)==0x06)n++;
  269. if(*(BYTE *)(Base+i+0x06)==0x89)n++;
  270. if(*(BYTE *)(Base+i+0x07)==0x86)n++;
  271. if(*(BYTE *)(Base+i+0x0C)==0x89)n++;
  272. if(*(BYTE *)(Base+i+0x0D)==0x86)n++;
  273.  
  274. if(n == 6) return (DWORD*)
  275. (Base + i + 2);n = 0;
  276. }
  277. return(0);
  278. }
  279.  
  280. typedef HRESULT ( WINAPI* oSetTransform ) (LPDIRECT3DDEVICE9 pDevice, D3DTRANSFORMSTATETYPE State, CONST
  281.  
  282. D3DMATRIX* pMatrix);
  283. oSetTransform pSetTransform;
  284.  
  285. HRESULT WINAPI mySetTransform(LPDIRECT3DDEVICE9 pDevice, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix)
  286. {
  287. // Code Here
  288. return pSetTransform(pDevice, State, pMatrix);
  289. }
  290.  
  291. int iDIRECT3D(void)
  292. {
  293.  
  294. HMODULE hD3D = NULL;
  295.  
  296. do
  297. {
  298. hD3D = GetModuleHandle("d3d9.dll");
  299. Sleep(100);
  300. }
  301. while(!hD3D);
  302.  
  303. DWORD_PTR * pDevice = FindDevice((DWORD)hD3D);
  304. DWORD_PTR * Vtable = 0;
  305. *(DWORD_PTR *)&Vtable = *(DWORD_PTR *)pDevice;
  306.  
  307. // pReset = (oReset) Detour->Create
  308.  
  309. ((PBYTE)VirtualFuncResolver(pDevice, &IDirect3DDevice9::Reset),(PBYTE)myReset,6);
  310. // pPresent = (oPresent) Detour->Create((PBYTE)
  311.  
  312. VirtualFuncResolver(pDevice, &IDirect3DDevice9::Present),(PBYTE)myPresent,6);
  313. // pBeginScene = (oBeginScene) Detour->Create((PBYTE)
  314.  
  315. VirtualFuncResolver(pDevice, &IDirect3DDevice9::BeginScene),(PBYTE)myBeginScene,6);
  316. pEndScene = (oEndScene) Detour->Create
  317.  
  318. ((PBYTE)VirtualFuncResolver(pDevice, &IDirect3DDevice9::EndScene),(PBYTE)myEndScene,DETOUR_TYPE_OBS_XOR);// this works
  319.  
  320. fine :)
  321. pDrawIndexedPrimitive = (oDrawIndexedPrimitive) Detour->Create((PBYTE)VirtualFuncResolver(pDevice,
  322.  
  323. &IDirect3DDevice9::DrawIndexedPrimitive), (PBYTE)myDrawIndexedPrimitive,DETOUR_TYPE_OBS_XOR );
  324. pSetTransform = (oSetTransform) Detour->Create((PBYTE)Vtable[37],
  325.  
  326. (PBYTE)mySetTransform,DETOUR_TYPE_OBS_XOR);
  327. return 0;
  328. }
  329.  
  330. char* cBase::GetFile(char *file)
  331. {
  332. static char path[320];
  333. for(int i= 0;i<strlen(path);i++)
  334. path[i]=0;
  335. strcpy(path, Base.dllpath);
  336. strcat(path, file);
  337. return path;
  338. }
  339.  
  340. void HackThread(void)
  341. {
  342. Hacks.HackThread();
  343. }
  344.  
  345. void cBase::WriteFile(FILE *file,const char *fmt, ...)
  346. {
  347. char buffer[225] = "";
  348. va_list va_alist;
  349. va_start (va_alist, fmt);
  350. _vsnprintf (buffer,sizeof(buffer), fmt, va_alist);
  351. fprintf(file,buffer);
  352. fprintf(file,"\n");
  353. fflush(file);
  354. va_end (va_alist);
  355. }
  356.  
  357. BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved){
  358. switch(dwReason)
  359. {
  360. case DLL_PROCESS_ATTACH:
  361. CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)iDIRECT3D, NULL, NULL, NULL);
  362. //CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)HackThread, NULL, NULL, NULL);
  363.  
  364. // Get Dll Location
  365. GetModuleFileName(hDll,Base.dllpath,512);
  366. for(int i = strlen(Base.dllpath);i > 0; i--)
  367. {
  368. if(Base.dllpath[i] == '\\')
  369. {
  370. Base.dllpath[i+1] = 0; break;
  371. }
  372. }
  373.  
  374. // Get Log File Location and Store into Class
  375. strcpy(Base.dllpath,Base.dllpath);
  376. strcpy(Base.logfile,Base.GetFile("Model_Rec_Log.txt"));
  377.  
  378. Base.LOG = fopen(Base.logfile,"w");
  379. // Basic Status Messages
  380.  
  381. break;
  382.  
  383. case DLL_PROCESS_DETACH:
  384.  
  385. break;
  386.  
  387. }
  388. return TRUE;
  389. }
Add Comment
Please, Sign In to add comment