Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Game data as one romfs.img, and the DLC rides in the same folder
LNPANDY4e3764273737
diff --git a/dm/ios/tools/build_ipa.sh b/dm/ios/tools/build_ipa.shindex 03853ae8..a9a76b21 100755--- a/dm/ios/tools/build_ipa.sh+++ b/dm/ios/tools/build_ipa.sh@@ -171,9 +171,14 @@ MAPS=()# DM_FULL_ROMFS=1 packs the game files into the package (upstream behaviour; only sensible for small# games — a full package of a large game is many GB and iOS refuses to install it with# PackageExtractionFailed). The default is the slim package: the app reads them from-# Documents/games/<id>/ (romfs.img, or a ROMFSARC archive: romfs.idx + romfs.NN shards).+# Documents/games/<id>/ (romfs.img and aoc/<index>.img), which the launcher copies in one go and+# which can also live on an external drive.if [ -n "${DM_FULL_ROMFS:-}" ]; then if [ -f "$ROMFS" ]; then MAPS=("$P/romfs.img=$ROMFS"); else MAPS=("$P/romfs=$ROMFS"); fi; fi-if [ -n "$AOC" ] && [ -d "$AOC" ]; then MAPS+=("$P/aoc=$AOC"); t "add-on content: $(ls "$AOC" | tr '\n' ' ')"; fi+if [ -n "${DM_FULL_ROMFS:-}" ] && [ -n "$AOC" ] && [ -d "$AOC" ]; then+ MAPS+=("$P/aoc=$AOC"); t "add-on content packed into the IPA: $(ls "$AOC" | tr '\n' ' ')"+elif [ -n "$AOC" ] && [ -d "$AOC" ]; then+ t "add-on content alongside the game data (DM_FULL_ROMFS=1 packs it): $(ls "$AOC" | tr '\n' ' ')"+fiif [ -n "${PSO:-}" ]; then MAPS+=("$P/pso=$PSO"); fiMAPS+=("$P/msl/$MSLDIR=$MSL_IOS/$MSLDIR" "$P=$APP")if [ -n "${DM_FULL_ROMFS:-}" ]; thendiff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex 5e9a3c9b..7ca373ee 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -54,6 +54,11 @@ TABLE: dict[str, tuple[str, str]] = {'nav.library': ('游戏库', 'Library'),'nav.builds': ('构建', 'Builds'),'nav.settings': ('设置', 'Settings'),+ 'settings.language': ('界面语言', 'Language'),+ 'settings.language.system': ('跟随系统', 'Follow system'),+ 'settings.language.zh': ('中文', '中文'),+ 'settings.language.en': ('English', 'English'),+ 'settings.appNote2': ('构建你自己的 Switch 游戏', 'Build your own Switch games'),'library.setupHint': ('首次构建前,请完成以下设置。', 'Before your first build, finish the setup below.'),'library.ready': ('可在 Mac 上运行', 'Ready on Mac'),'library.building': ('正在构建', 'Building'),@@ -246,8 +251,9 @@ TABLE: dict[str, tuple[str, str]] = {'dep.python.done': ('Python 已安装:%@', 'Python installed: %@'),'prog.title': ('构建进度', 'Build progress'),'prog.empty': ('开始构建后,这里显示脚本自己的每个阶段', "The script's own stages appear here once the build starts"),- 'prog.archive': ('RomFS 归档分片(200 MiB/片)', 'RomFS archive shards (200 MiB each)'),- 'prog.archiveShort': ('RomFS 归档分片', 'RomFS archive shards'),+ 'msg.aocCopied': ('附加内容(%d 个 DLC)已放进游戏文件夹的 aoc/', "add-on content (%d DLC) placed in the game folder's aoc/"),+ 'prog.archive': ('打包游戏数据为 romfs.img(单文件)', 'Pack game data as one romfs.img'),+ 'prog.archiveShort': ('游戏数据镜像', 'Game data image'),'prog.noRomfs': ('找不到解出的 RomFS', 'no extracted RomFS found'),'log.export': ('导出日志…', 'Export log…'),'log.exported': ('日志已保存:%@', 'Log saved: %@'),@@ -284,8 +290,8 @@ TABLE: dict[str, tuple[str, str]] = {'msg.archiveNoStart': ('无法启动 romfs_arc.py', 'Could not start romfs_arc.py'),'msg.archiveIpaOnly': ('IPA 已生成,归档失败', 'IPA built, but the archive failed'),'msg.done': ('完成:IPA 与 romfs 归档已生成,按下面三步装到手机', 'Done: the IPA and the romfs archive are ready — three steps below'),- 'prog.archiveDone': ('归档就绪:%@', 'archive ready: %@'),- 'prog.archiveReused': ('复用上次归档(%d 个文件未变)', 'reused the previous archive (%d files unchanged)'),+ 'prog.archiveDone': ('游戏数据就绪:%@/romfs.img', 'game data ready: %@/romfs.img'),+ 'prog.archiveReused': ('复用上次的镜像(%d 个文件未变)', 'reused the previous image (%d files unchanged)'),'msg.archiveReused': ('归档未变,复用 %@', 'archive unchanged, reusing %@'),'msg.archiveLog': ('归档:%@ → %@', 'Archive: %@ → %@'),}diff --git a/frontend-qt/nspb_qt/model.py b/frontend-qt/nspb_qt/model.pyindex 79d4833d..1a5f6245 100644--- a/frontend-qt/nspb_qt/model.py+++ b/frontend-qt/nspb_qt/model.py@@ -1078,13 +1078,15 @@ class Model(QObject):self.finished.emit(True, self.t('msg.archiveSkipped', str(extract)))returnromfs = str(versions[-1][1] / 'RomFS')+ # games/<id>/ is the per-game layout main.m looks in first, and the file inside it is+ # romfs.img — one file, which copies to a phone at full speed where 300,000 did notdest = str(Path(self.out_dir or Path(self.base_path).parent, 'romfs'))self.stages.append(Stage(name=self.t('prog.archiveShort'), state='running'))self.stagesChanged.emit()def work_() -> None:- args = [self.python_path, str(Path(self.repo_path, 'dm', 'tools', 'romfs_arc.py')),- 'pack', romfs, str(Path(dest, 'romfs')), '--shard-mib', '200']+ args = [self.python_path, str(Path(self.repo_path, 'dm', 'tools', 'romfs_image.py')),+ '--reuse', romfs, str(Path(dest, 'romfs.img'))]env = pu.child_env({'PYTHONPATH': str(Path(self.repo_path, 'dm', 'tools'))})ok = Truetry:diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex e566b06e..0c16fd94 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -1011,7 +1011,11 @@ final class BuildModel: ObservableObject {// side by side in one app.let gamesRoot = (outDir.isEmpty ? (basePath as NSString).deletingLastPathComponent : outDir) + "/games"let tid = Self.titleID(basePath).map { String(format: "%016llX", $0) } ?? "game"- let dest = gamesRoot + "/" + tid + "/romfs"+ // games/<id>/ holds romfs.img and aoc/ side by side: main.m's per-game lookup takes the+ // image, and the host mounts DLC from aoc/<index>.img (hle_fs.c aoc_dir). One folder, which+ // the user copies to the phone or keeps on an external drive as a whole.+ let gameDir = gamesRoot + "/" + tid+ let dest = gameDirtry? fm.createDirectory(atPath: dest, withIntermediateDirectories: true)// Reuse: packing is a multi-GB write, and the extracted RomFS is itself reused by the// script — so when the source tree's (version, file count, bytes) matches the stamp left@@ -1029,10 +1033,13 @@ final class BuildModel: ObservableObject {finishBuild(ok: true, note: t("msg.done"))return}- // a previous pack's shards must not survive a smaller new pack (the index names its own- // shards, but stale higher-numbered files would sit there confusingly)+ // One romfs.img instead of a ROMFSARC shard set: upstream reads the image directly+ // (hle_fs.c), one file copies to a phone at full speed where 300,000 did not, and it fits+ // an external drive. A shard set from an earlier build of this game is removed first —+ // main.m takes Documents/games/<id>/romfs.img before romfs/, so a stale archive would sit+ // there confusingly.for old in ((try? fm.contentsOfDirectory(atPath: dest)) ?? [])- where old == "romfs.idx" || (old.hasPrefix("romfs.") && old.dropFirst(6).allSatisfy(\.isNumber)) {+ where old == "romfs.img" || old == "romfs.idx" || (old.hasPrefix("romfs.") && old.dropFirst(6).allSatisfy(\.isNumber)) {try? fm.removeItem(atPath: dest + "/" + old)}let idx = 1000@@ -1041,9 +1048,8 @@ final class BuildModel: ObservableObject {let p = Process()p.executableURL = URL(fileURLWithPath: pythonPath.isEmpty ? "/usr/bin/python3" : pythonPath)- // base = dest + "/romfs": the pack writes romfs.idx + romfs.NN INSIDE the folder- // (base = dest would leave them as siblings of an empty folder)- p.arguments = [repoPath + "/dm/tools/romfs_arc.py", "pack", romfs, dest + "/romfs", "--shard-mib", "200"]+ // dest/romfs.img: one file, which main.m's per-game lookup takes before any folder.+ p.arguments = [repoPath + "/dm/tools/romfs_image.py", "--reuse", romfs, dest + "/romfs.img"]p.environment = ["PATH": "/usr/bin:/bin:/usr/local/bin:/opt/homebrew/bin", "PYTHONPATH": repoPath + "/dm/tools"]Self.inOwnGroup(p, python: p.executableURL!.path)let pipe = Pipe(); p.standardOutput = pipe; p.standardError = pipe@@ -1061,6 +1067,17 @@ final class BuildModel: ObservableObject {if succeeded {self.archivePath = destSelf.writeStamp(source: romfs, version: v, to: dest + "/.packstamp")+ // The DLC images ride along: with the slim default the build script leaves them in+ // the work folder instead of packing them into the IPA, and the host mounts them+ // from DM_AOC_DIR/<index>.img — so they belong in this game's folder.+ let aocSrc = workDir + "/aoc"+ let aocDst = dest + "/aoc"+ if fm.fileExists(atPath: aocSrc) {+ try? fm.removeItem(atPath: aocDst)+ try? fm.copyItem(atPath: aocSrc, toPath: aocDst)+ let n = ((try? fm.contentsOfDirectory(atPath: aocDst)) ?? []).count+ if n > 0 { self.say(String(format: self.t("msg.aocCopied"), n)) }+ }}if let i = self.stages.firstIndex(where: { $0.id == idx }) {self.stages[i].state = succeeded ? .done : .faileddiff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex 7be40a5b..fd28f470 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -339,8 +339,9 @@ enum L10n {"prog.title": ("构建进度", "Build progress"),"prog.empty": ("开始构建后,这里显示脚本自己的每个阶段","The script's own stages appear here once the build starts"),- "prog.archive": ("RomFS 归档分片(200 MiB/片)", "RomFS archive shards (200 MiB each)"),- "prog.archiveShort": ("RomFS 归档分片", "RomFS archive shards"),+ "msg.aocCopied": ("附加内容(%d 个 DLC)已放进游戏文件夹的 aoc/", "add-on content (%d DLC) placed in the game folder's aoc/"),+ "prog.archive": ("打包游戏数据为 romfs.img(单文件)", "Pack game data as one romfs.img"),+ "prog.archiveShort": ("游戏数据镜像", "Game data image"),"prog.noRomfs": ("找不到解出的 RomFS", "no extracted RomFS found"),// ---- log ----@@ -392,8 +393,8 @@ enum L10n {"msg.archiveNoStart": ("无法启动 romfs_arc.py", "Could not start romfs_arc.py"),"msg.archiveIpaOnly": ("IPA 已生成,归档失败", "IPA built, but the archive failed"),"msg.done": ("完成:IPA 与 romfs 归档已生成,按下面三步装到手机", "Done: the IPA and the romfs archive are ready — three steps below"),- "prog.archiveDone": ("归档就绪:%@", "archive ready: %@"),- "prog.archiveReused": ("复用上次归档(%d 个文件未变)", "reused the previous archive (%d files unchanged)"),+ "prog.archiveDone": ("游戏数据就绪:%@/romfs.img", "game data ready: %@/romfs.img"),+ "prog.archiveReused": ("复用上次的镜像(%d 个文件未变)", "reused the previous image (%d files unchanged)"),"msg.archiveReused": ("归档未变,复用 %@", "archive unchanged, reusing %@"),"msg.archiveLog": ("归档:%@ → %@", "Archive: %@ → %@"),]diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.pyindex 2b63a199..eafa1e75 100644--- a/scripts/sync_upstream.py+++ b/scripts/sync_upstream.py@@ -424,8 +424,19 @@ def patch_build_ipa(t):# DM_FULL_ROMFS=1 packs the game files into the package (upstream behaviour; only sensible for small# games — a full package of a large game is many GB and iOS refuses to install it with# PackageExtractionFailed). The default is the slim package: the app reads them from-# Documents/games/<id>/ (romfs.img, or a ROMFSARC archive: romfs.idx + romfs.NN shards).+# Documents/games/<id>/ (romfs.img and aoc/<index>.img), which the launcher copies in one go and+# which can also live on an external drive.if [ -n "${DM_FULL_ROMFS:-}" ]; then if [ -f "$ROMFS" ]; then MAPS=("$P/romfs.img=$ROMFS"); else MAPS=("$P/romfs=$ROMFS"); fi; fi''', 1)+ # Add-on content follows the same rule: with the slim default it goes to+ # Documents/games/<id>/aoc/<index>.img (the host already mounts *.img there, hle_fs.c+ # aoc_dir), so the IPA stays small and the game data is one folder the user copies.+ old_aoc = '''if [ -n "$AOC" ] && [ -d "$AOC" ]; then MAPS+=("$P/aoc=$AOC"); t "add-on content: $(ls "$AOC" | tr '\\n' ' ')"; fi'''+ if old_aoc in t and 'if [ -n "${DM_FULL_ROMFS:-}" ] && [ -n "$AOC" ]' not in t:+ t = t.replace(old_aoc, '''if [ -n "${DM_FULL_ROMFS:-}" ] && [ -n "$AOC" ] && [ -d "$AOC" ]; then+ MAPS+=("$P/aoc=$AOC"); t "add-on content packed into the IPA: $(ls "$AOC" | tr '\\n' ' ')"+elif [ -n "$AOC" ] && [ -d "$AOC" ]; then+ t "add-on content alongside the game data (DM_FULL_ROMFS=1 packs it): $(ls "$AOC" | tr '\\n' ' ')"+fi''', 1)old3 = '''t "pack IPA (already-compressed game files stored, everything else deflated)"'''if old3 not in t: fail('dm/ios/tools/build_ipa.sh: pack line missing after the MAPS assignment')t = t.replace(old3, '''if [ -n "${DM_FULL_ROMFS:-}" ]; then