From 840269088c76923d09f17921dcf693e9fa4d2c14 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 21 Aug 2019 13:45:52 +0200 Subject: [PATCH] Fix skipped Defeated Martian Madness flag --- lihzahrd/fileutils/filereader.py | 2 ++ lihzahrd/header/bossesdefeated.py | 2 ++ lihzahrd/tiles/rleencoding.py | 5 ----- lihzahrd/world.py | 25 +++++++++++++++++-------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lihzahrd/fileutils/filereader.py b/lihzahrd/fileutils/filereader.py index d15a37f..bb091cb 100644 --- a/lihzahrd/fileutils/filereader.py +++ b/lihzahrd/fileutils/filereader.py @@ -76,6 +76,8 @@ class FileReader: def read_until(self, address: int) -> bytearray: data = bytearray() + if self.file.tell() > address: + raise ValueError("Can't read backwards") while self.file.tell() < address: data += self.file.read(1) return data diff --git a/lihzahrd/header/bossesdefeated.py b/lihzahrd/header/bossesdefeated.py index ae66870..80b79ae 100644 --- a/lihzahrd/header/bossesdefeated.py +++ b/lihzahrd/header/bossesdefeated.py @@ -26,6 +26,7 @@ class BossesDefeated: ice_queen: bool, santa_nk1: bool, everscream: bool, + martian_madness: bool, lunar_pillars: PillarsInfo, old_ones_army: OldOnesArmyTiers): self.eye_of_cthulhu: bool = eye_of_cthulhu @@ -53,6 +54,7 @@ class BossesDefeated: self.ice_queen: bool = ice_queen self.santa_nk1: bool = santa_nk1 self.everscream: bool = everscream + self.martian_madness: bool = martian_madness self.lunar_pillars: PillarsInfo = lunar_pillars self.old_ones_army: OldOnesArmyTiers = old_ones_army diff --git a/lihzahrd/tiles/rleencoding.py b/lihzahrd/tiles/rleencoding.py index 83bdadd..48c3f51 100644 --- a/lihzahrd/tiles/rleencoding.py +++ b/lihzahrd/tiles/rleencoding.py @@ -13,11 +13,6 @@ class RLEEncoding(enum.IntEnum): DOUBLE_BYTE = 2 """The read data refers to 256-4800 tiles (2 bytes).""" - UNKNOWN_3 = 3 - """The read data refers to unknown tiles, assuming 256-4800 (2 bytes). - - Found in certain tModLoader worlds.""" - @classmethod def from_flags(cls, flags1): return cls(flags1[7] * 2 + flags1[6]) diff --git a/lihzahrd/world.py b/lihzahrd/world.py index eb98f72..9571a96 100644 --- a/lihzahrd/world.py +++ b/lihzahrd/world.py @@ -1,6 +1,7 @@ import uuid import math import typing +import multiprocessing from .fileutils import * from .header import * from .tiles import * @@ -263,6 +264,18 @@ class World: tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring) return [tile] * multiply_by + @classmethod + def _create_tilematrix(cls, f, world_size: Coordinates, tileframeimportant: typing.List[bool]): + """Create a TileMatrix object from a file.""" + tm = TileMatrix() + while tm.size.x < world_size.x: + column = [] + while len(column) < world_size.y: + readtiles = cls._read_tile_block(f, tileframeimportant) + column = [*column, *readtiles] + tm.add_column(column) + return tm + @classmethod def create_from_file(cls, filename: str): """Create a World object from a .wld file. @@ -456,6 +469,7 @@ class World: fast_forward_time=fast_forward_time) defeated_duke_fishron = f.bool() + defeated_martian_madness = f.bool() defeated_moon_lord = f.bool() defeated_pumpking = f.bool() defeated_mourning_wood = f.bool() @@ -530,18 +544,13 @@ class World: santa_nk1=defeated_santa_nk1, everscream=defeated_everscream, lunar_pillars=defeated_pillars, - old_ones_army=old_ones_army) + old_ones_army=old_ones_army, + martian_madness=defeated_martian_madness) unknown_world_header_data = f.read_until(pointers.world_tiles) # Tiles - tm = TileMatrix() - while tm.size.x < world_size.x: - column = [] - while len(column) < world_size.y: - readtiles = cls._read_tile_block(f, tileframeimportant) - column = [*column, *readtiles] - tm.add_column(column) + tm = cls._create_tilematrix(f, world_size, tileframeimportant) unknown_world_tiles_data = f.read_until(pointers.chests)