@@ -19,7 +19,9 @@ gw2al_addon_dsc gAddonDsc = {
1919 gAddonDeps
2020};
2121
22- HMODULE custom_d3d_module;
22+ HMODULE custom_d3d9_module;
23+ HMODULE custom_d3d11_module;
24+ HMODULE custom_dxgi_module;
2325gw2al_hashed_name eventEnableProcName;
2426
2527gw2al_core_vtable* instance::api = NULL ;
@@ -35,22 +37,22 @@ IDirect3D9* OnD3D9Create()
3537 if (GetD3D9CustomLib)
3638 {
3739 gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" Loading custom lib from D3D_wrapper_custom_d3d9_lib_query" );
38- custom_d3d_module = LoadLibraryW (GetD3D9CustomLib ());
40+ custom_d3d9_module = LoadLibraryW (GetD3D9CustomLib ());
3941 }
4042 else {
4143 gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" Loading system d3d9" );
42- custom_d3d_module = LoadLibraryW (infoBuf);
44+ custom_d3d9_module = LoadLibraryW (infoBuf);
4345 }
4446
45- if (!custom_d3d_module )
47+ if (!custom_d3d9_module )
4648 {
4749 gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" d3d9 library failed to load" );
4850 return 0 ;
4951 }
5052
5153 typedef IDirect3D9* (WINAPI* Direct3DCreate9Func)(UINT sdkver);
5254
53- Direct3DCreate9Func d3d9create_fun = (Direct3DCreate9Func)GetProcAddress (custom_d3d_module , " Direct3DCreate9" );
55+ Direct3DCreate9Func d3d9create_fun = (Direct3DCreate9Func)GetProcAddress (custom_d3d9_module , " Direct3DCreate9" );
5456
5557 if (!d3d9create_fun)
5658 {
@@ -85,22 +87,22 @@ HRESULT OnD3D11Create(DX11_CREATE_FDEF)
8587 if (GetD3D11CustomLib)
8688 {
8789 gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" Loading custom lib from D3D_wrapper_custom_d3d11_lib_query" );
88- custom_d3d_module = LoadLibraryW (GetD3D11CustomLib ());
90+ custom_d3d11_module = LoadLibraryW (GetD3D11CustomLib ());
8991 }
9092 else {
9193 gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" Loading system d3d11" );
92- custom_d3d_module = LoadLibraryW (infoBuf);
94+ custom_d3d11_module = LoadLibraryW (infoBuf);
9395 }
9496
95- if (!custom_d3d_module )
97+ if (!custom_d3d11_module )
9698 {
9799 gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" d3d11 library failed to load" );
98100 return 0 ;
99101 }
100102
101103 typedef HRESULT (WINAPI* D3D11CreateDeviceAndSwapChainFunc)(DX11_CREATE_FDEF);
102104
103- D3D11CreateDeviceAndSwapChainFunc d3d11create_fun = (D3D11CreateDeviceAndSwapChainFunc)GetProcAddress (custom_d3d_module , " D3D11CreateDeviceAndSwapChain" );
105+ D3D11CreateDeviceAndSwapChainFunc d3d11create_fun = (D3D11CreateDeviceAndSwapChainFunc)GetProcAddress (custom_d3d11_module , " D3D11CreateDeviceAndSwapChain" );
104106
105107 if (!d3d11create_fun)
106108 {
@@ -128,6 +130,73 @@ HRESULT OnD3D11Create(DX11_CREATE_FDEF)
128130 return res;
129131}
130132
133+ static int insideDXGICreate = 0 ;
134+
135+ HRESULT OnDXGICreate (UINT ver, UINT Flags, REFIID riid, void ** ppFactory)
136+ {
137+ typedef HRESULT (WINAPI* DXGIFactoryCreate0)(REFIID riid, void ** ppFactory);
138+ typedef HRESULT (WINAPI* DXGIFactoryCreate1)(REFIID riid, void ** ppFactory);
139+ typedef HRESULT (WINAPI* DXGIFactoryCreate2)(UINT Flags, REFIID riid, void ** ppFactory);
140+
141+ wchar_t infoBuf[4096 ];
142+ GetSystemDirectory (infoBuf, 4096 );
143+ lstrcatW (infoBuf, L" \\ dxgi.dll" );
144+
145+ wchar_t * (*GetDXGICustomLib)() = (wchar_t * (*)())gAPI ->query_function (gAPI ->hash_name (L" D3D_wrapper_custom_dxgi_lib_query" ));
146+
147+
148+ if (GetDXGICustomLib)
149+ {
150+ gAPI ->log_text (LL_INFO, L" d3d9_wrapper" , L" Loading custom lib from D3D_wrapper_custom_dxgi_lib_query" );
151+ custom_dxgi_module = LoadLibraryW (GetDXGICustomLib ());
152+ }
153+ else {
154+ gAPI ->log_text (LL_INFO, L" d3d9_wrapper" , L" Loading system dxgi" );
155+ custom_dxgi_module = LoadLibraryW (infoBuf);
156+ }
157+
158+ if (!custom_dxgi_module)
159+ {
160+ gAPI ->log_text (LL_INFO, L" d3d9_wrapper" , L" dxgi library failed to load" );
161+ return 0 ;
162+ }
163+
164+
165+ DXGIFactoryCreate0 origDXGI0 = (DXGIFactoryCreate0)GetProcAddress (custom_dxgi_module, " CreateDXGIFactory" );
166+ DXGIFactoryCreate1 origDXGI1 = (DXGIFactoryCreate1)GetProcAddress (custom_dxgi_module, " CreateDXGIFactory1" );
167+ DXGIFactoryCreate2 origDXGI2 = (DXGIFactoryCreate2)GetProcAddress (custom_dxgi_module, " CreateDXGIFactory2" );
168+
169+ HRESULT ret;
170+
171+ ++insideDXGICreate;
172+ switch (ver)
173+ {
174+ case 0 :
175+ ret = origDXGI0 (riid, ppFactory);
176+ break ;
177+ case 1 :
178+ ret = origDXGI1 (riid, ppFactory);
179+ break ;
180+ case 2 :
181+ ret = origDXGI2 (Flags, riid, ppFactory);
182+ break ;
183+ }
184+ --insideDXGICreate;
185+
186+ if (ret != S_OK)
187+ {
188+ gAPI ->log_text (LL_INFO, (wchar_t *)L" d3d9_wrapper" , (wchar_t *)L" CreateDXGIFactory failed" );
189+ return 0 ;
190+ }
191+
192+ if (insideDXGICreate == 0 )
193+ {
194+ *ppFactory = wrap_CreateDXGI (*ppFactory);
195+ }
196+
197+ return ret;
198+ }
199+
131200gw2al_addon_dsc* gw2addon_get_description ()
132201{
133202 return &gAddonDsc ;
@@ -254,6 +323,7 @@ gw2al_api_ret gw2addon_load(gw2al_core_vtable* core_api)
254323
255324 gAPI ->register_function (&OnD3D9Create, GW2AL_CORE_FUNN_D3DCREATE_HOOK);
256325 gAPI ->register_function (&OnD3D11Create, GW2AL_CORE_FUNN_D3D11CREATE_HOOK);
326+ gAPI ->register_function (&OnDXGICreate, GW2AL_CORE_FUNN_DXGICREATE_HOOK);
257327 gAPI ->register_function (&d3d9_wrapper_enable_event, eventEnableProcName);
258328
259329 wrap_InitEvents ();
@@ -322,8 +392,8 @@ gw2al_api_ret gw2addon_unload(int gameExiting)
322392 gAPI ->unregister_function (eventEnableProcName);
323393 gAPI ->unregister_function (GW2AL_CORE_FUNN_D3DCREATE_HOOK);
324394
325- if (custom_d3d_module )
326- FreeLibrary (custom_d3d_module );
395+ if (custom_d3d11_module )
396+ FreeLibrary (custom_d3d11_module );
327397
328398 return GW2AL_OK;
329399}
0 commit comments