-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathd3d9.hpp
77 lines (64 loc) · 1.84 KB
/
d3d9.hpp
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
73
74
75
76
77
#pragma once
#define interface struct
#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#undef interface
#include <imgui.h>
#include <imgui_impl_dx9.h>
#include "utils.hpp"
#include "Ruda-Bold.hpp"
#pragma comment(lib, "user32.lib")
// Our drawing function, called in Present
extern inline void render();
namespace globals
{
// Controls the visibility of the menu
inline bool menu = true;
}
namespace original
{
WNDPROC proc = nullptr;
decltype(&IDirect3DDevice9::Reset) reset = nullptr;
decltype(&IDirect3DDevice9::Present) present = nullptr;
}
namespace detours
{
LRESULT __stdcall proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
ImGui_ImplDX9_WndProcHandler(hwnd, msg, wParam, lParam);
return CallWindowProcW(original::proc, hwnd, msg, wParam, lParam);
}
HRESULT __stdcall present(IDirect3DDevice9* self, const RECT* src, const RECT* dst, HWND hwnd, const RGNDATA* rgn)
{
if (static bool initialised = false; !initialised)
{
auto gmod = FindWindowW(L"Valve001", nullptr);
original::proc = reinterpret_cast<WNDPROC>(
SetWindowLongPtrW(gmod, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(proc)) // reinterpret_cast for president
);
ImGui_ImplDX9_Init(gmod, self);
auto& io = ImGui::GetIO();
ImFontConfig config;
config.FontDataOwnedByAtlas = false;
io.FontDefault = io.Fonts->AddFontFromMemoryTTF(ruda, std::size(ruda), 14.f, &config);
io.IniFilename = nullptr;
initialised = true;
}
else
{
ImGui_ImplDX9_NewFrame();
render();
ImGui::Render();
}
return (self->*original::present)(src, dst, hwnd, rgn);
}
HRESULT __stdcall reset(IDirect3DDevice9* self, D3DPRESENT_PARAMETERS* params)
{
ImGui_ImplDX9_InvalidateDeviceObjects();
ImGui_ImplDX9_CreateDeviceObjects();
return (self->*original::reset)(params);
}
}