Basic d3d12 present hook

This commit is contained in:
FlightlessMango 2020-09-05 11:16:20 +02:00
parent 8d3e8b5205
commit 9391822da5
7 changed files with 82 additions and 18 deletions

View File

@ -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

View File

@ -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

19
src/win/d3d12_hook.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "kiero.h"
#include "d3d12_hook.h"
#include <cstdio>
#include <cassert>
#include <functional>
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<void*>(hkPresent12));
assert(ret == kiero::Status::Success);
}

22
src/win/d3d12_hook.h Normal file
View File

@ -0,0 +1,22 @@
#include <dxgi.h>
#include <dxgi1_5.h>
#include <dxgi1_4.h>
#ifdef _MSC_VER
#include <d3d12.h>
#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__

View File

@ -1,6 +1,7 @@
#include "kiero.h"
#include <windows.h>
#include <assert.h>
#include <cstdio>
#if KIERO_INCLUDE_D3D9
# include <d3d9.h>
@ -19,7 +20,11 @@
#if KIERO_INCLUDE_D3D12
# include <dxgi.h>
# include <d3d12.h>
#ifdef _MSC_VER
#include <d3d12.h>
#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<decltype(&::CreateDXGIFactory)>(::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<decltype(&::D3D12CreateDevice)>(::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
}

View File

@ -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

View File

@ -1,6 +1,10 @@
#include "kiero.h"
#include "windows.h"
#include <cstdio>
#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)