Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CTools.h"
- #include <Subauth.h>
- #include <math.h>
- CTools Tools;
- ofstream ofile;
- char dlldir[320];
- VOID CTools::WriteText(LPDIRECT3DDEVICE9 pDevice, INT x, INT y, DWORD color, CHAR *text)
- {
- RECT rect, rect2, rect3, rect4, rect5;
- SetRect(&rect5, x + 1, y, x, y);
- pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
- SetRect(&rect4, x - 1, y, x, y);
- pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
- SetRect(&rect3, x, y + 1, x, y);
- pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
- SetRect(&rect2, x, y - 1, x, y);
- pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 0, 0, 0));
- SetRect(&rect, x, y, x, y);
- pFont->DrawText(NULL, text, -1, &rect, DT_NOCLIP | DT_LEFT, color);
- }
- D3DXVECTOR3 CTools::GetMidPoint(D3DXVECTOR3 V1, D3DXVECTOR3 V2)
- {
- D3DXVECTOR3 Mid;
- Mid.x = (V1.x + V2.x) / 2;
- Mid.y = (V1.y + V2.y) / 2;
- Mid.z = (V1.z + V2.z) / 2;
- return Mid;
- }
- VOID* CTools::DetourCreate(BYTE *src, CONST BYTE *dst, CONST INT len)
- {
- BYTE *jmp = (BYTE *)malloc(len + 5);
- DWORD dwBack;
- VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
- memcpy(jmp, src, len);
- jmp += len;
- jmp[0] = 0xE9;
- *(DWORD *)(jmp + 1) = (DWORD)(src + len - jmp) - 5;
- src[0] = 0xE9;
- *(DWORD *)(src + 1) = (DWORD)(dst - src) - 5;
- for (INT i = 5; i < len; i++) src[i] = 0x90;
- VirtualProtect(src, len, dwBack, &dwBack);
- return(jmp - len);
- }
- DWORD CTools::SaveBytes(DWORD TargetFunction, unsigned char *backup)
- {
- memcpy((void*)backup, (void*)TargetFunction, (size_t)5);
- return 0;
- }
- DWORD CTools::RestoreBytes(DWORD TargetFunction, unsigned char *Org_Bytes)
- {
- DWORD dwOldProtection;
- VirtualProtect((void*)TargetFunction, 5, PAGE_EXECUTE_READWRITE, &dwOldProtection);
- memcpy((void*)TargetFunction, (void*)Org_Bytes, 5);
- return 0;
- }
- bool CTools::bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
- {
- for (; *szMask; ++szMask, ++pData, ++bMask)
- {
- if (*szMask == 'x' && *pData != *bMask)
- return 0;
- }
- return (*szMask) == NULL;
- }
- DWORD CTools::_FindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char * szMask)
- {
- for (DWORD i = 0; i<dwLen; i++)
- if (bCompare((BYTE*)(dwAddress + i), bMask, szMask))
- return (DWORD)(dwAddress + i);
- return 0;
- }
- void CTools::MsgBoxAddy(DWORD addy)
- {
- char szBuffer[1024];
- sprintf(szBuffer, "Addy: %02x", addy);
- MessageBox(NULL, szBuffer, "Title", MB_OK);
- }
- VOID WINAPI CTools::WriteMemory(LPVOID lpAddress, LPBYTE lpBuffer, DWORD dwLengh)
- {
- LPBYTE pAddress = (LPBYTE)lpAddress;
- LPBYTE pBuffer = (LPBYTE)lpBuffer;
- MEMORY_BASIC_INFORMATION MBI;
- VirtualQuery(lpAddress, &MBI, sizeof(MBI));
- VirtualProtect(MBI.BaseAddress, MBI.RegionSize, PAGE_EXECUTE_READWRITE, &MBI.Protect);
- while (dwLengh-- > 0)
- {
- *pAddress++ = *pBuffer++;
- }
- VirtualProtect(MBI.BaseAddress, MBI.RegionSize, MBI.Protect, &MBI.Protect);
- FlushInstructionCache(GetCurrentProcess(), lpAddress, dwLengh);
- }
- VOID WINAPI CTools::WriteJump(DWORD dwFunction, DWORD dwAddress)
- {
- BYTE DetourBytes[5] = { 0xE9,0x00,0x00,0x00,0x00 };
- *(DWORD*)(&DetourBytes[1]) = (dwFunction - dwAddress) - 0x5;
- WriteMemory((LPVOID)dwAddress, (LPBYTE)DetourBytes, 5);
- }
- MODULEINFO CTools::GetModuleInfo(char *szModule)
- {
- MODULEINFO modinfo = { 0 };
- HMODULE hModule = GetModuleHandle(szModule);
- if (hModule == 0)
- return modinfo;
- GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
- return modinfo;
- }
- DWORD CTools::FindPattern(char *module, char *pattern, char *mask, DWORD position)
- {
- MODULEINFO mInfo = GetModuleInfo(module);
- DWORD base = (DWORD)mInfo.lpBaseOfDll;
- DWORD size = (DWORD)mInfo.SizeOfImage;
- DWORD patternLength = (DWORD)strlen(mask);
- for (DWORD i = 0; i < size - patternLength; i++)
- {
- bool found = true;
- for (DWORD j = 0; j < patternLength; j++)
- {
- found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
- }
- if (found)
- {
- return base + i + position;
- }
- }
- return NULL;
- }
- DWORD CTools::D3D9VTable()
- {
- DWORD dwObjBase = (DWORD)LoadLibraryA(ed3d9);
- while (dwObjBase++ < dwObjBase + 0x127850)
- {
- if ((*(WORD*)(dwObjBase + 0x00)) == 0x06C7 && (*(WORD*)(dwObjBase + 0x06)) == 0x8689 && (*(WORD*)(dwObjBase + 0x0C)) == 0x8689)
- {
- dwObjBase += 2;
- break;
- }
- }
- return (dwObjBase);
- }
- char *CTools::GetDirectoryFile(char *filename)
- {
- static char path[320];
- strcpy(path, dlldir);
- strcat(path, filename);
- return path;
- }
- void __cdecl CTools::LogError(const char * fmt, ...)
- {
- va_list va_alist;
- char logbuf[256];
- FILE * fp;
- struct tm * current_tm;
- time_t current_time;
- time(¤t_time);
- current_tm = localtime(¤t_time);
- sprintf(logbuf, "");
- va_start(va_alist, fmt);
- _vsnprintf(logbuf + strlen(logbuf), sizeof(logbuf) - strlen(logbuf), fmt, va_alist);
- va_end(va_alist);
- if ((fp = fopen(GetDirectoryFile("Error.txt"), "a")) != NULL)
- {
- fprintf(fp, "%s\n", logbuf);
- fclose(fp);
- }
- }
- VOID CTools::FillRGB(int x, int y, int w, int h, D3DCOLOR color, LPDIRECT3DDEVICE9 pDevice)
- {
- D3DRECT rec = { x, y, x + w, y + h };
- pDevice->Clear(1, &rec, D3DCLEAR_TARGET, color, 0, 0);
- return;
- }
- VOID CTools::DrawPoint(int x, int y, int w, int h, D3DCOLOR color, LPDIRECT3DDEVICE9 pDevice)
- {
- FillRGB((int)x, (int)y, (int)w, (int)h, color, pDevice);
- }
- VOID CTools::DrawFilledRectangle(D3DXVECTOR2 Pos, D3DXVECTOR2 Size, D3DCOLOR Color)
- {
- D3DXVECTOR2 points[2];
- points[0] = Pos + D3DXVECTOR2((Size.x / 2), 0);
- points[1] = D3DXVECTOR2(Pos.x + (Size.x / 2), Pos.y + Size.y);
- ID3DXLine *dLine = this->pLine;
- bool antianalias = dLine->GetAntialias();
- bool gllines = dLine->GetGLLines();
- float width = dLine->GetWidth();
- dLine->SetAntialias(false);
- dLine->SetGLLines(false);
- dLine->SetWidth(Size.x);
- dLine->Begin();
- dLine->Draw(points, 2, Color);
- dLine->End();
- dLine->SetAntialias(antianalias);
- dLine->SetGLLines(gllines);
- dLine->SetWidth(width);
- return;
- }
- VOID CTools::DrawMouse(D3DXVECTOR2 Pos, D3DCOLOR Color)
- {
- int bList[9] = { 12,10,8,6,5,4,3,2,1 };
- int cList[6] = { 8,6,4,3,2,1 };
- for (int i = 0; i<9; i++)
- this->DrawFilledRectangle(D3DXVECTOR2(Pos.x + i, Pos.y + i), D3DXVECTOR2(1, bList[i]), D3DCOLOR_RGBA(000, 000, 000, 255));
- for (int i = 0; i<6; i++)
- this->DrawFilledRectangle(D3DXVECTOR2(Pos.x + (i + 1), Pos.y + (i + 2)), D3DXVECTOR2(1, cList[i]), Color);
- return;
- }
- VOID CTools::DrawCircle(D3DXVECTOR2 Pos, float Radius, int Sides, D3DCOLOR Color)
- {
- D3DXVECTOR2 Line[128];
- ID3DXLine *dLine = this->pLine;
- float Step = D3DX_PI * 2.0 / Sides;
- int Count = 0;
- for (float a = 0; a < D3DX_PI*2.0; a += Step) {
- float X1 = Radius * cos(a) + Pos.x;
- float Y1 = Radius * sin(a) + Pos.y;
- float X2 = Radius * cos(a + Step) + Pos.x;
- float Y2 = Radius * sin(a + Step) + Pos.y;
- Line[Count].x = X1;
- Line[Count].y = Y1;
- Line[Count + 1].x = X2;
- Line[Count + 1].y = Y2;
- Count += 2;
- }
- bool antianalias = dLine->GetAntialias();
- bool gllines = dLine->GetGLLines();
- float width = dLine->GetWidth();
- dLine->Begin();
- dLine->Draw(Line, Count, Color);
- dLine->End();
- dLine->SetAntialias(antianalias);
- dLine->SetGLLines(gllines);
- dLine->SetWidth(width);
- return;
- }
- void CTools::DrawRect(IDirect3DDevice9* dev, int x, int y, int w, int h, D3DCOLOR color)
- {
- D3DRECT BarRect = { x, y, x + w, y + h };
- dev->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, color, 0, 0);
- }
- void CTools::DrawLine(LPDIRECT3DDEVICE9 pDevice, float x, float y, float x2, float y2, float width, D3DCOLOR color)
- {
- ID3DXLine *dLine = this->pLine;
- if (dLine == NULL)
- {
- D3DXCreateLine(pDevice, &dLine);
- }
- D3DXVECTOR2 vLine[2];
- dLine->SetWidth(width);
- dLine->SetAntialias(false);
- dLine->SetGLLines(true);
- vLine[0].x = x;
- vLine[0].y = y;
- vLine[1].x = x2;
- vLine[1].y = y2;
- dLine->Begin();
- dLine->Draw(vLine, 2, color);
- dLine->End();
- }
- void CTools::DrawHealthBar(LPDIRECT3DDEVICE9 pDevice, int x, int y, int w, int h, D3DCOLOR color, D3DCOLOR BorderColor, int hp, int maxhp)
- {
- FillRGB(x, y, (hp / (double)maxhp) * w, h, color, pDevice);
- DrawRect(pDevice, x, y, w, h, BorderColor);
- }
- void CTools::LBox(IDirect3DDevice9* Device, int x, int y, int w, int h, D3DCOLOR Outline)
- {
- DrawRect(Device, x, y, w, 1, Outline);
- DrawRect(Device, x, y, 1, h, Outline);
- DrawRect(Device, x + w, y, 1, h, Outline);
- DrawRect(Device, x, y + h, w, 1, Outline);
- }
- HRESULT CTools::GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
- {
- if (FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)))
- return E_FAIL;
- WORD colour16 = ((WORD)((colour32 >> 28) & 0xF) << 12)
- | (WORD)(((colour32 >> 20) & 0xF) << 8)
- | (WORD)(((colour32 >> 12) & 0xF) << 4)
- | (WORD)(((colour32 >> 4) & 0xF) << 0);
- D3DLOCKED_RECT d3dlr;
- (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
- WORD *pDst16 = (WORD*)d3dlr.pBits;
- for (int xy = 0; xy < 8 * 8; xy++)
- *pDst16++ = colour16;
- (*ppD3Dtex)->UnlockRect(0);
- return S_OK;
- }
- D3DXVECTOR3* CTools::W2S2(LPDIRECT3DDEVICE9 pDevice, D3DXVECTOR3 &Position)
- {
- D3DXVECTOR3 vWorldLocation = Position;
- D3DXVec3Project(&Position, &vWorldLocation, &viewPort, &ProjMatrix, &ViewMatrix, &Identity);
- return &Position;
- }
- D3DXVECTOR3* CTools::W2S(LPDIRECT3DDEVICE9 pDevice, D3DXVECTOR3 &Position)
- {
- D3DXVECTOR3 vWorldLocation = Position;
- pDevice->GetTransform(D3DTS_VIEW, &ViewMatrix);
- pDevice->GetTransform(D3DTS_PROJECTION, &ProjMatrix);
- pDevice->GetTransform(D3DTS_WORLD, &WorldMatrix);
- pDevice->GetViewport(&viewPort);
- D3DXMatrixIdentity(&Identity);
- D3DXVec3Project(&Position, &vWorldLocation, &viewPort, &ProjMatrix, &ViewMatrix, &Identity);
- if (Position.z < 1)
- {
- return &Position;
- }
- return NULL;
- }
- float CTools::Distance(D3DXVECTOR3 vPoint1, D3DXVECTOR3 vPoint2)
- {
- float distance = sqrtf((vPoint2.x - vPoint1.x) * (vPoint2.x - vPoint1.x) +
- (vPoint2.y - vPoint1.y) * (vPoint2.y - vPoint1.y) +
- (vPoint2.z - vPoint1.z) * (vPoint2.z - vPoint1.z));
- return distance;
- }
- BOOL CTools::CheckWindowsVersion(DWORD dwMajorVersion, DWORD dwMinorVersion, DWORD dwProductType)
- {
- OSVERSIONINFOEX VersionInfo;
- ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFOEX));
- VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
- GetVersionEx((OSVERSIONINFO*)&VersionInfo);
- if (VersionInfo.dwMajorVersion == dwMajorVersion)
- {
- if (VersionInfo.dwMinorVersion == dwMinorVersion)
- {
- if (VersionInfo.wProductType == dwProductType)
- {
- return (TRUE);
- }
- }
- }
- return (FALSE);
- }
- void CTools::Bypass()
- {
- if (!Tools.initialize)
- {
- BYTE * pGAKS = reinterpret_cast<BYTE*>(GetAsyncKeyState);
- BYTE Orig[10];
- memcpy(Orig, pGAKS, 10);
- bool bChanged = false;
- while (!bChanged)
- {
- for (UINT i = 0; i != 10; ++i)
- if (pGAKS[i] != Orig[i])
- bChanged = true;
- Sleep(100);
- }
- DWORD dwOld = 0;
- VirtualProtect(pGAKS, 10, PAGE_EXECUTE_READWRITE, &dwOld);
- memcpy(pGAKS, Orig, 10);
- VirtualProtect(pGAKS, 10, dwOld, &dwOld);
- Tools.initialize = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement