Skip to content

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

Patch queue: drop the ROMFSARC reader and the touchpad experiment

v0lumehic6c960a8004c
diff --git a/.github/ISSUE_TEMPLATE/build_problem.yml b/.github/ISSUE_TEMPLATE/build_problem.yml
index 8bc36251..5a8814a4 100644
--- a/.github/ISSUE_TEMPLATE/build_problem.yml
+++ b/.github/ISSUE_TEMPLATE/build_problem.yml
@@ -93,7 +93,7 @@ body:
attributes:
label: Fork patches line
description: "The patches your build carries beyond upstream's engine: the first line of the game app's log (`fork patches: ...`), or the contents of `dm/fork_patches.txt` in the NX2Apple folder you built from. Optional."
- placeholder: "fork patches: runtime-profile, romfsarc, ..."
+ placeholder: "fork patches: runtime-profile, ios-game-data-folder, ..."
validations:
required: false
- type: checkboxes
diff --git a/.github/ISSUE_TEMPLATE/game_problem.yml b/.github/ISSUE_TEMPLATE/game_problem.yml
index 51f3f2d7..7aed134a 100644
--- a/.github/ISSUE_TEMPLATE/game_problem.yml
+++ b/.github/ISSUE_TEMPLATE/game_problem.yml
@@ -133,7 +133,7 @@ body:
attributes:
label: Fork patches line
description: "The first line of the game's log (`fork patches: ...`): the patches this build carries beyond upstream's engine. Optional, but it says whether a report belongs here or with seedds/nxnative."
- placeholder: "fork patches: runtime-profile, romfsarc, ..."
+ placeholder: "fork patches: runtime-profile, ios-game-data-folder, ..."
validations:
required: false
- type: textarea
diff --git a/BUILDING.md b/BUILDING.md
index 83ca05b4..d0cd7cd0 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -71,4 +71,4 @@ GAME=<title id> W=<work dir> PATCHED=<patched dir> \
`--full-romfs` (or `DM_FULL_ROMFS=1`) packs the RomFS into the package instead — upstream's
behaviour, only sensible for small games.
-The RomFS no longer has to be packed into a shard archive: the build writes the game's data as a single `romfs.img`. Archives made earlier (`romfs.idx` with `romfs.00`, `romfs.01`, …) still load, because the patch queue still carries the reader ([patches/0002-romfsarc.patch](patches/0002-romfsarc.patch), format in [docs/ROMFS_ARCHIVE.md](docs/ROMFS_ARCHIVE.md)).
+The RomFS no longer has to be packed into a shard archive: the build writes the game's data as a single `romfs.img`. Shard archives made earlier (`romfs.idx` with `romfs.00`, `romfs.01`, …) are no longer read; the launcher reports such a folder as having no game data, and the data is sent again once as a `romfs.img`.
diff --git a/BUILDING.zh-CN.md b/BUILDING.zh-CN.md
index d972e93a..f37e71aa 100644
--- a/BUILDING.zh-CN.md
+++ b/BUILDING.zh-CN.md
@@ -68,4 +68,4 @@ GAME=<title id> W=<工作目录> PATCHED=<改写目录> \
`--full-romfs`(或 `DM_FULL_ROMFS=1`)把 RomFS 打进包里——上游行为,只对小体量游戏有意义。
-RomFS 不再需要先打成分片归档:构建会把游戏数据写成一个 `romfs.img`。更早做好的归档(`romfs.idx` 加 `romfs.00`、`romfs.01`……)仍然能加载,因为补丁队列还带着它的读取层([patches/0002-romfsarc.patch](patches/0002-romfsarc.patch),格式见 [docs/ROMFS_ARCHIVE.md](docs/ROMFS_ARCHIVE.md))。
+RomFS 不再需要先打成分片归档:构建会把游戏数据写成一个 `romfs.img`。更早做好的分片归档(`romfs.idx` 加 `romfs.00`、`romfs.01`……)不再被读取;启动器会把这样的文件夹视为没有游戏数据,需要再发送一次 `romfs.img`。
diff --git a/README.md b/README.md
index 8b570775..807389be 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ keeps your games in a library you start with **Play**, the way a Switch does.
<img src="frontend/screenshots/launcher-library.webp" width="100%" alt="The launcher: a library of built games, one build in progress">
It is a community fork of **[nxnative](https://github.com/seedds/nxnative)**, which does the actual
-work (the code rewriter, the Horizon host, NVN on Metal and every game's profile). This fork adds the
+work (the code rewriter, the Horizon host, NVN on Metal and every game's profile); this fork adds the
launcher and a short list of patches, and follows nxnative every day.
## Requirements
@@ -52,11 +52,11 @@ launcher and a short list of patches, and follows nxnative every day.
the iOS SDK, and NVN games need [Xcode](https://apps.apple.com/app/xcode/id497799835) 27.1 (macOS 26.6
or later) unless built with `--allow-other-metal`.
- **Your own game dumps** (NSP or XCI) and **your own `prod.keys`** from your own console. Nothing is
- bundled, downloaded or looked up for you. The same `prod.keys` opens every one of your games, and a
+ bundled, downloaded or looked up for you. The same `prod.keys` opens every one of your games; a
current dump covers all retail titles.
- For an iPhone: iOS 26 or later and a recent phone. Older devices are untested.
-The app carries its own build tools and Python, so no Homebrew and no Python install. The .NET SDK 10
+The app carries its own build tools and Python, so no Homebrew and no Python install; the .NET SDK 10
is the one tool it still installs for you. The launcher's dependency page checks each requirement and
installs what it can with one click.
@@ -65,9 +65,9 @@ installs what it can with one click.
1. **Download the app**: `NS-Port-Builder-macOS-arm64.zip` from the
[latest release](https://github.com/LNPANDY/NX2Apple/releases/latest). Unzip it.
2. **Open it once with right-click, then Open.** The app is not signed with a paid Apple developer
- certificate, so macOS asks before the first start, and after that it opens normally.
+ certificate, so macOS asks before the first start; after that it opens normally.
3. **Follow the setup.** The launcher fetches the project it builds with (a **Download repository**
- button on the setup page, a shallow clone into `~/NX2Apple`, and if GitHub is slow, the page shows the
+ button on the setup page, a shallow clone into `~/NX2Apple`; if GitHub is slow, the page shows the
manual ZIP route), checks the tools above and updates itself later. You never need git.
4. **Build a game.** Pick the game's folder (or its base game, update, DLC and `prod.keys` one by
one), choose **This Mac** or **iPhone / iPad**, and press build. The page shows the real stages and
@@ -80,10 +80,10 @@ Building by hand from a terminal is in [BUILDING.md](BUILDING.md).
**On the Mac**, a finished game appears in the library with its key art. **Play** starts it.
**Launch options** (per game, kept across rebuilds) set the frame rate, console mode (docked or
-handheld), render scale and upscaling, game language, controls and more. What each does is in
+handheld), render scale and upscaling, game language, controls and more; what each does is in
[docs/settings.md](docs/settings.md). A controller drives the launcher as well as the games.
-**On the iPhone**, the app shows the same settings before the game starts. Tap **Play**. Touch
+**On the iPhone**, the app shows the same settings before the game starts; tap **Play**. Touch
controls come in a 2D and a 3D layout (tap the button at the top centre), and a connected controller
(Xbox, PlayStation, Switch Pro, MFi) replaces them. [docs/playing.md](docs/playing.md) covers touch,
rumble and motion. Short stutters the first time a scene appears are normal: the app compiles
@@ -93,19 +93,19 @@ that the Files app picks.
**Game language.** English is the default. On the Mac, use the **Game language** row of Launch
options. For anything the sheet lacks, write an `env.txt` of `KEY=VALUE` lines (for example
`DM_LANG=zh-Hans`) in one of two places: `~/Library/Application Support/nxnative/<title ID>/env.txt`
-wins and survives rebuilds, and `<App>.app/Contents/Resources/dm/env.txt` is the app's own. A Mac app
+wins and survives rebuilds; `<App>.app/Contents/Resources/dm/env.txt` is the app's own. A Mac app
built before the language row existed needs one rebuild to get it. On the iPhone, the same lines go
in `Documents/env.txt` (`DM_FPS_TARGET=30` caps the frame rate to save battery, `DM_OPMODE=0` picks
handheld mode).
**Saves and logs.** A Mac game in a library folder keeps its saves and its log beside the app
-(`log/<title ID>.log`). Otherwise they are in `~/Library/Application Support/nxnative/<title ID>/` and
+(`log/<title ID>.log`); otherwise they are in `~/Library/Application Support/nxnative/<title ID>/` and
`~/Library/Logs/nxnative/<title ID>.log`. On the iPhone they are in the Files app under the app's
name: `save/` and `log.txt` (the previous run is `log.prev.txt`).
**Reporting a bug.** Use the [issue forms](https://github.com/LNPANDY/NX2Apple/issues/new/choose)
(game problem, build problem, launcher problem). Each asks for the game and its title ID, your
-versions and device, **Settings > Copy diagnostics** and the game's log. [CONTRIBUTING.md](CONTRIBUTING.md)
+versions and device, **Settings > Copy diagnostics** and the game's log; [CONTRIBUTING.md](CONTRIBUTING.md)
says why. A report with the full `log.txt` is looked at first. Never attach keys, game files or
anything extracted from a game.
@@ -117,11 +117,11 @@ been tried on a phone yet. A few of them:
| | Game | Where it runs | Status |
|---|---|---|---|
-| <img src="docs/images/zelda-tears-of-the-kingdom.jpg" width="96" alt=""> | The Legend of Zelda: Tears of the Kingdom | Mac and iPhone | **Verified here**: 304,243 files, byte-checked, ~17 GB |
+| <img src="docs/images/zelda-tears-of-the-kingdom.jpg" width="96" alt=""> | The Legend of Zelda: Tears of the Kingdom | Mac and iPhone | **Verified here**: 304,243 files, byte-checked; ~17 GB |
| <img src="docs/images/hades-ii.jpg" width="96" alt=""> | Hades II | Mac and iPhone | **Verified here** |
| <img src="docs/images/animal-crossing-new-horizons.jpg" width="96" alt=""> | Animal Crossing: New Horizons | iPhone | **Verified here**: runs smoothly |
| <img src="docs/images/super-mario-odyssey.jpg" width="96" alt=""> | Super Mario Odyssey | iPhone | Reported playable upstream |
-| <img src="docs/images/zelda-breath-of-the-wild.jpg" width="96" alt=""> | The Legend of Zelda: Breath of the Wild | iPhone | Reported playable upstream, 60 fps with 1.9.0 |
+| <img src="docs/images/zelda-breath-of-the-wild.jpg" width="96" alt=""> | The Legend of Zelda: Breath of the Wild | iPhone | Reported playable upstream; 60 fps with 1.9.0 |
| <img src="docs/images/mario-kart-8-deluxe.jpg" width="96" alt=""> | Mario Kart 8 Deluxe | iPhone | Reported playable upstream |
**[GAMES.md](GAMES.md)** (中文: [GAMES.zh-CN.md](GAMES.zh-CN.md)) has the screenshot gallery with each
@@ -130,18 +130,18 @@ display version must match the profile's, or the build says so.
## Limitations
-- **Only the games with a profile.** A title outside the list needs bring-up work of its own. The
+- **Only the games with a profile.** A title outside the list needs bring-up work of its own; the
place to start is [docs/agents](docs/agents/README.md), upstream's guide for another Switch title.
- **Big games on an iPhone hit a memory limit.** Without the Increased Memory Limit entitlement iOS
gives the app about 3.4 GB, which is not enough for Tears of the Kingdom. The app requests it, and
- AltStore Classic 2.2+, Impactor and Xcode with a Personal Team keep it. SideStore with a free Apple
+ AltStore Classic 2.2+, Impactor and Xcode with a Personal Team keep it; SideStore with a free Apple
ID needs a one-time App ID fix, and Sideloadly drops it ([the steps](dm/ios/ENTITLEMENTS.md)). The
full measurements are in [GAMES.md](GAMES.md#verified-on).
-- **Unsigned apps.** The launcher and the iPhone builds are not signed for you, so you sideload them.
+- **Unsigned apps.** The launcher and the iPhone builds are not signed for you; you sideload them.
- **Your own files.** No game data, firmware or keys are included or downloaded.
-- **Older shard archives still load.** The first iPhone builds packed Tears of the Kingdom into a
- RomFS shard archive (`romfs.idx`). The build writes a single `romfs.img` now, and the reader for
- the old archives is still shipped ([docs/ROMFS_ARCHIVE.md](docs/ROMFS_ARCHIVE.md)).
+- **Older shard archives are not read any more.** The first iPhone builds packed Tears of the Kingdom
+ into a RomFS shard archive (`romfs.idx`); the build writes a single `romfs.img` now. An iPhone
+ that still holds an old archive needs the game data sent again once, as a `romfs.img` through the launcher.
## For developers
@@ -161,7 +161,7 @@ display version must match the profile's, or the build says so.
- **[v0lumehi](https://github.com/v0lumehi)** — **the Mac front end's launcher** (PR [#27](https://github.com/LNPANDY/NX2Apple/pull/27), 40 files): a game library with key art, per-game launch options, a real progress stream, and a Stop that ends the whole build's process group. The Mac app went from "a build form" to the first version of a launcher that opens like a Switch.
- **[m1guelpf](https://github.com/m1guelpf)** (Miguel Piedrafita) — two HLE fixes (PRs [#24](https://github.com/LNPANDY/NX2Apple/pull/24) and [#26](https://github.com/LNPANDY/NX2Apple/pull/26)): the missing `EnableAlbumImageTakenNotification` and `CreateWithAdjustableSystemClock` entries plus their snapshot type byte — each would have read a null in games that call them, and each came with a test.
-Want on this list? [Contributing](CONTRIBUTING.md#helping-with-games) says how to start. Reports with a full log and fixes with a test move fastest.
+Want on this list? [Contributing](CONTRIBUTING.md#helping-with-games) says how to start; reports with a full log and fixes with a test move fastest.
All of the engine work is other people's. This repository adds the launcher and the patch queue on top:
@@ -181,8 +181,6 @@ All of the engine work is other people's. This repository adds the launcher and
`dm/third_party` ships other projects with their licenses ([list](dm/third_party/README.md)).
-[LICENSE](LICENSE) is the plain MIT text with the copyright lines of seedds (nxnative), jhaizhou (d2r-mobile) and LNPANDY with the NX2Apple contributors. [NOTICE](NOTICE) says where the code comes from and which part LNPANDY wrote.
-
## Legal
**What this project is.** A build tool for games you already own. It reads dumps you made of your
@@ -196,18 +194,18 @@ redistribute any protection — LibHac opens the user's own dumps with the user'
operation a console performs on a cartridge.
**Trademarks.** Not affiliated with, sponsored by or endorsed by Nintendo. "Nintendo Switch" and
-game titles are trademarks of Nintendo Co., Ltd. All other trademarks belong to their respective
+game titles are trademarks of Nintendo Co., Ltd.; all other trademarks belong to their respective
owners.
-**Your responsibility.** Laws on making a personal backup copy differ by country, and some places do
+**Your responsibility.** Laws on making a personal backup copy differ by country; some places do
not allow it at all. You are responsible for knowing and following the law where you live, and for
never distributing game files, keys or the packages built from them — the project's outputs are for
personal use on your own hardware only. If you enjoy a game, buy it.
**Takedowns.** If you believe anything in this repository infringes your rights, open an issue or
-contact the maintainer directly. Valid claims will be actioned promptly, up to removing content or
+contact the maintainer directly; valid claims will be actioned promptly, up to removing content or
the repository.
**No warranty.** The software is provided "as is" under the licenses in [LICENSE](LICENSE) (this
-fork adds to upstream's, as the credits show) — without warranty of any kind, express or implied. Use
+fork adds to upstream's; see the credits) — without warranty of any kind, express or implied. Use
it at your own risk.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 39419698..1fdc86bd 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -42,26 +42,26 @@ NX2Apple 用你自己导出的游戏文件,在你的 Mac 和 iPhone 上运行
<img src="frontend/screenshots/launcher-library.webp" width="100%" alt="启动器:已构建游戏的游戏库,和一个正在进行的构建">
它是 **[nxnative](https://github.com/seedds/nxnative)** 的社区 fork。真正的工作(代码改写器、Horizon
-宿主层、NVN-on-Metal 和每个游戏的 profile)都是 nxnative 的。本 fork 在其上增加启动器和少量补丁,
+宿主层、NVN-on-Metal 和每个游戏的 profile)都是 nxnative 的;本 fork 在其上增加启动器和少量补丁,
并每天跟随 nxnative 更新。
## 环境要求
-- **Apple Silicon Mac。** 启动器支持 **macOS 13 或更新**。构建需要装了 iOS SDK 的 Xcode,NVN 游戏需要
+- **Apple Silicon Mac。** 启动器支持 **macOS 13 或更新**。构建需要装了 iOS SDK 的 Xcode;NVN 游戏需要
[Xcode](https://apps.apple.com/app/xcode/id497799835) 27.1(macOS 26.6 或更新),除非加 `--allow-other-metal`。
- **你自己的游戏文件**(NSP 或 XCI)和**你自己主机里导出的 `prod.keys`**。本项目不自带、不下载、
- 也不替你查找任何东西。一份 `prod.keys` 能解你所有的游戏,新导出的一份覆盖所有零售游戏。
+ 也不替你查找任何东西。一份 `prod.keys` 能解你所有的游戏;新导出的一份覆盖所有零售游戏。
- 要装到 iPhone:iOS 26 或更新,以及较新的手机。更旧的设备未测试。
-App 自带构建工具和 Python,不需要装 Homebrew 和 Python,但 .NET SDK 10 仍由 App 帮你安装。启动器的依赖页会逐项检查,能装的一键安装。
+App 自带构建工具和 Python,不需要装 Homebrew 和 Python;.NET SDK 10 仍由 App 帮你安装。启动器的依赖页会逐项检查,能装的一键安装。
## 安装
1. **下载 App**:从[最新版本](https://github.com/LNPANDY/NX2Apple/releases/latest)下载
`NS-Port-Builder-macOS-arm64.zip`,解压。
2. **首次启动:右键 → 打开。** 这个 App 没有付费的 Apple 开发者证书签名,所以 macOS 在第一次启动时会
- 询问,之后就能正常打开。
-3. **按设置页走。** 启动器会取回构建用的项目(设置页上的「下载仓库」按钮,浅克隆到 `~/NX2Apple`,
+ 询问;之后就能正常打开。
+3. **按设置页走。** 启动器会取回构建用的项目(设置页上的「下载仓库」按钮,浅克隆到 `~/NX2Apple`;
GitHub 不顺手时页面会给出手动 ZIP 的路线),检查上面的工具,之后还会自己更新。全程不需要懂 git。
4. **构建游戏。** 选好游戏文件夹(或者分别选本体、更新包、DLC 和 `prod.keys`),选择「这台 Mac」或
「iPhone / iPad」,按构建。页面显示真实的阶段和剩余时间,中途停止的构建会从上次继续。iPhone 构建
@@ -72,7 +72,7 @@ App 自带构建工具和 Python,不需要装 Homebrew 和 Python,但 .NET S
## 游玩
**在 Mac 上**,构建好的游戏带着封面出现在游戏库里,点 **Play** 启动。**启动选项**(按游戏保存,重新
-构建后仍然保留)可设置帧率、主机模式(底座或掌机)、渲染缩放和超分辨率、游戏语言、操控等。每项的
+构建后仍然保留)可设置帧率、主机模式(底座或掌机)、渲染缩放和超分辨率、游戏语言、操控等;每项的
作用见 [docs/settings.md](docs/settings.md)(英文)。手柄既能操作游戏,也能操作启动器。
**在 iPhone 上**,App 在游戏开始前显示同样的设置,点 **Play** 即可。触屏操控有 2D 和 3D 两种布局
@@ -82,17 +82,17 @@ App 会为它编译一次图形并记住。游戏数据(`romfs.img`)可以
**游戏语言。** 默认英文。Mac 上用启动选项里的「游戏语言」一行。面板里没有的设置,可以写一个
`env.txt`,每行 `KEY=VALUE`(例如 `DM_LANG=zh-Hans`),放在两处之一:
-`~/Library/Application Support/nxnative/<title ID>/env.txt` 优先,重新构建后仍在,
+`~/Library/Application Support/nxnative/<title ID>/env.txt` 优先,重新构建后仍在;
`<App>.app/Contents/Resources/dm/env.txt` 是 App 自带的。在加入语言选项之前构建的 Mac App 需要重新构建
一次才有该项。iPhone 上同样的行写在 `Documents/env.txt` 里(`DM_FPS_TARGET=30` 限帧省电,
`DM_OPMODE=0` 选掌机模式)。
-**存档和日志。** 放在游戏库文件夹里的 Mac 游戏,存档和日志在 App 旁边(`log/<title ID>.log`)。否则在
+**存档和日志。** 放在游戏库文件夹里的 Mac 游戏,存档和日志在 App 旁边(`log/<title ID>.log`);否则在
`~/Library/Application Support/nxnative/<title ID>/` 和 `~/Library/Logs/nxnative/<title ID>.log`。
iPhone 上在「文件」App 里该 App 名字下:`save/` 和 `log.txt`(上一次运行的是 `log.prev.txt`)。
**报告问题。** 请用[问题表单](https://github.com/LNPANDY/NX2Apple/issues/new/choose)(游戏问题、构建问题、
-启动器问题)。表单会要你填游戏和 title ID、版本和设备、**设置 > 复制诊断信息**,以及游戏的日志。
+启动器问题)。表单会要你填游戏和 title ID、版本和设备、**设置 > 复制诊断信息**,以及游戏的日志;
为什么需要见 [CONTRIBUTING.md](CONTRIBUTING.md)(英文)。附上完整 `log.txt` 的报告会优先处理。
千万不要附上密钥、游戏文件或任何从游戏中提取的内容。
@@ -103,11 +103,11 @@ iPhone 上在「文件」App 里该 App 名字下:`save/` 和 `log.txt`(上
| | 游戏 | 运行于 | 状态 |
|---|---|---|---|
-| <img src="docs/images/zelda-tears-of-the-kingdom.jpg" width="96" alt=""> | 塞尔达传说:王国之泪 | Mac 和 iPhone | **本 fork 验证**:304,243 个文件,逐字节校验,约 17 GB |
+| <img src="docs/images/zelda-tears-of-the-kingdom.jpg" width="96" alt=""> | 塞尔达传说:王国之泪 | Mac 和 iPhone | **本 fork 验证**:304,243 个文件,逐字节校验;约 17 GB |
| <img src="docs/images/hades-ii.jpg" width="96" alt=""> | Hades II | Mac 和 iPhone | **本 fork 验证** |
| <img src="docs/images/animal-crossing-new-horizons.jpg" width="96" alt=""> | 集合啦!动物森友会 | iPhone | **本 fork 验证**:流畅运行 |
| <img src="docs/images/super-mario-odyssey.jpg" width="96" alt=""> | 超级马力欧 奥德赛 | iPhone | 上游报告可玩 |
-| <img src="docs/images/zelda-breath-of-the-wild.jpg" width="96" alt=""> | 塞尔达传说:旷野之息 | iPhone | 上游报告可玩,1.9.0 可 60 fps |
+| <img src="docs/images/zelda-breath-of-the-wild.jpg" width="96" alt=""> | 塞尔达传说:旷野之息 | iPhone | 上游报告可玩;1.9.0 可 60 fps |
| <img src="docs/images/mario-kart-8-deluxe.jpg" width="96" alt=""> | 马力欧卡丁车 8 豪华版 | iPhone | 上游报告可玩 |
**[GAMES.zh-CN.md](GAMES.zh-CN.md)**(English: [GAMES.md](GAMES.md),带截图图库和每款的安装大小)
@@ -115,22 +115,22 @@ iPhone 上在「文件」App 里该 App 名字下:`save/` 和 `log.txt`(上
## 限制
-- **只支持有 profile 的游戏。** 列表之外的游戏需要单独的 bring-up 工作。起点是
+- **只支持有 profile 的游戏。** 列表之外的游戏需要单独的 bring-up 工作;起点是
[docs/agents](docs/agents/README.md)(上游为其他 Switch 游戏写的指南,英文)。
- **大体积游戏在 iPhone 上会碰到内存上限。** 没有 Increased Memory Limit entitlement 时 iOS 只给 App
约 3.4 GB,不够《王国之泪》用。App 请求了它,AltStore Classic 2.2+、Impactor 和 Xcode + Personal Team
- 会保留。SideStore 配合免费 Apple ID 需要对 App ID 做一次性修复,Sideloadly 会丢掉它
+ 会保留;SideStore 配合免费 Apple ID 需要对 App ID 做一次性修复,Sideloadly 会丢掉它
([步骤](dm/ios/ENTITLEMENTS.md))。完整的测量见 [GAMES.zh-CN.md](GAMES.zh-CN.md#验证情况)。
- **App 未签名。** 启动器和 iPhone 构建不会替你签名,需要你自己侧载。
- **你自己的文件。** 不包含也不下载任何游戏数据、固件或密钥。
-- **旧的分片归档仍能加载。** 最早的 iPhone 构建把《王国之泪》打成 RomFS 分片归档(`romfs.idx`)。现在
- 构建写出单个 `romfs.img`,但旧归档的读取层仍然随附([docs/ROMFS_ARCHIVE.md](docs/ROMFS_ARCHIVE.md))。
+- **旧的分片归档不再被读取。** 最早的 iPhone 构建把《王国之泪》打成 RomFS 分片归档(`romfs.idx`);现在
+ 构建写出单个 `romfs.img`。仍保留旧归档的 iPhone 需要通过启动器把游戏数据重新发送一次(`romfs.img`)。
## 给开发者
- **从源码构建:** [BUILDING.zh-CN.md](BUILDING.zh-CN.md)。**报告或修复问题:** [CONTRIBUTING.zh-CN.md](CONTRIBUTING.zh-CN.md)。
- **本 fork 对上游改了什么:** 引擎(`dm/`、`scripts/`、`docs/`、`ref/`、`AGENTS.md`)就是 nxnative 在固定提交上的
- 内容,加一组补丁,每个补丁写明本 fork 为什么带着它。见 [patches/README.md](patches/README.md)。
+ 内容,加一组补丁,每个补丁写明本 fork 为什么带着它。见 [patches/README.md](patches/README.md);
`python3 scripts/patches.py status` 列出带着的全部补丁。每天一次的任务移动固定提交并开 pull request,
某个补丁对不上时开一个点名该补丁的 issue。
- **其他 Switch 游戏:** [docs/agents](docs/agents/README.md)(解包、二进制调查、bring-up)。
@@ -143,7 +143,7 @@ iPhone 上在「文件」App 里该 App 名字下:`save/` 和 `log.txt`(上
- **[v0lumehi](https://github.com/v0lumehi)** —— **Mac 前端的启动器界面**(PR [#27](https://github.com/LNPANDY/NX2Apple/pull/27),40 个文件):游戏库、封面图、每游戏启动选项、真进度流、能真正结束整个构建进程组的 Stop。Mac 端从"一个构建表单"变成了"打开像一台 Switch 的启动器"的第一版。
- **[m1guelpf](https://github.com/m1guelpf)**(Miguel Piedrafita)—— 两个 HLE 修复(PR [#24](https://github.com/LNPANDY/NX2Apple/pull/24)、[#26](https://github.com/LNPANDY/NX2Apple/pull/26)):补上了 `EnableAlbumImageTakenNotification` 和 `CreateWithAdjustableSystemClock` 及其快照类型字节——两个原本会让游戏读到空指针的缺失条目,各带测试。
-想加入这个列表?[参与贡献](CONTRIBUTING.zh-CN.md#帮忙补充游戏)写了怎么开始。issue 里附上完整日志的报告和带测试的修复最快。
+想加入这个列表?[参与贡献](CONTRIBUTING.zh-CN.md#帮忙补充游戏)写了怎么开始;issue 里附上完整日志的报告和带测试的修复最快。
所有底层引擎的工作都是别人的。本仓库在其之上增加了启动器和补丁队列:
@@ -159,8 +159,6 @@ iPhone 上在「文件」App 里该 App 名字下:`save/` 和 `log.txt`(上
`dm/third_party` 里随附了其他项目及其许可证([列表](dm/third_party/README.md))。
-[LICENSE](LICENSE) 是标准 MIT 文本,版权行为 seedds(nxnative)、jhaizhou(d2r-mobile)以及 LNPANDY 和 NX2Apple 贡献者。[NOTICE](NOTICE) 说明代码的来源,以及哪一部分由 LNPANDY 编写。
-
## 法律
**本项目是什么。** 一个为你**已拥有**的游戏做构建的工具。它读取你在自己机器上从自己的卡带和购买中
@@ -172,13 +170,13 @@ NSP/XCI 导出文件,且不连接任何服务器。它不绕过、不移除、
密钥打开用户自己的导出文件,和主机读取卡带执行的是同一种操作。
**商标。** 与任天堂无关联,也未获得其赞助或认可。"Nintendo Switch" 及各游戏名称是任天堂株式会社的
-商标。其他商标归各自权利人所有。
+商标;其他商标归各自权利人所有。
**你的责任。** 制作个人备份副本的法律因国家而异,有些地方完全不允许。你有责任了解并遵守所在地的
法律,并且绝不分发游戏文件、密钥或由它们构建出的安装包——本项目的产物仅供在你自己的硬件上个人使用。
喜欢哪个游戏,请购买它。
-**下架。** 如果你认为本仓库中的任何内容侵犯了你的权利,请开 issue 或直接联系维护者。有效的权利
+**下架。** 如果你认为本仓库中的任何内容侵犯了你的权利,请开 issue 或直接联系维护者;有效的权利
主张会得到及时处理,包括删除相关内容乃至整个仓库。
**无担保。** 本软件按 [LICENSE](LICENSE) 中的许可证(本 fork 在上游之上有所附加,见致谢)以"现状"
diff --git a/dm/fork_patches.txt b/dm/fork_patches.txt
index c699719b..bf055e61 100644
--- a/dm/fork_patches.txt
+++ b/dm/fork_patches.txt
@@ -1,5 +1,4 @@
runtime-profile
-romfsarc
ios-game-data-folder
ios-slim-ipa
nsp-dotnet-home
@@ -10,7 +9,6 @@ mac-keymap
mac-library-folder
hades2-update-profile
env-switches-verify
-touchpad-geometry
ios-probe
fork-docs
ref-hle-hid-d2r
diff --git a/dm/host/Makefile b/dm/host/Makefile
index 2ea17ce7..b85ae360 100644
--- a/dm/host/Makefile
+++ b/dm/host/Makefile
@@ -16,7 +16,7 @@ endif
GAME_H = gen/$(GAME)/game_profile.h
CFLAGS=-O1 -g -Wall -Wno-unused-function
# Service-layer takeover hle_*.c files are included by wildcard: adding a file does not touch this line (avoids merge conflicts)
-SRC=main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c save_sync.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
+SRC=main.c loader.c hle.c crash.c probe.c thread.c save_sync.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
# NVN null device + nn::vi + the Vulkan layer (dm/gfx/)
# Sources under dm/gfx, dm/gfx/nvn, dm/gfx/tex, dm/gfx/vk and dm/gfx/gl are included by wildcard (tests/ and metal/ do not go into the host): adding a file does not touch this line
GFX=$(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/nvn/*.m ../gfx/nvn/*.S ../gfx/tex/*.c ../gfx/tex/*.m ../gfx/vk/*.m ../gfx/gl/*.m))
diff --git a/dm/host/hle_fs.c b/dm/host/hle_fs.c
index df984ef6..75457a03 100644
--- a/dm/host/hle_fs.c
+++ b/dm/host/hle_fs.c
@@ -7,7 +7,6 @@
#include "hle.h"
#include <mach/mach.h>
#include "front.h"
-#include "romfs_arc.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -384,28 +383,6 @@ static int host_path_ex(const char *p, char *out, size_t n, int *ro, int create)
char normed[1024]; const char *rest = c + 1;
if (strstr(rest, "/.")) { if (!norm_rest(rest, normed, sizeof normed)) return 0; rest = normed; } // only paths with "." components are normalized; the rest walk component by component as before
if (g_mnt[i].overlay[0] && !create) return rom_overlay_path(&g_mnt[i], rest, out, n);
- // Archive mount: the RomFS tree lives inside a ROMFSARC archive, so the host path is a
- // synthetic "@romfsarc:<guest path>" that the file calls below route to romfs_arc.c. Matched
- // by the mount directory (romfsarc_open recorded the base it actually opened), because the
- // mount name differs between games (rom, content).
- if (romfsarc_active() && g_mnt[i].ro && !create && g_mnt[i].dir[0] && !strcmp(g_mnt[i].dir, g_arc_base)) {
- // Fold runs of '/' the way the directory walk below does: the archive index stores one
- // separator per level, and a game may ask for "data:/bin/appli/icon_sick//bin/x.arc"
- // (Pokemon Sword's Bag: the doubled slash missed the lookup and the game then
- // dereferenced the null it got back — PR #9).
- char folded[1024]; const char *r = rest;
- if (strstr(rest, "//")) {
- size_t o = 0; int slash = 0;
- for (const char *q = rest; *q; q++) {
- if (*q == '/') { if (slash) continue; slash = 1; } else slash = 0;
- if (o + 1 >= sizeof folded) { errno = ENAMETOOLONG; return 0; }
- folded[o++] = *q;
- }
- folded[o] = 0; r = folded;
- }
- if (snprintf(out, n, ROMFSARC_SYNTH_PREFIX "%s", r) >= (int)n) { errno = ENAMETOOLONG; return 0; }
- return 1;
- }
strlcpy(out, g_mnt[i].dir, n);
while (*rest) {
while (*rest == '/') rest++;
@@ -450,22 +427,9 @@ static Result err_res(const char *op, const char *path) {
// ---------- Mount ----------
HLE_FORCE("_ZN2nn2fs22QueryMountRomCacheSizeEPm", "fsp-srv; rom reads the host directory directly, the cache gets only the minimum size", Result, h_fs_QueryRomCache, size_t *out) { *out = 0x1000; return RES_OK; }
-HLE_FORCE("_ZN2nn2fs8MountRomEPKcPvm", "fsp-srv; rom → host RomFS directory (or a ROMFSARC archive)", Result, h_fs_MountRom, const char *name, void *cache, size_t sz) {
+HLE_FORCE("_ZN2nn2fs8MountRomEPKcPvm", "fsp-srv; rom → host RomFS directory", Result, h_fs_MountRom, const char *name, void *cache, size_t sz) {
(void)cache; (void)sz; char b[1024];
- const char *dir = envdir("DM_ROMFS", "romfs", b, sizeof b);
- // Archive mount: romfsarc_open tries <dir>.idx, <dir>/romfs.idx and <dir>/romfs/romfs.idx, so the
- // player may copy the shards either beside the folder or into Documents/romfs/ itself.
- romfsarc_hdr h;
- if (romfsarc_open(dir, &h) == 0) {
- // Mount the resolved archive base (romfsarc_open recorded the one that worked in g_arc_base).
- // host_path_ex compares the mount directory against it.
- Result r = mount(name, g_arc_base, 1);
- if (r != RES_OK) { romfsarc_close(); return r; }
- LOG("fs rom: archive %s (%llu files, %llu dirs, %u shards, tree hash %016llx)", g_arc_base,
- (unsigned long long)h.file_count, (unsigned long long)h.dir_count, h.shard_count, (unsigned long long)h.tree_hash);
- return RES_OK;
- }
- Result r = mount(name, dir, 1);
+ Result r = mount(name, envdir("DM_ROMFS", "romfs", b, sizeof b), 1);
if (r == RES_OK && getenv("DM_ROMFS_OVERLAY")) {
PATH_LOCK();
for (int i = 0; i < g_nmnt; i++) if (!strcmp(g_mnt[i].name, name)) {
@@ -755,43 +719,6 @@ HLE_FORCE("_ZN2nn2fs14CommitSaveDataEPKc", "fsp-srv; same as Commit (SDK 11's ol
HLE_FORCE("_ZN2nn2fs7UnmountEPKc", "fsp-srv; the mount table is permanent, unmounting is a no-op", void, h_fs_Unmount, const char *name) { (void)name; }
// ---------- Files ----------
-// ---------- Archive-backed file handles ----------
-// An archive file has no host fd. It gets a handle number from a private table, and every operation
-// on it (ReadFile, GetFileSize, CloseFile) checks the table first. Handle numbers are distinct from
-// fds: real handles are fds (>= 3 in practice), archive handles are tagged by index into g_arc[].
-// Like every host handle they reach the guest through FH_OUT (shifted left by 4, 16-byte aligned) and come back
-// through FH_IN, so the tag sits at bit 57: below IMG_H's bit 58, and it still fits after the shift.
-typedef struct { uint32_t shard; uint64_t off, size; int used; } archandle;
-#define MAX_ARCH 4096
-static archandle g_arc[MAX_ARCH];
-static uint64_t g_arch_gen; // bumped on open/close so a stale handle never hits a recycled slot
-static uint64_t arc_new(uint32_t shard, uint64_t off, uint64_t size) {
- for (int i = 0; i < MAX_ARCH; i++) if (!g_arc[i].used) {
- g_arc[i].used = 1; g_arc[i].shard = shard; g_arc[i].off = off; g_arc[i].size = size;
- return ((uint64_t)1 << 57) | ((g_arch_gen & 0xffffff) << 32) | (uint32_t)i;
- }
- return 0;
-}
-static int arc_get(uint64_t h, archandle **out) {
- if ((h >> 57) != 1) return 0;
- uint32_t i = (uint32_t)h;
- if (i >= MAX_ARCH || !g_arc[i].used) return 0;
- if ((uint32_t)((h >> 32) & 0xffffff) != (uint32_t)(g_arch_gen & 0xffffff)) return 0;
- *out = &g_arc[i]; return 1;
-}
-static void arc_free(uint64_t h) {
- archandle *a; if (arc_get(h, &a)) a->used = 0;
-}
-static const char *arc_rel(const char *hp) {
- const char *rel = ROMFSARC_SYNTH_REL(hp);
- while (*rel == '/') rel++;
- return rel;
-}
-static int arc_file(const char *hp, uint32_t *shard, uint64_t *off, uint64_t *size) {
- return romfsarc_stat_file(arc_rel(hp), shard, off, size);
-}
-static int arc_dir(const char *hp) { return romfsarc_is_dir(arc_rel(hp)); }
-static void arc_norm(const char *hp, char *rel, size_t n) { strlcpy(rel, arc_rel(hp), n); }
HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Result, h_fs_OpenFile, uint64_t *out, const char *path, int mode) {
int mi; int64_t k;
if (img_path(path, &mi, &k)) {
@@ -804,15 +731,6 @@ HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Re
}
HP(path);
if (mode & (MODE_WRITE | MODE_APPEND)) RW();
- if (ROMFSARC_IS_SYNTH(hp)) { // archive entry: no fd, the handle carries shard/offset/size
- uint32_t shard; uint64_t off, size;
- if (!arc_file(hp, &shard, &off, &size)) { errno = ENOENT; return err_res("open", hp); }
- uint64_t ah = arc_new(shard, off, size);
- if (!ah) { errno = EMFILE; return err_res("open", hp); }
- *out = FH_OUT(ah);
- if (g_flag.fs) LOG("fs open %s mode=%d → archive handle (shard %u off %llu size %llu)", path, mode, shard, (unsigned long long)off, (unsigned long long)size);
- return RES_OK;
- }
int fd = open(hp, (mode & (MODE_WRITE | MODE_APPEND)) ? ((mode & MODE_READ) ? O_RDWR : O_WRONLY) : O_RDONLY);
if (fd < 0) return err_res("open", hp);
struct stat st; fstat(fd, &st);
@@ -836,20 +754,6 @@ HLE_FORCE("_ZN2nn2fs8ReadFileEPmNS0_10FileHandleElPvm", "fsp-srv → pread(2)",
sz = off < 0 || (uint64_t)off >= x->b ? 0 : (size_t)(x->b - off) < sz ? (size_t)(x->b - off) : sz;
}
dm_guest_write_prepare(buf, sz); // The destination may be a texture pool page write-protected by the graphics layer: a kernel write to a read-only page returns EFAULT instead of page-faulting, so unprotect and mark dirty first
- archandle *ah;
- if (arc_get(h, &ah)) { // archive entry: clamp to the file, read from its shard
- if (off < 0) { *out = 0; return RES_FAIL; }
- uint64_t avail = (uint64_t)off < ah->size ? ah->size - (uint64_t)off : 0;
- size_t want = sz < avail ? sz : (size_t)avail;
- if (want) { ssize_t r = romfsarc_pread(ah->shard, ah->off + (uint64_t)off, buf, want);
- if (r < 0) return err_res("pread (archive)", "handle"); got = (size_t)r; }
- *out = got;
- if (g_flag.fs) { static uint64_t n, bytes, next_b = 64 << 20; static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_lock(&m); n++; bytes += got;
- if (bytes >= next_b || n % 1000 == 0) { LOG("fs read total: %llu reads %.1f MiB (this one: archive offset %lld length %#zx)", n, bytes / 1048576.0, (long long)off, got); if (bytes >= next_b) next_b += 64 << 20; }
- pthread_mutex_unlock(&m); }
- return RES_OK;
- }
while (got < sz) {
ssize_t r = pread(fd, (uint8_t *)buf + got, sz - got, base + off + got);
if (r < 0) { if (errno == EINTR) continue;
@@ -906,7 +810,6 @@ HLE_FORCE("_ZN2nn2fs9WriteFileENS0_10FileHandleElPKvmRKNS0_11WriteOptionE", "fsp
}
HLE_FORCE("_ZN2nn2fs11GetFileSizeEPlNS0_10FileHandleE", "fsp-srv → fstat(2)", Result, h_fs_GetFileSize, int64_t *out, uint64_t h) { h = FH_IN(h);
if (!h) return RES_FAIL;
- archandle *ah; if (arc_get(h, &ah)) { *out = (int64_t)ah->size; return RES_OK; }
if (IMG_H(h)) { *out = (int64_t)g_mnt[IMG_M(h)].img->e[IMG_K(h)].b; return RES_OK; }
struct stat st; if (fstat((int)h, &st)) return err_res("fstat", "fd");
*out = st.st_size; return RES_OK;
@@ -923,7 +826,6 @@ HLE_FORCE("_ZN2nn2fs11SetFileSizeENS0_10FileHandleEl", "fsp-srv → ftruncate(2)
HLE_FORCE("_ZN2nn2fs9FlushFileENS0_10FileHandleE", "fsp-srv; host writes are already in the page cache, flushing is a no-op", Result, h_fs_FlushFile, uint64_t h) { (void)h; return RES_OK; }
HLE_FORCE("_ZN2nn2fs9CloseFileENS0_10FileHandleE", "fsp-srv → close(2)", void, h_fs_CloseFile, uint64_t h) { h = FH_IN(h);
if (!h || IMG_H(h)) return; // the null handle after a failed open (see ReadFile): do not touch fd 0; an image entry holds no descriptor
- if ((h >> 57) == 1) { arc_free(h); return; } // archive entry: nothing to close
g_fmode[(int)h & 0xffff] = 0; atomic_store(&g_ftxn[(int)h & 0xffff], 0);
close((int)h); }
HLE_FORCE("_ZN2nn2fs15GetFileOpenModeENS0_10FileHandleE", "fsp-srv; the open mode is recorded by the host", int, h_fs_GetFileOpenMode, uint64_t h) { h = FH_IN(h); return IMG_H(h) ? MODE_READ : g_fmode[(int)h & 0xffff]; }
@@ -1007,39 +909,12 @@ HLE_FORCE("_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc", "fsp-srv →
int mi; int64_t k;
if (img_path(path, &mi, &k)) { if (k < 0) return err_res("stat", path); *out = g_mnt[mi].img->e[k].type ? ENT_FILE : ENT_DIR; return RES_OK; }
HP(path); struct stat st;
- if (ROMFSARC_IS_SYNTH(hp)) { // archive entry or directory, from the index
- const char *rel = arc_rel(hp); // the index stores paths without a leading slash (abe35a3)
- uint32_t sh; uint64_t of, szf;
- if (romfsarc_stat_file(rel, &sh, &of, &szf)) { *out = ENT_FILE; return RES_OK; }
- if (romfsarc_is_dir(rel)) { *out = ENT_DIR; return RES_OK; }
- errno = ENOENT; return err_res("stat", hp);
- }
if (stat(hp, &st)) return err_res("stat", hp);
*out = S_ISDIR(st.st_mode) ? ENT_DIR : ENT_FILE; return RES_OK;
}
// ---------- Directories ----------
typedef struct { DIR *d; char path[1024]; DIR *od; char opath[1024]; DirectoryEntry *snap; int64_t nsnap, psnap; int mode; } dirh_t;
-
-// An archive directory has no host DIR: its entries come from the index, copied into the same
-// snapshot list the overlay mount uses, so ReadDirectory has one path for both.
-static void arc_snapshot(dirh_t *h, const char *hp) {
- char rel[1024]; arc_norm(hp, rel, sizeof rel);
- int n = romfsarc_count(rel);
- if (n <= 0) return;
- romfsarc_ent *ents = malloc((size_t)n * sizeof *ents);
- if (!ents) die("archive directory snapshot allocation failed");
- int got = romfsarc_list(rel, ents, n);
- if (got <= 0) { free(ents); return; }
- h->snap = calloc((size_t)got, sizeof *h->snap); h->nsnap = got;
- if (!h->snap) die("archive directory snapshot allocation failed");
- for (int i = 0; i < got; i++) {
- strlcpy(h->snap[i].name, ents[i].name, sizeof h->snap[i].name);
- h->snap[i].type = ents[i].is_dir ? ENT_DIR : ENT_FILE;
- h->snap[i].size = ents[i].is_dir ? 0 : ents[i].size;
- }
- free(ents);
-}
static void dir_snapshot(dirh_t *h, const mount_t *m, const char *rest) {
char fwd[1024]; rest = fwd_slashes(rest, fwd, sizeof fwd);
char *roots = strdup(m->overlay);
@@ -1101,15 +976,7 @@ HLE_FORCE("_ZN2nn2fs13OpenDirectoryEPNS0_15DirectoryHandleEPKci", "fsp-srv → o
}
*out = (uint64_t)h; return RES_OK;
}
- HP(path);
- if (ROMFSARC_IS_SYNTH(hp)) { // archive directory: no host DIR, only the snapshot
- if (!arc_dir(hp)) { errno = ENOTDIR; return err_res("opendir", hp); }
- dirh_t *ah = calloc(1, sizeof *ah); if (!ah) die("directory handle allocation failed");
- strlcpy(ah->path, hp, sizeof ah->path); ah->mode = mode;
- arc_snapshot(ah, hp);
- *out = (uint64_t)ah; return RES_OK;
- }
- DIR *d = opendir(hp);
+ HP(path); DIR *d = opendir(hp);
if (!d) return err_res("opendir", hp);
dirh_t *h = calloc(1, sizeof *h); h->d = d; strlcpy(h->path, hp, sizeof h->path); h->mode = mode;
const char *c = strchr(path, ':');
@@ -1122,7 +989,6 @@ HLE_FORCE("_ZN2nn2fs13ReadDirectoryEPlPNS0_14DirectoryEntryENS0_15DirectoryHandl
if (!hh) { *count = 0; return RES_FAIL; }
PATH_LOCK(); dirh_t *h = (dirh_t *)hh; int64_t n = 0; struct dirent *e;
if (h->snap) { while (n < max && h->psnap < h->nsnap) { DirectoryEntry *src = &h->snap[h->psnap++]; if (!(h->mode & (src->type == ENT_DIR ? DIRMODE_DIR : DIRMODE_FILE))) continue; ents[n++] = *src; } *count = n; return RES_OK; }
- if (!h->d) { *count = 0; return RES_OK; } // an archive directory that turned out empty (no snapshot, no host DIR)
int dfd = dirfd(h->d);
while (n < max && (e = readdir(h->d))) {
if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) continue;
diff --git a/dm/host/romfs_arc.c b/dm/host/romfs_arc.c
deleted file mode 100644
index d76681d1..00000000
--- a/dm/host/romfs_arc.c
+++ /dev/null
@@ -1,228 +0,0 @@
-// RomFS archive reader: see romfs_arc.h for the on-disk format.
-#include "romfs_arc.h"
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <pthread.h>
-
-typedef struct {
- uint32_t name_off, shard;
- uint64_t off, size;
- uint32_t mode, res;
-} filerec;
-
-typedef struct {
- uint32_t name_off, first_child, child_count, res;
-} dirrec;
-
-static struct {
- int open;
- void *idx; // mmap of the index file
- size_t idx_size;
- romfsarc_hdr hdr;
- const char *pool;
- const filerec *files;
- const dirrec *dirs;
- const uint32_t *children;
- char base[1024];
- int shard_fd[256];
- char shard_path[256][1024];
- pthread_mutex_t lock;
-} A = { .shard_fd = { [0 ... 255] = -1 }, .lock = PTHREAD_MUTEX_INITIALIZER };
-
-static uint64_t rd64(const void *p) { uint64_t v; memcpy(&v, p, 8); return v; }
-static uint32_t rd32(const void *p) { uint32_t v; memcpy(&v, p, 4); return v; }
-
-char g_arc_base[1024]; // the archive's base path, matched against mount directories by hle_fs.c
-
-static const char *fname(const filerec *f) { return A.pool + f->name_off; }
-static const char *dname(const dirrec *d) { return A.pool + d->name_off; }
-
-// Binary search the file table by path. Returns the record or NULL.
-static const filerec *find_file(const char *rel) {
- uint64_t lo = 0, hi = A.hdr.file_count;
- while (lo < hi) {
- uint64_t mid = lo + (hi - lo) / 2;
- int c = strcmp(fname(&A.files[mid]), rel);
- if (c == 0) return &A.files[mid];
- if (c < 0) lo = mid + 1; else hi = mid;
- }
- return NULL;
-}
-
-// 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;
- int c = strcmp(dname(&A.dirs[mid]), rel);
- if (c == 0) return &A.dirs[mid];
- if (c < 0) lo = mid + 1; else hi = mid;
- }
- return NULL;
-}
-
-// Open and validate one index file. Returns the mapping (and its size) or MAP_FAILED.
-static void *map_index(const char *path, size_t *size) {
- int fd = open(path, O_RDONLY);
- if (fd < 0) return MAP_FAILED;
- struct stat st;
- if (fstat(fd, &st)) { close(fd); errno = EIO; return MAP_FAILED; }
- if ((size_t)st.st_size < ROMFSARC_HDR) { close(fd); errno = EINVAL; return MAP_FAILED; }
- void *m = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- close(fd);
- if (m == MAP_FAILED) return MAP_FAILED;
- const uint8_t *b = m;
- if (memcmp(b, ROMFSARC_MAGIC, 8) || rd32(b + 8) != ROMFSARC_VERSION) {
- munmap(m, (size_t)st.st_size); errno = EINVAL; return MAP_FAILED;
- }
- *size = (size_t)st.st_size;
- return m;
-}
-
-int romfsarc_open(const char *base, romfsarc_hdr *out) {
- // The base is where the shards live, without the ".idx". Callers pass either the base itself
- // (DM_ROMFS=/games/totk/romfs with romfs.idx beside it) or a directory that holds the archive
- // (DM_ROMFS=Documents/romfs with Documents/romfs/romfs.idx inside, which is what the iOS app
- // sets). Try both, and a base that already carries the .idx suffix.
- char cand[4][1200];
- char stripped[1200];
- strlcpy(stripped, base, sizeof stripped);
- size_t sl = strlen(stripped);
- if (sl > 4 && !strcmp(stripped + sl - 4, ".idx")) stripped[sl - 4] = 0;
- snprintf(cand[0], sizeof cand[0], "%s.idx", stripped); // <base>.idx
- snprintf(cand[1], sizeof cand[1], "%s/romfs.idx", stripped); // <base>/romfs.idx
- snprintf(cand[2], sizeof cand[2], "%s/romfs/romfs.idx", stripped); // one more level (a bundle-style layout)
- cand[3][0] = 0;
- void *m = MAP_FAILED; size_t sz = 0; char used[1200] = "";
- for (int i = 0; i < 3; i++) {
- m = map_index(cand[i], &sz);
- if (m != MAP_FAILED) { strlcpy(used, cand[i], sizeof used); break; }
- }
- if (m == MAP_FAILED) return -1;
- // The resolved base is the index path minus ".idx": shard paths are built from it
- size_t ul = strlen(used); if (ul > 4) used[ul - 4] = 0;
- const uint8_t *b = m;
- romfsarc_hdr h;
- h.shard_count = rd32(b + 12);
- h.file_count = rd64(b + 24);
- h.dir_count = rd64(b + 32);
- h.tree_hash = rd64(b + 56);
- if (h.shard_count == 0 || h.shard_count > 256) { munmap(m, sz); errno = EINVAL; return -1; }
- uint64_t pool_sz = rd64(b + 40);
- uint64_t need = ROMFSARC_HDR + pool_sz + h.file_count * ROMFSARC_FILEREC + h.dir_count * ROMFSARC_DIRREC;
- // The child list follows the directory table; its length is implied by the last directory's range,
- // so the file only has to be at least as long as the three tables above.
- if (need > (uint64_t)sz) { munmap(m, sz); errno = EINVAL; return -1; }
- pthread_mutex_lock(&A.lock);
- A.open = 1; A.idx = m; A.idx_size = sz; A.hdr = h;
- A.pool = (const char *)(b + ROMFSARC_HDR);
- A.files = (const filerec *)(b + ROMFSARC_HDR + pool_sz);
- A.dirs = (const dirrec *)((const uint8_t *)A.files + h.file_count * ROMFSARC_FILEREC);
- A.children = (const uint32_t *)((const uint8_t *)A.dirs + h.dir_count * ROMFSARC_DIRREC);
- for (int i = 0; i < 256; i++) { A.shard_fd[i] = -1; A.shard_path[i][0] = 0; }
- // Shards are named after the index file's own base, so <dir>/romfs.idx pairs with <dir>/romfs.00
- strlcpy(A.base, used, sizeof A.base);
- strlcpy(g_arc_base, used, sizeof g_arc_base);
- pthread_mutex_unlock(&A.lock);
- if (out) *out = h;
- return 0;
-}
-
-int romfsarc_active(void) { return A.open; }
-
-int romfsarc_stat_file(const char *rel, uint32_t *shard, uint64_t *off, uint64_t *size) {
- if (!A.open) return 0;
- const filerec *f = find_file(rel);
- if (!f) return 0;
- if (shard) *shard = f->shard;
- if (off) *off = f->off;
- if (size) *size = f->size;
- return 1;
-}
-
-int romfsarc_is_dir(const char *rel) {
- if (!A.open) return 0;
- return find_dir(rel) != NULL;
-}
-
-static int shard_fd(uint32_t i) {
- if (i >= A.hdr.shard_count) { errno = EINVAL; return -1; }
- if (A.shard_fd[i] >= 0) return A.shard_fd[i];
- pthread_mutex_lock(&A.lock);
- if (A.shard_fd[i] < 0) {
- char p[1024];
- if (snprintf(p, sizeof p, "%s.%02u", A.base, i) < (int)sizeof p) {
- int fd = open(p, O_RDONLY);
- if (fd >= 0) { A.shard_fd[i] = fd; strlcpy(A.shard_path[i], p, sizeof A.shard_path[i]); }
- }
- }
- int fd = A.shard_fd[i];
- pthread_mutex_unlock(&A.lock);
- return fd;
-}
-
-ssize_t romfsarc_pread(uint32_t shard, uint64_t off, void *buf, size_t n) {
- int fd = shard_fd(shard);
- if (fd < 0) return -1;
- size_t done = 0;
- while (done < n) {
- ssize_t r = pread(fd, (uint8_t *)buf + done, n - done, (off_t)(off + done));
- if (r < 0) { if (errno == EINTR) continue; return -1; }
- if (r == 0) break;
- done += (size_t)r;
- }
- return (ssize_t)done;
-}
-
-int romfsarc_list(const char *rel, romfsarc_ent *out, int max) {
- if (!A.open) return -1;
- const dirrec *d = find_dir(rel);
- if (!d) return -1;
- int n = 0;
- for (uint32_t i = 0; i < d->child_count && n < max; i++) {
- uint32_t tag = A.children[d->first_child + i];
- romfsarc_ent *e = &out[n];
- if (tag & ROMFSARC_CHILD_DIR) {
- const dirrec *c = &A.dirs[tag & ~ROMFSARC_CHILD_DIR];
- // The directory table stores full paths; a child list entry carries only the leaf name
- const char *full = dname(c), *leaf = strrchr(full, '/');
- strlcpy(e->name, leaf ? leaf + 1 : full, sizeof e->name);
- e->is_dir = 1; e->size = 0;
- } else {
- const filerec *c = &A.files[tag];
- // The file table stores full paths; a child list entry carries only the leaf name
- const char *full = fname(c), *leaf = strrchr(full, '/');
- strlcpy(e->name, leaf ? leaf + 1 : full, sizeof e->name);
- e->is_dir = 0; e->size = (int64_t)c->size;
- }
- n++;
- }
- return n;
-}
-
-int romfsarc_count(const char *rel) {
- if (!A.open) return -1;
- const dirrec *d = find_dir(rel);
- return d ? (int)d->child_count : -1;
-}
-
-void romfsarc_close(void) {
- pthread_mutex_lock(&A.lock);
- for (int i = 0; i < 256; i++) if (A.shard_fd[i] >= 0) { close(A.shard_fd[i]); A.shard_fd[i] = -1; }
- if (A.idx) { munmap(A.idx, A.idx_size); A.idx = NULL; }
- A.open = 0;
- pthread_mutex_unlock(&A.lock);
-}
diff --git a/dm/host/romfs_arc.h b/dm/host/romfs_arc.h
deleted file mode 100644
index c4a25b48..00000000
--- a/dm/host/romfs_arc.h
+++ /dev/null
@@ -1,100 +0,0 @@
-// RomFS archive (ROMFSARC): a whole RomFS tree in one index file plus a few hundred shard files.
-//
-// Why: a RomFS like Tears of the Kingdom's is 300,000 files. Copying that into an App's Documents
-// takes hours over the Files app / Finder, and a 16 GB IPA with that many entries does not install
-// (PackageExtractionFailed). Packing the tree into ~100 shard files makes both a single copy.
-//
-// Layout (all integers little-endian):
-// <base>.idx header, name pool, file table, directory table
-// <base>.<NN> shard NN: the files' bytes back to back, in file-table order
-//
-// Header (64 bytes):
-// 0x00 char magic[8] "ROMFSARC"
-// 0x08 uint32 version 1
-// 0x0c uint32 shard_count
-// 0x10 uint64 index_size size of this index file
-// 0x18 uint64 file_count
-// 0x20 uint64 dir_count
-// 0x28 uint64 name_pool_size
-// 0x30 uint64 reserved
-// 0x38 uint64 tree_hash FNV-1a over (path, size) of every file, sorted: a cheap identity check
-//
-// File table: file_count records of 32 bytes, sorted by path (the name pool offset points at the
-// NUL-terminated relative path, '/'-separated, no leading slash):
-// 0x00 uint32 name_off
-// 0x04 uint32 shard
-// 0x08 uint64 offset_in_shard
-// 0x10 uint64 size
-// 0x18 uint32 mode 0777 bits (the executable bit matters for nothing in RomFS, kept for fidelity)
-// 0x1c uint32 reserved
-//
-// Directory table: dir_count records of 16 bytes, sorted by path ("" = the root):
-// 0x00 uint32 name_off
-// 0x04 uint32 first_child index into the child list
-// 0x08 uint32 child_count
-// 0x0c uint32 reserved
-// Child list: uint32 file-table / directory-table indices, each tagged: bit 31 set = a directory.
-// Children of one directory are contiguous and sorted by name.
-//
-// Path lookup is a binary search over the sorted tables; directory listing walks one child range.
-// Case sensitivity: Horizon paths are case-sensitive and the archive is built from a case-sensitive
-// walk, so the host looks names up exactly (the existing dir_index/case-alias machinery is not used
-// for archive mounts).
-#ifndef DM_ROMFS_ARC_H
-#define DM_ROMFS_ARC_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#define ROMFSARC_MAGIC "ROMFSARC"
-#define ROMFSARC_VERSION 1u
-#define ROMFSARC_HDR 64
-#define ROMFSARC_FILEREC 32
-#define ROMFSARC_DIRREC 16
-#define ROMFSARC_CHILD_DIR 0x80000000u
-
-// Synthetic host path prefix for archive-backed entries (see host_path_ex in hle_fs.c). A path that
-// starts with this marker is not a real file: the fs layer routes it to the archive instead.
-#define ROMFSARC_SYNTH_PREFIX "@romfsarc:"
-#define ROMFSARC_IS_SYNTH(p) (!strncmp((p), ROMFSARC_SYNTH_PREFIX, sizeof ROMFSARC_SYNTH_PREFIX - 1))
-#define ROMFSARC_SYNTH_REL(p) ((p) + sizeof ROMFSARC_SYNTH_PREFIX - 1)
-
-typedef struct {
- uint32_t shard_count;
- uint64_t file_count, dir_count;
- uint64_t tree_hash;
-} romfsarc_hdr;
-
-// Open the index at <base>.idx. Returns 0 on success, -1 with errno set on failure.
-// Keeps the index mapped; shards are opened lazily and cached.
-int romfsarc_open(const char *base, romfsarc_hdr *out);
-
-// Whether an archive is open (the fs layer then routes lookups here instead of the host tree).
-int romfsarc_active(void);
-
-// The base path the archive was opened from (without ".idx"): the fs layer matches mount
-// directories against it, so the mount name ("rom", "content", …) does not matter.
-extern char g_arc_base[];
-
-// Resolve a guest path (no leading slash, "" = root) to a file. On success fills the shard index,
-// offset and size; returns 1. Returns 0 when the path is not a file (missing or a directory).
-int romfsarc_stat_file(const char *rel, uint32_t *shard, uint64_t *off, uint64_t *size);
-
-// Whether the path names a directory ("" = root): 1 yes, 0 no.
-int romfsarc_is_dir(const char *rel);
-
-// Read from an open archive file. Same semantics as pread.
-ssize_t romfsarc_pread(uint32_t shard, uint64_t off, void *buf, size_t n);
-
-// Directory listing: write the entries of directory <rel> ("" = root) into the caller's array.
-// Each entry gets its name and type; files also get their size. Returns the number written, or -1.
-typedef struct { char name[0x301]; int is_dir; int64_t size; } romfsarc_ent;
-int romfsarc_list(const char *rel, romfsarc_ent *out, int max);
-
-// Number of entries in a directory (unfiltered), or -1.
-int romfsarc_count(const char *rel);
-
-void romfsarc_close(void);
-
-#endif
diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile
index 295a2583..89904bc7 100644
--- a/dm/host/tests/Makefile
+++ b/dm/host/tests/Makefile
@@ -12,7 +12,6 @@ QUIET = $(if $(strip $(SAN)),,2>/dev/null)
GINC = $(if $(strip $(GAME)),-I../gen/$(GAME) -I../../games/$(GAME),$(error GAME is not set: make GAME=<base game title ID>: $(shell python3 ../../games/game.py list | awk -F'\t' '{printf "%s (%s) ", $$1, $$3}')))
$(B)/t_fs $(B)/t_fs_case $(B)/t_fs_commit_list $(B)/t_fs_commit_list_tsan: ../romfs_image.h
GAME_H = ../gen/$(GAME)/game_profile.h
-run: $(B)/t_touchpad_geometry
run: $(B)/t_language $(B)/t_motion $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_commit_list $(B)/t_thread_leak $(B)/t_fs_case $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_condvar $(B)/t_condvar_old $(B)/t_pctl $(B)/t_time $(B)/t_shared_font $(B)/t_vorbis $(B)/t_vorbis_divides $(B)/t_hid $(B)/t_input_map $(B)/t_launcher_contract $(B)/t_haptics $(B)/t_haptics_apple
$(B)/t_language
$(B)/t_heap_size
@@ -51,7 +50,6 @@ run: $(B)/t_language $(B)/t_motion $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture
$(B)/t_launcher_contract
$(B)/t_haptics
$(B)/t_haptics_apple
- $(B)/t_touchpad_geometry
$(B)/t_nro
$(B)/t_symbols
run: $(B)/t_nro
@@ -98,20 +96,20 @@ $(B)/t_gesture: t_gesture.c ../hle_touch.c ../front.h ../dm.h $(GAME_H) | $(B)
$(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_gesture.c ../hle_touch.c
$(B)/t_thread_leak: t_thread_leak.c ../thread.c ../dm.h $(GAME_H) | $(B)
$(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_thread_leak.c
-$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
-$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
- $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
+$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
+$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
$(B)/t_fs_commit_list_tsan: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) | $(B)
$(CLANG) -O1 -g -fsanitize=thread -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
.PHONY: fs-tsan
fs-tsan: $(B)/t_fs_commit_list_tsan
TMPDIR="$(abspath $(B))" $(B)/t_fs_commit_list_tsan
-$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
+$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
run: $(B)/t_save_sync
-$(B)/t_save_sync: t_save_sync.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
- $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_save_sync.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
+$(B)/t_save_sync: t_save_sync.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_save_sync.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
.PHONY: save-sync
save-sync: $(B)/t_save_sync
TMPDIR="$(abspath $(B))" $(B)/t_save_sync $(QUIET)
@@ -160,8 +158,6 @@ $(B)/t_hid_tsan: t_hid.c ../hle_hid.c ../motion_fusion.h ../hle_haptics.c ../hle
$(CLANG) -O1 -g -fsanitize=thread -Wall -Werror -Wno-unused-function -I.. $(GINC) -o $@ t_hid.c ../hle_haptics.c
$(B)/t_haptics: t_haptics.c ../hle_haptics.c ../hle_haptics.h ../dm_input.h | $(B)
$(CLANG) -O1 -g -Wall -Werror -I.. -o $@ t_haptics.c ../hle_haptics.c
-$(B)/t_touchpad_geometry: t_touchpad_geometry.c ../touchpad_geometry.h ../dm_input.h | $(B)
- $(CLANG) -O1 -Wall -I.. $(GINC) -o $@ t_touchpad_geometry.c
$(B)/t_haptics_apple: t_haptics_apple.m ../haptics_apple.m ../haptics_apple.h ../hle_haptics.c ../hle_haptics.h | $(B)
$(CLANG) -O1 -g -fobjc-arc -Wall -Werror -I.. -o $@ t_haptics_apple.m ../hle_haptics.c -framework Cocoa -framework GameController -framework CoreHaptics -framework IOKit
$(B)/t_time: t_time.c ../hle_time.c ../hle.h ../dm.h $(GAME_H) | $(B)
diff --git a/dm/host/tests/t_romfs_arc.c b/dm/host/tests/t_romfs_arc.c
deleted file mode 100644
index 3f675332..00000000
--- a/dm/host/tests/t_romfs_arc.c
+++ /dev/null
@@ -1,87 +0,0 @@
-// Test romfs_arc.c against a packed archive: path lookup, partial reads, directory listing.
-// Build: clang -I dm/host -o /tmp/t_romfs_arc dm/host/tests/t_romfs_arc.c dm/host/romfs_arc.c
-#include "romfs_arc.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-static int fails;
-#define CHECK(cond, ...) do { if (!(cond)) { printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); fails++; } } while (0)
-
-int main(int argc, char **argv) {
- if (argc < 2) { printf("usage: %s <base>\n", argv[0]); return 2; }
- romfsarc_hdr h;
- if (romfsarc_open(argv[1], &h)) { perror("romfsarc_open"); return 2; }
- printf("opened: %llu files, %llu dirs, %u shards, hash %016llx\n",
- (unsigned long long)h.file_count, (unsigned long long)h.dir_count, h.shard_count,
- (unsigned long long)h.tree_hash);
- CHECK(romfsarc_active(), "active after open");
- CHECK(h.file_count > 0 && h.dir_count > 0 && h.shard_count > 0, "header counts");
-
- // Every file: stat it, read it whole, and read it in two halves at an offset
- romfsarc_ent *ents = calloc(4096, sizeof *ents);
- char path[1024] = "";
- int listed = romfsarc_list("", ents, 4096);
- CHECK(listed > 0, "root has entries, got %d", listed);
- CHECK(listed == romfsarc_count(""), "list and count agree at the root: %d vs %d", listed, romfsarc_count(""));
-
- // Walk the tree breadth first and check every file's bytes against a direct read of its shard
- size_t dcap = 1024;
- char **dirs = calloc(dcap, sizeof *dirs);
- int nd = 0;
- dirs[nd++] = strdup("");
- int checked = 0;
- while (nd) {
- char *d = dirs[--nd];
- int n = romfsarc_count(d);
- CHECK(n >= 0, "count of '%s'", d);
- romfsarc_ent *e = calloc((size_t)(n > 0 ? n : 1), sizeof *e);
- int got = romfsarc_list(d, e, n);
- CHECK(got == n, "list '%s': %d vs %d", d, got, n);
- for (int i = 0; i < got; i++) {
- char rel[1024];
- snprintf(rel, sizeof rel, "%s%s%s", d, *d ? "/" : "", e[i].name);
- 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 {
- uint32_t shard; uint64_t off, size;
- CHECK(romfsarc_stat_file(rel, &shard, &off, &size), "stat '%s'", rel);
- CHECK((int64_t)size == e[i].size, "size '%s': %llu vs %lld", rel,
- (unsigned long long)size, (long long)e[i].size);
- char *buf = malloc(size ? size : 1);
- ssize_t r = romfsarc_pread(shard, off, buf, size);
- CHECK(r == (ssize_t)size, "read '%s': %zd vs %llu", rel, r, (unsigned long long)size);
- // A read past this file's end lands in the next file's bytes: the archive is a flat
- // container, so the reader must not fabricate zeros. The fs layer clamps to the file
- // size (see h_fs_ReadFile), so this only checks the reader does not fail outright.
- char extra[16];
- ssize_t r2 = romfsarc_pread(shard, off + size, extra, sizeof extra);
- CHECK(r2 >= 0, "read past end of '%s' errored: %zd", rel, r2);
- free(buf);
- checked++;
- }
- }
- free(e);
- }
- CHECK(checked == (int)h.file_count, "walked %d files, header says %llu", checked, (unsigned long long)h.file_count);
-
- // Missing paths
- CHECK(!romfsarc_stat_file("nope/nothing", NULL, NULL, NULL), "missing file is not found");
- CHECK(!romfsarc_is_dir("nope"), "missing dir is not a dir");
- CHECK(romfsarc_list("nope", ents, 4) < 0, "list of a missing dir fails");
-
- // Root itself is a directory, and the empty path is not a file
- CHECK(romfsarc_is_dir(""), "root is a dir");
- CHECK(!romfsarc_stat_file("", NULL, NULL, NULL), "root is not a file");
-
- romfsarc_close();
- CHECK(!romfsarc_active(), "closed");
- free(ents);
- printf(fails ? "%d FAILURES\n" : "all checks passed (%d files)\n", fails ? fails : checked);
- return fails ? 1 : 0;
-}
diff --git a/dm/host/tests/t_touchpad_geometry.c b/dm/host/tests/t_touchpad_geometry.c
deleted file mode 100644
index bad6c625..00000000
--- a/dm/host/tests/t_touchpad_geometry.c
+++ /dev/null
@@ -1,131 +0,0 @@
-#include "../touchpad_geometry.h"
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-
-static void nearf(float actual, float expected, float tolerance) {
- assert(fabsf(actual - expected) <= tolerance);
-}
-
-static void test_layout(float width, float height, float expected_u) {
- float u = dm_touchpad_u(height);
- nearf(u, expected_u, 0.0001f);
-
- dm_touchpad_point face = dm_touchpad_face_center(width, height, 0, 0, 0, 0);
- dm_touchpad_point stick = dm_touchpad_stick_home(width, height, 0, 0, 0, 0);
- dm_touchpad_point dpad = dm_touchpad_dpad_center(width, height, 0, 0, 0, 0);
- nearf(face.x, width - DM_TP_FACE_X * u, 0.001f);
- nearf(face.y, height - DM_TP_PAD_Y * u, 0.001f);
- nearf(stick.x, DM_TP_STICK_X * u, 0.001f);
- nearf(stick.y, height - DM_TP_PAD_Y * u, 0.001f);
- nearf(dpad.x, DM_TP_LOW_X * u, 0.001f);
- nearf(dpad.y, height - DM_TP_LOW_Y * u, 0.001f);
-
- dm_touchpad_point a = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 0);
- dm_touchpad_point b = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 1);
- dm_touchpad_point x = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 2);
- dm_touchpad_point y = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 3);
- float gap = DM_TP_FACE_GAP * u;
- nearf(a.x - face.x, gap, 0.001f); nearf(a.y, face.y, 0.001f);
- nearf(b.y - face.y, gap, 0.001f); nearf(b.x, face.x, 0.001f);
- nearf(x.y - face.y, -gap, 0.001f); nearf(x.x, face.x, 0.001f);
- nearf(y.x - face.x, -gap, 0.001f); nearf(y.y, face.y, 0.001f);
-}
-
-static void test_directional_ownership(void) {
- const float cx = 400, cy = 300, gap = 50, radius = 33.75f;
- assert(dm_touchpad_face_buttons(cx + gap, cy, cx, cy, gap, radius) & DM_BTN_A);
- assert(dm_touchpad_face_buttons(cx, cy + gap, cx, cy, gap, radius) & DM_BTN_B);
- assert(dm_touchpad_face_buttons(cx, cy - gap, cx, cy, gap, radius) & DM_BTN_X);
- assert(dm_touchpad_face_buttons(cx - gap, cy, cx, cy, gap, radius) & DM_BTN_Y);
-
- const float r = 48;
- assert(dm_touchpad_dpad_buttons(cx + r, cy, cx, cy, r) == DM_BTN_RIGHT);
- assert(dm_touchpad_dpad_buttons(cx, cy - r, cx, cy, r) == DM_BTN_UP);
- assert(dm_touchpad_dpad_buttons(cx - r, cy, cx, cy, r) == DM_BTN_LEFT);
- assert(dm_touchpad_dpad_buttons(cx, cy + r, cx, cy, r) == DM_BTN_DOWN);
- assert(dm_touchpad_dpad_buttons(cx + r, cy - r, cx, cy, r) == (DM_BTN_RIGHT | DM_BTN_UP));
- assert(dm_touchpad_dpad_buttons(cx, cy, cx, cy, r) == 0); // native centre dead region
-}
-
-static void test_stick_shaping(void) {
- const float r = 77;
- int32_t x, y;
- dm_touchpad_stick_axis(r * 0.05f, 0, r, 0, &x, &y);
- assert(x == 0 && y == 0); // dead zone
-
- dm_touchpad_stick_axis(r * 0.45f, 0, r, 0, &x, &y);
- assert(x >= 16383 && x <= 16384 && y == 0); // half of full travel after dead-zone remap
-
- dm_touchpad_stick_axis(0, -r, r, 0, &x, &y);
- assert(x == 0 && y == DM_STICK_MAX);
- dm_touchpad_stick_axis(-r, 0, r, 0, &x, &y);
- assert(x == -DM_STICK_MAX && y == 0);
-
- dm_touchpad_stick_axis(r * 0.1f, 0, r, 1, &x, &y);
- assert(x == DM_STICK_MAX && y == 0); // legacy full-tilt right-stick mode
-}
-
-static void test_safe_insets_and_resize(void) {
- dm_touchpad_rect safe = dm_touchpad_safe_rect(844, 390, 42, 0, 42, 21);
- nearf(safe.x, 42, 0.001f); nearf(safe.y, 0, 0.001f);
- nearf(safe.width, 760, 0.001f); nearf(safe.height, 369, 0.001f);
-
- dm_touchpad_rect corner = dm_touchpad_corner_rect(844, 390, 42, 0, 42, 21);
- nearf(corner.x, 21, 0.001f); nearf(corner.width, 802, 0.001f);
- nearf(corner.height, 369, 0.001f);
- dm_touchpad_point face = dm_touchpad_face_center(844, 390, 42, 0, 42, 21);
- dm_touchpad_point stick = dm_touchpad_stick_home(844, 390, 42, 0, 42, 21);
- float u = 390.0f / 430.0f;
- nearf(face.x, 21 + 802 - DM_TP_FACE_X * u, 0.001f);
- nearf(stick.x, 21 + DM_TP_STICK_X * u, 0.001f);
-
- // 16:9 and 21:10 both cap control size at 1.3; a short resized window scales down.
- test_layout(1920, 1080, 1.3f);
- test_layout(1680, 800, 1.3f);
- test_layout(1280, 430, 1.0f);
-}
-
-static void test_botw_right_cluster_and_camera_tap(void) {
- for (int i = 0; i < 2; i++) {
- float w = i ? 1920.0f : 844.0f, h = i ? 1080.0f : 390.0f;
- float u = dm_touchpad_u(h);
- dm_touchpad_point face = dm_touchpad_face_center(w,h,0,0,0,0);
- dm_touchpad_point r = dm_touchpad_right_shoulder(w,h,0,0,0,0,0);
- dm_touchpad_point zr = dm_touchpad_right_shoulder(w,h,0,0,0,0,1);
- dm_touchpad_point x = dm_touchpad_face_button(w,h,0,0,0,0,2);
- nearf(r.y,zr.y,0.001f);
- nearf(zr.x-r.x,(DM_TP_ZL_R*2+DM_TP_SHOULDER_GAP)*u,0.001f);
- assert(r.y + DM_TP_ZL_R*u < x.y - DM_TP_FACE_R*u);
- assert(zr.x + DM_TP_ZL_R*u < w);
- float xgr = DM_TP_FACE_R * u * 1.25f;
- float shoulder_hit = DM_TP_ZL_R * u * DM_TP_SHOULDER_HIT_SCALE;
- assert(hypotf(r.x-x.x,r.y-x.y) > shoulder_hit+xgr);
- assert(hypotf(zr.x-x.x,zr.y-x.y) > shoulder_hit+xgr);
- assert(face.y > 0);
-
- float slop = DM_TP_LOOK_TAP_SLOP*u;
- assert(!dm_touchpad_look_dragged(400,200,400+slop*.5f,200,slop));
- assert(dm_touchpad_look_dragged(400,200,400+slop*1.1f,200,slop));
- // A drag that returns to its start is still classified as a drag by the caller's sticky flag.
- int dragged = dm_touchpad_look_dragged(400,200,400+slop*1.1f,200,slop);
- assert(dragged);
- assert(dm_touchpad_look_tap(.2f,0));
- assert(!dm_touchpad_look_tap(.36f,0));
- assert(!dm_touchpad_look_tap(.1f,1));
- assert(dm_touchpad_look_double_tap(10000000.08,10000000.28,100,100,101,102,u));
- assert(!dm_touchpad_look_double_tap(10000000.08,10000000.48,100,100,101,102,u));
- assert(!dm_touchpad_look_double_tap(10000000.08,10000000.28,100,100,100+49*u,102,u));
- dragged |= dm_touchpad_look_dragged(400,200,400,200,slop);
- assert(dragged);
- }
-}
-
-int main(void) {
- test_directional_ownership();
- test_stick_shaping();
- test_safe_insets_and_resize();
- test_botw_right_cluster_and_camera_tap();
- puts("touchpad geometry: direction ownership, layout, and stick shaping passed");
- return 0;
-}
diff --git a/dm/host/touchpad_geometry.h b/dm/host/touchpad_geometry.h
deleted file mode 100644
index affbb2d1..00000000
--- a/dm/host/touchpad_geometry.h
+++ /dev/null
@@ -1,179 +0,0 @@
-// Shared virtual-pad geometry for the UIKit controls and the opt-in Mac preview.
-#pragma once
-#include <math.h>
-
-typedef struct { float x, y; } dm_touchpad_point;
-typedef struct { float x, y, width, height; } dm_touchpad_rect;
-
-#include "dm_input.h"
-
-#define DM_TP_ZL_X 44.0f
-#define DM_TP_ZL_Y 40.0f
-#define DM_TP_ZL_R 26.0f
-#define DM_TP_L_X 44.0f
-#define DM_TP_L_Y 108.0f
-#define DM_TP_L_R 24.0f
-#define DM_TP_DROP_TIP 1.45f
-#define DM_TP_CORNER_IN 0.5f
-#define DM_TP_FACE_X 81.0f
-#define DM_TP_PAD_Y 82.0f
-#define DM_TP_FACE_GAP 50.0f
-#define DM_TP_FACE_R 27.0f
-#define DM_TP_PILL_DX 52.0f
-#define DM_TP_PILL_Y 22.0f
-#define DM_TP_PILL_W 50.0f
-#define DM_TP_PILL_H 28.0f
-#define DM_TP_SWAP_R 15.0f
-#define DM_TP_STICK_X 81.0f
-#define DM_TP_STICK_R 77.0f
-#define DM_TP_KNOB_R 30.0f
-#define DM_TP_STICK_GRAB 1.4f
-#define DM_TP_LSWIPE (1.0f / 3.0f)
-#define DM_TP_FULL 0.8f
-#define DM_TP_DEAD 0.1f
-#define DM_TP_LOW_X 231.0f
-#define DM_TP_LOW_Y 64.0f
-#define DM_TP_DPAD_R 48.0f
-#define DM_TP_ARM_W 17.0f
-#define DM_TP_ARM_IN 11.0f
-#define DM_TP_DPAD_GRAB 1.3f
-#define DM_TP_RSTICK_R 60.0f
-#define DM_TP_RSWIPE (1.0f / 2.0f)
-#define DM_TP_CLICK_X 102.0f
-#define DM_TP_CLICK_R 17.0f
-#define DM_TP_LOOK_TAP_SLOP 12.0f
-#define DM_TP_LOOK_TAP_MAX_SECONDS 0.35f
-#define DM_TP_LOOK_DOUBLE_TAP_INTERVAL 0.35f
-#define DM_TP_LOOK_DOUBLE_TAP_DISTANCE 48.0f
-#define DM_TP_SHOULDER_GAP 8.0f
-#define DM_TP_SHOULDER_HIT_SCALE 1.0f
-
-static inline float dm_touchpad_u(float height) {
- float u = height / 430.0f;
- return u < 1.3f ? u : 1.3f;
-}
-
-// safe insets and result use top-left coordinates, as UIKit does. AppKit
-// callers convert their bottom-left mouse coordinates at the view boundary.
-static inline dm_touchpad_rect dm_touchpad_corner_rect(float width, float height,
- float left, float top,
- float right, float bottom) {
- return (dm_touchpad_rect){left * .5f, top, width - (left + right) * .5f,
- height - top - bottom};
-}
-
-static inline dm_touchpad_rect dm_touchpad_safe_rect(float width, float height,
- float left, float top,
- float right, float bottom) {
- return (dm_touchpad_rect){left, top, width - left - right, height - top - bottom};
-}
-
-static inline dm_touchpad_point dm_touchpad_face_center(float width, float height,
- float left, float top,
- float right, float bottom) {
- dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);
- float u = dm_touchpad_u(height);
- return (dm_touchpad_point){c.x + c.width - DM_TP_FACE_X * u,
- c.y + c.height - DM_TP_PAD_Y * u};
-}
-
-// R and ZR sit together just above the face cluster on BOTW's virtual pad.
-static inline dm_touchpad_point dm_touchpad_right_shoulder(float width, float height,
- float left, float top,
- float right, float bottom,
- int zr) {
- dm_touchpad_point face = dm_touchpad_face_center(width, height, left, top, right, bottom);
- float u = dm_touchpad_u(height);
- float half = (DM_TP_ZL_R + DM_TP_SHOULDER_GAP * .5f) * u;
- float y = face.y - (DM_TP_FACE_GAP + DM_TP_FACE_R + DM_TP_ZL_R + 18.0f) * u;
- return (dm_touchpad_point){face.x + (zr ? half : -half), y};
-}
-
-static inline int dm_touchpad_look_dragged(float down_x, float down_y,
- float x, float y, float slop) {
- float dx = x - down_x, dy = y - down_y;
- return dx * dx + dy * dy > slop * slop;
-}
-static inline int dm_touchpad_look_tap(float duration, int dragged) {
- return !dragged && duration >= 0.0f && duration <= DM_TP_LOOK_TAP_MAX_SECONDS;
-}
-static inline int dm_touchpad_look_double_tap(double first_time, double second_time,
- float first_x, float first_y,
- float second_x, float second_y,
- float u) {
- float dx = second_x - first_x, dy = second_y - first_y;
- double dt = second_time - first_time;
- float limit = DM_TP_LOOK_DOUBLE_TAP_DISTANCE * u;
- return dt >= 0.0f && dt <= DM_TP_LOOK_DOUBLE_TAP_INTERVAL && dx*dx + dy*dy <= limit*limit;
-}
-
-static inline dm_touchpad_point dm_touchpad_stick_home(float width, float height,
- float left, float top,
- float right, float bottom) {
- dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);
- float u = dm_touchpad_u(height);
- return (dm_touchpad_point){c.x + DM_TP_STICK_X * u,
- c.y + c.height - DM_TP_PAD_Y * u};
-}
-
-static inline dm_touchpad_point dm_touchpad_dpad_center(float width, float height,
- float left, float top,
- float right, float bottom) {
- dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);
- float u = dm_touchpad_u(height);
- return (dm_touchpad_point){c.x + DM_TP_LOW_X * u,
- c.y + c.height - DM_TP_LOW_Y * u};
-}
-
-static inline dm_touchpad_point dm_touchpad_face_button(float width, float height,
- float left, float top,
- float right, float bottom,
- int button) {
- dm_touchpad_point c = dm_touchpad_face_center(width, height, left, top, right, bottom);
- float g = DM_TP_FACE_GAP * dm_touchpad_u(height);
- switch (button) {
- case 0: c.x += g; break; // A
- case 1: c.y += g; break; // B
- case 2: c.y -= g; break; // X
- default: c.x -= g; break; // Y
- }
- return c;
-}
-
-static inline uint64_t dm_touchpad_face_buttons(float x, float y, float center_x,
- float center_y, float gap, float radius) {
- uint64_t bits = 0;
- for (int b = 0; b < 4; b++) {
- dm_touchpad_point c = {center_x, center_y};
- if (b == 0) c.x += gap;
- else if (b == 1) c.y += gap;
- else if (b == 2) c.y -= gap;
- else c.x -= gap;
- float dx = x - c.x, dy = y - c.y;
- if (dx * dx + dy * dy <= radius * radius) bits |= 1ull << b;
- }
- return bits;
-}
-
-static inline uint64_t dm_touchpad_dpad_buttons(float x, float y, float center_x,
- float center_y, float radius) {
- float dx = x - center_x, dy = y - center_y;
- if (hypotf(dx, dy) < radius * .25f) return 0;
- float a = atan2f(-dy, dx) * (180.0f / 3.14159265358979323846f);
- uint64_t bits = 0;
- if (a > -67.5f && a < 67.5f) bits |= DM_BTN_RIGHT;
- if (a > 22.5f && a < 157.5f) bits |= DM_BTN_UP;
- if (a > 112.5f || a < -112.5f) bits |= DM_BTN_LEFT;
- if (a < -22.5f && a > -157.5f) bits |= DM_BTN_DOWN;
- return bits;
-}
-
-static inline void dm_touchpad_stick_axis(float dx, float dy, float radius,
- int full_tilt, int32_t *x, int32_t *y) {
- float d = hypotf(dx, dy), dead = radius * DM_TP_DEAD;
- if (d <= (full_tilt ? 0.0f : dead) || radius <= 0.0f) { *x = *y = 0; return; }
- float magnitude = (full_tilt ? 1.0f : fminf((d - dead) / (radius * DM_TP_FULL - dead), 1.0f)) / d;
- *x = (int32_t)lrintf(dx * magnitude * DM_STICK_MAX);
- *y = (int32_t)lrintf(-dy * magnitude * DM_STICK_MAX);
-}
-
diff --git a/dm/ios/Sources/DmIOS-Bridging-Header.h b/dm/ios/Sources/DmIOS-Bridging-Header.h
index 92a2b3a5..161a40de 100644
--- a/dm/ios/Sources/DmIOS-Bridging-Header.h
+++ b/dm/ios/Sources/DmIOS-Bridging-Header.h
@@ -1,3 +1,7 @@
// What Swift sees of the app's Objective-C: the data bookmark the Files app hands out (see
// DataBookmark.h). project.yml points SWIFT_OBJC_BRIDGING_HEADER here.
#import "DataBookmark.h"
+
+// main.m: set when the game data found is an old shard archive (romfs.idx), which is no longer read. The sentence names the
+// action (re-send the game data as romfs.img from the launcher), or NULL. The launcher's Game data section shows it.
+const char *dm_old_archive_message(void);
diff --git a/dm/ios/Sources/Launcher.swift b/dm/ios/Sources/Launcher.swift
index 53ad595c..d62e5c1c 100644
--- a/dm/ios/Sources/Launcher.swift
+++ b/dm/ios/Sources/Launcher.swift
@@ -61,6 +61,8 @@ private struct GameDataSection: View {
picked = dm_picked_data_path(&stale) ?? ""
if stale.boolValue && picked.isEmpty {
note = "The location you picked before is no longer readable (the app was signed differently). Please choose it again."
+ } else if note.isEmpty, let old = dm_old_archive_message() {
+ note = String(cString: old)
}
}
}
diff --git a/dm/ios/Sources/main.m b/dm/ios/Sources/main.m
index c4c84e5d..bec90271 100644
--- a/dm/ios/Sources/main.m
+++ b/dm/ios/Sources/main.m
@@ -41,22 +41,29 @@ static int romfs_identity_accepts(NSString *img) {
if (rc != ROMFS_ID_OK && rc != ROMFS_ID_NONE) fprintf(stderr, "[RED] boot: Documents/romfs.img is not the image this build needs (verdict %d); not used\n", rc);
return rc == ROMFS_ID_OK || rc == ROMFS_ID_NONE;
}
-// A folder holds this game's files if it has a ROMFSARC index or the profile's marker path.
+// Set when a folder holds an old shard archive (romfs.idx): the launcher's Game data section shows it.
+static char g_old_archive[200];
+const char *dm_old_archive_message(void) { return g_old_archive[0] ? g_old_archive : NULL; }
+// A folder holds this game's files if it has the profile's marker path.
// Shared by romfs_locate and the per-game layout below, so both answer the same question.
static BOOL romfs_dir_ok(NSString *d) {
NSFileManager *fm = NSFileManager.defaultManager;
- // A ROMFSARC archive: <dir>/romfs.idx next to romfs.NN shards. The host opens it when DM_ROMFS
- // points at the base; the marker check does not apply (there are no directories to walk).
- if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@"romfs.idx"]]) return YES;
// A plain directory tree: only one containing the game profile's romfs_marker path counts
// (Mario: System/Resource, the resource size table). Runtime profile: the marker is a profile
// value now; the compiled macro is only what dm_profile() falls back to without DM_PROFILE.
- return [fm fileExistsAtPath:[d stringByAppendingPathComponent:@(dm_profile()->romfs_marker)]];
+ if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@(dm_profile()->romfs_marker)]]) return YES;
+ // ROMFSARC shard archives (<dir>/romfs.idx next to romfs.NN) are no longer read: the folder is
+ // reported as holding no game data, and the log and the launcher's Game data section name the action.
+ if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@"romfs.idx"]]) {
+ snprintf(g_old_archive, sizeof g_old_archive, "The game data here is an old shard archive (romfs.idx), which this version no longer reads. Re-send the game data as romfs.img from the launcher.");
+ fprintf(stderr, "boot: %s holds an old RomFS shard archive (romfs.idx), which is no longer read. Re-send the game data as romfs.img from the launcher\n", d.fileSystemRepresentation);
+ }
+ return NO;
}
// Where one game's data lives under the per-game layout: Documents/games/<title ID>/, holding
// romfs.img the whole RomFS as one image file (what scripts/push_romfs.sh sends), or
-// romfs/ a ROMFSARC archive or a plain tree, for copies made before images
+// romfs/ a plain tree, for copies made before images
// msl/ this game's Metal shader libraries (optional; the app's own dm/ is used otherwise)
// save/ temp/ this game's saves and scratch space
// The layout exists so several games can share one installed app and so the game data can sit on
diff --git a/dm/tools/romfs_arc.py b/dm/tools/romfs_arc.py
deleted file mode 100644
index 000cb4c8..00000000
--- a/dm/tools/romfs_arc.py
+++ /dev/null
@@ -1,270 +0,0 @@
-#!/usr/bin/env python3
-"""Pack a RomFS tree into a ROMFSARC archive (one index file + N shard files).
-
-Why: Tears of the Kingdom's RomFS is 304,000 files. Copying that into an App's Documents takes
-hours, and a 16 GB IPA with that many entries fails to install on iOS (PackageExtractionFailed).
-An archive is ~120 files instead, so one copy moves it.
-
-Shard layout: files are grouped by their top-level directory (so one shard holds one kind of
-content), then split so that no shard passes --shard-mib. Files are written in path order within
-a shard; a shard never mixes content from different top-level directories unless that directory
-alone exceeds the limit.
-
-Usage:
- romfs_arc.py pack <romfs dir> <output base> [--shard-mib 200]
- romfs_arc.py list <base> [path] # debug: list a directory
- romfs_arc.py verify <base> <romfs dir> # compare every file's bytes against the source tree
-
-Format: see dm/host/romfs_arc.h.
-"""
-import argparse
-import collections
-import os
-import struct
-import sys
-
-MAGIC = b"ROMFSARC"
-VERSION = 1
-HDR = 64
-FILEREC = 32
-DIRREC = 16
-CHILD_DIR = 0x80000000
-
-
-def fnv1a(data, h=0xCBF29CE484222325):
- for b in data:
- h = ((h ^ b) * 0x100000001B3) & 0xFFFFFFFFFFFFFFFF
- return h
-
-
-def walk(root):
- """Every file and directory under root, as (relpath, size) / relpath. Relpaths use '/' and have
- no leading slash; the root itself is ''. Symlinks are followed (RomFS has none in the games
- seen so far); anything that is neither a file nor a directory is an error."""
- files, dirs = [], [""]
- for dp, dn, fn in os.walk(root):
- rel_dir = os.path.relpath(dp, root).replace(os.sep, "/")
- if rel_dir == ".":
- rel_dir = ""
- dn.sort()
- for d in dn:
- dirs.append(f"{rel_dir}/{d}" if rel_dir else d)
- for f in sorted(fn):
- p = os.path.join(dp, f)
- try:
- st = os.stat(p)
- except OSError as e:
- sys.exit(f"[RED] cannot stat {p}: {e}")
- files.append((f"{rel_dir}/{f}" if rel_dir else f, st.st_size))
- files.sort(key=lambda x: x[0])
- dirs.sort()
- return files, dirs
-
-
-def plan_shards(files, shard_bytes):
- """Assign every file a shard. Files are grouped by top-level directory, keeping the walk order
- (path order) inside a group; a group is cut into shards of at most shard_bytes."""
- by_top = collections.OrderedDict()
- for rel, size in files:
- top = rel.split("/", 1)[0]
- by_top.setdefault(top, []).append((rel, size))
- # Big groups first, so the shard count stays close to the size total / shard_bytes
- order = sorted(by_top.items(), key=lambda kv: -sum(s for _, s in kv[1]))
- assign, shard = {}, 0
- for top, items in order:
- cur = 0
- for rel, size in items:
- if cur and cur + size > shard_bytes:
- shard += 1
- cur = 0
- assign[rel] = (shard, cur)
- cur += size
- shard += 1
- return assign, shard
-
-
-def pack(romfs, base, shard_mib):
- shard_bytes = shard_mib << 20
- files, dirs = walk(romfs)
- total = sum(s for _, s in files)
- print(f"pack: {len(files):,} files, {len(dirs):,} directories, {total / 2**30:.2f} GiB", flush=True)
- assign, nshard = plan_shards(files, shard_bytes)
- print(f"pack: {nshard} shards of at most {shard_mib} MiB", flush=True)
-
- # Shard files: written in path order within each shard
- per_shard = collections.defaultdict(list)
- for rel, size in files:
- per_shard[assign[rel][0]].append((rel, size))
- os.makedirs(os.path.dirname(base) or ".", exist_ok=True)
- written = 0
- for i in range(nshard):
- path = f"{base}.{i:02d}"
- with open(path, "wb") as out:
- for rel, size in sorted(per_shard[i]):
- with open(os.path.join(romfs, rel), "rb") as f:
- left = size
- while left:
- buf = f.read(min(left, 1 << 22))
- if not buf:
- sys.exit(f"[RED] {rel}: file shrank while packing")
- out.write(buf)
- left -= len(buf)
- written += size
- print(f"\r shard {i + 1}/{nshard}: {os.path.getsize(path) / 2**20:.0f} MiB", end="", flush=True)
- print(f"\n wrote {written / 2**30:.2f} GiB in {nshard} shards", flush=True)
-
- # Name pool
- pool = bytearray()
- name_off = {}
-
- def intern(s):
- if s not in name_off:
- name_off[s] = len(pool)
- pool.extend(s.encode("utf-8") + b"\0")
- return name_off[s]
-
- for rel, _ in files:
- intern(rel)
- for d in dirs:
- intern(d)
-
- # File table (sorted by path, same order as `files`)
- file_idx = {}
- ftab = bytearray()
- for n, (rel, size) in enumerate(files):
- file_idx[rel] = n
- shard, off = assign[rel]
- ftab += struct.pack("<IIQQII", intern(rel), shard, off, size, 0o644, 0)
-
- # Directory table + child list. A directory's children are its immediate files and directories,
- # sorted by name, contiguous in the child list.
- dir_idx = {d: n for n, d in enumerate(dirs)}
- children_of = collections.defaultdict(list)
- for rel, _ in files:
- parent, _, name = rel.rpartition("/")
- children_of[parent].append((name, file_idx[rel]))
- for d in dirs:
- for sub in dirs:
- if sub and sub.rpartition("/")[0] == d and sub != d:
- # Only the leaf name goes in the child list; the directory's own path is in its record
- children_of[d].append((sub.rpartition("/")[2], dir_idx[sub] | CHILD_DIR))
-
- dtab = bytearray()
- child_list = []
- for d in dirs:
- kids = sorted(children_of[d])
- first = len(child_list)
- child_list.extend(tag for _, tag in kids)
- dtab += struct.pack("<IIII", intern(d), first, len(kids), 0)
-
- tree = bytearray()
- for rel, size in files:
- tree += f"{rel}\0{size}\0".encode()
- tree_hash = fnv1a(tree)
-
- idx_path = f"{base}.idx"
- with open(idx_path, "wb") as out:
- out.write(struct.pack("<8sIIQQQQQQ", MAGIC, VERSION, nshard, 0, len(files), len(dirs),
- len(pool), 0, tree_hash))
- out.write(pool)
- out.write(ftab)
- out.write(dtab)
- out.write(struct.pack(f"<{len(child_list)}I", *child_list) if child_list else b"")
- print(f"pack: index {os.path.getsize(idx_path) / 2**20:.1f} MiB ({len(pool) / 2**20:.1f} MiB names, "
- f"{len(files):,} files, {len(dirs):,} directories), tree hash {tree_hash:016x}", flush=True)
- print(f"pack: total {nshard + 1} files", flush=True)
-
-
-def load(base):
- with open(f"{base}.idx", "rb") as f:
- b = f.read()
- magic, ver, nshard, _pad, nfiles, ndirs, pool_sz, _r, tree_hash = struct.unpack_from("<8sIIQQQQQQ", b, 0)
- if magic != MAGIC or ver != VERSION:
- sys.exit("[RED] not a ROMFSARC index")
- pool = b[HDR:HDR + pool_sz]
- off = HDR + pool_sz
- files = []
- for i in range(nfiles):
- name_off, shard, foff, size, mode, _ = struct.unpack_from("<IIQQII", b, off + i * FILEREC)
- name = pool[name_off:pool.index(b"\0", name_off)].decode()
- files.append((name, shard, foff, size))
- off += nfiles * FILEREC
- dirs = []
- for i in range(ndirs):
- name_off, first, count, _ = struct.unpack_from("<IIII", b, off + i * DIRREC)
- name = pool[name_off:pool.index(b"\0", name_off)].decode()
- dirs.append((name, first, count))
- off += ndirs * DIRREC
- kids = struct.unpack_from(f"<{len(b) - off >> 2}I", b, off) if len(b) > off else ()
- return dict(nshard=nshard, files=files, dirs=dirs, kids=kids, tree_hash=tree_hash)
-
-
-def cmd_list(base, path):
- a = load(base)
- target = path.strip("/")
- d = next((x for x in a["dirs"] if x[0] == target), None)
- if not d:
- sys.exit(f"[RED] no such directory: {target or '/'}")
- _, first, count = d
- print(f"{target or '/'}: {count} entries")
- for k in a["kids"][first:first + count]:
- if k & CHILD_DIR:
- print(f" d {a['dirs'][k & ~CHILD_DIR][0].rpartition('/')[2]}/")
- else:
- name, shard, off, size = a["files"][k]
- print(f" f {name.rpartition('/')[2]:50} {size:12,} shard {shard:3} off {off:,}")
-
-
-def cmd_verify(base, romfs):
- a = load(base)
- print(f"verify: {len(a['files']):,} files")
- bad = 0
- for n, (rel, shard, off, size) in enumerate(a["files"]):
- src = os.path.join(romfs, rel)
- try:
- with open(src, "rb") as f:
- want = f.read()
- except OSError as e:
- print(f"[RED] missing source {rel}: {e}")
- bad += 1
- continue
- if len(want) != size:
- print(f"[RED] size mismatch {rel}: source {len(want)} archive {size}")
- bad += 1
- continue
- with open(f"{base}.{shard:02d}", "rb") as f:
- f.seek(off)
- got = f.read(size)
- if got != want:
- print(f"[RED] content mismatch {rel}")
- bad += 1
- if (n + 1) % 20000 == 0:
- print(f" {n + 1:,}/{len(a['files']):,}", flush=True)
- print(f"verify: {'OK' if not bad else f'{bad} problems'}")
- return 1 if bad else 0
-
-
-def main():
- ap = argparse.ArgumentParser(description="Pack a RomFS tree into a ROMFSARC archive")
- sub = ap.add_subparsers(dest="cmd", required=True)
- p = sub.add_parser("pack")
- p.add_argument("romfs")
- p.add_argument("base")
- p.add_argument("--shard-mib", type=int, default=200)
- l = sub.add_parser("list")
- l.add_argument("base")
- l.add_argument("path", nargs="?", default="")
- v = sub.add_parser("verify")
- v.add_argument("base")
- v.add_argument("romfs")
- a = ap.parse_args()
- if a.cmd == "pack":
- pack(a.romfs, a.base, a.shard_mib)
- elif a.cmd == "list":
- cmd_list(a.base, a.path)
- else:
- sys.exit(cmd_verify(a.base, a.romfs))
-
-
-if __name__ == "__main__":
- main()
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 35472c99..25ab8a5c 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -7,7 +7,7 @@ week of work. Sources are named so each claim can be re-checked.
## 1. Touch look and native aspect — the one capability we do not have
**From [devinhurry/touch-the-wild](https://github.com/devinhurry/touch-the-wild)** (not in
-upstream's tree: `hle_look.c`, `touchpad_geometry.h`, `hle_botw_touchhud.c`, `hle_aspect.c`
+upstream's tree: `hle_look.c`, `touchpad_geometry.h` (once carried here as an experiment, since dropped), `hle_botw_touchhud.c`, `hle_aspect.c`
all verified absent from seedds/nxnative).
Today the only way to turn the camera on a phone is holding a virtual right stick, which turns
@@ -127,9 +127,8 @@ saves and logs) and enables the runtime-profile work that was already done. Do A
if 4–8 games in one app is worth it, and C needs a `dlopen` experiment before any commitment.
External storage on iOS: `UIDocumentPickerViewController` for the folder, persist a security-
-scoped bookmark in UserDefaults, store the ROMFSARC index and shards there. `romfs_arc.c`
-already `pread`s per shard, so an external path works unchanged —
-`main.m romfs_locate` only checks `Documents/romfs` and `<App>/romfs` today.
+scoped bookmark in UserDefaults, store the picked location there (done: `romfs.img` is read from any
+security-scoped path, `dm_picked_data_path`; the shard-archive reader this note first assumed is gone).
## Safety note from the fork survey
diff --git a/docs/ROMFS_ARCHIVE.md b/docs/ROMFS_ARCHIVE.md
deleted file mode 100644
index 44bc93f2..00000000
--- a/docs/ROMFS_ARCHIVE.md
+++ /dev/null
@@ -1,95 +0,0 @@
-# RomFS archive (ROMFSARC)
-
-A whole RomFS tree packed into one index file plus ~100 shard files, so a game whose RomFS is
-hundreds of thousands of files can be copied to a phone as one folder instead of a directory tree.
-
-## Why
-
-Tears of the Kingdom's RomFS is 304,243 files / 15.9 GiB. Two problems follow:
-
-- **The IPA does not install.** A 16.6 GB IPA with 372,660 entries fails on iOS with
- `PackageExtractionFailed (Could not extract archive)`. The install daemon's extractor gives up:
- one directory holds 75,941 files and the ZIP64 central directory starts at 17.8 GB.
-- **Copying the tree is slow.** The Files app and Finder both do one round trip per file; 304,243
- small files take hours and often break partway.
-
-Packing the tree into 127 files makes the copy one operation of ~16 GB and lets the IPA stay small.
-
-## Using it
-
-### 1. Pack the game files
-
-```bash
-python3 dm/tools/romfs_arc.py pack <RomFS dir> <output base> --shard-mib 200
-```
-
-`<RomFS dir>` is the directory `nx_extract` wrote (the one holding `Pack/`, `Banc/`, `Sound/`, …).
-`<output base>` is a path prefix: the tool writes `<base>.idx` and `<base>.00`, `<base>.01`, ….
-Files are grouped by top-level directory and cut so no shard passes `--shard-mib`, so one shard
-holds one kind of content and no shard is unreasonably large.
-
-For TotK at 200 MiB per shard: 126 shards + 1 index = **127 files**.
-
-### 2. Copy it to the phone
-
-Put the whole set in the app's `Documents/romfs/`, keeping the base name:
-
-```
-Documents/romfs/romfs.idx
-Documents/romfs/romfs.00
-...
-Documents/romfs/romfs.125
-```
-
-The app looks for `romfs.idx` first (`dm/ios/Sources/main.m`, `romfs_locate`); a plain directory
-tree is still accepted when there is no index.
-
-### 3. Build the app without the RomFS
-
-```bash
-DM_NO_ROMFS=1 GAME=<title id> W=... PATCHED=... ROMFS=... MSL_IOS=... \
- dm/ios/tools/build_ipa.sh out.ipa
-```
-
-The package then holds only the app, the shader libraries and the tables (~750 MB for TotK), and
-the game files come from `Documents/romfs/` at run time.
-
-## Checking an archive
-
-```bash
-python3 dm/tools/romfs_arc.py list <base> [path] # list one directory
-python3 dm/tools/romfs_arc.py verify <base> <RomFS> # compare every file's bytes with the source
-```
-
-`verify` reads all 304,243 files of TotK's archive in about a minute and prints `verify: OK`.
-
-## Format
-
-See `dm/host/romfs_arc.h` for the byte layout. In short: a 64-byte header, a NUL-separated name
-pool, a file table sorted by path (32 bytes each), a directory table (16 bytes each) and a child
-list. Path lookup is a binary search; a directory listing walks one contiguous child range.
-
-The reader (`dm/host/romfs_arc.c`) maps the index with `mmap` and opens shards lazily, keeping up
-to 256 descriptors. Reads go straight to `pread` on the shard, so the page cache still works.
-
-## How the fs layer uses it
-
-`hle_fs.c` keeps its normal path handling. When an archive is open, `host_path_ex` returns a
-synthetic path (`@romfsarc:<guest path>`) for entries on the archive mount instead of a host file
-path; `OpenFile`, `GetEntryType`, `OpenDirectory` and the directory calls recognise that prefix and
-route to `romfs_arc.c`. File handles for archive entries are marked with bit 63 so they never
-collide with real fds, and `ReadFile` clamps to the file size (a shard is a flat container, so a
-read past the end would otherwise return the next file's bytes).
-
-The mount is recognised by its **directory**, not its name: titles differ (`rom` for most games,
-`content` for Tears of the Kingdom).
-
-## Limitations
-
-- **Read-only.** Writes go to the save/temp mounts as before; the archive is never written.
-- **Case-sensitive lookup.** The archive stores the names exactly as the source tree had them, so
- the case-insensitive alias machinery the host uses for APFS directories is bypassed.
-- **Symlinks are followed at pack time.** No supported game's RomFS has any.
-- **The index is held in memory.** 28 MB for TotK (17.9 MB of it names); the shards are not.
-- **No dedup or compression.** Shards are the source bytes verbatim, so `verify` is a plain
- comparison and a repack is deterministic.
diff --git a/docs/launcher-c-design.md b/docs/launcher-c-design.md
index bc814c7d..476a1c1e 100644
--- a/docs/launcher-c-design.md
+++ b/docs/launcher-c-design.md
@@ -231,11 +231,11 @@ section,无任何报错(第二个游戏的代码消失了)*,NRO 式"3
- **游戏列表** = 扫描两个来源后按 title id 连接:
1. **代码**:`Bundle.main/Frameworks/*.framework`,读每个 framework `Resources/game.manifest.json`
(构建时生成,第 3.2 节),运行期用 `getsectiondata`/段存在性做交叉校验(防 manifest 与段不一致)。
- 不建议扫 `romfs.idx` 当列表依据——romfs 是用户可移动的数据(外置盘是计划能力:romfs_arc.c 按分片
+ 不建议扫数据文件当列表依据——romfs 是用户可移动的数据(外置盘是计划能力:当时设想按分片
pread,天然支持外部路径,但今天 `main.m romfs_locate` 只查 per-game/Documents/bundle 三处,
文件夹选择器是待办,ROADMAP:129-132),代码在不在 bundle 里才是"装没装"。
2. **数据**:`Documents/games/*/`,"这个目录是不是一个游戏的文件"的判定已经存在:
- `main.m:19-28 romfs_dir_ok`(有 `romfs.idx` 或 profile 的 `romfs_marker` 路径即算)。
+ `main.m:19-28 romfs_dir_ok`(有 profile 的 `romfs_marker` 路径即算;旧的 `romfs.idx` 分片归档已不再读取)。
- 列表状态:代码+数据 = 可玩,只有代码 = 提示"把 romfs 放进 Files",只有数据 = 灰显"IPA 里没有这个游戏
的 framework(需要重签安装)"——这条提示就是 2.2 结论的用户可见面。
- **存档隔离**:已经有了。`Documents/games/<id>/{save,temp}`,`main.m:95-104`:
diff --git a/docs/launcher-c-plan.md b/docs/launcher-c-plan.md
index ab13b78d..e6e253c5 100644
--- a/docs/launcher-c-plan.md
+++ b/docs/launcher-c-plan.md
@@ -103,7 +103,7 @@ Keep "one game, one IPA" and move the game's modules out of the main executable
`pickedDataBookmark.<titleID>` with migration, `GameData.m` resolves like `main.m:69–117` with
explicit title id/marker, `GameLauncher.m` sets `DM_AOC_DIR`, `DM_MSL_DIR`, `DM_PSO_BUNDLE`
per game first and then app-wide, `LauncherSettings` is per game, and `GameLibrary` never treats
- `romfs.idx` as "code installed" (design §233–240).
+ a data file as "code installed" (design §233–240).
- Done when: two titles' `Documents/games/<id>/{romfs.img,romfs,save,temp,msl,pso,aoc}` are
isolated, a stale bookmark falls back, an identity mismatch falls back, and DLC `aoc/<index>.img`
mounts (`hle_fs.c:516-518`).
@@ -121,7 +121,7 @@ shell's `DMSH_CHAIN`, unique title ids, and at launch the loader cross-checks se
`nro_count > 0`) — a mismatch marks the game `broken` without affecting others.
Discovery: frameworks come from `Bundle.main.privateFrameworksURL/*.framework` and data from
-`Documents/games/<title_id>/` (`romfs.img` complete, or `romfs/romfs.idx`, or
+`Documents/games/<title_id>/` (`romfs.img` complete, or
`romfs/<manifest.romfs_marker>`), with a per-title bookmark for external drives, and the results merge into
playable / needsData / needsFramework / broken.
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.py
index f630667d..1e251d41 100644
--- a/frontend-qt/nspb_qt/localization.py
+++ b/frontend-qt/nspb_qt/localization.py
@@ -720,7 +720,7 @@ TABLE: dict[str, tuple[str, str, str]] = {
'msg.repoInvalidEmpty': ('仓库路径无效:未选择——用上方的「选择仓库…」指向本项目的 clone', 'Invalid repository path: none chosen — use Choose repository… above', 'Ogiltig förrådssökväg: inget valt. Använd ”Välj förråd …” ovan och välj projektets klon.'),
'msg.archiveSkipped': ('IPA 已生成,但归档跳过:找不到 %@/v*/RomFS', 'IPA built, archive skipped: no %@/v*/RomFS', 'IPA-filen skapades men arkiveringen hoppades över eftersom %@/v*/RomFS inte hittades'),
'msg.archiveFailed': ('归档失败(退出码 %d)', 'Archive failed (exit code %d)', 'Arkiveringen misslyckades (slutkod %d)'),
- 'msg.archiveNoStart': ('无法启动 romfs_arc.py', 'Could not start romfs_arc.py', 'Kunde inte starta romfs_arc.py'),
+ 'msg.archiveNoStart': ('无法启动 romfs_image.py', 'Could not start romfs_image.py', 'Kunde inte starta romfs_image.py'),
'msg.archiveIpaOnly': ('IPA 已生成,归档失败', 'IPA built, but the archive failed', 'IPA-filen byggdes, men arkiveringen misslyckades'),
'msg.done': ('完成:IPA 与 romfs 归档已生成,按下面三步装到手机', 'Done: the IPA and the romfs archive are ready — three steps below', 'Klart: IPA-filen och romfs-arkivet är färdiga. Följ de tre stegen nedan.'),
'prog.archiveDone': ('游戏数据就绪:%@/romfs.img', 'game data ready: %@/romfs.img', 'speldata klar: %@/romfs.img'),
diff --git a/frontend-qt/nspb_qt/win/build_app.py b/frontend-qt/nspb_qt/win/build_app.py
index dfab259b..6dbacdd5 100644
--- a/frontend-qt/nspb_qt/win/build_app.py
+++ b/frontend-qt/nspb_qt/win/build_app.py
@@ -82,7 +82,7 @@ def py(*args, env=None, capture=True) -> str:
#: Makefile's wildcards are the only place the source list is maintained: if upstream adds a
#: file to either line, silently missing it here would produce a link error or a subtly
#: incomplete host.
-WANT_SRC = ('SRC=main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c save_sync.c memstat.m '
+WANT_SRC = ('SRC=main.c loader.c hle.c crash.c probe.c thread.c save_sync.c memstat.m '
'haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S')
WANT_GFX = ('GFX=$(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/nvn/*.m ../gfx/nvn/*.S '
'../gfx/tex/*.c ../gfx/tex/*.m ../gfx/vk/*.m ../gfx/gl/*.m))')
@@ -111,7 +111,7 @@ def host_sources(repo: Path, game_h_dir: Path) -> tuple[list[Path], list[Path]]:
die(f'dm/host/Makefile changed ({what}= line): update host_sources() in '
f'frontend-qt/nspb_qt/win/build_app.py to match')
- src = [host / n for n in 'main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c save_sync.c '
+ src = [host / n for n in 'main.c loader.c hle.c crash.c probe.c thread.c save_sync.c '
'memstat.m haptics_apple.m'.split()]
src += sorted(host.glob('hle_*.c'), key=lambda p: p.name)
src += [host / 'front_mac.m', host / 'entry.S']
diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.py
index bb46a121..5a424e34 100644
--- a/frontend-qt/tests/test_win.py
+++ b/frontend-qt/tests/test_win.py
@@ -347,7 +347,7 @@ class HostSourcesTest(unittest.TestCase):
files, incs = build_app.host_sources(self.repo, self.gen)
names = {p.name for p in files}
# from SRC=
- for must in ('loader.c', 'hle.c', 'romfs_arc.c', 'crash.c', 'probe.c', 'thread.c',
+ for must in ('loader.c', 'hle.c', 'crash.c', 'probe.c', 'thread.c',
'memstat.m', 'haptics_apple.m', 'entry.S', 'main.c'):
self.assertIn(must, names, f'{must} missing from the host source list')
# Mac-only sources are dropped
@@ -375,7 +375,7 @@ class HostSourcesTest(unittest.TestCase):
(fake / 'dm/host').mkdir(parents=True)
makefile = (self.repo / 'dm/host/Makefile').read_text(encoding='utf-8')
(fake / 'dm/host/Makefile').write_text(
- makefile.replace('romfs_arc.c ', 'romfs_arc.c newfile.c '), encoding='utf-8')
+ makefile.replace('crash.c ', 'crash.c newfile.c '), encoding='utf-8')
with self.assertRaises(SystemExit) as ctx:
build_app.host_sources(fake, self.gen)
# host_sources() reports through build_app.die(), which raises SystemExit(1); the
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 0ac1cc25..4cedb251 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -2,7 +2,7 @@ import SwiftUI
// NS Port Builder: a macOS front end that walks a user through building a playable
// IPA from their own Switch game files. Not part of the host runtime; drives the
-// repository's scripts (build_ipa_from_nsp.py, romfs_arc.py) as subprocesses.
+// repository's scripts (build_ipa_from_nsp.py, romfs_image.py) as subprocesses.
//
// The four inputs are picked separately — base game, update, add-on content (DLC),
// prod.keys — because they are not always in one folder. When they are (the common
@@ -1561,7 +1561,7 @@ final class BuildModel: ObservableObject {
// MARK: Archive
- /// Pack the extracted RomFS into a ROMFSARC archive. The extracted folder is
+ /// Pack the extracted RomFS into one romfs.img. The extracted folder is
/// <work>/extract/v<N>/RomFS where N is the profile's package version, so take
/// the highest v* that actually has a RomFS instead of hardcoding one game.
/// `then` continues the build with the archive's folder (installing on a device) instead of ending it.
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index 35c466bf..36f8dbf2 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -879,7 +879,7 @@ enum L10n {
"msg.archiveSkipped": ("IPA 已生成,但归档跳过:找不到 %@/v*/RomFS",
"IPA built, archive skipped: no %@/v*/RomFS"),
"msg.archiveFailed": ("归档失败(退出码 %d)", "Archive failed (exit code %d)"),
- "msg.archiveNoStart": ("无法启动 romfs_arc.py", "Could not start romfs_arc.py"),
+ "msg.archiveNoStart": ("无法启动 romfs_image.py", "Could not start romfs_image.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": ("游戏数据就绪:%@/romfs.img", "game data ready: %@/romfs.img"),
@@ -1434,7 +1434,7 @@ enum L10n {
"drop.hint": "Släpp för att lägga till: NSP-, NSZ- eller XCI-filer, en mapp eller prod.keys",
"msg.launchFailed": "Kunde inte starta byggskriptet: %@",
"msg.archiveFailed": "Arkiveringen misslyckades (slutkod %d)",
- "msg.archiveNoStart": "Kunde inte starta romfs_arc.py",
+ "msg.archiveNoStart": "Kunde inte starta romfs_image.py",
"msg.archiveIpaOnly": "IPA-filen byggdes, men arkiveringen misslyckades",
"msg.done": "Klart: IPA-filen och romfs-arkivet är färdiga. Följ de tre stegen nedan.",
"prog.archiveDone": "speldata klar: %@/romfs.img",
diff --git a/patches/0002-romfsarc.patch b/patches/0002-romfsarc.patch
deleted file mode 100644
index 22eebfba..00000000
--- a/patches/0002-romfsarc.patch
+++ /dev/null
@@ -1,1106 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: v0lumehi <[email protected]>
-Date: Wed, 28 Oct 2026 13:33:53 +0100
-Subject: [PATCH] ROMFSARC: read RomFS shard archives
-
-A synthetic @romfsarc: host path, an archive MountRom, archive file handles, and directory snapshots from the index,
-plus the reader (romfs_arc.c) and its packer (romfs_arc.py).
-
-Upstream-Status: fork-only
-Reason: Legacy ROMFSARC shard archives (Tears of the Kingdom, 300k files) that players already made; upstream reads DMROMFS1 images instead. Kept so existing archives keep loading; retire when none are left
-Issue: LNPANDY/NX2Apple#123
----
- dm/host/Makefile | 2 +-
- dm/host/hle_fs.c | 140 ++++++++++++++++++-
- dm/host/romfs_arc.c | 228 ++++++++++++++++++++++++++++++
- dm/host/romfs_arc.h | 100 +++++++++++++
- dm/host/tests/Makefile | 12 +-
- dm/host/tests/t_romfs_arc.c | 87 ++++++++++++
- dm/tools/romfs_arc.py | 270 ++++++++++++++++++++++++++++++++++++
- docs/ROMFS_ARCHIVE.md | 95 +++++++++++++
- 8 files changed, 924 insertions(+), 10 deletions(-)
- create mode 100644 dm/host/romfs_arc.c
- create mode 100644 dm/host/romfs_arc.h
- create mode 100644 dm/host/tests/t_romfs_arc.c
- create mode 100644 dm/tools/romfs_arc.py
- create mode 100644 docs/ROMFS_ARCHIVE.md
-
-diff --git a/dm/host/Makefile b/dm/host/Makefile
-index 410b6ce4..2baa234b 100644
---- a/dm/host/Makefile
-+++ b/dm/host/Makefile
-@@ -16,7 +16,7 @@ endif
- GAME_H = gen/$(GAME)/game_profile.h
- CFLAGS=-O1 -g -Wall -Wno-unused-function
- # Service-layer takeover hle_*.c files are included by wildcard: adding a file does not touch this line (avoids merge conflicts)
--SRC=main.c loader.c hle.c crash.c probe.c thread.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
-+SRC=main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
- # NVN null device + nn::vi + the Vulkan layer (dm/gfx/)
- # Sources under dm/gfx, dm/gfx/nvn, dm/gfx/tex, dm/gfx/vk and dm/gfx/gl are included by wildcard (tests/ and metal/ do not go into the host): adding a file does not touch this line
- GFX=$(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/nvn/*.m ../gfx/nvn/*.S ../gfx/tex/*.c ../gfx/tex/*.m ../gfx/vk/*.m ../gfx/gl/*.m))
-diff --git a/dm/host/hle_fs.c b/dm/host/hle_fs.c
-index 035dbc04..643306f9 100644
---- a/dm/host/hle_fs.c
-+++ b/dm/host/hle_fs.c
-@@ -7,6 +7,7 @@
- #include "hle.h"
- #include <mach/mach.h>
- #include "front.h"
-+#include "romfs_arc.h"
- #include <dirent.h>
- #include <errno.h>
- #include <fcntl.h>
-@@ -382,6 +383,28 @@ static int host_path_ex(const char *p, char *out, size_t n, int *ro, int create)
- char normed[1024]; const char *rest = c + 1;
- if (strstr(rest, "/.")) { if (!norm_rest(rest, normed, sizeof normed)) return 0; rest = normed; } // only paths with "." components are normalized; the rest walk component by component as before
- if (g_mnt[i].overlay[0] && !create) return rom_overlay_path(&g_mnt[i], rest, out, n);
-+ // Archive mount: the RomFS tree lives inside a ROMFSARC archive, so the host path is a
-+ // synthetic "@romfsarc:<guest path>" that the file calls below route to romfs_arc.c. Matched
-+ // by the mount directory (romfsarc_open recorded the base it actually opened), because the
-+ // mount name differs between games (rom, content).
-+ if (romfsarc_active() && g_mnt[i].ro && !create && g_mnt[i].dir[0] && !strcmp(g_mnt[i].dir, g_arc_base)) {
-+ // Fold runs of '/' the way the directory walk below does: the archive index stores one
-+ // separator per level, and a game may ask for "data:/bin/appli/icon_sick//bin/x.arc"
-+ // (Pokemon Sword's Bag: the doubled slash missed the lookup and the game then
-+ // dereferenced the null it got back — PR #9).
-+ char folded[1024]; const char *r = rest;
-+ if (strstr(rest, "//")) {
-+ size_t o = 0; int slash = 0;
-+ for (const char *q = rest; *q; q++) {
-+ if (*q == '/') { if (slash) continue; slash = 1; } else slash = 0;
-+ if (o + 1 >= sizeof folded) { errno = ENAMETOOLONG; return 0; }
-+ folded[o++] = *q;
-+ }
-+ folded[o] = 0; r = folded;
-+ }
-+ if (snprintf(out, n, ROMFSARC_SYNTH_PREFIX "%s", r) >= (int)n) { errno = ENAMETOOLONG; return 0; }
-+ return 1;
-+ }
- strlcpy(out, g_mnt[i].dir, n);
- while (*rest) {
- while (*rest == '/') rest++;
-@@ -426,9 +449,22 @@ static Result err_res(const char *op, const char *path) {
-
- // ---------- Mount ----------
- HLE_FORCE("_ZN2nn2fs22QueryMountRomCacheSizeEPm", "fsp-srv; rom reads the host directory directly, the cache gets only the minimum size", Result, h_fs_QueryRomCache, size_t *out) { *out = 0x1000; return RES_OK; }
--HLE_FORCE("_ZN2nn2fs8MountRomEPKcPvm", "fsp-srv; rom → host RomFS directory", Result, h_fs_MountRom, const char *name, void *cache, size_t sz) {
-+HLE_FORCE("_ZN2nn2fs8MountRomEPKcPvm", "fsp-srv; rom → host RomFS directory (or a ROMFSARC archive)", Result, h_fs_MountRom, const char *name, void *cache, size_t sz) {
- (void)cache; (void)sz; char b[1024];
-- Result r = mount(name, envdir("DM_ROMFS", "romfs", b, sizeof b), 1);
-+ const char *dir = envdir("DM_ROMFS", "romfs", b, sizeof b);
-+ // Archive mount: romfsarc_open tries <dir>.idx, <dir>/romfs.idx and <dir>/romfs/romfs.idx, so the
-+ // player may copy the shards either beside the folder or into Documents/romfs/ itself.
-+ romfsarc_hdr h;
-+ if (romfsarc_open(dir, &h) == 0) {
-+ // Mount the resolved archive base (romfsarc_open recorded the one that worked in g_arc_base).
-+ // host_path_ex compares the mount directory against it.
-+ Result r = mount(name, g_arc_base, 1);
-+ if (r != RES_OK) { romfsarc_close(); return r; }
-+ LOG("fs rom: archive %s (%llu files, %llu dirs, %u shards, tree hash %016llx)", g_arc_base,
-+ (unsigned long long)h.file_count, (unsigned long long)h.dir_count, h.shard_count, (unsigned long long)h.tree_hash);
-+ return RES_OK;
-+ }
-+ Result r = mount(name, dir, 1);
- if (r == RES_OK && getenv("DM_ROMFS_OVERLAY")) {
- PATH_LOCK();
- for (int i = 0; i < g_nmnt; i++) if (!strcmp(g_mnt[i].name, name)) {
-@@ -708,6 +744,43 @@ HLE_FORCE("_ZN2nn2fs14CommitSaveDataEPKc", "fsp-srv; same as Commit (SDK 11's ol
- HLE_FORCE("_ZN2nn2fs7UnmountEPKc", "fsp-srv; the mount table is permanent, unmounting is a no-op", void, h_fs_Unmount, const char *name) { (void)name; }
-
- // ---------- Files ----------
-+// ---------- Archive-backed file handles ----------
-+// An archive file has no host fd. It gets a handle number from a private table, and every operation
-+// on it (ReadFile, GetFileSize, CloseFile) checks the table first. Handle numbers are distinct from
-+// fds: real handles are fds (>= 3 in practice), archive handles are tagged by index into g_arc[].
-+// Like every host handle they reach the guest through FH_OUT (shifted left by 4, 16-byte aligned) and come back
-+// through FH_IN, so the tag sits at bit 57: below IMG_H's bit 58, and it still fits after the shift.
-+typedef struct { uint32_t shard; uint64_t off, size; int used; } archandle;
-+#define MAX_ARCH 4096
-+static archandle g_arc[MAX_ARCH];
-+static uint64_t g_arch_gen; // bumped on open/close so a stale handle never hits a recycled slot
-+static uint64_t arc_new(uint32_t shard, uint64_t off, uint64_t size) {
-+ for (int i = 0; i < MAX_ARCH; i++) if (!g_arc[i].used) {
-+ g_arc[i].used = 1; g_arc[i].shard = shard; g_arc[i].off = off; g_arc[i].size = size;
-+ return ((uint64_t)1 << 57) | ((g_arch_gen & 0xffffff) << 32) | (uint32_t)i;
-+ }
-+ return 0;
-+}
-+static int arc_get(uint64_t h, archandle **out) {
-+ if ((h >> 57) != 1) return 0;
-+ uint32_t i = (uint32_t)h;
-+ if (i >= MAX_ARCH || !g_arc[i].used) return 0;
-+ if ((uint32_t)((h >> 32) & 0xffffff) != (uint32_t)(g_arch_gen & 0xffffff)) return 0;
-+ *out = &g_arc[i]; return 1;
-+}
-+static void arc_free(uint64_t h) {
-+ archandle *a; if (arc_get(h, &a)) a->used = 0;
-+}
-+static const char *arc_rel(const char *hp) {
-+ const char *rel = ROMFSARC_SYNTH_REL(hp);
-+ while (*rel == '/') rel++;
-+ return rel;
-+}
-+static int arc_file(const char *hp, uint32_t *shard, uint64_t *off, uint64_t *size) {
-+ return romfsarc_stat_file(arc_rel(hp), shard, off, size);
-+}
-+static int arc_dir(const char *hp) { return romfsarc_is_dir(arc_rel(hp)); }
-+static void arc_norm(const char *hp, char *rel, size_t n) { strlcpy(rel, arc_rel(hp), n); }
- HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Result, h_fs_OpenFile, uint64_t *out, const char *path, int mode) {
- int mi; int64_t k;
- if (img_path(path, &mi, &k)) {
-@@ -720,6 +793,15 @@ HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Re
- }
- HP(path);
- if (mode & (MODE_WRITE | MODE_APPEND)) RW();
-+ if (ROMFSARC_IS_SYNTH(hp)) { // archive entry: no fd, the handle carries shard/offset/size
-+ uint32_t shard; uint64_t off, size;
-+ if (!arc_file(hp, &shard, &off, &size)) { errno = ENOENT; return err_res("open", hp); }
-+ uint64_t ah = arc_new(shard, off, size);
-+ if (!ah) { errno = EMFILE; return err_res("open", hp); }
-+ *out = FH_OUT(ah);
-+ if (g_flag.fs) LOG("fs open %s mode=%d → archive handle (shard %u off %llu size %llu)", path, mode, shard, (unsigned long long)off, (unsigned long long)size);
-+ return RES_OK;
-+ }
- int fd = open(hp, (mode & (MODE_WRITE | MODE_APPEND)) ? ((mode & MODE_READ) ? O_RDWR : O_WRONLY) : O_RDONLY);
- if (fd < 0) return err_res("open", hp);
- struct stat st; fstat(fd, &st);
-@@ -743,6 +825,20 @@ HLE_FORCE("_ZN2nn2fs8ReadFileEPmNS0_10FileHandleElPvm", "fsp-srv → pread(2)",
- sz = off < 0 || (uint64_t)off >= x->b ? 0 : (size_t)(x->b - off) < sz ? (size_t)(x->b - off) : sz;
- }
- dm_guest_write_prepare(buf, sz); // The destination may be a texture pool page write-protected by the graphics layer: a kernel write to a read-only page returns EFAULT instead of page-faulting, so unprotect and mark dirty first
-+ archandle *ah;
-+ if (arc_get(h, &ah)) { // archive entry: clamp to the file, read from its shard
-+ if (off < 0) { *out = 0; return RES_FAIL; }
-+ uint64_t avail = (uint64_t)off < ah->size ? ah->size - (uint64_t)off : 0;
-+ size_t want = sz < avail ? sz : (size_t)avail;
-+ if (want) { ssize_t r = romfsarc_pread(ah->shard, ah->off + (uint64_t)off, buf, want);
-+ if (r < 0) return err_res("pread (archive)", "handle"); got = (size_t)r; }
-+ *out = got;
-+ if (g_flag.fs) { static uint64_t n, bytes, next_b = 64 << 20; static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
-+ pthread_mutex_lock(&m); n++; bytes += got;
-+ if (bytes >= next_b || n % 1000 == 0) { LOG("fs read total: %llu reads %.1f MiB (this one: archive offset %lld length %#zx)", n, bytes / 1048576.0, (long long)off, got); if (bytes >= next_b) next_b += 64 << 20; }
-+ pthread_mutex_unlock(&m); }
-+ return RES_OK;
-+ }
- while (got < sz) {
- ssize_t r = pread(fd, (uint8_t *)buf + got, sz - got, base + off + got);
- if (r < 0) { if (errno == EINTR) continue;
-@@ -799,6 +895,7 @@ HLE_FORCE("_ZN2nn2fs9WriteFileENS0_10FileHandleElPKvmRKNS0_11WriteOptionE", "fsp
- }
- HLE_FORCE("_ZN2nn2fs11GetFileSizeEPlNS0_10FileHandleE", "fsp-srv → fstat(2)", Result, h_fs_GetFileSize, int64_t *out, uint64_t h) { h = FH_IN(h);
- if (!h) return RES_FAIL;
-+ archandle *ah; if (arc_get(h, &ah)) { *out = (int64_t)ah->size; return RES_OK; }
- if (IMG_H(h)) { *out = (int64_t)g_mnt[IMG_M(h)].img->e[IMG_K(h)].b; return RES_OK; }
- struct stat st; if (fstat((int)h, &st)) return err_res("fstat", "fd");
- *out = st.st_size; return RES_OK;
-@@ -815,6 +912,7 @@ HLE_FORCE("_ZN2nn2fs11SetFileSizeENS0_10FileHandleEl", "fsp-srv → ftruncate(2)
- HLE_FORCE("_ZN2nn2fs9FlushFileENS0_10FileHandleE", "fsp-srv; host writes are already in the page cache, flushing is a no-op", Result, h_fs_FlushFile, uint64_t h) { (void)h; return RES_OK; }
- HLE_FORCE("_ZN2nn2fs9CloseFileENS0_10FileHandleE", "fsp-srv → close(2)", void, h_fs_CloseFile, uint64_t h) { h = FH_IN(h);
- if (!h || IMG_H(h)) return; // the null handle after a failed open (see ReadFile): do not touch fd 0; an image entry holds no descriptor
-+ if ((h >> 57) == 1) { arc_free(h); return; } // archive entry: nothing to close
- g_fmode[(int)h & 0xffff] = 0; atomic_store(&g_ftxn[(int)h & 0xffff], 0);
- close((int)h); }
- HLE_FORCE("_ZN2nn2fs15GetFileOpenModeENS0_10FileHandleE", "fsp-srv; the open mode is recorded by the host", int, h_fs_GetFileOpenMode, uint64_t h) { h = FH_IN(h); return IMG_H(h) ? MODE_READ : g_fmode[(int)h & 0xffff]; }
-@@ -898,12 +996,39 @@ HLE_FORCE("_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc", "fsp-srv →
- int mi; int64_t k;
- if (img_path(path, &mi, &k)) { if (k < 0) return err_res("stat", path); *out = g_mnt[mi].img->e[k].type ? ENT_FILE : ENT_DIR; return RES_OK; }
- HP(path); struct stat st;
-+ if (ROMFSARC_IS_SYNTH(hp)) { // archive entry or directory, from the index
-+ const char *rel = arc_rel(hp); // the index stores paths without a leading slash (abe35a3)
-+ uint32_t sh; uint64_t of, szf;
-+ if (romfsarc_stat_file(rel, &sh, &of, &szf)) { *out = ENT_FILE; return RES_OK; }
-+ if (romfsarc_is_dir(rel)) { *out = ENT_DIR; return RES_OK; }
-+ errno = ENOENT; return err_res("stat", hp);
-+ }
- if (stat(hp, &st)) return err_res("stat", hp);
- *out = S_ISDIR(st.st_mode) ? ENT_DIR : ENT_FILE; return RES_OK;
- }
-
- // ---------- Directories ----------
- typedef struct { DIR *d; char path[1024]; DIR *od; char opath[1024]; DirectoryEntry *snap; int64_t nsnap, psnap; int mode; } dirh_t;
-+
-+// An archive directory has no host DIR: its entries come from the index, copied into the same
-+// snapshot list the overlay mount uses, so ReadDirectory has one path for both.
-+static void arc_snapshot(dirh_t *h, const char *hp) {
-+ char rel[1024]; arc_norm(hp, rel, sizeof rel);
-+ int n = romfsarc_count(rel);
-+ if (n <= 0) return;
-+ romfsarc_ent *ents = malloc((size_t)n * sizeof *ents);
-+ if (!ents) die("archive directory snapshot allocation failed");
-+ int got = romfsarc_list(rel, ents, n);
-+ if (got <= 0) { free(ents); return; }
-+ h->snap = calloc((size_t)got, sizeof *h->snap); h->nsnap = got;
-+ if (!h->snap) die("archive directory snapshot allocation failed");
-+ for (int i = 0; i < got; i++) {
-+ strlcpy(h->snap[i].name, ents[i].name, sizeof h->snap[i].name);
-+ h->snap[i].type = ents[i].is_dir ? ENT_DIR : ENT_FILE;
-+ h->snap[i].size = ents[i].is_dir ? 0 : ents[i].size;
-+ }
-+ free(ents);
-+}
- static void dir_snapshot(dirh_t *h, const mount_t *m, const char *rest) {
- char fwd[1024]; rest = fwd_slashes(rest, fwd, sizeof fwd);
- char *roots = strdup(m->overlay);
-@@ -965,7 +1090,15 @@ HLE_FORCE("_ZN2nn2fs13OpenDirectoryEPNS0_15DirectoryHandleEPKci", "fsp-srv → o
- }
- *out = (uint64_t)h; return RES_OK;
- }
-- HP(path); DIR *d = opendir(hp);
-+ HP(path);
-+ if (ROMFSARC_IS_SYNTH(hp)) { // archive directory: no host DIR, only the snapshot
-+ if (!arc_dir(hp)) { errno = ENOTDIR; return err_res("opendir", hp); }
-+ dirh_t *ah = calloc(1, sizeof *ah); if (!ah) die("directory handle allocation failed");
-+ strlcpy(ah->path, hp, sizeof ah->path); ah->mode = mode;
-+ arc_snapshot(ah, hp);
-+ *out = (uint64_t)ah; return RES_OK;
-+ }
-+ DIR *d = opendir(hp);
- if (!d) return err_res("opendir", hp);
- dirh_t *h = calloc(1, sizeof *h); h->d = d; strlcpy(h->path, hp, sizeof h->path); h->mode = mode;
- const char *c = strchr(path, ':');
-@@ -978,6 +1111,7 @@ HLE_FORCE("_ZN2nn2fs13ReadDirectoryEPlPNS0_14DirectoryEntryENS0_15DirectoryHandl
- if (!hh) { *count = 0; return RES_FAIL; }
- PATH_LOCK(); dirh_t *h = (dirh_t *)hh; int64_t n = 0; struct dirent *e;
- if (h->snap) { while (n < max && h->psnap < h->nsnap) { DirectoryEntry *src = &h->snap[h->psnap++]; if (!(h->mode & (src->type == ENT_DIR ? DIRMODE_DIR : DIRMODE_FILE))) continue; ents[n++] = *src; } *count = n; return RES_OK; }
-+ if (!h->d) { *count = 0; return RES_OK; } // an archive directory that turned out empty (no snapshot, no host DIR)
- int dfd = dirfd(h->d);
- while (n < max && (e = readdir(h->d))) {
- if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) continue;
-diff --git a/dm/host/romfs_arc.c b/dm/host/romfs_arc.c
-new file mode 100644
-index 00000000..d76681d1
---- /dev/null
-+++ b/dm/host/romfs_arc.c
-@@ -0,0 +1,228 @@
-+// RomFS archive reader: see romfs_arc.h for the on-disk format.
-+#include "romfs_arc.h"
-+#include <errno.h>
-+#include <fcntl.h>
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <sys/mman.h>
-+#include <sys/stat.h>
-+#include <unistd.h>
-+#include <pthread.h>
-+
-+typedef struct {
-+ uint32_t name_off, shard;
-+ uint64_t off, size;
-+ uint32_t mode, res;
-+} filerec;
-+
-+typedef struct {
-+ uint32_t name_off, first_child, child_count, res;
-+} dirrec;
-+
-+static struct {
-+ int open;
-+ void *idx; // mmap of the index file
-+ size_t idx_size;
-+ romfsarc_hdr hdr;
-+ const char *pool;
-+ const filerec *files;
-+ const dirrec *dirs;
-+ const uint32_t *children;
-+ char base[1024];
-+ int shard_fd[256];
-+ char shard_path[256][1024];
-+ pthread_mutex_t lock;
-+} A = { .shard_fd = { [0 ... 255] = -1 }, .lock = PTHREAD_MUTEX_INITIALIZER };
-+
-+static uint64_t rd64(const void *p) { uint64_t v; memcpy(&v, p, 8); return v; }
-+static uint32_t rd32(const void *p) { uint32_t v; memcpy(&v, p, 4); return v; }
-+
-+char g_arc_base[1024]; // the archive's base path, matched against mount directories by hle_fs.c
-+
-+static const char *fname(const filerec *f) { return A.pool + f->name_off; }
-+static const char *dname(const dirrec *d) { return A.pool + d->name_off; }
-+
-+// Binary search the file table by path. Returns the record or NULL.
-+static const filerec *find_file(const char *rel) {
-+ uint64_t lo = 0, hi = A.hdr.file_count;
-+ while (lo < hi) {
-+ uint64_t mid = lo + (hi - lo) / 2;
-+ int c = strcmp(fname(&A.files[mid]), rel);
-+ if (c == 0) return &A.files[mid];
-+ if (c < 0) lo = mid + 1; else hi = mid;
-+ }
-+ return NULL;
-+}
-+
-+// 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;
-+ int c = strcmp(dname(&A.dirs[mid]), rel);
-+ if (c == 0) return &A.dirs[mid];
-+ if (c < 0) lo = mid + 1; else hi = mid;
-+ }
-+ return NULL;
-+}
-+
-+// Open and validate one index file. Returns the mapping (and its size) or MAP_FAILED.
-+static void *map_index(const char *path, size_t *size) {
-+ int fd = open(path, O_RDONLY);
-+ if (fd < 0) return MAP_FAILED;
-+ struct stat st;
-+ if (fstat(fd, &st)) { close(fd); errno = EIO; return MAP_FAILED; }
-+ if ((size_t)st.st_size < ROMFSARC_HDR) { close(fd); errno = EINVAL; return MAP_FAILED; }
-+ void *m = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-+ close(fd);
-+ if (m == MAP_FAILED) return MAP_FAILED;
-+ const uint8_t *b = m;
-+ if (memcmp(b, ROMFSARC_MAGIC, 8) || rd32(b + 8) != ROMFSARC_VERSION) {
-+ munmap(m, (size_t)st.st_size); errno = EINVAL; return MAP_FAILED;
-+ }
-+ *size = (size_t)st.st_size;
-+ return m;
-+}
-+
-+int romfsarc_open(const char *base, romfsarc_hdr *out) {
-+ // The base is where the shards live, without the ".idx". Callers pass either the base itself
-+ // (DM_ROMFS=/games/totk/romfs with romfs.idx beside it) or a directory that holds the archive
-+ // (DM_ROMFS=Documents/romfs with Documents/romfs/romfs.idx inside, which is what the iOS app
-+ // sets). Try both, and a base that already carries the .idx suffix.
-+ char cand[4][1200];
-+ char stripped[1200];
-+ strlcpy(stripped, base, sizeof stripped);
-+ size_t sl = strlen(stripped);
-+ if (sl > 4 && !strcmp(stripped + sl - 4, ".idx")) stripped[sl - 4] = 0;
-+ snprintf(cand[0], sizeof cand[0], "%s.idx", stripped); // <base>.idx
-+ snprintf(cand[1], sizeof cand[1], "%s/romfs.idx", stripped); // <base>/romfs.idx
-+ snprintf(cand[2], sizeof cand[2], "%s/romfs/romfs.idx", stripped); // one more level (a bundle-style layout)
-+ cand[3][0] = 0;
-+ void *m = MAP_FAILED; size_t sz = 0; char used[1200] = "";
-+ for (int i = 0; i < 3; i++) {
-+ m = map_index(cand[i], &sz);
-+ if (m != MAP_FAILED) { strlcpy(used, cand[i], sizeof used); break; }
-+ }
-+ if (m == MAP_FAILED) return -1;
-+ // The resolved base is the index path minus ".idx": shard paths are built from it
-+ size_t ul = strlen(used); if (ul > 4) used[ul - 4] = 0;
-+ const uint8_t *b = m;
-+ romfsarc_hdr h;
-+ h.shard_count = rd32(b + 12);
-+ h.file_count = rd64(b + 24);
-+ h.dir_count = rd64(b + 32);
-+ h.tree_hash = rd64(b + 56);
-+ if (h.shard_count == 0 || h.shard_count > 256) { munmap(m, sz); errno = EINVAL; return -1; }
-+ uint64_t pool_sz = rd64(b + 40);
-+ uint64_t need = ROMFSARC_HDR + pool_sz + h.file_count * ROMFSARC_FILEREC + h.dir_count * ROMFSARC_DIRREC;
-+ // The child list follows the directory table; its length is implied by the last directory's range,
-+ // so the file only has to be at least as long as the three tables above.
-+ if (need > (uint64_t)sz) { munmap(m, sz); errno = EINVAL; return -1; }
-+ pthread_mutex_lock(&A.lock);
-+ A.open = 1; A.idx = m; A.idx_size = sz; A.hdr = h;
-+ A.pool = (const char *)(b + ROMFSARC_HDR);
-+ A.files = (const filerec *)(b + ROMFSARC_HDR + pool_sz);
-+ A.dirs = (const dirrec *)((const uint8_t *)A.files + h.file_count * ROMFSARC_FILEREC);
-+ A.children = (const uint32_t *)((const uint8_t *)A.dirs + h.dir_count * ROMFSARC_DIRREC);
-+ for (int i = 0; i < 256; i++) { A.shard_fd[i] = -1; A.shard_path[i][0] = 0; }
-+ // Shards are named after the index file's own base, so <dir>/romfs.idx pairs with <dir>/romfs.00
-+ strlcpy(A.base, used, sizeof A.base);
-+ strlcpy(g_arc_base, used, sizeof g_arc_base);
-+ pthread_mutex_unlock(&A.lock);
-+ if (out) *out = h;
-+ return 0;
-+}
-+
-+int romfsarc_active(void) { return A.open; }
-+
-+int romfsarc_stat_file(const char *rel, uint32_t *shard, uint64_t *off, uint64_t *size) {
-+ if (!A.open) return 0;
-+ const filerec *f = find_file(rel);
-+ if (!f) return 0;
-+ if (shard) *shard = f->shard;
-+ if (off) *off = f->off;
-+ if (size) *size = f->size;
-+ return 1;
-+}
-+
-+int romfsarc_is_dir(const char *rel) {
-+ if (!A.open) return 0;
-+ return find_dir(rel) != NULL;
-+}
-+
-+static int shard_fd(uint32_t i) {
-+ if (i >= A.hdr.shard_count) { errno = EINVAL; return -1; }
-+ if (A.shard_fd[i] >= 0) return A.shard_fd[i];
-+ pthread_mutex_lock(&A.lock);
-+ if (A.shard_fd[i] < 0) {
-+ char p[1024];
-+ if (snprintf(p, sizeof p, "%s.%02u", A.base, i) < (int)sizeof p) {
-+ int fd = open(p, O_RDONLY);
-+ if (fd >= 0) { A.shard_fd[i] = fd; strlcpy(A.shard_path[i], p, sizeof A.shard_path[i]); }
-+ }
-+ }
-+ int fd = A.shard_fd[i];
-+ pthread_mutex_unlock(&A.lock);
-+ return fd;
-+}
-+
-+ssize_t romfsarc_pread(uint32_t shard, uint64_t off, void *buf, size_t n) {
-+ int fd = shard_fd(shard);
-+ if (fd < 0) return -1;
-+ size_t done = 0;
-+ while (done < n) {
-+ ssize_t r = pread(fd, (uint8_t *)buf + done, n - done, (off_t)(off + done));
-+ if (r < 0) { if (errno == EINTR) continue; return -1; }
-+ if (r == 0) break;
-+ done += (size_t)r;
-+ }
-+ return (ssize_t)done;
-+}
-+
-+int romfsarc_list(const char *rel, romfsarc_ent *out, int max) {
-+ if (!A.open) return -1;
-+ const dirrec *d = find_dir(rel);
-+ if (!d) return -1;
-+ int n = 0;
-+ for (uint32_t i = 0; i < d->child_count && n < max; i++) {
-+ uint32_t tag = A.children[d->first_child + i];
-+ romfsarc_ent *e = &out[n];
-+ if (tag & ROMFSARC_CHILD_DIR) {
-+ const dirrec *c = &A.dirs[tag & ~ROMFSARC_CHILD_DIR];
-+ // The directory table stores full paths; a child list entry carries only the leaf name
-+ const char *full = dname(c), *leaf = strrchr(full, '/');
-+ strlcpy(e->name, leaf ? leaf + 1 : full, sizeof e->name);
-+ e->is_dir = 1; e->size = 0;
-+ } else {
-+ const filerec *c = &A.files[tag];
-+ // The file table stores full paths; a child list entry carries only the leaf name
-+ const char *full = fname(c), *leaf = strrchr(full, '/');
-+ strlcpy(e->name, leaf ? leaf + 1 : full, sizeof e->name);
-+ e->is_dir = 0; e->size = (int64_t)c->size;
-+ }
-+ n++;
-+ }
-+ return n;
-+}
-+
-+int romfsarc_count(const char *rel) {
-+ if (!A.open) return -1;
-+ const dirrec *d = find_dir(rel);
-+ return d ? (int)d->child_count : -1;
-+}
-+
-+void romfsarc_close(void) {
-+ pthread_mutex_lock(&A.lock);
-+ for (int i = 0; i < 256; i++) if (A.shard_fd[i] >= 0) { close(A.shard_fd[i]); A.shard_fd[i] = -1; }
-+ if (A.idx) { munmap(A.idx, A.idx_size); A.idx = NULL; }
-+ A.open = 0;
-+ pthread_mutex_unlock(&A.lock);
-+}
-diff --git a/dm/host/romfs_arc.h b/dm/host/romfs_arc.h
-new file mode 100644
-index 00000000..c4a25b48
---- /dev/null
-+++ b/dm/host/romfs_arc.h
-@@ -0,0 +1,100 @@
-+// RomFS archive (ROMFSARC): a whole RomFS tree in one index file plus a few hundred shard files.
-+//
-+// Why: a RomFS like Tears of the Kingdom's is 300,000 files. Copying that into an App's Documents
-+// takes hours over the Files app / Finder, and a 16 GB IPA with that many entries does not install
-+// (PackageExtractionFailed). Packing the tree into ~100 shard files makes both a single copy.
-+//
-+// Layout (all integers little-endian):
-+// <base>.idx header, name pool, file table, directory table
-+// <base>.<NN> shard NN: the files' bytes back to back, in file-table order
-+//
-+// Header (64 bytes):
-+// 0x00 char magic[8] "ROMFSARC"
-+// 0x08 uint32 version 1
-+// 0x0c uint32 shard_count
-+// 0x10 uint64 index_size size of this index file
-+// 0x18 uint64 file_count
-+// 0x20 uint64 dir_count
-+// 0x28 uint64 name_pool_size
-+// 0x30 uint64 reserved
-+// 0x38 uint64 tree_hash FNV-1a over (path, size) of every file, sorted: a cheap identity check
-+//
-+// File table: file_count records of 32 bytes, sorted by path (the name pool offset points at the
-+// NUL-terminated relative path, '/'-separated, no leading slash):
-+// 0x00 uint32 name_off
-+// 0x04 uint32 shard
-+// 0x08 uint64 offset_in_shard
-+// 0x10 uint64 size
-+// 0x18 uint32 mode 0777 bits (the executable bit matters for nothing in RomFS, kept for fidelity)
-+// 0x1c uint32 reserved
-+//
-+// Directory table: dir_count records of 16 bytes, sorted by path ("" = the root):
-+// 0x00 uint32 name_off
-+// 0x04 uint32 first_child index into the child list
-+// 0x08 uint32 child_count
-+// 0x0c uint32 reserved
-+// Child list: uint32 file-table / directory-table indices, each tagged: bit 31 set = a directory.
-+// Children of one directory are contiguous and sorted by name.
-+//
-+// Path lookup is a binary search over the sorted tables; directory listing walks one child range.
-+// Case sensitivity: Horizon paths are case-sensitive and the archive is built from a case-sensitive
-+// walk, so the host looks names up exactly (the existing dir_index/case-alias machinery is not used
-+// for archive mounts).
-+#ifndef DM_ROMFS_ARC_H
-+#define DM_ROMFS_ARC_H
-+
-+#include <stdint.h>
-+#include <stddef.h>
-+#include <sys/types.h>
-+
-+#define ROMFSARC_MAGIC "ROMFSARC"
-+#define ROMFSARC_VERSION 1u
-+#define ROMFSARC_HDR 64
-+#define ROMFSARC_FILEREC 32
-+#define ROMFSARC_DIRREC 16
-+#define ROMFSARC_CHILD_DIR 0x80000000u
-+
-+// Synthetic host path prefix for archive-backed entries (see host_path_ex in hle_fs.c). A path that
-+// starts with this marker is not a real file: the fs layer routes it to the archive instead.
-+#define ROMFSARC_SYNTH_PREFIX "@romfsarc:"
-+#define ROMFSARC_IS_SYNTH(p) (!strncmp((p), ROMFSARC_SYNTH_PREFIX, sizeof ROMFSARC_SYNTH_PREFIX - 1))
-+#define ROMFSARC_SYNTH_REL(p) ((p) + sizeof ROMFSARC_SYNTH_PREFIX - 1)
-+
-+typedef struct {
-+ uint32_t shard_count;
-+ uint64_t file_count, dir_count;
-+ uint64_t tree_hash;
-+} romfsarc_hdr;
-+
-+// Open the index at <base>.idx. Returns 0 on success, -1 with errno set on failure.
-+// Keeps the index mapped; shards are opened lazily and cached.
-+int romfsarc_open(const char *base, romfsarc_hdr *out);
-+
-+// Whether an archive is open (the fs layer then routes lookups here instead of the host tree).
-+int romfsarc_active(void);
-+
-+// The base path the archive was opened from (without ".idx"): the fs layer matches mount
-+// directories against it, so the mount name ("rom", "content", …) does not matter.
-+extern char g_arc_base[];
-+
-+// Resolve a guest path (no leading slash, "" = root) to a file. On success fills the shard index,
-+// offset and size; returns 1. Returns 0 when the path is not a file (missing or a directory).
-+int romfsarc_stat_file(const char *rel, uint32_t *shard, uint64_t *off, uint64_t *size);
-+
-+// Whether the path names a directory ("" = root): 1 yes, 0 no.
-+int romfsarc_is_dir(const char *rel);
-+
-+// Read from an open archive file. Same semantics as pread.
-+ssize_t romfsarc_pread(uint32_t shard, uint64_t off, void *buf, size_t n);
-+
-+// Directory listing: write the entries of directory <rel> ("" = root) into the caller's array.
-+// Each entry gets its name and type; files also get their size. Returns the number written, or -1.
-+typedef struct { char name[0x301]; int is_dir; int64_t size; } romfsarc_ent;
-+int romfsarc_list(const char *rel, romfsarc_ent *out, int max);
-+
-+// Number of entries in a directory (unfiltered), or -1.
-+int romfsarc_count(const char *rel);
-+
-+void romfsarc_close(void);
-+
-+#endif
-diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile
-index 3fbba0ac..c60063b5 100644
---- a/dm/host/tests/Makefile
-+++ b/dm/host/tests/Makefile
-@@ -93,17 +93,17 @@ $(B)/t_gesture: t_gesture.c ../hle_touch.c ../front.h ../dm.h $(GAME_H) | $(B)
- $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_gesture.c ../hle_touch.c
- $(B)/t_thread_leak: t_thread_leak.c ../thread.c ../dm.h $(GAME_H) | $(B)
- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_thread_leak.c
--$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../hle_profile.c
--$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-- $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../hle_profile.c
-+$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../romfs_arc.c ../hle_profile.c
-+$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../romfs_arc.c ../hle_profile.c
- $(B)/t_fs_commit_list_tsan: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) | $(B)
- $(CLANG) -O1 -g -fsanitize=thread -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../hle_profile.c
- .PHONY: fs-tsan
- fs-tsan: $(B)/t_fs_commit_list_tsan
- TMPDIR="$(abspath $(B))" $(B)/t_fs_commit_list_tsan
--$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../hle_profile.c
-+$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../romfs_arc.c ../hle_profile.c
- $(B)/t_audio: t_audio.c ../hle_audio.c ../hle.h ../dm.h $(GAME_H) | $(B)
- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_audio.c -framework AudioToolbox
- $(B)/t_audio_spsc: t_audio_spsc.c ../hle_audio.c ../hle.h ../dm.h $(GAME_H) | $(B)
-diff --git a/dm/host/tests/t_romfs_arc.c b/dm/host/tests/t_romfs_arc.c
-new file mode 100644
-index 00000000..3f675332
---- /dev/null
-+++ b/dm/host/tests/t_romfs_arc.c
-@@ -0,0 +1,87 @@
-+// Test romfs_arc.c against a packed archive: path lookup, partial reads, directory listing.
-+// Build: clang -I dm/host -o /tmp/t_romfs_arc dm/host/tests/t_romfs_arc.c dm/host/romfs_arc.c
-+#include "romfs_arc.h"
-+#include <stdio.h>
-+#include <string.h>
-+#include <stdlib.h>
-+
-+static int fails;
-+#define CHECK(cond, ...) do { if (!(cond)) { printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); fails++; } } while (0)
-+
-+int main(int argc, char **argv) {
-+ if (argc < 2) { printf("usage: %s <base>\n", argv[0]); return 2; }
-+ romfsarc_hdr h;
-+ if (romfsarc_open(argv[1], &h)) { perror("romfsarc_open"); return 2; }
-+ printf("opened: %llu files, %llu dirs, %u shards, hash %016llx\n",
-+ (unsigned long long)h.file_count, (unsigned long long)h.dir_count, h.shard_count,
-+ (unsigned long long)h.tree_hash);
-+ CHECK(romfsarc_active(), "active after open");
-+ CHECK(h.file_count > 0 && h.dir_count > 0 && h.shard_count > 0, "header counts");
-+
-+ // Every file: stat it, read it whole, and read it in two halves at an offset
-+ romfsarc_ent *ents = calloc(4096, sizeof *ents);
-+ char path[1024] = "";
-+ int listed = romfsarc_list("", ents, 4096);
-+ CHECK(listed > 0, "root has entries, got %d", listed);
-+ CHECK(listed == romfsarc_count(""), "list and count agree at the root: %d vs %d", listed, romfsarc_count(""));
-+
-+ // Walk the tree breadth first and check every file's bytes against a direct read of its shard
-+ size_t dcap = 1024;
-+ char **dirs = calloc(dcap, sizeof *dirs);
-+ int nd = 0;
-+ dirs[nd++] = strdup("");
-+ int checked = 0;
-+ while (nd) {
-+ char *d = dirs[--nd];
-+ int n = romfsarc_count(d);
-+ CHECK(n >= 0, "count of '%s'", d);
-+ romfsarc_ent *e = calloc((size_t)(n > 0 ? n : 1), sizeof *e);
-+ int got = romfsarc_list(d, e, n);
-+ CHECK(got == n, "list '%s': %d vs %d", d, got, n);
-+ for (int i = 0; i < got; i++) {
-+ char rel[1024];
-+ snprintf(rel, sizeof rel, "%s%s%s", d, *d ? "/" : "", e[i].name);
-+ 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 {
-+ uint32_t shard; uint64_t off, size;
-+ CHECK(romfsarc_stat_file(rel, &shard, &off, &size), "stat '%s'", rel);
-+ CHECK((int64_t)size == e[i].size, "size '%s': %llu vs %lld", rel,
-+ (unsigned long long)size, (long long)e[i].size);
-+ char *buf = malloc(size ? size : 1);
-+ ssize_t r = romfsarc_pread(shard, off, buf, size);
-+ CHECK(r == (ssize_t)size, "read '%s': %zd vs %llu", rel, r, (unsigned long long)size);
-+ // A read past this file's end lands in the next file's bytes: the archive is a flat
-+ // container, so the reader must not fabricate zeros. The fs layer clamps to the file
-+ // size (see h_fs_ReadFile), so this only checks the reader does not fail outright.
-+ char extra[16];
-+ ssize_t r2 = romfsarc_pread(shard, off + size, extra, sizeof extra);
-+ CHECK(r2 >= 0, "read past end of '%s' errored: %zd", rel, r2);
-+ free(buf);
-+ checked++;
-+ }
-+ }
-+ free(e);
-+ }
-+ CHECK(checked == (int)h.file_count, "walked %d files, header says %llu", checked, (unsigned long long)h.file_count);
-+
-+ // Missing paths
-+ CHECK(!romfsarc_stat_file("nope/nothing", NULL, NULL, NULL), "missing file is not found");
-+ CHECK(!romfsarc_is_dir("nope"), "missing dir is not a dir");
-+ CHECK(romfsarc_list("nope", ents, 4) < 0, "list of a missing dir fails");
-+
-+ // Root itself is a directory, and the empty path is not a file
-+ CHECK(romfsarc_is_dir(""), "root is a dir");
-+ CHECK(!romfsarc_stat_file("", NULL, NULL, NULL), "root is not a file");
-+
-+ romfsarc_close();
-+ CHECK(!romfsarc_active(), "closed");
-+ free(ents);
-+ printf(fails ? "%d FAILURES\n" : "all checks passed (%d files)\n", fails ? fails : checked);
-+ return fails ? 1 : 0;
-+}
-diff --git a/dm/tools/romfs_arc.py b/dm/tools/romfs_arc.py
-new file mode 100644
-index 00000000..000cb4c8
---- /dev/null
-+++ b/dm/tools/romfs_arc.py
-@@ -0,0 +1,270 @@
-+#!/usr/bin/env python3
-+"""Pack a RomFS tree into a ROMFSARC archive (one index file + N shard files).
-+
-+Why: Tears of the Kingdom's RomFS is 304,000 files. Copying that into an App's Documents takes
-+hours, and a 16 GB IPA with that many entries fails to install on iOS (PackageExtractionFailed).
-+An archive is ~120 files instead, so one copy moves it.
-+
-+Shard layout: files are grouped by their top-level directory (so one shard holds one kind of
-+content), then split so that no shard passes --shard-mib. Files are written in path order within
-+a shard; a shard never mixes content from different top-level directories unless that directory
-+alone exceeds the limit.
-+
-+Usage:
-+ romfs_arc.py pack <romfs dir> <output base> [--shard-mib 200]
-+ romfs_arc.py list <base> [path] # debug: list a directory
-+ romfs_arc.py verify <base> <romfs dir> # compare every file's bytes against the source tree
-+
-+Format: see dm/host/romfs_arc.h.
-+"""
-+import argparse
-+import collections
-+import os
-+import struct
-+import sys
-+
-+MAGIC = b"ROMFSARC"
-+VERSION = 1
-+HDR = 64
-+FILEREC = 32
-+DIRREC = 16
-+CHILD_DIR = 0x80000000
-+
-+
-+def fnv1a(data, h=0xCBF29CE484222325):
-+ for b in data:
-+ h = ((h ^ b) * 0x100000001B3) & 0xFFFFFFFFFFFFFFFF
-+ return h
-+
-+
-+def walk(root):
-+ """Every file and directory under root, as (relpath, size) / relpath. Relpaths use '/' and have
-+ no leading slash; the root itself is ''. Symlinks are followed (RomFS has none in the games
-+ seen so far); anything that is neither a file nor a directory is an error."""
-+ files, dirs = [], [""]
-+ for dp, dn, fn in os.walk(root):
-+ rel_dir = os.path.relpath(dp, root).replace(os.sep, "/")
-+ if rel_dir == ".":
-+ rel_dir = ""
-+ dn.sort()
-+ for d in dn:
-+ dirs.append(f"{rel_dir}/{d}" if rel_dir else d)
-+ for f in sorted(fn):
-+ p = os.path.join(dp, f)
-+ try:
-+ st = os.stat(p)
-+ except OSError as e:
-+ sys.exit(f"[RED] cannot stat {p}: {e}")
-+ files.append((f"{rel_dir}/{f}" if rel_dir else f, st.st_size))
-+ files.sort(key=lambda x: x[0])
-+ dirs.sort()
-+ return files, dirs
-+
-+
-+def plan_shards(files, shard_bytes):
-+ """Assign every file a shard. Files are grouped by top-level directory, keeping the walk order
-+ (path order) inside a group; a group is cut into shards of at most shard_bytes."""
-+ by_top = collections.OrderedDict()
-+ for rel, size in files:
-+ top = rel.split("/", 1)[0]
-+ by_top.setdefault(top, []).append((rel, size))
-+ # Big groups first, so the shard count stays close to the size total / shard_bytes
-+ order = sorted(by_top.items(), key=lambda kv: -sum(s for _, s in kv[1]))
-+ assign, shard = {}, 0
-+ for top, items in order:
-+ cur = 0
-+ for rel, size in items:
-+ if cur and cur + size > shard_bytes:
-+ shard += 1
-+ cur = 0
-+ assign[rel] = (shard, cur)
-+ cur += size
-+ shard += 1
-+ return assign, shard
-+
-+
-+def pack(romfs, base, shard_mib):
-+ shard_bytes = shard_mib << 20
-+ files, dirs = walk(romfs)
-+ total = sum(s for _, s in files)
-+ print(f"pack: {len(files):,} files, {len(dirs):,} directories, {total / 2**30:.2f} GiB", flush=True)
-+ assign, nshard = plan_shards(files, shard_bytes)
-+ print(f"pack: {nshard} shards of at most {shard_mib} MiB", flush=True)
-+
-+ # Shard files: written in path order within each shard
-+ per_shard = collections.defaultdict(list)
-+ for rel, size in files:
-+ per_shard[assign[rel][0]].append((rel, size))
-+ os.makedirs(os.path.dirname(base) or ".", exist_ok=True)
-+ written = 0
-+ for i in range(nshard):
-+ path = f"{base}.{i:02d}"
-+ with open(path, "wb") as out:
-+ for rel, size in sorted(per_shard[i]):
-+ with open(os.path.join(romfs, rel), "rb") as f:
-+ left = size
-+ while left:
-+ buf = f.read(min(left, 1 << 22))
-+ if not buf:
-+ sys.exit(f"[RED] {rel}: file shrank while packing")
-+ out.write(buf)
-+ left -= len(buf)
-+ written += size
-+ print(f"\r shard {i + 1}/{nshard}: {os.path.getsize(path) / 2**20:.0f} MiB", end="", flush=True)
-+ print(f"\n wrote {written / 2**30:.2f} GiB in {nshard} shards", flush=True)
-+
-+ # Name pool
-+ pool = bytearray()
-+ name_off = {}
-+
-+ def intern(s):
-+ if s not in name_off:
-+ name_off[s] = len(pool)
-+ pool.extend(s.encode("utf-8") + b"\0")
-+ return name_off[s]
-+
-+ for rel, _ in files:
-+ intern(rel)
-+ for d in dirs:
-+ intern(d)
-+
-+ # File table (sorted by path, same order as `files`)
-+ file_idx = {}
-+ ftab = bytearray()
-+ for n, (rel, size) in enumerate(files):
-+ file_idx[rel] = n
-+ shard, off = assign[rel]
-+ ftab += struct.pack("<IIQQII", intern(rel), shard, off, size, 0o644, 0)
-+
-+ # Directory table + child list. A directory's children are its immediate files and directories,
-+ # sorted by name, contiguous in the child list.
-+ dir_idx = {d: n for n, d in enumerate(dirs)}
-+ children_of = collections.defaultdict(list)
-+ for rel, _ in files:
-+ parent, _, name = rel.rpartition("/")
-+ children_of[parent].append((name, file_idx[rel]))
-+ for d in dirs:
-+ for sub in dirs:
-+ if sub and sub.rpartition("/")[0] == d and sub != d:
-+ # Only the leaf name goes in the child list; the directory's own path is in its record
-+ children_of[d].append((sub.rpartition("/")[2], dir_idx[sub] | CHILD_DIR))
-+
-+ dtab = bytearray()
-+ child_list = []
-+ for d in dirs:
-+ kids = sorted(children_of[d])
-+ first = len(child_list)
-+ child_list.extend(tag for _, tag in kids)
-+ dtab += struct.pack("<IIII", intern(d), first, len(kids), 0)
-+
-+ tree = bytearray()
-+ for rel, size in files:
-+ tree += f"{rel}\0{size}\0".encode()
-+ tree_hash = fnv1a(tree)
-+
-+ idx_path = f"{base}.idx"
-+ with open(idx_path, "wb") as out:
-+ out.write(struct.pack("<8sIIQQQQQQ", MAGIC, VERSION, nshard, 0, len(files), len(dirs),
-+ len(pool), 0, tree_hash))
-+ out.write(pool)
-+ out.write(ftab)
-+ out.write(dtab)
-+ out.write(struct.pack(f"<{len(child_list)}I", *child_list) if child_list else b"")
-+ print(f"pack: index {os.path.getsize(idx_path) / 2**20:.1f} MiB ({len(pool) / 2**20:.1f} MiB names, "
-+ f"{len(files):,} files, {len(dirs):,} directories), tree hash {tree_hash:016x}", flush=True)
-+ print(f"pack: total {nshard + 1} files", flush=True)
-+
-+
-+def load(base):
-+ with open(f"{base}.idx", "rb") as f:
-+ b = f.read()
-+ magic, ver, nshard, _pad, nfiles, ndirs, pool_sz, _r, tree_hash = struct.unpack_from("<8sIIQQQQQQ", b, 0)
-+ if magic != MAGIC or ver != VERSION:
-+ sys.exit("[RED] not a ROMFSARC index")
-+ pool = b[HDR:HDR + pool_sz]
-+ off = HDR + pool_sz
-+ files = []
-+ for i in range(nfiles):
-+ name_off, shard, foff, size, mode, _ = struct.unpack_from("<IIQQII", b, off + i * FILEREC)
-+ name = pool[name_off:pool.index(b"\0", name_off)].decode()
-+ files.append((name, shard, foff, size))
-+ off += nfiles * FILEREC
-+ dirs = []
-+ for i in range(ndirs):
-+ name_off, first, count, _ = struct.unpack_from("<IIII", b, off + i * DIRREC)
-+ name = pool[name_off:pool.index(b"\0", name_off)].decode()
-+ dirs.append((name, first, count))
-+ off += ndirs * DIRREC
-+ kids = struct.unpack_from(f"<{len(b) - off >> 2}I", b, off) if len(b) > off else ()
-+ return dict(nshard=nshard, files=files, dirs=dirs, kids=kids, tree_hash=tree_hash)
-+
-+
-+def cmd_list(base, path):
-+ a = load(base)
-+ target = path.strip("/")
-+ d = next((x for x in a["dirs"] if x[0] == target), None)
-+ if not d:
-+ sys.exit(f"[RED] no such directory: {target or '/'}")
-+ _, first, count = d
-+ print(f"{target or '/'}: {count} entries")
-+ for k in a["kids"][first:first + count]:
-+ if k & CHILD_DIR:
-+ print(f" d {a['dirs'][k & ~CHILD_DIR][0].rpartition('/')[2]}/")
-+ else:
-+ name, shard, off, size = a["files"][k]
-+ print(f" f {name.rpartition('/')[2]:50} {size:12,} shard {shard:3} off {off:,}")
-+
-+
-+def cmd_verify(base, romfs):
-+ a = load(base)
-+ print(f"verify: {len(a['files']):,} files")
-+ bad = 0
-+ for n, (rel, shard, off, size) in enumerate(a["files"]):
-+ src = os.path.join(romfs, rel)
-+ try:
-+ with open(src, "rb") as f:
-+ want = f.read()
-+ except OSError as e:
-+ print(f"[RED] missing source {rel}: {e}")
-+ bad += 1
-+ continue
-+ if len(want) != size:
-+ print(f"[RED] size mismatch {rel}: source {len(want)} archive {size}")
-+ bad += 1
-+ continue
-+ with open(f"{base}.{shard:02d}", "rb") as f:
-+ f.seek(off)
-+ got = f.read(size)
-+ if got != want:
-+ print(f"[RED] content mismatch {rel}")
-+ bad += 1
-+ if (n + 1) % 20000 == 0:
-+ print(f" {n + 1:,}/{len(a['files']):,}", flush=True)
-+ print(f"verify: {'OK' if not bad else f'{bad} problems'}")
-+ return 1 if bad else 0
-+
-+
-+def main():
-+ ap = argparse.ArgumentParser(description="Pack a RomFS tree into a ROMFSARC archive")
-+ sub = ap.add_subparsers(dest="cmd", required=True)
-+ p = sub.add_parser("pack")
-+ p.add_argument("romfs")
-+ p.add_argument("base")
-+ p.add_argument("--shard-mib", type=int, default=200)
-+ l = sub.add_parser("list")
-+ l.add_argument("base")
-+ l.add_argument("path", nargs="?", default="")
-+ v = sub.add_parser("verify")
-+ v.add_argument("base")
-+ v.add_argument("romfs")
-+ a = ap.parse_args()
-+ if a.cmd == "pack":
-+ pack(a.romfs, a.base, a.shard_mib)
-+ elif a.cmd == "list":
-+ cmd_list(a.base, a.path)
-+ else:
-+ sys.exit(cmd_verify(a.base, a.romfs))
-+
-+
-+if __name__ == "__main__":
-+ main()
-diff --git a/docs/ROMFS_ARCHIVE.md b/docs/ROMFS_ARCHIVE.md
-new file mode 100644
-index 00000000..44bc93f2
---- /dev/null
-+++ b/docs/ROMFS_ARCHIVE.md
-@@ -0,0 +1,95 @@
-+# RomFS archive (ROMFSARC)
-+
-+A whole RomFS tree packed into one index file plus ~100 shard files, so a game whose RomFS is
-+hundreds of thousands of files can be copied to a phone as one folder instead of a directory tree.
-+
-+## Why
-+
-+Tears of the Kingdom's RomFS is 304,243 files / 15.9 GiB. Two problems follow:
-+
-+- **The IPA does not install.** A 16.6 GB IPA with 372,660 entries fails on iOS with
-+ `PackageExtractionFailed (Could not extract archive)`. The install daemon's extractor gives up:
-+ one directory holds 75,941 files and the ZIP64 central directory starts at 17.8 GB.
-+- **Copying the tree is slow.** The Files app and Finder both do one round trip per file; 304,243
-+ small files take hours and often break partway.
-+
-+Packing the tree into 127 files makes the copy one operation of ~16 GB and lets the IPA stay small.
-+
-+## Using it
-+
-+### 1. Pack the game files
-+
-+```bash
-+python3 dm/tools/romfs_arc.py pack <RomFS dir> <output base> --shard-mib 200
-+```
-+
-+`<RomFS dir>` is the directory `nx_extract` wrote (the one holding `Pack/`, `Banc/`, `Sound/`, …).
-+`<output base>` is a path prefix: the tool writes `<base>.idx` and `<base>.00`, `<base>.01`, ….
-+Files are grouped by top-level directory and cut so no shard passes `--shard-mib`, so one shard
-+holds one kind of content and no shard is unreasonably large.
-+
-+For TotK at 200 MiB per shard: 126 shards + 1 index = **127 files**.
-+
-+### 2. Copy it to the phone
-+
-+Put the whole set in the app's `Documents/romfs/`, keeping the base name:
-+
-+```
-+Documents/romfs/romfs.idx
-+Documents/romfs/romfs.00
-+...
-+Documents/romfs/romfs.125
-+```
-+
-+The app looks for `romfs.idx` first (`dm/ios/Sources/main.m`, `romfs_locate`); a plain directory
-+tree is still accepted when there is no index.
-+
-+### 3. Build the app without the RomFS
-+
-+```bash
-+DM_NO_ROMFS=1 GAME=<title id> W=... PATCHED=... ROMFS=... MSL_IOS=... \
-+ dm/ios/tools/build_ipa.sh out.ipa
-+```
-+
-+The package then holds only the app, the shader libraries and the tables (~750 MB for TotK), and
-+the game files come from `Documents/romfs/` at run time.
-+
-+## Checking an archive
-+
-+```bash
-+python3 dm/tools/romfs_arc.py list <base> [path] # list one directory
-+python3 dm/tools/romfs_arc.py verify <base> <RomFS> # compare every file's bytes with the source
-+```
-+
-+`verify` reads all 304,243 files of TotK's archive in about a minute and prints `verify: OK`.
-+
-+## Format
-+
-+See `dm/host/romfs_arc.h` for the byte layout. In short: a 64-byte header, a NUL-separated name
-+pool, a file table sorted by path (32 bytes each), a directory table (16 bytes each) and a child
-+list. Path lookup is a binary search; a directory listing walks one contiguous child range.
-+
-+The reader (`dm/host/romfs_arc.c`) maps the index with `mmap` and opens shards lazily, keeping up
-+to 256 descriptors. Reads go straight to `pread` on the shard, so the page cache still works.
-+
-+## How the fs layer uses it
-+
-+`hle_fs.c` keeps its normal path handling. When an archive is open, `host_path_ex` returns a
-+synthetic path (`@romfsarc:<guest path>`) for entries on the archive mount instead of a host file
-+path; `OpenFile`, `GetEntryType`, `OpenDirectory` and the directory calls recognise that prefix and
-+route to `romfs_arc.c`. File handles for archive entries are marked with bit 63 so they never
-+collide with real fds, and `ReadFile` clamps to the file size (a shard is a flat container, so a
-+read past the end would otherwise return the next file's bytes).
-+
-+The mount is recognised by its **directory**, not its name: titles differ (`rom` for most games,
-+`content` for Tears of the Kingdom).
-+
-+## Limitations
-+
-+- **Read-only.** Writes go to the save/temp mounts as before; the archive is never written.
-+- **Case-sensitive lookup.** The archive stores the names exactly as the source tree had them, so
-+ the case-insensitive alias machinery the host uses for APFS directories is bypassed.
-+- **Symlinks are followed at pack time.** No supported game's RomFS has any.
-+- **The index is held in memory.** 28 MB for TotK (17.9 MB of it names); the shards are not.
-+- **No dedup or compression.** Shards are the source bytes verbatim, so `verify` is a plain
-+ comparison and a repack is deterministic.
diff --git a/patches/0003-ios-game-data-folder.patch b/patches/0003-ios-game-data-folder.patch
index 4927cd8d..293d3152 100644
--- a/patches/0003-ios-game-data-folder.patch
+++ b/patches/0003-ios-game-data-folder.patch
@@ -10,15 +10,15 @@ Upstream-Status: pending
Reason: Several games in one app, game data on an external drive: Documents/games/<id>/{romfs.img,romfs,msl,save,temp} and a Files-app pick of the data folder (needs the runtime profile). iOS twin of seedds/nxnative#460, which is Mac only
Issue: LNPANDY/NX2Apple#123
---
- dm/ios/Sources/DataBookmark.h | 32 ++++++++
- dm/ios/Sources/DataBookmark.m | 79 ++++++++++++++++++
- dm/ios/Sources/DmIOS-Bridging-Header.h | 3 +
- dm/ios/Sources/Launcher.swift | 88 ++++++++++++++++++++
+ dm/ios/Sources/DataBookmark.h | 32 +++++++
+ dm/ios/Sources/DataBookmark.m | 79 +++++++++++++++++
+ dm/ios/Sources/DmIOS-Bridging-Header.h | 7 ++
+ dm/ios/Sources/Launcher.swift | 90 +++++++++++++++++++
dm/ios/Sources/front_ios.m | 13 ++-
- dm/ios/Sources/main.m | 109 +++++++++++++++++++++++--
+ dm/ios/Sources/main.m | 116 +++++++++++++++++++++++--
dm/ios/project.yml | 1 +
- dm/ios/tests/test_romfs_startup.py | 41 +++++++++-
- 8 files changed, 354 insertions(+), 12 deletions(-)
+ dm/ios/tests/test_romfs_startup.py | 41 ++++++++-
+ 8 files changed, 367 insertions(+), 12 deletions(-)
create mode 100644 dm/ios/Sources/DataBookmark.h
create mode 100644 dm/ios/Sources/DataBookmark.m
create mode 100644 dm/ios/Sources/DmIOS-Bridging-Header.h
@@ -148,18 +148,22 @@ index 00000000..3dcc3834
+}
diff --git a/dm/ios/Sources/DmIOS-Bridging-Header.h b/dm/ios/Sources/DmIOS-Bridging-Header.h
new file mode 100644
-index 00000000..92a2b3a5
+index 00000000..161a40de
--- /dev/null
+++ b/dm/ios/Sources/DmIOS-Bridging-Header.h
-@@ -0,0 +1,3 @@
+@@ -0,0 +1,7 @@
+// What Swift sees of the app's Objective-C: the data bookmark the Files app hands out (see
+// DataBookmark.h). project.yml points SWIFT_OBJC_BRIDGING_HEADER here.
+#import "DataBookmark.h"
++
++// main.m: set when the game data found is an old shard archive (romfs.idx), which is no longer read. The sentence names the
++// action (re-send the game data as romfs.img from the launcher), or NULL. The launcher's Game data section shows it.
++const char *dm_old_archive_message(void);
diff --git a/dm/ios/Sources/Launcher.swift b/dm/ios/Sources/Launcher.swift
-index dc63e4e3..df41a708 100644
+index dc63e4e3..32cb6a24 100644
--- a/dm/ios/Sources/Launcher.swift
+++ b/dm/ios/Sources/Launcher.swift
-@@ -8,6 +8,93 @@ import os
+@@ -8,6 +8,95 @@ import os
private func info(_ key: String) -> Any? { Bundle.main.object(forInfoDictionaryKey: key) }
@@ -215,6 +219,8 @@ index dc63e4e3..df41a708 100644
+ picked = dm_picked_data_path(&stale) ?? ""
+ if stale.boolValue && picked.isEmpty {
+ note = "The location you picked before is no longer readable (the app was signed differently). Please choose it again."
++ } else if note.isEmpty, let old = dm_old_archive_message() {
++ note = String(cString: old)
+ }
+ }
+}
@@ -253,7 +259,7 @@ index dc63e4e3..df41a708 100644
private struct LauncherView: View {
@ObservedObject var m: LauncherModel
let play: () -> Void
-@@ -45,6 +132,7 @@ private struct LauncherView: View {
+@@ -45,6 +134,7 @@ private struct LauncherView: View {
} footer: {
Text("Brings back all settings this game was tested with.")
}
@@ -307,7 +313,7 @@ index db2e49ea..80def564 100644
- (BOOL)prefersHomeIndicatorAutoHidden { return YES; }
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures { return UIRectEdgeAll; } // Edge gestures need two swipes, to avoid accidental exits
diff --git a/dm/ios/Sources/main.m b/dm/ios/Sources/main.m
-index fb37046e..5afddbb6 100644
+index fb37046e..b2064dca 100644
--- a/dm/ios/Sources/main.m
+++ b/dm/ios/Sources/main.m
@@ -7,9 +7,10 @@
@@ -322,26 +328,33 @@ index fb37046e..5afddbb6 100644
#include "romfs_identity.h"
#include "player_env.h"
#ifndef DM_PLAYER_BUILD
-@@ -40,9 +41,59 @@ static int romfs_identity_accepts(NSString *img) {
+@@ -40,9 +41,66 @@ static int romfs_identity_accepts(NSString *img) {
if (rc != ROMFS_ID_OK && rc != ROMFS_ID_NONE) fprintf(stderr, "[RED] boot: Documents/romfs.img is not the image this build needs (verdict %d); not used\n", rc);
return rc == ROMFS_ID_OK || rc == ROMFS_ID_NONE;
}
-+// A folder holds this game's files if it has a ROMFSARC index or the profile's marker path.
++// Set when a folder holds an old shard archive (romfs.idx): the launcher's Game data section shows it.
++static char g_old_archive[200];
++const char *dm_old_archive_message(void) { return g_old_archive[0] ? g_old_archive : NULL; }
++// A folder holds this game's files if it has the profile's marker path.
+// Shared by romfs_locate and the per-game layout below, so both answer the same question.
+static BOOL romfs_dir_ok(NSString *d) {
+ NSFileManager *fm = NSFileManager.defaultManager;
-+ // A ROMFSARC archive: <dir>/romfs.idx next to romfs.NN shards. The host opens it when DM_ROMFS
-+ // points at the base; the marker check does not apply (there are no directories to walk).
-+ if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@"romfs.idx"]]) return YES;
+ // A plain directory tree: only one containing the game profile's romfs_marker path counts
+ // (Mario: System/Resource, the resource size table). Runtime profile: the marker is a profile
+ // value now; the compiled macro is only what dm_profile() falls back to without DM_PROFILE.
-+ return [fm fileExistsAtPath:[d stringByAppendingPathComponent:@(dm_profile()->romfs_marker)]];
++ if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@(dm_profile()->romfs_marker)]]) return YES;
++ // ROMFSARC shard archives (<dir>/romfs.idx next to romfs.NN) are no longer read: the folder is
++ // reported as holding no game data, and the log and the launcher's Game data section name the action.
++ if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@"romfs.idx"]]) {
++ snprintf(g_old_archive, sizeof g_old_archive, "The game data here is an old shard archive (romfs.idx), which this version no longer reads. Re-send the game data as romfs.img from the launcher.");
++ fprintf(stderr, "boot: %s holds an old RomFS shard archive (romfs.idx), which is no longer read. Re-send the game data as romfs.img from the launcher\n", d.fileSystemRepresentation);
++ }
++ return NO;
+}
+
+// Where one game's data lives under the per-game layout: Documents/games/<title ID>/, holding
+// romfs.img the whole RomFS as one image file (what scripts/push_romfs.sh sends), or
-+// romfs/ a ROMFSARC archive or a plain tree, for copies made before images
++// romfs/ a plain tree, for copies made before images
+// msl/ this game's Metal shader libraries (optional; the app's own dm/ is used otherwise)
+// save/ temp/ this game's saves and scratch space
+// The layout exists so several games can share one installed app and so the game data can sit on
@@ -382,7 +395,7 @@ index fb37046e..5afddbb6 100644
NSString *img = [doc stringByAppendingPathComponent:@"romfs.img"];
if (romfs_image_complete(img) && romfs_identity_accepts(img)) {
// A folder copy from before images is now dead weight of up to many GB (often cut off partway). Deleting its 300,000 files here took longer than iOS allows an app to start
-@@ -58,13 +109,48 @@ static int romfs_identity_accepts(NSString *img) {
+@@ -58,13 +116,48 @@ static int romfs_identity_accepts(NSString *img) {
}
NSString *bundledImage = [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs.img"];
NSString *documentFolder = [doc stringByAppendingPathComponent:@"romfs"];
@@ -433,7 +446,7 @@ index fb37046e..5afddbb6 100644
// Boot prerequisites (done before UIApplicationMain): directories / environment variables / log -- the host's early load reads these
// Why a slim build found no usable game files: the verdict on Documents/romfs.img, in the log and for the screen (front_ios_boot_message). NULL when the build has no romfs.id
static char g_boot_message[640];
-@@ -127,15 +213,20 @@ static int boot_env(void) {
+@@ -127,15 +220,20 @@ static int boot_env(void) {
NSString *lang = [NSBundle.mainBundle objectForInfoDictionaryKey:@"DMLanguage"];
if (!getenv("DM_LANG") && [lang isKindOfClass:NSString.class] && lang.length) setenv("DM_LANG", lang.UTF8String, 0);
fprintf(stderr, "boot: game language %s\n", getenv("DM_LANG") ?: "en-US");
diff --git a/patches/0009-mac-keymap.patch b/patches/0009-mac-keymap.patch
index 114bc71a..f635c4e5 100644
--- a/patches/0009-mac-keymap.patch
+++ b/patches/0009-mac-keymap.patch
@@ -224,7 +224,7 @@ index 00000000..56fa4993
+}
+static int pad_map_is_default(const pad_map *m) { for (int b = 0; b < IM_BUTTONS; b++) if (m->to[b] != b) return 0; return 1; }
diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile
-index c60063b5..0b0a7799 100644
+index 3fbba0ac..50befe6e 100644
--- a/dm/host/tests/Makefile
+++ b/dm/host/tests/Makefile
@@ -12,7 +12,7 @@ QUIET = $(if $(strip $(SAN)),,2>/dev/null)
diff --git a/patches/0013-touchpad-geometry.patch b/patches/0013-touchpad-geometry.patch
deleted file mode 100644
index 40ea4832..00000000
--- a/patches/0013-touchpad-geometry.patch
+++ /dev/null
@@ -1,369 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: v0lumehi <[email protected]>
-Date: Wed, 28 Oct 2026 13:33:55 +0100
-Subject: [PATCH] Virtual-pad geometry and its test
-
-touchpad_geometry.h and t_touchpad_geometry.c.
-
-Upstream-Status: fork-only
-Reason: Virtual-pad geometry used by tests only; a fork experiment without a hook in the host
-Issue: LNPANDY/NX2Apple#123
----
- dm/host/tests/Makefile | 4 +
- dm/host/tests/t_touchpad_geometry.c | 131 ++++++++++++++++++++
- dm/host/touchpad_geometry.h | 179 ++++++++++++++++++++++++++++
- 3 files changed, 314 insertions(+)
- create mode 100644 dm/host/tests/t_touchpad_geometry.c
- create mode 100644 dm/host/touchpad_geometry.h
-
-diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile
-index 0b0a7799..93a17e8f 100644
---- a/dm/host/tests/Makefile
-+++ b/dm/host/tests/Makefile
-@@ -12,6 +12,7 @@ QUIET = $(if $(strip $(SAN)),,2>/dev/null)
- GINC = $(if $(strip $(GAME)),-I../gen/$(GAME) -I../../games/$(GAME),$(error GAME is not set: make GAME=<base game title ID>: $(shell python3 ../../games/game.py list | awk -F'\t' '{printf "%s (%s) ", $$1, $$3}')))
- $(B)/t_fs $(B)/t_fs_case $(B)/t_fs_commit_list $(B)/t_fs_commit_list_tsan: ../romfs_image.h
- GAME_H = ../gen/$(GAME)/game_profile.h
-+run: $(B)/t_touchpad_geometry
- run: $(B)/t_language $(B)/t_motion $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_commit_list $(B)/t_thread_leak $(B)/t_fs_case $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_condvar $(B)/t_condvar_old $(B)/t_pctl $(B)/t_time $(B)/t_shared_font $(B)/t_vorbis $(B)/t_vorbis_divides $(B)/t_hid $(B)/t_input_map $(B)/t_launcher_contract $(B)/t_haptics $(B)/t_haptics_apple
- $(B)/t_language
- $(B)/t_heap_size
-@@ -49,6 +50,7 @@ run: $(B)/t_language $(B)/t_motion $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture
- $(B)/t_launcher_contract
- $(B)/t_haptics
- $(B)/t_haptics_apple
-+ $(B)/t_touchpad_geometry
- $(B)/t_nro
- $(B)/t_symbols
- run: $(B)/t_nro
-@@ -151,6 +153,8 @@ $(B)/t_hid_tsan: t_hid.c ../hle_hid.c ../motion_fusion.h ../hle_haptics.c ../hle
- $(CLANG) -O1 -g -fsanitize=thread -Wall -Werror -Wno-unused-function -I.. $(GINC) -o $@ t_hid.c ../hle_haptics.c
- $(B)/t_haptics: t_haptics.c ../hle_haptics.c ../hle_haptics.h ../dm_input.h | $(B)
- $(CLANG) -O1 -g -Wall -Werror -I.. -o $@ t_haptics.c ../hle_haptics.c
-+$(B)/t_touchpad_geometry: t_touchpad_geometry.c ../touchpad_geometry.h ../dm_input.h | $(B)
-+ $(CLANG) -O1 -Wall -I.. $(GINC) -o $@ t_touchpad_geometry.c
- $(B)/t_haptics_apple: t_haptics_apple.m ../haptics_apple.m ../haptics_apple.h ../hle_haptics.c ../hle_haptics.h | $(B)
- $(CLANG) -O1 -g -fobjc-arc -Wall -Werror -I.. -o $@ t_haptics_apple.m ../hle_haptics.c -framework Cocoa -framework GameController -framework CoreHaptics -framework IOKit
- $(B)/t_time: t_time.c ../hle_time.c ../hle.h ../dm.h $(GAME_H) | $(B)
-diff --git a/dm/host/tests/t_touchpad_geometry.c b/dm/host/tests/t_touchpad_geometry.c
-new file mode 100644
-index 00000000..bad6c625
---- /dev/null
-+++ b/dm/host/tests/t_touchpad_geometry.c
-@@ -0,0 +1,131 @@
-+#include "../touchpad_geometry.h"
-+#include <assert.h>
-+#include <math.h>
-+#include <stdio.h>
-+
-+static void nearf(float actual, float expected, float tolerance) {
-+ assert(fabsf(actual - expected) <= tolerance);
-+}
-+
-+static void test_layout(float width, float height, float expected_u) {
-+ float u = dm_touchpad_u(height);
-+ nearf(u, expected_u, 0.0001f);
-+
-+ dm_touchpad_point face = dm_touchpad_face_center(width, height, 0, 0, 0, 0);
-+ dm_touchpad_point stick = dm_touchpad_stick_home(width, height, 0, 0, 0, 0);
-+ dm_touchpad_point dpad = dm_touchpad_dpad_center(width, height, 0, 0, 0, 0);
-+ nearf(face.x, width - DM_TP_FACE_X * u, 0.001f);
-+ nearf(face.y, height - DM_TP_PAD_Y * u, 0.001f);
-+ nearf(stick.x, DM_TP_STICK_X * u, 0.001f);
-+ nearf(stick.y, height - DM_TP_PAD_Y * u, 0.001f);
-+ nearf(dpad.x, DM_TP_LOW_X * u, 0.001f);
-+ nearf(dpad.y, height - DM_TP_LOW_Y * u, 0.001f);
-+
-+ dm_touchpad_point a = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 0);
-+ dm_touchpad_point b = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 1);
-+ dm_touchpad_point x = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 2);
-+ dm_touchpad_point y = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 3);
-+ float gap = DM_TP_FACE_GAP * u;
-+ nearf(a.x - face.x, gap, 0.001f); nearf(a.y, face.y, 0.001f);
-+ nearf(b.y - face.y, gap, 0.001f); nearf(b.x, face.x, 0.001f);
-+ nearf(x.y - face.y, -gap, 0.001f); nearf(x.x, face.x, 0.001f);
-+ nearf(y.x - face.x, -gap, 0.001f); nearf(y.y, face.y, 0.001f);
-+}
-+
-+static void test_directional_ownership(void) {
-+ const float cx = 400, cy = 300, gap = 50, radius = 33.75f;
-+ assert(dm_touchpad_face_buttons(cx + gap, cy, cx, cy, gap, radius) & DM_BTN_A);
-+ assert(dm_touchpad_face_buttons(cx, cy + gap, cx, cy, gap, radius) & DM_BTN_B);
-+ assert(dm_touchpad_face_buttons(cx, cy - gap, cx, cy, gap, radius) & DM_BTN_X);
-+ assert(dm_touchpad_face_buttons(cx - gap, cy, cx, cy, gap, radius) & DM_BTN_Y);
-+
-+ const float r = 48;
-+ assert(dm_touchpad_dpad_buttons(cx + r, cy, cx, cy, r) == DM_BTN_RIGHT);
-+ assert(dm_touchpad_dpad_buttons(cx, cy - r, cx, cy, r) == DM_BTN_UP);
-+ assert(dm_touchpad_dpad_buttons(cx - r, cy, cx, cy, r) == DM_BTN_LEFT);
-+ assert(dm_touchpad_dpad_buttons(cx, cy + r, cx, cy, r) == DM_BTN_DOWN);
-+ assert(dm_touchpad_dpad_buttons(cx + r, cy - r, cx, cy, r) == (DM_BTN_RIGHT | DM_BTN_UP));
-+ assert(dm_touchpad_dpad_buttons(cx, cy, cx, cy, r) == 0); // native centre dead region
-+}
-+
-+static void test_stick_shaping(void) {
-+ const float r = 77;
-+ int32_t x, y;
-+ dm_touchpad_stick_axis(r * 0.05f, 0, r, 0, &x, &y);
-+ assert(x == 0 && y == 0); // dead zone
-+
-+ dm_touchpad_stick_axis(r * 0.45f, 0, r, 0, &x, &y);
-+ assert(x >= 16383 && x <= 16384 && y == 0); // half of full travel after dead-zone remap
-+
-+ dm_touchpad_stick_axis(0, -r, r, 0, &x, &y);
-+ assert(x == 0 && y == DM_STICK_MAX);
-+ dm_touchpad_stick_axis(-r, 0, r, 0, &x, &y);
-+ assert(x == -DM_STICK_MAX && y == 0);
-+
-+ dm_touchpad_stick_axis(r * 0.1f, 0, r, 1, &x, &y);
-+ assert(x == DM_STICK_MAX && y == 0); // legacy full-tilt right-stick mode
-+}
-+
-+static void test_safe_insets_and_resize(void) {
-+ dm_touchpad_rect safe = dm_touchpad_safe_rect(844, 390, 42, 0, 42, 21);
-+ nearf(safe.x, 42, 0.001f); nearf(safe.y, 0, 0.001f);
-+ nearf(safe.width, 760, 0.001f); nearf(safe.height, 369, 0.001f);
-+
-+ dm_touchpad_rect corner = dm_touchpad_corner_rect(844, 390, 42, 0, 42, 21);
-+ nearf(corner.x, 21, 0.001f); nearf(corner.width, 802, 0.001f);
-+ nearf(corner.height, 369, 0.001f);
-+ dm_touchpad_point face = dm_touchpad_face_center(844, 390, 42, 0, 42, 21);
-+ dm_touchpad_point stick = dm_touchpad_stick_home(844, 390, 42, 0, 42, 21);
-+ float u = 390.0f / 430.0f;
-+ nearf(face.x, 21 + 802 - DM_TP_FACE_X * u, 0.001f);
-+ nearf(stick.x, 21 + DM_TP_STICK_X * u, 0.001f);
-+
-+ // 16:9 and 21:10 both cap control size at 1.3; a short resized window scales down.
-+ test_layout(1920, 1080, 1.3f);
-+ test_layout(1680, 800, 1.3f);
-+ test_layout(1280, 430, 1.0f);
-+}
-+
-+static void test_botw_right_cluster_and_camera_tap(void) {
-+ for (int i = 0; i < 2; i++) {
-+ float w = i ? 1920.0f : 844.0f, h = i ? 1080.0f : 390.0f;
-+ float u = dm_touchpad_u(h);
-+ dm_touchpad_point face = dm_touchpad_face_center(w,h,0,0,0,0);
-+ dm_touchpad_point r = dm_touchpad_right_shoulder(w,h,0,0,0,0,0);
-+ dm_touchpad_point zr = dm_touchpad_right_shoulder(w,h,0,0,0,0,1);
-+ dm_touchpad_point x = dm_touchpad_face_button(w,h,0,0,0,0,2);
-+ nearf(r.y,zr.y,0.001f);
-+ nearf(zr.x-r.x,(DM_TP_ZL_R*2+DM_TP_SHOULDER_GAP)*u,0.001f);
-+ assert(r.y + DM_TP_ZL_R*u < x.y - DM_TP_FACE_R*u);
-+ assert(zr.x + DM_TP_ZL_R*u < w);
-+ float xgr = DM_TP_FACE_R * u * 1.25f;
-+ float shoulder_hit = DM_TP_ZL_R * u * DM_TP_SHOULDER_HIT_SCALE;
-+ assert(hypotf(r.x-x.x,r.y-x.y) > shoulder_hit+xgr);
-+ assert(hypotf(zr.x-x.x,zr.y-x.y) > shoulder_hit+xgr);
-+ assert(face.y > 0);
-+
-+ float slop = DM_TP_LOOK_TAP_SLOP*u;
-+ assert(!dm_touchpad_look_dragged(400,200,400+slop*.5f,200,slop));
-+ assert(dm_touchpad_look_dragged(400,200,400+slop*1.1f,200,slop));
-+ // A drag that returns to its start is still classified as a drag by the caller's sticky flag.
-+ int dragged = dm_touchpad_look_dragged(400,200,400+slop*1.1f,200,slop);
-+ assert(dragged);
-+ assert(dm_touchpad_look_tap(.2f,0));
-+ assert(!dm_touchpad_look_tap(.36f,0));
-+ assert(!dm_touchpad_look_tap(.1f,1));
-+ assert(dm_touchpad_look_double_tap(10000000.08,10000000.28,100,100,101,102,u));
-+ assert(!dm_touchpad_look_double_tap(10000000.08,10000000.48,100,100,101,102,u));
-+ assert(!dm_touchpad_look_double_tap(10000000.08,10000000.28,100,100,100+49*u,102,u));
-+ dragged |= dm_touchpad_look_dragged(400,200,400,200,slop);
-+ assert(dragged);
-+ }
-+}
-+
-+int main(void) {
-+ test_directional_ownership();
-+ test_stick_shaping();
-+ test_safe_insets_and_resize();
-+ test_botw_right_cluster_and_camera_tap();
-+ puts("touchpad geometry: direction ownership, layout, and stick shaping passed");
-+ return 0;
-+}
-diff --git a/dm/host/touchpad_geometry.h b/dm/host/touchpad_geometry.h
-new file mode 100644
-index 00000000..affbb2d1
---- /dev/null
-+++ b/dm/host/touchpad_geometry.h
-@@ -0,0 +1,179 @@
-+// Shared virtual-pad geometry for the UIKit controls and the opt-in Mac preview.
-+#pragma once
-+#include <math.h>
-+
-+typedef struct { float x, y; } dm_touchpad_point;
-+typedef struct { float x, y, width, height; } dm_touchpad_rect;
-+
-+#include "dm_input.h"
-+
-+#define DM_TP_ZL_X 44.0f
-+#define DM_TP_ZL_Y 40.0f
-+#define DM_TP_ZL_R 26.0f
-+#define DM_TP_L_X 44.0f
-+#define DM_TP_L_Y 108.0f
-+#define DM_TP_L_R 24.0f
-+#define DM_TP_DROP_TIP 1.45f
-+#define DM_TP_CORNER_IN 0.5f
-+#define DM_TP_FACE_X 81.0f
-+#define DM_TP_PAD_Y 82.0f
-+#define DM_TP_FACE_GAP 50.0f
-+#define DM_TP_FACE_R 27.0f
-+#define DM_TP_PILL_DX 52.0f
-+#define DM_TP_PILL_Y 22.0f
-+#define DM_TP_PILL_W 50.0f
-+#define DM_TP_PILL_H 28.0f
-+#define DM_TP_SWAP_R 15.0f
-+#define DM_TP_STICK_X 81.0f
-+#define DM_TP_STICK_R 77.0f
-+#define DM_TP_KNOB_R 30.0f
-+#define DM_TP_STICK_GRAB 1.4f
-+#define DM_TP_LSWIPE (1.0f / 3.0f)
-+#define DM_TP_FULL 0.8f
-+#define DM_TP_DEAD 0.1f
-+#define DM_TP_LOW_X 231.0f
-+#define DM_TP_LOW_Y 64.0f
-+#define DM_TP_DPAD_R 48.0f
-+#define DM_TP_ARM_W 17.0f
-+#define DM_TP_ARM_IN 11.0f
-+#define DM_TP_DPAD_GRAB 1.3f
-+#define DM_TP_RSTICK_R 60.0f
-+#define DM_TP_RSWIPE (1.0f / 2.0f)
-+#define DM_TP_CLICK_X 102.0f
-+#define DM_TP_CLICK_R 17.0f
-+#define DM_TP_LOOK_TAP_SLOP 12.0f
-+#define DM_TP_LOOK_TAP_MAX_SECONDS 0.35f
-+#define DM_TP_LOOK_DOUBLE_TAP_INTERVAL 0.35f
-+#define DM_TP_LOOK_DOUBLE_TAP_DISTANCE 48.0f
-+#define DM_TP_SHOULDER_GAP 8.0f
-+#define DM_TP_SHOULDER_HIT_SCALE 1.0f
-+
-+static inline float dm_touchpad_u(float height) {
-+ float u = height / 430.0f;
-+ return u < 1.3f ? u : 1.3f;
-+}
-+
-+// safe insets and result use top-left coordinates, as UIKit does. AppKit
-+// callers convert their bottom-left mouse coordinates at the view boundary.
-+static inline dm_touchpad_rect dm_touchpad_corner_rect(float width, float height,
-+ float left, float top,
-+ float right, float bottom) {
-+ return (dm_touchpad_rect){left * .5f, top, width - (left + right) * .5f,
-+ height - top - bottom};
-+}
-+
-+static inline dm_touchpad_rect dm_touchpad_safe_rect(float width, float height,
-+ float left, float top,
-+ float right, float bottom) {
-+ return (dm_touchpad_rect){left, top, width - left - right, height - top - bottom};
-+}
-+
-+static inline dm_touchpad_point dm_touchpad_face_center(float width, float height,
-+ float left, float top,
-+ float right, float bottom) {
-+ dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);
-+ float u = dm_touchpad_u(height);
-+ return (dm_touchpad_point){c.x + c.width - DM_TP_FACE_X * u,
-+ c.y + c.height - DM_TP_PAD_Y * u};
-+}
-+
-+// R and ZR sit together just above the face cluster on BOTW's virtual pad.
-+static inline dm_touchpad_point dm_touchpad_right_shoulder(float width, float height,
-+ float left, float top,
-+ float right, float bottom,
-+ int zr) {
-+ dm_touchpad_point face = dm_touchpad_face_center(width, height, left, top, right, bottom);
-+ float u = dm_touchpad_u(height);
-+ float half = (DM_TP_ZL_R + DM_TP_SHOULDER_GAP * .5f) * u;
-+ float y = face.y - (DM_TP_FACE_GAP + DM_TP_FACE_R + DM_TP_ZL_R + 18.0f) * u;
-+ return (dm_touchpad_point){face.x + (zr ? half : -half), y};
-+}
-+
-+static inline int dm_touchpad_look_dragged(float down_x, float down_y,
-+ float x, float y, float slop) {
-+ float dx = x - down_x, dy = y - down_y;
-+ return dx * dx + dy * dy > slop * slop;
-+}
-+static inline int dm_touchpad_look_tap(float duration, int dragged) {
-+ return !dragged && duration >= 0.0f && duration <= DM_TP_LOOK_TAP_MAX_SECONDS;
-+}
-+static inline int dm_touchpad_look_double_tap(double first_time, double second_time,
-+ float first_x, float first_y,
-+ float second_x, float second_y,
-+ float u) {
-+ float dx = second_x - first_x, dy = second_y - first_y;
-+ double dt = second_time - first_time;
-+ float limit = DM_TP_LOOK_DOUBLE_TAP_DISTANCE * u;
-+ return dt >= 0.0f && dt <= DM_TP_LOOK_DOUBLE_TAP_INTERVAL && dx*dx + dy*dy <= limit*limit;
-+}
-+
-+static inline dm_touchpad_point dm_touchpad_stick_home(float width, float height,
-+ float left, float top,
-+ float right, float bottom) {
-+ dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);
-+ float u = dm_touchpad_u(height);
-+ return (dm_touchpad_point){c.x + DM_TP_STICK_X * u,
-+ c.y + c.height - DM_TP_PAD_Y * u};
-+}
-+
-+static inline dm_touchpad_point dm_touchpad_dpad_center(float width, float height,
-+ float left, float top,
-+ float right, float bottom) {
-+ dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);
-+ float u = dm_touchpad_u(height);
-+ return (dm_touchpad_point){c.x + DM_TP_LOW_X * u,
-+ c.y + c.height - DM_TP_LOW_Y * u};
-+}
-+
-+static inline dm_touchpad_point dm_touchpad_face_button(float width, float height,
-+ float left, float top,
-+ float right, float bottom,
-+ int button) {
-+ dm_touchpad_point c = dm_touchpad_face_center(width, height, left, top, right, bottom);
-+ float g = DM_TP_FACE_GAP * dm_touchpad_u(height);
-+ switch (button) {
-+ case 0: c.x += g; break; // A
-+ case 1: c.y += g; break; // B
-+ case 2: c.y -= g; break; // X
-+ default: c.x -= g; break; // Y
-+ }
-+ return c;
-+}
-+
-+static inline uint64_t dm_touchpad_face_buttons(float x, float y, float center_x,
-+ float center_y, float gap, float radius) {
-+ uint64_t bits = 0;
-+ for (int b = 0; b < 4; b++) {
-+ dm_touchpad_point c = {center_x, center_y};
-+ if (b == 0) c.x += gap;
-+ else if (b == 1) c.y += gap;
-+ else if (b == 2) c.y -= gap;
-+ else c.x -= gap;
-+ float dx = x - c.x, dy = y - c.y;
-+ if (dx * dx + dy * dy <= radius * radius) bits |= 1ull << b;
-+ }
-+ return bits;
-+}
-+
-+static inline uint64_t dm_touchpad_dpad_buttons(float x, float y, float center_x,
-+ float center_y, float radius) {
-+ float dx = x - center_x, dy = y - center_y;
-+ if (hypotf(dx, dy) < radius * .25f) return 0;
-+ float a = atan2f(-dy, dx) * (180.0f / 3.14159265358979323846f);
-+ uint64_t bits = 0;
-+ if (a > -67.5f && a < 67.5f) bits |= DM_BTN_RIGHT;
-+ if (a > 22.5f && a < 157.5f) bits |= DM_BTN_UP;
-+ if (a > 112.5f || a < -112.5f) bits |= DM_BTN_LEFT;
-+ if (a < -22.5f && a > -157.5f) bits |= DM_BTN_DOWN;
-+ return bits;
-+}
-+
-+static inline void dm_touchpad_stick_axis(float dx, float dy, float radius,
-+ int full_tilt, int32_t *x, int32_t *y) {
-+ float d = hypotf(dx, dy), dead = radius * DM_TP_DEAD;
-+ if (d <= (full_tilt ? 0.0f : dead) || radius <= 0.0f) { *x = *y = 0; return; }
-+ float magnitude = (full_tilt ? 1.0f : fminf((d - dead) / (radius * DM_TP_FULL - dead), 1.0f)) / d;
-+ *x = (int32_t)lrintf(dx * magnitude * DM_STICK_MAX);
-+ *y = (int32_t)lrintf(-dy * magnitude * DM_STICK_MAX);
-+}
-+
diff --git a/patches/0015-fork-docs.patch b/patches/0015-fork-docs.patch
index df2370a2..cf2d6128 100644
--- a/patches/0015-fork-docs.patch
+++ b/patches/0015-fork-docs.patch
@@ -13,14 +13,14 @@ Issue: LNPANDY/NX2Apple#123
docs/MULTIPLAYER.md | 139 +++++++++++++++
docs/RELEASE-NOTES-GUIDE.md | 105 +++++++++++
docs/RELEASE_NOTES.md | 77 ++++++++
- docs/ROADMAP.md | 140 +++++++++++++++
+ docs/ROADMAP.md | 139 +++++++++++++++
docs/WORK-IN-PROGRESS.md | 88 ++++++++++
docs/badges/games.json | 6 +
docs/badges/verified.json | 6 +
docs/launcher-c-design.md | 339 ++++++++++++++++++++++++++++++++++++
docs/launcher-c-plan.md | 213 ++++++++++++++++++++++
docs/probe-dlopen.md | 64 +++++--
- 11 files changed, 1262 insertions(+), 15 deletions(-)
+ 11 files changed, 1261 insertions(+), 15 deletions(-)
create mode 100644 dm/ios/ENTITLEMENTS.md
create mode 100644 docs/MULTIPLAYER.md
create mode 100644 docs/RELEASE-NOTES-GUIDE.md
@@ -479,10 +479,10 @@ index 00000000..2f1132cb
+- **GabeThe21stGamer**:暴露了旧工具与无证书两条路径的报告(#87),以及免证书安装的免费 Apple ID 实测。
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
new file mode 100644
-index 00000000..35472c99
+index 00000000..25ab8a5c
--- /dev/null
+++ b/docs/ROADMAP.md
-@@ -0,0 +1,140 @@
+@@ -0,0 +1,139 @@
+# Roadmap: what to do next, and why
+
+Three investigations ran in parallel (runtime profiles for a universal launcher, a survey of
@@ -492,7 +492,7 @@ index 00000000..35472c99
+## 1. Touch look and native aspect — the one capability we do not have
+
+**From [devinhurry/touch-the-wild](https://github.com/devinhurry/touch-the-wild)** (not in
-+upstream's tree: `hle_look.c`, `touchpad_geometry.h`, `hle_botw_touchhud.c`, `hle_aspect.c`
++upstream's tree: `hle_look.c`, `touchpad_geometry.h` (once carried here as an experiment, since dropped), `hle_botw_touchhud.c`, `hle_aspect.c`
+all verified absent from seedds/nxnative).
+
+Today the only way to turn the camera on a phone is holding a virtual right stick, which turns
@@ -612,9 +612,8 @@ index 00000000..35472c99
+if 4–8 games in one app is worth it, and C needs a `dlopen` experiment before any commitment.
+
+External storage on iOS: `UIDocumentPickerViewController` for the folder, persist a security-
-+scoped bookmark in UserDefaults, store the ROMFSARC index and shards there. `romfs_arc.c`
-+already `pread`s per shard, so an external path works unchanged —
-+`main.m romfs_locate` only checks `Documents/romfs` and `<App>/romfs` today.
++scoped bookmark in UserDefaults, store the picked location there (done: `romfs.img` is read from any
++security-scoped path, `dm_picked_data_path`; the shard-archive reader this note first assumed is gone).
+
+## Safety note from the fork survey
+
@@ -743,7 +742,7 @@ index 00000000..92b31479
+}
diff --git a/docs/launcher-c-design.md b/docs/launcher-c-design.md
new file mode 100644
-index 00000000..bc814c7d
+index 00000000..476a1c1e
--- /dev/null
+++ b/docs/launcher-c-design.md
@@ -0,0 +1,339 @@
@@ -980,11 +979,11 @@ index 00000000..bc814c7d
+- **游戏列表** = 扫描两个来源后按 title id 连接:
+ 1. **代码**:`Bundle.main/Frameworks/*.framework`,读每个 framework `Resources/game.manifest.json`
+ (构建时生成,第 3.2 节),运行期用 `getsectiondata`/段存在性做交叉校验(防 manifest 与段不一致)。
-+ 不建议扫 `romfs.idx` 当列表依据——romfs 是用户可移动的数据(外置盘是计划能力:romfs_arc.c 按分片
++ 不建议扫数据文件当列表依据——romfs 是用户可移动的数据(外置盘是计划能力:当时设想按分片
+ pread,天然支持外部路径,但今天 `main.m romfs_locate` 只查 per-game/Documents/bundle 三处,
+ 文件夹选择器是待办,ROADMAP:129-132),代码在不在 bundle 里才是"装没装"。
+ 2. **数据**:`Documents/games/*/`,"这个目录是不是一个游戏的文件"的判定已经存在:
-+ `main.m:19-28 romfs_dir_ok`(有 `romfs.idx` 或 profile 的 `romfs_marker` 路径即算)。
++ `main.m:19-28 romfs_dir_ok`(有 profile 的 `romfs_marker` 路径即算;旧的 `romfs.idx` 分片归档已不再读取)。
+ - 列表状态:代码+数据 = 可玩,只有代码 = 提示"把 romfs 放进 Files",只有数据 = 灰显"IPA 里没有这个游戏
+ 的 framework(需要重签安装)"——这条提示就是 2.2 结论的用户可见面。
+- **存档隔离**:已经有了。`Documents/games/<id>/{save,temp}`,`main.m:95-104`:
@@ -1088,7 +1087,7 @@ index 00000000..bc814c7d
+> **Update (merged):** the dlopen probe now exists — `dm/ios/probe/` with `build_probe.sh`, committed alongside this document, and `probe-out/DmProbe.ipa` is built. W1 step 1 is done. What remains is running it on an iOS 26 device and reading `Documents/probe-log.txt`.
diff --git a/docs/launcher-c-plan.md b/docs/launcher-c-plan.md
new file mode 100644
-index 00000000..ab13b78d
+index 00000000..e6e253c5
--- /dev/null
+++ b/docs/launcher-c-plan.md
@@ -0,0 +1,213 @@
@@ -1197,7 +1196,7 @@ index 00000000..ab13b78d
+ `pickedDataBookmark.<titleID>` with migration, `GameData.m` resolves like `main.m:69–117` with
+ explicit title id/marker, `GameLauncher.m` sets `DM_AOC_DIR`, `DM_MSL_DIR`, `DM_PSO_BUNDLE`
+ per game first and then app-wide, `LauncherSettings` is per game, and `GameLibrary` never treats
-+ `romfs.idx` as "code installed" (design §233–240).
++ a data file as "code installed" (design §233–240).
+- Done when: two titles' `Documents/games/<id>/{romfs.img,romfs,save,temp,msl,pso,aoc}` are
+ isolated, a stale bookmark falls back, an identity mismatch falls back, and DLC `aoc/<index>.img`
+ mounts (`hle_fs.c:516-518`).
@@ -1215,7 +1214,7 @@ index 00000000..ab13b78d
+`nro_count > 0`) — a mismatch marks the game `broken` without affecting others.
+
+Discovery: frameworks come from `Bundle.main.privateFrameworksURL/*.framework` and data from
-+`Documents/games/<title_id>/` (`romfs.img` complete, or `romfs/romfs.idx`, or
++`Documents/games/<title_id>/` (`romfs.img` complete, or
+`romfs/<manifest.romfs_marker>`), with a per-title bookmark for external drives, and the results merge into
+playable / needsData / needsFramework / broken.
+
diff --git a/patches/0017-fork-patches-stamp.patch b/patches/0017-fork-patches-stamp.patch
index 46d2323e..484271c2 100644
--- a/patches/0017-fork-patches-stamp.patch
+++ b/patches/0017-fork-patches-stamp.patch
@@ -23,10 +23,10 @@ Issue: LNPANDY/NX2Apple#123
6 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/dm/ios/Sources/main.m b/dm/ios/Sources/main.m
-index 5afddbb6..c4c84e5d 100644
+index b2064dca..bec90271 100644
--- a/dm/ios/Sources/main.m
+++ b/dm/ios/Sources/main.m
-@@ -178,6 +178,9 @@ static int boot_env(void) {
+@@ -185,6 +185,9 @@ static int boot_env(void) {
NSString *log = [doc stringByAppendingPathComponent:@"log.txt"], *prev = [doc stringByAppendingPathComponent:@"log.prev.txt"];
[fm removeItemAtPath:prev error:nil]; [fm moveItemAtPath:log toPath:prev error:nil];
if (freopen(log.fileSystemRepresentation, "w", stderr)) setvbuf(stderr, NULL, _IOLBF, 0);
diff --git a/patches/0025-cloud-saves.patch b/patches/0025-cloud-saves.patch
index 7e22ba68..e30547e7 100644
--- a/patches/0025-cloud-saves.patch
+++ b/patches/0025-cloud-saves.patch
@@ -15,7 +15,6 @@ Tested: dm/host/tests/t_save_sync.c (47 checks, also under TSan and ASan/UBSan),
Upstream-Status: forwarded seedds/nxnative#617
Reason: Cross-save between a game's Mac and iPhone apps through an iCloud Drive folder the player picks (CloudKit needs entitlements these signings do not have)
Issue: none yet
-
---
dm/host/Makefile | 4 +-
dm/host/hle_fs.c | 11 +
@@ -41,15 +40,15 @@ Issue: none yet
create mode 100644 dm/ios/Sources/SaveSync.m
diff --git a/dm/host/Makefile b/dm/host/Makefile
-index 2baa234b..2ea17ce7 100644
+index 410b6ce4..b85ae360 100644
--- a/dm/host/Makefile
+++ b/dm/host/Makefile
@@ -16,7 +16,7 @@ endif
GAME_H = gen/$(GAME)/game_profile.h
CFLAGS=-O1 -g -Wall -Wno-unused-function
# Service-layer takeover hle_*.c files are included by wildcard: adding a file does not touch this line (avoids merge conflicts)
--SRC=main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
-+SRC=main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c save_sync.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
+-SRC=main.c loader.c hle.c crash.c probe.c thread.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
++SRC=main.c loader.c hle.c crash.c probe.c thread.c save_sync.c memstat.m haptics_apple.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S
# NVN null device + nn::vi + the Vulkan layer (dm/gfx/)
# Sources under dm/gfx, dm/gfx/nvn, dm/gfx/tex, dm/gfx/vk and dm/gfx/gl are included by wildcard (tests/ and metal/ do not go into the host): adding a file does not touch this line
GFX=$(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/nvn/*.m ../gfx/nvn/*.S ../gfx/tex/*.c ../gfx/tex/*.m ../gfx/vk/*.m ../gfx/gl/*.m))
@@ -63,10 +62,10 @@ index 2baa234b..2ea17ce7 100644
clean: # the host and everything make generates for it (gen/: the profile headers, the game stamp and the libvpx build; dmhost_* and *.dSYM beside them, as in .gitignore)
rm -rf gen dmhost dmhost_* *.dSYM
diff --git a/dm/host/hle_fs.c b/dm/host/hle_fs.c
-index 643306f9..df984ef6 100644
+index 035dbc04..75457a03 100644
--- a/dm/host/hle_fs.c
+++ b/dm/host/hle_fs.c
-@@ -18,6 +18,7 @@
+@@ -17,6 +17,7 @@
#include <sys/clonefile.h>
#include <sys/xattr.h>
#include "romfs_image.h"
@@ -74,7 +73,7 @@ index 643306f9..df984ef6 100644
// Every take-over in this file runs on the big host stack (hle_bigstack.c): path buffers are sized by PATH_MAX and one file open takes 6-7 KB of stack, while a game's save thread can have as little as 8 KB (Super Mario 3D World + Bowser's Fury)
#undef HLE_FORCE
-@@ -632,6 +633,7 @@ HLE_FORCE("_ZN2nn2fs13MountSaveDataEPKcRKNS_7account3UidE", "fsp-srv; save data
+@@ -596,6 +597,7 @@ HLE_FORCE("_ZN2nn2fs13MountSaveDataEPKcRKNS_7account3UidE", "fsp-srv; save data
const char *d = getenv("DM_SAVE");
if (!d) die("DM_SAVE is not set: point it at a writable copy of a save directory");
char dd[1024]; strlcpy(dd, d, sizeof dd); size_t L = strlen(dd); while (L > 1 && dd[L - 1] == '/') dd[--L] = 0; // strip trailing slashes (.work / .new are appended at the same level)
@@ -82,7 +81,7 @@ index 643306f9..df984ef6 100644
return mount_ex(name, dd, 0, 1);
}
// Device save data: one save for the console instead of one per user. Animal Crossing: New Horizons keeps its island there (3.0.3's main mounts no account save data at all); the host
-@@ -644,6 +646,7 @@ HLE_FORCE("_ZN2nn2fs19MountDeviceSaveDataEPKc", "fsp-srv; device save data → t
+@@ -608,6 +610,7 @@ HLE_FORCE("_ZN2nn2fs19MountDeviceSaveDataEPKc", "fsp-srv; device save data → t
const char *d = getenv("DM_SAVE");
if (!d) die("DM_SAVE is not set: point it at a writable copy of a save directory");
char dd[1024]; strlcpy(dd, d, sizeof dd); size_t L = strlen(dd); while (L > 1 && dd[L - 1] == '/') dd[--L] = 0;
@@ -90,7 +89,7 @@ index 643306f9..df984ef6 100644
strlcat(dd, "_device", sizeof dd);
return mount_ex(name, dd, 0, 1);
}
-@@ -653,6 +656,13 @@ HLE_FORCE("_ZN2nn2fs20ExtendDeviceSaveDataEll", "fsp-srv; extend device save dat
+@@ -617,6 +620,13 @@ HLE_FORCE("_ZN2nn2fs20ExtendDeviceSaveDataEll", "fsp-srv; extend device save dat
HLE_FORCE("_ZN2nn2fs22GetSaveDataRestoreFlagEPbPKc", "fsp-srv; save data restored from a backup: never", Result, h_fs_RestoreFlag, uint8_t *out, const char *name) { (void)name; *out = 0; return RES_OK; }
static _Atomic uint64_t g_save_commits; // number of successful commits (used by the front end when going to background to wait for "the game's current save has been committed")
uint64_t dm_fs_commit_count(void) { return atomic_load(&g_save_commits); }
@@ -104,7 +103,7 @@ index 643306f9..df984ef6 100644
// Both Commit overloads share this transaction engine. Caller holds the path
// and mount locks; front-end failure notification is delivered after unlocking.
static Result commit_mount_locked(int i, int *notify_error) {
-@@ -698,6 +708,7 @@ static Result commit_mount_locked(int i, int *notify_error) {
+@@ -662,6 +672,7 @@ static Result commit_mount_locked(int i, int *notify_error) {
static int n; if (r == RES_OK) { uint64_t tc2 = clock_gettime_nsec_np(CLOCK_MONOTONIC);
LOG("save commit #%d: %s swapped atomically into %s (%d save writes so far) (clone + swap %llu us, since this transaction's first write %llu us)", ++n, g_mnt[i].dir, g_mnt[i].commit, atomic_load(&g_save_writes),
(unsigned long long)((tc2 - tc1) / 1000), (unsigned long long)(tw0 ? (tc2 - tw0) / 1000 : 0)); atomic_fetch_add(&g_save_commits, 1);
@@ -703,10 +702,10 @@ index 00000000..4f16f89c
+// Clones the committed save folder `dir` to `to` while no Commit can swap it (hle_fs.c takes its lock; the default, with no host running, does not need one). 0 on success
+int dm_fs_clone_committed(const char *dir, const char *to);
diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile
-index 26bc1eac..1998f813 100644
+index 50befe6e..89904bc7 100644
--- a/dm/host/tests/Makefile
+++ b/dm/host/tests/Makefile
-@@ -21,6 +21,7 @@ run: $(B)/t_motion $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t
+@@ -22,6 +22,7 @@ run: $(B)/t_language $(B)/t_motion $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture
TMPDIR="$(abspath $(B))" $(B)/t_fs_commit_list
$(B)/t_thread_leak
TMPDIR="$(abspath $(B))" $(B)/t_fs_case $(QUIET)
@@ -718,28 +717,28 @@ index 26bc1eac..1998f813 100644
$(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_gesture.c ../hle_touch.c
$(B)/t_thread_leak: t_thread_leak.c ../thread.c ../dm.h $(GAME_H) | $(B)
$(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_thread_leak.c
--$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../romfs_arc.c ../hle_profile.c
--$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-- $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../romfs_arc.c ../hle_profile.c
+-$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../hle_profile.c
+-$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+- $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../hle_profile.c
-$(B)/t_fs_commit_list_tsan: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) | $(B)
- $(CLANG) -O1 -g -fsanitize=thread -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../hle_profile.c
-+$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
-+$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
++$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
++ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
++$(B)/t_fs_commit_list: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
++ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
+$(B)/t_fs_commit_list_tsan: t_fs_commit_list.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) | $(B)
+ $(CLANG) -O1 -g -fsanitize=thread -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_fs_commit_list.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
.PHONY: fs-tsan
fs-tsan: $(B)/t_fs_commit_list_tsan
TMPDIR="$(abspath $(B))" $(B)/t_fs_commit_list_tsan
--$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../romfs_arc.c ../hle_profile.c
-+$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
+-$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
+- $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../hle_profile.c
++$(B)/t_fs_case: t_fs_case.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
++ $(CLANG) -O1 -Wno-unused-function -I.. $(GINC) -o $@ t_fs_case.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
+run: $(B)/t_save_sync
-+$(B)/t_save_sync: t_save_sync.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../romfs_arc.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
-+ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_save_sync.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../romfs_arc.c ../hle_profile.c
++$(B)/t_save_sync: t_save_sync.c t_fs_stub.c ../hle_fs.c ../save_sync.c ../save_sync.h ../hle_bigstack.c ../hle.h ../dm.h $(GAME_H) ../hle_profile.c ../hle_profile.h | $(B)
++ $(CLANG) -O1 -Wall -Wno-unused-function -I.. $(GINC) -o $@ t_save_sync.c t_fs_stub.c ../hle_bigstack.c ../save_sync.c ../hle_profile.c
+.PHONY: save-sync
+save-sync: $(B)/t_save_sync
+ TMPDIR="$(abspath $(B))" $(B)/t_save_sync $(QUIET)
@@ -1097,7 +1096,7 @@ index 3dcc3834..bd5a1ec9 100644
+ } else if (fromPick) { unsetenv("DM_SAVE_SYNC"); fromPick = NO; }
+}
diff --git a/dm/ios/Sources/Launcher.swift b/dm/ios/Sources/Launcher.swift
-index df41a708..53ad595c 100644
+index 32cb6a24..d62e5c1c 100644
--- a/dm/ios/Sources/Launcher.swift
+++ b/dm/ios/Sources/Launcher.swift
@@ -4,6 +4,7 @@
@@ -1108,7 +1107,7 @@ index df41a708..53ad595c 100644
import os
private func info(_ key: String) -> Any? { Bundle.main.object(forInfoDictionaryKey: key) }
-@@ -64,15 +65,66 @@ private struct GameDataSection: View {
+@@ -66,15 +67,66 @@ private struct GameDataSection: View {
}
}
@@ -1176,7 +1175,7 @@ index df41a708..53ad595c 100644
picker.allowsMultipleSelection = false
picker.delegate = context.coordinator
return picker
-@@ -133,6 +185,7 @@ private struct LauncherView: View {
+@@ -135,6 +187,7 @@ private struct LauncherView: View {
Text("Brings back all settings this game was tested with.")
}
GameDataSection()
@@ -1250,7 +1249,7 @@ index 00000000..2d9d1e52
+ }
+}
diff --git a/dm/ios/Sources/front_ios.m b/dm/ios/Sources/front_ios.m
-index 56a432f1..fc79813e 100644
+index 80def564..a5fed12b 100644
--- a/dm/ios/Sources/front_ios.m
+++ b/dm/ios/Sources/front_ios.m
@@ -9,6 +9,8 @@
@@ -1262,7 +1261,7 @@ index 56a432f1..fc79813e 100644
UIView *dm_gamepad_view(CGRect frame);
void dm_gamepad_reset(void);
-@@ -79,6 +81,7 @@ - (void)startGame {
+@@ -80,6 +82,7 @@ - (void)startGame {
lb.text = @"Game files not found.\nPut the RomFS folder into this App's Documents as \"romfs\" (Files app), then restart.";
[self.view addSubview:lb]; return;
}
@@ -1270,7 +1269,7 @@ index 56a432f1..fc79813e 100644
front_hud_env(); // before the game view makes its device (an env file's DM_METAL_HUD sets it in main.m already)
self.game = [[DmGameView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.game];
-@@ -271,11 +274,23 @@ static void front_ios_audio_watch(void) {
+@@ -272,11 +275,23 @@ static void front_ios_audio_watch(void) {
// Scene lifecycle (called by SceneDelegate in main.m): 0 resign active, 1 enter background, 2 return to foreground, 3 become active. On entering background, freeze the guest clock and suspend after in-flight GPU work completes (submitting GPU work in background gets the process killed).
// The screen stays on while the game is active: only touches reset the idle timer, so with a controller (or during a cutscene) the screen dimmed and locked mid-game
@@ -1408,7 +1407,7 @@ index 2cf5f549..4124e726 100644
fprintf(stderr, "launcher: the host exited with %d\n", WEXITSTATUS(status));
return WEXITSTATUS(status);
diff --git a/dm/mac/pack_app.py b/dm/mac/pack_app.py
-index 6f28830c..74048300 100755
+index afadf7af..3adf27bb 100755
--- a/dm/mac/pack_app.py
+++ b/dm/mac/pack_app.py
@@ -84,12 +84,13 @@ def swift_sources(): # the settings window, with the iOS launcher's model and
@@ -1429,7 +1428,7 @@ index 6f28830c..74048300 100755
def make_icns(jpg, out): # the game's icon (256x256 JPEG) at every size an .icns holds
-@@ -219,7 +220,7 @@ def pack(a):
+@@ -228,7 +229,7 @@ def pack(a):
if not codesign: raise SystemExit('codesign is not available')
codesign = Path(codesign).resolve()
minos = min_os(a.host)
@@ -1439,7 +1438,7 @@ index 6f28830c..74048300 100755
'trees': [(p, inventory(Path(p))) for p in (a.romfs, a.aoc) if p],
'tools': [[str(c), c.stat().st_mode, c.stat().st_size, c.stat().st_mtime_ns, c.stat().st_ctime_ns, run([c, '--version']).strip()] for c in (clang, swiftc)] + [
diff --git a/dm/tools/tests/test_nsp_mac_app.py b/dm/tools/tests/test_nsp_mac_app.py
-index eaffe27b..9dee8fc0 100644
+index c1f6d997..2826142b 100644
--- a/dm/tools/tests/test_nsp_mac_app.py
+++ b/dm/tools/tests/test_nsp_mac_app.py
@@ -117,7 +117,7 @@ class PackReuse(unittest.TestCase):
@@ -1471,10 +1470,10 @@ index eaffe27b..9dee8fc0 100644
def test_selected_file_modes_and_file_additions_and_removals_invalidate(self):
diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv
-index e8b7ca63..a03fc1e9 100644
+index 370739f9..044f8e27 100644
--- a/docs/env_switches.tsv
+++ b/docs/env_switches.tsv
-@@ -254,6 +254,7 @@ DM_RUMBLE_LOG diagnostic `=1` logs the game's vibration handle requests and, onc
+@@ -255,6 +255,7 @@ DM_RUMBLE_LOG diagnostic `=1` logs the game's vibration handle requests and, onc
DM_RUMBLE_MIN player `=0..0.9`: controller rumble levels below it stay silent and the rest is stretched over the full range (default 0; the phone is unaffected); for games whose quiet HD rumble texture keeps rotating motors running (Mario Kart 8 Deluxe: 0.45); launcher setting
DM_SAVE path This run's save folder (must be set); the device save is `<DM_SAVE>_device`, and `pso_user.tsv` goes in its parent folder; the Mac launcher, the iOS app and the NSP script set it
DM_SAVED_CHOICES switch `0` ignores the player's saved choices (launcher.<VAR> in the app's preferences) and leaves them saved; the Mac launcher and the iOS settings screen
diff --git a/patches/0026-lm3-depth-mode.patch b/patches/0026-lm3-depth-mode.patch
index 2cd923e7..5f2a6d55 100644
--- a/patches/0026-lm3-depth-mode.patch
+++ b/patches/0026-lm3-depth-mode.patch
@@ -12,7 +12,6 @@ Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream-Status: forwarded seedds/nxnative#580
Reason: Luigi's Mansion 3 sets depth mode near = 0: the profile key lets the bundled pipeline archive match
Issue: LNPANDY/NX2Apple#123
-
---
dm/games/0100DCA0064A6000/README.md | 2 ++
dm/games/0100DCA0064A6000/game.tsv | 3 +++
@@ -20,7 +19,7 @@ Issue: LNPANDY/NX2Apple#123
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/dm/games/0100DCA0064A6000/README.md b/dm/games/0100DCA0064A6000/README.md
-index 361d3ba..87328bc 100644
+index 361d3baf..87328bcb 100644
--- a/dm/games/0100DCA0064A6000/README.md
+++ b/dm/games/0100DCA0064A6000/README.md
@@ -34,6 +34,8 @@ No `patches.py`.
@@ -33,7 +32,7 @@ index 361d3ba..87328bc 100644
- **Current: shadow cascades from an array of driver-table handles** (586 pixel shaders: `array<texture2d_array<float>, 32> fp_t2das_cb2_0`, `shaders with a binding whose slot was not decoded 588`), indexed by (0x80 + a cascade offset) ÷ 8 over the driver table c2 (`c2_array`).
- **Resolved: the boot aborted in Metal's pipeline validation** (`MTLPixelFormatDepth16Unorm is not color renderable`): a 1024×1024 D16 texture (a shadow) is drawn through an R16 view. Such a pass now draws into a colour shadow of the same pixel size, copied in before and back after the pass (`shrt_block`; D16 and D32F; not D24S8).
diff --git a/dm/games/0100DCA0064A6000/game.tsv b/dm/games/0100DCA0064A6000/game.tsv
-index 2003f56..8b95071 100644
+index 2003f565..8b95071b 100644
--- a/dm/games/0100DCA0064A6000/game.tsv
+++ b/dm/games/0100DCA0064A6000/game.tsv
@@ -50,3 +50,6 @@ pad_layout full
@@ -44,10 +43,10 @@ index 2003f56..8b95071 100644
+# (dm/gfx/tools/pso_offline.py). Without it the Mac prebuild made near = -w bases, the host refused the bundled archive and rebuilt 3,852 pairs at every start
+depth_mode zero
diff --git a/dm/games/README.md b/dm/games/README.md
-index 3228057..a8315ac 100644
+index d5bedb71..7c3c8618 100644
--- a/dm/games/README.md
+++ b/dm/games/README.md
-@@ -166,7 +166,7 @@ One row per profile; the notes are each profile's `README.md`.
+@@ -173,7 +173,7 @@ One row per profile; the notes are each profile's `README.md`.
| `alloc_big_align` | `on` / `off` (the default): `nn::mem::StandardAllocator::Allocate` aligns blocks of 64 KB or more to 64 KB (`hle_os.c`). Vanillaware's engine (13 Sentinels: Aegis Rim, Unicorn Overlord) takes a memory pool's storage from malloc and cuts ring heaps out of it at 64 KB alignment relative to the pool's GPU address. On the Switch that address is big-page aligned; the host's is the CPU address, only 4 KB aligned, so the last ring heap does not fit and keeps base 0, and the game writes through a null pointer (13 Sentinels entering its first battle, Unicorn Overlord past the title screen) |
| `shared_font` | Optional, decided by the game files without it (the SDK version the host reads from the `sdk` module, `loader.c` `dm_sdk_major`, and `main`'s imports, `dm_main_imports`): what the shared-font address points at. `bfttf` (SDK 11 and later, when `main` imports `ScalableFontEngineHelper::Decode`) = the 8-byte BFTTF header (with the "already decoded" marker) followed by the TTF, which Mario passes to `Decode`; `ttf` = the TTF itself, which SDK 10 and older games hand straight to `ScalableFontEngine::LoadFont` (Super Mario 3D World + Bowser's Fury: with the header the engine fails with error 403 and the game crashes looking up a glyph; Odyssey, Link's Awakening, Age of Calamity and Three Houses alike) and Unity's player to FreeType (Patrick's Parabox: with the header its Japanese, Korean and Chinese text drew nothing). No profile sets it |
| `device_api` | Optional, decided by the SDK version without it: the NVN API version `major.minor` that `nvnDeviceGetInteger` reports, 55.15 for SDK 11 and later (what Mario requires) and 53.313 for SDK 10 and older (`hle_nvn.c` `nvn_api`). Games check it and skip creating their device on a mismatch: Super Mario 3D World + Bowser's Fury (SDK 10) requires major 53 and minor ≥ 313. No profile sets it. `DM_NVN_API` overrides. Not part of the shader chain version (only `shader_*` keys are) |
diff --git a/patches/series b/patches/series
index 533c7ae0..0786746c 100644
--- a/patches/series
+++ b/patches/series
@@ -1,6 +1,5 @@
# Applied in this order onto the commit in ../.upstream-ref with git am -3. See README.md.
0001-runtime-profile.patch
-0002-romfsarc.patch
0003-ios-game-data-folder.patch
0004-ios-slim-ipa.patch
0005-nsp-dotnet-home.patch
@@ -11,7 +10,6 @@
0010-mac-library-folder.patch
0011-hades2-update-profile.patch
0012-env-switches-verify.patch
-0013-touchpad-geometry.patch
0014-ios-probe.patch
0015-fork-docs.patch
0016-ref-hle-hid-d2r.patch
diff --git a/scripts/tests/test_patches.py b/scripts/tests/test_patches.py
index daa18178..d2f1367e 100644
--- a/scripts/tests/test_patches.py
+++ b/scripts/tests/test_patches.py
@@ -384,7 +384,7 @@ class HostTestRules(unittest.TestCase):
self.assertIn('-fsanitize=address,undefined', command)
rules = (REPO / 'dm/host/tests/Makefile').read_text().splitlines()
prerequisites = ' '.join(line for line in rules if line.startswith('run:'))
- for name in ('t_language', 't_input_map', 't_launcher_contract', 't_touchpad_geometry'):
+ for name in ('t_language', 't_input_map', 't_launcher_contract'):
self.assertIn(f'$(B)/{name}', prerequisites)
self.assertIn(f'\t$(B)/{name}', rules)