Last active
January 25, 2025 08:31
-
-
Save baoanhng/f413551e6b95f494fa4bfe902fb9aa61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
import os | |
import subprocess | |
import json | |
from shutil import which | |
# Made by nie0 :fuckhadros: | |
# v2 | |
if len(argv) != 2: | |
print('Usage: py hdiffapply.py [game_folder]') | |
exit() | |
game_folder = argv[1] | |
delete_files_path = os.path.join(game_folder, 'deletefiles.txt') | |
print(delete_files_path) | |
if not os.path.exists(delete_files_path): | |
print('deletefiles.txt doesnt exist in game directory!') | |
exit() | |
hdiff_map_path = os.path.join(game_folder, 'hdiffmap.json') | |
if not os.path.exists(hdiff_map_path): | |
print('hdiffmap.json doesnt exist in game directory!') | |
exit() | |
delete_paths = open(delete_files_path, 'r') | |
delete_files = delete_paths.read().split('\n') | |
for file in delete_files: | |
if len(file) < 1: | |
print(file) | |
continue | |
actualPath = os.path.join(game_folder, file) | |
print(actualPath) | |
print(os.path.exists(actualPath)) | |
if os.path.exists(actualPath): | |
print(f'Deleting {actualPath}') | |
os.remove(actualPath) | |
# Also doesnt work in vs code terminal :) | |
hzpatchz = which('hpatchz') | |
if hzpatchz is None: | |
print('HDiffPatch not found in system path!\nTry to open cmd again or reboot\nGithub link: https://github.com/sisong/HDiffPatch') | |
exit() | |
hdiff_json = open(hdiff_map_path) | |
data = json.load(hdiff_json) | |
#.\hpatchz.exe source_file_name patch_file_name target_file_name | |
for entry in data['diff_map']: | |
source_file_name = os.path.join(game_folder, entry['source_file_name']) | |
patch_file_name = os.path.join(game_folder, entry['patch_file_name']) | |
target_file_name = os.path.join(game_folder, entry['target_file_name']) | |
# Check if files exist | |
if not os.path.exists(source_file_name): | |
print(f"Source file missing: {source_file_name}") | |
continue | |
if not os.path.exists(patch_file_name): | |
print(f"Patch file missing: {patch_file_name}") | |
continue | |
print(f"Applying patch: {patch_file_name} -> {target_file_name} using {source_file_name}") | |
subprocess.run([hzpatchz, "-f", source_file_name, patch_file_name, target_file_name]) # -f to force overwriting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment