示例#1
0
    def save(self, writer=None):
        writer = writer if writer is not None else BinaryIO()
        start = writer.tell()
        writer.write(self.magic)
        size_ofs = writer.tell()
        writer.writeUInt32(0)
        writer = self.texinfo.save(writer)
        writer = self.tex4x4info.save(writer)
        writer = self.palinfo.save(writer)

        writer.writeAlign(4)
        ofs = writer.tell() - start
        with writer.seek(self.texinfo._lookupofs_ofs):
            writer.writeUInt16(ofs)
        for i in xrange(self.texdict.num):
            texparam = self.texparams[i]
            self.texdict.data[i] = \
                struct.pack('II',
                            (texparam.ofs >> 3) |
                            ((log2(texparam.width >> 3)) << 20) |
                            ((log2(texparam.height >> 3)) << 23) |
                            (texparam.format << 26) |
                            (texparam.color0 << 29), 0)
        writer = self.texdict.save(writer)

        writer.writeAlign(4)
        ofs = writer.tell() - start
        with writer.seek(self.palinfo._lookupofs_ofs):
            writer.writeUInt16(ofs)
        for i in xrange(self.paldict.num):
            param = self.palparams[i]
            self.paldict.data[i] = struct.pack('HH', param.ofs, param.count4)
        writer = self.paldict.save(writer)

        writer.writeAlign(8)
        ofs = writer.tell() - start
        with writer.seek(self.texinfo._dataofs_ofs):
            writer.writeUInt32(ofs)  # texinfo dataofs
        datastart = writer.tell()
        writer.write(self.texdata)
        writer.writeAlign(8)
        size = writer.tell() - datastart
        with writer.seek(self.texinfo._datasize_ofs):
            writer.writeUInt16(size >> 3)  # texinfo datasize

        writer.writeAlign(8)
        ofs = writer.tell() - start
        with writer.seek(self.palinfo._dataofs_ofs):
            writer.writeUInt32(ofs)  # palinfo dataofs
        datastart = writer.tell()
        writer.write(self.paldata)
        writer.writeAlign(8)
        size = writer.tell() - datastart
        with writer.seek(self.palinfo._datasize_ofs):
            writer.writeUInt16(size >> 3)  # palinfo datasize

        return writer
示例#2
0
 def test_texparams(self):
     default = TEX()
     default.texdict.num = 1
     default.texparams = [TexParam(0, 16, 16, 3, 0)]
     default.texdict.names.append('test1')
     out = default.save().getvalue()
     new = TEX()
     new.load(BinaryIO(out))
     self.assertEqual(default.texparams, new.texparams)
示例#3
0
 def test_default(self):
     default = G3DResDict()
     default.data.append('\x00' * 4)
     default.names.append('testing')
     default.nodes.append(Node(1, 2, 3, 4))
     out = default.save().getvalue()
     new = G3DResDict()
     new.load(BinaryIO(out))
     self.assertEqual(default.data, new.data)
     self.assertEqual(default.sizeunit, new.sizeunit)
     self.assertEqual(default.names, new.names)
     self.assertEqual(default.nodes, new.nodes)
示例#4
0
 def save(self, writer=None):
     """
     When writing the general structure, it saves offsets
     to unknown values. It is the duty of the parent to
     fill these in
     """
     writer = writer if writer is not None else BinaryIO()
     writer.writeUInt32(self.vramkey)
     self._datasize_ofs = writer.tell()
     writer.writeUInt16(0)  # datasize
     if self.infotype != TexInfo.INFO_PAL:
         self._lookupofs_ofs = writer.tell()
         writer.writeUInt16(0)
     writer.writeUInt16(0)
     if self.infotype == TexInfo.INFO_PAL:
         self._lookupofs_ofs = writer.tell()
         writer.writeUInt16(0)
     writer.writeUInt16(8)
     self._dataofs_ofs = writer.tell()
     writer.writeUInt32(0)
     if self.infotype == TexInfo.INFO_TEX4X4:
         writer.writeUInt32(0)
     return writer
示例#5
0
 def save(self, writer=None):
     if writer is None:
         writer = BinaryIO()
     start = writer.tell()
     writer.writeUInt8(self.version)
     num = len(self.data)
     writer.writeUInt8(num)
     sizeofs = writer.tell()
     writer.writeUInt16(0)
     writer.writeUInt16(8)
     writer.writeUInt16(0)  # refofs
     for i in xrange(num):
         # TODO: Build PTree. Although it isn't actually used
         try:
             node = self.nodes[i]
         except:
             node = Node(0, 0, 0, 0)
         for j in xrange(4):
             writer.writeUInt8(node[j])
     writer.writeAlign(4)
     namerel = writer.tell()
     refofs = namerel - start
     writer.writeUInt16(self.sizeunit)
     nameofsofs = writer.tell()
     writer.writeUInt16(0)
     for i in xrange(num):
         writer.write(self.data[i])
         if len(self.data[i]) < self.sizeunit:
             writer.write('\x00' * (self.sizeunit - len(self.data[i])))
     nameofs = writer.tell() - namerel
     with writer.seek(nameofsofs):
         writer.writeUInt16(nameofs)
     nameofs = writer.tell()
     for i in xrange(num):
         writer.write(self.names[i])
         writer.writePadding(nameofs + i * 16)
     size = writer.tell() - start
     with writer.seek(sizeofs):
         writer.writeUInt16(size)
         writer.writeUInt16(8)
         writer.writeUInt16(refofs)
     return writer
