Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <d3d9.h>
- #include <d3dx9.h>
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- #include "detours.h"
- #pragma comment(lib, "detours.lib")
- INT SCREEN_WIDTH = 1440;
- INT SCREEN_HEIGHT = 900;
- HINSTANCE DllHandle;
- typedef HRESULT(__stdcall* endScene)(IDirect3DDevice9* pDevice);
- endScene pEndScene;
- LPD3DXFONT font;
- using namespace std;
- struct Vec3
- {
- float x, y, z;
- };
- struct Vec4
- {
- float x, y, z, w;
- };
- struct Vec2
- {
- float x, y;
- };
- float Matrix[16];
- Vec2 vScreen;
- DWORD gameModule;
- DWORD gameModuleS;
- DWORD viewMatrix = 0x5ADBF8;
- DWORD entityList = 0x4D3904;
- DWORD gameModuleEntity;
- DWORD vecOrigin = 0x260;
- DWORD localPlayer;
- DWORD healthhh = 0x94;
- DWORD iTeamNum = 0x9C;
- DWORD isdormant = 0x17E;
- DWORD dwLocalPlayer = 0xD8B2AC;
- DWORD isDormat;
- //defining our vectors
- bool WorldToScreen(Vec3 pos, Vec2& screen, float matrix[16], int windowWidth, int windowHeight)
- {
- Vec4 clipCoords;
- clipCoords.x = pos.x * matrix[0] + pos.y * matrix[1] + pos.z * matrix[2] + matrix[3];
- clipCoords.y = pos.x * matrix[4] + pos.y * matrix[5] + pos.z * matrix[6] + matrix[7];
- clipCoords.z = pos.x * matrix[8] + pos.y * matrix[9] + pos.z * matrix[10] + matrix[11];
- clipCoords.w = pos.x * matrix[12] + pos.y * matrix[13] + pos.z * matrix[14] + matrix[15];
- if (clipCoords.w < 0.1f)
- return false;
- Vec3 NDC;
- NDC.x = clipCoords.x / clipCoords.w;
- NDC.y = clipCoords.y / clipCoords.w;
- NDC.z = clipCoords.z / clipCoords.w;
- screen.x = (windowWidth / 2 * NDC.x) + (NDC.x + windowWidth / 2);
- screen.y = -(windowHeight / 2 * NDC.y) + (NDC.y + windowHeight / 2);
- return true;
- }
- void Line(float x1, float y1, float x2, float y2, float width, bool antilias, DWORD color,LPDIRECT3DDEVICE9 pDevice) {
- ID3DXLine* line;
- D3DXCreateLine(pDevice, &line);
- D3DXVECTOR2 linePos[] = { D3DXVECTOR2(x1,y1),D3DXVECTOR2(x2,y2) };
- line->SetWidth(width);
- if (antilias) {
- line->SetAntialias(antilias);
- }
- line->Begin();
- line->Draw(linePos, 2, color);
- line->End();
- line->Release();
- }
- HRESULT __stdcall hookedEndScene(IDirect3DDevice9* pDevice) {
- //now here we can create our own graphics
- int padding = 2;
- int rectx1 = 100, rectx2 = 300, recty1 = 50, recty2 = 100;
- D3DRECT rectangle = { rectx1, recty1, rectx2, recty2 };
- pDevice->Clear(1, &rectangle, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 0.0f, 0); // this draws a rectangle
- if (!font)
- D3DXCreateFont(pDevice, 16, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &font);
- RECT textRectangle;
- SetRect(&textRectangle, rectx1 + padding, recty1 + padding, rectx2 - padding, recty2 - padding);
- if (localPlayer == NULL)//checks if your local player is existant
- {
- while (localPlayer == NULL)
- {
- localPlayer = *(DWORD*)(gameModuleEntity + entityList);
- }
- }
- for (short int i = 1; i < 64; i++)
- {
- //each entity is 0x10 apart in memory
- DWORD entity = *(DWORD*)(gameModuleEntity + entityList + i * 0x10);
- if (entity != NULL)
- {
- if (entity != localPlayer)//Makes sure we dont draw on our own player
- {
- int entityTeam = *(int*)(entity + iTeamNum);
- Vec3 entityLocation = *(Vec3*)(entity + vecOrigin);
- isDormat = *(DWORD*)(entity + isdormant);
- DWORD health = *(DWORD*)(entity + healthhh);
- if (isDormat == 4294901760)//Checks if the entity is culled
- {
- if (health > 0)
- {
- if (WorldToScreen(entityLocation, vScreen, Matrix, SCREEN_WIDTH, SCREEN_HEIGHT)) {
- Line(SCREEN_WIDTH / 2, SCREEN_HEIGHT, vScreen.x, vScreen.y, 3, true, D3DCOLOR_ARGB(255, 255, 0, 255), pDevice);
- }
- }
- }
- }
- }
- }
- font->DrawText(NULL, "Stasik", -1, &textRectangle, DT_NOCLIP | DT_LEFT, D3DCOLOR_ARGB(255, 153, 255, 153)); //draw text;
- return pEndScene(pDevice); // call original endScene
- }
- void hookEndScene() {
- IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION); // create IDirect3D9 object
- if (!pD3D)
- return;
- D3DPRESENT_PARAMETERS d3dparams = { 0 };
- d3dparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dparams.hDeviceWindow = GetForegroundWindow();
- d3dparams.Windowed = true;
- IDirect3DDevice9* pDevice = nullptr;
- HRESULT result = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dparams.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dparams, &pDevice);
- if (FAILED(result) || !pDevice) {
- pD3D->Release();
- return;
- }
- //if device creation worked out -> lets get the virtual table:
- void** vTable = *reinterpret_cast<void***>(pDevice);
- //now detour:
- pEndScene = (endScene)DetourFunction((PBYTE)vTable[42], (PBYTE)hookedEndScene);
- pDevice->Release();
- pD3D->Release();
- }
- DWORD __stdcall EjectThread(LPVOID lpParameter) {
- Sleep(100);
- FreeLibraryAndExitThread(DllHandle, 0);
- return 0;
- }
- DWORD WINAPI Menue(HINSTANCE hModule) {
- AllocConsole();
- FILE* fp;
- freopen_s(&fp, "CONOUT$", "w", stdout); //sets cout to be used with our newly created console
- hookEndScene();
- gameModuleEntity = (DWORD)GetModuleHandle("client.dll");
- gameModuleS = (DWORD)GetModuleHandle("engine.dll");
- while (true) {
- memcpy(&Matrix, (PBYTE*)(gameModuleS + viewMatrix), sizeof(Matrix));
- localPlayer = *(DWORD*)(gameModuleEntity + entityList);
- if (GetAsyncKeyState(VK_F3)) {
- DetourRemove((PBYTE)pEndScene, (PBYTE)hookedEndScene); //unhook to avoid game crash
- break;
- }
- }
- std::cout << "ight imma head out" << std::endl;
- Sleep(1000);
- fclose(fp);
- FreeConsole();
- CreateThread(0, 0, EjectThread, 0, 0, 0);
- return 0;
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- DllHandle = hModule;
- CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Menue, NULL, 0, NULL);
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement