-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD3D9Hook.cpp
More file actions
72 lines (62 loc) · 1.9 KB
/
Copy pathD3D9Hook.cpp
File metadata and controls
72 lines (62 loc) · 1.9 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
67
68
69
70
71
72
#include "D3D9Hook.h"
#include <d3d9.h>
#include <windows.h>
#pragma comment(lib, "d3d9.lib")
namespace
{
LRESULT CALLBACK DummyWndProc(HWND h, UINT m, WPARAM w, LPARAM l)
{
return DefWindowProc(h, m, w, l);
}
}
void* GetD3D9EndSceneAddress()
{
WNDCLASSEXA wc = {0};
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = DummyWndProc;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpszClassName = "TRDummyD3D";
if (!RegisterClassExA(&wc))
return nullptr;
HWND hwnd = CreateWindowA(wc.lpszClassName, "", WS_OVERLAPPEDWINDOW,
0, 0, 1, 1, nullptr, nullptr, wc.hInstance,
nullptr);
if (!hwnd)
{
UnregisterClassA(wc.lpszClassName, wc.hInstance);
return nullptr;
}
void* endScene = nullptr;
IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (d3d)
{
D3DPRESENT_PARAMETERS pp = {0};
pp.Windowed = TRUE;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.hDeviceWindow = hwnd;
IDirect3DDevice9* device = nullptr;
HRESULT hr = d3d->CreateDevice(
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT,
&pp, &device);
if (FAILED(hr) || !device)
{
pp.Windowed = FALSE;
hr = d3d->CreateDevice(
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING |
D3DCREATE_DISABLE_DRIVER_MANAGEMENT,
&pp, &device);
}
if (SUCCEEDED(hr) && device)
{
void** vtable = *reinterpret_cast<void***>(device);
endScene = vtable[42];
device->Release();
}
d3d->Release();
}
DestroyWindow(hwnd);
UnregisterClassA(wc.lpszClassName, wc.hInstance);
return endScene;
}