Skip to content

[GEN][ZH] Prevent AMD/ATI driver crash on game launch by temporarily unloading and renaming dbghelp.dll #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ if((WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") AND ${CMAKE_SIZEOF_VOID_P} EQU
include(cmake/miles.cmake)
include(cmake/bink.cmake)
include(cmake/dx8.cmake)
include(cmake/dbghelp.cmake)
endif()

# Define a dummy stlport target when not on VC6.
Expand Down
5 changes: 5 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ set(WWLIB_SRC
#crcstraw.h
cstraw.cpp
cstraw.h
DbgHelpGuard.cpp
DbgHelpGuard.h
DbgHelpLoader.cpp
DbgHelpLoader.h
Except.cpp
Except.h
FastAllocator.cpp
Expand Down Expand Up @@ -66,6 +70,7 @@ set(WWLIB_SRC
#lzostraw.cpp
#lzostraw.h
#lzo_conf.h
MallocAllocator.h
#md5.cpp
#md5.h
mempool.h
Expand Down
59 changes: 59 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/DbgHelpGuard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 TheSuperHackers
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "DbgHelpGuard.h"

#include "DbgHelpLoader.h"


DbgHelpGuard::DbgHelpGuard()
: m_hasLoaded(false)
{
activate();
}

DbgHelpGuard::~DbgHelpGuard()
{
deactivate();
}

void DbgHelpGuard::activate()
{
if (DbgHelpLoader::isLoadedFromSystem())
{
// This is ok. Do nothing.
}
else if (DbgHelpLoader::isLoaded())
{
// This is maybe not ok. But do nothing until this becomes a user facing problem.
}
else
{
// Front load the DLL now to prevent other code from loading the potentially wrong DLL.
m_hasLoaded = DbgHelpLoader::load();
}
}

void DbgHelpGuard::deactivate()
{
if (m_hasLoaded)
{
DbgHelpLoader::unload();
m_hasLoaded = false;
}
}
44 changes: 44 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/DbgHelpGuard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 TheSuperHackers
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "always.h"


// This class temporarily loads and unloads dbghelp.dll from the desired location to prevent
// other code from potentially loading it from an undesired location.
// This helps avoid crashing on boot using recent AMD/ATI drivers, which attempt to load and use
// dbghelp.dll from the game install directory but are unable to do so correctly because
// the dbghelp.dll that ships with the game is very old and the AMD/ATI code does not handle
// that correctly.

class DbgHelpGuard
{
public:

DbgHelpGuard();
~DbgHelpGuard();

void activate();
void deactivate();

private:

bool m_hasLoaded;
};
Loading
Loading