Commit Graph
9 Commits
Author SHA1 Message Date
Valiantsin DzerakhandClaude Opus 5.5 b9b8f3dce1 Each mod plugin is built or refused on its own: one that is refused, crashes or hangs costs only itself (#845)
tools/exefs_plugins.py ran every plugin's init in one service run and refused them all when one was refused. Now a run
without inits lists the plugin modules, then each plugin runs in service runs of its own (TOTK_PLUGIN_ONLY, the others
stay loaded): a refused svc, a crash (the FATAL line is the reason), a timeout or a failed check refuses that plugin
alone, with its reason in plugins.status; the rest are built in. 4 plugins take 2.3 s.

At start, plugins_start compares each plugin right after its own init and takes its branches out of main's .text before
the next one, so each init sees the game's bytes, as in its service run. Only that init's aliases are flushed: the
start stays at 113 ms for Full Inventory Expansion + Quick Weapon Durability (107 ms before).

The installer's second lift keeps every plugin of the service runs in the layout when one is built: the records hold
that layout's addresses. A refused plugin stays loaded and never starts. A mod with a built plugin and a refused one,
used without its code, runs the built one (mods.c; --probe-mods case T).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:25:24 +03:00
Valiantsin DzerakhandClaude Opus 5.5 d865000929 A mod plugin's init runs at every start and its hooks go on when it writes what the build recorded (#845)
After the design in #845 by itaskaev2, with one change: no image taken after a build-time run. When a
plugin's patch set is on, sdk's DT_INIT runs first, then the plugin's, in the environment of the service
run (rtld image below main, the QueryMemory view, the alias pool, process-memory aliases), then the game's
constructors. That is rtld's order on the Switch (oss-rtld, librtld/source/ld.cpp __rtld_modules_init
runs the modules from the last loaded to the first). sdk's first DT_INIT only registers it with its musl
and main's DT_INIT finishes it, so its flag stays 1 and it is not called a second time. The plugin keeps
its heap blocks, GOT and alias addresses.

The words the init wrote into the game modules and the plugin's .text after it are compared with
patches.h: equal, the set stays on; different, it goes off for this run, the reason is logged, the Mods
tab row says so and build-cache/plugins.stale has the next start run the rebuild. The branches written
into main's .text are taken back. mods.c reads build-cache/plugins.status: a built plugin's set joins its
mod's sets and the Mods tab order, a refused one keeps its mod off with the reason (the catalog texts in
en, ru, pt-BR, zh-Hans), a plugin without a line waits for the rebuild. A plugin file changed after the
build is left out by the loader. TOTK_PLUGIN_TRACE=1 logs the first call of each hook entry.

Without a plugin in the build nothing of this runs. --probe-mods covers a plugin set against another mod's
patch on one site, a refused plugin, one the build lacks and one whose start differs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:48:23 +03:00
Valiantsin DzerakhandClaude Opus 5.5 873903d98f The Mods tab order decides code sites too, conflicts show per mod, and each mod can be used without its code
Load order: mods_exefs_apply ranks each mod's patch sets by its position (rt_patch_rank) and runtime/patches.c fills
the pick byte of every contested site from the sets that are on, lowest rank first; a tie (two files of one mod)
goes to the later file, as emulators apply a mod's files in name order. Reorder and restart, no rebuild. The pick is
redone when an ordered set is switched at run time. Nothing changes for sites one set patches.

Conflicts: one table (mods_conflict) of winner, loser, part (files, data bytes, code sites) and count. romfs.c fills
it for files, mods_exefs_apply for the data bytes two mods stored and for the contested code sites. The log has both
directions per entry and one line per contested code site; each row of the Mods tab lists what the mod overrides and
what overrides it.

Use without its code: a per-mod switch under the row of a mod with a code module or an ExeFS patch file the port
cannot apply (mods_no_code in totk.ini, off by default). On, that code is left out and the rest of the mod is used;
the row says what is left out and why. mods_without_code = 1 holds it on for every mod and now covers the
unsupported patch files too.

