Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma content(lib, "d3d9.lib")
- #pragma content(lib, "d3dx9.lib")
- #pragma content(lib, "detours.lib")
- #include <Windows.h>
- #include <iostream>
- #include <string>
- #include <Detours.h>
- #include <imgui.h>
- #include "imgui.h"
- #include "imgui_impl_dx9.h"
- #include "imgui_impl_win32.h"
- #include <d3d9.h>
- #include <d3dx9.h>
- typedef HRESULT(_stdcall* EndScene)(LPDIRECT3DDEVICE9 pDevice);
- HRESULT _stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice);
- EndScene oEndScene;
- LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
- IDirect3D9* g_pD3D = NULL;
- HWND window = NULL;
- BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam)
- {
- DWORD wndProcID;
- GetWindowThreadProcessId(handle, &wndProcID);
- if (GetCurrentProcessId() != wndProcID)
- {
- return TRUE;
- }
- window = handle;
- return FALSE;
- }
- HWND GetProcessWindow()
- {
- EnumWindows(EnumWindowsCallback, NULL);
- return window;
- }
- bool GetD3D9Device(void** pTable, size_t size)
- {
- if (!pTable)
- {
- return false;
- }
- g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
- if (!g_pD3D)
- {
- return false;
- }
- D3DPRESENT_PARAMETERS d3dpp = {};
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = GetProcessWindow();
- d3dpp.Windowed = false;
- g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow,
- D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice);
- if (!g_pd3dDevice)
- {
- g_pD3D->Release();
- return false;
- }
- memcpy(pTable, *reinterpret_cast<void***>(g_pd3dDevice), size);
- g_pd3dDevice->Release();
- g_pD3D->Release();
- return true;
- }
- void CleanupDeviceD3D()
- {
- if (g_pd3dDevice)
- {
- g_pd3dDevice->Release();
- g_pd3dDevice = NULL;
- }
- if (g_pD3D)
- {
- g_pD3D->Release();
- g_pD3D = NULL;
- }
- }
- HRESULT _stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)
- {
- static bool init = false;
- if (!init)
- {
- MessageBoxA(0, "Hello!", "Hello from inside endscene!)", 0);
- init = true;
- }
- return oEndScene(pDevice);
- }
- DWORD WINAPI mainThread(PVOID base)
- {
- void* d3d9Device[119];
- if (GetD3D9Device(d3d9Device, sizeof(d3d9Device)))
- {
- oEndScene = (EndScene)Detours::X86::DetourFunction((Detours::uint8_t*)d3d9Device[42], (Detours::uint8_t*)hkEndScene);
- while (true)
- {
- if (GetAsyncKeyState(VK_F10))
- {
- CleanupDeviceD3D();
- FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
- }
- }
- }
- FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
- }
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- CreateThread(nullptr, NULL, mainThread, hModule, NULL, nullptr);
- 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