Skip to content

Commit

Permalink
(archives.nexon)(#198) cleaning up a little
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-biscuits committed Sep 2, 2024
1 parent ad0ddcb commit 6c067f2
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions bsp_tool/archives/nexon.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ def as_bytes(self) -> bytes:

class PakCentralDirectory:
"""preceded by magic CS\x01\x02"""
# NOTE: byte alignment sucks, would try Struct otherwise
# header
unused: int # always 0
crc32: int
uncompressed_size: int
compressed_size: int
path_size: int
unknown: int
header_offset: int
header_offset: int # file offset of LocalFile
# data
path: str

Expand All @@ -93,14 +92,14 @@ def __repr__(self) -> str:
@classmethod
def from_stream(cls, stream: io.BytesIO) -> PakCentralDirectory:
out = cls()
out.unused = int.from_bytes(stream.read(2), "little")
out.crc32 = int.from_bytes(stream.read(4), "little")
out.uncompressed_size = int.from_bytes(stream.read(4), "little")
out.compressed_size = int.from_bytes(stream.read(4), "little")
out.path_size = int.from_bytes(stream.read(4), "little")
out.unknown = int.from_bytes(stream.read(2), "little")
out.header_offset = int.from_bytes(stream.read(4), "little")
out.path = stream.read(out.path_size).decode()
out.unused = binary.read_struct(stream, "H")
out.crc32 = binary.read_struct(stream, "I")
out.uncompressed_size = binary.read_struct(stream, "I")
out.compressed_size = binary.read_struct(stream, "I")
out.path_size = binary.read_struct(stream, "I")
out.unknown = binary.read_struct(stream, "H")
out.header_offset = binary.read_struct(stream, "I")
out.path = stream.read(out.path_size).decode("latin_1")
return out

def as_bytes(self) -> bytes:
Expand All @@ -112,7 +111,7 @@ def as_bytes(self) -> bytes:
self.path_size.to_bytes(4, "little"),
self.unknown.to_bytes(2, "little"),
self.header_offset.to_bytes(4, "little"),
self.path.encode()])
self.path.encode("latin_1")])


class PakEOCD: # End of Central Directory
Expand Down

0 comments on commit 6c067f2

Please sign in to comment.