def update_fif_data(fif_path, base, text_json_file, narc_tmp_path, font,
                    alternative_font, imagemagick_convert_path):
    index = int(basename(fif_path)[len(f"{base}English_"):][:2], base=10)
    fif_base = fif_path[:-len(".fif.json")]
    font_rel_size = 0
    font_top_margin = 0
    if 'adv_menu' in abspath(fif_path).split(sep)[-1]:
        font_rel_size = -5
        font_top_margin = 4
    if 'staff_roll' in abspath(fif_path).split(sep)[-1]:
        font_rel_size = -9
        font_top_margin = 5
    fif_command = f"python generate_font_data.py {text_json_file} {narc_tmp_path} {fif_base} -f {fif_path} -g {font} -a {alternative_font} -i {index} --font_rel_size {font_rel_size} --font_top_margin {font_top_margin}"
    print(f"[-] Generate fif file and font images from {fif_path}...")
    # print(fif_command)
    process = Popen(fif_command, stdout=PIPE, stderr=PIPE)
    print_process(process, CONSOLE_ENCODING)

    ddss = glob.glob(path_join(narc_tmp_path, "**",
                               f"{fif_base}_[0-9][0-9].dds"),
                     recursive=True)
    for dds in ddss:
        print(f"[-] Remove old dds file {dds}...")
        remove(dds)

    pngs = glob.glob(path_join(narc_tmp_path, "**",
                               f"{fif_base}_[0-9][0-9].dds.png"),
                     recursive=True)
    for png in pngs:
        convert_png_to_dds(png, imagemagick_convert_path)
Exemplo n.º 2
0
def mtx_to_json(json_file, mtx_to_json_path):
    if json_file.endswith(".fif.json"):
        return
    print(f"[-] Converting {json_file} to mtx")
    process = Popen(
        f"{mtx_to_json_path} {json_file}", stdout=PIPE, stderr=PIPE
    )
    print_process(process, CONSOLE_ENCODING)
def convert_png_to_dds(png_path, imagemagick_convert_path, dds_path=None):
    if dds_path is None:
        dds_path = png_path[:-len(".png")]
    if isfile(dds_path):
        print(f"[-] Remove old dds file {dds_path}...")
        remove(dds_path)
    print(f"[-] Convert png file {png_path} to dds...")
    process = Popen(
        f"{imagemagick_convert_path} -define dds:compression=dxt5 {png_path} {dds_path}",
        stdout=PIPE,
        stderr=PIPE,
    )
    print_process(process, CONSOLE_ENCODING)
def generate_tppk(original_path, tppk_tool_path):
    print(f"[-] Generate tppk file from {original_path}...")
    temp_dir = path_join(TEMP_DIR_PAR, str(UUID(bytes=urandom(16), version=4)))
    makedirs(abspath(temp_dir), exist_ok=True)
    for item in listdir(original_path):
        if item.endswith(".png"):
            continue
        elif item.endswith(".psd"):
            continue
        copyfile(path_join(original_path, item), path_join(temp_dir, item))
    output_tppk_dir = original_path[:-len("_tppk_extracted")]
    process = Popen(
        f'{tppk_tool_path} create "{output_tppk_dir}" "{temp_dir}"',
        stdout=PIPE,
        stderr=PIPE,
    )
    print_process(process, CONSOLE_ENCODING)
    rmtree(temp_dir)
def generate_narc(src_path, dst_path, original_path, output_narc_dir,
                  narchive_path):
    print(f"[-] Generate narchive file from {original_path}...")
    temp_dir_par = path_join(TEMP_DIR_PAR,
                             str(UUID(bytes=urandom(16), version=4)))
    temp_dir = path_join(temp_dir_par, "tmp")
    makedirs(abspath(temp_dir), exist_ok=True)
    for item in listdir(path_join(src_path, original_path)):
        if (item.endswith(".fif.json") or item.endswith(".png")
                or item.endswith("_tppk_extracted")):
            continue
        copyfile(
            path_join(path_join(src_path, original_path), item),
            path_join(temp_dir, item),
        )
    output_narc_dir = path_join(dst_path,
                                output_narc_dir[:-len("_narc_extracted")])
    mkdir_parent(output_narc_dir)
    cmd = f'{narchive_path} create "{output_narc_dir}" "{temp_dir_par}"'
    process = Popen(cmd, stdout=PIPE, stderr=PIPE)
    print_process(process, CONSOLE_ENCODING)
    rmtree(temp_dir_par)
        help="directory path to convert",
        required=True,
    )
    parser.add_argument("-b",
                        "--bntx_script_path",
                        help="bntx extractor script path",
                        required=True)

    args = parser.parse_args()

    bntx_script_path = abspath(args.bntx_script_path)

    all_files = glob.glob(path_join(args.dir_path, "**", "*"), recursive=True)
    for file in all_files:
        file = abspath(file)
        if isdir(file):
            continue
        with open(file, "rb") as f:
            magic_code = f.read(4)
            if magic_code != b"BNTX":
                continue
            file_parent = abspath(path_join(file, pardir))
            print(f"[-] convert {file}")
            process = Popen(
                f"python {bntx_script_path} {file}",
                cwd=file_parent,
                stdout=PIPE,
                stderr=PIPE,
            )
            print_process(process, CONSOLE_ENCODING)