Read and write MPQ archives.
$ dotnet add package War3Net.IO.MpqWar3Net.IO.Mpq is a .NET library for reading and writing MPQ (MoPaQ) archives, a container format used by Blizzard games including Warcraft III. It is part of the War3Net modding library.
using War3Net.IO.Mpq;
// Open an existing archive
using var archive = MpqArchive.Open("path/to/archive.mpq", loadListFile: true);
// Check if a file exists
if (archive.FileExists("war3map.w3i"))
{
// Open and read a file
using var stream = archive.OpenFile("war3map.w3i");
// Process the stream...
}
using War3Net.IO.Mpq;
// Create files to add to the archive
var file1 = MpqFile.New(File.OpenRead("script.j"), "war3map.j");
var file2 = MpqFile.New(new MemoryStream(data), "war3map.w3i");
// Configure archive options
var options = new MpqArchiveCreateOptions
{
BlockSize = 3,
HashTableSize = 16,
ListFileCreateMode = MpqFileCreateMode.Overwrite,
AttributesCreateMode = MpqFileCreateMode.Overwrite,
};
// Create the archive
using var archive = MpqArchive.Create(
"output.mpq",
new[] { file1, file2 },
options);
using War3Net.IO.Mpq;
// Open the original archive
using var archive = MpqArchive.Open("map.w3x", loadListFile: true);
// Create a builder from the archive
var builder = new MpqArchiveBuilder(archive);
// Add a new file
var newFile = MpqFile.New(new MemoryStream(newData), "newfile.txt");
builder.AddFile(newFile);
// Remove an existing file
builder.RemoveFile("oldfile.txt");
// Save the modified archive
builder.SaveTo("modified.w3x");
using War3Net.IO.Mpq;
var file = MpqFile.New(stream, "encrypted.dat");
// Set compression type
file.CompressionType = MpqCompressionType.ZLib;
// Set target flags for compression and encryption
file.TargetFlags = MpqFileFlags.Exists
| MpqFileFlags.CompressedMulti
| MpqFileFlags.Encrypted;
The main types provided by this library are:
War3Net.IO.Mpq.MpqArchive - Represents an MPQ archive for reading or creatingWar3Net.IO.Mpq.MpqArchiveBuilder - Builder for modifying existing archivesWar3Net.IO.Mpq.MpqArchiveCreateOptions - Configuration options for archive creationWar3Net.IO.Mpq.MpqFile - Represents a file to be added to an archiveWar3Net.IO.Mpq.MpqStream - Stream for reading file contents from an archiveWar3Net.IO.Mpq.MpqEntry - Metadata entry for a file in the block tableWar3Net.IO.Mpq.MpqHash - Hash table entry for file lookupWar3Net.IO.Mpq.MpqFileFlags - Flags for file compression, encryption, and existenceWar3Net.IO.Mpq.MpqCompressionType - Compression algorithms (ZLib, PKLib, BZip2, etc.)War3Net.IO.Mpq.MpqLocale - Locale identifiers for multi-language supportWar3Net.IO.Mpq is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
This README was generated with the assistance of AI and may contain inaccuracies. Please verify the information and consult the source code for authoritative details.