Exemplo n.º 1
0
def pakTransformPack(file):
    resources, _, encoding, version = ReadPak(file, True, True)
    if version == 4:
        newFile = UniFile(file[:file.rfind('.')] + '.v5.pak')
        print('Transform "' + file + '"(v4) to "' + newFile + '(v5).')
        WritePak(newFile, resources, encoding)
    elif version == 5:
        newFile = UniFile(file[:file.rfind('.')] + '.v4.pak')
        print('Transform "' + file + '"(v5) to "' + newFile + '(v4).')
        WritePakV4(newFile, resources, encoding)
Exemplo n.º 2
0
 def getUnknownName(type):
     ext = ''
     if len(content) > 6:
         head = content[:4]
         if head == b'\x89PNG':
             ext = '.png'
         elif head == b'"use':
             ext = '.js'
         elif head == b'RIFF':
             ext = '.avi'
         elif head == b'(fun':
             ext = '.js'
         elif head == b'<htm':
             ext = '.htm'
         elif head == b'<!DO' or head == b'<!do' or head == b'<!--':
             ext = '.htm'
         elif head[:2] == b'\x1f\x8b':
             ext = '.gz'
         elif content.find(b'function') != -1:
             ext = '.js'
         elif head[:1] == b'{':
             ext = '.json'
         elif head[:1] == b'<':
             ext = '.htm'
         elif content.find(b'width') != -1 or content.find(
                 b'styles') != -1 or content.find(
                     b'display') != -1 or content.find(
                         b'!important') != -1:
             ext = '.css'
     return UniFile(os.path.join(dirname, type, name + ext))
Exemplo n.º 3
0
def PakResAddByMerge(file):
    jsonFile = os.path.join(os.path.dirname(sys.argv[0]), 'pakResIds.json')
    inFile = open(jsonFile, 'r')
    ids = json.load(inFile)
    inFile.close()
    inFile = open(file, 'r')
    newIds = json.load(inFile)
    inFile.close()
    for name in newIds:
        ids[name] = os.path.relpath(newIds[name]).replace('\\', '/')
    outFile = open(UniFile(jsonFile), 'w')
    json.dump(ids, outFile, indent=4, ensure_ascii=False)
    outFile.close()
Exemplo n.º 4
0
def PakDataPack(file):
    oriFile = file[:file.rfind('_')]
    oriFilePos = oriFile.rfind('_')
    encoding = GetEncodingId(oriFile[oriFilePos + 1:])
    oriFile = oriFile[:oriFilePos] + '.pak'
    resources = {}
    for name in os.listdir(file):
        full = os.path.join(file, name)
        if (os.path.isfile(full)):
            inFile = open(full, 'rb')
            resources[int(name)] = inFile.read()
            inFile.close()
    WritePak(UniFile(oriFile), resources, encoding)
Exemplo n.º 5
0
def PakDataUnpack(file,hardLink=False):
    resources,aliases,encoding=ReadPak(file)
    dirname=UniFile(file[:file.rfind('.')]+'_'+Encodings[encoding]+'_data')
    os.mkdir(dirname)
    for id in resources:
        outFile=open(os.path.join(dirname,str(id)),'wb')
        outFile.write(resources[id])
        outFile.close()
    if hardLink:
        for id in aliases:
            os.link(os.path.join(dirname,str(aliases[id])),os.path.join(dirname,str(id)))
    else:
        for id in aliases:
            os.symlink(os.path.join(dirname,str(aliases[id])),os.path.join(dirname,str(id)))
Exemplo n.º 6
0
def PakLangUnpack(file):
    resources, aliases, encoding = ReadPak(file)
    merged = {}
    for id in resources:
        merged[id] = {
            'ids': [id],
            'text': resources[id].decode(Encodings[encoding])
        }
    for id in aliases:
        merged[aliases[id]]['ids'].append(id)
    listed = list(merged.values())
    listed.insert(0, {'encoding': Encodings[encoding]})
    outFile = open(UniFile(file[:file.rfind('.')] + '.json'),
                   'w',
                   encoding=Encodings[encoding])
    json.dump(listed, outFile, indent=4, ensure_ascii=False)
    outFile.close()
