mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 21:15:57 +00:00
Preserve plugin image paths in generated patch tables
This commit is contained in:
1 parent
afae80c908
commit
d4497da8c7
3 files changed
+83
-6
No files matched your search
+16
-3
@@ -1,7 +1,8 @@
|
||||
"""Code patch table for the generator: guest instructions replaced in the lifted C, switchable at run time.
|
||||
|
||||
Lifted code cannot be byte-patched when the game runs, so a patch is applied when the C is generated. A patch file
|
||||
(gen.py --patches) has these kinds of lines; `#` starts a comment, fields are separated by whitespace:
|
||||
(gen.py --patches) has these kinds of lines; `#` starts a comment, fields are separated by whitespace. A plugin image
|
||||
path may be a JSON double-quoted string to preserve spaces, `#` and escaped characters:
|
||||
|
||||
set <name> <env> <default> [ordered] a patch set: a run-time switch <env>=0/1, <default> when it is unset
|
||||
site <set> <module> <address> <original> <replacement> [<replacement> ...]
|
||||
@@ -77,6 +78,7 @@ entry the runtime watches: their lifted C starts with FN_ENTER (runtime/cpu.h),
|
||||
branch to fnprof_hit while the runtime sets it. A table with hook lines puts FN_ENTER into these functions only; a table
|
||||
without any keeps it in every function, as does gen.py --fn-enter-all (a whole-game function-entry profile).
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
PAGE = 0x1000
|
||||
@@ -187,10 +189,21 @@ def load(path, mods):
|
||||
sets, index, sites, spins, hooks, ordered, plugins = [], {}, {}, {}, {}, set(), {}
|
||||
bases = {n: (b, s) for n, b, s in mods}
|
||||
for no, raw in enumerate(Path(path).read_text(encoding='utf-8').splitlines(), 1):
|
||||
f = raw.split('#', 1)[0].split()
|
||||
where = f'{path}:{no}'
|
||||
prefix = raw.split(None, 4)
|
||||
if len(prefix) == 5 and prefix[0] == 'plugin' and prefix[4].startswith('"'):
|
||||
try:
|
||||
image, end = json.JSONDecoder().raw_decode(prefix[4])
|
||||
except json.JSONDecodeError as e:
|
||||
raise PatchError(f'{where}: invalid quoted plugin image: {e.msg}') from None
|
||||
tail = prefix[4][end:].strip()
|
||||
if tail and not tail.startswith('#'):
|
||||
raise PatchError(f'{where}: unexpected text after quoted plugin image')
|
||||
f = prefix[:4] + [image]
|
||||
else:
|
||||
f = raw.split('#', 1)[0].split()
|
||||
if not f:
|
||||
continue
|
||||
where = f'{path}:{no}'
|
||||
if f[0] == 'set' and (len(f) == 4 or len(f) == 5 and f[4] == 'ordered'):
|
||||
if f[1] in index:
|
||||
raise PatchError(f'{where}: set {f[1]} defined twice')
|
||||
|
||||
Reference in new issue
Block a user