From ac821df7faef5c2457b7575c204f77ebcf3b1448 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 7 Sep 2020 07:49:14 +0200 Subject: [PATCH] Win32 basic d3d11 present hook --- src/keybinds.cpp | 1 - src/meson.build | 1 + src/win/d3d11_hook.cpp | 28 ++++++++++++++++++++++++++++ src/win/d3d11_hook.h | 13 +++++++++++++ src/win/d3d12_hook.cpp | 3 +-- src/win/d3d_shared.cpp | 6 ++++++ src/win/d3d_shared.h | 1 + src/win/kiero.cpp | 4 ++-- src/win/kiero.h | 2 +- src/win/main.cpp | 9 ++++++++- 10 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 src/win/d3d11_hook.cpp create mode 100644 src/win/d3d11_hook.h diff --git a/src/keybinds.cpp b/src/keybinds.cpp index 0285afe0..7cc579b8 100644 --- a/src/keybinds.cpp +++ b/src/keybinds.cpp @@ -22,7 +22,6 @@ void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& par #endif if (pressed && (now - logger->last_log_end() > 11s)) { last_f2_press = now; - printf("pressed\n"); if (logger->is_active()) { logger->stop_logging(); } else { diff --git a/src/meson.build b/src/meson.build index 52518b1c..6f02da73 100644 --- a/src/meson.build +++ b/src/meson.build @@ -48,6 +48,7 @@ if ['windows', 'mingw'].contains(host_machine.system()) 'win/main.cpp', 'win/kiero.cpp', 'win/d3d12_hook.cpp', + 'win/d3d11_hook.cpp', 'win/d3d_shared.cpp', ) endif diff --git a/src/win/d3d11_hook.cpp b/src/win/d3d11_hook.cpp new file mode 100644 index 00000000..c1a48aaa --- /dev/null +++ b/src/win/d3d11_hook.cpp @@ -0,0 +1,28 @@ +#include "kiero.h" + +#if KIERO_INCLUDE_D3D11 + +#include "d3d11_hook.h" +#include +#include + +#include "d3d_shared.h" + +typedef long(__stdcall* Present)(IDXGISwapChain*, UINT, UINT); +static Present oPresent = NULL; + +long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) +{ + d3d_run(); + return oPresent(pSwapChain, SyncInterval, Flags); +} + +void impl::d3d11::init() +{ + printf("init d3d11\n"); + auto ret = kiero::bind(8, (void**)&oPresent, reinterpret_cast(hkPresent11)); + assert(ret == kiero::Status::Success); + init_d3d_shared(); +} + +#endif // KIERO_INCLUDE_D3D11 \ No newline at end of file diff --git a/src/win/d3d11_hook.h b/src/win/d3d11_hook.h new file mode 100644 index 00000000..d0c1a8e1 --- /dev/null +++ b/src/win/d3d11_hook.h @@ -0,0 +1,13 @@ +#ifndef __D3D11_IMPL_H__ +#define __D3D11_IMPL_H__ + +namespace impl +{ + namespace d3d11 + { + void init(); + } +} + + +#endif // __D3D11_IMPL_H__ \ No newline at end of file diff --git a/src/win/d3d12_hook.cpp b/src/win/d3d12_hook.cpp index 58980111..44148aad 100644 --- a/src/win/d3d12_hook.cpp +++ b/src/win/d3d12_hook.cpp @@ -9,8 +9,7 @@ typedef long(__fastcall* PresentD3D12) (IDXGISwapChain* pSwapChain, UINT SyncInt PresentD3D12 oPresentD3D12; long __fastcall hkPresent12(IDXGISwapChain3* pSwapChain, UINT SyncInterval, UINT Flags){ - check_keybinds(sw_stats, params, vendorID); - update_hud_info(sw_stats, params, vendorID); + d3d_run(); return oPresentD3D12(pSwapChain, SyncInterval, Flags); } diff --git a/src/win/d3d_shared.cpp b/src/win/d3d_shared.cpp index c826ccce..cb60c07d 100644 --- a/src/win/d3d_shared.cpp +++ b/src/win/d3d_shared.cpp @@ -1,4 +1,5 @@ #include "d3d_shared.h" +#include "overlay.h" bool cfg_inited = false; ImVec2 window_size; @@ -13,4 +14,9 @@ void init_d3d_shared(){ parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG")); cfg_inited = true; // init_cpu_stats(params); +} + +void d3d_run(){ + check_keybinds(sw_stats, params, vendorID); + update_hud_info(sw_stats, params, vendorID); } \ No newline at end of file diff --git a/src/win/d3d_shared.h b/src/win/d3d_shared.h index 75270998..ff087424 100644 --- a/src/win/d3d_shared.h +++ b/src/win/d3d_shared.h @@ -7,4 +7,5 @@ extern struct swapchain_stats sw_stats; extern uint32_t vendorID; extern void init_d3d_shared(void); +extern void d3d_run(void); extern uint32_t get_device_id_dxgi(void); \ No newline at end of file diff --git a/src/win/kiero.cpp b/src/win/kiero.cpp index 61f77189..2401327c 100644 --- a/src/win/kiero.cpp +++ b/src/win/kiero.cpp @@ -281,8 +281,8 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) return Status::ModuleNotFoundError; } - void* D3D11CreateDeviceAndSwapChain; - if ((D3D11CreateDeviceAndSwapChain = ::GetProcAddress(libD3D11, "D3D11CreateDeviceAndSwapChain")) == NULL) + auto D3D11CreateDeviceAndSwapChain = reinterpret_cast(::GetProcAddress(libD3D11, "D3D11CreateDeviceAndSwapChain")); + if (!D3D11CreateDeviceAndSwapChain) { ::DestroyWindow(window); ::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance); diff --git a/src/win/kiero.h b/src/win/kiero.h index 3d275226..3fe6c015 100644 --- a/src/win/kiero.h +++ b/src/win/kiero.h @@ -7,7 +7,7 @@ #define KIERO_INCLUDE_D3D9 0 // 1 if you need D3D9 hook #define KIERO_INCLUDE_D3D10 0 // 1 if you need D3D10 hook -#define KIERO_INCLUDE_D3D11 0 // 1 if you need D3D11 hook +#define KIERO_INCLUDE_D3D11 1 // 1 if you need D3D11 hook #define KIERO_INCLUDE_D3D12 1 // 1 if you need D3D12 hook #define KIERO_INCLUDE_OPENGL 0 // 1 if you need OpenGL hook #define KIERO_INCLUDE_VULKAN 1 // 1 if you need Vulkan hook diff --git a/src/win/main.cpp b/src/win/main.cpp index 26f7293e..16454780 100644 --- a/src/win/main.cpp +++ b/src/win/main.cpp @@ -1,7 +1,9 @@ #include "windows.h" #include #include "kiero.h" - +#if KIERO_INCLUDE_D3D11 +# include "d3d11_hook.h" +#endif #if KIERO_INCLUDE_D3D12 # include "d3d12_hook.h" #endif @@ -24,6 +26,11 @@ int MainThread() { switch (kiero::getRenderType()) { +#if KIERO_INCLUDE_D3D11 + case kiero::RenderType::D3D11: + impl::d3d11::init(); + break; +#endif #if KIERO_INCLUDE_D3D12 case kiero::RenderType::D3D12: impl::d3d12::init();