Advertisement
allen343434

Untitled

Mar 23rd, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1. #include "CTools.h"
  2. #include <Subauth.h>
  3. #include <math.h>
  4.  
  5. CTools Tools;
  6.  
  7. ofstream ofile;
  8. char dlldir[320];
  9.  
  10. VOID CTools::WriteText(LPDIRECT3DDEVICE9 pDevice, INT x, INT y, DWORD color, CHAR *text)
  11. {
  12. RECT rect, rect2, rect3, rect4, rect5;
  13.  
  14. SetRect(&rect5, x + 1, y, x, y);
  15. pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
  16.  
  17. SetRect(&rect4, x - 1, y, x, y);
  18. pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
  19.  
  20. SetRect(&rect3, x, y + 1, x, y);
  21. pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
  22.  
  23. SetRect(&rect2, x, y - 1, x, y);
  24. pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
  25.  
  26. SetRect(&rect, x, y, x, y);
  27. pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, color);
  28. }
  29.  
  30. D3DXVECTOR3 CTools::GetMidPoint(D3DXVECTOR3 V1, D3DXVECTOR3 V2)
  31. {
  32. D3DXVECTOR3 Mid;
  33. Mid.x = (V1.x + V2.x) / 2;
  34. Mid.y = (V1.y + V2.y) / 2;
  35. Mid.z = (V1.z + V2.z) / 2;
  36. return Mid;
  37. }
  38.  
  39. VOID* CTools::DetourCreate(BYTE *src, CONST BYTE *dst, CONST INT len)
  40. {
  41. BYTE *jmp = (BYTE *)malloc(len + 5);
  42. DWORD dwBack;
  43.  
  44. VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
  45. memcpy(jmp, src, len);
  46. jmp += len;
  47. jmp[0] = 0xE9;
  48. *(DWORD *)(jmp + 1) = (DWORD)(src + len - jmp) - 5;
  49. src[0] = 0xE9;
  50. *(DWORD *)(src + 1) = (DWORD)(dst - src) - 5;
  51. for (INT i = 5; i < len; i++) src[i] = 0x90;
  52. VirtualProtect(src, len, dwBack, &dwBack);
  53. return(jmp - len);
  54. }
  55.  
  56. DWORD CTools::SaveBytes(DWORD TargetFunction, unsigned char *backup)
  57. {
  58. memcpy((void*)backup, (void*)TargetFunction, (size_t)5);
  59. return 0;
  60. }
  61.  
  62. DWORD CTools::RestoreBytes(DWORD TargetFunction, unsigned char *Org_Bytes)
  63. {
  64. DWORD dwOldProtection;
  65. VirtualProtect((void*)TargetFunction, 5, PAGE_EXECUTE_READWRITE, &dwOldProtection);
  66. memcpy((void*)TargetFunction, (void*)Org_Bytes, 5);
  67. return 0;
  68. }
  69.  
  70. bool CTools::bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
  71. {
  72. for (; *szMask; ++szMask, ++pData, ++bMask)
  73. {
  74. if (*szMask == 'x' && *pData != *bMask)
  75. return 0;
  76. }
  77. return (*szMask) == NULL;
  78. }
  79.  
  80. DWORD CTools::_FindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char * szMask)
  81. {
  82. for (DWORD i = 0; i<dwLen; i++)
  83. if (bCompare((BYTE*)(dwAddress + i), bMask, szMask))
  84. return (DWORD)(dwAddress + i);
  85. return 0;
  86. }
  87.  
  88. void CTools::MsgBoxAddy(DWORD addy)
  89. {
  90. char szBuffer[1024];
  91. sprintf(szBuffer, "Addy: %02x", addy);
  92. MessageBox(NULL, szBuffer, "Title", MB_OK);
  93. }
  94.  
  95. VOID WINAPI CTools::WriteMemory(LPVOID lpAddress, LPBYTE lpBuffer, DWORD dwLengh)
  96. {
  97. LPBYTE pAddress = (LPBYTE)lpAddress;
  98. LPBYTE pBuffer = (LPBYTE)lpBuffer;
  99. MEMORY_BASIC_INFORMATION MBI;
  100. VirtualQuery(lpAddress, &MBI, sizeof(MBI));
  101. VirtualProtect(MBI.BaseAddress, MBI.RegionSize, PAGE_EXECUTE_READWRITE, &MBI.Protect);
  102. while (dwLengh-- > 0)
  103. {
  104. *pAddress++ = *pBuffer++;
  105. }
  106. VirtualProtect(MBI.BaseAddress, MBI.RegionSize, MBI.Protect, &MBI.Protect);
  107. FlushInstructionCache(GetCurrentProcess(), lpAddress, dwLengh);
  108. }
  109.  
  110. VOID WINAPI CTools::WriteJump(DWORD dwFunction, DWORD dwAddress)
  111. {
  112. BYTE DetourBytes[5] = { 0xE9,0x00,0x00,0x00,0x00 };
  113. *(DWORD*)(&DetourBytes[1]) = (dwFunction - dwAddress) - 0x5;
  114. WriteMemory((LPVOID)dwAddress, (LPBYTE)DetourBytes, 5);
  115. }
  116.  
  117. MODULEINFO CTools::GetModuleInfo(char *szModule)
  118. {
  119. MODULEINFO modinfo = { 0 };
  120. HMODULE hModule = GetModuleHandle(szModule);
  121. if (hModule == 0)
  122. return modinfo;
  123. GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
  124. return modinfo;
  125. }
  126.  
  127. DWORD CTools::FindPattern(char *module, char *pattern, char *mask, DWORD position)
  128. {
  129. MODULEINFO mInfo = GetModuleInfo(module);
  130. DWORD base = (DWORD)mInfo.lpBaseOfDll;
  131. DWORD size = (DWORD)mInfo.SizeOfImage;
  132. DWORD patternLength = (DWORD)strlen(mask);
  133.  
  134. for (DWORD i = 0; i < size - patternLength; i++)
  135. {
  136. bool found = true;
  137.  
  138. for (DWORD j = 0; j < patternLength; j++)
  139. {
  140. found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
  141. }
  142.  
  143. if (found)
  144. {
  145. return base + i + position;
  146. }
  147. }
  148.  
  149. return NULL;
  150. }
  151.  
  152. DWORD CTools::D3D9VTable()
  153. {
  154. DWORD dwObjBase = (DWORD)LoadLibraryA(ed3d9);
  155. while (dwObjBase++ < dwObjBase + 0x127850)
  156. {
  157. if ((*(WORD*)(dwObjBase + 0x00)) == 0x06C7 && (*(WORD*)(dwObjBase + 0x06)) == 0x8689 && (*(WORD*)(dwObjBase + 0x0C)) == 0x8689)
  158. {
  159. dwObjBase += 2;
  160. break;
  161. }
  162. }
  163. return (dwObjBase);
  164. }
  165.  
  166. char *CTools::GetDirectoryFile(char *filename)
  167. {
  168. static char path[320];
  169. strcpy(path, dlldir);
  170. strcat(path, filename);
  171. return path;
  172. }
  173.  
  174. void __cdecl CTools::LogError(const char * fmt, ...)
  175. {
  176. va_list va_alist;
  177. char logbuf[256];
  178. FILE * fp;
  179. struct tm * current_tm;
  180. time_t current_time;
  181.  
  182. time(&current_time);
  183. current_tm = localtime(&current_time);
  184.  
  185. sprintf(logbuf, "");
  186.  
  187. va_start(va_alist, fmt);
  188. _vsnprintf(logbuf + strlen(logbuf), sizeof(logbuf) - strlen(logbuf), fmt, va_alist);
  189. va_end(va_alist);
  190.  
  191. if ((fp = fopen(GetDirectoryFile("Error.txt"), "a")) != NULL)
  192. {
  193. fprintf(fp, "%s\n", logbuf);
  194. fclose(fp);
  195. }
  196. }
  197.  
  198. VOID CTools::FillRGB(int x, int y, int w, int h, D3DCOLOR color, LPDIRECT3DDEVICE9 pDevice)
  199. {
  200. D3DRECT rec = { x, y, x + w, y + h };
  201. pDevice->Clear(1, &rec, D3DCLEAR_TARGET, color, 0, 0);
  202. return;
  203. }
  204.  
  205. VOID CTools::DrawPoint(int x, int y, int w, int h, D3DCOLOR color, LPDIRECT3DDEVICE9 pDevice)
  206. {
  207. FillRGB((int)x, (int)y, (int)w, (int)h, color, pDevice);
  208. }
  209.  
  210. VOID CTools::DrawFilledRectangle(D3DXVECTOR2 Pos, D3DXVECTOR2 Size, D3DCOLOR Color)
  211. {
  212. D3DXVECTOR2 points[2];
  213.  
  214. points[0] = Pos + D3DXVECTOR2((Size.x / 2), 0);
  215. points[1] = D3DXVECTOR2(Pos.x + (Size.x / 2), Pos.y + Size.y);
  216.  
  217. ID3DXLine *dLine = this->pLine;
  218. bool antianalias = dLine->GetAntialias();
  219. bool gllines = dLine->GetGLLines();
  220. float width = dLine->GetWidth();
  221. dLine->SetAntialias(false);
  222. dLine->SetGLLines(false);
  223. dLine->SetWidth(Size.x);
  224. dLine->Begin();
  225. dLine->Draw(points, 2, Color);
  226. dLine->End();
  227. dLine->SetAntialias(antianalias);
  228. dLine->SetGLLines(gllines);
  229. dLine->SetWidth(width);
  230. return;
  231. }
  232.  
  233. VOID CTools::DrawMouse(D3DXVECTOR2 Pos, D3DCOLOR Color)
  234. {
  235. int bList[9] = { 12,10,8,6,5,4,3,2,1 };
  236. int cList[6] = { 8,6,4,3,2,1 };
  237.  
  238. for (int i = 0; i<9; i++)
  239. this->DrawFilledRectangle(D3DXVECTOR2(Pos.x + i, Pos.y + i), D3DXVECTOR2(1, bList[i]), D3DCOLOR_RGBA(000, 000, 000, 255));
  240. for (int i = 0; i<6; i++)
  241. this->DrawFilledRectangle(D3DXVECTOR2(Pos.x + (i + 1), Pos.y + (i + 2)), D3DXVECTOR2(1, cList[i]), Color);
  242. return;
  243. }
  244.  
  245. VOID CTools::DrawCircle(D3DXVECTOR2 Pos, float Radius, int Sides, D3DCOLOR Color)
  246. {
  247. D3DXVECTOR2 Line[128];
  248. ID3DXLine *dLine = this->pLine;
  249. float Step = D3DX_PI * 2.0 / Sides;
  250. int Count = 0;
  251. for (float a = 0; a < D3DX_PI*2.0; a += Step) {
  252. float X1 = Radius * cos(a) + Pos.x;
  253. float Y1 = Radius * sin(a) + Pos.y;
  254. float X2 = Radius * cos(a + Step) + Pos.x;
  255. float Y2 = Radius * sin(a + Step) + Pos.y;
  256. Line[Count].x = X1;
  257. Line[Count].y = Y1;
  258. Line[Count + 1].x = X2;
  259. Line[Count + 1].y = Y2;
  260. Count += 2;
  261. }
  262. bool antianalias = dLine->GetAntialias();
  263. bool gllines = dLine->GetGLLines();
  264. float width = dLine->GetWidth();
  265. dLine->Begin();
  266. dLine->Draw(Line, Count, Color);
  267. dLine->End();
  268. dLine->SetAntialias(antianalias);
  269. dLine->SetGLLines(gllines);
  270. dLine->SetWidth(width);
  271. return;
  272. }
  273.  
  274. void CTools::DrawRect(IDirect3DDevice9* dev, int x, int y, int w, int h, D3DCOLOR color)
  275. {
  276. D3DRECT BarRect = { x, y, x + w, y + h };
  277. dev->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, color, 0, 0);
  278. }
  279.  
  280. void CTools::DrawLine(LPDIRECT3DDEVICE9 pDevice, float x, float y, float x2, float y2, float width, D3DCOLOR color)
  281. {
  282. ID3DXLine *dLine = this->pLine;
  283. if (dLine == NULL)
  284. {
  285. D3DXCreateLine(pDevice, &dLine);
  286. }
  287. D3DXVECTOR2 vLine[2];
  288. dLine->SetWidth(width);
  289. dLine->SetAntialias(false);
  290. dLine->SetGLLines(true);
  291. vLine[0].x = x;
  292. vLine[0].y = y;
  293. vLine[1].x = x2;
  294. vLine[1].y = y2;
  295. dLine->Begin();
  296. dLine->Draw(vLine, 2, color);
  297. dLine->End();
  298. }
  299.  
  300. void CTools::DrawHealthBar(LPDIRECT3DDEVICE9 pDevice, int x, int y, int w, int h, D3DCOLOR color, D3DCOLOR BorderColor, int hp, int maxhp)
  301. {
  302. FillRGB(x, y, (hp / (double)maxhp) * w, h, color, pDevice);
  303. DrawRect(pDevice, x, y, w, h, BorderColor);
  304. }
  305.  
  306. void CTools::LBox(IDirect3DDevice9* Device, int x, int y, int w, int h, D3DCOLOR Outline)
  307. {
  308. DrawRect(Device, x, y, w, 1, Outline);
  309. DrawRect(Device, x, y, 1, h, Outline);
  310. DrawRect(Device, x + w, y, 1, h, Outline);
  311. DrawRect(Device, x, y + h, w, 1, Outline);
  312. }
  313.  
  314. HRESULT CTools::GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
  315. {
  316. if (FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)))
  317. return E_FAIL;
  318.  
  319. WORD colour16 = ((WORD)((colour32 >> 28) & 0xF) << 12)
  320. | (WORD)(((colour32 >> 20) & 0xF) << 8)
  321. | (WORD)(((colour32 >> 12) & 0xF) << 4)
  322. | (WORD)(((colour32 >> 4) & 0xF) << 0);
  323. D3DLOCKED_RECT d3dlr;
  324. (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
  325. WORD *pDst16 = (WORD*)d3dlr.pBits;
  326. for (int xy = 0; xy < 8 * 8; xy++)
  327. *pDst16++ = colour16;
  328. (*ppD3Dtex)->UnlockRect(0);
  329. return S_OK;
  330. }
  331.  
  332. D3DXVECTOR3* CTools::W2S2(LPDIRECT3DDEVICE9 pDevice, D3DXVECTOR3 &Position)
  333. {
  334. D3DXVECTOR3 vWorldLocation = Position;
  335. D3DXVec3Project(&Position, &vWorldLocation, &viewPort, &ProjMatrix, &ViewMatrix, &Identity);
  336. return &Position;
  337. }
  338.  
  339. D3DXVECTOR3* CTools::W2S(LPDIRECT3DDEVICE9 pDevice, D3DXVECTOR3 &Position)
  340. {
  341. D3DXVECTOR3 vWorldLocation = Position;
  342. pDevice->GetTransform(D3DTS_VIEW, &ViewMatrix);
  343. pDevice->GetTransform(D3DTS_PROJECTION, &ProjMatrix);
  344. pDevice->GetTransform(D3DTS_WORLD, &WorldMatrix);
  345. pDevice->GetViewport(&viewPort);
  346.  
  347. D3DXMatrixIdentity(&Identity);
  348. D3DXVec3Project(&Position, &vWorldLocation, &viewPort, &ProjMatrix, &ViewMatrix, &Identity);
  349.  
  350. if (Position.z < 1)
  351. {
  352. return &Position;
  353. }
  354. return NULL;
  355. }
  356.  
  357. float CTools::Distance(D3DXVECTOR3 vPoint1, D3DXVECTOR3 vPoint2)
  358. {
  359. float distance = sqrtf((vPoint2.x - vPoint1.x) * (vPoint2.x - vPoint1.x) +
  360. (vPoint2.y - vPoint1.y) * (vPoint2.y - vPoint1.y) +
  361. (vPoint2.z - vPoint1.z) * (vPoint2.z - vPoint1.z));
  362.  
  363. return distance;
  364. }
  365.  
  366. BOOL CTools::CheckWindowsVersion(DWORD dwMajorVersion, DWORD dwMinorVersion, DWORD dwProductType)
  367. {
  368. OSVERSIONINFOEX VersionInfo;
  369. ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFOEX));
  370. VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
  371. GetVersionEx((OSVERSIONINFO*)&VersionInfo);
  372. if (VersionInfo.dwMajorVersion == dwMajorVersion)
  373. {
  374. if (VersionInfo.dwMinorVersion == dwMinorVersion)
  375. {
  376. if (VersionInfo.wProductType == dwProductType)
  377. {
  378. return (TRUE);
  379. }
  380. }
  381. }
  382. return (FALSE);
  383. }
  384.  
  385. void CTools::Bypass()
  386. {
  387. if (!Tools.initialize)
  388. {
  389. BYTE * pGAKS = reinterpret_cast<BYTE*>(GetAsyncKeyState);
  390. BYTE Orig[10];
  391. memcpy(Orig, pGAKS, 10);
  392.  
  393. bool bChanged = false;
  394.  
  395. while (!bChanged)
  396. {
  397. for (UINT i = 0; i != 10; ++i)
  398. if (pGAKS[i] != Orig[i])
  399. bChanged = true;
  400. Sleep(100);
  401. }
  402.  
  403. DWORD dwOld = 0;
  404. VirtualProtect(pGAKS, 10, PAGE_EXECUTE_READWRITE, &dwOld);
  405. memcpy(pGAKS, Orig, 10);
  406. VirtualProtect(pGAKS, 10, dwOld, &dwOld);
  407. Tools.initialize = 1;
  408. }
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement