A mod reaches the game in one of two ways:
- RomFS content is loaded while the game runs. Whether a mod is used is decided by one file:
manifest.tsv. The app does not scan folders for mods. - Code patches for the main module (
exefs/main.pchtxt,exefs/*.ips,exefs/*.ips32) are merged into the app at build time with--mod. See Code patches below.
Nothing under exefs/ is loaded while the game runs: the app runs the three code modules it was built from,
rewritten for Apple silicon and bound to their SHA-256. The build is the only place code can change.
The launcher points TOTK_ROMFS_MODS at
~/Library/Application Support/MacNativeGames/TOTK/mods/<version>
where <version> is the game version the app was built from: v0 (1.0.0), v121 (1.2.1) or
v143 (1.4.3).
When no controller is connected at start and mods/<version>-keyboard/manifest.tsv exists, the launcher points
TOTK_ROMFS_MODS at that folder instead, so the prompts show the Mac keyboard's keys while you play on the keyboard:
python3.14 scripts/make_button_icons.py "$HOME/Library/Application Support/MacNativeGames/TOTK/mods/v0-keyboard" \
--app "Tears of the Kingdom.app" --version v0 --style azerty # or --style keyboard for a US layoutThe choice is made once per start: connecting a controller later keeps the keyboard icons until the next start.
Only the files listed in manifest.tsv are served. Each line has four tab-separated fields:
<RomFS path> <size> <SHA-256 of the mod file> <SHA-256 of the original, or ->
At startup the loader checks each listed file's size and SHA-256, and checks the original's SHA-256
against the game image. - in the last field adds a file the game's RomFS does not have (used by mods
that add assets). Paths are case-sensitive and keep the RomFS spelling.
Tears of the Kingdom and Breath of the Wild on the Mac keep a record of the mods folder after a full check (in the game's data folder, never in
the mods folder): while the manifest's text and every listed file's size, dates and file identity stay the same, the next start reuses
the check instead of hashing again. Another mods folder or a changed file hashes again; TOTK_ROMFS_VERIFY=full always does.
A folder without manifest.tsv means "no mod". Files copied into the folder but not listed are not
used. In detail:
- A new path that is not listed is treated as absent: the game cannot see the file.
- A replacement whose size or hash changed without regenerating the manifest stops the start with
RomFS overlay file missing or wrong sizeorRomFS overlay integrity mismatch. - A path that exists in the game but is not listed is read from the game, so the copied file has no effect.
A build can perform steps 2 and 3 with --mod <mod folder> --install-mod-romfs. That flag replaces the version
folder whole (what it held is kept next to it as a backup - see the mod's RomFS files); without it the build
leaves the folder alone
and prints the two commands that fill it by hand. The steps below are the manual route either way.
-
Quit the game completely.
-
Copy the mod's RomFS paths directly into the version folder. If the mod ships a
romfs/folder, copy its contents, not the folder itself:MODDIR="$HOME/Library/Application Support/MacNativeGames/TOTK/mods/v121" rsync -a --exclude='.DS_Store' --exclude='manifest.tsv' "/path/to/mod/romfs/" "$MODDIR/"
-
Generate the manifest with the built app. Run this from the repository root:
python3.14 games/totk/scripts/make_mod_manifest.py "$MODDIR" \ --app "/path/to/Tears of the Kingdom.app" --version v121
The script reads
Contents/Resources/totk/extracted/<version>/romfsfrom the app, hashes each file and its original, leaves out files that are identical to the original, and writesmanifest.tsv. It prints a line such as...: 12 files (10 replaced, 2 added).--check,--excludeand--versionbelong to this script, not tobuild_app.py(which only takes--modand--install-mod-romfsand runs the script itself,--checkincluded, whatever flags were passed):--checkreports what the manifest would hold and writes nothing,--excludeleaves a path to the app's own version of it. -
Start the game and check the log:
grep "mods/v121 checked" "$HOME/Library/Logs/MacNativeGames/totk.log" | tail -1
It should say
.../mods/v121 checked, N files; additions also printM files added to the RomFS.
The game reads the installed folder as it is; it does not follow the folder that was downloaded or unpacked. If the new version removes files, set the old version folder aside (or delete it after a backup) before copying, or the removed files stay active. Generate the manifest again after every change.
--mod <mod folder> merges a mod's main-module code patches into the app while it is built. The app has no module
loader: at start it maps the three code modules it was built from (main, sdk and subsdk0), rewritten for Apple
silicon and bound by SHA-256. The patches are applied to the verified retail main of the version being built before
that rewrite, so the app still matches the hash it is bound to; RomFS (data) mods are unaffected and are still
loaded at start.
python3.14 build_app.py "/path/to/Tears of the Kingdom.xci" -k "/path/to/prod.keys" --mod "/path/to/Mod"Several mods with code patches are combined in a mod manager first: TKMM's merged output is one folder with one
exefs/ and one romfs/ (a manager may also pack several mods' records into one .ips), and --mod takes that
folder as it is. Two patch files that change the same bytes are refused with both names, so a merge that overwrote
one mod's change with another's stops the build instead of shipping silently.
The folder holds the mod's files in the usual layout - exefs/ for code, romfs/ for data - and either half is
enough: without exefs/ there is no code to merge, and without romfs/ the version folder is never touched. An
exefs/ that holds nothing to merge into main (subsdk9, a main.npdm) is a note, not a failure: the build
carries on, its code half is in the app, and its data half takes effect once the folder is installed
(--install-mod-romfs, or by hand). With --update the patch is merged into the updated module, which is the one
the app runs.
A main .pchtxt can also be applied when the game starts, without a build:
open --env TOTK_PCHTXT="/path/to/mods.pchtxt" "/path/to/Tears of the Kingdom.app"It is read the way --mod reads it, and its @nsobid must match main's build ID, which a built app keeps in
extracted/<version>/exefs/main.build-id. The rewriter doesn't see these bytes, so a patch that makes system calls,
uses the thread-pointer or counter registers, or uses x18 still needs a build with --mod. A line on a site the app
patches itself stops the start.
Breath of the Wild 1.9.0 and 1.6.0. The same --mod flag and the same patch formats work for both Breath of the Wild
builds (give the game files as for any build of that version: the base NSP and --update, or the card image for 1.6.0).
The patch is applied to the verified main of that version, and the @nsobid- line must name that main (the 20 bytes at
0x40 of the extracted main). It is refused when it lands on a site the app patches or checks itself in this game: the
real-time frame step, the pad repeat count (on 1.6.0 the whole 38-instruction pad loop and the 9-instruction pause menu
countdown), the docked render size, the output size (TOTK_OUTPUT_RES, 1.6.0 only), the TOTK_JQ_CHECK sites (1.6.0 only) and the sites listed for that version in
runtime/game_version.h (games/totk/scripts/patch_sites.py reads them out of runtime/game_patches_botw.c, and out of
game_version.h and the runtime files that use those addresses). Three
things differ from Tears of the Kingdom:
--install-mod-romfsis refused for this game. Copy the mod's RomFS files into~/Library/Application Support/MacNativeGames/BotW/mods/botw160(botw190for 1.9.0) and write the manifest as in Breath of the Wild below; the build prints this when the mod has aromfs/.--platform iosbuilds the iPhone / iPad app from the same merged main, but a code mod was not tried on a phone.- To try a
.pchtxtwithout a build, start the game from the work folder (<work>/totk, which holdsextracted/botw190/exefs/mainorextracted/botw160/exefs/main) withTOTK_PCHTXT=<file>(a development switch, Mac only; the same reading as the build, but the bytes go into the rewritten main the game runs, so a patch on an instruction the rewriter changed behaves differently there). The game stops at start when the file is for another build of main, touches a site the build refuses (the list above), reaches outside main or has a byte that is not two hex digits.
What was tested: 1.9.0 code mods were built and played on a Mac (M1 Pro). On 1.6.0 (M1 Pro, macOS 27, base v0 and the
1.6.0 update, Great Plateau save, docked; October 24) mod_exefs.py apply --version botw160 refuses a patch on a site the
app reserves, and a one-word mod merged with build_app.py --mod builds and boots at 58-60 fps. TOTK_PCHTXT was not
tried on 1.6.0, and the unit tests cover its site list and its reader. Nothing was tested on a device: there was no real Switch to compare with, and
no --mod build was made for an iPhone / iPad.
A build does not write to the version folder (~/Library/Application Support/MacNativeGames/TOTK/mods/<version>;
Breath of the Wild's is BotW/mods/botw160 or botw190, see below) unless this flag is given: the folder may hold another mod's files, or files copied by hand. With the flag, the
build replaces it with the mod's romfs/ and writes its manifest.tsv:
python3.14 build_app.py "/path/to/Tears of the Kingdom.xci" -k "/path/to/prod.keys" \
--mod "/path/to/Mod" --install-mod-romfsThen, at the very end, the build:
- replaces
~/Library/Application Support/MacNativeGames/TOTK/mods/<version>with a copy of the mod'sromfs/, so after the build the folder holds exactly this mod's RomFS and nothing else. What it held before - another mod's files, files copied by hand - is not deleted: it is moved next to it as<version>.backup-<date>-<time>(the game never loads that folder; delete it yourself once you no longer need it). A mod whose files the game would all take from the app instead replaces nothing, and then the folder is left alone: see below; - writes
manifest.tsvwithscripts/make_mod_manifest.pyagainst the app just built, so a path the app replaces itself is left out (the heap table included: the 2K overlay carries the mod's heap sizes; the UI archive is merged instead, which leaves the mod's own copy next to it as<name>.mod-original- the game ignores it), and a misspelt path stops the build at its last step - the app is already written by then - with the reason instead of stopping the game later.
The folder is not touched until a complete replacement exists: the build copies the mod's romfs/ into a folder
next to it, writes the manifest there, and moves the new copy into place only when it is complete (the old folder
becomes the backup). Before any of it, the manifest tool runs with --check on the mod's own folder, so a
misspelt path stops the build while the version folder still holds what it held; and a mod whose files the game
would all take from the app instead (every one identical to the original, or one the app replaces itself) replaces
nothing the game loads - the build says so and leaves the folder alone rather than swapping in a folder with no
manifest. The build warns when it starts and again right before the copy:
--install-mod-romfs: the player's mod folder for the version this build makes will be REPLACED by The Second Quest
1.4.3/romfs (and its manifest.tsv) when the build ends; what it holds now is moved next to it as
<folder>.backup-<date>-<time>, not deleted. Without the flag the build leaves the folder alone.
...
.../mods/v143: replaced by The Second Quest 1.4.3/romfs and its manifest.tsv (--install-mod-romfs); what it held before is kept in .../mods/v143.backup-20261021-213000
4/4 app: .../mods/v143 holds 5250 files from The Second Quest 1.4.3/romfs now (what it held before: .../mods/v143.backup-20261021-213000; delete that folder once you no longer need it)
left out (the app replaces it, and the 2K overlay already carries these heap sizes): System/HeapSize/Product.Nin_NX_NVN.HeapDef.byml.zs
.../mods/v143/manifest.tsv: 5229 files (4200 replaced, 1029 added)
Without the flag the build leaves the folder untouched and prints the two commands that perform the copy and the manifest by hand.
Nothing changes at run time: the game loads this folder and its manifest as before. The iPhone / iPad build has
no player mod folder yet, so there --mod merges the code patches only (and --install-mod-romfs is refused
there: there is no folder to fill).
What the build does, in order:
-
Extracts and verifies the retail ExeFS, as always. The patch is only ever applied to the verified retail module of the version being built, never to an already rewritten one.
-
Applies the mod's patches. Offsets are main addresses - the address space the game's code lives in, the same numbers the app's own patch tables use:
.pchtxt: the community format, read the same way as the runtime's ownTOTK_PCHTXTreader (section switches and@flaglines included, see below). The first line must be@nsobid-<build id>: the 16 bytes the rewriter's tables use (32 hex digits) or the 20 bytes the runtime compares (40 hex digits; the runtime's ownTOTK_PCHTXTexperiment takes only that longer form). Patch lines<hex main address> <hex bytes>follow, and only lines after@enabledcount:@disabledswitches the following section off again (a file that keeps an edit around without applying it),@enabledswitches it back on, and@stopends the file. A@flag offset_shift 0x100line must come before the first patch line - it says the addresses leave out the 0x100-byte NSO header an IPS form counts, which is how they are applied; a file without it, or with another shift, is refused by file and line rather than patched 0x100 bytes off.@flag print_values(a display option of the patching tools, in every community pchtxt we have seen) is accepted; any other flag is refused. The@nsobid-line identifies the target build, so the file name does not matter..ips/.ips32: applied as emulators apply them, whose offsets count the 0x100-byte NSO header, so the build subtracts 0x100. A record below 0x100, a truncated file or a missingEOFis an error. The file names neither its module nor its build, so it is read as a main patch only when it is namedmain, or after main's build id (exefs/<build id>.ips, the Atmosphere and mod-manager convention). Anything else is left out with a note: a patch forsdkorsubsdk9, or one named after another build of main. An.ipsnamedmainhas no id to check; naming it after the build id, or shipping a.pchtxt, provides that check.
-
Checks the result before building on it. The patch is refused, with the address and the reason, when it lands outside main's text, rodata or data (the padding after text is reserved), when two patch files change the same bytes, when it changes nothing, or when it touches a site the app patches itself - the 60 FPS and real-time frame-step sites, render/output resolution, ultrawide, cloth, and the rewriter's registered cuts. Those features are set by the app (
TOTK_FPS60,TOTK_REALTIME,TOTK_RENDER_RES,TOTK_OUTPUT_RES,TOTK_ASPECT): the runtime re-checks the original instruction at each of its sites and stops the game if it changed. -
Rewrites the patched module for Apple silicon and binds the app to its SHA-256. The report in
--work(analysis/phase12-validation.jsonfor 1.0.0,analysis/<version>-port/phase12-validation.jsonotherwise, undermod_exefs) records the mod folder, every patch file's SHA-256, the addresses it changed and the merged module's hash.
The iPhone / iPad build merges the same way: --mod with --platform ios.
What else a mod's exefs/ may hold:
In the mod's exefs/ |
Result |
|---|---|
*.pchtxt, *.ips, *.ips32 for main |
merged into the build; an .ips must be named main or after main's build id, while a .pchtxt names its build in @nsobid- and may be named anything |
main.npdm |
ignored with a note: the native loader never reads a module's metadata |
subsdk9 and other extra code modules |
not loaded, with a note in the build output and in the report: the app loads the three modules it was built from (main, sdk, subsdk0), so the module's own code never runs |
a whole replacement main |
refused: a patch is required instead, so the build can check it against this version |
nothing for main (subsdk9 alone, a main.npdm alone, even an empty exefs/) |
noted, not refused: nothing is merged into main and the build carries on - its code is not in the app, and its data applies once the folder is installed |
An extra module is how a mod built with a hooking framework (exlaunch and the like) changes code while the game runs: its trampolines never install here. Such a mod - The Second Quest is one - keeps its main patches and its whole RomFS, but not the part of its code changes that lives in that module. Making one work means the app growing a module loader (rewriting the module for Apple silicon and answering its service calls), which this version does not do.
Changing the mod's code after a build means building again (the mod's bytes are part of the app), and a
build with --mod --install-mod-romfs also replaces its data folder. Changing only RomFS files needs no build:
copy them into the version folder and write the manifest again (steps 2 and 3 above). A merge that already
happened is reused: the rewrite is skipped while the recorded hash matches, and the record names the
rewriter's own SHA-256 too, so a changed patch_nso.py makes it rewrite instead of reusing the old image.
The 2K output overlay records the heap table it was built on: a build without --mod after a build with it
rebuilds the overlay from the retail table instead of keeping the mod's heap sizes.
Some texture packs are made for an emulator's 8 GB DRAM mode and do not fit the 3.2 GiB a retail console gives the game. For a separate, manually enabled texture overlay, prepare the pack outside the source checkout:
python3.14 games/totk/scripts/install_texture_pack.py "/path/to/pack/RomFS" \
--app "/path/to/Tears of the Kingdom.app" --version v143 --output "/path/to/installed-textures"
printf '%s\n' '/path/to/installed-textures' > "$HOME/Library/Application Support/MacNativeGames/TOTK/texture-pack-path.txt"The pack is off by default and has no in-game settings entry. A legacy texture-pack.txt is ignored.
To enable it explicitly for one launch:
open --env TOTK_TEXTURE_PACK=1 "/path/to/Tears of the Kingdom.app"The enabled pack loads its checked texture overlay and selects the 8 GB memory layout. An ordinary launch keeps stock
textures, size tables and memory layout. The installer fits the size tables to the app's game version and preserves
all installed canvas-heap increments. Reinstall to a new output folder after changing the pack, game version or canvas
modes, then update the saved path. TOTK_TEXTURE_PACK_DIR overrides the path. A conflicting TOTK_DRAM_8GB=0, missing
files or another mod replacing the same size table stops startup with a log message. This feature is for Mac TOTK.
For the older workflow that merges texture files into the player's other mods:
Texture packs are the work of their respective authors and are not included in this repository. For manual installation on the Mac with 1.4.3:
-
Put the pack's
romfsfiles (for example,4kTextures/RomFS) into the version's mod folder (mods/v143), together with any other mod you use. -
The pack's heap table and resource size tables are made for the version it was built for. Fit them to the app's version:
python3.14 games/totk/scripts/texture_pack_tables.py ~/Library/Application\ Support/MacNativeGames/TOTK/mods/v143 \ --app "Tears of the Kingdom.app"
It writes 1.4.3's own
HeapDefwith only the heaps the pack makes bigger raised (for example:TextureHeap,ゲームグラフィックスand草), and 1.4.3'sResourceSizeTable.Product.143with every replaced texture's entry grown by as much as the file grew. Then write the manifest withmake_mod_manifest.pyas usual. Run both again whenever the folder changes. -
Start the game in 8 GB mode:
open --env TOTK_DRAM_8GB=1 "Tears of the Kingdom.app"TOTK_DRAM_8GBreports a 6.8 GiB application pool to the game (as the emulators' 8 GB mode does); the pack'sTextureHeappool, about 3.8 GiB, becomes one zero-copy GPU buffer.
Checked on a 24 GB M-series Mac: about 8.7 GB resident in play and the GPU near full load (the GPU is the bottleneck). A Mac with less memory than that is not expected to run it.
The Breath of the Wild app reads its mods from the folder for its version, botw160 for 1.6.0 or botw190 for 1.9.0:
~/Library/Application Support/MacNativeGames/BotW/mods/botw160
~/Library/Application Support/MacNativeGames/BotW/mods/botw190
The RomFS half above applies: copy the mod's RomFS contents into that folder and generate the manifest with the app,
naming the folder botw160 or botw190, or passing --version botw160 or --version botw190 (1.6.0 shown):
MODDIR="$HOME/Library/Application Support/MacNativeGames/BotW/mods/botw160"
python3 games/totk/scripts/make_mod_manifest.py "$MODDIR" --app "/path/to/Breath of the Wild.app"Check grep "mods/botw160 checked" ~/Library/Logs/MacNativeGames/botw.log | tail -1 after the start
(mods/botw190 checked on 1.9.0).
- A mod that makes a resource larger than the original also has to ship the matching resource size table,
System/Resource/ResourceSizeTable.product.srsizetable, built for the same version. Without it the game reserves the original size and stops at start (for example a translation whosePack/Bootup_<lang>.packgrew). - The game's language follows the app's preferred language, which also picks the language folder a mod must use (
USenforen-US). To give only this game another language:defaults write org.macnativegames.botw AppleLanguages -array en-US.
Button icons that follow your controls (1.9.0 and 1.6.0, an Xbox or PlayStation controller): the builder's Controls tab
("Update the game's button icons", 1.9.0 only), or by hand after you change the layout, makes a mod in which each prompt shows the
button that drives that input, read from controls.txt (the A prompt shows B while the right face button does A):
python3 games/totk/scripts/make_botw_button_icons.py "$HOME/Library/Application Support/MacNativeGames/BotW/mods/botw190" \
--app "/path/to/Breath of the Wild.app"For 1.6.0, give its mod folder (BotW/mods/botw160); the version is taken from the app (--version names it when the
app holds both). 1.6.0's font numbers the stick presses and the d-pad differently, as Tears of the Kingdom does, and the
script uses each version's own code points.
For an Xbox controller it draws nothing: the icon font already holds every button, so each input's code point is pointed at the icon of its
button (LB RB LT RT show as L R ZL ZR, Menu and View as + and -). The action guide beside an object ("A Open") becomes
the Xbox diamond, A at the bottom, B right, X left, Y top, with the button that does the action lit in its place (an
action of A, B, X or Y moved to a button outside the diamond, such as LB, keeps the Switch's diamond there; its prompt in
the text still names LB).
With controller-type.txt saying playstation (key 6), the player gets PlayStation icons, drawn over the font's own button glyphs in their cells (--style playstation,
games/totk/scripts/botw_playstation_icons.py): Cross, Circle, Square and Triangle, L1 R1 L2 R2, Options and Create, and
the guide's key textures with them (its faint letters are left blank); --style xbox keeps the letters. A Nintendo
controller (controller-type.txt saying switch) keeps the
game's own icons, which already name its buttons. The mod replaces the seven Font/Font_*.sbfarc (six on 1.6.0) and
Pack/Bootup.pack (whose Layout/Common.sblarc holds the guide); the layouts keep their size, so no size table is
needed, but another mod that replaces Pack/Bootup.pack cannot be used with it.
The Odyssey app reads its mods from the folder for the update it was built from, v130 for 1.3.0 or v141 for 1.4.1:
~/Library/Application Support/MacNativeGames/Odyssey/mods/v130
~/Library/Application Support/MacNativeGames/Odyssey/mods/v141
The RomFS half above applies: copy the mod's RomFS contents into that folder and generate the manifest with Odyssey's own script and the app (1.4.1 shown):
MODDIR="$HOME/Library/Application Support/MacNativeGames/Odyssey/mods/v141"
python3 games/odyssey/scripts/make_mod_manifest.py "$MODDIR" --app "/path/to/Odyssey.app"Check grep "mods/v141 checked" "$HOME/Library/Application Support/MacNativeGames/Odyssey/last-run.log" after the
start (mods/v130 checked on 1.3.0). Without a manifest the log says RomFS overlay: none and names the folder it
looked in.
- 1.3.0 and 1.4.1 merge to the same game data, so a manifest written for one fits the other. When you build the app again from the other update, rename the folder.
- An app built with a bigger render size (the default, for key 3) replaces
SystemData/ProjectGraphicsQuality.szsitself. The script leaves that file out of the mod's manifest: two overlays that replace one file stop the start. - The game's language follows the Mac's first preferred language. A translation replaces the files of one language
(for English,
LocalizedData/USen/...andLocalizedData/EUen/...) and shows when the game runs in that language.
The games draw their UI from small textures (48x48 and 72x72 button and icon masks, colour icons) that the 3456x1944 picture
magnifies about 2x, so their edges look soft. The Mac app of a Switch 1 game can draw larger copies instead: it looks for
<key>.png in the pack folder when a texture is uploaded, and uses a picture whose size is a whole multiple (up to 8x, the
same on both axes) of the texture. The app falls back to the game's own texture for every texture that has no picture. The UI
shaders use normalised coordinates, so a larger picture draws at the same place and size. Key lists exist for Breath of the
Wild (1.9.0 and 1.6.0 have the same keys, so one pack serves both) and for Tears of the Kingdom 1.4.3. Nothing of the game is
in the project: the pictures come from your own game.
| Variable | Meaning |
|---|---|
MNG_UI_PACK_DIR |
The pack folder. Default ~/Library/Application Support/MacNativeGames/<game>/ui-pack, where <game> is BotW or TOTK. |
MNG_UI_PACK=0 |
Turns the pack off. |
MNG_UI_PACK_HARVEST=<dir> |
Harvest mode: writes each UI texture the game draws into <dir> as <key>.png, with a line in harvest.tsv. A texture already there is not written again, so the folder grows over runs. |
MNG_UI_PACK_HARVEST_FS |
The fragment shaders to harvest, as key prefixes separated by commas, or * for every fragment shader. Default for Breath of the Wild 87d90016,e6a88e12,e1f8208d (the picture shaders and the temperature gauge), for other games *. |
The key is <hash>-<width>x<height>-<NVN format>, where the hash covers the texture's bytes as the game stores them.
Pictures hold the stored channel values: 8-bit grey for one-channel masks, RGB with blue 0 for two-channel masks, RGBA (not
premultiplied, sRGB colour left encoded) for colour.
Workflow
-
Harvest. Start the game with the variable set, and play through the menus, the HUD and the map:
open --env MNG_UI_PACK_HARVEST="$HOME/Library/Application Support/MacNativeGames/BotW/ui-harvest" "/path/to/Breath of the Wild.app"
-
Build the pack with Python 3.14, from the repository folder. Set
--screen-heightto the height of the game's picture (1944 for 3456x1944, 1080 for 1920x1080):python3.14 -m tools.ui_pack build --game botw \ --harvest "$HOME/Library/Application Support/MacNativeGames/BotW/ui-harvest" \ --out "$HOME/Library/Application Support/MacNativeGames/BotW/ui-pack" \ --screen-height 1944
For Tears of the Kingdom 1.4.3, use
--game totk-1.4.3and theTOTKfolders. -
Start the game as usual. The log (
~/Library/Logs/MacNativeGames/botw.logortotk.log) shows[ui-pack]lines with the number of pictures in use.
How the pictures are made. The tool builds only the textures of the game's key list (games/botw/assets/ui_pack_keys.tsv,
games/totk/assets/ui_pack_keys_v143.tsv), with the draw scale and the options given there. It traces each mask into exact
shapes and draws them again at 8x the texture (4x when the longest side is above 128 texels, 2x above 256), with the
texture's own plateau levels, so round stays round and straight stays straight. The picture is pre-filtered for the size at
which it draws on screen: the key list holds the draw scale measured in game shots, and --screen-height converts it to your
picture. Build for your picture's height. If you are not sure, take the smaller height: a pack built for a larger height than
you play at can look worse than the game's own texture.
Quality check. Each picture is checked before it is written: on screen its mean ink and its plateau levels match the
texture, its shapes drawn back at the texture's size match the texture, and it is at least as close to the ideal shape as the
game's texture. A texture that fails is not written, so the game draws its own. The build lists it with the measured values
in manifest.tsv and in its summary, and still exits 0. The tool skips colour art, flat textures, pure gradients and the
textures whose key list entry says skip (with the reason). It names the listed textures that your harvest does not have
yet. Show them in the game with the harvest on, then build again.
--dry-run shows the plan, --only <key,...> limits the keys, --force builds again what is current, --all also builds
the harvested textures that the list does not have (with the default options), and --jobs N sets the number of workers. A
second build makes only the pictures whose texture, options, draw scale or screen height changed. The tool lists what it
wrote in manifest.tsv in the pack folder and rewrites or deletes only the pictures listed there, so pictures made by
another tool or by hand stay. An ai-manifest.tsv from the earlier AI builder is taken over: its pictures are
built again or deleted, and the file is deleted. Delete a picture to go back to the game's texture for that key.
Repeatable builds. tools/deps/pins.py fixes the NumPy, SciPy, ContourPy and Pillow wheels and their SHA-256 values.
The command installs them in an isolated cache automatically. ContourPy (BSD-3-Clause) traces fitted level sets; the
pixel-boundary tracer is this project's MIT implementation. Existing packs rebuild once for method v3.2. Synthetic
shape tests pass, but per-key tuning made with the previous tracer needs visual validation on the player's own harvest.
The repository holds no file made from the game. The harvest folder and the pack are made from your game data: they stay on your Mac and never go into the repository or a pull request.
- Do not edit
manifest.tsvby hand; regenerate it. - Do not change files while the game runs. The loader records each file's identity at start and stops if a file changes mid-session.
- There is one overlay directory for player mods: to use several mods, merge their files into one version folder and generate one manifest. Do not nest mod folders. If two mods change the same path, choose one file.
- The build replaces a few RomFS files itself:
UI/LayoutArchive/Common.Product.<n>.Nin_NX_NVN.blarc.zs(quick-menu timing;<n>is 100, 110 or 140 depending on the version),Event/EventFlow/DmF_SY_GameOver.bfevfl.zs, and with the 2K outputSystem/HeapSize/Product.Nin_NX_NVN.HeapDef.byml.zs. Two overlays cannot replace one path (the start would stop with "two overlays replace the same file"), so:- the UI archive is merged: a translation's archive keeps its textures and takes the build's quick-menu edit - the
tool writes the merged archive in the mod folder, keeps the mod's own copy next to it as
<name>.mod-original, and the merged file replaces the build's overlay (#73). It refuses when the mod changed the members the build patches (the capture animations) rather than silently dropping one side; - the heap table is folded in by the build: with
--modthe 2K overlay is built on top of the mod's table; - any other one (the game-over flow) is left to the app, with a line saying which file it left out.
- the UI archive is merged: a translation's archive keeps its textures and takes the build's quick-menu edit - the
tool writes the merged archive in the mod folder, keeps the mod's own copy next to it as
make_mod_manifest.pyhandles all of them itself: the UI archive is merged as above, and any other mod file whose path the app replaces is left out of the manifest (with a line saying so), because both overlays cannot be loaded. For the heap table the line says whether the app's 2K overlay carries the mod's sizes (already carries these heap sizes, which the build arranges with--mod) or says to build with--mod.- A mod manager (TKMM, or Ryujinx's
mods/contents/<title id>/<name>) providesexefs/andromfs/in one folder:--modtakes that folder - itsexefspatches are merged, and a manager's merged.ipsmay hold several mods' records in one file - and--install-mod-romfshas the build replace the version folder with itsromfs/and write the manifest itself (no--excludeneeded: the manager's heap table and the app's 2K overlay are reconciled). Re-merge in the manager and build again after every change: the game checks every file's hash at start. This is also how several mods with code patches are combined: merge them in the manager first, then build with--mod <the manager's output folder> --install-mod-romfs; the build refuses two patch files that change the same bytes and names both of them. - Graft (by nickpetrovic, MIT, built from source) is a community mod manager for these Mac apps: it merges Tears of the Kingdom mods with TkSharp (the library TKMM uses), checks their code patches and installs the result into the version folder above. It is a separate project that this repository has not tested; it needs a MacNativeGames checkout and the .NET 10 SDK.
- A mod with a code patch also needs its
exefs/patch to match the game version the app is built from. The build checks what the file itself says: a.pchtxtis refused when its@nsobid-names another main, and an.ips/.ips32named after a build id is left out when that id is not this main's. - This guide covers the Mac app; installing mods into the iPhone/iPad app container is not covered.
The game closes the window and writes one line to ~/Library/Logs/MacNativeGames/totk.log instead of starting with data
it cannot trust. The line above it names the file. The log is off by default: turn it on with
defaults write org.macnativegames.totk TOTK_DEBUG_LOG -bool YES (org.macnativegames.botw for Breath of the Wild) and start
the game again. The grep checks on this page need it too.
two overlays replace the same file- the manifest lists a path the app replaces itself: a manifest written by hand or by another tool, sincemake_mod_manifest.pyleaves those paths out by itself (the UI archive it merges instead). Regenerate it with that script.two overlays add the same file- two overlays (the app's, or two mod folders) add one path the RomFS lacks.RomFS overlay integrity mismatch- a file in the mods folder differs from the SHA-256 in the manifest: files were copied in after the manifest was written. Regenerate it (make_mod_manifest.pywrites nothing for a mismatching dump).RomFS overlay names a file the RomFS lacks/adds a file the RomFS already has- a replacement's original is wrong (a file copied from another game version); regenerate the manifest and rebuild the app for that version.RomFS overlay file changed while the game ran- the folder was edited during play; restart the game (and regenerate the manifest).
The window can also vanish with no line of ours: a mod's data can make Metal abort the process (the log then has a host
call stack, for example -[MTLTextureDescriptorInternal validateWithDevice:] "requests 9 mipmap levels, but the
dimensions (1, 1, 1) can only support 1"). A texture with more mip levels than its size holds is something the Switch
never checks and Metal refuses to build; the app caps the chain at what the dimensions allow and logs
[tex] <w>x<h>x<d> ... 声明 N 级 mip ..., so check the mod's texture if the picture looks wrong.
These come from how a pack was built, not from its content, and none of them prints one of the lines above.
- A
.pchtxtwithout@flag offset_shift 0x100. Its addresses aremainaddresses, while an IPS file's offsets count the 0x100-byte NSO header. BothTOTK_PCHTXTand--modstop the start when a patch line comes before that flag, or when it names another shift: the alternative is every byte landing 0x100 bytes off without an error. Converting an IPS by hand:main address = IPS32 offset - 0x100. - A
.zswhose zstd frame does not declare its content size. The game's decompressor has no size to read for those and decompresses to a null destination: the window dies right afterENTER nnMainand the log holds nothing of ours.zstdwrites such frames when compressing from a pipe (zstd -c); the descriptor byte of the frame header (raw[4]) must have bits 7-6 set. Compress from the bytes with a library, assert(raw[4] >> 6) & 3, and keep the window size, checksum and dictionary of the file being replaced (zstd -l -v). - A merged
ResourceSizeTablethat kept the records but lost the slots. A manager that merges.rsizetablefiles can write the record array only; actors whose slot is gone then load with size 0. Slot names are logical resource paths (Actor/...), not RomFS paths, so not finding them in the index is normal. Rebuild the table as a union of the tables being merged - each value copied byte for byte, the record array kept sorted by key, since the game binary-searches it - and check the frame header of the compressed result before installing it.grow_restblingames/totk/scripts/make_button_icons.pyis one writer of that format.
一个 mod 有两种方式进入游戏:
- RomFS 内容在游戏运行时加载,是否生效完全由
manifest.tsv决定,App 不会扫描文件夹找 mod。 - 主模块的代码补丁(
exefs/main.pchtxt、exefs/*.ips、exefs/*.ips32)在构建时用--mod合并进 App,见下面的代码补丁。
exefs/ 里的文件在运行时一律不加载:App 跑的是构建时改写好的三个代码模块,按 SHA-256 绑定。代码只能
在构建这一环节改变。
启动器把 TOTK_ROMFS_MODS 指向
~/Library/Application Support/MacNativeGames/TOTK/mods/<version>
<version> 是构建这个 App 时使用的游戏版本:v0(1.0.0)、v121(1.2.1)、
v143(1.4.3)。
启动时没有连接手柄、且 mods/<version>-keyboard/manifest.tsv 存在时,启动器改把 TOTK_ROMFS_MODS 指向那个目录,
用键盘玩的时候提示里显示的就是 Mac 键盘的按键:
python3.14 scripts/make_button_icons.py "$HOME/Library/Application Support/MacNativeGames/TOTK/mods/v0-keyboard" \
--app "Tears of the Kingdom.app" --version v0 --style azerty # 美式键盘用 --style keyboard每次启动只选一次:游戏中途再接上手柄,键盘图标会保留到下次启动。
只有列在 manifest.tsv 里的文件才会被提供给游戏。每一行是四个用制表符分开的字段:
<RomFS 路径> <大小> <mod 文件的 SHA-256> <原版文件的 SHA-256,或 ->
启动时加载器会逐个核对 mod 文件的大小和 SHA-256,并核对原版文件的 SHA-256。最后一个字段是 -
表示这是游戏 RomFS 里没有的新文件(用于新增资源)。路径区分大小写,必须和 RomFS 里的写法一致。
Mac 版王国之泪和旷野之息在一次完整核对之后为 mod 目录留一份记录(放在游戏数据目录里,不放进 mod 目录):清单的内容,以及清单里每个文件的
大小、日期和文件身份都没变时,下次启动沿用这次核对,不再重新计算哈希。换一个 mod 目录或改了文件就重新核对;
TOTK_ROMFS_VERIFY=full 每次都完整核对。
没有 manifest.tsv 就等于没有 mod。只把文件复制进目录但不写进清单,游戏不会使用:
- 清单里没有的新路径会被当成不存在,游戏完全看不到这个文件。
- 覆盖已有文件但大小或哈希变了、又没有重新生成清单,启动会直接报
RomFS overlay file missing or wrong size或RomFS overlay integrity mismatch。 - 原版有这个路径、但清单里没列,游戏会读取原版文件,复制进去的文件看起来“没有效果”。
构建可以用 --mod <mod 目录> --install-mod-romfs 完成第 2、3 步。这个参数会把版本目录整个替换掉(原来的内容
作为备份留在旁边,见下文模组的 RomFS 文件);不带它时构建不会碰这个目录,只在结束时打印手动执行的两条命令。下面是
手动流程(构建做的是同一件事,只是先在旁边的目录里做好再整体换进来)。
-
先完全退出游戏。
-
把 mod 的 RomFS 路径直接放进版本目录。如果 mod 带一层
romfs/文件夹,复制的是它里面的 内容,不是romfs这一层:MODDIR="$HOME/Library/Application Support/MacNativeGames/TOTK/mods/v121" rsync -a --exclude='.DS_Store' --exclude='manifest.tsv' "/path/to/mod/romfs/" "$MODDIR/"
-
用构建好的 App 生成清单。在仓库根目录执行:
python3.14 games/totk/scripts/make_mod_manifest.py "$MODDIR" \ --app "/path/to/Tears of the Kingdom.app" --version v121
脚本会读取 App 里的
Contents/Resources/totk/extracted/<version>/romfs,计算每个文件和原版 文件的哈希,跳过与原始完全相同的文件,然后写入manifest.tsv。成功时会打印类似...: 12 files (10 replaced, 2 added)的一行。--check、--exclude、--version都是这个脚本的选项,不是build_app.py的(构建只接收--mod和--install-mod-romfs,自己带--check调用这个脚本,与传入的参数无关):--check只报告清单会 包含什么、不写任何文件;--exclude把某个路径留给 App 自己的版本。 -
启动游戏,确认日志:
grep "mods/v121 checked" "$HOME/Library/Logs/MacNativeGames/totk.log" | tail -1
应出现
.../mods/v121 checked, N files;有新增文件时还会打印M files added to the RomFS。
游戏读取的是安装目录本身,不会跟着下载或解压出来的那个文件夹走。如果新版本删掉了旧版本的某些 文件,先把旧的版本目录整个移走(或备份后删除)再复制,否则被删掉的文件会继续生效。每次改动后 都要重新生成清单。
--mod <模组文件夹> 在构建 App 时把模组主模块的代码补丁(IPS、IPS32,或文本格式 .pchtxt)合并进去。
python3.14 build_app.py "/path/to/Tears of the Kingdom.xci" -k "/path/to/prod.keys" --mod "/path/to/Mod"App 没有模块加载器:启动时它映射的是构建时的那三个代码模块(main、sdk、subsdk0),已经改写为 Apple 芯片版本
并按 SHA-256 绑定。--mod 在改写之前把补丁应用到当前版本核对过的原版 main 上,所以构建出的 App 仍与它绑定的
哈希一致;RomFS(数据)部分不受影响,仍按上面的说明在启动时加载。
多个带代码补丁的 mod 先在模组管理器里合并:TKMM 的合并输出就是一个文件夹,里面一套 exefs/、一套
romfs/(管理器也可能把几个 mod 的记录合进同一个 .ips),--mod 原样接收这个文件夹。两个补丁文件改到同一批
字节时构建会拒绝并报出两个文件名,所以「合并时被另一个 mod 覆盖」这种情况会停在构建阶段,不会不声不响地打进去。
文件夹按 mod 的常见结构放文件——代码在 exefs/、数据在 romfs/;只有一半也可以:没有 exefs/
就是没有代码要合并,没有 romfs/ 时构建不会碰版本目录。exefs/ 里没有可合并进 main 的东西(只有
subsdk9、只有 main.npdm,甚至空的 exefs/)只算提示、不算失败:构建照常往下走,只是这个 mod 只生效数据
那一半。带 --update 时补丁合并进更新后的模块,也就是 App 实际运行的那个。
main 的 .pchtxt 也可以在游戏启动时应用,无需重新构建:
open --env TOTK_PCHTXT="/path/to/mods.pchtxt" "/path/to/Tears of the Kingdom.app"读法与 --mod 相同,@nsobid 必须与 main 的构建 ID 一致;构建好的 App 把它存放在 extracted/<版本>/exefs/main.build-id。
改写器看不到这些字节,所以含系统调用、使用线程指针或计数器寄存器、或使用 x18 的补丁仍需在构建时用 --mod。补丁行落在 App
自己修改的位置时启动会停止。
旷野之息 1.9.0 和 1.6.0。 同样的 --mod 参数和同样的补丁格式适用于旷野之息的两个版本(游戏文件按该版本的常规构建给出:基础 NSP 加 --update,1.6.0 也可以给卡带镜像)。
补丁打在核对过的该版本 main 上,@nsobid- 一行必须是这个 main 的(解出的 main 偏移 0x40 起的 20 字节)。补丁落在这个游戏里 App 自己打补丁或检查的位置上会被拒绝:
实时帧步长、手柄重复计数(1.6.0 上是整段 38 条指令的手柄循环和 9 条指令的暂停菜单倒计时)、底座模式渲染分辨率、输出分辨率(TOTK_OUTPUT_RES,仅 1.6.0)、TOTK_JQ_CHECK 的位置(仅 1.6.0),以及 runtime/game_version.h 里该版本一段列出的位置
(games/totk/scripts/patch_sites.py 从 runtime/game_patches_botw.c 读出,game_version.h 的位置从它和用到这些地址的运行时文件读出)。与王国之泪有三处不同:
- 这个游戏拒绝
--install-mod-romfs。把模组的 RomFS 文件复制到~/Library/Application Support/MacNativeGames/BotW/mods/botw160(1.9.0 是botw190),再按下面「旷野之息」一节生成清单;模组带romfs/时构建会提示这一点。 --platform ios用同一份合并后的 main 构建 iPhone / iPad 版,但没有在手机上试过代码模组。- 想不重新构建就试一个
.pchtxt,在工作目录(<work>/totk,里面有extracted/botw190/exefs/main或extracted/botw160/exefs/main)里用TOTK_PCHTXT=<文件>启动游戏 (开发用开关,仅 Mac;读法与构建相同,但字节写进游戏实际运行的改写后 main, 所以补丁落在改写器改过的指令上时表现会不同)。文件是给另一个 main 的、改到构建会拒绝的位置(见上面的列表)、超出 main 的范围,或有一个字节不是两位十六进制数时,游戏在启动时停止。
测试范围:1.9.0 的代码模组在 Mac(M1 Pro)上构建并实际玩过。1.6.0(M1 Pro,macOS 27,基础 v0 加 1.6.0 更新,初始台地存档,底座模式;10 月 24 日):mod_exefs.py apply --version botw160 拒绝落在 App 保留位置上的补丁,用 build_app.py --mod 合并的单字模组能构建并启动,58-60 帧。TOTK_PCHTXT 没有在 1.6.0 上试过,单元测试覆盖它的位置列表和读取器。
没有在任何设备上测试:没有真机 Switch 可以对比,也没有做过带 --mod 的 iPhone / iPad 构建。
不加这个参数时,构建不会写版本目录(~/Library/Application Support/MacNativeGames/TOTK/mods/<version>):
里面可能有另一个 mod 的文件,也可能是手动复制进去的。加上这个参数,构建会用模组的 romfs/ 替换它并生成
manifest.tsv:
python3.14 build_app.py "/path/to/Tears of the Kingdom.xci" -k "/path/to/prod.keys" \
--mod "/path/to/Mod" --install-mod-romfs这时构建最后会:
- 用 mod 的
romfs/的副本替换~/Library/Application Support/MacNativeGames/TOTK/mods/<version>, 所以构建结束后这个目录里就是这一个 mod 的 RomFS,没有别的。原来的内容(另一个 mod 的文件、手动复制进去的 文件)不会删除,而是挪到旁边的<version>.backup-<日期>-<时间>(游戏不读这个目录,不需要了自己删掉)。如果 这个 mod 的文件最终一个都不会被游戏加载,那就什么都没替换,目录保持不动,见下文; - 用
scripts/make_mod_manifest.py对着刚构建好的 App 生成manifest.tsv,所以 App 自己替换的路径会被排除 (包括堆表:2K 覆盖文件已经带着 mod 的堆大小;UI 归档则是合并,模组原文件会以<name>.mod-original留在旁边, 游戏不会读它);路径大小写写错的会终止构建并给出原因,而不是等到启动时才停止。
版本目录在完整副本就绪之前不会被动:构建先把 mod 的 romfs/ 复制到它旁边的一个目录里、在那里写好清单,确认完整
之后才把新的一份换进来(旧的目录变成备份)。在此之前还会用 --check 在 mod 自己的目录上跑一遍清单工具,所以路径写错
的 mod 会在版本目录还没被碰过时就停下;另外,如果这个 mod 的文件最终一个都不会被游戏加载(全部与原版相同,或者全是
App 自己会替换的文件),它其实什么都没替换——这时构建会说明并保持版本目录不动,而不是换成一个没有清单的目录。
构建开始时和复制前各提示一次:
--install-mod-romfs: the player's mod folder for the version this build makes will be REPLACED by The Second Quest
1.4.3/romfs (and its manifest.tsv) when the build ends; what it holds now is moved next to it as
<folder>.backup-<date>-<time>, not deleted. Without the flag the build leaves the folder alone.
...
.../mods/v143: replaced by The Second Quest 1.4.3/romfs and its manifest.tsv (--install-mod-romfs); what it held before is kept in .../mods/v143.backup-20261021-213000
4/4 app: .../mods/v143 holds 5250 files from The Second Quest 1.4.3/romfs now (what it held before: .../mods/v143.backup-20261021-213000; delete that folder once you no longer need it)
left out (the app replaces it, and the 2K overlay already carries these heap sizes): System/HeapSize/Product.Nin_NX_NVN.HeapDef.byml.zs
.../mods/v143/manifest.tsv: 5229 files (4200 replaced, 1029 added)
不带这个参数时,构建完全不碰这个目录,只打印手动执行的两条命令。
运行时没有任何变化,游戏仍然在启动时加载这个目录和清单;构建只负责复制和写清单。iPhone / iPad 构建
目前没有玩家 mod 目录,所以那里 --mod 只合并代码补丁(--install-mod-romfs 会被直接拒绝:没有可填的目录)。
构建做的事,按顺序:
-
照常解出并核对原版 ExeFS。补丁只打在当前版本、核对过的原版模块上,绝不会打在已经改写过的模块上。
-
打补丁。偏移量都是主地址(游戏代码所在的地址空间,和 App 自己补丁表用的数字一致):
.pchtxt:社区文本格式,读取规则和运行时一致。第一行必须是@nsobid-<build id>:改写器表里用的 16 字节(32 位十六进制)或运行时比较的 20 字节(40 位十六进制;运行时自己的TOTK_PCHTXT实验只认长 的这种)。后面是<十六进制主地址> <十六进制字节>行,只有@enabled之后的行生效:@disabled把后面的 段落重新关掉(作者留着但不启用某段改动的写法),@enabled再打开,@stop结束整个文件。第一条补丁行之前 必须有@flag offset_shift 0x100(说明这些地址不含 IPS 算法里的 0x100 字节 NSO 头,构建正是这样打的); 没有这一行、或者是别的位移值,都按文件和行号拒绝,而不是打偏 0x100 字节。@flag print_values(补丁工具的 显示选项,我们见过的社区 pchtxt 都带)可以出现;其它 flag 会拒绝。@nsobid-那一行决定目标 build,所以文件名任意。.ips/.ips32:按模拟器的用法应用,其偏移量包含 0x100 字节的 NSO 头,构建时会减掉 0x100。 偏移小于 0x100、文件截断、缺少EOF都算错误。这种文件本身不写模块名和 build id,所以只有名字是main,或者是 main 的 build id(exefs/<build id>.ips,Atmosphere 和模组管理器的约定)时才会 当作 main 补丁读入;其余情况(给sdk、subsdk9的补丁,或者名字里是另一个 build id 的补丁) 会留出清单并提示。名为main的.ips没有 id 可核对;按 build id 命名,或改用.pchtxt,才会有这项检查。
-
打完后先检查再往下走。以下情况会被拒绝,并指出地址和原因:补丁落在 main 的 text、rodata、data 之外(text 之后的填充区是保留的);两个补丁文件改同一批字节;补丁什么都没改;补丁改到了 App 自己 打补丁的位置——60 帧与实时单帧步进的地址、渲染/输出分辨率、超宽屏、布料,以及改写器登记的 cut。 这些功能由 App 设置(
TOTK_FPS60、TOTK_REALTIME、TOTK_RENDER_RES、TOTK_OUTPUT_RES、TOTK_ASPECT):运行时会逐个核对那里原来的指令,被改了就直接停止游戏。 -
把打过补丁的模块改写为 Apple 芯片版本,App 按它的 SHA-256 绑定。
--work里的报告(1.0.0 是analysis/phase12-validation.json,其他版本是analysis/<version>-port/phase12-validation.json, 字段mod_exefs)记录 mod 目录、每个补丁文件的 SHA-256、改动的地址和合并后模块的哈希。
iPhone / iPad 构建同样处理:--mod 加 --platform ios。
mod 的 exefs/ 里可能还有这些文件,构建这样处理:
mod 的 exefs/ 里 |
结果 |
|---|---|
给 main 的 *.pchtxt、*.ips、*.ips32 |
合并进构建;.ips 必须叫 main 或按 main 的 build id 命名,.pchtxt 由 @nsobid- 指定版本、文件名任意 |
main.npdm |
忽略并提示:原生加载器不读模块元数据 |
subsdk9 等额外代码模块 |
不加载:构建输出和报告里都会注明;App 只加载构建时的三个模块(main、sdk、subsdk0),模块自己的代码不会运行 |
整个替换的 main |
拒绝:只能用补丁,构建才能按版本核对 |
没有可合并进 main 的东西(只有 subsdk9、只有 main.npdm,甚至空的 exefs/) |
只提示、不拒绝:main 不做任何合并,构建继续;这个 mod 的代码不进 App,数据部分要装进版本目录才生效 |
用 exlaunch 这类 hook 框架做的 mod,运行时改代码的部分就在这种额外模块里:它的 trampoline 在本 App 里不会安装。像 The Second Quest 这样的 mod,主模块补丁和整个 RomFS 都会生效,但依赖那个模块的那部分 代码改动不会。要支持它就得让 App 具备模块加载能力(把模块也改写为 Apple 芯片版本,并实现它用到的 服务),本版本没有做。
构建之后再改 mod 的代码就要重新构建(mod 的字节已经是 App 的一部分),而带 --mod --install-mod-romfs 的
构建也会顺带替换它的数据目录。只改 RomFS 文件不需要构建:把文件放进版本目录、重新生成清单即可(上面的第 2、3
步)。已经合并过的结果会复用:记录的哈希一致时跳过改写;记录里也写了改写器自己的 SHA-256,所以 patch_nso.py
一改就会重新改写,而不是复用旧镜像。2K 输出覆盖文件会记下它是在哪份堆表上生成的:先带 --mod 构建、之后不带
--mod 再构建时,会按原版堆表重新生成,而不是继续沿用 mod 的堆大小。
需要手动启用独立材质层时,先把材质包安装到源码目录外的文件夹:
python3.14 games/totk/scripts/install_texture_pack.py "/材质包路径/RomFS" \
--app "/游戏路径/Tears of the Kingdom.app" --version v143 --output "/外置盘/已安装材质"
printf '%s\n' '/外置盘/已安装材质' > "$HOME/Library/Application Support/MacNativeGames/TOTK/texture-pack-path.txt"材质包默认关闭,设置中没有入口,旧的 texture-pack.txt 开启记录不再生效。
仅在需要时显式启用一次:
open --env TOTK_TEXTURE_PACK=1 "/游戏路径/Tears of the Kingdom.app"启用时一起加载经过校验的材质、容量表和 8 GB 内存布局;普通启动保留原版资源与内存布局。
安装工具按 App 的实际游戏版本生成容量表,并保留各档分辨率的堆增量。更新材质包、游戏版本或画布档位后,
安装到新目录并修改路径文件。TOTK_TEXTURE_PACK_DIR 可覆盖路径;显式关闭 8 GB 布局、文件缺失或其他模组
替换同一容量表时会停止启动并记录原因。此功能只用于 Mac 的王国之泪。
下面是把材质与其他模组合并的旧用法:
有些材质包是给模拟器的 8 GB DRAM 模式做的,装不进真机给游戏的 3.2 GiB。材质包属于各自作者,不包含在本仓库中。 在 Mac 上手动配合 1.4.3 使用:
-
把材质包的
romfs文件(例如4kTextures/RomFS)和你用的其他 mod 一起放进该版本的 mod 文件夹(mods/v143)。 -
材质包自带的堆表和资源尺寸表是按它对应的版本做的,先改成 App 的版本:
python3.14 games/totk/scripts/texture_pack_tables.py ~/Library/Application\ Support/MacNativeGames/TOTK/mods/v143 \ --app "Tears of the Kingdom.app"
它写出 1.4.3 自己的
HeapDef,只把材质包加大的堆调大(例如TextureHeap、ゲームグラフィックス、草), 并写出 1.4.3 的ResourceSizeTable.Product.143,每个被替换贴图的条目按文件变大的量加大。然后照常用make_mod_manifest.py生成清单。文件夹有变化时两步都要重跑。 -
用 8 GB 模式启动:
open --env TOTK_DRAM_8GB=1 "Tears of the Kingdom.app"TOTK_DRAM_8GB向游戏报告 6.8 GiB 的应用内存池(和模拟器的 8 GB 模式一样);材质包约 3.8 GiB 的TextureHeap池做成一个零拷贝 GPU 缓冲。
在 24 GB 的 Apple 芯片 Mac 上验证:游玩时常驻内存约 8.7 GB,GPU 接近满载(瓶颈在 GPU)。内存更小的 Mac 预计跑不动。
旷野之息 App 按版本从对应目录读取 mod,1.6.0 是 botw160,1.9.0 是 botw190:
~/Library/Application Support/MacNativeGames/BotW/mods/botw160
~/Library/Application Support/MacNativeGames/BotW/mods/botw190
上面的 RomFS 部分都适用:把 mod 的 RomFS 内容复制进这个目录,再用 App 生成清单(目录名为 botw160 或 botw190,或加 --version botw160 或 --version botw190;下面以 1.6.0 为例):
MODDIR="$HOME/Library/Application Support/MacNativeGames/BotW/mods/botw160"
python3 games/totk/scripts/make_mod_manifest.py "$MODDIR" --app "/path/to/Breath of the Wild.app"启动后用 grep "mods/botw160 checked" ~/Library/Logs/MacNativeGames/botw.log | tail -1 检查(1.9.0 是 mods/botw190 checked)。
- 如果 mod 让某个资源比原版大,还必须带上为同一版本生成的资源大小表
System/Resource/ResourceSizeTable.product.srsizetable。没有它游戏会按原版大小分配,启动时就会停止(例如Pack/Bootup_<语言>.pack变大的翻译 mod)。 - 游戏语言跟随 App 的首选语言,也由它决定 mod 要放在哪个语言目录(
en-US对应USen)。只给这个游戏换语言:defaults write org.macnativegames.botw AppleLanguages -array en-US。
跟随你的按键设置的按钮图标(1.9.0 和 1.6.0,Xbox 或 PlayStation 手柄):在 builder 的 Controls 页点“Update the game's button
icons”(仅 1.9.0),或者改完布局后手动运行,生成一个 mod,让每个提示显示实际执行该输入的按钮(读取 controls.txt;右侧面键执行 A
时,A 的提示显示 B):
python3 games/totk/scripts/make_botw_button_icons.py "$HOME/Library/Application Support/MacNativeGames/BotW/mods/botw190" \
--app "/path/to/Breath of the Wild.app"1.6.0 请给它自己的 mod 目录(BotW/mods/botw160);版本从 app 读取(app 同时含两个版本时用 --version 指定)。1.6.0 的字体
对摇杆按下和十字键的编号不同(与王国之泪相同),脚本使用各版本自己的码位。
Xbox 手柄时它不画任何东西:图标字体里已经有每个按钮,所以只是把每个输入的码位指向对应按钮的图标(LB RB LT RT 显示为 L R ZL ZR,Menu
和 View 显示为 + 和 -)。物体旁的操作提示(“A 打开”)变成 Xbox 的菱形:A 在下、B 在右、X 在左、Y 在上,执行该操作的按钮在
它的位置上高亮(A、B、X、Y 的操作若移到菱形之外的按钮,例如 LB,那里保留 Switch 的菱形;文字里的提示仍显示 LB)。controller-type.txt 为 playstation(按键 6)时得到 PlayStation 图标:在字体自己的按钮字形格子里画上叉、圆、方、三角,L1 R1 L2 R2,Options 和 Create,操作提示的按键贴图也一样(浅色字母留空)(--style playstation,games/totk/scripts/botw_playstation_icons.py;--style xbox 保留字母);任天堂手柄(controller-type.txt 为 switch)保留游戏自己的图标,它们本来
就对应手柄上的按钮。mod 替换七个(1.6.0 为六个)Font/Font_*.sbfarc 和 Pack/Bootup.pack(其中的 Layout/Common.sblarc 存放操作提示);
布局大小不变,所以不需要资源大小表,但不能和另一个替换 Pack/Bootup.pack 的 mod 一起使用。
奥德赛 App 按构建它所用的更新从对应目录读取 mod,1.3.0 是 v130,1.4.1 是 v141:
~/Library/Application Support/MacNativeGames/Odyssey/mods/v130
~/Library/Application Support/MacNativeGames/Odyssey/mods/v141
上面的 RomFS 部分都适用:把 mod 的 RomFS 内容复制进这个目录,再用奥德赛自己的脚本和 App 生成清单(下面以 1.4.1 为例):
MODDIR="$HOME/Library/Application Support/MacNativeGames/Odyssey/mods/v141"
python3 games/odyssey/scripts/make_mod_manifest.py "$MODDIR" --app "/path/to/Odyssey.app"启动后用 grep "mods/v141 checked" "$HOME/Library/Application Support/MacNativeGames/Odyssey/last-run.log" 检查(1.3.0 是 mods/v130 checked)。没有清单时,日志写 RomFS overlay: none,并给出它查找的目录。
- 1.3.0 和 1.4.1 合并后的游戏数据完全相同,所以为其中一个生成的清单也适用于另一个。用另一个更新重新构建 App 时,把目录改名即可。
- 按更大渲染尺寸构建的 App(默认如此,供按键 3 使用)自己会替换
SystemData/ProjectGraphicsQuality.szs。脚本会把这个文件从 mod 的清单里去掉:两个覆盖层替换同一个文件时,启动会停止。 - 游戏语言跟随 Mac 的首选语言。翻译 mod 替换某一种语言的文件(英语是
LocalizedData/USen/...和LocalizedData/EUen/...),游戏以该语言运行时显示。
游戏的界面用小贴图(48x48 和 72x72 的按键、图标遮罩,以及彩色图标),3456x1944 的画面把它们放大约 2 倍,边缘因此发虚。
Switch 1 游戏的 Mac App 可以改用更大的副本:贴图上传时,它在贴图包文件夹里找 <key>.png,图片尺寸是贴图的整数倍
(最多 8 倍,两个方向相同)时就使用它。没有图片的贴图仍用游戏自己的贴图。界面着色器使用归一化坐标,所以更大的图片
画在同一位置、同一大小。清单已有旷野之息(1.9.0 和 1.6.0 的 key 相同,一个贴图包两个版本都能用)和王国之泪 1.4.3。
项目里不含任何游戏内容:图片来自你自己的游戏。
| 环境变量 | 含义 |
|---|---|
MNG_UI_PACK_DIR |
贴图包文件夹。默认 ~/Library/Application Support/MacNativeGames/<游戏>/ui-pack,<游戏> 为 BotW 或 TOTK。 |
MNG_UI_PACK=0 |
关闭贴图包。 |
MNG_UI_PACK_HARVEST=<dir> |
采集模式:把游戏绘制的每张界面贴图以 <key>.png 写入 <dir>,并在 harvest.tsv 里记一行。已在文件夹里的贴图不会重写,所以文件夹会随多次运行增长。 |
MNG_UI_PACK_HARVEST_FS |
要采集的片段着色器,写 key 前缀,用逗号分隔,或写 * 表示所有片段着色器。旷野之息默认 87d90016,e6a88e12,e1f8208d(图片着色器和温度计),其他游戏默认 *。 |
key 为 <哈希>-<宽>x<高>-<NVN 格式>,哈希覆盖游戏存放的贴图字节。图片保存的是存储的通道值:单通道遮罩为 8 位灰度,
双通道遮罩为蓝色为 0 的 RGB,彩色图为 RGBA(不预乘,sRGB 颜色保持编码值)。
流程
-
采集。带着变量启动游戏,走一遍菜单、HUD 和地图:
open --env MNG_UI_PACK_HARVEST="$HOME/Library/Application Support/MacNativeGames/BotW/ui-harvest" "/path/to/Breath of the Wild.app"
-
在仓库文件夹里用 Python 3.14 制作贴图包。
--screen-height设为游戏画面的高度(3456x1944 为 1944,1920x1080 为 1080):python3.14 -m tools.ui_pack build --game botw \ --harvest "$HOME/Library/Application Support/MacNativeGames/BotW/ui-harvest" \ --out "$HOME/Library/Application Support/MacNativeGames/BotW/ui-pack" \ --screen-height 1944
王国之泪 1.4.3 用
--game totk-1.4.3和TOTK文件夹。 -
照常启动游戏。日志(
~/Library/Logs/MacNativeGames/botw.log或totk.log)里的[ui-pack]行会显示在用的图片数量。
图片怎么做。 工具只制作该游戏清单(games/botw/assets/ui_pack_keys.tsv、games/totk/assets/ui_pack_keys_v143.tsv)里的贴图,
按其中给定的绘制倍数和选项。它把每个遮罩描成精确的形状,再以贴图的 8 倍重画(最长边超过 128 像素时 4 倍,超过 256 时 2 倍),
保留贴图自己的平台灰度,所以圆的仍是圆的,直的仍是直的。图片按它在屏幕上绘制的大小预先滤波:清单记着在游戏截图里测出的
绘制倍数,--screen-height 把它换算到你的画面。请按你的画面高度制作。不确定时取较小的高度:按比实际游玩更大的高度做的贴图包,
可能比游戏自己的贴图更难看。
质量检查。 每张图片写出前都要检查:在屏幕上,平均墨量和平台灰度与贴图一致;形状按贴图尺寸画回后与贴图一致;与理想形状的
差距不超过游戏贴图本身。没通过的贴图不写出,游戏画它自己的贴图;制作时把它和测量值记在 manifest.tsv 和总结里,退出码仍为 0。
工具跳过彩色图、平坦贴图、纯渐变,以及清单里写了 skip(附原因)的贴图。制作时会列出采集里还没有的清单贴图;开着采集
在游戏里让它们显示出来,再制作一次。
--dry-run 只显示计划,--only <key,...> 限定 key,--force 重做已是最新的图片,--all 连清单里没有的采集贴图也按默认选项制作,
--jobs N 设定并行数。再次制作时只重做贴图、选项、绘制倍数或画面高度变了的图片。工具把写出的图片记在贴图包文件夹的
manifest.tsv 里,只重写或删除其中列出的图片,所以其他工具做的或手工放入的图片会保留。之前 AI 工具留下的
ai-manifest.tsv 会被接管:其中的图片重新制作或删除,然后删掉这个文件。删除某张图片,该 key 就回到游戏自己的贴图。
可复现的构建。 tools/deps/pins.py 固定 NumPy、SciPy、ContourPy、Pillow 的轮子和 SHA-256,命令自动安装到独立缓存。
ContourPy(BSD-3-Clause)追踪拟合场的轮廓,像素边界由本项目自己的 MIT 实现处理。方法版本改为 v3.2,旧包会重做一次。
合成形状回归通过;原轮廓工具的逐项参数仍需用玩家自己的采集画面核对。
仓库里没有任何从游戏生成的文件。采集文件夹和贴图包由你的游戏数据生成,只保留在你的 Mac 上,不放进仓库或拉取请求。
- 不要手改
manifest.tsv,每次重新生成。 - 游戏运行中不要改 mod 文件;加载器会在启动时记录每个文件的身份,运行中变化会停止游戏。
- 玩家 mod 只有一个覆盖目录:多个 mod 就合并到同一个版本目录,最后生成一份清单;不要把 mod 文件夹嵌套进去。两个 mod 改同一个路径时,只能选一个文件。
- 构建本身也会替换几个 RomFS 文件:
UI/LayoutArchive/Common.Product.<n>.Nin_NX_NVN.blarc.zs(快捷菜单时机,<n>按版本是 100、110 或 140)、Event/EventFlow/DmF_SY_GameOver.bfevfl.zs,开 2K 输出时还有System/HeapSize/Product.Nin_NX_NVN.HeapDef.byml.zs。两份覆盖无法替换同一个路径(启动会报“two overlays replace the same file”),所以:- UI 归档是合并的:翻译模组的归档保留自己的贴图,同时接受构建对快捷菜单的改动——工具把合并后的归档写进模组
目录,模组原文件保留为旁边的
<name>.mod-original,合并后的文件取代构建的覆盖层(#73)。如果模组改动了构建也会 修改的成员(那些 capture 动画),工具会拒绝,而不是悄悄丢掉一侧; - 堆表由构建叠加:带
--mod时 2K 覆盖文件是在模组那份堆表之上生成的; - 其余路径(比如 game-over 流程)留给 App,并打印说明排除了哪个文件。
- UI 归档是合并的:翻译模组的归档保留自己的贴图,同时接受构建对快捷菜单的改动——工具把合并后的归档写进模组
目录,模组原文件保留为旁边的
- 这些文件由
make_mod_manifest.py自己处理:UI 归档按上面的方式合并,其它与 App 自身替换项相同的模组文件不会写进 清单(并打印一行说明),因为两份覆盖无法同时加载。堆表那一行说明 App 是否已经带着这些堆大小, 否则提示用--mod重新构建。 - 模组管理器(TKMM,或 Ryujinx 的
mods/contents/<title id>/<name>)给出的是同一个文件夹里的exefs/和romfs/: 把这个文件夹交给--mod(里面的exefs补丁会合并,管理器合并出来的.ips可能一个文件里装着好几个模组的记录), 再加上--install-mod-romfs让构建把对应版本的 mods 目录整个换成它的romfs/并生成清单(不需要再手动--exclude:管理器的堆表和 App 的 2K 覆盖文件会自动协调)。每次在管理器里重新合并后都要重新构建,因为游戏启动时会逐个校验文件哈希。多个带代码 补丁的 mod 也是这样合的:先在管理器里合并,再用--mod <管理器的输出文件夹> --install-mod-romfs构建;两个补丁文件改到同一批字节 时构建会拒绝,并同时报出这两个文件。 - Graft(nickpetrovic 做的社区模组管理器,MIT,要从源码编译)是给这些 Mac App 用的:用 TkSharp(TKMM 用的库)合并王国之泪的模组,检查它们的代码补丁,再装进上面的版本目录。它是独立项目,本仓库 没有测试过;需要一份 MacNativeGames 源码和 .NET 10 SDK。
- 带代码补丁的 mod,其
exefs/补丁也要和构建所用的游戏版本一致。构建按文件自己写的东西核对:.pchtxt的@nsobid-不是这个 main 就拒绝;按 build id 命名的.ips/.ips32,id 不是这个 main 就留出并提示。 - 本文面向 Mac App;iPhone/iPad 的 App 容器内安装未在此说明。
游戏会关掉窗口,并在 ~/Library/Logs/MacNativeGames/totk.log 写下最后一行原因,它上面一行就是出问题的文件。日志默认关闭:先用 defaults write org.macnativegames.totk TOTK_DEBUG_LOG -bool YES(旷野之息是 org.macnativegames.botw)打开,再启动一次。本页的 grep 检查也需要先打开日志。
two overlays replace the same file:清单里列了 App 自己也会替换的路径——通常是手工写的清单或别的工具写的清单(UI 归档 的情况会改成合并而不是排除), 因为make_mod_manifest.py自己就会把这类路径排除。用那个脚本重新生成即可。two overlays add the same file:两个覆盖(App 的或两个模组目录)新增了同一个 RomFS 里没有的路径。RomFS overlay integrity mismatch:模组目录里的文件和清单里的 SHA-256 不一致,也就是生成清单之后又拷了文件进去。 重新生成清单即可(make_mod_manifest.py遇到对不上的文件不会写清单)。RomFS overlay names a file the RomFS lacks/adds a file the RomFS already has:替换项的“原件”对不上(文件是从 别的游戏版本拷来的);按对应版本重新生成清单并重新构建 App。RomFS overlay file changed while the game ran:游戏运行中改了文件夹;重启游戏并重新生成清单。
窗口也可能直接消失、日志里没有上面这些行:某个模组的数据能让 Metal 直接终止进程(此时日志里有宿主调用栈,例如
-[MTLTextureDescriptorInternal validateWithDevice:] 报 “requests 9 mipmap levels, but the dimensions (1, 1, 1) can only
support 1”)。mip 级数超过尺寸允许的贴图在 Switch 上没人检查,Metal 却拒绝创建;App 会把级数裁到尺寸允许的数量并记一行
[tex] <w>x<h>x<d> ... 声明 N 级 mip ...,画面不对时应检查该模组的贴图。
这三处出在包的打包方式上,而不是包的内容;它们都不会打印上面那些行。
.pchtxt缺@flag offset_shift 0x100。 文件里的地址是main地址,而 IPS 的偏移把 0x100 字节的 NSO 头也算了进去。 补丁行出现在这个 flag 之前、或写的不是 0x100,TOTK_PCHTXT和--mod都会直接停止启动——否则每个字节都会静默地 偏 0x100 落错位置。手工把 IPS 转成 pchtxt:main 地址 = IPS32 偏移 - 0x100。.zs的 zstd 帧没有声明内容大小。 游戏的解压器无从得知解压后多大,会解到空指针上:窗口在ENTER nnMain之后 立刻消失,日志里没有我们这边的任何一行。zstd从管道压缩(zstd -c)时会写出这种帧;帧头描述符字节(raw[4]) 的 bit7-6 必须非 0。改为对字节数组调用库压缩,断言(raw[4] >> 6) & 3,窗口大小、校验和、字典都与被替换的原文件 保持一致(zstd -l -v可看)。- 合并后的
ResourceSizeTable留下了记录、丢了槽。 只合并.rsizetable记录数组的管理器,会让槽位消失的那批 actor 按 0 大小加载。槽名是逻辑资源路径(Actor/...),不是 RomFS 路径,在索引里查不到属正常。按参与合并的各张表求并集 重建——值逐字节照抄,记录数组保持按 key 升序(游戏按 key 二分查找)——装进去之前再核对压缩结果的帧头。games/totk/scripts/make_button_icons.py里的grow_restbl就是这种格式的一个写入示例。