Skip to content

Commit 59bfb57

Browse files
committed
separate dxgi,d3d11 & loader dll
to hook dxgi & d3d11 at same time without extra deps
1 parent 28d5bfb commit 59bfb57

File tree

15 files changed

+566
-9
lines changed

15 files changed

+566
-9
lines changed

d3d11/d3d11.vcxproj

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<ProjectGuid>{5A73591F-E0F2-400D-9C93-146CD068E18A}</ProjectGuid>
24+
<Keyword>Win32Proj</Keyword>
25+
<RootNamespace>d3d11</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>DynamicLibrary</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v142</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>DynamicLibrary</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v142</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>DynamicLibrary</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v142</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>DynamicLibrary</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v142</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
74+
<LinkIncremental>false</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
80+
<LinkIncremental>true</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
86+
<ClCompile>
87+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
88+
<WarningLevel>Level3</WarningLevel>
89+
<FunctionLevelLinking>true</FunctionLevelLinking>
90+
<IntrinsicFunctions>true</IntrinsicFunctions>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>NDEBUG;D3D11_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>true</ConformanceMode>
94+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
95+
</ClCompile>
96+
<Link>
97+
<SubSystem>Windows</SubSystem>
98+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
99+
<OptimizeReferences>true</OptimizeReferences>
100+
<GenerateDebugInformation>true</GenerateDebugInformation>
101+
<EnableUAC>false</EnableUAC>
102+
<ModuleDefinitionFile>deffile.def</ModuleDefinitionFile>
103+
</Link>
104+
</ItemDefinitionGroup>
105+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
106+
<ClCompile>
107+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
108+
<WarningLevel>Level3</WarningLevel>
109+
<SDLCheck>true</SDLCheck>
110+
<PreprocessorDefinitions>WIN32;_DEBUG;D3D11_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
111+
<ConformanceMode>true</ConformanceMode>
112+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
113+
</ClCompile>
114+
<Link>
115+
<SubSystem>Windows</SubSystem>
116+
<GenerateDebugInformation>true</GenerateDebugInformation>
117+
<EnableUAC>false</EnableUAC>
118+
<ModuleDefinitionFile>deffile.def</ModuleDefinitionFile>
119+
</Link>
120+
</ItemDefinitionGroup>
121+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
122+
<ClCompile>
123+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
124+
<WarningLevel>Level3</WarningLevel>
125+
<SDLCheck>true</SDLCheck>
126+
<PreprocessorDefinitions>_DEBUG;D3D11_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
127+
<ConformanceMode>true</ConformanceMode>
128+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
129+
</ClCompile>
130+
<Link>
131+
<SubSystem>Windows</SubSystem>
132+
<GenerateDebugInformation>true</GenerateDebugInformation>
133+
<EnableUAC>false</EnableUAC>
134+
<ModuleDefinitionFile>deffile.def</ModuleDefinitionFile>
135+
</Link>
136+
</ItemDefinitionGroup>
137+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
138+
<ClCompile>
139+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
140+
<WarningLevel>Level3</WarningLevel>
141+
<FunctionLevelLinking>true</FunctionLevelLinking>
142+
<IntrinsicFunctions>true</IntrinsicFunctions>
143+
<SDLCheck>true</SDLCheck>
144+
<PreprocessorDefinitions>WIN32;NDEBUG;D3D11_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
145+
<ConformanceMode>true</ConformanceMode>
146+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
147+
</ClCompile>
148+
<Link>
149+
<SubSystem>Windows</SubSystem>
150+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
151+
<OptimizeReferences>true</OptimizeReferences>
152+
<GenerateDebugInformation>true</GenerateDebugInformation>
153+
<EnableUAC>false</EnableUAC>
154+
<ModuleDefinitionFile>deffile.def</ModuleDefinitionFile>
155+
</Link>
156+
</ItemDefinitionGroup>
157+
<ItemGroup>
158+
<ClCompile Include="dllmain.cpp" />
159+
</ItemGroup>
160+
<ItemGroup>
161+
<None Include="deffile.def" />
162+
</ItemGroup>
163+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
164+
<ImportGroup Label="ExtensionTargets">
165+
</ImportGroup>
166+
</Project>

d3d11/deffile.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LIBRARY d3d11.dll
2+
EXPORTS
3+
4+
; d3d11
5+
6+
D3D11CreateDevice
7+
D3D11CreateDeviceAndSwapChain

