1
0
mirror of synced 2024-11-24 05:50:12 +01:00

gfx: add dxgi factory2 hook

This commit is contained in:
Kevin Trocolli 2023-10-09 09:22:23 -04:00
parent 7baf35596b
commit 5e5614d24b

View File

@ -73,6 +73,7 @@ void gfx_dxgi_hook_init(const struct gfx_config *cfg, HINSTANCE self)
memcpy(&gfx_config, cfg, sizeof(*cfg)); memcpy(&gfx_config, cfg, sizeof(*cfg));
hook_table_apply(NULL, "dxgi.dll", dxgi_hooks, _countof(dxgi_hooks)); hook_table_apply(NULL, "dxgi.dll", dxgi_hooks, _countof(dxgi_hooks));
hook_table_apply(NULL, "dxgi", dxgi_hooks, _countof(dxgi_hooks));
if (next_CreateDXGIFactory == NULL || next_CreateDXGIFactory1 == NULL) { if (next_CreateDXGIFactory == NULL || next_CreateDXGIFactory1 == NULL) {
dxgi = LoadLibraryW(L"dxgi.dll"); dxgi = LoadLibraryW(L"dxgi.dll");
@ -110,14 +111,15 @@ void gfx_dxgi_hook_init(const struct gfx_config *cfg, HINSTANCE self)
goto fail; goto fail;
} }
/* `CreateDXGIFactory2` was introduced in Windows 8.1 and the original
* Nu runs Windows 8, so do not require it to exist */
} }
if (self != NULL) { if (self != NULL) {
dll_hook_push(self, L"dxgi.dll"); dll_hook_push(self, L"dxgi.dll");
dll_hook_push(self, L"dxgi");
} }
dprintf("DXGI: init\n");
return; return;
fail: fail:
@ -192,7 +194,7 @@ HRESULT WINAPI CreateDXGIFactory2(UINT flags, REFIID riid, void **factory)
return hr; return hr;
} }
//hr = hook_factory(riid, factory); hr = hook_factory(riid, factory);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; return hr;
@ -206,8 +208,10 @@ static HRESULT hook_factory(REFIID riid, void **factory)
struct com_proxy *proxy; struct com_proxy *proxy;
IDXGIFactory *api_0; IDXGIFactory *api_0;
IDXGIFactory1 *api_1; IDXGIFactory1 *api_1;
IDXGIFactory2 *api_2;
IDXGIFactoryVtbl *vtbl_0; IDXGIFactoryVtbl *vtbl_0;
IDXGIFactory1Vtbl *vtbl_1; IDXGIFactory1Vtbl *vtbl_1;
IDXGIFactory2Vtbl *vtbl_2;
HRESULT hr; HRESULT hr;
api_0 = NULL; api_0 = NULL;
@ -242,6 +246,20 @@ static HRESULT hook_factory(REFIID riid, void **factory)
vtbl_1 = proxy->vptr; vtbl_1 = proxy->vptr;
vtbl_1->CreateSwapChain = my_IDXGIFactory1_CreateSwapChain; vtbl_1->CreateSwapChain = my_IDXGIFactory1_CreateSwapChain;
*factory = proxy;
} else if (memcmp(riid, &IID_IDXGIFactory2, sizeof(*riid)) == 0) {
api_2 = *factory;
hr = com_proxy_wrap(&proxy, api_2, sizeof(*api_2->lpVtbl));
if (FAILED(hr)) {
dprintf("DXGI: com_proxy_wrap returned %x\n", (int) hr);
goto fail;
}
vtbl_2 = proxy->vptr;
vtbl_2->CreateSwapChain = my_IDXGIFactory2_CreateSwapChain;
*factory = proxy; *factory = proxy;
} }
@ -255,6 +273,9 @@ fail:
if (api_1 != NULL) { if (api_1 != NULL) {
IDXGIFactory1_Release(api_1); IDXGIFactory1_Release(api_1);
} }
if (api_2 != NULL) {
IDXGIFactory2_Release(api_2);
}
return hr; return hr;
} }