diff --git a/meson.build b/meson.build index 6a0dc0d..d228f89 100644 --- a/meson.build +++ b/meson.build @@ -171,15 +171,15 @@ if is_unixy else dep_dl = cc.find_library('dl') endif +# check for linking with rt by default + if cc.has_function('clock_gettime') + dep_rt = null_dep + else + dep_rt = cc.find_library('rt') + endif else dep_dl = null_dep -endif - -# check for linking with rt by default -if cc.has_function('clock_gettime') dep_rt = null_dep -else - dep_rt = cc.find_library('rt') endif if dep_vulkan.found() @@ -222,7 +222,7 @@ dearimgui_dep = dearimgui_sp.get_variable('dearimgui_dep') if ['windows', 'mingw'].contains(host_machine.system()) subdir('modules/minhook') windows_deps = [ - minhook_dep + minhook_dep, ] else windows_deps = null_dep diff --git a/src/meson.build b/src/meson.build index 933c4be..7a1c5ad 100644 --- a/src/meson.build +++ b/src/meson.build @@ -31,7 +31,8 @@ opengl_files = [] if ['windows', 'mingw'].contains(host_machine.system()) vklayer_files += files( 'win/main.cpp', - 'win/kiero.cpp' + 'win/kiero.cpp', + 'win/d3d12_hook.cpp', ) endif diff --git a/src/win/d3d12_hook.cpp b/src/win/d3d12_hook.cpp new file mode 100644 index 0000000..dd212b7 --- /dev/null +++ b/src/win/d3d12_hook.cpp @@ -0,0 +1,19 @@ +#include "kiero.h" +#include "d3d12_hook.h" +#include +#include +#include + +typedef long(__fastcall* PresentD3D12) (IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags); +PresentD3D12 oPresentD3D12; + +long __fastcall hkPresent12(IDXGISwapChain3* pSwapChain, UINT SyncInterval, UINT Flags){ + printf("d3d12 present\n"); + return oPresentD3D12(pSwapChain, SyncInterval, Flags); +} + +void impl::d3d12::init() +{ + auto ret = kiero::bind(140, (void**)&oPresentD3D12, reinterpret_cast(hkPresent12)); + assert(ret == kiero::Status::Success); +} \ No newline at end of file diff --git a/src/win/d3d12_hook.h b/src/win/d3d12_hook.h new file mode 100644 index 0000000..e024bca --- /dev/null +++ b/src/win/d3d12_hook.h @@ -0,0 +1,22 @@ +#include +#include +#include +#ifdef _MSC_VER + #include +#else + #include "/usr/include/wine/windows/d3d12.h" +#endif +#ifndef __D3D12_IMPL_H__ +#define __D3D12_IMPL_H__ + +namespace impl +{ + namespace d3d12 + { + void init(); + void uninit(); + } +} + + +#endif // __D3D12_IMPL_H__ \ No newline at end of file diff --git a/src/win/kiero.cpp b/src/win/kiero.cpp index 103c038..c4ffca8 100644 --- a/src/win/kiero.cpp +++ b/src/win/kiero.cpp @@ -1,6 +1,7 @@ #include "kiero.h" #include #include +#include #if KIERO_INCLUDE_D3D9 # include @@ -19,7 +20,11 @@ #if KIERO_INCLUDE_D3D12 # include -# include +#ifdef _MSC_VER + #include +#else + #include "/usr/include/wine/windows/d3d12.h" +#endif #endif #if KIERO_INCLUDE_OPENGL @@ -374,8 +379,8 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) return Status::ModuleNotFoundError; } - void* CreateDXGIFactory; - if ((CreateDXGIFactory = ::GetProcAddress(libDXGI, "CreateDXGIFactory")) == NULL) + auto CreateDXGIFactory = reinterpret_cast(::GetProcAddress(libDXGI, "CreateDXGIFactory")); + if (!CreateDXGIFactory) { ::DestroyWindow(window); ::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance); @@ -398,8 +403,8 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) return Status::UnknownError; } - void* D3D12CreateDevice; - if ((D3D12CreateDevice = ::GetProcAddress(libD3D12, "D3D12CreateDevice")) == NULL) + auto D3D12CreateDevice = reinterpret_cast(::GetProcAddress(libD3D12, "D3D12CreateDevice")); + if (!D3D12CreateDevice) { ::DestroyWindow(window); ::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance); @@ -508,7 +513,6 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) ::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance); g_renderType = RenderType::D3D12; - return Status::Success; #endif } diff --git a/src/win/kiero.h b/src/win/kiero.h index ec36bdd..cc8e8e4 100644 --- a/src/win/kiero.h +++ b/src/win/kiero.h @@ -8,7 +8,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_D3D12 0 // 1 if you need D3D12 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 #define KIERO_USE_MINHOOK 0 // 1 if you will use kiero::bind function diff --git a/src/win/main.cpp b/src/win/main.cpp index fd031b4..26f7293 100644 --- a/src/win/main.cpp +++ b/src/win/main.cpp @@ -1,6 +1,10 @@ -#include "kiero.h" #include "windows.h" #include +#include "kiero.h" + +#if KIERO_INCLUDE_D3D12 +# include "d3d12_hook.h" +#endif void ConsoleSetup() { @@ -12,10 +16,24 @@ void ConsoleSetup() freopen("CONIN$", "r", stdin); } -int MainThread(){ +int MainThread() +{ ConsoleSetup(); printf("MangoHud Attached!\n"); - return 0; + if (kiero::init(kiero::RenderType::Auto) == kiero::Status::Success) + { + switch (kiero::getRenderType()) + { +#if KIERO_INCLUDE_D3D12 + case kiero::RenderType::D3D12: + impl::d3d12::init(); + break; +#endif + } + + return 1; + } + return 0; } BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID)