-
Notifications
You must be signed in to change notification settings - Fork 0
/
dx.cpp
52 lines (48 loc) · 1.45 KB
/
dx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "includes.h"
int window_height, window_width;
BOOL CALLBACK enumWind(HWND handle, LPARAM lp) {
DWORD windowProcessID;
GetWindowThreadProcessId(handle, &windowProcessID);
if (GetCurrentProcessId() != windowProcessID)
return TRUE;
window = handle;
return FALSE;
}
HWND GetProcessWindow() {
window = NULL;
EnumWindows(enumWind, NULL);
RECT size;
GetWindowRect(window, &size);
window_width = size.right - size.left;
window_height = size.bottom - size.top;
window_height -= 29;
window_width -= 5;
return window;
}
bool GetD3D9Device(void** pTable, size_t size) {
if (!pTable)
return false;
IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (!pD3D)
return false;
IDirect3DDevice9* pDummyDevice = nullptr;
D3DPRESENT_PARAMETERS d3dpp = {};
d3dpp.Windowed = false;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = GetProcessWindow();
HRESULT dummyDeviceCreated = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDummyDevice);
if (dummyDeviceCreated != S_OK) {
d3dpp.Windowed = !d3dpp.Windowed;
HRESULT dummyDeviceCreated = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDummyDevice);
if (dummyDeviceCreated != S_OK) {
pD3D->Release();
return false;
}
}
memcpy(pTable, *(void***) (pDummyDevice), size);
pDummyDevice->Release();
pD3D->Release();
return true;
}