From d4692f9b79abdb9d1a56477755b646832fa103ae Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 21 Aug 2019 20:33:08 +0200 Subject: [PATCH] Begin implementing LEB128 --- lihzahrd/fileutils/filereader.py | 11 ++++++++++- lihzahrd/world.py | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lihzahrd/fileutils/filereader.py b/lihzahrd/fileutils/filereader.py index bb091cb..d25dd75 100644 --- a/lihzahrd/fileutils/filereader.py +++ b/lihzahrd/fileutils/filereader.py @@ -57,9 +57,18 @@ class FileReader: left, right, top, bottom = struct.unpack("iiii", self.file.read(16)) return Rect(left, right, top, bottom) + def leb128(self) -> int: + byte = self.uint1() + while byte & 0b1000_0000: + byte = byte & 0b0111_1111 + byte = byte << 7 + byte = byte | self.uint1() + # TODO + raise NotImplementedError("TODO") + def string(self, size=None) -> str: if size is None: - size = self.uint1() + size = self.leb128() return str(self.file.read(size), encoding="latin1") def uuid(self) -> uuid.UUID: diff --git a/lihzahrd/world.py b/lihzahrd/world.py index 350b422..1a10cf4 100644 --- a/lihzahrd/world.py +++ b/lihzahrd/world.py @@ -547,7 +547,7 @@ class World: unknown_world_header_data = f.read_until(pointers.world_tiles) # Tiles - tm = cls._create_tilematrix(f, world_size, tileframeimportant) + #`tm = cls._create_tilematrix(f, world_size, tileframeimportant) unknown_world_tiles_data = f.read_until(pointers.chests) @@ -577,7 +577,7 @@ class World: name=chest_name, contents=chest_contents) chests.append(chest) - tm[chest.position].extra = chest + #`tm[chest.position].extra = chest unknown_chests_data = f.read_until(pointers.signs) @@ -590,7 +590,7 @@ class World: sign = Sign(text=f.string(), position=Coordinates(f.int4(), f.int4())) signs.append(sign) - tm[sign.position].extra = sign + #`tm[sign.position].extra = sign unknown_signs_data = f.read_until(pointers.npcs)