HydraHook
Direct3D and Core Audio hooking library for Windows
Toggle main menu visibility
Loading...
Searching...
No Matches
Direct3D9Ex.cpp
Go to the documentation of this file.
1
/*
2
MIT License
3
4
Copyright (c) 2018-2026 Benjamin Höglinger-Stelzer
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
25
#include "
Direct3D9Ex.h
"
26
#include "
Exceptions.hpp
"
27
28
#include <wrl/client.h>
29
30
using namespace
HydraHook::Core::Exceptions
;
31
using
Microsoft::WRL::ComPtr;
32
33
Direct3D9Hooking::Direct3D9Ex::Direct3D9Ex
() :
34
d3d9_ex(nullptr), d3d9_device_ex(nullptr)
35
{
36
temp_window
= std::make_unique<Window>(
"TempDirect3D9ExOverlayWindow"
);
37
38
const
auto
hMod = GetModuleHandle(
"d3d9.dll"
);
39
40
if
(hMod ==
nullptr
)
41
{
42
throw
ModuleNotFoundException
(
"Could not get the handle to d3d9.dll"
);
43
}
44
45
const
auto
Direct3DCreate9Ex =
static_cast<
LPVOID
>
(GetProcAddress(hMod,
"Direct3DCreate9Ex"
));
46
if
(Direct3DCreate9Ex ==
nullptr
)
47
{
48
throw
RuntimeException
(
"Could not locate the Direct3DCreate9Ex procedure entry point"
);
49
}
50
51
ComPtr<IDirect3D9Ex> d3d9;
52
auto
error_code =
static_cast<
HRESULT(WINAPI *)(UINT, IDirect3D9Ex**)
>
(Direct3DCreate9Ex
53
)(D3D_SDK_VERSION, d3d9.GetAddressOf());
54
if
(FAILED(error_code))
55
{
56
throw
DXAPIException
(
"Could not create the DirectX 9 interface"
, error_code);
57
}
58
59
D3DDISPLAYMODE display_mode;
60
error_code = d3d9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &display_mode);
61
if
(FAILED(error_code))
62
{
63
throw
DXAPIException
(
"Could not determine the current display mode"
, error_code);
64
}
65
66
D3DPRESENT_PARAMETERS present_parameters;
67
ZeroMemory(&present_parameters,
sizeof
(D3DPRESENT_PARAMETERS));
68
present_parameters.Windowed = TRUE;
69
present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
70
present_parameters.BackBufferFormat = display_mode.Format;
71
72
ComPtr<IDirect3DDevice9Ex> device;
73
error_code = d3d9->CreateDeviceEx(
74
D3DADAPTER_DEFAULT,
75
D3DDEVTYPE_HAL,
76
temp_window
->windowHandle(),
77
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT,
78
&present_parameters,
79
nullptr
,
80
device.GetAddressOf()
81
);
82
if
(FAILED(error_code))
83
{
84
throw
DXAPIException
(
"Could not create the Direct3D 9 device"
, error_code);
85
}
86
87
d3d9_ex = d3d9.Detach();
88
d3d9_device_ex = device.Detach();
89
}
90
91
std::vector<size_t>
Direct3D9Hooking::Direct3D9Ex::vtable
()
const
92
{
93
return
std::vector<size_t>(*
reinterpret_cast<
size_t
**
>
(d3d9_device_ex),
94
*
reinterpret_cast<
size_t
**
>
(d3d9_device_ex) +
VTableElements
);
95
}
96
97
Direct3D9Hooking::Direct3D9Ex::~Direct3D9Ex
()
98
{
99
if
(d3d9_device_ex)
100
d3d9_device_ex->Release();
101
102
if
(d3d9_ex)
103
d3d9_ex->Release();
104
}
Direct3D9Ex.h
Direct3D 9Ex device vtable indices (extends Direct3D9).
Exceptions.hpp
HydraHook exception types (Detours, Win32, generic).
Direct3D9Hooking::Direct3D9Ex::~Direct3D9Ex
~Direct3D9Ex()
Definition
Direct3D9Ex.cpp:97
Direct3D9Hooking::Direct3D9Ex::vtable
std::vector< size_t > vtable() const override
Returns vtable indices for hookable methods (Present, Reset, etc.).
Definition
Direct3D9Ex.cpp:91
Direct3D9Hooking::Direct3D9Ex::VTableElements
static const int VTableElements
Definition
Direct3D9Ex.h:64
Direct3D9Hooking::Direct3D9Ex::Direct3D9Ex
Direct3D9Ex()
Definition
Direct3D9Ex.cpp:33
Direct3DHooking::Direct3DBase::temp_window
std::unique_ptr< Window > temp_window
Definition
Direct3DBase.h:50
HydraHook::Core::Exceptions::DXAPIException::DXAPIException
DXAPIException(const std::string &msg, HRESULT result)
Definition
Exceptions.hpp:107
HydraHook::Core::Exceptions::ModuleNotFoundException::ModuleNotFoundException
ModuleNotFoundException(const std::string &msg)
Definition
Exceptions.hpp:64
HydraHook::Core::Exceptions::RuntimeException::RuntimeException
RuntimeException(const std::string &msg)
Definition
Exceptions.hpp:21
HydraHook::Core::Exceptions
Definition
Exceptions.hpp:17
src
HydraHook
Game
Hook
Direct3D9Ex.cpp
Generated by
1.18.0