Skip to content

host/mods: load emulator mod folders (1/2): RomFS, cheats, exefs patches - #2149

Closed
roandegraaf wants to merge 1 commit into
seedds:mainfrom
roandegraaf:mods-loader
Closed

roandegraaf wants to merge 1 commit into
seedds:mainfrom
roandegraaf:mods-loader

Conversation

@roandegraaf

@roandegraaf roandegraaf commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Rebased on main at 034e91a (2026-11-12). Only the game note's "Found on this game" list conflicted. One addition from main: its rewriter now also rounds odd-sized sub / add sp, #imm frames (c081686), so the host also refuses a patch that writes sub / add sp, sp, #imm by an amount that is not a multiple of 16 (five new t_mods cases).

Part of a set of three. This one stands alone on main. #2150 is stacked on it (merge this first). #2151 is independent of both, but touches neighbouring lines in dm.h, front_mac.m, hle_hid.c, t_hid.c and the docs, so whichever lands second needs a small rebase, which I will do.

Overlaps #883, which also adds a dm/host/hle_mods.c and RomFS mods through the overlay, but builds mods into the app at pack time (build_ipa_from_nsp.py --mods) and runs code patches through patch_nso.py then. This PR reads a mods folder at run time, switches RomFS mods while the game runs, merges cheat files, and applies code patches as a module loads (#2150 rewrites the rest at launch). #2305 adds a LayeredFS romfs/ folder and game updates, with launcher buttons; #519 writes a profile's own <module>.runtime.tsv at load time, not mod files. The maintainer may want one mods design; I can fold the pack-time path of #883 in or rebase onto it.

What and why

A mod folder as Ryujinx, the yuzu family or Atmosphère take it had no place to go: only DM_ROMFS_OVERLAY replaced RomFS files, by hand, and one cheat file per build was read.

