From d3320a4677f7432593397b2c14edb7873d54154c Mon Sep 17 00:00:00 2001 From: Flawed <33593723+ff14wed@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:55:39 -0800 Subject: [PATCH] Update opcode file reader to only apply changes lines with old version - Also updates readme with this change - And switch from minor_patch_diff vtable_diff in the recommended workfloww for minor patches --- README.md | 7 +++---- generate_opcodes_file.py | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 60f92b9..42a4d94 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,12 @@ Pass `--help` to any of the scripts for usage. Example: ```sh -python minor_patch_diff.py ffxiv_dx11.6.30.exe ffxiv_dx11.6.30h.exe > 6.30h.diff.json +python vtable_diff.py ffxiv_dx11.6.30.exe ffxiv_dx11.6.30h.exe > 6.30h.diff.json ``` Post-diff processing: ```sh -python generate_opcodes_file.py 6.30h 6.30h.diff.json Ipcs.6.30h.h -# TODO: Need a script to resolve opcodes for handlers with multiple opcodes +python generate_opcodes_file.py 6.30 6.30h 6.30h.diff.json Ipcs.6.30h.h python generate_act_format.py Ipcs.6.30h.h ``` @@ -67,7 +66,7 @@ python traces_diff.py 6.28h-traces 6.30-traces 6.30.diff.json Post-diff processing: ```sh -python generate_opcodes_file.py 6.30h 6.30h.diff.json Ipcs.6.30h.h +python generate_opcodes_file.py 6.30 6.30h 6.30h.diff.json Ipcs.6.30h.h # TODO: Need a script to resolve opcodes for handlers with multiple opcodes python generate_act_format.py Ipcs.6.30h.h ``` diff --git a/generate_opcodes_file.py b/generate_opcodes_file.py index 8b1f5d6..60391d6 100644 --- a/generate_opcodes_file.py +++ b/generate_opcodes_file.py @@ -27,32 +27,38 @@ def opcodes_str(opcodes): return "UNKNOWN" -def replace_line_with_new_opcode(line, diff, ver): - match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line) +def replace_line_with_new_opcode(line, diff, ver, old_ver): + match_groups = re.findall( + r"^(\s*[^\/]\w+\s*)=\s*(.*),(\s*)\/\/.*" + old_ver + "$", line + ) if len(match_groups) != 1: return line opcode_name = match_groups[0][0] opcode_val = match_groups[0][1] + comment_spacing = match_groups[0][2] if " or " in opcode_val: old_opcode = int(opcode_val.split(" or ")[0], 16) else: old_opcode = int(opcode_val, 16) if old_opcode in diff: new_opcodes = diff[old_opcode] - return f"{opcode_name}= {opcodes_str(new_opcodes)}, // updated {ver}\n" + return f"{opcode_name}= {opcodes_str(new_opcodes)},{comment_spacing}// updated {ver}\n" - return f"// {line}" + return f"{line}" @click.command() +@click.argument("old_version_string") @click.argument("new_version_string") @click.argument("diff_file", type=click.File("r")) @click.argument("opcodes_file", type=click.File("r")) @click.option( "--reverse", is_flag=True, help="Applies the diff file in the opposite direction" ) -def generate_opcodes_file(new_version_string, diff_file, opcodes_file, reverse): +def generate_opcodes_file( + old_version_string, new_version_string, diff_file, opcodes_file, reverse +): """ Parses an OPCODES_FILE and applies a JSON DIFF_FILE to generate a new one. The opcodes file is basically anything that has syntax resembling Sapphire's @@ -61,13 +67,18 @@ def generate_opcodes_file(new_version_string, diff_file, opcodes_file, reverse): Example: - python generate_opcodes_file.py 6.30h diff.json Ipcs.h + python generate_opcodes_file.py 6.30 6.30h diff.json Ipcs.h """ diff = load_diff_file(diff_file, reverse) queued_lines = [] for line in opcodes_file.readlines(): queued_lines.append( - replace_line_with_new_opcode(line, diff, new_version_string) + replace_line_with_new_opcode( + line, + diff, + new_version_string, + old_version_string, + ) ) new_filename = f"{new_version_string}_opcodes.txt"