diff --git a/inc/config.h b/inc/config.h index 562535edf8..fe0f8854c3 100644 --- a/inc/config.h +++ b/inc/config.h @@ -20,6 +20,8 @@ typedef struct CNCDDRAWCONFIG char dll_file_ext[MAX_PATH]; INIFILE ini; BOOL is_wine; + BOOL d3d9on12; + BOOL opengl_core; /* Optional settings */ diff --git a/inc/dd.h b/inc/dd.h index 2e3e09f20d..afd00d9d4a 100644 --- a/inc/dd.h +++ b/inc/dd.h @@ -143,8 +143,6 @@ typedef struct CNCDDRAW DWORD minfps_tick_len; DWORD gui_thread_id; BOOL show_driver_warning; - BOOL d3d9on12; - BOOL opengl_core; } CNCDDRAW; diff --git a/src/dd.c b/src/dd.c index 06abd7db7b..909310e283 100644 --- a/src/dd.c +++ b/src/dd.c @@ -1466,11 +1466,11 @@ HRESULT dd_CreateEx(GUID* lpGuid, LPVOID* lplpDD, REFIID iid, IUnknown* pUnkOute if (_strcmpi(g_config.renderer, "direct3d9on12") == 0) { - g_ddraw->d3d9on12 = TRUE; + g_config.d3d9on12 = TRUE; } else if (_strcmpi(g_config.renderer, "openglcore") == 0) { - g_ddraw->opengl_core = TRUE; + g_config.opengl_core = TRUE; } if (tolower(g_config.renderer[0]) == 'd') /* direct3d9 or direct3d9on12*/ diff --git a/src/dllmain.c b/src/dllmain.c index f26e4ddb0f..ee3c2cc68f 100644 --- a/src/dllmain.c +++ b/src/dllmain.c @@ -52,6 +52,12 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) while (s) { + /* Workaround for bug in Windows 11 (Steam RA2 crash) */ + if (_strcmpi(s, "Win7RTM") == 0) + { + g_config.d3d9on12 = TRUE; + } + if (_strcmpi(s, "WIN95") == 0 || _strcmpi(s, "WIN98") == 0 || _strcmpi(s, "NT4SP5") == 0) { char mes[128] = { 0 }; diff --git a/src/opengl_utils.c b/src/opengl_utils.c index a1bfbaef3d..2f14a5ee3e 100644 --- a/src/opengl_utils.c +++ b/src/opengl_utils.c @@ -218,7 +218,7 @@ void oglu_init() wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)xwglGetProcAddress("wglCreateContextAttribsARB"); } - if (g_ddraw->opengl_core) + if (g_config.opengl_core) { wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)xwglGetProcAddress("wglCreateContextAttribsARB"); } diff --git a/src/render_d3d9.c b/src/render_d3d9.c index e755008695..faed00ac19 100644 --- a/src/render_d3d9.c +++ b/src/render_d3d9.c @@ -27,11 +27,27 @@ BOOL d3d9_is_available() if ((g_d3d9.hmodule = real_LoadLibraryA("d3d9.dll"))) { - IDirect3D9* (WINAPI * d3d_create9)(UINT) = - (IDirect3D9 * (WINAPI*)(UINT))real_GetProcAddress(g_d3d9.hmodule, "Direct3DCreate9"); + if (g_config.d3d9on12) + { + D3D9ON12_ARGS args; + memset(&args, 0, sizeof(args)); + args.Enable9On12 = TRUE; + + IDirect3D9* (WINAPI * d3d_create9on12)(INT, D3D9ON12_ARGS*, UINT) = + (void*)real_GetProcAddress(g_d3d9.hmodule, "Direct3DCreate9On12"); + + if (d3d_create9on12 && (d3d9 = d3d_create9on12(D3D_SDK_VERSION, &args, 1))) + IDirect3D9_Release(d3d9); + } - if (d3d_create9 && (d3d9 = d3d_create9(D3D_SDK_VERSION))) - IDirect3D9_Release(d3d9); + if (!d3d9) + { + IDirect3D9* (WINAPI * d3d_create9)(UINT) = + (IDirect3D9 * (WINAPI*)(UINT))real_GetProcAddress(g_d3d9.hmodule, "Direct3DCreate9"); + + if (d3d_create9 && (d3d9 = d3d_create9(D3D_SDK_VERSION))) + IDirect3D9_Release(d3d9); + } } return d3d9 != NULL; @@ -59,7 +75,7 @@ BOOL d3d9_create() IDirect3D9* (WINAPI * d3d_create9on12)(INT, D3D9ON12_ARGS*, UINT) = NULL; IDirect3D9* (WINAPI * d3d_create9)(UINT) = (void*)real_GetProcAddress(g_d3d9.hmodule, "Direct3DCreate9"); - if (g_ddraw->d3d9on12) + if (g_config.d3d9on12) { d3d_create9on12 = (void*)real_GetProcAddress(g_d3d9.hmodule, "Direct3DCreate9On12"); }