Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,4 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25
- [`devicectl` copies a large RomFS image through the Mac's memory](../../../docs/reference/packing.md#devicectl-copies-a-large-romfs-image-through-the-macs-memory): the 26.2 GB image's pushes to an iPad filled a 16 GB Mac's swap and failed; now sent over AFC.
- [`devicectl`'s `--remove-existing-content` empties the app's whole container](../../../docs/reference/packing.md#devicectls---remove-existing-content-empties-the-apps-whole-container): the first complete copy of the image, deleted by the DLC step after it.
- [The driver wires memory tens of thousands of times a second with residency sets on the queues](../../../docs/reference/frame-rate.md#the-driver-wires-memory-tens-of-thousands-of-times-a-second-with-residency-sets-on-the-queues): resolved by naming the residency sets on each command buffer; the driver's cause is open. 0 of 20 launches in the state on a 16 GB M4 and 0 of 4 on a 16 GB M2, against 10 of 20 and 5 of 5.
- [An app packed from a NUP without control data says version 1.0](../../../docs/reference/packing.md#an-app-packed-from-a-nup-without-control-data-says-version-10): fixed in the NSP script. This game's NUP carries no NACP and its build row no display version, so the Mac app said 1.0; the script now takes the NUP's display version record, 1.1.1.
12 changes: 8 additions & 4 deletions dm/tools/nacp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The game name, display version and languages from the NSP's control data (control.nacp, saved in the extraction folder by nx_extract): the iOS app name and version come from them (shared by the packing script and build_ipa.sh),
# and the packing script checks the game language against the languages the game supports.
# Usage: nacp.py <control.nacp> (prints the game name), nacp.py --version <control.nacp> (prints the display version), nacp.py --languages <control.nacp> (prints the supported language codes);
# each prints an empty line and exits 1 when none can be read. From Python: import nacp; nacp.name(path), nacp.version(path), nacp.languages(path)
# each prints an empty line and exits 1 when none can be read. From Python: import nacp; nacp.name(path), nacp.version(path), nacp.bundle_version(text), nacp.languages(path)
import re, struct, sys, zlib
from pathlib import Path

Expand Down Expand Up @@ -33,9 +33,13 @@ def name(path):
def version(path):
"""The display version (0x10 bytes at 0x3060, e.g. 1.2.1), cut to what iOS accepts as a bundle version (up to three dot-separated integers); a missing file or no leading number returns an empty string"""
p = Path(path)
if not p.is_file(): return ''
m = re.match(rb'\d+(\.\d+){0,2}', p.read_bytes()[0x3060:0x3070])
return m.group().decode() if m else ''
return bundle_version(p.read_bytes()[0x3060:0x3070].decode('latin-1')) if p.is_file() else ''


def bundle_version(text):
"""A display version from elsewhere (a game profile's build row, a NUP's label) cut the same way: 1.2.1 of 1.2.1_5; no leading number (v131072, ?, None) returns an empty string"""
m = re.match(r'\d+(\.\d+){0,2}', text or '')
return m.group() if m else ''


def languages(path):
Expand Down
15 changes: 15 additions & 0 deletions dm/tools/tests/test_nsp_nup.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,21 @@ def test_name_label_without_nacp_writes_none(self): # the script then takes th
self.assertFalse((self.out() / 'control.nacp').exists())
self.assertEqual((self.out() / 'icon.jpg').read_bytes(), b'\xff\xd8 icon')

def test_app_version_without_nacp_is_the_profiles_then_the_label(self): # a NUP update carries no control data: Ocarina of Time's Mac app said 1.0 for 1.1.1
write_nup(self.path, [(0, TID, 0, version(), tlv([(pack_nup.T_DISPLAY, b'1.1.1')])), (1, TID, VER, version(), b''), (1, TID, VER + 1, version(), tlv([(pack_nup.T_DISPLAY, b'v2 final')]))])
n = self.open(); _, base, vers, _ = pack_nup.scan(n)
self.assertEqual([pack_nup.display_label(*a) for a in ((base,), (vers[VER], base), (vers[VER],), (vers[VER + 1], base))], ['1.1.1', '1.1.1', '', 'v2 final']) # an update's own, else its base game's
with_nacp, bare = self.dir / 'with', self.dir / 'bare'; with_nacp.mkdir(); bare.mkdir()
(with_nacp / 'control.nacp').write_bytes(control_nacp('Test Game', 'テス', '1.2.3'))
g = mock.Mock(builds=lambda: {'v1': {'display': '1.4.0_5', 'main': 'aa'}, 'v2': {'display': 'v131072', 'main': 'bb'}, 'v3': {'display': '?'}})
vars(nsp)['nacp'] = nacp; of = nsp.app_version_of # main sets it
self.assertEqual(of(with_nacp, bare, g, 'v1', '9.9'), '1.2.3') # the packed version's control data
self.assertEqual(of(bare, with_nacp, g, 'v1', '9.9'), '1.2.3') # the base game's
self.assertEqual(of(bare, bare, g, 'v1', '9.9'), '1.4.0') # the profile's build row, cut to a bundle version
self.assertEqual(of(bare, bare, g, 'v2', '1.1.1'), '1.1.1') # a row without a display version: the label
self.assertEqual(of(bare, bare, g, 'v3', 'v2 final'), '') # a label that is no version: none (the app says 1.0)
self.assertEqual(of(bare, bare, g, 'v9'), '') # a version no row names, no label

def test_repeat_keeps_what_is_unchanged(self):
n = self.open(); app, base, vers, _ = pack_nup.scan(n)
pack_nup.pack_version(n, vers[VER], base, app, self.out(), say=lambda s: None)
Expand Down
1 change: 1 addition & 0 deletions docs/agents/symptoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
- a game version the profile registers, packed with fewer DLC (or none, or other ones) than the profile was split with, stops at the shader split with `the split shader tables differ from game profile <id>'s`, though the NSP script should derive a DLC-only profile for it (`the installed DLC shader content differs from the registered tables: using a shader-only derived profile`). → [A registered build without the profile's DLC stops at the shader split](../reference/packing.md#a-registered-build-without-the-profiles-dlc-stops-at-the-shader-split)
- a program packed alone (`--program N`) or packed with its launcher (the launcher's profile names it in `programs`) mounts another DLC than the one it asks for, or none: the build prints `DLC index 0:` for the application's first DLC, the run reports one index fewer than the build extracted (`aoc: reporting 1 add-on contents {1}` for two DLC), `fs mount dlc:` names the wrong image, and the program can end at start (`nnMain returned`). → [A program of a multi-program game mounts the wrong DLC](../reference/packing.md#a-program-of-a-multi-program-game-mounts-the-wrong-dlc)
- the game shows `?` where it shows its version (Super Mario Bros. Wonder's title screen: `Ver. ?`), and the build's lines name the version as `v327680 (?)`. → [A game packed from a NUP or a dump shows "Ver. ?" for a build its profile registers](../reference/packing.md#a-game-packed-from-a-nup-or-a-dump-shows-ver--for-a-build-its-profile-registers)
- Finder shows `Version 1.0` for the Mac app of a game at another version (`CFBundleShortVersionString` 1.0 in its `Info.plist`), and the build's game line names 1.0. → [An app packed from a NUP without control data says version 1.0](../reference/packing.md#an-app-packed-from-a-nup-without-control-data-says-version-10)
- the settings of a Mac app or IPA packed from a NUP or a dump folder have no Game language row, while `DM_LANG` in the environment changes the language. Reported on Donkey Kong Bananza (NX2Apple#619, #659; the reporters' packed files were not available). → [No Game language row in an app packed from a NUP or a dump](../reference/packing.md#no-game-language-row-in-an-app-packed-from-a-nup-or-a-dump)
- starting a Mac app through a front end with unchanged settings enables the encode thread, and can disable Metal 4 pipelines and the pipeline archive; starting the same app from Finder keeps the host's defaults. → [A Mac front end's default settings change Metal execution paths](../reference/packing.md#a-mac-front-ends-default-settings-change-metal-execution-paths)
- in a Mac app, the settings window stays on screen after **Play**, not responding (a spinning cursor over it), until the game ends. → [The Mac settings window stays on screen after Play](../reference/packing.md#the-mac-settings-window-stays-on-screen-after-play)
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/packing.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@
- **Found on:** [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md) (1.2.1, v327680, an update-only NUP; `main` ff773e90…, the registered build): `Ver. ?` before, `Ver. 1.2.1` after, one Mac boot each to the title screen.
- **Check:** `dm/tools/tests/test_nsp_alias.py` `test_derived_profile_keeps_the_display_version_the_profile_registers_for_the_build`.

### An app packed from a NUP without control data says version 1.0

- **Symptom:** Finder shows `Version 1.0` for the Mac app of a game at another version (`CFBundleShortVersionString` 1.0 in its `Info.plist`), and the build's game line names 1.0.
- **Cause:** the app version came from `control.nacp` alone, the packed version's or else the base game's. A NUP's packages may carry none (the container then has the display version only as a record its packer typed) and a dump has none, so the script passed no version and the packer wrote its default.
- **Fix:** `app_version_of` takes the control data first, then the display version the profile's `build` row registers for the packed version, then the NUP's display version record (`pack_nup.display_label`: the package's, else its base game's or the metadata record's). Each is cut to a bundle version, and a row or a label that is no version (`v131072`, `?`) gives none. The IPA takes the same version.
- **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) (v131072, a NUP with a base game and an update package, neither with a NACP and both labelled `1.1.1`; its build row has no display version): the Mac app said 1.0. For that NUP and its build folder the function now gives 1.1.1; the app was not packed again.
- **Check:** `dm/tools/tests/test_nsp_nup.py` `test_app_version_without_nacp_is_the_profiles_then_the_label`.

### No Game language row in an app packed from a NUP or a dump

- **Symptom:** the settings of a Mac app or IPA packed from a NUP or a dump folder have no Game language row, while `DM_LANG` in the environment changes the language. Reported on [Donkey Kong Bananza](../../dm/games/040074A01BF12000/README.md) ([NX2Apple#619](https://github.com/LNPANDY/NX2Apple/issues/619), [#659](https://github.com/LNPANDY/NX2Apple/issues/659); the reporters' packed files were not available).
Expand Down
11 changes: 9 additions & 2 deletions scripts/build_ipa_from_nsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3146,6 +3146,14 @@ def app_icon(given, spare, *dirs):
return given or own or spare, bool(spare and not (given or own))


def app_version_of(game, base, g, pkg_ver, label=''):
"""The app version is the packed game's display version: the update's control data when an update is packed (nx_extract saves it next to the RomFS), else the base game's. A package
without control data (a NUP update, a dump) has the one the profile registers for the packed build, then the label a NUP's packer gave it (pack_nup.display_label; The Legend of Zelda:
Ocarina of Time's NUP has no NACP and a build row without a display version, and its Mac app said 1.0 for 1.1.1). Each is cut to a bundle version; '' when none gives one (the app then says 1.0)"""
return (nacp.version(game / 'control.nacp') or nacp.version(base / 'control.nacp') or nacp.bundle_version((g.builds().get(pkg_ver) or {}).get('display'))
or nacp.bundle_version(label))


def say_game(app, name, version, bundle_id, out, icon):
"""Which game the app is, once its name, version and bundle ID are settled (before the shader stages): the event game for a front end (json mode; the base game's title ID as DMTitleID has it,
out = the IPA or Mac app, None for an Xcode project; icon = the image the app is given: --icon / ICON, else the extracted icon.jpg, else --fallback-icon / FALLBACK_ICON; None without one), then the message for people"""
Expand Down Expand Up @@ -3413,8 +3421,7 @@ def main(args=None):
if prepare_xcode:
try: xcode_projects.check_bundle_id(workspace, project, bundle_id)
except ValueError as e: raise BuildError(str(e)) from e
# the app version is the packed game's display version: the update's control data when an update is packed (nx_extract saves it next to the RomFS), else the base game's
app_version = nacp.version(game / 'control.nacp') or nacp.version(base / 'control.nacp')
app_version = app_version_of(game, base, g, pkg_ver, pack_nup.display_label(picks[pkg_ver][1] or picks[pkg_ver][0], picks[pkg_ver][0] or pack_nup.app_package(fam['nup'])) if nup else '') # a NUP without a base game: its metadata record, as for its control data
if mac_pack and not (args.out or OUT_IPA): out_ipa = work.parent / f'{mac_app_name(app_name)}{"-provisional" if shadowed else ""}.app'
icon, stand_in = app_icon(user_icon, spare_icon, game, base)
if (not mac or mac_pack) and getattr(args, 'in_programs', None) is None: # an app is made, once: a program packed with the application's first (in_programs) is part of its app
Expand Down
10 changes: 8 additions & 2 deletions scripts/pack_nup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# a .nup file, or a folder that holds one, and goes on with its other steps; run on its own, this script does only this step.
# A NUP holds the same packages as a dump folder (scripts/pack_dump.py): the base game, updates by version and DLC by title ID, each an exefs/ and romfs/ tree, its files stored raw or as one zstd
# frame each, with a SHA-256 per file. Its files are not encrypted, so it needs no keys. Unlike a dump it may carry control data in each package's meta block: the NACP and the icon. Its name,
# publisher and display version records are labels the packer typed (Hyrule Warriors: Age of Imprisonment's says "HWAoI"), not the console's: without a NACP the name comes from the profile.
# publisher and display version records are labels the packer typed (Hyrule Warriors: Age of Imprisonment's says "HWAoI"), not the console's: without a NACP the name comes from the profile, and the app version from the profile's build row, else the display version label (display_label).
# A container may hold no base game, in two forms that mean the same: no base record, with standalone_update on every update (SPEC §3.1.2), or a base record with no files (title ID 0), as packers
# leave when an update holds the whole game (Pokemon Pokopia's v655360). The title ID is then the program ID of the code present, there is no version 0, and the selected update needs its own ExeFS
# and RomFS, taken as the whole game. The flag does not promise that (the spec says such an update needs a matching base elsewhere), and nothing in a container can prove it, so the scripts say so
Expand Down Expand Up @@ -43,7 +43,7 @@ class Error(Exception): pass
BASE, UPDATE, ADDON = 0, 1, 2
KINDS = ('base', 'update', 'addon', 'addon_update', 'system')
STANDALONE = 1 # package flags bit 0: an update in a container without a base
T_NACP, T_ICON, T_LICONS = 2, 3, 10
T_NACP, T_ICON, T_DISPLAY, T_LICONS = 2, 3, 4, 10
ARTIFACTS = romfs_image.ARTIFACTS # dump-tool files a producer may have kept (SPEC §6.3): not game files
NO_BASE = 'no base game in this NUP: its update is taken as the whole game (if the game then stops on missing files, the update holds only what changed: pack a NUP with the base game)'

Expand Down Expand Up @@ -401,6 +401,12 @@ def control(k, out, fallback=None): # the package's control data beside its Ex
else: (out / name).unlink(missing_ok=True)


def display_label(k, base=None): # the display version the packer labelled the package with (else its base game's), '' without one. A label, not the console's value (the header):
for p in (k, base): # the app version takes it only when no control data and no build row of the profile gives one
if p is not None and (v := p.meta().get(T_DISPLAY)): return v.decode('utf-8', 'replace')
return ''


def romfs_of(k, base): # the RomFS folder a version runs with: its own, or the base game's for an update without one
d = k.romfs if k.romfs != NO_DIR else base.romfs if base is not None else NO_DIR
if d == NO_DIR: raise Error(f'{k.name}: no romfs/ in this package or the base game')
Expand Down
Loading