mirror of
https://github.com/Xeeynamo/sotn-decomp.git
synced 2024-11-23 13:09:44 +00:00
b851d5e4d2
As per title. I also added a new tool called `dirt_patch`. As I mentioned in our Discord server there is some left-over data from previous dev builds in DRA.BIN and potentially elsewhere too. The tool uses the new file `config/dirt.us.json` which stores a list of patches to avoid crazy hacks and `#ifdef` for the sake of getting a match. I hope this tool will not be abused.
33 lines
832 B
Python
33 lines
832 B
Python
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
import json
|
|
|
|
|
|
def patch(config_file_name):
|
|
with open(config_file_name, "r") as f:
|
|
patches = json.load(f)
|
|
for patch in patches:
|
|
name = patch["name"]
|
|
with open(name, "r+b") as f:
|
|
for str_offset in patch:
|
|
if not str_offset.startswith("0x"):
|
|
continue
|
|
offset = int(str_offset[2:], base=16)
|
|
value = patch[str_offset]
|
|
f.seek(offset)
|
|
f.write(bytes([value]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(
|
|
description="given a configuration, patches an existing binary"
|
|
)
|
|
parser.add_argument(
|
|
"config",
|
|
help="File path of the patch configuration",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
patch(args.config)
|