Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #include "Window.h"
- #include "d3d9_manager.h"
- Window* mainWindow = NULL;
- d3d9_manager* directX = NULL;
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG uMsg;
- mainWindow = new Window(480, 640, "Test D3D9", hInstance, WindowProc);
- ShowWindow(mainWindow->getHandle(), nCmdShow);
- while (GetMessage(&uMsg, mainWindow->getHandle(), NULL, NULL))
- {
- TranslateMessage(&uMsg);
- DispatchMessage(&uMsg);
- }
- return uMsg.wParam;
- }
- typedef HRESULT (WINAPI* oPresent) (LPDIRECT3DDEVICE9, CONST RECT* ,CONST RECT* , HWND, CONST RGNDATA* );
- oPresent pPresent = NULL;
- HRESULT myPresent(LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
- {
- return pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
- }
- typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
- tEndScene oEndScene = NULL;
- HRESULT WINAPI myEndScene (LPDIRECT3DDEVICE9 pDevice)
- {
- return oEndScene(pDevice);
- }
- PBYTE HookVTableFunction(PDWORD* dwVTable, PBYTE dwHook, INT Index )
- {
- DWORD dwOld = 0;
- VirtualProtect((void*)((*dwVTable) + (Index*4) ), 4, PAGE_EXECUTE_READWRITE, &dwOld);
- PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
- (*dwVTable)[Index] = (DWORD)dwHook;
- VirtualProtect((void*)((*dwVTable) + (Index*4)), 4, dwOld, &dwOld);
- return pOrig;
- }
- LPDIRECT3DDEVICE9 pDevice;
- DWORD* vTable;
- DWORD WINAPI Hook_Thread (LPVOID)
- {
- for(;;Sleep(75))
- {
- if (GetAsyncKeyState(VK_NUMPAD1))
- HookVTableFunction((PDWORD*)pDevice, (PBYTE)myEndScene, 42);
- }
- }
- DWORD WINAPI Draw_Thread( LPVOID)
- {
- for(;;Sleep(1000/60))
- {
- HRESULT hr;
- hr = directX->testDevice();
- if(SUCCEEDED(hr))
- {
- directX->Clear(0);
- directX->startDrawing();
- directX->getFont("Arial1")->DrawTextA(NULL, "Hello world!", -1, NULL, NULL, D3DCOLOR_ARGB(255, 0, 255, 0));
- LPD3DXLINE menuLine = directX->getLine("Line1");
- D3DXVECTOR2 dLine[5];
- dLine[0].x = 50; dLine[0].y = 50;
- dLine[1].x = 350; dLine[1].y = 50;
- dLine[2].x = 350; dLine[2].y = 400;
- dLine[3].x = 50; dLine[3].y = 400;
- dLine[4].x = 50; dLine[4].y = 50;
- menuLine->Begin();
- menuLine->Draw(dLine, 5, D3DCOLOR_XRGB(255,255,255));
- menuLine->End();
- directX->stopDrawing();
- directX->toScreen();
- }
- if(hr == D3DERR_DEVICELOST)
- {
- Sleep(500);
- }
- else if (hr == D3DERR_DEVICENOTRESET)
- {
- hr = directX->Reset();
- if(SUCCEEDED(hr))
- {
- // creating objects again
- }
- }
- }
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_CREATE:
- {
- directX = new d3d9_manager(hWnd);
- pDevice = directX->getDevice();
- DWORD* pVTable = (DWORD*)pDevice;
- vTable = (DWORD*)pVTable[0];
- directX->createFont("Arial1");
- directX->createLine("Line1");
- CreateThread(NULL, NULL, Hook_Thread, NULL, NULL, NULL);
- CreateThread(NULL, NULL, Draw_Thread, NULL, NULL, NULL);
- }
- break;
- case WM_CLOSE:
- delete directX;
- delete mainWindow;
- ExitProcess(0);
- break;
- default:
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement