Skip to content

Commit

Permalink
Merge pull request #164 from magicbear/compatible_xbox
Browse files Browse the repository at this point in the history
add compatible for open xbox sav file
  • Loading branch information
cheahjs committed Mar 16, 2024
2 parents e3e3ba0 + 5145002 commit 3a39590
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions palworld_save_tools/palsav.py
Expand Up @@ -8,7 +8,14 @@ def decompress_sav_to_gvas(data: bytes) -> tuple[bytes, int]:
compressed_len = int.from_bytes(data[4:8], byteorder="little")
magic_bytes = data[8:11]
save_type = data[11]
data_start_offset = 12
# Check for magic bytes
if magic_bytes == b"CNK":
uncompressed_len = int.from_bytes(data[12:16], byteorder="little")
compressed_len = int.from_bytes(data[16:20], byteorder="little")
magic_bytes = data[20:23]
save_type = data[23]
data_start_offset = 24
if magic_bytes != MAGIC_BYTES:
if (
magic_bytes == b"\x00\x00\x00"
Expand All @@ -29,10 +36,10 @@ def decompress_sav_to_gvas(data: bytes) -> tuple[bytes, int]:
raise Exception(f"unhandled compression type: {save_type}")
if save_type == 0x31:
# Check if the compressed length is correct
if compressed_len != len(data) - 12:
if compressed_len != len(data) - data_start_offset:
raise Exception(f"incorrect compressed length: {compressed_len}")
# Decompress file
uncompressed_data = zlib.decompress(data[12:])
uncompressed_data = zlib.decompress(data[data_start_offset:])
if save_type == 0x32:
# Check if the compressed length is correct
if compressed_len != len(uncompressed_data):
Expand Down

0 comments on commit 3a39590

Please sign in to comment.