Skip to content

Commit 86e63cb

Browse files
committed
Avoid d3d9.dll crash @ 0x0002A733 (Top 5 most popular MTA crash) and add known incompatible d3d9.dll interface.
Note that this particular DLL isn't a mod, and isn't functional, but is just a poor, outdated Win7 DLL paste into a massively distributed GTA installation variant or mod-pack.
1 parent 363e2b5 commit 86e63cb

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

Client/loader/MainFunctions.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,98 @@ void CheckDataFiles()
10231023
ExitProcess(EXIT_ERROR);
10241024
}
10251025

1026+
// No-op known incompatible/broken d3d9.dll versions from the launch directory
1027+
// By using file version we account for variants as well. Function is extendable in theory, but meant for D3D9.dll 6.3.9600.17415 (MTA top 5 crash)
1028+
{
1029+
struct SIncompatibleVersion
1030+
{
1031+
int iMajor;
1032+
int iMinor;
1033+
int iBuild;
1034+
int iRelease;
1035+
};
1036+
1037+
static const SIncompatibleVersion incompatibleVersions[] = {
1038+
{6, 3, 9600, 17415}, // This d3d9.dll always crashes the user @ 0x0002A733 (CreateSurfaceLH). Furthermore, it's not a graphical mod or functional. Some GTA:SA distributor just placed their own, outdated Win7 DLL in the folder.
1039+
};
1040+
1041+
static bool bChecked = false;
1042+
if (!bChecked)
1043+
{
1044+
bChecked = true;
1045+
1046+
// Check all 3 game roots
1047+
const std::vector<SString> directoriesToCheck = {
1048+
GetLaunchPath(), // MTA installation folder root
1049+
strGTAPath, // Real GTA:SA installation folder root. As chosen by DiscoverGTAPath()
1050+
PathJoin(GetMTADataPath(), "GTA San Andreas"), // Proxy-mirror that MTA uses for core GTA data files (C:\ProgramData\MTA San Andreas All\<MTA major version>\GTA San Andreas)
1051+
};
1052+
1053+
for (const SString& directory : directoriesToCheck)
1054+
{
1055+
if (directory.empty())
1056+
continue;
1057+
if (!ValidatePath(directory))
1058+
continue;
1059+
1060+
const SString strD3dModuleFilename = PathJoin(directory, "d3d9.dll");
1061+
if (!ValidatePath(strD3dModuleFilename) || !FileExists(strD3dModuleFilename))
1062+
continue;
1063+
1064+
SharedUtil::SLibVersionInfo versionInfo = {};
1065+
if (!SharedUtil::GetLibVersionInfo(strD3dModuleFilename, &versionInfo))
1066+
continue;
1067+
1068+
bool bIsIncompatible = false;
1069+
for (const SIncompatibleVersion& entry : incompatibleVersions)
1070+
{
1071+
if (versionInfo.GetFileVersionMajor() == entry.iMajor &&
1072+
versionInfo.GetFileVersionMinor() == entry.iMinor &&
1073+
versionInfo.GetFileVersionBuild() == entry.iBuild &&
1074+
versionInfo.GetFileVersionRelease() == entry.iRelease)
1075+
{
1076+
bIsIncompatible = true;
1077+
break;
1078+
}
1079+
}
1080+
1081+
if (!bIsIncompatible)
1082+
continue;
1083+
1084+
const SString strBackupModuleFilename = PathJoin(directory, "d3d9.bak.incompatible");
1085+
const WString wideSourcePath = FromUTF8(strD3dModuleFilename);
1086+
const WString wideBackupPath = FromUTF8(strBackupModuleFilename);
1087+
1088+
if (FileExists(strBackupModuleFilename))
1089+
{
1090+
SetFileAttributesW(wideBackupPath.c_str(), FILE_ATTRIBUTE_NORMAL);
1091+
DeleteFileW(wideBackupPath.c_str());
1092+
}
1093+
1094+
SetFileAttributesW(wideSourcePath.c_str(), FILE_ATTRIBUTE_NORMAL);
1095+
1096+
bool bRenamed = MoveFileExW(wideSourcePath.c_str(), wideBackupPath.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) != 0;
1097+
if (!bRenamed)
1098+
{
1099+
if (!CopyFileW(wideSourcePath.c_str(), wideBackupPath.c_str(), FALSE))
1100+
continue;
1101+
1102+
SetFileAttributesW(wideBackupPath.c_str(), FILE_ATTRIBUTE_NORMAL);
1103+
1104+
if (!DeleteFileW(wideSourcePath.c_str()))
1105+
continue;
1106+
1107+
bRenamed = true;
1108+
}
1109+
1110+
if (bRenamed)
1111+
{
1112+
SetFileAttributesW(wideBackupPath.c_str(), FILE_ATTRIBUTE_NORMAL);
1113+
}
1114+
}
1115+
}
1116+
}
1117+
10261118
// Check for essential MTA files
10271119
static const char* dataFiles[] = {
10281120
"MTA\\cgui\\images\\background_logo.png",

0 commit comments

Comments
 (0)