Esempio n. 1
0
 def save(self):
     with self.game.open('overlays_dez',
                         'overlay_{0:04}.bin'.format(
                             self.game.overworld_sprite_table[0]),
                         mode='r+') as handle:
         writer = BinaryIO.writer(handle)
         writer.seek(self.game.overworld_sprite_table[1])
         Editable.save(self, writer)
Esempio n. 2
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     writer = Editable.save(self, writer)
     writer = self.scrn.save(writer)
     size = writer.tell() - start
     with writer.seek(start + self.get_offset('size_')):
         writer.writeUInt32(size)
     return writer
Esempio n. 3
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     self.mdldict.num = len(self.models)
     writer = Editable.save(self, writer)
     writer = self.mdldict.save(writer)
     for i in range(self.mdldict.num):
         writer = self.models[i].save(writer)
     size = writer.tell() - start
     with writer.seek(start + self.get_offset('size_')):
         writer.writeUInt32(size)
     return writer
Esempio n. 4
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     self.num = len(self.glyphs)
     base_glyph = Glyph()
     self.footer_offset = base_glyph.get_size() * self.num + self.headersize
     writer = Editable.save(self, writer)
     writer = self.glyphs.save(writer)
     self.widths = [0] * self.num
     for i, glyph in enumerate(self.glyphs):
         self.widths[i] = width = glyph.get_bbox()[0]
         writer.writeUInt8(width)
     return writer
Esempio n. 5
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     writer = Editable.save(self, writer)
     if self.game.is_hgss():
         writer.write(self.block1)
         self.ublock1_size = len(self.block1)
     writer = self.permissions.save(writer)
     self.permission_size = self.permissions.get_size()
     writer = self.objects.save(writer)
     self.objects_size = self.objects.get_size()
     writer.write(self.bmd)
     self.bmd_size = len(self.bmd)
     writer.write(self.bdhc)
     self.bdhc_size = len(self.bdhc)
     with writer.seek(start):
         Editable.save(self, writer)
     return writer
Esempio n. 6
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     self.num_furniture = len(self.furniture)
     self.num_overworlds = len(self.overworlds)
     self.num_warps = len(self.warps)
     self.num_triggers = len(self.triggers)
     writer.writeUInt32(self.num_furniture)
     for furniture in self.furniture:
         writer = furniture.save(writer)
     writer.writeUInt32(self.num_overworlds)
     for overworld in self.overworlds:
         writer = overworld.save(writer)
     writer.writeUInt32(self.num_warps)
     for warp in self.warps:
         writer = warp.save(writer)
     writer.writeUInt32(self.num_triggers)
     for trigger in self.triggers:
         writer = trigger.save(writer)
     return writer
Esempio n. 7
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     writer = Editable.save(self, writer)
     for record_idx, record_name in enumerate(self.record_names):
         self.record_offsets[record_idx] = writer.tell() - start
         if record_name == 'SEQARC':
             prefixes = set()
             offsets = []
             for entry in self.records[record_name]:
                 if entry[0] == record_name:
                     prefixes.add(entry[1])
             writer.writeUInt32(len(prefixes))
             ofs_ofs = writer.tell()
             for i in range(len(prefixes) * 2):
                 writer.writeUInt32(0)
             for name in prefixes:
                 offsets.append(writer.tell() - start)
                 writer.writeString(name)
                 writer.writeAlign(8)
                 offsets.append(writer.tell() - start)
                 num, text_writer = self.save_entries(
                     self.records[record_name],
                     writer.tell() - start + 4, (record_name, name))
                 writer.writeUInt32(num)
                 writer.write(text_writer.getvalue())
             with writer.seek(ofs_ofs):
                 writer.write(array.array('I', offsets).tostring())
         else:
             num, text_writer = self.save_entries(self.records[record_name],
                                                  writer.tell() - start + 4,
                                                  (record_name, ))
             writer.writeUInt32(num)
             writer.write(text_writer.getvalue())
         writer.writeAlign(8)
     self.size = writer.tell() - start
     with writer.seek(start):
         writer = Editable.save(self, writer)
     return writer
