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
This commit is contained in:
Flawed
2023-03-06 23:55:39 -08:00
parent e9ec632a31
commit d3320a4677
2 changed files with 21 additions and 11 deletions
+3 -4
View File
@@ -44,13 +44,12 @@ Pass `--help` to any of the scripts for usage.
Example: Example:
```sh ```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: Post-diff processing:
```sh ```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 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: Post-diff processing:
```sh ```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 # TODO: Need a script to resolve opcodes for handlers with multiple opcodes
python generate_act_format.py Ipcs.6.30h.h python generate_act_format.py Ipcs.6.30h.h
``` ```
+18 -7
View File
@@ -27,32 +27,38 @@ def opcodes_str(opcodes):
return "UNKNOWN" return "UNKNOWN"
def replace_line_with_new_opcode(line, diff, ver): def replace_line_with_new_opcode(line, diff, ver, old_ver):
match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line) match_groups = re.findall(
r"^(\s*[^\/]\w+\s*)=\s*(.*),(\s*)\/\/.*" + old_ver + "$", line
)
if len(match_groups) != 1: if len(match_groups) != 1:
return line return line
opcode_name = match_groups[0][0] opcode_name = match_groups[0][0]
opcode_val = match_groups[0][1] opcode_val = match_groups[0][1]
comment_spacing = match_groups[0][2]
if " or " in opcode_val: if " or " in opcode_val:
old_opcode = int(opcode_val.split(" or ")[0], 16) old_opcode = int(opcode_val.split(" or ")[0], 16)
else: else:
old_opcode = int(opcode_val, 16) old_opcode = int(opcode_val, 16)
if old_opcode in diff: if old_opcode in diff:
new_opcodes = diff[old_opcode] 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.command()
@click.argument("old_version_string")
@click.argument("new_version_string") @click.argument("new_version_string")
@click.argument("diff_file", type=click.File("r")) @click.argument("diff_file", type=click.File("r"))
@click.argument("opcodes_file", type=click.File("r")) @click.argument("opcodes_file", type=click.File("r"))
@click.option( @click.option(
"--reverse", is_flag=True, help="Applies the diff file in the opposite direction" "--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. 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 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: 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) diff = load_diff_file(diff_file, reverse)
queued_lines = [] queued_lines = []
for line in opcodes_file.readlines(): for line in opcodes_file.readlines():
queued_lines.append( 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" new_filename = f"{new_version_string}_opcodes.txt"