dm/host/hle_mods.c reads a mods folder (DM_MODS, default <DM_ROOT>/mods), one folder per mod in the layouts mods ship in, ordered and switched by order.txt. A folder of mods is a pack; two of a pack that replace the same RomFS file are alternatives.

  • RomFS. romfs/ folders join the overlay, and the Mac window's Mods menu (or DM_CTL mod-on / mod-off) changes the list while the game runs.
    • <name>.dm-delete hides a game file or directory, and those of the mods after it. This is a new convention of this host: LayeredFS and the emulators have none, so the name is yours to change.
    • A name that differs from the game's only in case is taken, with a warning in the log. Before, such a mod silently did nothing.
  • Cheats. Every cheats/<build ID>.txt of the running build is loaded as one list, the cheats folder's own first, then each mod's by priority.
    • A cheat an earlier file has with the same name and code is left out; the same name with other code is a second entry (Name #2).
    • A mod's cheats outside a section are listed under the mod's name.
    • <build>.enabled and <build>.values stay one file each, in the cheats folder. CHEAT_MAX is 512, for all files together.
  • Code patches. exefs/*.pchtxt and <build ID>.ips are written into the module whose build ID they name while it is still writable (loader.c map_image), a file whole or not at all. A file is refused with a [RED] line when a patch replaces a word the rewriter moved (<name>.changed.tsv) or writes an instruction the rewriter would have had to replace (an svc, a thread or timer system register, an exclusive access, sub sp, sp, xN, sub / add sp, sp, #imm not a multiple of 16, x18). tools/mods: rewrite refused mod code patches at launch (2/2) #2150 takes those.

Not loaded: a mod's code modules (ExLaunch, Skyline). No exefs patch on iOS (signed code).

Reference entry: Mods made for emulators do nothing, or only half of them does. User docs: docs/development.md "Mods".

Checked

  • Tests, on this branch after the rebase (upstream main at 034e91a): the host builds; make -C dm/host/tests GAME=0400486024DEC000 run exits 0 (t_mods ok with the new sp cases, t_cheats 156 / 156, t_fs with the new overlay cases, t_hid); test_docs, test_env_switches, test_lint_python, test_lint_c, test_architecture pass.
  • Games run: 0400486024DEC000 (v131072) on the Mac, with two RomFS mods switched from the Mods menu while playing, and headless to the frame loop with synthetic patch files. Those runs were on an older base (my shader libraries are of chain e82ac5d18f5e), so on this branch the game itself was not run.
  • Not checked: any other game, the packed .app, iOS, a downloaded mod with a code patch. The delete marker and the case fallback are unit-tested only, not exercised in a running game.
  • Devices and OS: Apple M4 Pro, macOS 27.2.
  • scripts/regress.py check --games: not run. Only one game is built on this Mac, and the report wants five; hle_fs.c, hle_cheats.c and loader.c are on every game's path, so a run on your games would be welcome.

Front ends

Front-ends: new: mods are folders in DM_MODS (default <DM_ROOT>/mods), ordered and turned off by order.txt there; the host reads it at the start
Front-ends: interface: every .txt of the running build is loaded, from the cheats folder and each enabled mod's cheats/, as one list; a cheat's section may be a mod's name

Docs

  • The finding is in its game note or its docs/reference/<subsystem>.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • No game files, keys or data extracted from a game in the change or the attachments

Mods made for Switch emulators load from a mods folder: RomFS files switched while the game runs, cheat files of every mod as one list, .pchtxt / .ips patches as a module loads (DM_MODS, the Mac window's Mods menu).

dm/host/hle_mods.c reads DM_MODS (default <DM_ROOT>/mods), one folder per mod in
the layouts mods ship in (romfs/, exefs/, cheats/ directly, or under
atmosphere/contents/<title ID>/), ordered and switched by order.txt. A folder of
mods is a pack; two of a pack that replace the same RomFS file are alternatives.

- romfs/ folders join the RomFS overlay, and the Mods menu (or DM_CTL "mod-on" /
  "mod-off") changes the list while the game runs (dm_fs_overlay_set). A
  <name>.dm-delete marker hides a game file or directory, and those of the mods
  after it. A name that differs from the game's only in case is taken, with a
  warning in the log, where it silently did nothing before.
- Every cheats/<build ID>.txt of the running build is loaded, the cheats
  folder's own first, then each mod's by priority: a cheat an earlier file has
  with the same name and code is left out, the same name with other code is a
  second entry ("Name seedds#2"), a mod's cheats are listed under its name, and
  <build>.enabled / <build>.values stay one file each, in the cheats folder.
  CHEAT_MAX is 512, for all files together.
- exefs/*.pchtxt and <build ID>.ips are written into the module whose build ID
  they name while it is still writable (loader.c map_image), a file whole or
  not at all. A file is refused with a [RED] line when a patch replaces a word
  the rewriter moved (<name>.changed.tsv) or writes an instruction the rewriter
  would have had to replace; applying those before the rewriter runs is the
  next change.

Mac-tested on 0400486024DEC000 only: two RomFS mods from the
menu, synthetic patches and cheat files. Code modules of a mod (ExLaunch,
Skyline) are not loaded, and no exefs patch is applied on iOS.

Rebased on main at 034e91a: only the game note's Found on this game list conflicted (both kept); symptom index regenerated. Main's rewriter now also rounds odd-sized sub/add sp, #imm frames (c081686), so the host refuses a patch that writes sub / add sp, sp, #imm by an amount that is not a multiple of 16 too (t_mods: five new cases). Checked again: host build, make -C dm/host/tests run (t_mods, t_cheats, t_fs, t_hid), test_docs, test_env_switches, test_architecture, lint tests.

Front-ends: new: mods are folders in DM_MODS (default <DM_ROOT>/mods), ordered and turned off by order.txt there; the host reads it at the start
Front-ends: interface: every <build ID>.txt of the running build is loaded, from the cheats folder and each enabled mod's cheats/, as one list; a cheat's section may be a mod's name
@roandegraaf roandegraaf changed the title Mods 1/2: emulator mod folders now load on the Mac — RomFS swaps live from a Mods menu, cheats from every mod, .pchtxt / .ips patches host/mods: load emulator mod folders (1/2): RomFS, cheats, exefs patches Nov 12, 2026
@seedds

seedds commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Thanks @roandegraaf for putting together this mod-folder loader and documenting the emulator folder conventions and safety checks!

Closing this combined PR as superseded by the smaller, actively maintained split PRs #3146 (per-game Mac mods folder and mods.txt), #3153 (add-on content overlays and ARH1 archive patching), and #3158 (ExeFS IPS/IPS32/.pchtxt patches), alongside main's existing DM_ROMFS_OVERLAY and cheat engine. We checked this PR and the split PRs against current main.

Still open: reviewing and landing those focused mod PRs, keeping this PR's rewrite-safety checks and mod layout notes in mind.

@seedds seedds closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400486024DEC000 A game host The Horizon host: SVCs, services, threads, memory (dm/host) mac The Mac front end and app (dm/mac, front_mac.m)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants