Beispiel #1
0
 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
Beispiel #2
0
    def load(self, reader):
        start = reader.tell()
        Editable.load(self, reader)
        self.matdict.load(reader)
        reader.seek(start + self.texmatdict_offset)
        self.texmatdict.load(reader)
        reader.seek(start + self.palmatdict_offset)
        self.palmatdict.load(reader)

        self.materials = []
        self.tex_map = {}
        self.pal_map = {}

        for i in range(self.texmatdict.num):
            idx_ofs, idx_num, bound = struct.unpack('HBB',
                                                    self.texmatdict.data[i])
            reader.seek((idx_ofs & 0xFFFF) + start)
            for j in range(idx_num):
                idx = reader.readUInt8()
                if idx in self.tex_map and not bound:
                    continue
                self.tex_map[idx] = i
        for i in range(self.palmatdict.num):
            idx_ofs, idx_num, bound = struct.unpack('HBB',
                                                    self.palmatdict.data[i])
            reader.seek((idx_ofs & 0xFFFF) + start)
            for j in range(idx_num):
                idx = reader.readUInt8()
                if idx in self.pal_map and not bound:
                    continue
                self.pal_map[idx] = i
        for i in range(self.matdict.num):
            ofs, = struct.unpack('I', self.matdict.data[i])
            reader.seek(ofs + start)
            self.materials.append(Material(reader=reader))
Beispiel #3
0
 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
Beispiel #4
0
    def load(self, reader):
        Editable.load(self, reader)

        if self.flag_ & self.FLAG_NO_SCALE:
            self.scale_s_fx32 = 4096
            self.scale_t_fx32 = 4096
        else:
            self.scale_s_fx32 = reader.readInt32()
            self.scale_t_fx32 = reader.readInt32()

        if self.flag_ & self.FLAG_NO_ROTATE:
            self.rot_sin_fx32 = 0
            self.rot_cos_fx32 = 0
        else:
            self.rot_sin_fx32 = reader.readInt32()
            self.rot_cos_fx32 = reader.readInt32()

        if self.flag_ & self.FLAG_NO_TRANSLATE:
            self.trans_s_fx32 = 0
            self.trans_t_fx32 = 0
        else:
            self.trans_s_fx32 = reader.readInt32()
            self.trans_t_fx32 = reader.readInt32()

        if self.flag_ & self.FLAG_EFFECT_MATRIX:
            self.effect = [reader.readInt32() for i in range(16)]
Beispiel #5
0
 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)
Beispiel #6
0
    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)
Beispiel #7
0
 def load(self, reader):
     Editable.load(self, reader)
     self.entries = []
     for i in range(self.num):
         start = reader.readUInt32()
         stop = start + reader.readUInt32()
         reader.read(8)
         self.entries.append(slice(start, stop))
Beispiel #8
0
 def load(self, reader):
     Editable.load(self, reader)
     if self.trainer.hold_items:
         self.item = reader.readUInt16()
     if self.trainer.movesets:
         self.moves = [reader.readUInt16() for i in range(4)]
     if self.trainer.game.is_hgss():
         self.seal_capsule = reader.readUInt16()
     return self
Beispiel #9
0
 def load(self, reader):
     Editable.load(self, reader)
     assert self.magic == 'RGCN', 'Expected RGCN got '.format(self.magic)
     self.char.load(reader)
     if self.numblocks > 1:
         self.cpos.load(reader)
         self.cpos.loaded = True
     else:
         self.cpos.loaded = False
Beispiel #10
0
 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
Beispiel #11
0
 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())
Beispiel #12
0
 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
Beispiel #13
0
 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))
Beispiel #14
0
    def load(self, reader):
        start = reader.tell()
        Editable.load(self, reader)

        self.nodes.load(reader)
        assert self.nodes.nodedict.num == self.num_nodes

        self.sbc = []
        reader.seek(start + self.sbc_offset)
        for i in range(self.mat_offset - self.sbc_offset):
            self.sbc.append(reader.readUInt8())  # SBC

        reader.seek(start + self.mat_offset)
        self.materials.load(reader)
        assert self.materials.matdict.num == self.num_materials,\
            (self.materials.matdict.num, self.num_materials)

        reader.seek(start + self.shp_offset)
        self.shapes.load(reader)
        assert self.shapes.shapedict.num == self.num_shapes
Beispiel #15
0
    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
Beispiel #16
0
 def load(self, reader):
     start = reader.tell()
     Editable.load(self, reader)
     reader.seek(start + self.size_)
Beispiel #17
0
 def load(self, reader):
     Editable.load(self, reader)
     self.data = reader.read(self.datasize)
     if self.cgr.encryption != NCGR.ENCRYPTION_NONE:
         self.decrypt(self.cgr.encryption)
Beispiel #18
0
 def load(self, reader):
     Editable.load(self, reader)
     self.mdldict.load(reader)
     self.models = []
     for idx in range(self.mdldict.num):
         self.models.append(Model(reader=reader))
Beispiel #19
0
 def load(self, reader):
     Editable.load(self, reader)
     self.abnk.load(reader)
     self.labl.load(reader)
Beispiel #20
0
 def load(self, reader):
     Editable.load(self, reader)
     self.entries = SizedCollection(InfoGROUPEntry().base_struct,
                                    length=self.num)