Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Two build breakers from PR #31, applied ahead of its rebase (and one sync-patcher alignment)

LNPANDYdec3c3725a9b
diff --git a/dm/host/romfs_arc.c b/dm/host/romfs_arc.c
index a8fe0458..d76681d1 100644
--- a/dm/host/romfs_arc.c
+++ b/dm/host/romfs_arc.c
@@ -56,7 +56,14 @@ static const filerec *find_file(const char *rel) {
}
// Binary search the directory table by path. Returns the record or NULL.
+// A trailing slash names the same directory, as it does for opendir(3) on the plain tree: Bayonetta 3 opens "movie/" at boot,
+// and without this the archive said the movie folder did not exist, so the game never started its opening movie on iOS.
static const dirrec *find_dir(const char *rel) {
+ char trimmed[1024]; size_t n = strlen(rel);
+ if (n && rel[n - 1] == '/' && n < sizeof trimmed) {
+ while (n && rel[n - 1] == '/') n--;
+ memcpy(trimmed, rel, n); trimmed[n] = 0; rel = trimmed;
+ }
uint64_t lo = 0, hi = A.hdr.dir_count;
while (lo < hi) {
uint64_t mid = lo + (hi - lo) / 2;
diff --git a/dm/host/tests/t_romfs_arc.c b/dm/host/tests/t_romfs_arc.c
index 82ac9140..3f675332 100644
--- a/dm/host/tests/t_romfs_arc.c
+++ b/dm/host/tests/t_romfs_arc.c
@@ -44,6 +44,8 @@ int main(int argc, char **argv) {
if (e[i].is_dir) {
CHECK(romfsarc_is_dir(rel), "is_dir '%s'", rel);
CHECK(!romfsarc_stat_file(rel, NULL, NULL, NULL), "dir is not a file: '%s'", rel);
+ char slash[1024]; snprintf(slash, sizeof slash, "%s/", rel); // a trailing slash names the same directory (Bayonetta 3 opens "movie/")
+ CHECK(romfsarc_is_dir(slash) && romfsarc_count(slash) == romfsarc_count(rel), "trailing slash '%s'", slash);
if ((size_t)nd == dcap) { dcap *= 2; dirs = realloc(dirs, dcap * sizeof *dirs); }
dirs[nd++] = strdup(rel);
} else {
diff --git a/dm/ios/Sources/main.m b/dm/ios/Sources/main.m
index 7879a70d..224154fd 100644
--- a/dm/ios/Sources/main.m
+++ b/dm/ios/Sources/main.m
@@ -43,7 +43,7 @@ static NSString *romfs_locate(void) {
NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
// Per-game first: Documents/games/<id>/romfs — what the launcher-style layout produces, and what
// lets a user keep several games' data side by side (or on an external drive).
- NSString *per_game = [game_dir_for(DM_GAME_ID) stringByAppendingPathComponent:@"romfs"];
+ NSString *per_game = [game_dir_for(dm_profile()->id) stringByAppendingPathComponent:@"romfs"];
if ([fm fileExistsAtPath:per_game] && romfs_dir_ok(per_game)) return per_game;
for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]]) {
if (romfs_dir_ok(d)) return d;
@@ -92,7 +92,7 @@ static int boot_env(void) {
// (so two games in one app never share a save folder), else the old Documents/{save,temp}. An
// env file still wins — DM_SAVE/DM_TEMP set there are already in the environment and
// setenv(..., 0) leaves them alone.
- NSString *gdir = game_dir_for(DM_GAME_ID);
+ NSString *gdir = game_dir_for(dm_profile()->id);
// Tie the data folder to where the game files actually came from: if romfs_locate fell back to
// Documents/romfs, the saves must stay beside it (a game folder without romfs is not in use).
BOOL per_game = [romfs hasPrefix:gdir];
diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.py
index dd32bad0..066d09f7 100644
--- a/scripts/sync_upstream.py
+++ b/scripts/sync_upstream.py
@@ -670,8 +670,8 @@ static int g_bc_cpu; // decode BC on the CPU: no GPU support and the profi
done(f'nvn_mtl.m {name}')
return t
-MAIN_M_ROMFS = ('static NSString *romfs_locate(void) {\n NSFileManager *fm = NSFileManager.defaultManager;\n NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];\n for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]])\n if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@DM_GAME_ROMFS_MARKER]]) return d; // only a directory containing the game profile\'s romfs_marker path counts (Mario: System/Resource, the resource size table)\n return nil;\n}\n\n', '// A folder holds this game\'s files if it has a ROMFSARC index or the profile\'s marker path.\n// Shared by romfs_locate and the per-game layout below, so both answer the same question.\nstatic BOOL romfs_dir_ok(NSString *d) {\n NSFileManager *fm = NSFileManager.defaultManager;\n // A ROMFSARC archive: <dir>/romfs.idx next to romfs.NN shards. The host opens it when DM_ROMFS\n // points at the base; the marker check does not apply (there are no directories to walk).\n if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@"romfs.idx"]]) return YES;\n // A plain directory tree: only one containing the game profile\'s romfs_marker path counts\n // (Mario: System/Resource, the resource size table). Runtime profile: the marker is a profile\n // value now; the compiled macro is only what dm_profile() falls back to without DM_PROFILE.\n return [fm fileExistsAtPath:[d stringByAppendingPathComponent:@(dm_profile()->romfs_marker)]];\n}\n\n// Where one game\'s data lives under the per-game layout: Documents/games/<title ID>/, holding\n// romfs/ the archive (romfs.idx + shards) or a plain tree\n// msl/ this game\'s Metal shader libraries (optional; the app\'s own dm/ is used otherwise)\n// save/ temp/ this game\'s saves and scratch space\n// The layout exists so several games can share one installed app and so the game data can sit on\n// an external drive the Files app exposes (a folder copied there keeps this shape).\nstatic NSString *game_dir_for(const char *title_id) {\n NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];\n return [[doc stringByAppendingPathComponent:@"games"] stringByAppendingPathComponent:@(title_id)];\n}\n\nstatic NSString *romfs_locate(void) {\n NSFileManager *fm = NSFileManager.defaultManager;\n NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];\n // Per-game first: Documents/games/<id>/romfs — what the launcher-style layout produces, and what\n // lets a user keep several games\' data side by side (or on an external drive).\n NSString *per_game = [game_dir_for(DM_GAME_ID) stringByAppendingPathComponent:@"romfs"];\n if ([fm fileExistsAtPath:per_game] && romfs_dir_ok(per_game)) return per_game;\n for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]]) {\n if (romfs_dir_ok(d)) return d;\n }\n return nil;\n}\n\n')
-MAIN_M_ENV = (' setenv("DM_ROMFS", romfs.fileSystemRepresentation, 0);\n setenv("DM_SAVE", [doc stringByAppendingPathComponent:@"save"].fileSystemRepresentation, 0);\n setenv("DM_TEMP", [doc stringByAppendingPathComponent:@"temp"].fileSystemRepresentation, 0);\n NSString *dm = [res stringByAppendingPathComponent:@"dm"];\n setenv("DM_NVN_SHMAP", [dm stringByAppendingPathComponent:@"shader_map.tsv"].fileSystemRepresentation, 0);\n setenv("DM_MSL_DIR", [res stringByAppendingPathComponent:@"msl"].fileSystemRepresentation, 0);\n', ' setenv("DM_ROMFS", romfs.fileSystemRepresentation, 0);\n // Saves and scratch space: Documents/games/<id>/{save,temp} when the per-game layout is in use\n // (so two games in one app never share a save folder), else the old Documents/{save,temp}. An\n // env file still wins — DM_SAVE/DM_TEMP set there are already in the environment and\n // setenv(..., 0) leaves them alone.\n NSString *gdir = game_dir_for(DM_GAME_ID);\n // Tie the data folder to where the game files actually came from: if romfs_locate fell back to\n // Documents/romfs, the saves must stay beside it (a game folder without romfs is not in use).\n BOOL per_game = [romfs hasPrefix:gdir];\n NSString *save_dir = per_game ? [gdir stringByAppendingPathComponent:@"save"] : [doc stringByAppendingPathComponent:@"save"];\n NSString *temp_dir = per_game ? [gdir stringByAppendingPathComponent:@"temp"] : [doc stringByAppendingPathComponent:@"temp"];\n for (NSString *d in @[save_dir, temp_dir]) [fm createDirectoryAtPath:d withIntermediateDirectories:YES attributes:nil error:nil];\n setenv("DM_SAVE", save_dir.fileSystemRepresentation, 0);\n setenv("DM_TEMP", temp_dir.fileSystemRepresentation, 0);\n if (per_game) fprintf(stderr, "boot: per-game data folder %s\\n", gdir.fileSystemRepresentation);\n NSString *dm = [res stringByAppendingPathComponent:@"dm"];\n setenv("DM_NVN_SHMAP", [dm stringByAppendingPathComponent:@"shader_map.tsv"].fileSystemRepresentation, 0);\n // Shader libraries: a game\'s own <gdir>/msl first (a per-game layout may carry its own), else\n // the app\'s shared <App>/msl.\n NSString *per_game_msl = [gdir stringByAppendingPathComponent:@"msl"];\n NSString *msl = (per_game && [fm fileExistsAtPath:per_game_msl]) ? per_game_msl : [res stringByAppendingPathComponent:@"msl"];\n setenv("DM_MSL_DIR", msl.fileSystemRepresentation, 0);\n')
+MAIN_M_ROMFS = ('static NSString *romfs_locate(void) {\n NSFileManager *fm = NSFileManager.defaultManager;\n NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];\n for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]])\n if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@DM_GAME_ROMFS_MARKER]]) return d; // only a directory containing the game profile\'s romfs_marker path counts (Mario: System/Resource, the resource size table)\n return nil;\n}\n\n', '// A folder holds this game\'s files if it has a ROMFSARC index or the profile\'s marker path.\n// Shared by romfs_locate and the per-game layout below, so both answer the same question.\nstatic BOOL romfs_dir_ok(NSString *d) {\n NSFileManager *fm = NSFileManager.defaultManager;\n // A ROMFSARC archive: <dir>/romfs.idx next to romfs.NN shards. The host opens it when DM_ROMFS\n // points at the base; the marker check does not apply (there are no directories to walk).\n if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@"romfs.idx"]]) return YES;\n // A plain directory tree: only one containing the game profile\'s romfs_marker path counts\n // (Mario: System/Resource, the resource size table). Runtime profile: the marker is a profile\n // value now; the compiled macro is only what dm_profile() falls back to without DM_PROFILE.\n return [fm fileExistsAtPath:[d stringByAppendingPathComponent:@(dm_profile()->romfs_marker)]];\n}\n\n// Where one game\'s data lives under the per-game layout: Documents/games/<title ID>/, holding\n// romfs/ the archive (romfs.idx + shards) or a plain tree\n// msl/ this game\'s Metal shader libraries (optional; the app\'s own dm/ is used otherwise)\n// save/ temp/ this game\'s saves and scratch space\n// The layout exists so several games can share one installed app and so the game data can sit on\n// an external drive the Files app exposes (a folder copied there keeps this shape).\nstatic NSString *game_dir_for(const char *title_id) {\n NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];\n return [[doc stringByAppendingPathComponent:@"games"] stringByAppendingPathComponent:@(title_id)];\n}\n\nstatic NSString *romfs_locate(void) {\n NSFileManager *fm = NSFileManager.defaultManager;\n NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];\n // Per-game first: Documents/games/<id>/romfs — what the launcher-style layout produces, and what\n // lets a user keep several games\' data side by side (or on an external drive).\n NSString *per_game = [game_dir_for(dm_profile()->id) stringByAppendingPathComponent:@"romfs"];\n if ([fm fileExistsAtPath:per_game] && romfs_dir_ok(per_game)) return per_game;\n for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]]) {\n if (romfs_dir_ok(d)) return d;\n }\n return nil;\n}\n\n')
+MAIN_M_ENV = (' setenv("DM_ROMFS", romfs.fileSystemRepresentation, 0);\n setenv("DM_SAVE", [doc stringByAppendingPathComponent:@"save"].fileSystemRepresentation, 0);\n setenv("DM_TEMP", [doc stringByAppendingPathComponent:@"temp"].fileSystemRepresentation, 0);\n NSString *dm = [res stringByAppendingPathComponent:@"dm"];\n setenv("DM_NVN_SHMAP", [dm stringByAppendingPathComponent:@"shader_map.tsv"].fileSystemRepresentation, 0);\n setenv("DM_MSL_DIR", [res stringByAppendingPathComponent:@"msl"].fileSystemRepresentation, 0);\n', ' setenv("DM_ROMFS", romfs.fileSystemRepresentation, 0);\n // Saves and scratch space: Documents/games/<id>/{save,temp} when the per-game layout is in use\n // (so two games in one app never share a save folder), else the old Documents/{save,temp}. An\n // env file still wins — DM_SAVE/DM_TEMP set there are already in the environment and\n // setenv(..., 0) leaves them alone.\n NSString *gdir = game_dir_for(dm_profile()->id);\n // Tie the data folder to where the game files actually came from: if romfs_locate fell back to\n // Documents/romfs, the saves must stay beside it (a game folder without romfs is not in use).\n BOOL per_game = [romfs hasPrefix:gdir];\n NSString *save_dir = per_game ? [gdir stringByAppendingPathComponent:@"save"] : [doc stringByAppendingPathComponent:@"save"];\n NSString *temp_dir = per_game ? [gdir stringByAppendingPathComponent:@"temp"] : [doc stringByAppendingPathComponent:@"temp"];\n for (NSString *d in @[save_dir, temp_dir]) [fm createDirectoryAtPath:d withIntermediateDirectories:YES attributes:nil error:nil];\n setenv("DM_SAVE", save_dir.fileSystemRepresentation, 0);\n setenv("DM_TEMP", temp_dir.fileSystemRepresentation, 0);\n if (per_game) fprintf(stderr, "boot: per-game data folder %s\\n", gdir.fileSystemRepresentation);\n NSString *dm = [res stringByAppendingPathComponent:@"dm"];\n setenv("DM_NVN_SHMAP", [dm stringByAppendingPathComponent:@"shader_map.tsv"].fileSystemRepresentation, 0);\n // Shader libraries: a game\'s own <gdir>/msl first (a per-game layout may carry its own), else\n // the app\'s shared <App>/msl.\n NSString *per_game_msl = [gdir stringByAppendingPathComponent:@"msl"];\n NSString *msl = (per_game && [fm fileExistsAtPath:per_game_msl]) ? per_game_msl : [res stringByAppendingPathComponent:@"msl"];\n setenv("DM_MSL_DIR", msl.fileSystemRepresentation, 0);\n')
def patch_main_m(t):