Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dllmain.cpp : Defines the entry point for the DLL application.
- #include "pch.h"
- #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")
- HINSTANCE DllHandle;
- typedef HRESULT(__stdcall* endScene)(IDirect3DDevice9* pDevice);
- endScene pEndScene;
- LPD3DXFONT font;
- 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)) {
- 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;
- }
Add Comment
Please, Sign In to add comment