Repository navigation
Expand file tree
/
Copy pathdx.cpp
More file actions
66 lines (50 loc) · 1.53 KB
/
Copy pathdx.cpp
File metadata and controls
66 lines (50 loc) · 1.53 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "includes.h"
// window height and width
int windowHeight, windowWidth;
// callback to be called for each toplevel window
BOOL CALLBACK enumWind(HWND handle, LPARAM lp) {
DWORD procId;
GetWindowThreadProcessId(handle, &procId);
if (GetCurrentProcessId() != procId)
return TRUE;
window = handle;
return FALSE;
}
// get process window
HWND GetProcessWindow() {
window = NULL;
EnumWindows(enumWind, NULL);
RECT size;
GetWindowRect(window, &size);
windowWidth = size.right - size.left;
windowHeight = size.bottom - size.top;
windowHeight -= 29;
windowWidth -= 5;
return window;
}
// get get vTable
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 dummyDevCreated = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDummyDevice);
if (dummyDevCreated != S_OK) {
d3dpp.Windowed = !d3dpp.Windowed;
HRESULT dummyDevCreated = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDummyDevice);
if (dummyDevCreated != S_OK) {
pD3D->Release();
return false;
}
}
memcpy(pTable, *(void***)(pDummyDevice), size);
pDummyDevice->Release();
pD3D->Release();
return true;
}