Skip to content

Commit

Permalink
Force MPQ v1 if archive is Warcraft 3 map, to bypass map corruption.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Vind committed Nov 23, 2024
1 parent 98398b9 commit 5a26f2c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ void showUsage(const std::string& strApplicationName)
<< endl;
}

bool isWar3Map(const std::string& filename) {
// Find the position of the last dot in the filename
size_t dotPosition = filename.rfind('.');
if (dotPosition == std::string::npos) {
// No dot found in the filename, so no extension
return false;
}

// Extract the extension
std::string extension = filename.substr(dotPosition);

// Convert to lowercase for case-insensitive comparison
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);

// Check if the extension matches .w3m or .w3x
return extension == ".w3m" || extension == ".w3x";
}

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -228,7 +245,8 @@ int main(int argc, char** argv)


cout << "Opening '" << args.File(0) << "'..." << endl;
if (!SFileOpenArchive(args.File(0), 0, MPQ_OPEN_READ_ONLY, &hArchive))
bool isMap = isWar3Map(args.File(0));
if (!SFileOpenArchive(args.File(0), 0, MPQ_OPEN_READ_ONLY | (isMap ? MPQ_OPEN_FORCE_MPQ_V1 : 0) , &hArchive))
{
cerr << "Failed to open the file '" << args.File(0) << "'" << endl;
return -1;
Expand Down

0 comments on commit 5a26f2c

Please sign in to comment.