Skip to content

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

Automate upstream sync; per-game version list; recover lost fork features

LNPANDY0cc8671e2478
diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml
new file mode 100644
index 00000000..666168f4
--- /dev/null
+++ b/.github/workflows/sync-upstream.yml
@@ -0,0 +1,60 @@
+# Daily: follow upstream seedds/nxnative. The fork is a fresh repository (no shared git
+# history), so GitHub's own "Sync fork" does not apply; scripts/sync_upstream.py is the
+# sync instead — upstream's tree, the fork's features re-applied, then verification
+# (Python 3.9 parse, bash -n, the archive reader test, a macOS host build). Success is
+# committed and pushed; a failure opens an issue and pushes nothing.
+name: Sync upstream
+
+on:
+ schedule:
+ - cron: '30 21 * * *' # 21:30 UTC = 5:30 Beijing
+ workflow_dispatch:
+
+permissions:
+ contents: write
+ issues: write
+
+jobs:
+ sync:
+ runs-on: macos-latest # the host build needs clang + macOS headers
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Fetch upstream
+ run: |
+ git remote add upstream https://github.com/seedds/nxnative.git
+ git fetch upstream main
+
+ - name: Sync (and verify)
+ id: sync
+ run: |
+ LAST=$(cat .upstream-ref 2>/dev/null || true)
+ NEW=$(git rev-parse upstream/main)
+ echo "new=$NEW" >> "$GITHUB_OUTPUT"
+ if [ "$LAST" = "$NEW" ]; then echo "Already at $NEW"; exit 0; fi
+ python3 scripts/sync_upstream.py --old "${LAST:-$NEW}" --new "$NEW" 2>&1 | tee sync.log
+ exit ${PIPESTATUS[0]}
+
+ - name: Commit and push
+ if: success() && steps.sync.outcome == 'success'
+ run: |
+ git config user.name "sync-bot"
+ git config user.email "[email protected]"
+ git rev-parse upstream/main > .upstream-ref
+ git add -A
+ git diff --cached --quiet || git commit -m "Sync upstream $(git rev-parse --short upstream/main)"
+ git push
+
+ - name: Open an issue when the sync fails
+ if: failure()
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ NEW=$(git rev-parse upstream/main 2>/dev/null || echo '?')
+ tail -40 sync.log > sync-tail.log 2>/dev/null || echo "see the workflow log" > sync-tail.log
+ gh issue create --title "Upstream sync failed at ${NEW:0:7}" \
+ --body "The scheduled sync could not re-apply the fork's patches or verify the build. The tree is untouched on main; run scripts/sync_upstream.py locally to see the full picture.
+
+ \`\`\`
+ $(tail -40 sync.log 2>/dev/null)
+ \`\`\`" || echo "issue creation failed; the log is in sync.log"
diff --git a/.gitignore b/.gitignore
index 7ffc7cba..b48e0fa8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,7 @@ romfs.[0-9][0-9]
# Swift Package build products and the packaged app (rebuild with `swift build -c release`)
frontend/.build/
frontend/NS Port Builder.app/
+
+# Made from each shader build's Mac outputs (c1_guard.py, cb_extent.py; the NSP script makes them), not committed
+dm/games/*/c1_full.tsv
+dm/games/*/cb_extent.tsv
diff --git a/.upstream-ref b/.upstream-ref
new file mode 100644
index 00000000..802766ff
--- /dev/null
+++ b/.upstream-ref
@@ -0,0 +1 @@
+ebe75c9d5d34486f714678f850f0e74bbab398ac
diff --git a/README.md b/README.md
index 927eb786..f3d89cca 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,16 @@ Chinese (including which games are verified), are on the
[releases page](https://github.com/LNPANDY/nxnative-romfs-archive/releases) and in
[docs/RELEASE_NOTES.md](docs/RELEASE_NOTES.md).
+## Staying current with upstream
+
+A scheduled GitHub Actions workflow (`.github/workflows/sync-upstream.yml`, daily 21:30 UTC, also
+runnable by hand) follows [seedds/nxnative](https://github.com/seedds/nxnative): it re-applies this
+fork's features onto upstream's tree through `scripts/sync_upstream.py`, verifies the result
+(Python 3.9 parse of every script, `bash -n`, the archive reader test, a macOS host build) and
+pushes — or opens an issue with the log when a patch no longer fits, pushing nothing. The repo is a
+fresh repository rather than a true fork, so GitHub's own "Sync fork" does not apply here; the last
+synced upstream commit lives in `.upstream-ref`.
+
## Using it
### 1. Build the app (as upstream)
@@ -269,113 +279,62 @@ The mount is recognised by its **directory**, not its name: titles differ (`rom`
the game's build IDs, memory layout, shader tables and per-game switches — and this fork adds the
RomFS archive layer on top, so a large game can be installed at all.
-| Game | Title ID | Status |
-|---|---|---|
-| Super Mario Odyssey | `0100000000010000` | Playable on an iPhone (upstream) |
-| Ace Attorney Investigations Collection | `010005501E68C000` | Profile present; not verified on a phone |
-| Hollow Knight: Silksong | `010013C00E930000` | Profile present; not verified on a phone |
-| Digimon Story Cyber Sleuth: Complete Edition | `010014E00DB56000` | Profile present; not verified on a phone |
-| Super Mario Bros. Wonder | `010015100B514000` | Playable on an iPhone (upstream) |
-| Raging Loop | `010020400E1C2000` | Profile present; not verified on a phone |
-| ANIMAL WELL | `010020D01AD24000` | Playable on an iPhone (upstream) |
-| Super Mario 3D World + Bowser's Fury | `010028600EBDA000` | Playable on an iPhone (upstream) |
-| Hyrule Warriors: Age of Calamity | `01002B00111A2000` | Playable on an iPhone (upstream) |
-| Celeste | `01002B30028F6000` | Profile present; not verified on a phone |
-| The Great Ace Attorney Chronicles | `010036E00FB20000` | Playable on an iPhone (upstream) |
-| FINAL FANTASY TACTICS - The Ivalice Chronicles | `010038B015560000` | Profile present; not verified on a phone |
-| 13 Sentinels: Aegis Rim | `01003FC01670C000` | Playable on an iPhone (upstream) |
-| DARK SOULS: REMASTERED | `01004AB00A260000` | Profile present; not verified on a phone |
-| Monster Train 2 | `010051701FB46000` | Playable on an iPhone (upstream) |
-| OCTOPATH TRAVELER 0 | `01005270232F2000` | Profile present; not verified on a phone |
-| Hades | `0100535012974000` | Playable on an iPhone (upstream) |
-| Fire Emblem: Three Houses | `010055D009F78000` | Playable on an iPhone (upstream) |
-| FINAL FANTASY RESONANCE | `0100606026F12000` | Playable on an iPhone (upstream) |
-| Big Brain Academy: Brain vs. Brain | `0100620012D6E000` | Profile present; not verified on a phone |
-| Unicorn Overlord | `010069401ADB8000` | Profile present; not verified on a phone |
-| The Legend of Zelda: Link's Awakening | `01006BB00C6F0000` | Playable on an iPhone (upstream) |
-| DRAGON QUEST XI S: Echoes of an Elusive Age – Definitive Edition | `01006C300E9F0000` | Profile present; not verified on a phone |
-| Animal Crossing: New Horizons | `01006F8002326000` | Profile present; not verified on a phone |
-| AI: THE SOMNIUM FILES - nirvanA Initiative | `0100713016CCC000` | Playable on an iPhone (upstream) |
-| The Legend of Zelda: Breath of the Wild | `01007EF00011E000` | Playable on an iPhone (upstream) |
-| AI: THE SOMNIUM FILES | `010089B00D09C000` | Playable on an iPhone (upstream) |
-| STEINS;GATE RE:BOOT | `01008BC024FDE000` | Profile present; not verified on a phone |
-| Metroid Dread | `010093801237C000` | Playable on an iPhone (upstream) |
-| Super Mario Galaxy | `010099C022B96000` | Playable on an iPhone (upstream) |
-| Captain Toad: Treasure Tracker | `01009BF0072D4000` | Profile present; not verified on a phone |
-| Hades II | `0100A00019DE0000` | **Verified here** — Hades II — builds, installs and runs on an iPhone; 33-file archive |
-| Cuphead | `0100A5C00D162000` | Profile present; not verified on a phone |
-| Fire Emblem Engage | `0100A6301214E000` | Playable on an iPhone (upstream) |
-| Absolum | `0100A83022A22000` | Profile present; not verified on a phone |
-| DRAGON QUEST VII Reimagined | `0100A9D01C446000` | Profile present; not verified on a phone |
-| Monster Hunter Rise | `0100B04011742000` | Profile present; not verified on a phone |
-| Catherine: Full Body | `0100BF00112C0000` | Profile present; not verified on a phone |
-| Rhythm Heaven Groove | `0100D9F01D474000` | Profile present; not verified on a phone |
-| Luigi's Mansion 3 | `0100DCA0064A6000` | Playable on an iPhone (upstream) |
-| Patrick's Parabox | `0100E44016C22000` | Profile present; not verified on a phone |
-| Paper Mario: The Thousand-Year Door | `0100ECD018EBE000` | Profile present; not verified on a phone |
-| The Legend of Zelda: Tears of the Kingdom | `0100F2C0115B6000` | **Verified here** — Tears of the Kingdom — builds, installs and runs on an iPhone; 304,243 files into 127 archive shards, byte-verified |
-| Pokémon Legends: Z-A | `0100F43008C44000` | Profile present; not verified on a phone |
-| Brain Memory Training Academy | `0100F5D01DA3A000` | Profile present; not verified on a phone |
-| Super Mario Galaxy 2 | `0100FD8022DAA000` | Profile present; not verified on a phone |
-
-"Verified here" means the whole chain was exercised on this fork: build, install on an iPhone, run,
-and (for the archive) every file byte-compared against the source. "Playable on an iPhone (upstream)"
-means the upstream project reports it working; this fork has not re-tested those. A profile alone
-does not guarantee a title boots — the host changes a game needs are part of upstream's work, and
-this fork follows it.
-
-| Game | Title ID | Status |
-|---|---|---|
-| Super Mario Odyssey | `0100000000010000` | Playable on an iPhone (upstream) |
-| Ace Attorney Investigations Collection | `010005501E68C000` | Profile present; not verified on a phone |
-| Hollow Knight: Silksong | `010013C00E930000` | Profile present; not verified on a phone |
-| Digimon Story Cyber Sleuth: Complete Edition | `010014E00DB56000` | Profile present; not verified on a phone |
-| Super Mario Bros. Wonder | `010015100B514000` | Playable on an iPhone (upstream) |
-| Mario Kart 8 Deluxe | `0100152000022000` | Playable on an iPhone (upstream) |
-| Raging Loop | `010020400E1C2000` | Profile present; not verified on a phone |
-| ANIMAL WELL | `010020D01AD24000` | Playable on an iPhone (upstream) |
-| Super Mario 3D World + Bowser's Fury | `010028600EBDA000` | Playable on an iPhone (upstream) |
-| Hyrule Warriors: Age of Calamity | `01002B00111A2000` | Playable on an iPhone (upstream) |
-| Celeste | `01002B30028F6000` | Profile present; not verified on a phone |
-| The Great Ace Attorney Chronicles | `010036E00FB20000` | Playable on an iPhone (upstream) |
-| FINAL FANTASY TACTICS - The Ivalice Chronicles | `010038B015560000` | Profile present; not verified on a phone |
-| 13 Sentinels: Aegis Rim | `01003FC01670C000` | Playable on an iPhone (upstream) |
-| DARK SOULS: REMASTERED | `01004AB00A260000` | Profile present; not verified on a phone |
-| Monster Train 2 | `010051701FB46000` | Playable on an iPhone (upstream) |
-| OCTOPATH TRAVELER 0 | `01005270232F2000` | Profile present; not verified on a phone |
-| Hades | `0100535012974000` | Playable on an iPhone (upstream) |
-| Fire Emblem: Three Houses | `010055D009F78000` | Playable on an iPhone (upstream) |
-| FINAL FANTASY RESONANCE | `0100606026F12000` | Playable on an iPhone (upstream) |
-| Big Brain Academy: Brain vs. Brain | `0100620012D6E000` | Profile present; not verified on a phone |
-| Unicorn Overlord | `010069401ADB8000` | Profile present; not verified on a phone |
-| The Legend of Zelda: Link's Awakening | `01006BB00C6F0000` | Playable on an iPhone (upstream) |
-| DRAGON QUEST XI S: Echoes of an Elusive Age – Definitive Edition | `01006C300E9F0000` | Profile present; not verified on a phone |
-| Animal Crossing: New Horizons | `01006F8002326000` | Profile present; not verified on a phone |
-| AI: THE SOMNIUM FILES - nirvanA Initiative | `0100713016CCC000` | Playable on an iPhone (upstream) |
-| The Legend of Zelda: Breath of the Wild | `01007EF00011E000` | Playable on an iPhone (upstream) |
-| AI: THE SOMNIUM FILES | `010089B00D09C000` | Playable on an iPhone (upstream) |
-| STEINS;GATE RE:BOOT | `01008BC024FDE000` | Profile present; not verified on a phone |
-| Metroid Dread | `010093801237C000` | Playable on an iPhone (upstream) |
-| Super Mario Galaxy | `010099C022B96000` | Playable on an iPhone (upstream) |
-| Captain Toad: Treasure Tracker | `01009BF0072D4000` | Profile present; not verified on a phone |
-| Hades II | `0100A00019DE0000` | **Verified here** — Hades II — builds, installs and runs on an iPhone; 33-file archive |
-| Cuphead | `0100A5C00D162000` | Profile present; not verified on a phone |
-| Fire Emblem Engage | `0100A6301214E000` | Playable on an iPhone (upstream) |
-| Absolum | `0100A83022A22000` | Profile present; not verified on a phone |
-| DRAGON QUEST VII Reimagined | `0100A9D01C446000` | Profile present; not verified on a phone |
-| Monster Hunter Rise | `0100B04011742000` | Profile present; not verified on a phone |
-| Catherine: Full Body | `0100BF00112C0000` | Profile present; not verified on a phone |
-| Balatro | `0100CD801CE5E000` | Playable on an iPhone (upstream) |
-| Rhythm Heaven Groove | `0100D9F01D474000` | Profile present; not verified on a phone |
-| Luigi's Mansion 3 | `0100DCA0064A6000` | Playable on an iPhone (upstream) |
-| Patrick's Parabox | `0100E44016C22000` | Profile present; not verified on a phone |
-| Paper Mario: The Thousand-Year Door | `0100ECD018EBE000` | Profile present; not verified on a phone |
-| The Legend of Zelda: Tears of the Kingdom | `0100F2C0115B6000` | **Verified here** — Tears of the Kingdom — builds, installs and runs on an iPhone; 304,243 files into 127 archive shards, byte-verified |
-| Pokémon Legends: Z-A | `0100F43008C44000` | Profile present; not verified on a phone |
-| Brain Memory Training Academy | `0100F5D01DA3A000` | Profile present; not verified on a phone |
-| Super Mario Galaxy 2 | `0100FD8022DAA000` | Profile present; not verified on a phone |
-
-
+The update column is the version the build actually checks: the update NSP's display version
+must match the profile's registered build (the base game's own version does not matter — the
+update layers over it). "无(v0)" = the base game alone is enough.
+
+| Game | Title ID | Update required | Status |
+|---|---|---|---|
+| Super Mario Odyssey | `0100000000010000` | 1.4.1 (v393216) | Playable on an iPhone (upstream) |
+| Ace Attorney Investigations Collection | `010005501E68C000` | 1.0.0.2 (v131072) | Profile present; not verified on a phone |
+| Hollow Knight: Silksong | `010013C00E930000` | 1.0.30000 (v655360) | Profile present; not verified on a phone |
+| Digimon Story Cyber Sleuth: Complete Edition | `010014E00DB56000` | 1.0.3 (v196608) | Profile present; not verified on a phone |
+| Super Mario Bros. Wonder | `010015100B514000` | 1.2.1 (v327680) | Playable on an iPhone (upstream) |
+| Mario Kart 8 Deluxe | `0100152000022000` | 4.0.0 (v1441792) | Playable on an iPhone (upstream) |
+| Raging Loop | `010020400E1C2000` | 无(v0) | Profile present; not verified on a phone |
+| ANIMAL WELL | `010020D01AD24000` | 1.0.10 (v655360) | Playable on an iPhone (upstream) |
+| Super Mario 3D World + Bowser's Fury | `010028600EBDA000` | 1.2.2 (v262144) | Playable on an iPhone (upstream) |
+| Hyrule Warriors: Age of Calamity | `01002B00111A2000` | 1.3.0 (v327680) | Playable on an iPhone (upstream) |
+| Celeste | `01002B30028F6000` | 1.4.1.1 (v589824) | Profile present; not verified on a phone |
+| The Great Ace Attorney Chronicles | `010036E00FB20000` | 无(v0) | Playable on an iPhone (upstream) |
+| FINAL FANTASY TACTICS - The Ivalice Chronicles | `010038B015560000` | 1.4.0 (v393216) | Profile present; not verified on a phone |
+| 13 Sentinels: Aegis Rim | `01003FC01670C000` | 1.10 (v65536) | Playable on an iPhone (upstream) |
+| DARK SOULS: REMASTERED | `01004AB00A260000` | 1.0.3 (v196608) | Profile present; not verified on a phone |
+| Monster Train 2 | `010051701FB46000` | 1.1.1 (v131072) | Playable on an iPhone (upstream) |
+| OCTOPATH TRAVELER 0 | `01005270232F2000` | 1.0.5 (v327680) | Profile present; not verified on a phone |
+| Hades | `0100535012974000` | 1.0.38233 (v589824) | Playable on an iPhone (upstream) |
+| Fire Emblem: Three Houses | `010055D009F78000` | 1.2.0 (v327680) | Playable on an iPhone (upstream) |
+| FINAL FANTASY RESONANCE | `0100606026F12000` | 1.0.1 (v65536) | Playable on an iPhone (upstream) |
+| Big Brain Academy: Brain vs. Brain | `0100620012D6E000` | 1.2.0 (v131072) | Profile present; not verified on a phone |
+| Unicorn Overlord | `010069401ADB8000` | 1.05 (v262144) | Profile present; not verified on a phone |
+| The Legend of Zelda: Link's Awakening | `01006BB00C6F0000` | 1.1.0 (v131072) | Playable on an iPhone (upstream) |
+| DRAGON QUEST XI S: Echoes of an Elusive Age – Definitive Edition | `01006C300E9F0000` | 1.0.4 (v262144) | Profile present; not verified on a phone |
+| Animal Crossing: New Horizons | `01006F8002326000` | 3.0.3 (v2228224) | Profile present; not verified on a phone |
+| AI: THE SOMNIUM FILES - nirvanA Initiative | `0100713016CCC000` | 1.0.2 (v131072) | Playable on an iPhone (upstream) |
+| The Legend of Zelda: Breath of the Wild | `01007EF00011E000` | 1.9.0 (v1114112) | Playable on an iPhone (upstream) |
+| AI: THE SOMNIUM FILES | `010089B00D09C000` | 1.0.1 (v65536) | Playable on an iPhone (upstream) |
+| STEINS;GATE RE:BOOT | `01008BC024FDE000` | 1.0.3 (v131072) | Profile present; not verified on a phone |
+| Metroid Dread | `010093801237C000` | 2.1.0 (v327680) | Playable on an iPhone (upstream) |
+| Super Mario Galaxy | `010099C022B96000` | 1.3.1 (v327680) | Playable on an iPhone (upstream) |
+| Captain Toad: Treasure Tracker | `01009BF0072D4000` | 1.4.2 (v393216) | Profile present; not verified on a phone |
+| Hades II | `0100A00019DE0000` | 无(v0) | **Verified here** — builds, installs and runs on an iPhone; 33-file archive |
+| Cuphead | `0100A5C00D162000` | 1.3.7 (v655360) | Profile present; not verified on a phone |
+| Fire Emblem Engage | `0100A6301214E000` | 2.0.0 (v327680) | Playable on an iPhone (upstream) |
+| Absolum | `0100A83022A22000` | 1.1.1 (v393216) | Profile present; not verified on a phone |
+| DRAGON QUEST VII Reimagined | `0100A9D01C446000` | 1.2.0 (v131072) | Profile present; not verified on a phone |
+| Monster Hunter Rise | `0100B04011742000` | 16.0.2 (v2228224) | Profile present; not verified on a phone |
+| Catherine: Full Body | `0100BF00112C0000` | 1.0.1a (v131072) | Profile present; not verified on a phone |
+| Balatro | `0100CD801CE5E000` | 1.1.3 (v851968) | Playable on an iPhone (upstream) |
+| Rhythm Heaven Groove | `0100D9F01D474000` | 无(v0) | Profile present; not verified on a phone |
+| Luigi's Mansion 3 | `0100DCA0064A6000` | 1.4.0 (v327680) | Playable on an iPhone (upstream) |
+| Patrick's Parabox | `0100E44016C22000` | 1.0.1 (v65536) | Profile present; not verified on a phone |
+| Paper Mario: The Thousand-Year Door | `0100ECD018EBE000` | 1.0.1 (v65536) | Profile present; not verified on a phone |
+| The Legend of Zelda: Tears of the Kingdom | `0100F2C0115B6000` | 1.4.3 (v720896) | **Verified here** — builds, installs and runs on an iPhone; 304,243 files into 127 archive shards, byte-verified |
+| Pokémon Legends: Z-A | `0100F43008C44000` | 2.0.2 (v393216) | Profile present; not verified on a phone |
+| Brain Memory Training Academy | `0100F5D01DA3A000` | 无(v0) | Profile present; not verified on a phone |
+| Super Mario Galaxy 2 | `0100FD8022DAA000` | 1.4.0 (v393216) | Profile present; not verified on a phone |
+
+## Verified on
- **Tears of the Kingdom** (0100F2C0115B6000, v1.0.0 + update 1.4.3): 304,243 files packed into 127
files; all 304,243 byte-compared against the source (`verify: OK`); the game runs from the archive
diff --git a/README.zh-CN.md b/README.zh-CN.md
index e589c165..a7f4a098 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -69,6 +69,15 @@ cd frontend && swift run # 或直接双击 frontend/NS Port Builder.app
[Releases 页面](https://github.com/LNPANDY/nxnative-romfs-archive/releases),仓库内也存了一份:
[docs/RELEASE_NOTES.md](docs/RELEASE_NOTES.md)。
+## 跟随上游更新
+
+一个定时的 GitHub Actions 工作流(`.github/workflows/sync-upstream.yml`,每天 21:30 UTC,也可手动
+触发)跟随 [seedds/nxnative](https://github.com/seedds/nxnative):通过 `scripts/sync_upstream.py`
+把本 fork 的特性重新应用到上游新树上,并做验证(全部脚本按 Python 3.9 解析、`bash -n`、归档读取
+测试、macOS 宿主编译),通过即提交推送;补丁对不上时开一个 issue 并附日志,不推送。本仓库是独立
+新建的仓库而非真正的 fork,GitHub 自带的「Sync fork」用不了;上次同步的上游提交记录在
+`.upstream-ref`。
+
## 使用方法
### 1. 构建 App(与上游相同)
@@ -247,56 +256,59 @@ DM_OPMODE=0 # 掌机模式:720p 渲染而不是底座的 1080p
本仓库自带 48 个游戏 profile。profile 决定了一个游戏能不能构建——build ID、内存布局、
shader 表、每个游戏各自的开关;本 fork 在此基础上加了 RomFS 归档层,让大体积游戏能装得下。
-| 游戏 | Title ID | 状态 |
-|---|---|---|
-| Super Mario Odyssey | `0100000000010000` | 上游报告 iPhone 可玩 |
-| Ace Attorney Investigations Collection | `010005501E68C000` | 有 profile,未在手机上验证 |
-| Hollow Knight: Silksong | `010013C00E930000` | 有 profile,未在手机上验证 |
-| Digimon Story Cyber Sleuth: Complete Edition | `010014E00DB56000` | 有 profile,未在手机上验证 |
-| Super Mario Bros. Wonder | `010015100B514000` | 上游报告 iPhone 可玩 |
-| Mario Kart 8 Deluxe | `0100152000022000` | 上游报告 iPhone 可玩 |
-| Raging Loop | `010020400E1C2000` | 有 profile,未在手机上验证 |
-| ANIMAL WELL | `010020D01AD24000` | 上游报告 iPhone 可玩 |
-| Super Mario 3D World + Bowser's Fury | `010028600EBDA000` | 上游报告 iPhone 可玩 |
-| Hyrule Warriors: Age of Calamity | `01002B00111A2000` | 上游报告 iPhone 可玩 |
-| Celeste | `01002B30028F6000` | 有 profile,未在手机上验证 |
-| The Great Ace Attorney Chronicles | `010036E00FB20000` | 上游报告 iPhone 可玩 |
-| FINAL FANTASY TACTICS - The Ivalice Chronicles | `010038B015560000` | 有 profile,未在手机上验证 |
-| 13 Sentinels: Aegis Rim | `01003FC01670C000` | 上游报告 iPhone 可玩 |
-| DARK SOULS: REMASTERED | `01004AB00A260000` | 有 profile,未在手机上验证 |
-| Monster Train 2 | `010051701FB46000` | 上游报告 iPhone 可玩 |
-| OCTOPATH TRAVELER 0 | `01005270232F2000` | 有 profile,未在手机上验证 |
-| Hades | `0100535012974000` | 上游报告 iPhone 可玩 |
-| Fire Emblem: Three Houses | `010055D009F78000` | 上游报告 iPhone 可玩 |
-| FINAL FANTASY RESONANCE | `0100606026F12000` | 上游报告 iPhone 可玩 |
-| Big Brain Academy: Brain vs. Brain | `0100620012D6E000` | 有 profile,未在手机上验证 |
-| Unicorn Overlord | `010069401ADB8000` | 有 profile,未在手机上验证 |
-| The Legend of Zelda: Link's Awakening | `01006BB00C6F0000` | 上游报告 iPhone 可玩 |
-| DRAGON QUEST XI S: Echoes of an Elusive Age – Definitive Edition | `01006C300E9F0000` | 有 profile,未在手机上验证 |
-| Animal Crossing: New Horizons | `01006F8002326000` | 有 profile,未在手机上验证 |
-| AI: THE SOMNIUM FILES - nirvanA Initiative | `0100713016CCC000` | 上游报告 iPhone 可玩 |
-| The Legend of Zelda: Breath of the Wild | `01007EF00011E000` | 上游报告 iPhone 可玩 |
-| AI: THE SOMNIUM FILES | `010089B00D09C000` | 上游报告 iPhone 可玩 |
-| STEINS;GATE RE:BOOT | `01008BC024FDE000` | 有 profile,未在手机上验证 |
-| Metroid Dread | `010093801237C000` | 上游报告 iPhone 可玩 |
-| Super Mario Galaxy | `010099C022B96000` | 上游报告 iPhone 可玩 |
-| Captain Toad: Treasure Tracker | `01009BF0072D4000` | 有 profile,未在手机上验证 |
-| Hades II | `0100A00019DE0000` | **本 fork 已验证** —— Hades II —— 构建、安装、在 iPhone 上运行;33 个文件的归档 |
-| Cuphead | `0100A5C00D162000` | 有 profile,未在手机上验证 |
-| Fire Emblem Engage | `0100A6301214E000` | 上游报告 iPhone 可玩 |
-| Absolum | `0100A83022A22000` | 有 profile,未在手机上验证 |
-| DRAGON QUEST VII Reimagined | `0100A9D01C446000` | 有 profile,未在手机上验证 |
-| Monster Hunter Rise | `0100B04011742000` | 有 profile,未在手机上验证 |
-| Catherine: Full Body | `0100BF00112C0000` | 有 profile,未在手机上验证 |
-| Balatro | `0100CD801CE5E000` | 上游报告 iPhone 可玩 |
-| Rhythm Heaven Groove | `0100D9F01D474000` | 有 profile,未在手机上验证 |
-| Luigi's Mansion 3 | `0100DCA0064A6000` | 上游报告 iPhone 可玩 |
-| Patrick's Parabox | `0100E44016C22000` | 有 profile,未在手机上验证 |
-| Paper Mario: The Thousand-Year Door | `0100ECD018EBE000` | 有 profile,未在手机上验证 |
-| The Legend of Zelda: Tears of the Kingdom | `0100F2C0115B6000` | **本 fork 已验证** —— 王国之泪 —— 构建、安装、在 iPhone 上运行;304,243 个文件归档成 127 片,逐字节校验通过 |
-| Pokémon Legends: Z-A | `0100F43008C44000` | 有 profile,未在手机上验证 |
-| Brain Memory Training Academy | `0100F5D01DA3A000` | 有 profile,未在手机上验证 |
-| Super Mario Galaxy 2 | `0100FD8022DAA000` | 有 profile,未在手机上验证 |
+「需要的更新包」就是构建时严格校验的版本:更新包 NSP 的显示版本必须与 profile 注册的 build 一致
+(本体自身的版本无所谓——更新会叠加在本体上)。「无(v0)」= 只需本体。
+
+| 游戏 | Title ID | 需要的更新包 | 状态 |
+|---|---|---|---|
+| Super Mario Odyssey | `0100000000010000` | 1.4.1 (v393216) | 上游报告 iPhone 可玩 |
+| Ace Attorney Investigations Collection | `010005501E68C000` | 1.0.0.2 (v131072) | 有 profile,未在手机上验证 |
+| Hollow Knight: Silksong | `010013C00E930000` | 1.0.30000 (v655360) | 有 profile,未在手机上验证 |
+| Digimon Story Cyber Sleuth: Complete Edition | `010014E00DB56000` | 1.0.3 (v196608) | 有 profile,未在手机上验证 |
+| Super Mario Bros. Wonder | `010015100B514000` | 1.2.1 (v327680) | 上游报告 iPhone 可玩 |
+| Mario Kart 8 Deluxe | `0100152000022000` | 4.0.0 (v1441792) | 上游报告 iPhone 可玩 |
+| Raging Loop | `010020400E1C2000` | 无(v0) | 有 profile,未在手机上验证 |
+| ANIMAL WELL | `010020D01AD24000` | 1.0.10 (v655360) | 上游报告 iPhone 可玩 |
+| Super Mario 3D World + Bowser's Fury | `010028600EBDA000` | 1.2.2 (v262144) | 上游报告 iPhone 可玩 |
+| Hyrule Warriors: Age of Calamity | `01002B00111A2000` | 1.3.0 (v327680) | 上游报告 iPhone 可玩 |
+| Celeste | `01002B30028F6000` | 1.4.1.1 (v589824) | 有 profile,未在手机上验证 |
+| The Great Ace Attorney Chronicles | `010036E00FB20000` | 无(v0) | 上游报告 iPhone 可玩 |
+| FINAL FANTASY TACTICS - The Ivalice Chronicles | `010038B015560000` | 1.4.0 (v393216) | 有 profile,未在手机上验证 |
+| 13 Sentinels: Aegis Rim | `01003FC01670C000` | 1.10 (v65536) | 上游报告 iPhone 可玩 |
+| DARK SOULS: REMASTERED | `01004AB00A260000` | 1.0.3 (v196608) | 有 profile,未在手机上验证 |
+| Monster Train 2 | `010051701FB46000` | 1.1.1 (v131072) | 上游报告 iPhone 可玩 |
+| OCTOPATH TRAVELER 0 | `01005270232F2000` | 1.0.5 (v327680) | 有 profile,未在手机上验证 |
+| Hades | `0100535012974000` | 1.0.38233 (v589824) | 上游报告 iPhone 可玩 |
+| Fire Emblem: Three Houses | `010055D009F78000` | 1.2.0 (v327680) | 上游报告 iPhone 可玩 |
+| FINAL FANTASY RESONANCE | `0100606026F12000` | 1.0.1 (v65536) | 上游报告 iPhone 可玩 |
+| Big Brain Academy: Brain vs. Brain | `0100620012D6E000` | 1.2.0 (v131072) | 有 profile,未在手机上验证 |
+| Unicorn Overlord | `010069401ADB8000` | 1.05 (v262144) | 有 profile,未在手机上验证 |
+| The Legend of Zelda: Link's Awakening | `01006BB00C6F0000` | 1.1.0 (v131072) | 上游报告 iPhone 可玩 |
+| DRAGON QUEST XI S: Echoes of an Elusive Age – Definitive Edition | `01006C300E9F0000` | 1.0.4 (v262144) | 有 profile,未在手机上验证 |
+| Animal Crossing: New Horizons | `01006F8002326000` | 3.0.3 (v2228224) | 有 profile,未在手机上验证 |
+| AI: THE SOMNIUM FILES - nirvanA Initiative | `0100713016CCC000` | 1.0.2 (v131072) | 上游报告 iPhone 可玩 |
+| The Legend of Zelda: Breath of the Wild | `01007EF00011E000` | 1.9.0 (v1114112) | 上游报告 iPhone 可玩 |
+| AI: THE SOMNIUM FILES | `010089B00D09C000` | 1.0.1 (v65536) | 上游报告 iPhone 可玩 |
+| STEINS;GATE RE:BOOT | `01008BC024FDE000` | 1.0.3 (v131072) | 有 profile,未在手机上验证 |
+| Metroid Dread | `010093801237C000` | 2.1.0 (v327680) | 上游报告 iPhone 可玩 |
+| Super Mario Galaxy | `010099C022B96000` | 1.3.1 (v327680) | 上游报告 iPhone 可玩 |
+| Captain Toad: Treasure Tracker | `01009BF0072D4000` | 1.4.2 (v393216) | 有 profile,未在手机上验证 |
+| Hades II | `0100A00019DE0000` | 无(v0) | **本 fork 已验证** —— 构建、安装、在 iPhone 上运行;33 个文件的归档 |
+| Cuphead | `0100A5C00D162000` | 1.3.7 (v655360) | 有 profile,未在手机上验证 |
+| Fire Emblem Engage | `0100A6301214E000` | 2.0.0 (v327680) | 上游报告 iPhone 可玩 |
+| Absolum | `0100A83022A22000` | 1.1.1 (v393216) | 有 profile,未在手机上验证 |
+| DRAGON QUEST VII Reimagined | `0100A9D01C446000` | 1.2.0 (v131072) | 有 profile,未在手机上验证 |
+| Monster Hunter Rise | `0100B04011742000` | 16.0.2 (v2228224) | 有 profile,未在手机上验证 |
+| Catherine: Full Body | `0100BF00112C0000` | 1.0.1a (v131072) | 有 profile,未在手机上验证 |
+| Balatro | `0100CD801CE5E000` | 1.1.3 (v851968) | 上游报告 iPhone 可玩 |
+| Rhythm Heaven Groove | `0100D9F01D474000` | 无(v0) | 有 profile,未在手机上验证 |
+| Luigi's Mansion 3 | `0100DCA0064A6000` | 1.4.0 (v327680) | 上游报告 iPhone 可玩 |
+| Patrick's Parabox | `0100E44016C22000` | 1.0.1 (v65536) | 有 profile,未在手机上验证 |
+| Paper Mario: The Thousand-Year Door | `0100ECD018EBE000` | 1.0.1 (v65536) | 有 profile,未在手机上验证 |
+| The Legend of Zelda: Tears of the Kingdom | `0100F2C0115B6000` | 1.4.3 (v720896) | **本 fork 已验证** —— 构建、安装、在 iPhone 上运行;304,243 个文件归档成 127 片,逐字节校验通过 |
+| Pokémon Legends: Z-A | `0100F43008C44000` | 2.0.2 (v393216) | 有 profile,未在手机上验证 |
+| Brain Memory Training Academy | `0100F5D01DA3A000` | 无(v0) | 有 profile,未在手机上验证 |
+| Super Mario Galaxy 2 | `0100FD8022DAA000` | 1.4.0 (v393216) | 有 profile,未在手机上验证 |
「本 fork 已验证」表示完整走通了整条链路:构建、装到 iPhone、运行,归档还逐字节比对过源文件。
「上游报告 iPhone 可玩」是上游项目的结果,本 fork 未重新测试。只有 profile 不保证游戏能启动——
diff --git a/dm/games/0100A00019DE0000/game.fork.tsv b/dm/games/0100A00019DE0000/game.fork.tsv
new file mode 100644
index 00000000..39368d0c
--- /dev/null
+++ b/dm/games/0100A00019DE0000/game.fork.tsv
@@ -0,0 +1,69 @@
+# Hades II (Supergiant Games' engine on NVN, SDK 19.3.9 base / 20.5.15 update).
+# Base game v0 (display version 0.0.126424) and update v1.0.137848 are both registered.
+# Started from the NSP script's provisional profile; values marked "Mario's" are not measured for this game yet.
+# Unlike Hades (Vulkan), the Switch version renders with NVN: its 88 shaders are BNSH files in Shaders/NVN/bin (.vert / .frag; the .shader files list each program's pair).
+# The ExeFS has only main and sdk. main's EOS_* imports (Epic Online Services, from nro/EOSSDK-Switch-Shipping.nro, loaded through nn::ro) stay offline: the host
+# registers no NRR, so the game never loads the NRO.
+
+# ---- Identity ----
+title_id 0100A00019DE0000
+program_id 0100A00019DE0000
+
+# ---- App ----
+name Hades II
+ipa HadesII.ipa
+app_category public.app-category.action-games
+# the right stick aims (the weapons with ManualAiming in Game/Weapons/PlayerWeapons.sjson)
+pad_layout full
+
+# ---- Versions ----
+# The update's build IDs come from its own ExeFS (the base game's from upstream's profile).
+build v0 0.0.126424 main=5219053e5eb156be80fbb2f303779531 sdk=d83a56a5558798414c78ec722867a7da
+build v1 1.0.137848 main=8ce1ac48e9fa74479051f3520e632df4 sdk=190030518b5d64e5d87b84bc54661af9
+package v1
+shader_versions v0 v1
+
+# ---- Files ----
+modules main sdk
+romfs_marker Audio/Switch/Music.bank
+zip_store .bank:.bik:.fsb:.gpk:.nro:.pkg:.xnb:.metallib
+
+# ---- Graphics ----
+
+# ---- Memory ----
+# The NPDM declares no system resource (META +0x14 = 0): the game uses SetHeapSize. It asks for 3.10 GB (pool − used memory), which the 3.25 GB heap region of
+# the 4 GB layout holds. main carries an 82 MB bss: the rewritten modules take more than the default 64 MB of used memory, so SetHeapSize(pool − 64 MB) would not fit
+mem_reserve 0x100000000
+mem_alias 0x10000000
+mem_stack 0x10000000
+app_pool 0xCD500000
+mem_used 0x6c00000
+
+# ---- Widescreen (host only, NOT enabled for this game) ----
+# The swapchain size 1280x720 is hardcoded twice in main: a rodata entry at +0x6d337c ({u32 w,
+# u32 h}, dead data) and two immediate instructions at +0x2a6080 (movz/movk x8) that write it into
+# a config object. Patching the rodata entry does nothing (the immediates win); patching the
+# immediates too makes the init run and then crash later (main+0x48e5a4, null deref in the
+# 0x2a7a20 call chain): the value feeds more than the swapchain, and whatever else depends on
+# 1280x720 specifically is not satisfied by just widening it. Real widescreen for this title
+# needs its resolution pipeline reversed — out of scope here.
+# Round 2 detail: with the immediates patched to 1600x900, the init crashes at
+# main+0x48e5a4 (ldr x2,[x21,#8] with a null x21) inside the 0x2a7a20 chain — the
+# allocation at 0x499840 fails or a lookup misses for the wider size. d2r-mobile's
+# widescreen works because its title's whole resolution path was brought up: PARAMS
+# slots (4 sites) plus the KASPECT aspect cap plus the derived-mask fix, each found
+# and tested one by one. The same depth of work is needed here.
+
+# ---- NVN driver constant segments (Mario's values, the translator's built-in layout, except the texture slot count) ----
+# The game's shaders bind textures at fixed, sparse slots: c2 handles at 0x20 + 8 r for r = 0, 1, 3, 6, 8, 11, 15, 21, 25, 26, 30, 31 and 34 over all 88 shaders.
+# Slot 34 (SceneFade.frag, 0x130) lies past Mario's 32 slots, where his image table starts; this game has no image bindings and no shader reads c2 at run time
+nvn_tex_base 0x20
+nvn_tex_slots 35
+nvn_samp_base 0x568
+nvn_img_base 0x120
+nvn_img_slots 8
+nvn_ssbo_bases vs=0x110 ps=0x510 cs=0x310
+
+# ---- Shader split ----
+shader_groups /Shaders/=shaders
+shader_note Hades II shaders (Shaders/NVN/bin)
diff --git a/dm/games/0100A00019DE0000/game.tsv b/dm/games/0100A00019DE0000/game.tsv
index aca851d6..39368d0c 100644
--- a/dm/games/0100A00019DE0000/game.tsv
+++ b/dm/games/0100A00019DE0000/game.tsv
@@ -1,4 +1,5 @@
-# Hades II (Supergiant Games' engine on NVN, SDK 19.3.9), base game v0 (the NACP's display version 0.0.126424).
+# Hades II (Supergiant Games' engine on NVN, SDK 19.3.9 base / 20.5.15 update).
+# Base game v0 (display version 0.0.126424) and update v1.0.137848 are both registered.
# Started from the NSP script's provisional profile; values marked "Mario's" are not measured for this game yet.
# Unlike Hades (Vulkan), the Switch version renders with NVN: its 88 shaders are BNSH files in Shaders/NVN/bin (.vert / .frag; the .shader files list each program's pair).
# The ExeFS has only main and sdk. main's EOS_* imports (Epic Online Services, from nro/EOSSDK-Switch-Shipping.nro, loaded through nn::ro) stay offline: the host
@@ -16,9 +17,11 @@ app_category public.app-category.action-games
pad_layout full
# ---- Versions ----
+# The update's build IDs come from its own ExeFS (the base game's from upstream's profile).
build v0 0.0.126424 main=5219053e5eb156be80fbb2f303779531 sdk=d83a56a5558798414c78ec722867a7da
-package v0
-shader_versions v0
+build v1 1.0.137848 main=8ce1ac48e9fa74479051f3520e632df4 sdk=190030518b5d64e5d87b84bc54661af9
+package v1
+shader_versions v0 v1
# ---- Files ----
modules main sdk
@@ -36,6 +39,31 @@ mem_stack 0x10000000
app_pool 0xCD500000
mem_used 0x6c00000
+# ---- Widescreen (host only, NOT enabled for this game) ----
+# The swapchain size 1280x720 is hardcoded twice in main: a rodata entry at +0x6d337c ({u32 w,
+# u32 h}, dead data) and two immediate instructions at +0x2a6080 (movz/movk x8) that write it into
+# a config object. Patching the rodata entry does nothing (the immediates win); patching the
+# immediates too makes the init run and then crash later (main+0x48e5a4, null deref in the
+# 0x2a7a20 call chain): the value feeds more than the swapchain, and whatever else depends on
+# 1280x720 specifically is not satisfied by just widening it. Real widescreen for this title
+# needs its resolution pipeline reversed — out of scope here.
+# Round 2 detail: with the immediates patched to 1600x900, the init crashes at
+# main+0x48e5a4 (ldr x2,[x21,#8] with a null x21) inside the 0x2a7a20 chain — the
+# allocation at 0x499840 fails or a lookup misses for the wider size. d2r-mobile's
+# widescreen works because its title's whole resolution path was brought up: PARAMS
+# slots (4 sites) plus the KASPECT aspect cap plus the derived-mask fix, each found
+# and tested one by one. The same depth of work is needed here.
+
+# ---- NVN driver constant segments (Mario's values, the translator's built-in layout, except the texture slot count) ----
+# The game's shaders bind textures at fixed, sparse slots: c2 handles at 0x20 + 8 r for r = 0, 1, 3, 6, 8, 11, 15, 21, 25, 26, 30, 31 and 34 over all 88 shaders.
+# Slot 34 (SceneFade.frag, 0x130) lies past Mario's 32 slots, where his image table starts; this game has no image bindings and no shader reads c2 at run time
+nvn_tex_base 0x20
+nvn_tex_slots 35
+nvn_samp_base 0x568
+nvn_img_base 0x120
+nvn_img_slots 8
+nvn_ssbo_bases vs=0x110 ps=0x510 cs=0x310
+
# ---- Shader split ----
shader_groups /Shaders/=shaders
shader_note Hades II shaders (Shaders/NVN/bin)
diff --git a/dm/host/hle_fs.c b/dm/host/hle_fs.c
index 71931bf8..aff4505d 100644
--- a/dm/host/hle_fs.c
+++ b/dm/host/hle_fs.c
@@ -820,8 +820,8 @@ HLE_FORCE("_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc", "fsp-srv →
HP(path); struct stat st;
if (ROMFSARC_IS_SYNTH(hp)) { // archive entry or directory, from the index
const char *rel = ROMFSARC_SYNTH_REL(hp);
- uint32_t sh; uint64_t of, sz2;
- if (romfsarc_stat_file(rel, &sh, &of, &sz2)) { *out = ENT_FILE; return RES_OK; }
+ 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);
}
diff --git a/dm/ios/Sources/main.m b/dm/ios/Sources/main.m
index 4ffddaf7..e9592d16 100644
--- a/dm/ios/Sources/main.m
+++ b/dm/ios/Sources/main.m
@@ -17,8 +17,15 @@ static char *g_argv[4]; static int g_argc;
static NSString *romfs_locate(void) {
NSFileManager *fm = NSFileManager.defaultManager;
NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
- for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]])
- if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@DM_GAME_ROMFS_MARKER]]) return d; // only a directory containing the game profile's romfs_marker path counts (Mario: System/Resource, the resource size table)
+ for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]]) {
+ // 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).
+ NSString *idx = [d stringByAppendingPathComponent:@"romfs.idx"];
+ if ([fm fileExistsAtPath:idx]) return d;
+ // A plain directory tree: only one containing the game profile's romfs_marker path counts
+ // (Mario: System/Resource, the resource size table)
+ if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@DM_GAME_ROMFS_MARKER]]) return d;
+ }
return nil;
}
diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.py
new file mode 100644
index 00000000..55b9cd45
--- /dev/null
+++ b/scripts/sync_upstream.py
@@ -0,0 +1,526 @@
+#!/usr/bin/env python3
+"""Sync this fork with upstream seedds/nxnative.
+
+The fork was started as a fresh repository (no shared git history), so GitHub's own
+"Sync fork" does not apply. The sync is a mechanical procedure — take upstream's tree,
+re-apply the fork's features, verify the result builds — and this script is that
+procedure, so a scheduled CI job can run it unattended.
+
+What it does:
+ 1. diffs the two upstream refs over the vendored paths (dm/ scripts/ docs/ AGENTS.md ref/)
+ 2. applies adds and modifications file by file, and deletions — except the fork's own
+ files (the RomFS archive layer), which upstream must not delete
+ 3. re-applies the fork's patches to the four files that carry them
+ (hle_fs.c, the host Makefile, build_ipa.sh, the NSP script); every patch is
+ anchor-based and idempotent, and one that no longer fits fails the run loudly
+ rather than producing a silently broken tree
+ 4. verifies: every .py parses on the Python this fork supports as its floor (3.9),
+ the iOS build script survives bash -n, the archive reader test passes, and the
+ macOS host builds for a real profile (skippable with --skip-build)
+
+On success the caller commits and pushes; on failure nothing is written outside the
+working tree, so CI can open an issue with the log instead.
+
+Usage: sync_upstream.py --old <upstream sha> --new <upstream sha> [--skip-build]
+"""
+import argparse, os, subprocess, sys, shutil, tempfile
+from pathlib import Path
+
+REPO = Path(__file__).resolve().parent.parent
+VENDORED = ('dm', 'scripts', 'docs', 'AGENTS.md', 'ref')
+# The fork's own files, inside vendored paths: upstream deletes and rewrites must not touch them.
+OURS = {'dm/host/romfs_arc.c', 'dm/host/romfs_arc.h', 'dm/tools/romfs_arc.py',
+ 'dm/host/tests/t_romfs_arc.c', 'docs/ROMFS_ARCHIVE.md',
+ 'dm/games/0100A00019DE0000/game.fork.tsv'}
+# Vendored files that carry fork patches: taken fresh from upstream, then patched below.
+PATCHED = ('dm/host/hle_fs.c', 'dm/host/Makefile', 'dm/ios/tools/build_ipa.sh',
+ 'scripts/build_ipa_from_nsp.py', 'dm/gfx/tools/shader_split.py',
+ 'dm/ios/Sources/main.m')
+
+def git(*a):
+ r = subprocess.run(['git', *a], cwd=REPO, capture_output=True, text=True)
+ if r.returncode: sys.exit(f'git {" ".join(a)} failed: {r.stderr.strip()}')
+ return r.stdout
+
+def blob(rev, path):
+ r = subprocess.run(['git', 'cat-file', 'blob', f'{rev}:{path}'], cwd=REPO, capture_output=True)
+ return r.stdout if r.returncode == 0 else None
+
+def upstream_changes(old, new):
+ """(kind, path) for every vendored file that differs, kind in AM D."""
+ out = git('diff', '--name-status', old, new, '--', *VENDORED).splitlines()
+ changes = []
+ for line in out:
+ parts = line.split('\t')
+ kind, path = parts[0][0], parts[-1]
+ changes.append((kind, path))
+ return changes
+
+# ---- the fork's patches. Each is (name, already-marker, [(old, new), ...]); a patch whose
+# marker is present is skipped, one whose old text is absent fails the run. ----
+
+HLE = 'dm/host/hle_fs.c'
+def patch_hle_fs(t):
+ P = []
+ P.append(('include', '#include "romfs_arc.h"', [(
+ '#include "hle.h"\n#include <mach/mach.h>\n#include "front.h"\n',
+ '#include "hle.h"\n#include <mach/mach.h>\n#include "front.h"\n#include "romfs_arc.h"\n')]))
+ P.append(('synthetic path', 'ROMFSARC_SYNTH_PREFIX "%s"', [(
+ ' if (g_mnt[i].overlay[0] && !create) return rom_overlay_path(&g_mnt[i], rest, out, n);',
+ ''' 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)) {
+ if (snprintf(out, n, ROMFSARC_SYNTH_PREFIX "%s", rest) >= (int)n) { errno = ENAMETOOLONG; return 0; }
+ return 1;
+ }''')]))
+ P.append(('MountRom', 'romfsarc_open(dir, &h)', [(
+ '''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];
+ Result r = mount(name, envdir("DM_ROMFS", "romfs", b, sizeof b), 1);''',
+ '''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];
+ 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);''')]))
+ P.append(('archive handles', 'static uint64_t arc_new', [(
+ 'HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Result, h_fs_OpenFile, uint64_t *out, const char *path, int mode) {',
+ '''// ---------- 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[].
+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 << 63) | ((g_arch_gen & 0x7fffffff) << 32) | (uint32_t)i;
+ }
+ return 0;
+}
+static int arc_get(uint64_t h, archandle **out) {
+ if (!(h >> 63)) return 0;
+ uint32_t i = (uint32_t)h;
+ if (i >= MAX_ARCH || !g_arc[i].used) return 0;
+ if ((uint32_t)((h >> 32) & 0x7fffffff) != (uint32_t)(g_arch_gen & 0x7fffffff)) 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) {''')]))
+ P.append(('OpenFile', 'arc_new(shard, off, size)', [(
+ ''' HP(path);
+ if (mode & (MODE_WRITE | MODE_APPEND)) RW();
+ int fd = open(hp, (mode & (MODE_WRITE | MODE_APPEND)) ? ((mode & MODE_READ) ? O_RDWR : O_WRONLY) : O_RDONLY);''',
+ ''' 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 = 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);''')]))
+ P.append(('ReadFile', 'romfsarc_pread(ah->shard', [(
+ ''' size_t got = 0; int reprep = 0;
+ 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
+ while (got < sz) {''',
+ ''' size_t got = 0; int reprep = 0;
+ 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) {''')]))
+ P.append(('GetFileSize', 'ah->size; return RES_OK', [(
+ '''HLE_FORCE("_ZN2nn2fs11GetFileSizeEPlNS0_10FileHandleE", "fsp-srv → fstat(2)", Result, h_fs_GetFileSize, int64_t *out, uint64_t h) {
+ if (!h) return RES_FAIL;''',
+ '''HLE_FORCE("_ZN2nn2fs11GetFileSizeEPlNS0_10FileHandleE", "fsp-srv → fstat(2)", Result, h_fs_GetFileSize, int64_t *out, uint64_t h) {
+ if (!h) return RES_FAIL;
+ archandle *ah; if (arc_get(h, &ah)) { *out = (int64_t)ah->size; return RES_OK; }''')]))
+ P.append(('CloseFile', 'arc_free(h)', [(
+ '''HLE_FORCE("_ZN2nn2fs9CloseFileENS0_10FileHandleE", "fsp-srv → close(2)", void, h_fs_CloseFile, uint64_t h) {
+ if (!h) return; // the null handle after a failed open (see ReadFile): do not touch fd 0''',
+ '''HLE_FORCE("_ZN2nn2fs9CloseFileENS0_10FileHandleE", "fsp-srv → close(2)", void, h_fs_CloseFile, uint64_t h) {
+ if (!h) return; // the null handle after a failed open (see ReadFile): do not touch fd 0
+ if (h >> 63) { arc_free(h); return; } // archive entry: nothing to close''')]))
+ P.append(('GetEntryType', 'romfsarc_stat_file(rel', [(
+ '''HLE_FORCE("_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc", "fsp-srv → stat(2)", Result, h_fs_GetEntryType, int32_t *out, const char *path) {
+ HP(path); struct stat st;''',
+ '''HLE_FORCE("_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc", "fsp-srv → stat(2)", Result, h_fs_GetEntryType, int32_t *out, const char *path) {
+ HP(path); struct stat st;
+ if (ROMFSARC_IS_SYNTH(hp)) { // archive entry or directory, from the index
+ const char *rel = ROMFSARC_SYNTH_REL(hp);
+ 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);
+ }''')]))
+ P.append(('snapshot helper', 'static void arc_snapshot', [])) # inserted below, needs dirh_t
+ P.append(('OpenDirectory', 'arc_snapshot(ah, hp)', [(
+ '''HLE_FORCE("_ZN2nn2fs13OpenDirectoryEPNS0_15DirectoryHandleEPKci", "fsp-srv → opendir(3)", Result, h_fs_OpenDirectory, uint64_t *out, const char *path, int mode) {
+ HP(path); DIR *d = opendir(hp);''',
+ '''HLE_FORCE("_ZN2nn2fs13OpenDirectoryEPNS0_15DirectoryHandleEPKci", "fsp-srv → opendir(3)", Result, h_fs_OpenDirectory, uint64_t *out, const char *path, int mode) {
+ 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);''')]))
+ P.append(('ReadDirectory guard', "an archive directory that turned out empty", [(
+ ''' int dfd = dirfd(h->d);''',
+ ''' 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);''')]))
+ P.append(('CloseDirectory guard', 'if (h->d) closedir(h->d)', [(
+ ''' dirh_t *h = (dirh_t *)hh; closedir(h->d); if (h->od) closedir(h->od); free(h->snap); free(h);''',
+ ''' dirh_t *h = (dirh_t *)hh; if (h->d) closedir(h->d); if (h->od) closedir(h->od); free(h->snap); free(h);''')]))
+
+ for name, marker, pairs in P:
+ if marker in t:
+ skip(f'hle_fs.c {name} (already patched)'); continue
+ for old, new in pairs:
+ if old not in t: fail(f'{HLE}: patch "{name}" anchor missing: {old[:70]!r}')
+ t = t.replace(old, new, 1)
+ done(f'hle_fs.c {name}')
+ # arc_snapshot goes right after the dirh_t typedef: it names the type
+ if 'static void arc_snapshot' not in t:
+ import re
+ m = re.search(r'typedef struct \{ DIR \*d;.*?\} dirh_t;\n', t, re.S)
+ if not m: fail(f'{HLE}: dirh_t typedef not found')
+ t = t[:m.end()] + SNAPSHOT + t[m.end():]
+ done('hle_fs.c arc_snapshot')
+ return t
+
+SNAPSHOT = '''
+// 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);
+}
+'''
+
+def patch_makefile(t):
+ if 'romfs_arc.c' in t: return skip('Makefile (already patched)')
+ old = 'SRC=main.c loader.c hle.c crash.c probe.c thread.c memstat.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S'
+ if old not in t: fail('dm/host/Makefile: SRC anchor missing (upstream changed the source list)')
+ return done('Makefile SRC', t.replace(old, 'SRC=main.c loader.c hle.c romfs_arc.c crash.c probe.c thread.c memstat.m $(sort $(wildcard hle_*.c)) front_mac.m entry.S', 1))
+
+ENT = '''# The unsigned IPA: an unsigned binary has no signature for a sideloader to read entitlements from,
+# so the request would be lost (AltStore reads the signature it replaces). Sign ad-hoc with the
+# entitlement first; the sideloader strips this signature and carries the entitlement over.
+if [ "$PREPARE_XCODE" != YES ] && [ -n "${DM_ENTITLEMENTS-default}" ]; then
+ if [ -n "${DM_ENTITLEMENTS:-}" ]; then cp "$DM_ENTITLEMENTS" "$APP/DmIOS.entitlements" || die "copy DM_ENTITLEMENTS"
+ else printf '%s\\n' '<?xml version="1.0" encoding="UTF-8"?>' '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' \\
+ '<plist version="1.0"><dict><key>com.apple.developer.kernel.increased-memory-limit</key><true/></dict></plist>' > "$APP/DmIOS.entitlements" || die "entitlements"; fi
+ codesign --force --sign - --entitlements "$APP/DmIOS.entitlements" "$APP" || die "ad-hoc sign with entitlements (the sideloader re-signs; this only carries the request)"
+ codesign -d --entitlements :- "$APP" 2>/dev/null | grep -q increased-memory-limit || die "entitlements did not make it into the placeholder signature"
+ t "entitlements: increased-memory-limit embedded in the placeholder signature"
+fi
+'''
+
+def patch_build_ipa(t):
+ if 'placeholder signature' in t: return skip('build_ipa.sh entitlements (already patched)')
+ old = 'xcodegen generate -q > /dev/null || die "xcodegen"'
+ if old not in t: fail('dm/ios/tools/build_ipa.sh: xcodegen anchor missing')
+ t = t.replace(old, ENT + old, 1)
+ old2 = '''MAPS+=("$P/romfs=$ROMFS")
+t "pack IPA (already-compressed game files stored, everything else deflated)"'''
+ if old2 not in t: fail('dm/ios/tools/build_ipa.sh: pack anchor missing')
+ return done('build_ipa.sh slim + entitlements', t.replace(old2, '''# DM_FULL_ROMFS=1 packs the RomFS into the package (upstream behaviour; only sensible for small
+# games — a full package of a large game is many GB and iOS refuses to install it with
+# PackageExtractionFailed). The default is the slim package: the app reads the game files from
+# Documents/romfs (a directory tree, or a ROMFSARC archive: romfs.idx + romfs.NN shards).
+if [ -n "${DM_FULL_ROMFS:-}" ]; then
+ MAPS+=("$P/romfs=$ROMFS")
+ t "pack full IPA with RomFS (already-compressed game files stored, everything else deflated)"
+else
+ t "pack slim IPA without RomFS (game files come from Documents/romfs; DM_FULL_ROMFS=1 packs them)"
+fi''', 1))
+
+def patch_nsp(t):
+ P = []
+ P.append(('work-dir arg', '--work-dir', [(
+ " ap.add_argument('--env-file', help='environment switches for a diagnostic build (one KEY=VALUE per line)')",
+ " ap.add_argument('--work-dir', help='where the build folder goes (default: <NSP folder>/<title ID>_build); the extracted files, shader cache and temporary files all live there')\n"
+ " ap.add_argument('--env-file', help='environment switches for a diagnostic build (one KEY=VALUE per line)')")]))
+ P.append(('work-dir paths', 'args.work_dir', [(
+ " out_ipa = Path(os.path.expanduser(args.out or OUT_IPA)).resolve() if (args.out or OUT_IPA) else nsp_dir / g.get('ipa') # by default in the NSP folder, next to the NSPs and <id>_build/\n"
+ " if shadowed and not (args.out or OUT_IPA): out_ipa = out_ipa.with_name(out_ipa.stem + '-provisional.ipa') # never over the IPA of the game's real profile\n"
+ " work = nsp_dir / f'{g.id}_build'",
+ " work = Path(os.path.expanduser(args.work_dir)).resolve() if args.work_dir else nsp_dir / f'{g.id}_build' # the folder holding the NSPs by default; --work-dir puts the build elsewhere\n"
+ " out_ipa = Path(os.path.expanduser(args.out or OUT_IPA)).resolve() if (args.out or OUT_IPA) else work.parent / g.get('ipa') # by default next to the NSPs and <id>_build/\n"
+ " if shadowed and not (args.out or OUT_IPA): out_ipa = out_ipa.with_name(out_ipa.stem + '-provisional.ipa') # never over the IPA of the game's real profile")]))
+ P.append(('DOTNET_ROOT', 'list-runtimes', [(
+ " env.setdefault('USER', getpass.getuser()) # xcodegen fails without USER (Couldn't find current username)",
+ """ env.setdefault('USER', getpass.getuser()) # xcodegen fails without USER (Couldn't find current username)
+ # nx_extract is a framework-dependent app: without DOTNET_ROOT the host refuses to start it even
+ # when dotnet is on PATH (~/.dotnet is not a registered install location). The root is parsed from
+ # `dotnet --list-runtimes`, not assumed to be the binary's directory: Homebrew's
+ # /opt/homebrew/bin/dotnet is a symlink into Cellar and its runtime lives in …/libexec, so dirname
+ # gave …/bin and the apphost failed to find its runtime. Also into os.environ: some steps run
+ # without env= and inherit this process's environment.
+ if not env.get('DOTNET_ROOT') and (dn := shutil.which('dotnet', path=env['PATH'])):
+ root = None
+ try:
+ out = subprocess.run([dn, '--list-runtimes'], capture_output=True, text=True, timeout=60).stdout
+ for ln in out.splitlines():
+ if not ln.startswith('Microsoft.NETCore.App'): continue
+ p = ln[ln.rfind('[') + 1:ln.rfind(']')] if '[' in ln else ''
+ if p.endswith('/shared/Microsoft.NETCore.App'): root = p[:-len('/shared/Microsoft.NETCore.App')]
+ elif p: root = p
+ break
+ except Exception: pass
+ env['DOTNET_ROOT'] = os.environ['DOTNET_ROOT'] = root or str(Path(dn).resolve().parent)""")]))
+ P.append(('3.9 survey note', "listed = ', '.join('{} ({})'.format(n, mods[n]['kind'])", [(
+ ''' if extra: notes.append(f'modules besides main / sdk: {", ".join(f"{n} ({mods[n]["kind"]})" for n in extra)}; the provisional profile loads {G["modules"][0]} (load order main, subsdk*, sdk)')''',
+ ''' if extra:
+ # Nested same-quote strings inside an f-string need Python 3.12 (PEP 701); this script has to
+ # parse on the 3.9 that ships with the Xcode command line tools, so keep the inner
+ # expressions out of the f-string.
+ listed = ', '.join('{} ({})'.format(n, mods[n]['kind']) for n in extra)
+ notes.append('modules besides main / sdk: ' + listed + '; the provisional profile loads '
+ + G['modules'][0] + ' (load order main, subsdk*, sdk)')''')]))
+ P.append(('3.9 not-brought-up note', '_known = ", ".join("{} {}".format(v, b["display"])', [(
+ ''' say(f'[RED] this {artifact} uses {pkg_ver} ({disp}), which game profile {reg.id} was not brought up on ''',
+ ''' _known = ", ".join("{} {}".format(v, b["display"]) for v, b in reg.builds().items())
+ say(f'[RED] this {artifact} uses {pkg_ver} ({disp}), which game profile {reg.id} was not brought up on '''),
+ ('''({", ".join(f"{v} {b["display"]}" for v, b in reg.builds().items())})''',
+ '''({_known})''')]))
+ P.append(('3.9 derived note', '_reg = ", ".join("{} {}".format(v, b["display"]) for v, b in builds.items())', [(
+ ''' if pkg_ver not in builds: derived = f'{pkg_ver} is not a version game profile {g.id} registers ({", ".join(f"{v} {b["display"]}" for v, b in builds.items())})\'''',
+ ''' if pkg_ver not in builds:
+ _reg = ", ".join("{} {}".format(v, b["display"]) for v, b in builds.items())
+ derived = f'{pkg_ver} is not a version game profile {g.id} registers ({_reg})\'''')]))
+ for name, marker, pairs in P:
+ if marker in t:
+ skip(f'NSP script {name} (already patched)'); continue
+ hit = True
+ for old, new in pairs:
+ if old not in t:
+ if name.startswith('3.9'): # upstream may fix these themselves; a miss is not an error
+ hit = False; skip(f'NSP script {name} (upstream no longer has the pattern)'); break
+ fail(f'scripts/build_ipa_from_nsp.py: patch "{name}" anchor missing')
+ t = t.replace(old, new, 1)
+ if hit: done(f'NSP script {name}')
+ return t
+
+def patch_shader_split(t):
+ if 'a backslash cannot sit inside an f-string expression' in t: return skip('shader_split.py (already patched)')
+ old = ''' ue_inline_shaders(d, f'/{rel}#{re.sub(r"^(\\.\\./)+", "", os.path.normpath(pk.mount + name))}', out)'''
+ if old not in t: fail('dm/gfx/tools/shader_split.py: ue_inline_shaders anchor missing')
+ new = ''' _sub = re.sub(r"^(\\.\\./)+", "", os.path.normpath(pk.mount + name)) # a backslash cannot sit inside an f-string expression before 3.12
+ ue_inline_shaders(d, '/{}#{}'.format(rel, _sub), out)'''
+ return done('shader_split.py 3.9', t.replace(old, new, 1))
+
+def patch_main_m(t):
+ if 'romfs.idx' in t: return skip('main.m romfs.idx (already patched)')
+ old = (' for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]])\n'
+ ' if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@DM_GAME_ROMFS_MARKER]]) return d; // only a directory containing the game profile\'s romfs_marker path counts (Mario: System/Resource, the resource size table)')
+ new = (' for (NSString *d in @[[doc stringByAppendingPathComponent:@"romfs"], [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"romfs"]]) {\n'
+ ' // A ROMFSARC archive: <dir>/romfs.idx next to romfs.NN shards. The host opens it when DM_ROMFS\n'
+ ' // points at the base; the marker check does not apply (there are no directories to walk).\n'
+ ' NSString *idx = [d stringByAppendingPathComponent:@"romfs.idx"];\n'
+ ' if ([fm fileExistsAtPath:idx]) return d;\n'
+ ' // A plain directory tree: only one containing the game profile\'s romfs_marker path counts\n'
+ ' // (Mario: System/Resource, the resource size table)\n'
+ ' if ([fm fileExistsAtPath:[d stringByAppendingPathComponent:@DM_GAME_ROMFS_MARKER]]) return d;\n'
+ ' }')
+ if old not in t: fail('dm/ios/Sources/main.m: romfs_locate anchor missing')
+ return done('main.m romfs.idx', t.replace(old, new, 1))
+
+def patch_hades2(t):
+ """The fork's Hades II profile carries what we verified end to end — the update (v1,
+ 1.0.137848) registered and packed, the measured NVN texture slots (35: slot 34 lies past the
+ translator's built-in 32) and the widescreen investigation notes — and upstream's is v0-only.
+ The fork's full file ships beside it as game.fork.tsv and is restored wholesale when the
+ sync loses the marker; if upstream reworks the profile, merge by hand."""
+ if 'build v1 1.0.137848' in t: return skip('Hades II profile (already patched)')
+ fork = (REPO / 'dm/games/0100A00019DE0000/game.fork.tsv').read_text(encoding='utf-8')
+ say(' … restoring the fork\'s Hades II profile (update v1, measured slots, notes)')
+ return done('Hades II profile v1', fork)
+
+# One marker per carrier: the string that exists only when the fork's patch is in place.
+MARKERS = {
+ 'dm/host/hle_fs.c': 'romfsarc',
+ 'dm/host/Makefile': 'romfs_arc.c',
+ 'dm/ios/tools/build_ipa.sh': 'DM_FULL_ROMFS',
+ 'scripts/build_ipa_from_nsp.py': '--work-dir',
+ 'dm/gfx/tools/shader_split.py': 'a backslash cannot sit inside an f-string expression',
+ 'dm/ios/Sources/main.m': 'romfs.idx',
+ 'dm/games/0100A00019DE0000/game.tsv': 'build v1 1.0.137848',
+}
+PATCHERS = {
+ 'dm/host/hle_fs.c': patch_hle_fs,
+ 'dm/host/Makefile': patch_makefile,
+ 'dm/ios/tools/build_ipa.sh': patch_build_ipa,
+ 'scripts/build_ipa_from_nsp.py': patch_nsp,
+ 'dm/gfx/tools/shader_split.py': patch_shader_split,
+ 'dm/ios/Sources/main.m': patch_main_m,
+ 'dm/games/0100A00019DE0000/game.tsv': patch_hades2,
+}
+
+report, problems = [], []
+class SyncProblem(Exception): pass
+def say(s): report.append(s); print(s, flush=True)
+def fail(s):
+ problems.append(s); say('[FAIL] ' + s)
+ raise SyncProblem(s)
+def skip(name): say(f' = {name}')
+def done(name, t=None):
+ say(f' + {name}')
+ return t
+
+def take_from_upstream(rev, path, dest):
+ data = blob(rev, path)
+ if data is None: fail(f'{path}: not in upstream {rev}'); return
+ dest.parent.mkdir(parents=True, exist_ok=True)
+ dest.write_bytes(data)
+
+def verify(skip_build):
+ say('--- verify ---')
+ py = '/usr/bin/python3' if os.path.exists('/usr/bin/python3') else sys.executable
+ bad = []
+ for root, dirs, files in os.walk(REPO):
+ dirs[:] = [d for d in dirs if d not in ('.git', 'third_party', '__pycache__', '.build', 'node_modules')]
+ for f in files:
+ if not f.endswith('.py'): continue
+ p = Path(root) / f
+ r = subprocess.run([py, '-c', 'import ast,sys\ntry: ast.parse(open(sys.argv[1],encoding="utf-8",errors="replace").read())\nexcept SyntaxError as e: print(f"{e.lineno}: {e.msg}")', str(p)], capture_output=True, text=True)
+ if r.stdout.strip(): bad.append(f'{p.relative_to(REPO)}:{r.stdout.strip()}')
+ if bad:
+ for b in bad: fail(f'Python 3.9 syntax: {b}')
+ else: say(f' + every .py parses on the Python 3.9 floor')
+ r = subprocess.run(['bash', '-n', 'dm/ios/tools/build_ipa.sh'], cwd=REPO, capture_output=True, text=True)
+ if r.returncode: fail(f'build_ipa.sh: bash -n failed: {r.stderr.strip()}')
+ else: say(' + build_ipa.sh: bash -n OK')
+ # archive reader: compile and run against a small generated archive
+ with tempfile.TemporaryDirectory() as td:
+ src, arc = Path(td) / 'src', Path(td) / 'romfs'
+ (src / 'sub').mkdir(parents=True)
+ (src / 'a.txt').write_bytes(b'hello'); (src / 'sub' / 'b.txt').write_bytes(b'world')
+ r = subprocess.run([sys.executable, 'dm/tools/romfs_arc.py', 'pack', str(src), str(arc), '--shard-mib', '1'], cwd=REPO, capture_output=True, text=True)
+ if r.returncode: fail(f'archive pack failed: {r.stderr.strip()[:200]}'); return
+ exe = Path(td) / 't_arc'
+ r = subprocess.run(['clang', '-O1', '-I', 'dm/host', '-o', str(exe), 'dm/host/tests/t_romfs_arc.c', 'dm/host/romfs_arc.c'], cwd=REPO, capture_output=True, text=True)
+ if r.returncode: fail(f'archive test compile failed: {r.stderr.strip()[:400]}'); return
+ r = subprocess.run([str(exe), str(arc)], capture_output=True, text=True)
+ if r.returncode or 'all checks passed' not in r.stdout: fail(f'archive test failed: {r.stdout.strip()[:200]} {r.stderr.strip()[:200]}')
+ else: say(' + archive reader test passed')
+ if skip_build: say(' = host build skipped (--skip-build)'); return
+ games = sorted(p.name for p in (REPO / 'dm/games').iterdir() if p.name.startswith('0100'))
+ game = '01006F8002326000' if '01006F8002326000' in games else games[0]
+ say(f' … building the macOS host for {game} (a few minutes)')
+ r = subprocess.run(['make', '-C', 'dm/host', f'GAME={game}', 'dmhost', '-j4'], cwd=REPO, capture_output=True, text=True)
+ if r.returncode:
+ tail = '\n'.join((r.stdout + r.stderr).splitlines()[-25:])
+ fail(f'host build failed:\n{tail}')
+ else: say(f' + host build OK ({game})')
+
+def apply_changes(a, changes):
+ """Take every changed file from upstream, then re-apply the fork's patches to the carriers."""
+ touched = 0
+ for kind, path in changes:
+ dest = REPO / path
+ if kind == 'D':
+ if path in OURS: fail(f'upstream deleted a fork file: {path}')
+ if dest.exists(): dest.unlink(); say(f' - {path}'); touched += 1
+ continue
+ if path in OURS: fail(f'upstream writes over a fork file: {path} (resolve by hand)')
+ take_from_upstream(a.new, path, dest); touched += 1
+ if path in PATCHED:
+ r = PATCHERS[path](dest.read_text(encoding='utf-8', errors='replace'))
+ if r is not None and r != dest.read_text(encoding='utf-8', errors='replace'):
+ dest.write_text(r, encoding='utf-8')
+ say(f'{touched} files taken from upstream')
+ # Second pass over every carrier, including ones upstream did not change this time: a fork
+ # patch can be lost without the file ever appearing in the diff (a wholesale tree replace,
+ # a bad merge), so presence is asserted, not assumed.
+ for path, patcher in PATCHERS.items():
+ p = REPO / path
+ if not p.exists(): fail(f'{path}: missing before patching')
+ t = p.read_text(encoding='utf-8', errors='replace')
+ r = patcher(t)
+ if r is not None and r != t: p.write_text(r, encoding='utf-8')
+ now = p.read_text(encoding='utf-8', errors='replace')
+ if MARKERS[path] not in now:
+ fail(f'{path}: fork patch marker missing after sync: {MARKERS[path]!r}')
+
+
+def main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument('--old', required=True, help='upstream ref the fork is currently at')
+ ap.add_argument('--new', required=True, help='upstream ref to sync to')
+ ap.add_argument('--skip-build', action='store_true')
+ a = ap.parse_args()
+
+ say(f'sync {a.old[:7]} → {a.new[:7]}')
+ changes = upstream_changes(a.old, a.new)
+ say(f'{len(changes)} upstream file changes under {" ".join(VENDORED)}')
+ try:
+ apply_changes(a, changes)
+ verify(a.skip_build)
+ except SyncProblem: pass
+ if problems:
+ say(f'\nSYNC FAILED: {len(problems)} problem(s) — nothing committed; the working tree is left as the script wrote it, `git checkout -- .` restores it')
+ sys.exit(1)
+ say('\nSYNC OK — commit and push from the caller')
+
+
+if __name__ == '__main__':
+ main()