decrypt_filename

 avatar
unknown
plain_text
a year ago
1.8 kB
14
Indexable
import os
import shutil
import re

def unpack_files(filemap_path='./src/nefi.txt', res_dir='./dat', out_dir='./game'):
    # Regex tìm dòng dạng: fileUtils:setNewFilename('res/ui/loading.json','d271f9f01545f5569ccf102aee1a43ae.dat')
    pattern = re.compile(r"fileUtils:setNewFilename\('(.+?)','([a-f0-9]{32})(?:\.(dat|DAT))?'\)")
    
    if not os.path.exists(filemap_path):
        print(f"[ERR] Không tìm thấy {filemap_path}")
        return

    with open(filemap_path, 'r', encoding='utf-8') as f:
        lines = f.readlines()

    count_ok = 0
    count_fail = 0

    for line in lines:
        match = pattern.search(line)
        if not match:
            continue

        original_file, hashed_file, ext = match.groups()

        # Ưu tiên đuôi đúng, nếu không có thì thử thêm .dat / .DAT
        possible_names = []
        if ext:
            possible_names.append(f"{hashed_file}.{ext}")
        else:
            possible_names.extend([f"{hashed_file}.dat", f"{hashed_file}.DAT"])

        # Tìm file đầu tiên tồn tại
        src = None
        for name in possible_names:
            candidate = os.path.join(res_dir, name)
            if os.path.exists(candidate):
                src = candidate
                break

        if not src:
            print(f"[MISSING] {hashed_file}")
            count_fail += 1
            continue

        dst = os.path.join(out_dir, original_file)
        os.makedirs(os.path.dirname(dst), exist_ok=True)
        shutil.copy2(src, dst)
        print(f"[OK] {original_file} <- {os.path.basename(src)}")
        count_ok += 1

    print(f"\n DONE: {count_ok} file ok, {count_fail} thiếu")

if __name__ == '__main__':
    unpack_files()
Editor is loading...
Leave a Comment