Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
host/mods: load emulator mod folders: RomFS, cheats, exefs patches
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 #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
  • Loading branch information
roandegraaf committed Nov 12, 2026
commit 83bc59c846dd48c4fd856ac44ccc523e4271a776
1 change: 1 addition & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25
- [The blend helper's output reference on iOS](../../../docs/reference/shaders.md#the-blend-helpers-output-reference-on-ios): resolved, 22,296 of 42,848 Mac shaders failed to compile on macOS 26 ([GitHub issue #2272](https://github.com/seedds/nxnative/issues/2272)); the Mac compile now names the host's minimum macOS.
- [A NaN colour under a zero blend weight](../../../docs/reference/shaders.md#a-nan-colour-under-a-zero-blend-weight): resolved, white clouds over the ground mist between Kokiri Forest and Hyrule Field and over the ferns at the camera in Kokiri Forest ([issue #1839](https://github.com/seedds/nxnative/issues/1839)). The mist shader `5ad65c0eefd09c7f` writes NaN at alpha 0 where its layer has density 0; NVIDIA's blender, with the option NVN's driver sets, adds nothing there, Apple's stored the NaN.
- [A first start builds every base of the prewarm list before the first frame](../../../docs/reference/rendering.md#a-first-start-builds-every-base-of-the-prewarm-list-before-the-first-frame): the 450-475 s first-start prepare on an M5 Max; the Mac app now bundles the list's pipelines (`--prebake`, on by default) and it took 4.3 s.
- [Mods made for emulators do nothing, or only half of them does](../../../docs/reference/services.md#mods-made-for-emulators-do-nothing-or-only-half-of-them-does): current. The mods folder was brought up here, on the Mac, with a controller UI mod and a pack of tunic recolours switched from the Mods menu while playing.
- [The 60 Hz link at 40 fps in fullscreen on a ProMotion screen](../../../docs/reference/frame-rate.md#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen): 40 fps in fullscreen on an M5 Pro MacBook Pro with the GPU at 10 ms of the 16.7, every present one 120 Hz refresh late and every other display-link tick skipped; the screen's fixed 60 Hz mode held 60.0 fps there and fullscreen now switches to it, with the 120 Hz link (59 fps) for screens with no such mode.
- [The shader package and the shader map come from different splits](../../../docs/reference/packing.md#the-shader-package-and-the-shader-map-come-from-different-splits): resolved, a black screen with sound in a build through NX2Apple ([issue #1841](https://github.com/seedds/nxnative/issues/1841)); the present pass was translated from a terrain shader's record. Records now carry their keys, and the shader build finds them by key.
- [Native mesh pipelines compiled at their first draw](../../../docs/reference/shaders.md#native-mesh-pipelines-compiled-at-their-first-draw): resolved. The foliage, shadows and enemies drawn with task and mesh shaders stalled at their first draw on a cold Metal cache (59.5 s of builds at the Kokiri Forest entry on an M5 Max, one frame of 42.9 s), as nothing recorded or kept their pipelines; `pso_manifest.tsv` now carries 164 `M` rows (Kokiri Forest, Hyrule Field, Castle Town, Hyrule Castle, and 41 from later play, Death Mountain Trail among it), and with the prepare step they are built before the first frame. Pipelines outside the list still stall once, then go into `pso_user.tsv`. With the first 123 alone, a cold first start (empty Metal cache and pipeline archive, M4 Pro) on a Death Mountain Trail save built 9 and 10 at their first draw in two runs, 2.7 and 4.2 s, frames of 1,775 and 1,657 ms; with all 164, none, worst frame 25.6 and 18.5 ms, the prepare step 29.6 and 29.3 s → 32.1 and 31.0 s.
Expand Down
10 changes: 10 additions & 0 deletions dm/host/dm.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ void dm_guest_heap_range(uint64_t *base, size_t *open_len); // hle_svc.c: the
int dm_guest_heap_read(uint64_t addr, void *out, size_t len); // hle_svc.c: hole-free guest heap read for the cheat VM (under the memory lock); 0 = ok, 1 = a byte outside the opened span
int dm_guest_heap_write(uint64_t addr, const void *src, size_t len); // hle_svc.c: hole-free guest heap write (the dirty tracking sees it first)
// Cheats (hle_cheats.c): Atmosphère-format cheat code files applied to the running game (docs/development.md "Cheats")
void dm_mods_init(void); // Before load_modules (main.c): finds the mods folder's mods, in order, and puts their romfs folders into DM_ROMFS_OVERLAY (hle_mods.c)
void dm_mods_patch_module(module_t *m, const char *dir); // A mapped, still writable module: the mods' .pchtxt / .ips patches for its build (loader.c map_image)
void dm_mods_report_unmatched(void); // After load_modules: the patch files no loaded module's build matched
const char *dm_mods_dir_path(void); // The mods folder ("" when neither DM_MODS nor DM_ROOT is set); it need not exist
int dm_mods_count(void); const char *dm_mods_name(int i); int dm_mods_on(int i); // Every mod folder found at the start, in priority order, on or off (the Mac window's Mods menu)
void dm_mods_set(int i, int on); // Turn a mod on or off: its romfs folder at once, and in order.txt; dm_mods_edited() is 1 once a mod with code patches or cheats changed (those wait for the next start)
void dm_fs_overlay_set(const char *list); // Replace the RomFS overlay folders while the game runs (hle_fs.c)
int dm_mods_edited(void);
int dm_mods_exclusive(int i); // 1 for a pack's variant that replaces the same files as another of the pack: turning it on turns that one off
const char *dm_mods_cheat_dir(int i, const char **mod); // The i-th mod cheats folder in priority order and its mod's name, NULL past the last
void dm_cheats_init(void); // Called once in host_preload after loading the modules (main.c): reads DM_CHEATS and friends, loads the build's file
void dm_cheats_present(void); // Per presented frame (hle_nvn.c presents): applies the enabled cheats once
// The Cheats submenu's rows (front_mac.m, Mac window only). Readers of the list of cheats; the front end copies the strings out immediately
Expand Down
35 changes: 35 additions & 0 deletions dm/host/front_mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,37 @@
[g_cheats_panel show];
}
@end
// The Mods menu (hle_mods.c), rebuilt on every open
@interface DmModsMenuDelegate : NSObject <NSMenuDelegate>
@end
@implementation DmModsMenuDelegate
- (void)menuNeedsUpdate:(NSMenu *)menu {
[menu removeAllItems];
int n = dm_mods_count();
NSString *pack = nil;
for (int i = 0; i < n; i++) {
NSArray<NSString *> *parts = [@(dm_mods_name(i)) componentsSeparatedByString:@"/"];
if (parts.count > 1 && ![parts[0] isEqualToString:pack]) [menu addItemWithTitle:parts[0] action:nil keyEquivalent:@""].enabled = NO;

Check failure on line 888 in dm/host/front_mac.m

View workflow job for this annotation

GitHub Actions / clang-tidy (ratchet)

nil passed to a callee that requires a non-null 1st parameter [clang-analyzer-nullability.NullPassedToNonnull] (1 in this file, the baseline has 0)
pack = parts.count > 1 ? parts[0] : nil;
NSMenuItem *it = [menu addItemWithTitle:parts.lastObject action:@selector(toggleMod:) keyEquivalent:@""];
if (dm_mods_exclusive(i)) it.toolTip = @"Replaces the same files as another mod of this pack: turning it on turns that one off";
it.target = self; it.tag = i; it.state = dm_mods_on(i) ? NSControlStateValueOn : NSControlStateValueOff; it.indentationLevel = pack ? 1 : 0;
}
if (!n) [menu addItemWithTitle:@"No mods in the mods folder" action:nil keyEquivalent:@""].enabled = NO;
if (dm_mods_edited()) [menu addItemWithTitle:@"Code patches and cheats change at the next start" action:nil keyEquivalent:@""].enabled = NO;
[menu addItem:[NSMenuItem separatorItem]];
const char *dir = dm_mods_dir_path();
NSMenuItem *op = [menu addItemWithTitle:@"Open Mods Folder" action:*dir ? @selector(openModsFolder:) : nil keyEquivalent:@""];
op.target = self; op.enabled = *dir != 0;
}
- (void)toggleMod:(NSMenuItem *)it { dm_mods_set((int)it.tag, !dm_mods_on((int)it.tag)); }
- (void)openModsFolder:(NSMenuItem *)it {
(void)it; NSString *dir = @(dm_mods_dir_path());
[[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:dir isDirectory:YES]];
}
@end
static DmModsMenuDelegate *g_mods_menu;
static DmCheatsMenuDelegate *g_cheats_menu; // NSMenu keeps its delegate unretained

@implementation DmCheatsPanel {
Expand Down Expand Up @@ -1559,6 +1590,10 @@
// Cheats menu has been opened once. Every open rebuilds them through the delegate as before
[g_cheats_menu menuNeedsUpdate:cm];
[[bar addItemWithTitle:@"Cheats" action:nil keyEquivalent:@""] setSubmenu:cm];
g_mods_menu = [DmModsMenuDelegate new];
NSMenu *mm = [[NSMenu alloc] initWithTitle:@"Mods"];
mm.delegate = g_mods_menu; mm.autoenablesItems = NO;
[[bar addItemWithTitle:@"Mods" action:nil keyEquivalent:@""] setSubmenu:mm];
if (getenv("DM_CHEATS_WINDOW") && atoi(getenv("DM_CHEATS_WINDOW"))) // the Cheats panel open from the start (beside the game, not key)
dispatch_async(dispatch_get_main_queue(), ^{ [g_cheats_menu showPanel:nil]; });
[[bar addItemWithTitle:@"Window" action:nil keyEquivalent:@""] setSubmenu:wm];
Expand Down
Loading
Loading