Store patch definitions as commented JSONC with separate script fragments

Patch definitions under exe-patches/ and gui-patches/ move from
patch.json/locate.json to patch.jsonc/locate.jsonc. Each file now holds
only the data needed to apply the patch plus a short English comment
stating what it changes, why the local service cannot provide it, and
what happens without it. Every definition records the game versions it
was verified on (verified_on, required).

GUI patches keep their stock text and replacement in find.nut and
replace.nut next to patch.jsonc instead of escaped JSON strings, so the
script edits are readable, diffable and can carry Quirrel comments.
Matching treats CRLF and LF as the same line break because stock
scripts mix both; only the matched span is rewritten.

Loaders on both sides (packages/build, packages/exepatch, wtotools)
reject unknown keys so analysis text cannot creep back into the data.
JSONC parsing moves into a shared @wto/jsonc package; the build now
parses tuning/store.jsonc instead of scanning it with a regex.

Verified: npm run typecheck; check-patches (10/10 ready on 2.61.0.37);
check-gui (33 patches, 24 scripts compile); the TypeScript and Python
appliers produce identical scripts, byte-identical to the previous
definitions except one stock script with mixed line endings.

The 15 battle patches are migrated mechanically and still carry the
pending-review comment; they are rewritten by the LocalMP review.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 03:24:12 +08:00
1 parent 6a189513b0
commit 16b5d3cab1
185 files changed
+2676 -1487

No files matched your search

+20 -26
View File
@@ -8,13 +8,13 @@ with the target script's real `gui.vromfs.bin` imports runs the full `SQParser`
"""
from __future__ import annotations
import json
import re
import subprocess
import tempfile
from dataclasses import dataclass
from pathlib import Path
from .guipatch import apply, load_gui_patches
from .vromfs import Archive, read_archive
MOUNT_PREFIXES: tuple[tuple[str, str], ...] = (
@@ -112,54 +112,48 @@ def verify_gui_patches(
endpoint: str = "127.0.0.1:47115",
) -> GuiCheckReport:
archive = read_archive(gui_pack_path.read_bytes())
patch_files = sorted(patches_dir.rglob("patch.json"))
patches = load_gui_patches(patches_dir)
touched_files: list[str] = []
errors: list[str] = []
for patch_path in patch_files:
raw = json.loads(patch_path.read_text(encoding="utf-8"))
target = raw["file"].lower()
for patch in patches:
target = patch.file.lower()
if target not in archive.files:
errors.append(f"{raw['id']}: missing file {target} in gui.vromfs.bin")
errors.append(f"{patch.identifier}: missing file {target} in gui.vromfs.bin")
continue
current = archive.files[target].decode("utf-8")
find_text = raw["edit"]["find"]
first = current.find(find_text)
if first == -1:
errors.append(f"{raw['id']}: target snippet not found in {target}")
if any("`" in edit.replace for edit in patch.edits):
errors.append(f"{patch.identifier}: backtick string syntax is unsupported by 2.61.0.37 Quirrel VM; use $\"...\" or +")
continue
if current.find(find_text, first + len(find_text)) != -1:
errors.append(f"{raw['id']}: target snippet appears more than once in {target}")
try:
updated = apply(archive.files[target].decode("utf-8"), patch, endpoint)
except ValueError as error:
errors.append(str(error))
continue
replace_text = raw["edit"]["replace"].replace("{{LOCAL_ENDPOINT}}", endpoint)
if "`" in replace_text:
errors.append(f"{raw['id']}: backtick string syntax is unsupported by 2.61.0.37 Quirrel VM; use $\"...\" or +")
continue
updated = current[:first] + replace_text + current[first + len(find_text):]
archive.put(target, updated.encode("utf-8"))
if target not in touched_files:
touched_files.append(target)
if errors:
return GuiCheckReport(len(patch_files), 0, tuple(errors))
return GuiCheckReport(len(patches), 0, tuple(errors))
export_cache: dict[str, set[str]] = {}
native_syms = _collect_all_named_imports(archive)
stock_archive = read_archive(gui_pack_path.read_bytes())
for patch_path in patch_files:
raw = json.loads(patch_path.read_text(encoding="utf-8"))
target = raw["file"].lower()
for patch in patches:
target = patch.file.lower()
stock_src = stock_archive.files[target].decode("utf-8")
imp_names, imp_classes = _resolve_file_bindings(stock_src, stock_archive, export_cache, native_syms)
reserved = (imp_names | imp_classes) - set(MODULE_BUILTINS)
new_locals = _declared_locals(raw["edit"]["replace"]) - _declared_locals(raw["edit"]["find"])
new_locals: set[str] = set()
for edit in patch.edits:
new_locals |= _declared_locals(edit.replace) - _declared_locals(edit.find)
collisions = sorted(new_locals & reserved)
if collisions:
errors.append(f"{raw['id']}: local binding(s) {collisions} conflict with module imports in {target}")
errors.append(f"{patch.identifier}: local binding(s) {collisions} conflict with module imports in {target}")
if errors:
return GuiCheckReport(len(patch_files), 0, tuple(errors))
return GuiCheckReport(len(patches), 0, tuple(errors))
with tempfile.TemporaryDirectory(prefix="wto-gui-check-") as tmp:
tmp_dir = Path(tmp)
@@ -191,7 +185,7 @@ def verify_gui_patches(
if line.strip():
errors.append(line.strip())
return GuiCheckReport(len(patch_files), len(touched_files), tuple(errors))
return GuiCheckReport(len(patches), len(touched_files), tuple(errors))
def _resolve_vromfs_path(spec: str) -> str | None: