-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hook.h
64 lines (49 loc) · 1.74 KB
/
Hook.h
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
#pragma once
#include <d3d11.h>
#include <iostream>
class VMTHook;
class Hooks
{
public:
static uintptr_t* CreateDeviceAndSwap();
static void HookInit();
// Hooked functions
static HRESULT __stdcall HookedPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT flags);
static LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Original functions
typedef HRESULT(__stdcall* D3D11Present_o)(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags);
private:
D3D11Present_o oD3D11Present = nullptr;
WNDPROC pOriginalWNDProc = nullptr;
HWND hWindow = nullptr;
std::unique_ptr<VMTHook> pD3DSwap = nullptr;
s
ID3D11Device* pD3DDevice = nullptr;
ID3D11DeviceContext* pD3DContext = nullptr;
ID3D11Texture2D* pD3DRenderTargetTexture = nullptr;
ID3D11RenderTargetView* pD3DRenderTargetView = nullptr;
};
class VMTHook
{
public:
VMTHook(void* Instance) : ppBaseTable(reinterpret_cast<uintptr_t**>(Instance)) { this->pOriginalVMT = *ppBaseTable; }
uintptr_t Hook(void* NewFunc, const std::size_t Index)
{
// save orignal function address
this->pOrgVFunc = (uintptr_t*)this->pOriginalVMT[Index];
// change vmt function pointer
this->pOriginalVMT[Index] = reinterpret_cast<uintptr_t>(NewFunc);
return (uintptr_t)this->pOrgVFunc;
}
void UnHook(const std::size_t Index) { this->pOriginalVMT[Index] = (uintptr_t)this->pOrgVFunc; };
template <class T>
T GetOriginal()
{
return reinterpret_cast<T>(this->mOrgVFunc);
};
private:
uintptr_t* pOriginalVMT = nullptr; // Store original vtable
uintptr_t* pOrgVFunc = nullptr; // Store original vtable
uintptr_t** ppBaseTable = nullptr;
};
delete <<