--probe-mods: order to winner at contested sites in both orders, the same-mod tie, a switched-off mod, a run-time
switch of the winner, the conflict table for data and code, the per-mod switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:11:43 +03:00
8e098e95a8 A mod with a code module the port cannot run can be used without it (mods_without_code)
Taken from PR #790, which carries Eric Dallo's work from his fork (ericdallo/totk-pc-recomp, 6241358f): only its
mods_without_code part, adapted to dev, which has the ExeFS data writes already (#835) and no plugin runner. A mod with
an exefs/subsdk* or a replaced exefs/main stays off as a whole; mods_without_code = 1 under [mods] uses the rest of it
(RomFS files, cheats, ExeFS patch files) without that code. ModInfo.code names the modules that do not load; the
scan logs it, the Mods tab says it on the mod's row and shows the switch once such a mod is there.

Co-Authored-By: itaskaev2 <165683571+itaskaev2@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:56:42 +03:00
fa94e36549 Store the data writes of mods' ExeFS patch files into main before the game runs
An IPS, IPS32 or pchtxt file for main that writes main's .rodata, .data or .bss was refused as a whole. Such writes
need no lifting: tools/exefs_patches.py now puts them in build-cache/exefs.data, and runtime/mods.c stores them into
the loaded main before any game code runs, as emulators and Atmosphere apply a patch file to the module before its
dynamic linker runs. A DT_RELR word gets main's base added; bytes over words an explicit-addend relocation fills change
nothing and are dropped; a write into the dynamic linker's tables, a lazily bound function pointer or outside main's
image keeps the file unsupported. A mod whose data lines do not all fit the build keeps its code patches off too.

The mods are applied from the bottom one up (mods_exefs_apply), so where two mods write the same bytes the higher one
wins, as it does for files. --probe-mods checks it with two mods writing one byte.

The lifted code reads some of main's bytes at lift time (the jump tables). recomp/gen.py lists those ranges in
<gen>/main/folded.txt, and the setup checks the data writes against them after the lift: a file that writes them
becomes unsupported, since the change would not reach the generated code. Generated C without mods is unchanged.

This is the data part of #790 (ericdallo's ExeFS work), split out on its own; the plugin part follows separately.

Co-Authored-By: itaskaev2 <165683571+itaskaev2@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 15:51:42 +01:00
itaskaev2andClaude Opus 5.5 8ac207f353 Grow the texture heap a mod's HeapDef asks for instead of serving that table
HD texture packs made for the emulators ship their own HeapDef with TextureHeap and its parent grown for the
emulators' 8 GB memory option (HDPacks.com's 4K pack: by 3,419,000 KiB). Served as it is, the game asked for room the
application pool does not have and crashed at start (#673); without the file it looped the panic Blood Moon.

Before mem_init sizes the pool, resolution.c reads the HeapDef of every switched-on mod (mods.c mods_peek_romfs, which
lists the mods' RomFS roots without the rest of the scan: mods_scan needs paths main sets later) and counts the largest
TextureHeap growth over the shipped 506,880 KiB like TOTK_TEX_HEAP_EXTRA_MB (the larger of the two, at most 4 GiB). The
pool and the heap cap grow by it, and romfs.c heapdef_overlay serves the game's own table grown by that amount in the
mod's place, so the other heaps keep the sizes of the game version that runs.

Tested with the HDPacks.com 4K Texture Pack v1.0 as players install it, on 1.4.3 and 1.2.1 (RTX 4080 SUPER): the game
loads a save and runs at 60 fps with 0 validation errors, and holds 4.5 GB of game memory pools against 1.2 GB without
the pack. docs/mods.md, README.md and totk.ini.example say so; other packs come with no guarantee.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 09:43:41 +01:00
Valiantsin DzerakhandClaude Opus 5.5 c3dae879cb Build the mods' ExeFS patches into the game and switch them with their mod
A mod that patched the game code (.ips, .pchtxt) stayed off as a whole.
tools/exefs_patches.py now reads IPS, IPS32 and IPSwitch files from each
mod's exefs folder and from atmosphere/exefs_patches/<name>/. It keeps the
ones whose build id is main's and turns their writes into main's code into
one patch set per file. The writes go through the same rules as the code
cheats (tools/cheats.py convert). A file that writes main's data, or that the
rules cannot express, is unsupported as a whole. The setup's lift runs it
after cheats.py and writes build-cache/exefs.status.

runtime/mods.c checks each patch file against that status:

- a built file's set is switched on with its mod;
- a file the build lacks keeps the mod off and starts the rebuild at the next
  start, like a code cheat does;
- an unsupported file keeps the mod off, and the Mods tab shows the reason;
- a file for another version is counted and left out.

A mod patch on a site of one of the port's own sets turns that set off while
the mod is on, and the Mods tab names it. The Mods tab also gets the "Rebuild
the game now" row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 14:29:40 +03:00
Valiantsin DzerakhandClaude Opus 5.5 ac69f39529 Read cheat files from the mods folder instead of shipping them
A cheat file is now part of a mod: mods/<mod>/cheats/<build id>.txt, or the
Atmosphere places inside the mod folder, the file name in any case. The port
ships no cheat files any more (the MyNXCheats files and their notice row are
gone).

- tools/cheats.py --mods builds the code cheats of every mod folder; a
  cheat's key hashes "<mod folder>/<name>", so two mods' cheats of one name
  keep their own switches.
- The setup reads the cheats from <install>/mods and writes the status to
  build-cache/cheats.status.
- runtime/cheats.c reads the files of the enabled mods the port can use, in
  the Mods tab order, and the status from build-cache.
- A mod with only cheats is usable. The Cheats tab groups the cheats by mod,
  and the Mods tab says how many cheats a mod brought.
- The cheat texts are in all four menu languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 14:05:31 +03:00
Valiantsin DzerakhandClaude Opus 5.5 b875e3efee Scan a mods folder next to totk.exe and keep its order and switches in totk.ini
One folder per mod as emulators take them: romfs, exefs and cheats folders, the Atmosphere layout and TKMM's output
(romfslite counts as romfs). A mod with its own code (subsdk or a replaced main) stays off as a whole, so does one with
ExeFS patches until a rebuild applies them; cheat files are listed, not loaded yet. The scan goes through the platform
layer, so Linux builds it. probe-mods covers the layouts and the order keys; probe-cfg fails on a key listed twice in
the defaults table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 13:14:36 +03:00