From 514500251884046dd60e7ffa6fe5c11dca07db3a Mon Sep 17 00:00:00 2001 From: MagicBear Date: Wed, 13 Mar 2024 13:12:56 +0800 Subject: [PATCH] add compatible for open xbox sav file --- palworld_save_tools/palsav.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/palworld_save_tools/palsav.py b/palworld_save_tools/palsav.py index 98bf182..f8f6d3e 100644 --- a/palworld_save_tools/palsav.py +++ b/palworld_save_tools/palsav.py @@ -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" @@ -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):