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:
@@ -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
|
||||
```
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user