From d17ba3b59f129a4da3e5b64780b0e0aab568c436 Mon Sep 17 00:00:00 2001 From: jarmonik Date: Sun, 21 Jan 2024 05:29:30 +0200 Subject: [PATCH] Fixed (hopefully) d3d9 device creation on wine. --- OVP/D3D9Client/D3D9Client.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/OVP/D3D9Client/D3D9Client.cpp b/OVP/D3D9Client/D3D9Client.cpp index 798088501..fdbdff7ef 100644 --- a/OVP/D3D9Client/D3D9Client.cpp +++ b/OVP/D3D9Client/D3D9Client.cpp @@ -70,6 +70,8 @@ IDirect3D9* g_pD3DObject = 0; // Made valid when VideoTab is created D3D9Catalog *TileCatalog; +typedef IDirect3D9* (__stdcall* __Direct3DCreate9On12)(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries); + set MeshCatalog; set SurfaceCatalog; unordered_map SharedTextures; @@ -320,14 +322,22 @@ bool D3D9Client::clbkInitialise() D3D9ON12_ARGS args = {}; args.Enable9On12 = Config->Enable9On12 != 0; - // NOTE: Link error 'unresolved external symbol' means that d3d9.lib is outdated, use the latest one. - g_pD3DObject = Direct3DCreate9On12(D3D_SDK_VERSION, &args, 1); + HMODULE hDXMod = GetModuleHandle("D3D9.dll"); + __Direct3DCreate9On12 pDirect3DCreate9On12 = nullptr; + + if (hDXMod) pDirect3DCreate9On12 = (__Direct3DCreate9On12)GetProcAddress(hDXMod, "Direct3DCreate9On12"); - if (g_pD3DObject) { - oapiWriteLog("[D3D9] DirectX9 Created..."); + if (OapiExtension::RunsUnderWINE() || pDirect3DCreate9On12 == nullptr) { + g_pD3DObject = Direct3DCreate9(D3D_SDK_VERSION); + oapiWriteLog("[D3D9] Native Interface"); + } + else { + g_pD3DObject = pDirect3DCreate9On12(D3D_SDK_VERSION, &args, 1); if (Config->Enable9On12) oapiWriteLog("[D3D9] DX9 emulation via DX12"); else oapiWriteLog("[D3D9] Native Interface"); } + + if (g_pD3DObject) oapiWriteLog("[D3D9] DirectX9 Created..."); else { oapiWriteLog("[D3D9][ERROR] Failed to create DirectX9"); FailedDeviceError();