diff --git a/Directory.Packages.props b/Directory.Packages.props
index 7247a19e..b58c3ca7 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -33,10 +33,10 @@
-
-
+
+
-
+
@@ -46,7 +46,7 @@
-
+
diff --git a/docs/changelogs/War3Net.Build.Core.changelog.md b/docs/changelogs/War3Net.Build.Core.changelog.md
index 20bb036d..c9bd614e 100644
--- a/docs/changelogs/War3Net.Build.Core.changelog.md
+++ b/docs/changelogs/War3Net.Build.Core.changelog.md
@@ -1,5 +1,9 @@
# War3Net.Build.Core Changelog
+## v6.0.3
+### Changes
+- Updated War3Net.IO.Mpq from v6.0.2 to v6.0.3.
+
## v6.0.2
### Breaking changes
- Updated target framework from .NET 5.0 to .NET 6.0.
diff --git a/docs/changelogs/War3Net.Build.changelog.md b/docs/changelogs/War3Net.Build.changelog.md
index 2c223ef4..7ed725e7 100644
--- a/docs/changelogs/War3Net.Build.changelog.md
+++ b/docs/changelogs/War3Net.Build.changelog.md
@@ -1,5 +1,9 @@
# War3Net.Build Changelog
+## v6.0.3
+### Changes
+- Updated War3Net.Build.Core from v6.0.2 to v6.0.3.
+
## v6.0.2
### Breaking changes
- Updated target framework from .NET 5.0 to .NET 6.0.
diff --git a/docs/changelogs/War3Net.IO.Mpq.changelog.md b/docs/changelogs/War3Net.IO.Mpq.changelog.md
index 840f1483..6d180109 100644
--- a/docs/changelogs/War3Net.IO.Mpq.changelog.md
+++ b/docs/changelogs/War3Net.IO.Mpq.changelog.md
@@ -1,5 +1,10 @@
# War3Net.IO.Mpq Changelog
+## v6.0.3
+### Changes
+- Added `Count` and `EnumerateHashes()` to `MpqArchive`.
+- Changed `MpqArchive[int]` from internal to public.
+
## v6.0.2
### Breaking changes
- `Attributes.Crc32s` changed from `List` to `List`, matching the actual unsigned nature of CRC32 values.
diff --git a/src/War3Net.IO.Mpq/BlockTable.cs b/src/War3Net.IO.Mpq/BlockTable.cs
index 220c59fc..45d6aeeb 100644
--- a/src/War3Net.IO.Mpq/BlockTable.cs
+++ b/src/War3Net.IO.Mpq/BlockTable.cs
@@ -59,7 +59,7 @@ internal BlockTable(BinaryReader reader, uint size, uint headerOffset)
///
/// Gets the capacity of the .
///
- public override uint Size => (uint)_entries.Count;
+ public override int Size => _entries.Count;
///
/// Gets the key used to encrypt and decrypt the .
diff --git a/src/War3Net.IO.Mpq/HashTable.cs b/src/War3Net.IO.Mpq/HashTable.cs
index ad7d70af..634817ff 100644
--- a/src/War3Net.IO.Mpq/HashTable.cs
+++ b/src/War3Net.IO.Mpq/HashTable.cs
@@ -26,7 +26,7 @@ public HashTable(uint size)
}
_mask = GenerateMask(size);
- size = Size;
+ size = _mask + 1;
_hashes = new MpqHash[size];
for (var i = 0; i < size; i++)
@@ -103,7 +103,7 @@ internal HashTable(BinaryReader reader, uint size)
///
/// Gets the capacity of the .
///
- public override uint Size => _mask + 1;
+ public override int Size => _hashes.Length;
///
/// Gets the mask for this .
@@ -207,7 +207,7 @@ private void TryAdd(MpqHash hash, uint index, uint hashCollisions)
var startIndex = (int)index - (int)hashCollisions;
if (startIndex < 0)
{
- startIndex += (int)Size;
+ startIndex += Size;
}
for (var i = 0; i < hashCollisions; i++)
diff --git a/src/War3Net.IO.Mpq/MpqArchive.cs b/src/War3Net.IO.Mpq/MpqArchive.cs
index 02c36f23..a766e36c 100644
--- a/src/War3Net.IO.Mpq/MpqArchive.cs
+++ b/src/War3Net.IO.Mpq/MpqArchive.cs
@@ -366,7 +366,14 @@ void InsertMpqFile(MpqFile mpqFile, bool updateEndOfStream, bool allowMultiple =
writer.Seek((int)_headerOffset, SeekOrigin.Begin);
- _mpqHeader = new MpqHeader((uint)_headerOffset, (uint)(endOfStream - fileOffset), _hashTable.Size, _blockTable.Size, createOptions.BlockSize, _archiveFollowsHeader);
+ _mpqHeader = new MpqHeader(
+ (uint)_headerOffset,
+ (uint)(endOfStream - fileOffset),
+ (uint)_hashTable.Size,
+ (uint)_blockTable.Size,
+ createOptions.BlockSize,
+ _archiveFollowsHeader);
+
_mpqHeader.WriteTo(writer);
if (wantGenerateSignature)
@@ -386,6 +393,11 @@ void InsertMpqFile(MpqFile mpqFile, bool updateEndOfStream, bool allowMultiple =
}
}
+ ///
+ /// Gets the size of the , i.e. the exclusive upper bound for .
+ ///
+ public int Count => _blockTable.Size;
+
internal Stream BaseStream => _baseStream;
internal MemoryMappedFile? MemoryMappedFile => _memoryMappedFile;
@@ -403,7 +415,12 @@ void InsertMpqFile(MpqFile mpqFile, bool updateEndOfStream, bool allowMultiple =
internal BlockTable BlockTable => _blockTable;
- internal MpqEntry this[int index] => _blockTable[index];
+ ///
+ /// Gets the at the given position in the .
+ ///
+ /// The zero-based index of the in the .
+ /// Thrown when is not a valid index in the .
+ public MpqEntry this[int index] => _blockTable[index];
///
/// Opens an existing for reading.
@@ -749,6 +766,25 @@ public IEnumerable GetMpqEntries(string fileName, MpqLocale? locale =
}
}
+ ///
+ /// Enumerates the 's live entries (i.e. excluding empty and deleted entries).
+ ///
+ ///
+ /// A 's corresponding can be retrieved through ,
+ /// using as the index.
+ ///
+ public IEnumerable EnumerateHashes()
+ {
+ for (var i = 0; i < _hashTable.Size; i++)
+ {
+ var hash = _hashTable[i];
+ if (!hash.IsEmpty && !hash.IsDeleted)
+ {
+ yield return hash;
+ }
+ }
+ }
+
// TODO: set hashCollisions values (currently they're always set to 0)
public IEnumerable GetMpqFiles()
{
@@ -778,7 +814,7 @@ public IEnumerable GetMpqFiles()
}
}
- for (var i = 0; i < (int)_blockTable.Size; i++)
+ for (var i = 0; i < _blockTable.Size; i++)
{
var mpqEntry = _blockTable[i];
if (!addedEntries.Contains(mpqEntry))
diff --git a/src/War3Net.IO.Mpq/MpqTable.cs b/src/War3Net.IO.Mpq/MpqTable.cs
index a2704ec8..9bb2a36d 100644
--- a/src/War3Net.IO.Mpq/MpqTable.cs
+++ b/src/War3Net.IO.Mpq/MpqTable.cs
@@ -20,7 +20,7 @@ internal MpqTable()
///
/// Gets the capacity of the .
///
- public abstract uint Size { get; }
+ public abstract int Size { get; }
///
/// Gets the key used to encrypt and decrypt the .
@@ -106,7 +106,7 @@ private byte[] GetEncryptedData()
using (var reader = new BinaryReader(memoryStream))
{
- data = reader.ReadBytes((int)Size * EntrySize);
+ data = reader.ReadBytes(Size * EntrySize);
Encrypt(data);
}
}