d3d11/dllmain.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
#define WIN32_LEAN_AND_MEAN
3+
#include <windows.h>
4+
#include <d3d11.h>
5+
6+
#define DX11_CREATE_PLIST pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext
7+
8+
typedef HRESULT(WINAPI* D3D11CreateDeviceAndSwapChainFunc)(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, const DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext);
9+
10+
HMODULE target_lib = 0;
11+
const wchar_t* target_lib_name = L"addonLoader.dll";
12+
13+
void* getTargetProc(const char* procName)
14+
{
15+
if (!target_lib)
16+
{
17+
target_lib = LoadLibrary(target_lib_name);
18+
}
19+
20+
return GetProcAddress(target_lib, procName);
21+
}
22+
23+
24+
extern "C" HRESULT WINAPI D3D11CreateDevice(IDXGIAdapter * pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL * pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, ID3D11Device * *ppDevice, D3D_FEATURE_LEVEL * pFeatureLevel, ID3D11DeviceContext * *ppImmediateContext)
25+
{
26+
return D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, nullptr, nullptr, ppDevice, pFeatureLevel, ppImmediateContext);
27+
}
28+
29+
extern "C" HRESULT WINAPI D3D11CreateDeviceAndSwapChain(IDXGIAdapter * pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL * pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, const DXGI_SWAP_CHAIN_DESC * pSwapChainDesc, IDXGISwapChain * *ppSwapChain, ID3D11Device * *ppDevice, D3D_FEATURE_LEVEL * pFeatureLevel, ID3D11DeviceContext * *ppImmediateContext)
30+
{
31+
D3D11CreateDeviceAndSwapChainFunc fun = (D3D11CreateDeviceAndSwapChainFunc)getTargetProc("D3D11CreateDeviceAndSwapChain");
32+
33+
return fun(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
34+
}
35+
36+
37+
38+
BOOL APIENTRY DllMain( HMODULE hModule,
39+
DWORD ul_reason_for_call,
40+
LPVOID lpReserved
41+
)
42+
{
43+
return TRUE;
44+
}
45+

dxgi/deffile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LIBRARY addonLoader.dll
2+
EXPORTS
3+
4+
; dxgi
5+
6+
CreateDXGIFactory
7+
CreateDXGIFactory1
8+
CreateDXGIFactory2

dxgi/dllmain.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#define WIN32_LEAN_AND_MEAN
2+
#include <windows.h>
3+
4+
typedef HRESULT(WINAPI* DXGIFactoryCreate0)(REFIID riid, void** ppFactory);
5+
typedef HRESULT(WINAPI* DXGIFactoryCreate1)(REFIID riid, void** ppFactory);
6+
typedef HRESULT(WINAPI* DXGIFactoryCreate2)(UINT Flags, REFIID riid, void** ppFactory);
7+
8+
HMODULE target_lib = 0;
9+
const wchar_t* target_lib_name = L"addonLoader.dll";
10+
11+
void* getTargetProc(const char* procName)
12+
{
13+
if (!target_lib)
14+
{
15+
target_lib = LoadLibrary(target_lib_name);
16+
}
17+
18+
return GetProcAddress(target_lib, procName);
19+
}
20+
21+
HRESULT WINAPI CreateDXGIFactory(REFIID riid, void** ppFactory)
22+
{
23+
DXGIFactoryCreate0 fun = (DXGIFactoryCreate0)getTargetProc("CreateDXGIFactory");
24+
return fun(riid, ppFactory);
25+
}
26+
27+
HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void** ppFactory)
28+
{
29+
DXGIFactoryCreate1 fun = (DXGIFactoryCreate1)getTargetProc("CreateDXGIFactory1");
30+
return fun(riid, ppFactory);
31+
}
32+
33+
HRESULT WINAPI CreateDXGIFactory2(UINT Flags, REFIID riid, void** ppFactory)
34+
{
35+
DXGIFactoryCreate2 fun = (DXGIFactoryCreate2)getTargetProc("CreateDXGIFactory2");
36+
return fun(Flags, riid, ppFactory);
37+
}
38+
39+
BOOL APIENTRY DllMain( HMODULE hModule,
40+
DWORD ul_reason_for_call,
41+
LPVOID lpReserved
42+
)
43+
{
44+
return TRUE;
45+
}
46+

0 commit comments

Comments
 (0)