예제 #1
0
    def modelstoFakeLZO(self, path, tabPath, outBinPath, outTabPath):
        """Convert a model 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)
        tabCksum = 0
        while True:
            offs    = tabFile.readu32()
            if offs == 0xFFFFFFFF: break
            high = offs & 0xFF000000
            if high & 0x10000000:
                #printf("Model %08X\r\n", offs)
                offs = offs & 0xFFFFFF
                inFile.seek(offs)

                data = inFile.read(4)
                if data == b'\xFA\xCE\xFE\xED':
                    while data not in (b'ZLB\0', b'DIR\0', b'\xE0\xE0\xE0\xE0', b'\xF0\xF0\xF0\xF0'):
                        outBin.write(data)
                        data = inFile.read(4)
                inFile.seek(offs)

                data = inZlb.decompress()
                header = b'ZLB\0' + struct.pack('>3I', 1, len(data), len(data)) + b'Rena'
                data = header + data
                tabVal = outBin.tell() | high
                outBin.write(data)
                while outBin.tell() & 0xF: outBin.writeu8(0)

            else: # don't use this model
                tabVal = 0x00000000
            tabCksum += ((tabVal >> 24) & 0xFF)
            tabCksum += ((tabVal >> 16) & 0xFF)
            tabCksum += ((tabVal >>  8) & 0xFF)
            tabCksum += ( tabVal        & 0xFF)
            outTab.writeu32(tabVal)

        tabVal = outBin.tell()
        outTab.writeu32(tabVal)
        tabCksum += ((tabVal >> 24) & 0xFF)
        tabCksum += ((tabVal >> 16) & 0xFF)
        tabCksum += ((tabVal >>  8) & 0xFF)
        tabCksum += ( tabVal        & 0xFF)

        outTab.writeu32(0xFFFFFFFF)
        tabCksum += (0xFF * 4)
        outTab.writeu32(tabCksum & 0xFFFFFFFF)
        for i in range(7):
            outTab.writeu32(0)
예제 #2
0
    def textoDIR(self, path, tabPath, outBinPath, outTabPath):
        """Convert a texture file's contents to uncompressed DIR 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)
        tabCksum = 0
        while True:
            offs    = tabFile.readu32()
            if offs == 0xFFFFFFFF: break
            high = offs & 0xFF000000
            if high & 0x80000000:
                offs = (offs & 0xFFFFFF) * 2
                nFrames = (high >> 24) & 0x3F
                inFile.seek(offs)

                # read frame values
                if nFrames > 1: frameData = inFile.readu32(nFrames+1)
                else: frameData = []

                data = inZlb.decompress()
                #data = b'\0\0\0\0' + b'\0\0\0\0' + b'\0\0\0\0' + data
                dl = len(data)
                header = b'DIR\0' + struct.pack('>3I', 0, dl, dl)
                header += b'\0\0\0\0' + b'\0\0\0\0' + b'\0\0\0\0' + b'\0\0\0\0'
                data = header + data
                tabVal = (outBin.tell() >> 1) | high
                if nFrames > 1: outBin.writeu32(*frameData)
                outBin.write(data)
                while outBin.tell() & 0xF: outBin.writeu8(0)

            else: # don't use this texture
                tabVal = 0x01000000
            tabCksum += ((tabVal >> 24) & 0xFF)
            tabCksum += ((tabVal >> 16) & 0xFF)
            tabCksum += ((tabVal >>  8) & 0xFF)
            tabCksum += ( tabVal        & 0xFF)
            outTab.writeu32(tabVal)
        outTab.writeu32(0xFFFFFFFF)
        tabCksum += (0xFF * 4)
        outTab.writeu32(tabCksum & 0xFFFFFFFF)
        for i in range(7):
            outTab.writeu32(0)
예제 #3
0
    def textoLZO(self, path, tabPath, outBinPath, outTabPath):
        """Convert a texture file's contents to LZO.

        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)
        outLzo  = DPLZO(outBin)
        tabCksum = 0
        while True:
            offs    = tabFile.readu32()
            if offs == 0xFFFFFFFF: break
            high = offs & 0xFF000000
            if high & 0x80000000:
                offs = (offs & 0xFFFFFF) * 2
                nFrames = (high >> 24) & 0x3F
                inFile.seek(offs)

                # read frame values
                if nFrames > 1: frameData = inFile.readu32(nFrames+1)
                else: frameData = []

                data = outLzo.compress(inZlb.decompress())
                tabVal = (outBin.tell() >> 1) | (high & 0xC0000000) | ((nFrames-1) << 24)
                if nFrames > 1: outBin.writeu32(*frameData)
                outBin.write(data)
                while outBin.tell() & 0xF: outBin.writeu8(0)

            else: # don't use this texture
                tabVal = 0x01000000
            tabCksum += ((tabVal >> 24) & 0xFF)
            tabCksum += ((tabVal >> 16) & 0xFF)
            tabCksum += ((tabVal >>  8) & 0xFF)
            tabCksum += ( tabVal        & 0xFF)
            outTab.writeu32(tabVal)
        outTab.writeu32(0xFFFFFFFF)
        tabCksum += (0xFF * 4)
        outTab.writeu32(tabCksum & 0xFFFFFFFF)
        for i in range(7):
            outTab.writeu32(0)