Skip to content

Commit

Permalink
#295 add workaround for Win11 steam RA2 crash
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Mar 11, 2024
1 parent f2d1e9e commit 82571fe
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 0 additions & 2 deletions inc/dd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down
6 changes: 6 additions & 0 deletions src/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion src/opengl_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
26 changes: 21 additions & 5 deletions src/render_d3d9.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 82571fe

Please sign in to comment.