-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.cpp
66 lines (57 loc) · 1.97 KB
/
hooks.cpp
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 "../../argentum.hpp"
namespace argentum::hooks {
void __stdcall key_up(int p_this, __int16* key, int a3) {
ImGuiIO& io = ImGui::GetIO();
io.AddInputCharacter(*(__int16*)key);
o_key_up(p_this, key, a3);
}
long D3DAPI dx9_reset(IDirect3DDevice9* device, D3DPRESENT_PARAMETERS* present_params) {
ImGui_ImplDX9_InvalidateDeviceObjects();
const auto ret = o_dx9_reset(device, present_params);
ImGui_ImplDX9_CreateDeviceObjects();
return ret;
}
bool initialised = false;
long D3DAPI dx9_present(IDirect3DDevice9* device,
RECT* src_rect, RECT* dst_rect, HWND dst_wnd_override, RGNDATA* dirty_region
) {
if (GetForegroundWindow() != g_engine->get_window())
{
g_engine->set_window(GetForegroundWindow());
initialised = !initialised;
}
if(!dst_wnd_override) {
if (!initialised) {
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::GetStyle().WindowMinSize = { 450, 350 };
ImGui::GetIO().WantCaptureMouse || ImGui::GetIO().WantTextInput || ImGui::GetIO().WantCaptureKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
ImGui_ImplWin32_Init(g_engine->get_window());
ImGui_ImplDX9_Init(device);
ImGui_ImplDX9_CreateDeviceObjects();
ImGui::GetIO().ImeWindowHandle = g_engine->get_window();
initialised = true;
}
ImGui_ImplDX9_NewFrame();
ImGuiIO& io = ImGui::GetIO();
POINT p = {};
GetCursorPos(&p);
ImGui_ImplWin32_NewFrame();
ScreenToClient(g_engine->get_window(), &p);
io.MousePos.x = p.x - 7;
io.MousePos.y = p.y - 150;
ImGui::NewFrame();
for (int i = 6; i < 256; i++) {
io.KeysDown[i] = (GetAsyncKeyState(i) & 0x8000) != 0;
}
io.MouseDown[0] = (GetKeyState(VK_LBUTTON) & 0x8000) != 0;
io.MouseDown[1] = (GetKeyState(VK_RBUTTON) & 0x8000) != 0;
g_menu->render();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
}
return o_dx9_present(device, src_rect, dst_rect, dst_wnd_override, dirty_region);
}
}