mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-24 09:04:22 +00:00
Fix strings being parsed incorrectly: they use ULEB128!
This commit is contained in:
parent
d4692f9b79
commit
4eefcc227b
3 changed files with 16 additions and 13 deletions
|
@ -57,18 +57,21 @@ class FileReader:
|
||||||
left, right, top, bottom = struct.unpack("iiii", self.file.read(16))
|
left, right, top, bottom = struct.unpack("iiii", self.file.read(16))
|
||||||
return Rect(left, right, top, bottom)
|
return Rect(left, right, top, bottom)
|
||||||
|
|
||||||
def leb128(self) -> int:
|
def uleb128(self) -> int:
|
||||||
byte = self.uint1()
|
times = 0
|
||||||
while byte & 0b1000_0000:
|
value = 0
|
||||||
byte = byte & 0b0111_1111
|
more = True
|
||||||
byte = byte << 7
|
while more:
|
||||||
byte = byte | self.uint1()
|
byte = self.uint1()
|
||||||
# TODO
|
shifted_byte = (byte & 0b0111_1111) << (7 * times)
|
||||||
raise NotImplementedError("TODO")
|
times += 1
|
||||||
|
value += shifted_byte
|
||||||
|
more = bool(byte & 0b1000_0000)
|
||||||
|
return value
|
||||||
|
|
||||||
def string(self, size=None) -> str:
|
def string(self, size=None) -> str:
|
||||||
if size is None:
|
if size is None:
|
||||||
size = self.leb128()
|
size = self.uleb128()
|
||||||
return str(self.file.read(size), encoding="latin1")
|
return str(self.file.read(size), encoding="latin1")
|
||||||
|
|
||||||
def uuid(self) -> uuid.UUID:
|
def uuid(self) -> uuid.UUID:
|
||||||
|
|
|
@ -547,7 +547,7 @@ class World:
|
||||||
unknown_world_header_data = f.read_until(pointers.world_tiles)
|
unknown_world_header_data = f.read_until(pointers.world_tiles)
|
||||||
|
|
||||||
# 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)
|
unknown_world_tiles_data = f.read_until(pointers.chests)
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ class World:
|
||||||
name=chest_name,
|
name=chest_name,
|
||||||
contents=chest_contents)
|
contents=chest_contents)
|
||||||
chests.append(chest)
|
chests.append(chest)
|
||||||
#`tm[chest.position].extra = chest
|
tm[chest.position].extra = chest
|
||||||
|
|
||||||
unknown_chests_data = f.read_until(pointers.signs)
|
unknown_chests_data = f.read_until(pointers.signs)
|
||||||
|
|
||||||
|
@ -590,7 +590,7 @@ class World:
|
||||||
sign = Sign(text=f.string(),
|
sign = Sign(text=f.string(),
|
||||||
position=Coordinates(f.int4(), f.int4()))
|
position=Coordinates(f.int4(), f.int4()))
|
||||||
signs.append(sign)
|
signs.append(sign)
|
||||||
#`tm[sign.position].extra = sign
|
tm[sign.position].extra = sign
|
||||||
|
|
||||||
unknown_signs_data = f.read_until(pointers.npcs)
|
unknown_signs_data = f.read_until(pointers.npcs)
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ with open("README.md", "r") as f:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="lihzahrd",
|
name="lihzahrd",
|
||||||
version="1.0b5",
|
version="1.0b6",
|
||||||
author="Stefano Pigozzi",
|
author="Stefano Pigozzi",
|
||||||
author_email="ste.pigozzi@gmail.com",
|
author_email="ste.pigozzi@gmail.com",
|
||||||
description="A Terraria world parser in Python",
|
description="A Terraria world parser in Python",
|
||||||
|
|
Loading…
Reference in a new issue