示例#6
0
 def get_value(self):
     """String of this Archive"""
     writer = BinaryIO()
     return self.save(writer).getvalue()
示例#7
0
 def test_default(self):
     default = Personal()
     out = default.save().getvalue()
     new = Personal()
     new.load(BinaryIO(out))
     self.assertEqual(out, new.save().getvalue())
示例#8
0
 def test_gen5(self):
     default = Personal(version=Personal.BLACK)
     out = default.save().getvalue()
     new = Personal(version=Personal.BLACK)
     new.load(BinaryIO(out))
     self.assertEqual(out, new.save().getvalue())
示例#9
0
 def save(self, writer=None):
     if writer is None:
         writer = BinaryIO()
     start = writer.tell()
     writer.write(self.magic)
     sizeofs = writer.tell()
     writer.writeUInt32(0)
     writer.writeUInt16(self.num)
     writer.writeUInt16(0)
     for entry in self.entries:
         writer.writeUInt32(entry.start)
         writer.writeUInt32(entry.stop)
     size = writer.tell()-start
     with writer.seek(sizeofs):
         writer.writeUInt32(size)
     return writer
示例#10
0
 def save(self, writer=None):
     if writer is None:
         writer = BinaryIO()
     start = writer.tell()
     writer.write(self.magic)
     writer.writeUInt16(self.endian)
     writer.writeUInt16(self.version)
     sizeofs = writer.tell()
     writer.writeUInt32(0)
     headersizeofs = writer.tell()
     writer.writeUInt16(0)
     writer.writeUInt16(self.numblocks)
     size = writer.tell()-start
     with writer.seek(headersizeofs):
         writer.writeUInt16(size)
     writer = self.fatb.save(writer)
     writer = self.fntb.save(writer)
     writer = self.fimg.save(writer)
     writer.writeUInt32(0)
     size = writer.tell()-start
     with writer.seek(sizeofs):
         writer.writeUInt32(size)
     return writer
示例#11
0
 def save(self, writer=None):
     if writer is None:
         writer = BinaryIO()
     start = writer.tell()
     writer.write(self.magic)
     sizeofs = writer.tell()
     writer.writeUInt32(0)
     data = []
     for fdata, entry in zip(self.files, self.narc.fatb.entries):
         total = len(data)
         if entry.start > total:
             data += '\x00'*(entry.start-total)
         data[entry] = fdata
     writer.write(''.join(data))
     size = writer.tell()-start
     with writer.seek(sizeofs):
         writer.writeUInt32(size)
     return writer
示例#12
0
 def save(self, writer=None):
     if writer is None:
         writer = BinaryIO()
     start = writer.tell()
     writer.write(self.magic)
     sizeofs = writer.tell()
     writer.writeUInt32(0)
     writer.writeUInt32(4)
     writer.writeUInt32(0x10000)
     size = writer.tell()-start
     with writer.seek(sizeofs):
         writer.writeUInt32(size)
     return writer
示例#13
0
 def save(self, writer=None):
     if writer is None:
         writer = BinaryIO()
     start = writer.tell()
     writer.writeUInt8(self.version)
     num = len(self.data)
     writer.writeUInt8(num)
     sizeofs = writer.tell()
     writer.writeUInt16(0)
     writer.writeUInt16(8)
     writer.writeUInt16(0)  # refofs
     for i in xrange(num):
         # TODO: Build PTree. Although it isn't actually used
         try:
             node = self.nodes[i]
         except:
             node = Node(0, 0, 0, 0)
         for j in xrange(4):
             writer.writeUInt8(node[j])
     writer.writeAlign(4)
     namerel = writer.tell()
     refofs = namerel-start
     writer.writeUInt16(self.sizeunit)
     nameofsofs = writer.tell()
     writer.writeUInt16(0)
     for i in xrange(num):
         writer.write(self.data[i])
         if len(self.data[i]) < self.sizeunit:
             writer.write('\x00'*(self.sizeunit-len(self.data[i])))
     nameofs = writer.tell()-namerel
     with writer.seek(nameofsofs):
         writer.writeUInt16(nameofs)
     nameofs = writer.tell()
     for i in xrange(num):
         writer.write(self.names[i])
         writer.writePadding(nameofs+i*16)
     size = writer.tell()-start
     with writer.seek(sizeofs):
         writer.writeUInt16(size)
         writer.writeUInt16(8)
         writer.writeUInt16(refofs)
     return writer
示例#14
0
 def test_texinfo(self):
     default = TexInfo(None)
     out = default.save().getvalue()
     new = TexInfo(None)
     new.load(BinaryIO(out))
     self.assertEqual(out, new.save().getvalue())
示例#15
0
 def test_default(self):
     default = TEX()
     out = default.save().getvalue()
     new = TEX()
     new.load(BinaryIO(out))
     self.assertEqual(default.texparams, new.texparams)