diff options
| author | cadmic <cadmic24@gmail.com> | 2025-02-06 12:10:30 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-06 21:10:30 +0100 |
| commit | e63d2b73b7d4f7d95a50264a6a1b1fa4e5f37ff4 (patch) | |
| tree | fda76c9dbdb5650c059eb1ffc948ccabcebd1438 /tools | |
| parent | 9a3878ec7e0892b31c7af707ca9d91a08e31bc91 (diff) | |
Use CIC 6102 for iQue decompressed ROMs (#2457)
* Use CIC 6102 for iQue decompressed ROMs
* Future-proof is_ique
* Make things more readable
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/decompress_baserom.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/tools/decompress_baserom.py b/tools/decompress_baserom.py index aeea9e3da..4e79d848e 100755 --- a/tools/decompress_baserom.py +++ b/tools/decompress_baserom.py @@ -30,10 +30,11 @@ def decompress_zlib(data: bytes) -> bytes: return bytes(output) -def decompress(data: bytes, is_zlib_compressed: bool) -> bytes: - if is_zlib_compressed: +def decompress(data: bytes, is_ique: bool) -> bytes: + if is_ique: return decompress_zlib(data) - return crunch64.yaz0.decompress(data) + else: + return crunch64.yaz0.decompress(data) def round_up(n, shift): @@ -41,11 +42,13 @@ def round_up(n, shift): return (n + mod - 1) >> shift << shift -def update_crc(decompressed: io.BytesIO) -> io.BytesIO: +def update_crc(decompressed: io.BytesIO, is_ique: bool) -> io.BytesIO: print("Recalculating crc...") - calculated_checksum = ipl3checksum.CICKind.CIC_X105.calculateChecksum( - bytes(decompressed.getbuffer()) - ) + if is_ique: + cic_kind = ipl3checksum.CICKind.CIC_6102_7101 + else: + cic_kind = ipl3checksum.CICKind.CIC_X105 + calculated_checksum = cic_kind.calculateChecksum(bytes(decompressed.getbuffer())) new_crc = struct.pack(f">II", calculated_checksum[0], calculated_checksum[1]) decompressed.seek(0x10) @@ -57,7 +60,7 @@ def decompress_rom( file_content: bytearray, dmadata_start: int, dma_entries: list[dmadata.DmaEntry], - is_zlib_compressed: bool, + is_ique: bool, ) -> bytearray: rom_segments = {} # vrom start : data s.t. len(data) == vrom_end - vrom_start new_dmadata = [] # new dmadata: list[dmadata.Entry] @@ -73,7 +76,7 @@ def decompress_rom( new_dmadata.append(dma_entry) continue if dma_entry.is_compressed(): - new_contents = decompress(file_content[p_start:p_end], is_zlib_compressed) + new_contents = decompress(file_content[p_start:p_end], is_ique) rom_segments[v_start] = new_contents else: rom_segments[v_start] = file_content[p_start : p_start + v_end - v_start] @@ -95,7 +98,7 @@ def decompress_rom( decompressed.seek(padding_start) decompressed.write(b"\x00" * (padding_end - padding_start)) # re-calculate crc - return bytearray(update_crc(decompressed).getbuffer()) + return bytearray(update_crc(decompressed, is_ique).getbuffer()) def get_str_hash(byte_array): @@ -246,10 +249,8 @@ def main(): # Decompress if any(dma_entry.is_compressed() for dma_entry in dma_entries): print("Decompressing rom...") - is_zlib_compressed = version in {"ique-cn", "ique-zh"} - file_content = decompress_rom( - file_content, dmadata_start, dma_entries, is_zlib_compressed - ) + is_ique = version.startswith("ique-") + file_content = decompress_rom(file_content, dmadata_start, dma_entries, is_ique) # Double check the hash str_hash = get_str_hash(file_content) |
