menu stuff

big ugly commit, cuz idc
This commit is contained in:
Mc-muffin
2023-05-27 17:10:21 -05:00
parent f7f95e8b82
commit 96ef521958
7 changed files with 320 additions and 31 deletions

View File

@@ -156,13 +156,19 @@ def is_compressed(data: bytes) -> bool:
if len(data) < 0x09:
return False
if data[0] not in (0, 1, 3):
return False
expected_size = struct.unpack("<L", data[1:5])[0]
aligned_size = (expected_size + 9) + (0x100 - ((expected_size + 9) % 0x100))
tail_data = abs(len(data) - (expected_size + 9))
if expected_size == len(data) - 9:
if expected_size == len(data) - 9 or aligned_size == len(data):
return True
if tail_data <= 0x10 and data[expected_size + 9 :] == b"#" * tail_data:
if (tail_data <= 0x10 and data[expected_size + 9 :] == b"#" * tail_data) or (
tail_data <= 0x4 and data[expected_size + 9 :] == b"\x00" * tail_data
):
return True # SCPK files have these trailing "#" bytes :(
return False