Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <Windows.h>
  2. #pragma comment( lib, "gdi32.lib" )
  3. #pragma comment( lib, "user32.lib" )
  4.  
  5. #include <stdio.h>
  6.  
  7. #include <d3d8.h>
  8. #pragma comment( lib, "d3d8.lib" )
  9.  
  10. #include <detours.h>
  11. #pragma comment( lib, "detours.lib" )
  12.  
  13. typedef HRESULT( WINAPI* tEndScene ) ( IDirect3DDevice8* );
  14. tEndScene pEndScene = NULL;
  15.  
  16. void FillRGB( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice8* pDevice )
  17. {
  18.     D3DRECT rec = { x, y, x + w, y + h };
  19.     pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
  20. }
  21.  
  22. HRESULT WINAPI hkEndScene( IDirect3DDevice8* pDevice )
  23. {
  24.     FillRGB( 10, 10, 100, 100, 0xFF00FF00, pDevice );
  25.  
  26.     return pEndScene( pDevice );
  27. }
  28.  
  29. LRESULT CALLBACK MsgProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  30. {
  31.     return DefWindowProc( hwnd, uMsg, wParam, lParam );
  32. }
  33.  
  34. DWORD WINAPI MainThread( LPVOID )
  35. {
  36.     WNDCLASSEXA wc = { sizeof( WNDCLASSEXA ), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, "DX", NULL };
  37.     RegisterClassExA( &wc );
  38.     HWND hWnd = CreateWindowA( "DX", NULL, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL );
  39.  
  40.     D3DPRESENT_PARAMETERS d3dpp;
  41.     LPDIRECT3DDEVICE8 pd3dDevice;
  42.     IDirect3D8 *pd3dInterface = Direct3DCreate8( D3D_SDK_VERSION );
  43.  
  44.     ZeroMemory( &d3dpp, sizeof( d3dpp ) );
  45.     d3dpp.Windowed = TRUE;
  46.     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  47.     d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
  48.     HRESULT hr = pd3dInterface->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice );
  49.     if ( FAILED( hr ) )
  50.     {
  51.         if ( hr == E_NOTIMPL )
  52.             MessageBox( NULL, L"Could not create device, please make sure the target window is not minimized", L"Error", MB_OK );
  53.         else
  54.             MessageBox( NULL, L"Could not create device", L"Error", MB_OK );
  55.  
  56.         return 0;
  57.     }
  58.  
  59.     PDWORD VTable = ( PDWORD ) pd3dDevice;
  60.     VTable = ( PDWORD )VTable[0];
  61.  
  62.     pEndScene = ( tEndScene )DetourFunction( ( PBYTE )VTable[35], ( PBYTE )hkEndScene );
  63.  
  64.     // Debug
  65.     /*char buf[256];
  66.     sprintf_s( buf, "0x%p", pd3dDevice );
  67.     MessageBoxA( nullptr, buf, "", MB_OK );*/
  68.  
  69.     return 0;
  70. }
  71.  
  72. BOOL WINAPI DllMain( HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved )
  73. {
  74.     if ( dwReason == DLL_PROCESS_ATTACH )
  75.     {
  76.         DisableThreadLibraryCalls( hModule );
  77.         CreateThread( nullptr, 0, MainThread, hModule, 0, nullptr );
  78.         return TRUE;
  79.     }
  80.  
  81.     return FALSE;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement