Skip to content

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

8.5 KB
Raw Blame
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: v0lumehi <[email protected]>
Date: Wed, 28 Oct 2026 13:34:47 +0100
Subject: [PATCH] Builds record the fork's patches: DMForkPatches in Info.plist
 and the first line of the log

dm/fork_patches.txt (one patch name per line, written by scripts/patches.py from the series) is stamped into
the iOS app's Info.plist (project.yml, build_ipa.sh) and the Mac app's (pack_app.py). The iOS host writes
"fork patches: <names>" as the first line of Documents/log.txt, the Mac launcher as the first line of its log.
A report from such a build says which patches it carried, so one from a configuration upstream does not
support goes to the fork, not to seedds/nxnative.

Upstream-Status: fork-only
Reason: Route bug reports: a build beyond upstream's support matrix names the patches it carries
Issue: LNPANDY/NX2Apple#123
---
 dm/ios/Sources/main.m       | 3 +++
 dm/ios/project.yml          | 1 +
 dm/ios/tools/build_ipa.sh   | 1 +
 dm/ios/tools/build_smoke.py | 2 +-
 dm/mac/launcher.c           | 2 ++
 dm/mac/pack_app.py          | 9 ++++++++-
 6 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/dm/ios/Sources/main.m b/dm/ios/Sources/main.m
index 56267e1..076d4ef 100644
--- a/dm/ios/Sources/main.m
+++ b/dm/ios/Sources/main.m
@@ -234,6 +234,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);
+    // First line of the log: the fork's patches this build carries (Info.plist DMForkPatches), so a report says whether it comes from a build beyond upstream's support
+    NSString *fork_patches = [NSBundle.mainBundle objectForInfoDictionaryKey:@"DMForkPatches"];
+    fprintf(stderr, "fork patches: %s\n", [fork_patches isKindOfClass:NSString.class] && fork_patches.length ? fork_patches.UTF8String : "none");
     // Environment switch files (for on-device diagnostics: a sideloaded app cannot be given environment variables from outside): one KEY=VALUE per line, # starts a comment; Documents/env.txt takes precedence over dm/env.txt in the bundle (put there by build_ipa.sh's DM_ENV_FILE)
     NSMutableArray<NSString *> *from_file = [NSMutableArray array], *from_launch = [NSMutableArray array];
     for (char **e = environ; *e; e++) {   // set at launch (Xcode, devicectl): before the env files, and the launcher keeps them
diff --git a/dm/ios/project.yml b/dm/ios/project.yml
index e542cf1..8964dbb 100644
--- a/dm/ios/project.yml
+++ b/dm/ios/project.yml
@@ -48,6 +48,7 @@ targets:
         LSApplicationCategoryType: ${DM_APP_CATEGORY}   # game profile app_category
         DMShowFPS: ${DM_SHOW_FPS}           # YES = the frame-rate counter is on (front_ios.m; set by build_ipa.sh)
         DMLanguage: ${DM_LANG}              # the game language code (main.m sets DM_LANG from it; set by build_ipa.sh)
+        DMForkPatches: ${DM_FORK_PATCHES}   # the fork's patches this build carries (dm/fork_patches.txt, written by scripts/patches.py; set by build_ipa.sh)
         LSSupportsGameMode: true
         GCSupportsControllerUserInteraction: true   # Physical controllers (GameController)
         GCSupportedGameControllers:
diff --git a/dm/ios/tools/build_ipa.sh b/dm/ios/tools/build_ipa.sh
index ad5b881..3448d38 100755
--- a/dm/ios/tools/build_ipa.sh
+++ b/dm/ios/tools/build_ipa.sh
@@ -44,6 +44,7 @@ VNACP=${CONTROL:-$VNACP}   # from here on, the file that lists the game's langua
 export LC_ALL=C DM_BUNDLE_ID=${DM_BUNDLE_ID:-org.nxnative.$(echo "$GAME" | tr 'A-Z' 'a-z')} DM_DISPLAY_NAME DM_APP_VERSION DM_APP_CATEGORY=$(gp app_category) DM_TEAM_ID=${DM_TEAM_ID:-0000000000}   # placeholder identity: unsigned, the install tool replaces it
 if [ "${DM_SHOW_FPS:-0}" = 1 ]; then export DM_SHOW_FPS=YES; else export DM_SHOW_FPS=NO; fi
 export DM_LANG=${DM_LANG:-en-US}
+export DM_FORK_PATCHES=$(paste -sd, "$DM/fork_patches.txt" 2>/dev/null || true)   # DMForkPatches in Info.plist (scripts/patches.py writes the list; empty on a build without fork patches)
 if [ "$PREPARE_XCODE" = YES ]; then
   IOS=${DM_XCODE_PROJECT_DIR:-$W/xcode}
   mkdir -p "$IOS" || die "mkdir $IOS"
diff --git a/dm/ios/tools/build_smoke.py b/dm/ios/tools/build_smoke.py
index aa5732a..2e94b2e 100644
--- a/dm/ios/tools/build_smoke.py
+++ b/dm/ios/tools/build_smoke.py
@@ -55,7 +55,7 @@ def main():
                DM_BUNDLE_ID='org.nxnative.ci', DM_DISPLAY_NAME='CI build fixture',
                DM_APP_VERSION='1.0', DM_APP_CATEGORY=profile.get('app_category'),
                DM_TEAM_ID='', DM_SCHEME_NAME='DmIOS', DM_APPICON='',
-               DM_SHOW_FPS='NO', DM_LANG='en-US')
+               DM_SHOW_FPS='NO', DM_LANG='en-US', DM_FORK_PATCHES='')
 
     def run(*command, capture=False):
         return subprocess.run([str(c) for c in command], cwd=project, env=env,
diff --git a/dm/mac/launcher.c b/dm/mac/launcher.c
index 42e8ba7..a80f656 100644
--- a/dm/mac/launcher.c
+++ b/dm/mac/launcher.c
@@ -207,6 +207,7 @@ int main(int argc, char **argv) {
     snprintf(dm, sizeof dm, "%s/dm", res); snprintf(romfs, sizeof romfs, "%s/romfs", res);
     char name[256] = "nxnative", id[64] = "", marker[512] = "", lang[32] = "";
     if (!info_string("CFBundleName", name, sizeof name)) snprintf(name, sizeof name, "nxnative");
+    char fork_patches[1024] = ""; info_string("DMForkPatches", fork_patches, sizeof fork_patches);
     info_string("DMRomfsMarker", marker, sizeof marker); info_string("DMLanguage", lang, sizeof lang);
     if (!info_string("DMTitleID", id, sizeof id) || strchr(id, '/')) { alert(name, "This app has no title ID in its Info.plist (DMTitleID): pack it again with build_ipa_from_nsp.py --platform mac-app."); return 1; }
     struct stat st; snprintf(p, sizeof p, "%s/romfs.img", res);
@@ -278,6 +279,7 @@ int main(int argc, char **argv) {
     rename(log, prev);
     int fd = open(log, O_WRONLY | O_CREAT | O_TRUNC, 0644);
     if (fd >= 0) { dup2(fd, 1); dup2(fd, 2); close(fd); setvbuf(stdout, NULL, _IOLBF, 0); }
+    fprintf(stderr, "fork patches: %s\n", *fork_patches ? fork_patches : "none");   // first line of the log (Info.plist DMForkPatches)
     fprintf(stderr, "launcher: %s (%s), host %s\n", name, id, host);
     CFArrayRef rules = setting_rules();   // the settings the launch environment already set: the window shows them, fixed
     for (CFIndex i = 0; rules && i < CFArrayGetCount(rules); i++) { char env[128]; if (rule_env(CFArrayGetValueAtIndex(rules, i), env, sizeof env) && getenv(env)) add_key(&g_launch_keys, env); }
diff --git a/dm/mac/pack_app.py b/dm/mac/pack_app.py
index 56f82c5..d25c446 100755
--- a/dm/mac/pack_app.py
+++ b/dm/mac/pack_app.py
@@ -118,12 +118,19 @@ def settings_rules(listed):   # DMSettings: what the launcher accepts as each se
     return rules
 
 
+def fork_patches():
+    """The fork's patches this build carries (dm/fork_patches.txt, written by scripts/patches.py), comma-separated: DMForkPatches in Info.plist, and the first line of the log"""
+    try: return ','.join(l.strip() for l in (Path(__file__).resolve().parents[1] / 'fork_patches.txt').read_text().splitlines() if l.strip())
+    except OSError: return ''
+
+
 def info_plist(a, minos, icon):
     # LSSupportsGameMode off: macOS's Game Mode holds the GPU at its lowest clock while it is busy (docs/reference/frame-rate.md, macOS Game Mode holds the GPU at its lowest clock)
     p = {'CFBundleName': a.name, 'CFBundleDisplayName': a.name, 'CFBundleIdentifier': a.bundle_id or f'org.nxnative.{a.title_id.lower()}',
          'CFBundleVersion': a.version or '1.0', 'CFBundleShortVersionString': a.version or '1.0', 'CFBundlePackageType': 'APPL', 'CFBundleExecutable': EXE,
          'CFBundleInfoDictionaryVersion': '6.0', 'LSMinimumSystemVersion': minos, 'LSArchitecturePriority': ['arm64'], 'NSHighResolutionCapable': True,
-         'LSApplicationCategoryType': a.category or 'public.app-category.games', 'LSSupportsGameMode': False, 'DMTitleID': a.title_id.upper(), 'DMRomfsMarker': a.marker or '', 'DMLanguage': a.lang or 'en-US'}
+         'LSApplicationCategoryType': a.category or 'public.app-category.games', 'LSSupportsGameMode': False, 'DMTitleID': a.title_id.upper(), 'DMRomfsMarker': a.marker or '', 'DMLanguage': a.lang or 'en-US',
+         'DMForkPatches': fork_patches()}
     if icon: p['CFBundleIconFile'] = 'AppIcon'
     if a.settings:
         listed = json.loads(Path(a.settings).read_text(encoding='utf-8'))['settings']