Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #pragma comment( lib, "gdi32.lib" )
- #pragma comment( lib, "user32.lib" )
- #include <stdio.h>
- #include <d3d8.h>
- #pragma comment( lib, "d3d8.lib" )
- #include <detours.h>
- #pragma comment( lib, "detours.lib" )
- typedef HRESULT( WINAPI* tEndScene ) ( IDirect3DDevice8* );
- tEndScene pEndScene = NULL;
- void FillRGB( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice8* pDevice )
- {
- D3DRECT rec = { x, y, x + w, y + h };
- pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
- }
- HRESULT WINAPI hkEndScene( IDirect3DDevice8* pDevice )
- {
- FillRGB( 10, 10, 100, 100, 0xFF00FF00, pDevice );
- return pEndScene( pDevice );
- }
- LRESULT CALLBACK MsgProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
- {
- return DefWindowProc( hwnd, uMsg, wParam, lParam );
- }
- DWORD WINAPI MainThread( LPVOID )
- {
- WNDCLASSEXA wc = { sizeof( WNDCLASSEXA ), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, "DX", NULL };
- RegisterClassExA( &wc );
- HWND hWnd = CreateWindowA( "DX", NULL, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL );
- D3DPRESENT_PARAMETERS d3dpp;
- LPDIRECT3DDEVICE8 pd3dDevice;
- IDirect3D8 *pd3dInterface = Direct3DCreate8( D3D_SDK_VERSION );
- ZeroMemory( &d3dpp, sizeof( d3dpp ) );
- d3dpp.Windowed = TRUE;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
- HRESULT hr = pd3dInterface->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice );
- if ( FAILED( hr ) )
- {
- if ( hr == E_NOTIMPL )
- MessageBox( NULL, L"Could not create device, please make sure the target window is not minimized", L"Error", MB_OK );
- else
- MessageBox( NULL, L"Could not create device", L"Error", MB_OK );
- return 0;
- }
- PDWORD VTable = ( PDWORD ) pd3dDevice;
- VTable = ( PDWORD )VTable[0];
- pEndScene = ( tEndScene )DetourFunction( ( PBYTE )VTable[35], ( PBYTE )hkEndScene );
- // Debug
- /*char buf[256];
- sprintf_s( buf, "0x%p", pd3dDevice );
- MessageBoxA( nullptr, buf, "", MB_OK );*/
- return 0;
- }
- BOOL WINAPI DllMain( HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved )
- {
- if ( dwReason == DLL_PROCESS_ATTACH )
- {
- DisableThreadLibraryCalls( hModule );
- CreateThread( nullptr, 0, MainThread, hModule, 0, nullptr );
- return TRUE;
- }
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement