Skip to content

Commit db63a1d

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 0a0a685 commit db63a1d

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
@@ -1024,6 +1024,98 @@ void CheckDataFiles()
10241024
ExitProcess(EXIT_ERROR);
10251025
}
10261026

1027+
// No-op known incompatible/broken d3d9.dll versions from the launch directory
1028+
// 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)
1029+
{
1030+
struct SIncompatibleVersion
1031+
{
1032+
int iMajor;
1033+
int iMinor;
1034+
int iBuild;
1035+
int iRelease;
1036+
};
1037+
1038+
static const SIncompatibleVersion incompatibleVersions[] = {
1039+
{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.
1040+
};
1041+
1042+
static bool bChecked = false;
1043+
if (!bChecked)
1044+
{
1045+
bChecked = true;
1046+
1047+
// Check all 3 game roots
1048+
const std::vector<SString> directoriesToCheck = {
1049+
GetLaunchPath(), // MTA installation folder root
1050+
strGTAPath, // Real GTA:SA installation folder root. As chosen by DiscoverGTAPath()
1051+
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)
1052+
};
1053+
1054+
for (const SString& directory : directoriesToCheck)
1055+
{
1056+
if (directory.empty())
1057+
continue;
1058+
if (!ValidatePath(directory))
1059+
continue;
1060+
1061+
const SString strD3dModuleFilename = PathJoin(directory, "d3d9.dll");
1062+
if (!ValidatePath(strD3dModuleFilename) || !FileExists(strD3dModuleFilename))
1063+
continue;
1064+
1065+
SharedUtil::SLibVersionInfo versionInfo = {};
1066+
if (!SharedUtil::GetLibVersionInfo(strD3dModuleFilename, &versionInfo))
1067+
continue;
1068+
1069+
bool bIsIncompatible = false;
1070+
for (const SIncompatibleVersion& entry : incompatibleVersions)
1071+
{
1072+
if (versionInfo.GetFileVersionMajor() == entry.iMajor &&
1073+
versionInfo.GetFileVersionMinor() == entry.iMinor &&
1074+
versionInfo.GetFileVersionBuild() == entry.iBuild &&
1075+
versionInfo.GetFileVersionRelease() == entry.iRelease)
1076+
{
1077+
bIsIncompatible = true;
1078+
break;
1079+
}
1080+
}
1081+
1082+
if (!bIsIncompatible)
1083+
continue;
1084+
1085+
const SString strBackupModuleFilename = PathJoin(directory, "d3d9.bak.incompatible");
1086+
const WString wideSourcePath = FromUTF8(strD3dModuleFilename);
1087+
const WString wideBackupPath = FromUTF8(strBackupModuleFilename);
1088+
1089+
if (FileExists(strBackupModuleFilename))
1090+
{
1091+
SetFileAttributesW(wideBackupPath.c_str(), FILE_ATTRIBUTE_NORMAL);
1092+
DeleteFileW(wideBackupPath.c_str());
1093+
}
1094+
1095+
SetFileAttributesW(wideSourcePath.c_str(), FILE_ATTRIBUTE_NORMAL);
1096+
1097+
bool bRenamed = MoveFileExW(wideSourcePath.c_str(), wideBackupPath.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) != 0;
1098+
if (!bRenamed)
1099+
{
1100+
if (!CopyFileW(wideSourcePath.c_str(), wideBackupPath.c_str(), FALSE))
1101+
continue;
1102+
1103+
SetFileAttributesW(wideBackupPath.c_str(), FILE_ATTRIBUTE_NORMAL);
1104+
1105+
if (!DeleteFileW(wideSourcePath.c_str()))
1106+
continue;
1107+
1108+
bRenamed = true;
1109+
}
1110+
1111+
if (bRenamed)
1112+
{
1113+
SetFileAttributesW(wideBackupPath.c_str(), FILE_ATTRIBUTE_NORMAL);
1114+
}
1115+
}
1116+
}
1117+
}
1118+
10271119
// Check for essential MTA files
10281120
static const char* dataFiles[] = {
10291121
"MTA\\cgui\\images\\background_logo.png",

0 commit comments

Comments
 (0)