Skip to content

Commit

Permalink
modify original spd header instead of generating a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Secre-C committed Oct 10, 2023
1 parent 3cba029 commit cc8f7e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
17 changes: 6 additions & 11 deletions Emulator/SPD.File.Emulator/Spd/SpdBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,18 @@ public override unsafe MultiStream Build(IntPtr handle, string filepath, Logger?
MemoryStream headerStream = new(HEADER_LENGTH);

// Write Header
headerStream.Write(0x30525053); // 'SPR0'
headerStream.Write(2); // unk04 (usually 2)

// Calculate filesize
long newFileSize = totalTextureSize + HEADER_LENGTH + textureEntryStream.Length + spriteStream.Length;

headerStream.Write((int)newFileSize); // filesize
headerStream.Write(0); // unk0c (usually 0)
headerStream.Write(32); // unk10 (usually 32)
_spdHeader._fileSize = (int)newFileSize;
_spdHeader._textureEntryCount = (short)_textureEntries.Count;
_spdHeader._spriteEntryCount = (short)_spriteEntries.Count;
_spdHeader._textureEntryOffset = HEADER_LENGTH;
_spdHeader._spriteEntryOffset = HEADER_LENGTH + (_textureEntries.Count * TEXTURE_ENTRY_LENGTH);

int textureCount = _textureEntries.Count;
headerStream.Write((short)textureCount); // texture count
headerStream.Write((short)_spriteEntries.Count); // sprite count
headerStream.Write(HEADER_LENGTH); // texture entry start offset
headerStream.Write(HEADER_LENGTH + (textureCount * TEXTURE_ENTRY_LENGTH)); // sprite entry start offset
headerStream.Write(_spdHeader);

// Calculate
// Make Multistream
var pairs = new List<StreamOffsetPair<Stream>>()
{
Expand Down
10 changes: 5 additions & 5 deletions Emulator/SPD.File.Emulator/Spd/SpdHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public struct SpdHeader
#pragma warning disable IDE0051 // Remove unused private members
int magic;
int _unk04;
int _fileSize;
internal int _fileSize;
int _unk0c;
int _unk10;
short _textureEntryCount;
short _spriteEntryCount;
int _textureEntryOffset;
int _spriteEntryOffset;
internal short _textureEntryCount;
internal short _spriteEntryCount;
internal int _textureEntryOffset;
internal int _spriteEntryOffset;

public readonly (short, int) GetTextureEntryCountAndOffset() => (_textureEntryCount, _textureEntryOffset);
public readonly (short, int) GetSpriteEntryCountAndOffset() => (_spriteEntryCount, _spriteEntryOffset);
Expand Down

0 comments on commit cc8f7e0

Please sign in to comment.