Esempio n. 8
0
 def save(self, writer=None):
     for name, data in self.files.iteritems():
         name = os.path.splitext(name)[0]
         name_parts = name.split('/')
         record_name = name_parts.pop(0)
         if name_parts not in self.symb.records[record_name]:
             self.symb.records[record_name].append(name_parts)
             # TODO: handle new info entries?!
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     writer = Editable.save(self, writer)
     for block_ofs, block in zip(
             self.block_offsets,
         [self.symb, self.fat, self.info, self.file]):
         block_ofs.block_offset = writer.tell() - start
         writer = block.save(writer)
         writer.writeAlign(4)
         block_ofs.block_size = writer.tell(
         ) - start - block_ofs.block_offset
     with writer.seek(start):
         writer = Editable.save(self, writer)
     return writer
Esempio n. 9
0
 def save(self, writer):
     writer = BinaryIO.writer(writer)
     flag = self.flag
     writer.writeUInt16(flag)
     writer.writeInt16(self.rot_00_fx16)
     if not (self.flag & self.FLAG_NO_TRANSLATE):
         writer.writeInt32(self.trans_x_fx32)
         writer.writeInt32(self.trans_y_fx32)
         writer.writeInt32(self.trans_z_fx32)
     if not (self.flag & self.FLAG_NO_ROTATE):
         writer.writeInt16(self.rot_01_fx16)
         writer.writeInt16(self.rot_02_fx16)
         writer.writeInt16(self.rot_10_fx16)
         writer.writeInt16(self.rot_11_fx16)
         writer.writeInt16(self.rot_20_fx16)
         writer.writeInt16(self.rot_21_fx16)
         writer.writeInt16(self.rot_22_fx16)
     if not (self.flag & self.FLAG_NO_SCALE):
         try:
             self.inv_scale_x = 1 / self.scale_x
         except ZeroDivisionError:
             self.inv_scale_x = 0.0
         try:
             self.inv_scale_y = 1 / self.scale_y
         except ZeroDivisionError:
             self.inv_scale_y = 0.0
         try:
             self.inv_scale_z = 1 / self.scale_z
         except ZeroDivisionError:
             self.inv_scale_z = 0.0
         writer.writeInt32(self.scale_x_fx32)
         writer.writeInt32(self.scale_y_fx32)
         writer.writeInt32(self.scale_z_fx32)
         writer.writeInt32(self.inv_scale_x_fx32)
         writer.writeInt32(self.inv_scale_y_fx32)
         writer.writeInt32(self.inv_scale_z_fx32)
     return writer
Esempio n. 10
0
 def save(self, writer=None):
     if self.tex.loaded:
         self.numblocks = 2
     else:
         self.numblocks = 1
     writer = BinaryIO.writer(writer)
     start = writer.tell()
     writer = Editable.save(self, writer)
     offset_offset = writer.tell()
     for i in range(self.numblocks):
         writer.writeUInt32(0)
     block_ofs = writer.tell() - start
     with writer.seek(offset_offset):
         writer.writeUInt32(block_ofs)
     writer = self.mdl.save(writer)
     if self.tex.loaded:
         block_ofs = writer.tell() - start
         with writer.seek(offset_offset + 4):
             writer.writeUInt32(block_ofs)
         writer = self.tex.save(writer)
     size = writer.tell() - start
     with writer.seek(start + self.get_offset('size_')):
         writer.writeUInt32(size)
     return writer
Esempio n. 11
0
 def save(self, writer=None):
     writer = BinaryIO.writer(writer)
     for lvlmove in self.moves:
         writer = lvlmove.save(writer)
     writer = LevelMove.end(self.game).save(writer)
     return writer