Skip to content

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

launcher: build a NUP or game folder of a game with no profile when the engine surveys it (#748, #721)

v0lumehi0645efac6731
diff --git a/frontend/Sources/NXCore/BuildFailureKind.swift b/frontend/Sources/NXCore/BuildFailureKind.swift
index 693b460a..d128f999 100644
--- a/frontend/Sources/NXCore/BuildFailureKind.swift
+++ b/frontend/Sources/NXCore/BuildFailureKind.swift
@@ -8,7 +8,6 @@ package enum BuildFailureKind: String, CaseIterable {
case rosetta, translator, zbic, iosSDK, cltSelected, otherMetal, shaderRegression, damagedNSP, a32Program
/// The inputs: the keys file, the game folder, a drive that is gone.
case keys, severalGames, noTitleID, driveMissing
- /// A game folder or NUP (a Switch 2 game, GameFolder.swift) of a game the engine has no profile for: the script packs one only with a profile.
/// prod.keys lacks the master key the game needs: the keys are older than the game (nx_extract's exit code 6, seedds/nxnative 3104c0a).
case keysOld
/// The build's and the install's own steps.
diff --git a/frontend/Sources/NXCore/GameFolder.swift b/frontend/Sources/NXCore/GameFolder.swift
index 83810467..13536db4 100644
--- a/frontend/Sources/NXCore/GameFolder.swift
+++ b/frontend/Sources/NXCore/GameFolder.swift
@@ -185,12 +185,20 @@ package enum GameFolder {
!engineRoot.isEmpty && FileManager.default.fileExists(atPath: engineRoot + "/scripts/pack_nup.py")
}
- /// Whether the engine has a profile for the game. The script packs a game folder only for a game with a profile: the survey
- /// that makes a provisional one reads NSPs.
+ /// Whether the engine has a profile for the game: `dm/games/<title ID>/game.tsv`. An engine that surveys a game without one
+ /// (`engineSurveysWithoutProfile`) does not need it to build a NUP or a game folder.
package static func engineHasProfile(_ titleID: UInt64, engineRoot: String) -> Bool {
!engineRoot.isEmpty && FileManager.default.fileExists(atPath: engineRoot + "/dm/games/" + String(format: "%016llX", titleID) + "/game.tsv")
}
+ /// Whether the engine builds a NUP or a game folder of a game with no profile, from a provisional profile it makes by a survey:
+ /// `scripts/build_ipa_from_nsp.py` has `survey_nup` and `survey_dump` (seedds/nxnative 056e41fe, PR #1295). An older engine packs
+ /// a game folder only for a game with a profile.
+ package static func engineSurveysWithoutProfile(_ engineRoot: String) -> Bool {
+ guard !engineRoot.isEmpty, let data = FileManager.default.contents(atPath: engineRoot + "/scripts/build_ipa_from_nsp.py") else { return false }
+ return data.range(of: Data("def survey_nup".utf8)) != nil
+ }
+
/// The `name` row of the game's profile: a game folder has no control data, so the script names the app after it too.
package static func profileName(_ titleID: UInt64, engineRoot: String) -> String? {
guard !engineRoot.isEmpty,
diff --git a/frontend/Sources/NXModel/BuildStore+GameFolder.swift b/frontend/Sources/NXModel/BuildStore+GameFolder.swift
index 3cb77955..1dd8c531 100644
--- a/frontend/Sources/NXModel/BuildStore+GameFolder.swift
+++ b/frontend/Sources/NXModel/BuildStore+GameFolder.swift
@@ -37,16 +37,18 @@ extension BuildStore {
updateSlot("base") { $0.problem = why }
}
- /// What the engine lacks for this folder: the packer (an older engine), or a profile for the game. nil without an engine yet:
- /// the build asks again before it starts.
+ /// What the engine lacks for this folder: the packer, or a profile for the game. Only an engine without the survey needs the
+ /// profile, a newer one builds a game with no profile from a provisional one. nil without an engine yet: the build asks again
+ /// before it starts.
package func gameFolderEngineProblem(_ contents: GameFolder.Contents) -> String? {
let engine = EngineLayout.root(repo.path)
guard !engine.isEmpty, FileManager.default.fileExists(atPath: engine + "/dm") else { return nil }
if contents.nup != nil ? !GameFolder.engineBuildsNUPs(engine) : !GameFolder.engineBuildsFolders(engine) {
return t(contents.nup != nil ? "folder.engineOldNUP" : "folder.engineOld")
}
- // A NUP whose package table names no title ID: the script reads it from the code, and checks the profile itself
- if contents.hasTitleID, !GameFolder.engineHasProfile(contents.titleID, engineRoot: engine) { return String(format: t("folder.noProfile"), contents.titleIDHex) }
+ // A NUP whose package table names no title ID: the script reads it from the code, and checks the profile itself.
+ // An engine with the survey builds a game with no profile from a provisional one.
+ if contents.hasTitleID, !GameFolder.engineSurveysWithoutProfile(engine), !GameFolder.engineHasProfile(contents.titleID, engineRoot: engine) { return String(format: t("folder.noProfile"), contents.titleIDHex) }
return nil
}
diff --git a/frontend/Tests/NXCoreTests/GameFolderTests.swift b/frontend/Tests/NXCoreTests/GameFolderTests.swift
index ed7fca42..5172b55e 100644
--- a/frontend/Tests/NXCoreTests/GameFolderTests.swift
+++ b/frontend/Tests/NXCoreTests/GameFolderTests.swift
@@ -129,6 +129,16 @@ final class GameFolderTests: XCTestCase {
write("engine/dm/games/040074A01BF12000/game.tsv")
XCTAssertTrue(GameFolder.engineHasProfile(0x040074A01BF12000, engineRoot: engine))
}
+
+ func testTheSurveyWithoutAProfileIsFoundInTheBuildScript() {
+ let engine = root + "/engine"
+ XCTAssertFalse(GameFolder.engineSurveysWithoutProfile(engine))
+ XCTAssertFalse(GameFolder.engineSurveysWithoutProfile(""))
+ write("engine/scripts/build_ipa_from_nsp.py", Data("def survey_dump(src, out):\n pass\n".utf8))
+ XCTAssertFalse(GameFolder.engineSurveysWithoutProfile(engine), "the NUP survey is the mark")
+ write("engine/scripts/build_ipa_from_nsp.py", Data("def survey_dump(src, out):\n pass\ndef survey_nup(n, k, base, out):\n pass\n".utf8))
+ XCTAssertTrue(GameFolder.engineSurveysWithoutProfile(engine))
+ }
}
extension GameFolderTests {
diff --git a/frontend/Tests/NXModelTests/GameFolderStoreTests.swift b/frontend/Tests/NXModelTests/GameFolderStoreTests.swift
index 73de40e0..2558b764 100644
--- a/frontend/Tests/NXModelTests/GameFolderStoreTests.swift
+++ b/frontend/Tests/NXModelTests/GameFolderStoreTests.swift
@@ -212,6 +212,30 @@ import XCTest
XCTAssertEqual(store.slot("base").problem, store.t("folder.engineOldNUP"))
}
+ /// An old engine (no survey in the script) refuses a NUP of a game it has no profile for, one with the survey builds it.
+ func testANUPOfAGameWithoutAProfileNeedsTheSurveyInTheEngine() throws {
+ let (store, _) = makeStore(profile: false)
+ let nup = root + "/Bananza.nup"
+ write(nup, nupData())
+ write(root + "/engine/scripts/build_ipa_from_nsp.py", Data("def survey_dump(src, out):\n pass\n".utf8))
+ store.scan(folder: nup)
+ XCTAssertEqual(store.slot("base").problem, String(format: store.t("folder.noProfile"), "040074A01BF12000"))
+ XCTAssertFalse(store.canBuild)
+ write(root + "/engine/scripts/build_ipa_from_nsp.py", Data("def survey_nup(n, k, base, out):\n pass\n".utf8))
+ store.scan(folder: nup)
+ XCTAssertEqual(store.gameFolder?.nup, nup)
+ XCTAssertEqual(store.slot("base").problem, "")
+ XCTAssertTrue(store.canBuild)
+ }
+
+ func testAGameFolderOfAGameWithoutAProfileNeedsTheSurveyInTheEngine() {
+ let (store, game) = makeStore(profile: false)
+ write(root + "/engine/scripts/build_ipa_from_nsp.py", Data("def survey_nup(n, k, base, out):\n pass\n".utf8))
+ store.scan(folder: game)
+ XCTAssertNotNil(store.gameFolder)
+ XCTAssertTrue(store.canBuild)
+ }
+
/// A NUP's header and package table: base, one update, no data (as syntheticNUP in NXCoreTests).
private func nupData() -> Data {
func put(_ d: inout [UInt8], _ o: Int, _ v: UInt64, _ n: Int) { for i in 0..<n { d[o + i] = UInt8(v >> (8 * UInt64(i)) & 0xFF) } }