Files
2026-11-30 09:52:34 +08:00

3.4 KiB

CLAUDE.md

CLI + local web UI (wukongmods) that manages the Black Myth: Wukong C# Loader (KintaroModding/b1csharploader) and its mods. Python 3.8+, standard library only: keep it dependency-free so it runs with a bare python3 -m wukongmods on Windows, Linux and macOS.

Layout

  • wukongmods/core.py: on-disk model (Game): loader status, mod listing, enable/disable, config.json and b1cs.ini editing, value coercion/validation, removal. No network.
  • wukongmods/install.py: downloads (curl → wget → urllib fallback), GitHub releases API, zip extraction for mods and the loader, config merging on reinstall, update checks.
  • wukongmods/doctor.py: checks returning {level, area, message, fix} dicts; levels ok/info/warn/error.
  • wukongmods/registry.py: known mods (repo, aliases, config schema) and b1cs.ini schema.
  • wukongmods/prefs.py: ~/.wukongmods.json (override with WUKONGMODS_PREFS), Win64 normalization, Steam library detection per OS.
  • wukongmods/cli.py: argparse commands. ModError = user-facing error → exit code 2.
  • wukongmods/server.py + wukongmods/web/index.html: ThreadingHTTPServer on 127.0.0.1 with a JSON API (GET /api/state[?since=hash], POST /api/<action>) and a single vanilla-JS page.
  • tests/test_wukongmods.py: offline unittest suite using a fake Win64 folder and synthetic zips.

Domain rules (from the C# Loader source)

  • The loader loads only CSharpLoader/Mods/<Name>/<Name>.dll (folder name == dll name). Mods/Common/ holds shared dlls and is not a mod.
  • version.dll (native loader) lives in Win64/, next to b1-Win64-Shipping.exe, not in CSharpLoader/.
  • Uninstalling the loader = delete version.dll + CSharpLoader/.
  • Release zips are rooted at b1/Binaries/Win64/...; README/LICENSE sit at the zip root.

Conventions

  • Enable/disable prefers the mod's boolean Enable/Enabled key in config.json; only when it is absent (or --rename) rename <Name>.dll ↔ <Name>.dll.disabled, and always report the rename.
  • Never clobber user settings: reinstalling merges old values into the new config.json, written only after all other files succeeded; loader reinstall never overwrites b1cs.ini (it only adds missing keys) and never touches Mods/.
  • ini keys and registry lookups by folder name are case-insensitive.
  • GITHUB_TOKEN goes only to api.github.com and never on a command line (curl -K - stdin, wget private --config file).
  • Every zip path goes through _safe_path (no absolute, drive-letter or .. paths).
  • Writes are atomic (temp file + os.replace); b1cs.ini edits preserve other lines and comments.
  • config.json keys starting with _ (e.g. _help) are read-only documentation.
  • Web server: bind only 127.0.0.1; every POST needs the per-run X-Token; reject non-localhost Host headers. Build DOM with textContent (the h() helper), never innerHTML, since mod data comes from disk/GitHub.
  • The web UI polls state every 3 s; it must not overwrite a form with unsaved edits (drafts).

Testing

python3 -m unittest discover -s tests

Manual testing: copy CSharpLoader/ and version.dll from a real install into a scratch folder, touch b1-Win64-Shipping.exe there, and use --win64 or WUKONGMODS_PREFS so the real game folder and ~/.wukongmods.json are not modified. Only macOS has been tested; keep paths OS-neutral (pathlib, no shell-specific commands).