Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "plugin.h"
- #include <d3dx8.h>
- #include "src/detours.h"
- #pragma comment(lib,"d3dx8.lib")
- using namespace plugin;
- typedef HRESULT(__stdcall* hCreateDevice)
- (
- IDirect3D8* pDirect3D, // this
- UINT Adapter,
- D3DDEVTYPE DeviceType,
- HWND hFocusWindow,
- DWORD BehaviorFlags,
- D3DPRESENT_PARAMETERS* pPresentationParameters,
- IDirect3DDevice8** ppReturnedDeviceInterface
- );
- static auto OLD_CreateDevice = (hCreateDevice)nullptr;
- class d3d8_test {
- public:
- d3d8_test()
- {
- if (AllocConsole())
- {
- freopen("CONIN$", "r", stdin);
- freopen("CONOUT$", "w", stdout);
- freopen("CONOUT$", "w", stderr);
- }
- myDevice = nullptr;
- if (GetFunctionAddress())
- {
- HookFunctions();
- }
- }
- bool GetFunctionAddress()
- {
- HMODULE lib = GetModuleHandleW(L"d3d8.dll");
- if (!lib)
- {
- lib = LoadLibraryW(L"d3d8.dll");
- if (!lib)
- {
- printf("failed to load d3d8.dll");
- return false;
- }
- }
- OLD_CreateDevice = (hCreateDevice)GetProcAddress(lib, "CreateDevice");
- if (!OLD_CreateDevice)
- {
- printf("GetProcAddress failed");
- return false;
- }
- return true;
- }
- void HookFunctions()
- {
- DetourRestoreAfterWith();
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(PVOID&)OLD_CreateDevice, NEW_CreateDevice);
- DetourTransactionCommit();
- }
- static bool NEW_CreateDevice
- (
- IDirect3D8* pDirect3D, // this
- UINT Adapter,
- D3DDEVTYPE DeviceType,
- HWND hFocusWindow,
- DWORD BehaviorFlags,
- D3DPRESENT_PARAMETERS* pPresentationParameters,
- IDirect3DDevice8** ppReturnedDeviceInterface
- )
- {
- HRESULT hr = OLD_CreateDevice(pDirect3D, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
- if (SUCCEEDED(hr))
- {
- printf("device created successfully\n");
- myDevice = *ppReturnedDeviceInterface;
- }
- else
- {
- printf("failed to create device\n");
- }
- return hr;
- }
- private:
- static IDirect3DDevice8* myDevice;
- } _d3d8_test;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement