def load(self): self.map = {} with self.game.open('arm9.dec.bin') as handle: reader = BinaryIO.reader(handle) reader.seek(self.game.type_icon_table[1]) Editable.load(self, BinaryIO.reader(reader)) return self
def load(self): self.map = {} with self.game.open( 'overlays_dez', 'overlay_{0:04}.bin'.format( self.game.overworld_sprite_table[0])) as handle: reader = BinaryIO.reader(handle) reader.seek(self.game.overworld_sprite_table[1]) Editable.load(self, BinaryIO.reader(reader)) for sprite in self.table: self.map[sprite.sprite_id] = sprite return self
def load(self, reader): reader = BinaryIO.reader(reader) Editable.load(self, reader) if self.game.is_hgss(): self.block1 = reader.read(self.ublock1_size) """entry_size = Permission(self.game).get_size() # self.permissions = [Permission(self.game, reader=reader) # for i in range(self.permission_size/entry_size)] self.permissions = Editable() self.permissions.array('entries', Permission(self.game).base_struct, length=self.permission_size/entry_size) self.permissions.freeze() self.permissions.load(reader) entry_size = MapObject(self.game).get_size() self.objects = [MapObject(self.game, reader=reader) for i in range(self.objects_size/entry_size)]""" entry = Permission(self.game) # TODO: non-fixed w/h self.permissions = Collection2d(entry.base_struct, 0x20, 0x20) self.permissions.load(reader) entry = MapObject(self.game) self.objects = SizedCollection( entry.base_struct, self.objects_size/entry.get_size()) self.objects.load(reader) self.bmd = reader.read(self.bmd_size) # TODO later self.bdhc = reader.read(self.bdhc_size)
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() Editable.load(self, reader) self.records = {} for record_ofs, record_name in zip(self.record_offsets, self.record_names): if not record_ofs: continue reader.seek(start + record_ofs) num = reader.readUInt32() if record_name == 'SEQARC': offsets = [] for i in range(num): offsets.append((reader.readUInt32(), reader.readUInt32())) entries = [] for i, (offset, sub_offset) in enumerate(offsets): reader.seek(start + offset) name = reader.readString() reader.seek(start + sub_offset) prefix = (record_name, name) entries += self.load_entries(reader, start, prefix, num) else: entries = self.load_entries(reader, start, (record_name, ), num) self.records[record_name] = entries
def load(self, reader): reader = BinaryIO.reader(reader) Editable.load(self, reader) self.name = reader.read(self.namelen) """land_data_block = Editable() land_data_block.array('entries', land_data_block.uint16, length=self.width*self.height) land_data_block.freeze() self.land_data_maps = land_data_block.load(reader) print(len(reader.read()))""" with self.simulate(): if self.has_map_definition_ids: self.map_definitions = Collection2d(self.uint16, self.width, self.height) self.map_definitions.load(reader) else: self.map_definitions = None if self.has_mystery_zone: self.mystery_details = Collection2d(self.uint8, self.width, self.height) self.mystery_details.load(reader) else: self.mystery_details = None self.land_data_maps = Collection2d(self.uint16, self.width, self.height) self.land_data_maps.load(reader)
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() self.name = reader.read(12).rstrip('\x00') self.code = reader.read(4) with reader.seek(start + 0xA0): self.base_code = reader.read(4).rstrip('\x00') if not self.base_code: self.base_code = self.code
def load(self, reader): reader = BinaryIO.reader(reader) self.moves = [] while True: lvlmove = LevelMove(self.game, reader=reader) if lvlmove.is_end(): break else: self.moves.append(lvlmove)
def load(self): self.filenames = [] with self.game.open('arm9.dec.bin') as arm9: reader = BinaryIO.reader(arm9) reader.seek(self.game.file_system_table[1]) while True: offset = reader.readUInt32() if not offset: break with reader.seek(offset - 0x02000000): # TODO: BW ram ofs self.filenames.append(reader.readString())
def load(self, reader): """Loads a reader into this model Parameters ---------- reader : BinaryIO, string, file, other readable """ reader = BinaryIO.reader(reader) amount = ctypes.sizeof(self._data) data = reader.read(amount) self._data = self._type.from_buffer_copy(data) return self
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() Editable.load(self, reader) self.glyphs = [] # TODO: glyph reading self.glyphs = SizedCollection(Glyph().base_struct, length=self.num) self.glyphs.load(reader) self.widths = [] reader.seek(start + self.footer_offset) for i in range(self.num): self.widths.append(reader.readUInt8())
def load(self): with self.game.open('overlays_dez', 'overlay_{0:04}.bin'.format( self.game.type_effectiveness_table[0])) as handle: reader = BinaryIO.reader(handle) reader.seek(self.game.type_effectiveness_table[1]) while True: effect = TypeEffectiveness(self.game) effect.load(reader=reader) if effect.source_type == 0xFE and effect.target_type == 0xFE: break self.effectives.append(effect) self.length = len(self.effectives)
def load(self, reader): reader = BinaryIO.reader(reader) self.num_furniture = reader.readUInt32() self.furniture = [Furniture(reader=reader) for i in range(self.num_furniture)] self.num_overworlds = reader.readUInt32() self.overworlds = [Overworld(reader=reader) for i in range(self.num_overworlds)] self.num_warps = reader.readUInt32() self.warps = [Warp(reader=reader) for i in range(self.num_warps)] self.num_triggers = reader.readUInt32() self.triggers = [Trigger(reader=reader) for i in range(self.num_triggers)]
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() Editable.load(self, reader) assert self.magic == 'BMD0', 'Expected BMD0 got '.format(self.magic) block_offsets = [] for i in range(self.numblocks): block_offsets.append(reader.readUInt32()) reader.seek(start + block_offsets[0]) self.mdl.load(reader) if self.numblocks > 1: reader.seek(start + block_offsets[1]) self.tex.load(reader) self.tex.loaded = True else: self.tex.loaded = False
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() Editable.load(self, reader) assert self.magic == 'SDAT' for block_ofs, block in zip( self.block_offsets, [self.symb, self.info, self.fat, self.file]): if not block_ofs.block_offset: continue reader.seek(start + block_ofs.block_offset) block.load(reader) self.file.files = [] for entry in self.fat.entries: reader.seek(start + entry.start) self.file.files.append(reader.read(entry.stop - entry.start))
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() Editable.load(self, reader) self.records = {} for i, record_ofs in enumerate(self.record_offsets): if not record_ofs: continue reader.seek(start + record_ofs) num = reader.readUInt32() offsets = SizedCollection(self.uint32, length=num) offsets.load(reader=reader) first_entry = expected = reader.tell() - start template_entry = self.record_classes[i]() entry_size = template_entry.get_size() for offset in offsets.entries: if offset != expected: break else: entries = SizedCollection(template_entry.base_struct, length=num) entries.load(reader=reader) self.records[SYMB.record_names[i]] = entries continue adjusted_num = (max(offsets.entries[:] + [first_entry]) - first_entry) / entry_size + 1 entries = SizedCollection(template_entry.base_struct, length=adjusted_num) entries.load(reader=reader) new_entries = SizedCollection(self.record_classes[i]().base_struct, length=num) for idx, offset in enumerate(offsets.entries): if not offset: # what are these entries even? new_entries[idx].file_id = 0 continue target = (offset - first_entry) / entry_size new_entries[idx] = entries.entries[target] self.records[SYMB.record_names[i]] = new_entries
def from_bdf(self, handle): """Loads a BDF font file""" try: reader = BinaryIO.reader(handle) assert reader.readline().split(' ')[0] == 'STARTFONT' except: raise ValueError('Expected BDF handle to be loaded') table, rtable = load_table() startchar_re = re.compile('^STARTCHAR U?\+?([0-9A-F]+)') bbox_re = re.compile('^BBX ([0-9]+) ([0-9]+) (-?[0-9]+) (-?[0-9]+)') encoding_re = re.compile('^ENCODING (?:-1 )?([0-9]+)') bits_re = re.compile('^BITS_?PER_?PIXEL_? (1|2|4|8|16|32)') size_re = re.compile('^SIZE [0-9]+ [0-9]+ [0-9]+ ([0-9]+)') bpp = 1 while True: line = reader.readline() if line.startswith('CHARS'): num = int(line.strip('\n').split(' ')[1]) break match = size_re.match(line) if match: bpp = int(match.group(1)) continue entries = {} while num > 0: while True: line = reader.readline() match = startchar_re.match(line) if not match: continue ucode = int(match.group(1), 16) break entries[ucode] = entry = Glyph() ecode = None width = height = None x_ofs = 0 y_ofs = 0 while True: line = reader.readline() if line.startswith('ENDCHAR'): break if line.startswith('STARTCHAR'): # WARNING: Overflowed break match = encoding_re.match(line) if match: ecode = int(match.group(1)) continue match = bits_re.match(line) if match: bpp = int(match.group(1)) continue match = bbox_re.match(line) if match: width = int(match.group(1)) x_ofs = int(match.group(3)) height = int(match.group(2)) y_ofs = int(match.group(4)) if line.startswith('BITMAP'): if width is None: # WARNING: BBX not set continue if bpp != 2: # WARNING: not 2bpp continue if x_ofs != 0: # ??? pass for y in range(16 - height - y_ofs, 16): line = reader.readline() if line.startswith('ENDCHAR'): break entry.set_line(y, width, int(line, 16)) else: continue break num -= 1 num = len(entries) for ucode in entries: if ucode & 0xF000 == 0x8000: num = max(ucode - 0x7FFF, num) self.num = num self.glyphs = SizedCollection(Glyph().base_struct, length=num) for ucode in entries: if ucode & 0xF000 == 0x8000: glyph_id = ucode - 0x8000 else: glyph_id = rtable[unichr(ucode).encode('unicode-escape')] - 1 self.glyphs[glyph_id] = entries[ucode]._data
def load(self, reader): reader = BinaryIO.reader(reader) self.flag_ = reader.readUInt16() self.rot_00_fx16 = reader.readInt16() if self.flag_ & self.FLAG_NO_TRANSLATE: self.trans_x_fx32 = 0 self.trans_y_fx32 = 0 self.trans_z_fx32 = 0 else: self.trans_x_fx32 = reader.readInt32() self.trans_y_fx32 = reader.readInt32() self.trans_z_fx32 = reader.readInt32() if self.flag_ & self.FLAG_NO_ROTATE: for i in range(3): for j in range(3): setattr(self, 'rot_{0}{1}_fx16'.format(i, j), int(i == j) * 4096) elif self.flag_ & self.FLAG_NO_PIVOT: self.rot_01_fx16 = reader.readInt16() self.rot_02_fx16 = reader.readInt16() self.rot_10_fx16 = reader.readInt16() self.rot_11_fx16 = reader.readInt16() self.rot_12_fx16 = reader.readInt16() self.rot_20_fx16 = reader.readInt16() self.rot_21_fx16 = reader.readInt16() self.rot_22_fx16 = reader.readInt16() else: for i in range(3): for j in range(3): setattr(self, 'rot_{0}{1}_fx16'.format(i, j), int(i == j) * 4096) self.pivot_a_fx16 = reader.readInt16() self.pivot_b_fx16 = reader.readInt16() pivot = (self.flag_ >> 4) & 0xf if self.flag_ & self.FLAG_PIVOT_REVC: pivoc_c = -self.pivot_b_fx16 else: pivoc_c = self.pivot_b_fx16 if self.flag_ & self.FLAG_PIVOT_REVD: pivoc_d = -self.pivot_a_fx16 else: pivoc_d = self.pivot_a_fx16 if pivot == 0: self.rot_11_fx16 = self.pivot_a_fx16 self.rot_12_fx16 = self.pivot_b_fx16 self.rot_21_fx16 = pivoc_c self.rot_22_fx16 = pivoc_d elif pivot == 4: self.rot_00_fx16 = self.pivot_a_fx16 self.rot_02_fx16 = self.pivot_b_fx16 self.rot_20_fx16 = pivoc_c self.rot_22_fx16 = pivoc_d elif pivot == 8: self.rot_00_fx16 = self.pivot_a_fx16 self.rot_01_fx16 = self.pivot_b_fx16 self.rot_10_fx16 = pivoc_c self.rot_11_fx16 = pivoc_d else: raise NotImplementedError( 'Pivot {0} is not supported'.format(pivot)) if self.flag_ & self.FLAG_NO_SCALE: self.scale_x_fx32 = 4096 self.scale_y_fx32 = 4096 self.scale_z_fx32 = 4096 self.inv_scale_x_fx32 = 4096 self.inv_scale_y_fx32 = 4096 self.inv_scale_z_fx32 = 4096 else: self.scale_x_fx32 = reader.readInt32() self.scale_y_fx32 = reader.readInt32() self.scale_z_fx32 = reader.readInt32() self.inv_scale_x_fx32 = reader.readInt32() self.inv_scale_y_fx32 = reader.readInt32() self.inv_scale_z_fx32 = reader.readInt32()
def load(self, reader): reader = BinaryIO.reader(reader) start = reader.tell() self.data = reader.read(512) # Entire contents with reader.seek(start+0x156): self.code = self.base_code = reader.read(4)
def load_pokemon(self, reader): reader = BinaryIO.reader(reader) self.pokemon = [] for i in range(self.num_pokemon): self.pokemon.append(TrainerPokemon(self, reader=reader))