Skip to content

Commit 1fde565

Browse files
committed
[GEN][ZH] Prevent AMD/ATI driver crash on game launch by temporarily unloading and renaming dbghelp.dll
1 parent e8b55f5 commit 1fde565

File tree

28 files changed

+1007
-184
lines changed

28 files changed

+1007
-184
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ if((WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") AND ${CMAKE_SIZEOF_VOID_P} EQU
4343
include(cmake/miles.cmake)
4444
include(cmake/bink.cmake)
4545
include(cmake/dx8.cmake)
46-
include(cmake/dbghelp.cmake)
4746
endif()
4847

4948
# Define a dummy stlport target when not on VC6.

Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ set(WWLIB_SRC
3232
#crcstraw.h
3333
cstraw.cpp
3434
cstraw.h
35+
DbgHelpGuard.cpp
36+
DbgHelpGuard.h
37+
DbgHelpLoader.cpp
38+
DbgHelpLoader.h
3539
Except.cpp
3640
Except.h
3741
FastAllocator.cpp
@@ -66,6 +70,7 @@ set(WWLIB_SRC
6670
#lzostraw.cpp
6771
#lzostraw.h
6872
#lzo_conf.h
73+
MallocAllocator.h
6974
#md5.cpp
7075
#md5.h
7176
mempool.h
@@ -98,6 +103,8 @@ set(WWLIB_SRC
98103
#regexpr.cpp
99104
#regexpr.h
100105
#search.h
106+
ScopedFileRenamer.cpp
107+
ScopedFileRenamer.h
101108
sharebuf.h
102109
Signaler.h
103110
simplevec.h
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "DbgHelpGuard.h"
20+
21+
#include "DbgHelpLoader.h"
22+
23+
24+
DbgHelpGuard::DbgHelpGuard()
25+
{
26+
deactivate();
27+
}
28+
29+
DbgHelpGuard::~DbgHelpGuard()
30+
{
31+
reactivate();
32+
}
33+
34+
void DbgHelpGuard::deactivate()
35+
{
36+
DbgHelpLoader::blockLoad();
37+
38+
if (DbgHelpLoader::isLoadedFromSystem())
39+
{
40+
// This is ok. Do nothing.
41+
}
42+
else if (DbgHelpLoader::isLoaded())
43+
{
44+
DbgHelpLoader::unload();
45+
m_wasLoaded = true;
46+
m_dbgHelpRenamer.rename("dbghelp.dll", "dbghelp.dll.bak");
47+
}
48+
else
49+
{
50+
m_dbgHelpRenamer.rename("dbghelp.dll", "dbghelp.dll.bak");
51+
}
52+
}
53+
54+
void DbgHelpGuard::reactivate()
55+
{
56+
m_dbgHelpRenamer.revert();
57+
DbgHelpLoader::unblockLoad();
58+
59+
if (m_wasLoaded)
60+
{
61+
DbgHelpLoader::load();
62+
}
63+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#include "always.h"
22+
23+
#include "ScopedFileRenamer.h"
24+
25+
26+
// This class temporarily unloads dbghelp.dll and prevents it from loading during its lifetime.
27+
// This helps avoid crashing on boot using recent AMD/ATI drivers, which attempt to load and use
28+
// dbghelp.dll from the game install directory but are unable to do so correctly because
29+
// the dbghelp.dll that ships with the game is very old and the AMD/ATI code does not handle
30+
// that correctly. This workaround is not required if the dbghelp.dll was loaded from the system
31+
// directory.
32+
33+
class DbgHelpGuard
34+
{
35+
public:
36+
37+
DbgHelpGuard();
38+
~DbgHelpGuard();
39+
40+
void deactivate();
41+
void reactivate();
42+
43+
private:
44+
45+
ScopedFileRenamer m_dbgHelpRenamer;
46+
bool m_wasLoaded;
47+
};

0 commit comments

Comments
 (0)