Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================
- //defs.def (to give the exports the correct name and ordinals)
- EXPORTS
- D3DPERF_BeginEvent=__E__0__ @1
- D3DPERF_EndEvent=__E__1__ @2
- D3DPERF_GetStatus=__E__2__ @3
- D3DPERF_QueryRepeatFrame=__E__3__ @4
- D3DPERF_SetMarker=__E__4__ @5
- D3DPERF_SetOptions=__E__5__ @6
- D3DPERF_SetRegion=__E__6__ @7
- Direct3DCreate9=__E__7__ @8
- //=============================
- //dllmain.cpp (where the stuff is done)
- #include <windows.h>
- #include <windowsx.h>
- #include <d3d9.h>
- #include "stdafx.h"
- #include <stdio.h>
- #include <string.h>
- #pragma comment(lib, "detours.lib")
- #include <detours.h>
- #pragma pack(1)
- HINSTANCE hLThis = 0;
- HINSTANCE hL = 0;
- FARPROC p[8] = {0};
- typedef IDirect3D9 *(WINAPI* D3D9_Type)(UINT SDKVersion);
- typedef HRESULT (WINAPI*D3D9_CreateDevice) (int *lixo,UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,
- D3DPRESENT_PARAMETERS *pPresentationParameters,
- IDirect3DDevice9 **ppReturnedDeviceInterface);
- D3D9_Type D3DCreate9_fn;
- D3D9_CreateDevice CreateDevice_Real;
- BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID)
- {
- if (reason == DLL_PROCESS_ATTACH)
- {
- hLThis = hInst;
- char pasta_w[256];
- GetSystemDirectoryA(pasta_w,256);
- strcat(pasta_w,"\\d3d9.dll");
- hL = LoadLibraryA(pasta_w);
- if (!hL) return false;
- p[0] = GetProcAddress(hL,"D3DPERF_BeginEvent");
- p[1] = GetProcAddress(hL,"D3DPERF_EndEvent");
- p[2] = GetProcAddress(hL,"D3DPERF_GetStatus");
- p[3] = GetProcAddress(hL,"D3DPERF_QueryRepeatFrame");
- p[4] = GetProcAddress(hL,"D3DPERF_SetMarker");
- p[5] = GetProcAddress(hL,"D3DPERF_SetOptions");
- p[6] = GetProcAddress(hL,"D3DPERF_SetRegion");
- p[7] = GetProcAddress(hL,"Direct3DCreate9");
- D3DCreate9_fn = (D3D9_Type) GetProcAddress(hL, "Direct3DCreate9");
- }
- if (reason == DLL_PROCESS_DETACH)
- {
- FreeLibrary(hL);
- }
- return 1;
- }
- // D3DPERF_BeginEvent
- extern "C" __declspec(naked) void __stdcall __E__0__()
- {
- __asm
- {
- jmp p[0*4];
- }
- }
- // D3DPERF_EndEvent
- extern "C" __declspec(naked) void __stdcall __E__1__()
- {
- __asm
- {
- jmp p[1*4];
- }
- }
- // D3DPERF_GetStatus
- extern "C" __declspec(naked) void __stdcall __E__2__()
- {
- __asm
- {
- jmp p[2*4];
- }
- }
- // D3DPERF_QueryRepeatFrame
- extern "C" __declspec(naked) void __stdcall __E__3__()
- {
- __asm
- {
- jmp p[3*4];
- }
- }
- // D3DPERF_SetMarker
- extern "C" __declspec(naked) void __stdcall __E__4__()
- {
- __asm
- {
- jmp p[4*4];
- }
- }
- // D3DPERF_SetOptions
- extern "C" __declspec(naked) void __stdcall __E__5__()
- {
- __asm
- {
- jmp p[5*4];
- }
- }
- // D3DPERF_SetRegion
- extern "C" __declspec(naked) void __stdcall __E__6__()
- {
- __asm
- {
- jmp p[6*4];
- }
- }
- HRESULT CreateDevice_alt___(UINT Adapter, D3DDEVTYPE DeviceType,HWND hFocusWindow, DWORD BehaviorFlags,D3DPRESENT_PARAMETERS *pPresentationParameters,IDirect3DDevice9 **ppReturnedDeviceInterface)
- {
- /*
- IDirect3DDevice9* pDirect3DDevice9;
- HRESULT hRes = Direct3D9->CreateDevice( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, &pDirect3DDevice9 );
- *ppReturnedDeviceInterface = new Direct3DDevice9Wrapper( pDirect3DDevice9, this, pPresentationParameters );
- return hRes;
- */
- return 0;
- }
- HRESULT __stdcall CreateDevice_alt(int *Lixo,
- UINT Adapter,//0=primera gpu?
- D3DDEVTYPE DeviceType,//1=hal
- HWND hFocusWindow,//é uma janela
- DWORD BehaviorFlags,
- D3DPRESENT_PARAMETERS *pPresentationParameters,
- IDirect3DDevice9 **ppReturnedDeviceInterface)
- {
- RECT res;
- char podre[256];
- GetWindowRect(GetDesktopWindow(),&res);
- //the "fix" for the device creation
- pPresentationParameters->Windowed=false;
- pPresentationParameters->BackBufferWidth=res.right;
- pPresentationParameters->BackBufferHeight=res.bottom;
- sprintf(podre,"Windowed: %s\nRes:%d,%d\nBbufferCnt:%d\nMSAA type:%d quality:%d\nSwapEffect:%d",
- (pPresentationParameters->Windowed)?"true":"false",
- pPresentationParameters->BackBufferWidth,
- pPresentationParameters->BackBufferHeight,
- pPresentationParameters->BackBufferCount,
- pPresentationParameters->MultiSampleType,
- pPresentationParameters->MultiSampleQuality,
- pPresentationParameters->SwapEffect
- );
- //MessageBoxA(0,podre,"Yay",0);
- return CreateDevice_Real(Lixo,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ppReturnedDeviceInterface);
- }
- // Direct3DCreate9
- extern "C" IDirect3D9* __stdcall __E__7__(UINT SDKVersion)
- {
- IDirect3D9 * pDirect3D = D3DCreate9_fn( SDKVersion );
- UINT_PTR* pVTable = (UINT_PTR*)(*((UINT_PTR*)pDirect3D));
- CreateDevice_Real = (D3D9_CreateDevice) pVTable[16];
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(PVOID&)CreateDevice_Real, CreateDevice_alt);
- if (DetourTransactionCommit() != ERROR_SUCCESS)
- {
- //MessageBox(0, L"failed to create createdev hook", L"", 0);
- }
- return pDirect3D;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement