feat(game)!: the game side and the whole mod API in Rust, with system mods and the sandbox on by default #2822
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2822
Loading…
Reference in a new issue
No description provided.
Delete branch "mod-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Why. On
mainthe game side (everything between the C host and the lifted game) is C (game/*.c), with eachsetting and feature wired into it and into the C++ Insert menu, and the only mods are file mods (
romfs,exefs,cheats) loaded by
game/mods.c. There is no way for a mod to run code, and the game runs with the player's fullrights. This moves the game side to Rust, adds a mod API that script mods run on, rebuilds every setting and feature
as a system mod on that same API, and makes the builder start every game confined.
This is #2434 squashed into one commit (the same tree as
its last head,
696eed7f). Its reviews, comments and earlier test runs are there; the full history is onHumanBean:wip/mod-api-history, which
holds the commits named below (
75b9274d,fdab42dd).What changed
game/crates:game-core,game-sites,api,script,ui,content,longshot-gameand their helpers), linked into the game as one static library. The hook sites stay tables(
game/sites) the lifter reads. Design:game/DESIGN.md.TypeScript itself as it loads it (no Node, no build step).
mod.tomlis the manifest. A mod asks for permissionsthe player grants; it gets events, settings, storage, UI (HUD, windows, world labels), input, the network (when
confirmed) and the game's state through the
longshotmodules. Turning a mod off puts back what it changed that thegame has not saved yet. Mods can also add content, and hook sites of their own that the next game build places.
File mods load as before. Docs:
docs/modding/, with 41 example mods and their tests.game/mods, on the same API as players' mods:Rust (cheats, shadows, widescreen, sprint and walk, HDR, grass, prompts...), TypeScript (the Insert menu itself, the
Mods tab, the mod inspector, Discord status, the FPS counter, CRT, colour vision, text, area names, Skip title...),
and six settings-only
mod.tomls. The TypeScript ones are compiled into the program. Everylongshot_options.inikey keeps its name (tests/test_menu_ini_keys.py's FROZEN list).longshot-builderstarts the gameprocess; tools start it through
longshot-builder game. On Linux the builder applies Landlock andno_new_privsand the game a seccomp filter; on Windows the game runs in an AppContainer with no capability (its plan made in Rust,
build_core::sandbox_windows). The game starts no process. Everything it may not do itself goes to the builder overone framed channel (
host/builder_channel.h; the game's side is Rust,builder_link): the mods' network and IPC,settings writes, saves, crash reports, controllers, restarts, message boxes, and the links and folders it opens. A
mod's network is confirmed in the builder's own window and kept in the profile's
trust.json, which the game canread and never write. The environment the builder passes is one list (
build_core::env_own).builds nothing, the settings host, the mods list and the UI step only on a change, and the script watchdog sleeps
until the next deadline.
compile.
What players see change
HOS_SANDBOX=0in the real environment turns that off;longshot_env.txtcannot.mods included, and Discord status moved there from Gameplay.
release notes.
Read first:
game/DESIGN.md,game/game.h,docs/modding/README.md,docs/dev/reference/builder.md,docs/dev/reference/sandbox.md,gpu/vk/vk_api.h(MKWVK_API_VERSION80).Testing
Tested: Linux (CachyOS, Linux 7.3, RTX 3090, NVIDIA 620.70.06), on
75b9274d(the head adds docs, test fixes,main's newest (a docs change) and #2751 (the dev queue), none of it in the game), the sandbox on (Landlock ABI 9, seccomp, network closed), through the job queue:[error]line.net:https://example.orggets the builder's question and is refused until confirmed; adevelopment mod's fetch returns 200.
HOS_CRASH_TEST): a complete crash record in the game folder'sdiagnostics/bug-reports.HOS_NATIVE_CLOTH=check): 0 mismatches over every kernel.on (
permissions.changedfires); a hot reload that does not compile keeps the old instance running and says why; agood one runs the new code with the grants kept; switching it off fires
stopping, ends its timers and its settingslistener.
items.pouchAddbuilt into the game (longshot-builder build, one site placed) andcalled at a pouch add; switched off it is "off at the next start" (as the docs say), and after a restart its site
is called by nothing.
The checks:
mise run teston75b9274d, then the failing ones again on the head: 15 fail, each also failing onmain(
2a146054) with the same error (compared message by message: the program-cache fixtures'spirv_pack::Store, the guestholes'
UploadLayoutGuard, the video and input fixtures,test_windows_on_linux,test_xinput_thread); the Rustworkspace's fmt, clippy
-D warningsandcargo test --releasepass. The Windows game folder cross-links with llvm-mingw; it has not run on Windows.Still to test:
scripts/parity_gates.py) and feature checks, expectingmain's results apartfrom "Fixed on the way" (@Beanstalk, or by hand)
committing, shots written, mods' IPC through the broker (@Beanstalk)
restart), save and load a chosen slot, a second profile kept apart; expecting no menu faults
(the earlier report) (@Beanstalk or
a tester)
menu alone, not mods' UI), and a crash reported by
longshot-builder playat the next start (by hand)kokiri-startwith the sandbox on, expecting no sandbox refusals inthe log (@Beanstalk)
Measurements
Verdict: fps, 1 % lows and frame-time tails level with
mainor better; start to play about 5 s shorter. The gamethread does about 0.1–0.2 ms more CPU a frame (the mod runtime's own frame; accepted, closing it is a follow-up), and
the process keeps about 90 MB more private memory.
Setup: Linux 7.3, RTX 3090, NVIDIA 620.70.06; Hyrule Field (child), 1080p native, Upscaler Off, fixed resolution,
uncapped, no player mods;
dev.py ab,main(2a146054) against this PR (75b9274d), interleaved, the median of eachrun (the first 600 frames left out). The PC had other work on it: compare the sides, not the fps against other PRs.
2a14605475b9274dmain_cpu_ms)On a quieter PC earlier the same day (3 × 90 s):
main_cpu_ms1.64–1.66 against 1.80–1.85, fps level (136.9–138.4against 138.3–139.3).
being a script mod here.
link-hud, its HUD read every frame; 2 × 60 s against the PR without it): no fps orframe-time loss; the game thread +0.07 ms.
main(1413b172): the PR side (75b9274d) already holdsmainto01d6878b;main's commits since2a146054are Debug-tab rows, Pause in background (off unless the window is behind), the program cache's store andthe dev tools, none in a steady frame's work, so the comparison holds. The head's commits since
75b9274dchange docs,tests and the dev queue only.
Switches this adds or changes, the default each ships at and why (rows in
gpu/vk/switches.def):Kill switches, on by default (each is the new behaviour;
=0is the old one, for an A/B or a fallback):HOS_SANDBOX: on; every run confines itself, a run the system cannot confine goes on unconfined with a player'sscript mods held. On for safety, not from measurements; its cost is in the table above.
HOS_GAME_BARRIER_WAIT: on; three parallel-for job barriers wait on their mask word instead of sleeping 20 us andpolling.
=0against unset, 2 × 60 s: 137.3 against 138.1 fps, within the spread; it ships on because it ends thepolling (less CPU awake), with no cost measured.
HOS_GAME_FIRST_NIGHT_FIX: on; clears the first adult night's stuck time lock so the clock runs (a fix).HOS_MODS_WATCH: on; mods/ and profile.json watched by the system's change notices, so folder script mods hot-reload.HOS_SHADOW_RES: Highest is the game's 3072 at 16:9 and grows only past 16:9 (4512 at 21:9, 5120 at 32:9), as onmainat 16:9.HOS_SHADOW_SPLITS: cascade 0 ends at 15 m at 16:9 (12 m at 32:9), cascade 1 at 45 m.=0(the game'ssplits) against unset, 2 × 60 s: 126.1 against 131.5 fps, every
=0run below every default run; the default costsnothing and keeps near shadows sharp.
HOS_SYSTEM_MODS_OFF: unset, every system mod by its own rules; for A/Bs and parity runs.RX_VK_DRS: on, host dynamic resolution drives Render resolution Auto (unchanged default, the row reworded).RX_VK_FG_AUTO_GUARD: on, frame generation's Auto steps down when overloaded (unchanged default, the row reworded).RX_VK_FX,RX_VK_WORLD,RX_VK_TEX_PACKS: on, script mods' screen effects, world shapes and texture packs aredrawn;
=0for an A/B only.Tuning:
RX_VK_FX_BUDGET_US: 2000; a script mod's screen effect over 2 ms of GPU time a frame is stopped for the session.HOS_WIDE_MAX_PX: 5120 x 2160 pixels, a native size already of the picture's shape keeps its own.Player and builder overrides, unset by default (unset is the normal run; the builder or launcher sets them):
HOS_AUDIO_DEVICE,HOS_LANGUAGE,HOS_MOUSE_NATIVE,HOS_RES_SCALE,HOS_NO_MODS(the menu or saved choiceapplies);
LONGSHOT_SAFE_START,LONGSHOT_SET,LONGSHOT_MOD_STORE,LONGSHOT_SHADER_CACHE,LONGSHOT_GAME_MODULE(set bylongshot-builder play);LONGSHOT_SHADER_STORE,LONGSHOT_NFC_DIR,RX_VK_DLSS_DIR(the user's own folders);LONGSHOT_PREPARE_ONLY(off, a normal run).Set by the builder for the game it starts, never by a run:
LONGSHOT_BUILDER_CHANNEL,LONGSHOT_BUILDER_PIPES,LONGSHOT_PADS_FD,LONGSHOT_NUP_HANDLE,LONGSHOT_SANDBOX_BY_BUILDER,LONGSHOT_SANDBOX_NEEDS,LONGSHOT_SANDBOX_NOTE,LONGSHOT_SANDBOX_PRIVATE,LONGSHOT_SANDBOX_USER.Set by the builder or the game for themselves (unset in any other run):
LONGSHOT_CONTROL_BY_BUILDER,LONGSHOT_CRASH_BY_BUILDER,LONGSHOT_CRASH_DUMP,LONGSHOT_LOG_PATH,LONGSHOT_BUILD_STAMP(the builder's stamp thegame says in its
hello),HOS_START_SLOT(the profile'sstart_slot).Diagnostics and tests, off by default (no cost when unset):
HOS_CONTROL_PEER_SID(unset: the control pipe is thisuser's alone),
HOS_CRASH_MINIDUMP(off),HOS_EVENT_STATS(off),LONGSHOT_WAIT_FOR_DEBUGGER(off),RX_VK_NOOPT(off: the driver's optimizer on),RX_VK_SKIP_CODE(unset: nothing left out), the tests' ownLONGSHOT_COST_REPORT,LONGSHOT_TEST_GAME,LONGSHOT_TEST_SETTINGS_WRITE_ALONE;HOS_AB,HOS_CHAIN,HOS_CONTROL,HOS_CONTROL_EVAL,HOS_ENV_FILE,HOS_GAME_TRACE_SAVES,HOS_INPUT_SCRIPT,HOS_INPUT_SYNC(1, withHOS_INPUT_PLAYonly),HOS_MOD_TESTS,HOS_MOD_TESTS_OUT,HOS_MOD_TESTS_SAVE,HOS_MOD_TESTS_TIMEOUT(3600 s),HOS_PRESENT_TRACE,HOS_PROFILE_DIR,HOS_SAMPLE_FILE,HOS_SYSTEM_MODS_DIR,HOS_WINDOW_NOACTIVATE,LONGSHOT_DEV_MODS,RX_VK_DUMP,RX_VK_FRAMELOG,RX_VK_FRAME_LOG,RX_VK_HANG_DUMP,RX_VK_LOG_TEX_HASH,RX_VK_MENU_SCRIPT,RX_VK_SHOTS; the game-free tests'LONGSHOT_FAKE_ASPECT.Development tools only, not read by the game:
LONGSHOT_CACHE(unset: the installed launcher's builder cache),LONGSHOT_RUST_STORE_MB(unset: 30 GB kept of the game's Rust in the object store),LONGSHOT_CARGO_TARGET_ROOT,LONGSHOT_SCCACHE(on when sccache isinstalled),
LONGSHOT_SHADER_STORE_DEV(on),LONGSHOT_HEADS,LONGSHOT_QUEUE_*,LONGSHOT_GAMESCOPE(shared jobsonly),
LONGSHOT_GAMESCOPE_SIZE(1920x1080),LONGSHOT_GAMESCOPE_TIMEOUT(60 s),LONGSHOT_FFMPEG,LONGSHOT_GLSLANG,LONGSHOT_REQUIRE_SHADERS,LONGSHOT_NO_CLANG,RX_GAME_MODULE(build flags).Not switches (constants and enums the check matched by name):
HOS_BIND_*,HOS_KEY_SPRINT,HOS_PAD_*,HOS_SW_N,HOS_PROMPT_*,HOS_REBIND_*,HOS_RENDER_*,HOS_NET_*,HOS_LOG_*,HOS_OPT_*(old option numbers, kept soinput recordings replay),
HOS_T_*(the env-line parser's kinds),HOS_PATH_CAP,LONGSHOT_SANDBOX_ANYTHING(a test'sname under the sandbox's own prefix),
HOS_HUD_DEFAULT_PLACEMENT,HOS_WIDE_MENUS_EXTENDED,HOS_HEAP_BASE,HOS_SYSTEM_BASE,HOS_CONTROL_GAME_CLIENTS/_FLAGS/_JSON,LONGSHOT_PROFILE_SETTINGS. Named only as removed:HOS_GAME_CHEATS,HOS_GAME_PROTECT_HEARTS,HOS_GAME_BOOT_SAVE/HOS_BOOT_SAVE(nowLONGSHOT_SETor the Skiptitle mod),
HOS_GAME_TELEPORT_EVENT,HOS_GAME_TELEPORT_STARTER.Risks
that. The fallback is a revert of this one commit; there is no switch back to the C game side.
HOS_SANDBOX=0in the real environment turns it off(
longshot_env.txtcannot).network's per-mod limits from the builder's copy, one settings writer, the log tails out of the game's reach).
still has the mod's value; saves are never rewritten. Release notes say it that way.
branch; VR (OpenXR) under the sandbox is a written limit: a runtime that starts its own service from the game cannot.
longshot_options.ini, saves, file mods andcaches read the same. A renderer built for an older
MKWVK_API_VERSIONrefuses to load, as it should.Checklist
Ready for review
main; the title is a Conventional Commit. (main's newest is merged in.)only.)
mise run testpasses (any failure that also fails onmainis named). (15 failures, each failing onmainwith thesame error.)
main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.(The site tables hold masked signatures and addresses only.)
When it applies
mainand passes here.gpu/vk/switches.def.(
HOS_SANDBOXships on for safety, its cost in the table.)tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged). (To 80.)mise run testreads what it compiled.)mise run teston75b9274d.)mainand here, for a change that shows on screen. (Compared on this PC, not posted: thehyrule-fieldscene's spot after its teleport, 1080p native,main2a146054and75b9274d: the same picture, only the fireflies and Navi moved.)game/DESIGN.md,docs/dev/reference/(sandbox, builder, broker-net, mods), the modding docs,docs/dev/developing.md.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Description from #2434 (squashed here into one commit,
9e6b9c57, the same tree as #2434's last head).Possibly related, for context:
9e6b9c5782eaf4a48b9eDescription rewritten: what main has (a C game side, file mods only, no sandbox) and what this adds; nothing about native or wasm mods, which never existed. The commit's message says the same (now
eaf4a48b, the same tree).Tested in the game on this PC (Linux 7.3 CachyOS, RTX 3090, NVIDIA 620.70.06), on #2434's heads
75b9274dandfdab42dd(this PR's commit has the tree of #2434's last head,696eed7f; the commits afterfdab42ddchanged lint, tests and docs only), the sandbox on: boot to play with all 29 system mods, the control bridge through the builder, network confirmation and a development mod's fetch, controllers through the builder, a forced crash's record, cloth parity (0 mismatches), the Insert menu's tabs and the Mods tab, a mod's lifecycle (denied and revoked permissions, a reload that does not compile, a good reload, a stop), and a mod's hook built into the game, called, and no longer called after its switch-off and a restart. Measurements against main are in the description.816d235493cdbb85513dcdbb85513dc5e5b676cbView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.