Skip to content

Commit

Permalink
Fixed handling of asset references for saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
master131 committed Jan 25, 2019
1 parent 11f7ef9 commit 78db3c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion Format/SndAliasBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class SndAliasBank : IDisposable
public int SizeOfDependencyEntry { get; set; }
public List<SndAssetBankEntry> Entries { get; set; }
public List<byte[]> Checksums { get; set; }
public long Unknown { get; set; }
public long Length { get; set; }
public long OffsetOfEntries { get; set; }
public long OffsetOfChecksums { get; set; }
Expand Down
11 changes: 8 additions & 3 deletions Format/SndAliasBankWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ public void Write(Stream stream, bool autoCalculate, bool fixHashes = false)
entry.Data.Cache();
}

// Calculate asset reference count
var assetReferenceCount = 0L;
for (assetReferenceCount = 0; assetReferenceCount < _sndAliasBank.AssetReferences.Length; assetReferenceCount++)
if (_sndAliasBank.AssetReferences[assetReferenceCount] == null)
break;

// Write the header.
stream.SetLength(0);

var writer = new BinaryWriter(stream);
writer.Write(_sndAliasBank.Magic);
writer.Write(_sndAliasBank.Version);
writer.Write(_sndAliasBank.SizeOfAudioEntry);
writer.Write(_sndAliasBank.SizeOfChecksumEntry);
writer.Write(_sndAliasBank.SizeOfDependencyEntry);
writer.Write(_sndAliasBank.Entries.Count);
writer.Write(_sndAliasBank.Unknown);
writer.Write(assetReferenceCount);
var lengthAndOffsetsPosition = stream.Position;
writer.Write(_sndAliasBank.Length);
writer.Write(_sndAliasBank.OffsetOfEntries);
Expand All @@ -43,7 +48,7 @@ public void Write(Stream stream, bool autoCalculate, bool fixHashes = false)
// Write the asset references.
for (int i = 0; i < _sndAliasBank.AssetReferences.Length; i++)
{
var value = _sndAliasBank.AssetReferences[i];
var value = _sndAliasBank.AssetReferences[i] ?? string.Empty;

// Truncate the reference name if required.
if (value.Length > _sndAliasBank.SizeOfDependencyEntry)
Expand Down

0 comments on commit 78db3c7

Please sign in to comment.