From 7c2f3b2778e20fe91547be67d9d18c17cb7fd44b Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 19 Apr 2025 12:42:41 +0800 Subject: [PATCH] Add support to modify BGI scenario strings --- extract_bgi.py | 76 ++++++++++++++++++++++++++ patch_bgi.py | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 extract_bgi.py create mode 100644 patch_bgi.py diff --git a/extract_bgi.py b/extract_bgi.py new file mode 100644 index 0000000..d93b2fa --- /dev/null +++ b/extract_bgi.py @@ -0,0 +1,76 @@ +import struct +import json +import sys + + +class BGIScript: + def __init__(self, path: str): + self.path = path + with open(path, 'rb') as f: + self.data = bytearray(f.read()) + self.read_header() + self.get_instr_end() + + def read_header(self): + self.header_size = struct.unpack(' 2: + json_f = sys.argv[2] +scr = BGIScript(base) +print(scr.header_size) +print(scr.iPos) +print(scr.last_pos) +with open(json_f, "w", encoding="utf-8") as f: + json.dump(scr.extract_values(), f, ensure_ascii=False, indent=2) diff --git a/patch_bgi.py b/patch_bgi.py new file mode 100644 index 0000000..47ab9cd --- /dev/null +++ b/patch_bgi.py @@ -0,0 +1,144 @@ +import struct +import json +import sys + + +class BGIScript: + def __init__(self, path: str): + self.path = path + with open(path, 'rb') as f: + self.data = bytearray(f.read()) + self.read_header() + self.get_instr_end() + + def read_header(self): + self.header_size = struct.unpack('= 3: + json_f = sys.argv[2] +output = f"../patched/{base}" +if len(sys.argv) >= 4: + output = sys.argv[3] +scr = BGIScript(base) +print(scr.header_size) +print(scr.iPos) +print(scr.last_pos) +with open(json_f, "r", encoding="utf-8") as f: + data = json.load(f) +scr.setup_values(data) +scr.save_as(output)