Exemplo n.º 7
0
def PakResAddByDir(file):
    jsonFile = os.path.join(os.path.dirname(sys.argv[0]), 'pakResIds.json')
    inFile = open(jsonFile, 'r')
    ids = json.load(inFile)
    inFile.close()
    for root, _, files in os.walk(file):
        for name in files:
            full = os.path.abspath(os.path.join(root, name))
            absName = os.path.relpath(full, file)
            if not (absName.startswith('unknown\\')
                    or absName.startswith('preAlias\\')
                    or absName.startswith('alias\\')):
                inFile = open(full, 'rb')
                ids[GetMd5(inFile.read())] = absName.replace('\\', '/')
                inFile.close()
    outFile = open(UniFile(jsonFile), 'w')
    json.dump(ids, outFile, indent=4, ensure_ascii=False)
    outFile.close()
Exemplo n.º 8
0
def PakLangPack(file):
    prencoding = 'UTF-8'
    inFile = open(file, 'r', encoding=prencoding)
    content = json.load(inFile)
    inFile.close()
    encoding = content[0]['encoding']
    iencoding = GetEncodingId(encoding)
    if encoding != prencoding:
        inFile = open(file, 'r', encoding=encoding)
        content = json.load(inFile)
        inFile.close()
    resources = {}
    content = content[1:]
    for info in content:
        data = info["text"].encode(encoding)
        for idx in info['ids']:
            resources[int(idx)] = data
    WritePak(UniFile(file[:file.rfind('.')] + '.pak'), resources, iencoding)
Exemplo n.º 9
0
def PakResLink(file, linkFull=False, linkAlias=False, hardLink=False):
    def link(src, dst):
        if hardLink:
            os.link(src, dst)
        else:
            os.symlink(src, dst)

    inFile = open(os.path.join(os.path.dirname(sys.argv[0]), 'pakResIds.json'),
                  'r')
    ids = json.load(inFile)
    inFile.close()
    dirname = UniFile(file[:file.rfind('_')] + '_link')
    os.mkdir(dirname)
    for name in os.listdir(file):
        full = os.path.abspath(os.path.join(file, name))
        inFile = open(full, 'rb')
        content = inFile.read()
        inFile.close()

        def getUnknownName(type):
            ext = ''
            if len(content) > 6:
                head = content[:4]
                if head == b'\x89PNG':
                    ext = '.png'
                elif head == b'"use':
                    ext = '.js'
                elif head == b'RIFF':
                    ext = '.avi'
                elif head == b'(fun':
                    ext = '.js'
                elif head == b'<htm':
                    ext = '.htm'
                elif head == b'<!DO' or head == b'<!do' or head == b'<!--':
                    ext = '.htm'
                elif head[:2] == b'\x1f\x8b':
                    ext = '.gz'
                elif content.find(b'function') != -1:
                    ext = '.js'
                elif head[:1] == b'{':
                    ext = '.json'
                elif head[:1] == b'<':
                    ext = '.htm'
                elif content.find(b'width') != -1 or content.find(
                        b'styles') != -1 or content.find(
                            b'display') != -1 or content.find(
                                b'!important') != -1:
                    ext = '.css'
            return UniFile(os.path.join(dirname, type, name + ext))

        if os.path.islink(full):
            if linkAlias:
                link(full, getUnknownName('alias'))
        else:
            md5 = GetMd5(content)
            if md5 in ids:
                newName = os.path.join(dirname, ids[md5])
                if os.path.exists(newName):
                    if linkAlias:
                        print(
                            '"' + newName +
                            '" has existed as a non alias file, save it to preAlias.'
                        )
                        link(full, getUnknownName('preAlias'))
                    else:
                        print('"' + newName +
                              '" has existed as a non alias file, ignore it.')
                else:
                    link(full, UniFile(newName))
            else:
                if linkFull:
                    print(name + '(' + md5 +
                          ') is not in res list, save it to unknwon')
                    link(full, getUnknownName('unknown'))
                else:
                    print(name + '(' + md5 +
                          ') is not in res list, ignore it.')