From bf261e1c18cc4567c208836b6599e1e61ed1f4ca Mon Sep 17 00:00:00 2001 From: Hurricane996 Date: Mon, 23 Oct 2023 20:49:41 -0500 Subject: [PATCH 1/2] added little endian suport for SBN files --- tools/splat_ext/pm_sbn.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/splat_ext/pm_sbn.py b/tools/splat_ext/pm_sbn.py index 665db018252..9a9c99557db 100644 --- a/tools/splat_ext/pm_sbn.py +++ b/tools/splat_ext/pm_sbn.py @@ -31,6 +31,13 @@ def align(misaligned: int): return (misaligned + 0xF) & (~0xF) + +def convert_fstring_to_proper_endianness(le: bool, fstring: str) -> str: + if le: + return fstring.replace(">","<") + else: + return fstring + class SBN: files: List["SBNFile"] unknown_data: bytes @@ -71,7 +78,9 @@ def decode(self, data: bytes): return len(data) - def encode(self) -> bytes: + def encode(self, is_le: bool = false) -> bytes: + convert_fstring = functools.partial(convert_fstring_to_proper_endianness, is_le) + num_bytes = 0 num_bytes += 0x40 # header @@ -121,7 +130,7 @@ def encode(self) -> bytes: INIToffset=init_header_offset, ) - struct.pack_into(SBNHeader.fstring, data, 0, *header) + struct.pack_into(convert_fstring(SBNHeader.fstring), data, 0, *header) # unknown data for offset, byte in enumerate(self.unknown_data): @@ -149,7 +158,7 @@ def encode(self) -> bytes: entry = SBNFileEntry(offset=current_file_offset, fmt=format, size=file.fakesize) struct.pack_into( - SBNFileEntry.fstring, + convert_fstring(SBNFileEntry.fstring), data, entries_offset + index * SBNFileEntry.length, *entry, @@ -171,29 +180,29 @@ def encode(self) -> bytes: shortsSize=mseq_end - mseq_offset, ) - struct.pack_into(INITHeader.fstring, data, init_header_offset, *initHeader) + struct.pack_into(convert_fstring(INITHeader.fstring), data, init_header_offset, *initHeader) current_bank_offset = bank_entry_offset for bank in self.init.bk_entries: - struct.pack_into(BufferEntry.fstring, data, current_bank_offset, *bank) + struct.pack_into(convert_fstring(BufferEntry.fstring), data, current_bank_offset, *bank) current_bank_offset += BufferEntry.length sentinel = BufferEntry(0xFFFF, 0x00, 0x00) - struct.pack_into(BufferEntry.fstring, data, current_bank_offset, *sentinel) + struct.pack_into(convert_fstring(BufferEntry.fstring), data, current_bank_offset, *sentinel) current_song_offset = song_entry_offset for song in self.init.song_entries: - struct.pack_into(InitSongEntry.fstring, data, current_song_offset, *song) + struct.pack_into(convert_fstring(InitSongEntry.fstring), data, current_song_offset, *song) current_song_offset += InitSongEntry.length sentinel2 = InitSongEntry(0xFFFF, 0x00, 0x00, 0x00) - struct.pack_into(InitSongEntry.fstring, data, current_song_offset, *sentinel2) + struct.pack_into(convert_fstring(InitSongEntry.fstring), data, current_song_offset, *sentinel2) current_mseq_offset = mseq_offset for mseq in self.init.mseq_entries: - struct.pack_into(">H", data, current_mseq_offset, mseq) + struct.pack_into(convert_fstring(">H"), data, current_mseq_offset, mseq) current_mseq_offset += 2 - struct.pack_into(">H", data, current_mseq_offset, 0xFFFF) + struct.pack_into(convert_fstring(">H"), data, current_mseq_offset, 0xFFFF) return bytes(data) From cb5a811e22d7859888b390e474320cca8d5c3e22 Mon Sep 17 00:00:00 2001 From: Hurricane996 Date: Mon, 23 Oct 2023 20:56:07 -0500 Subject: [PATCH 2/2] formatting --- tools/splat_ext/pm_sbn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/splat_ext/pm_sbn.py b/tools/splat_ext/pm_sbn.py index 9a9c99557db..089812b36fb 100644 --- a/tools/splat_ext/pm_sbn.py +++ b/tools/splat_ext/pm_sbn.py @@ -31,13 +31,13 @@ def align(misaligned: int): return (misaligned + 0xF) & (~0xF) - def convert_fstring_to_proper_endianness(le: bool, fstring: str) -> str: if le: - return fstring.replace(">","<") + return fstring.replace(">", "<") else: return fstring + class SBN: files: List["SBNFile"] unknown_data: bytes