Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //dllmain.cpp
- // dllmain.cpp : Defines the entry point for the DLL application.
- #include "pch.h"
- #include <iostream>
- #include <vector>
- #include "Entity.h"
- #include <d3d9.h>
- #include <d3dx9.h>
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- #include "detours.h"
- #pragma comment(lib, "detours.lib")
- HINSTANCE DllHandle;
- typedef HRESULT(__stdcall* endScene)(IDirect3DDevice9* pDevice);
- endScene pEndScene;
- LPD3DXFONT font;
- //ESP
- uintptr_t pEntityTableBase = 0x400506EC;
- std::vector<Entity*> loadEntities() {
- int failCounter = 0;
- std::vector<Entity*> entities;
- for (int i = 0; i < 9999; ++i) {
- uintptr_t pointer = *(uintptr_t*)(pEntityTableBase + 0x08 + i * 12);
- if (pointer) {
- failCounter = 0;
- Entity* entity = (Entity*)pointer;
- entities.push_back(entity);
- }
- else
- failCounter++;
- if (failCounter > 5)
- return entities;
- }
- return entities;
- }
- 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);
- font->DrawText(NULL, "Press Numpad0 to Exit", -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();
- while (true) {
- Sleep(50);
- if (GetAsyncKeyState(VK_NUMPAD0)) {
- std::vector<Entity*> entities = loadEntities();
- for (Entity* entity : entities) {
- std::cout << "position: x: " << entity->feet.x << " y:" << entity->feet.y << " z:" << entity->feet.z << std::endl;
- std::cout << "health: " << entity->health << std::endl;
- std::cout << "shield: " << entity->shield << std::endl << std::endl;
- }
- }
- if (GetAsyncKeyState(VK_NUMPAD1)) {
- DetourRemove((PBYTE)pEndScene,(PBYTE)hookedEndScene);
- 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;
- }
- //Entity.h
- #pragma once
- #include "Vector.h"
- class Entity
- {
- public:
- char pad_0000[92]; //0x0000
- Vector3 feet; //0x005C
- char pad_0068[56]; //0x0068
- Vector3 torso; //0x00A0
- char pad_00AC[52]; //0x00AC
- float health; //0x00E0
- float shield; //0x00E4
- }; //Size: 0x00E8
- //Vector.h
- #pragma once
- struct Vector2 {
- float x, y;
- };
- struct Vector3 {
- float x, y, z;
- };
- struct Vector4 {
- float x, y, z, w;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement