Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<PackageVersion Include="Veldrid.StartupUtilities" Version="4.8.0" />
<PackageVersion Include="Veldrid.Utilities" Version="4.8.0" />
<PackageVersion Include="War3Api.Object" Version="1.31.1-rc.11" />
<PackageVersion Include="War3Net.Build" Version="6.0.2" />
<PackageVersion Include="War3Net.Build.Core" Version="6.0.2" />
<PackageVersion Include="War3Net.Build" Version="6.0.3" />
<PackageVersion Include="War3Net.Build.Core" Version="6.0.3" />
<PackageVersion Include="War3Net.CodeAnalysis" Version="6.0.2" />
<PackageVersion Include="War3Net.CodeAnalysis.Decompilers" Version="6.0.2" />
<PackageVersion Include="War3Net.CodeAnalysis.Decompilers" Version="6.0.3" />
<PackageVersion Include="War3Net.CodeAnalysis.Jass" Version="6.0.2" />
<PackageVersion Include="War3Net.CodeAnalysis.Transpilers" Version="6.0.2" />
<PackageVersion Include="War3Net.CodeAnalysis.VJass" Version="0.1.0" />
Expand All @@ -46,7 +46,7 @@
<PackageVersion Include="War3Net.Drawing.Blp" Version="6.0.2" />
<PackageVersion Include="War3Net.IO.Casc" Version="0.1.0" />
<PackageVersion Include="War3Net.IO.Compression" Version="6.0.2" />
<PackageVersion Include="War3Net.IO.Mpq" Version="6.0.2" />
<PackageVersion Include="War3Net.IO.Mpq" Version="6.0.3" />
<PackageVersion Include="War3Net.IO.Slk" Version="6.0.2" />
<PackageVersion Include="War3Net.Modeling" Version="0.1.0" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions docs/changelogs/War3Net.Build.Core.changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions docs/changelogs/War3Net.Build.changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 5 additions & 0 deletions docs/changelogs/War3Net.IO.Mpq.changelog.md
Original file line number Diff line number Diff line change
@@ -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<int>` to `List<uint>`, matching the actual unsigned nature of CRC32 values.
Expand Down
2 changes: 1 addition & 1 deletion src/War3Net.IO.Mpq/BlockTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal BlockTable(BinaryReader reader, uint size, uint headerOffset)
/// <summary>
/// Gets the capacity of the <see cref="BlockTable"/>.
/// </summary>
public override uint Size => (uint)_entries.Count;
public override int Size => _entries.Count;

/// <summary>
/// Gets the key used to encrypt and decrypt the <see cref="BlockTable"/>.
Expand Down
6 changes: 3 additions & 3 deletions src/War3Net.IO.Mpq/HashTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -103,7 +103,7 @@ internal HashTable(BinaryReader reader, uint size)
/// <summary>
/// Gets the capacity of the <see cref="HashTable"/>.
/// </summary>
public override uint Size => _mask + 1;
public override int Size => _hashes.Length;

/// <summary>
/// Gets the mask for this <see cref="HashTable"/>.
Expand Down Expand Up @@ -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++)
Expand Down
42 changes: 39 additions & 3 deletions src/War3Net.IO.Mpq/MpqArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -386,6 +393,11 @@ void InsertMpqFile(MpqFile mpqFile, bool updateEndOfStream, bool allowMultiple =
}
}

/// <summary>
/// Gets the size of the <see cref="BlockTable"/>, i.e. the exclusive upper bound for <see cref="this[int]"/>.
/// </summary>
public int Count => _blockTable.Size;

internal Stream BaseStream => _baseStream;

internal MemoryMappedFile? MemoryMappedFile => _memoryMappedFile;
Expand All @@ -403,7 +415,12 @@ void InsertMpqFile(MpqFile mpqFile, bool updateEndOfStream, bool allowMultiple =

internal BlockTable BlockTable => _blockTable;

internal MpqEntry this[int index] => _blockTable[index];
/// <summary>
/// Gets the <see cref="MpqEntry"/> at the given position in the <see cref="BlockTable"/>.
/// </summary>
/// <param name="index">The zero-based index of the <see cref="MpqEntry"/> in the <see cref="BlockTable"/>.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="index"/> is not a valid index in the <see cref="BlockTable"/>.</exception>
public MpqEntry this[int index] => _blockTable[index];

/// <summary>
/// Opens an existing <see cref="MpqArchive"/> for reading.
Expand Down Expand Up @@ -749,6 +766,25 @@ public IEnumerable<MpqEntry> GetMpqEntries(string fileName, MpqLocale? locale =
}
}

/// <summary>
/// Enumerates the <see cref="HashTable"/>'s live entries (i.e. excluding empty and deleted entries).
/// </summary>
/// <remarks>
/// A <see cref="MpqHash"/>'s corresponding <see cref="MpqEntry"/> can be retrieved through <see cref="this[int]"/>,
/// using <see cref="MpqHash.BlockIndex"/> as the index.
/// </remarks>
public IEnumerable<MpqHash> 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<MpqFile> GetMpqFiles()
{
Expand Down Expand Up @@ -778,7 +814,7 @@ public IEnumerable<MpqFile> 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))
Expand Down
4 changes: 2 additions & 2 deletions src/War3Net.IO.Mpq/MpqTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal MpqTable()
/// <summary>
/// Gets the capacity of the <see cref="MpqTable"/>.
/// </summary>
public abstract uint Size { get; }
public abstract int Size { get; }

/// <summary>
/// Gets the key used to encrypt and decrypt the <see cref="MpqTable"/>.
Expand Down Expand Up @@ -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);
}
}
Expand Down