Пример #1
0
 def listAnimations(self, discRoot, modelId):
     """List the animation IDs used by given model."""
     modelId = int(modelId, 0)
     modAnimTab = BinaryFile(discRoot+'/MODANIM.TAB', 'rb')
     modAnimOffs = modAnimTab.readu16(modelId << 1)
     nextOffs = modAnimTab.readu16((modelId+1) << 1)
     nAnims = (nextOffs - modAnimOffs) >> 1
     modAnimBin = BinaryFile(discRoot+'/MODANIM.BIN', 'rb')
     animIds = modAnimBin.readBytes(nAnims*2, modAnimOffs)
     animIds = struct.unpack('>%dh' % nAnims, animIds)
     printf("%4d animations; MODANIM.BIN 0x%06X - 0x%06X, min 0x%04X max 0x%04X\n",
         nAnims, modAnimOffs, modAnimOffs+(nAnims*2),
         max(0, min(animIds)), max(animIds))
     for i in range(0, nAnims, 8):
         printf('%04X: %s\n', i,
         ' '.join(map(lambda v: '%04X' % (v&0xFFFF), animIds[i:i+8])))
Пример #2
0
    def mapstoFakeLZO(self, path, tabPath, outBinPath, outTabPath):
        """Convert MAPS.BIN file's contents to "fake LZO" format.

        path: input file to convert.
        tabPath: table for input file.
        outBinPath: output path for .bin file.
        outTabPath: output path for .tab file.
        """
        inFile  = BinaryFile(path,       'rb')
        tabFile = BinaryFile(tabPath,    'rb')
        outBin  = BinaryFile(outBinPath, 'wb')
        outTab  = BinaryFile(outTabPath, 'wb')
        inZlb   = Zlb(inFile)
        offs    = tabFile.readu32()
        while offs != 0xFFFFFFFF:
            nextOffs = tabFile.readu32()
            inLen    = nextOffs - offs
            inFile.seek(offs)

            tabVal = outBin.tell()
            outTab.writeu32(tabVal)

            while offs < nextOffs:
                inFile.seek(offs)
                data = inFile.read(4)
                if len(data) == 0: break
                elif data == b'\xFA\xCE\xFE\xED':
                    rawLen, zlbOffs, compLen = inFile.readStruct('3I')
                    dOut = data + struct.pack('>3I', rawLen+0x28, zlbOffs, rawLen+4)
                    printf("Write FACEFEED at %08X: %s\r\n", outBin.tell(),
                        dOut.hex())
                    outBin.write(dOut)
                    for i in range(zlbOffs):
                        outBin.writeu16(inFile.readu16())
                    offs += len(data)
                elif data == b'ZLB\0':
                    inFile.seek(offs)
                    data = inZlb.decompress()
                    dl   = len(data) + 4
                    outBin.write(b'LZO\0' + struct.pack('3I', 0, 0, dl) + b'Rena' + data)
                else:
                    outBin.write(data)
                offs = inFile.tell()
            offs = nextOffs

        tabVal = outBin.tell()
        outTab.writeu32(tabVal)
        outTab.writeu32(0xFFFFFFFF)
        for i in range(3):
            outTab.writeu32(0)