Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
Battle.net games take part in highball library and highball play, and get Mac apps like other games (highball#432, #417)
Gauthier Piarretteadc48b3b972d
diff --git a/Sources/HighballKit/PlayLink.swift b/Sources/HighballKit/PlayLink.swiftindex e44a8f3..a1e76c0 100644--- a/Sources/HighballKit/PlayLink.swift+++ b/Sources/HighballKit/PlayLink.swift@@ -10,6 +10,8 @@ public enum PlayLink {case steam(appid: Int)case epic(appName: String)case pin(bottle: String, id: UUID)+ /// A game Battle.net installed, by Blizzard's product code (highball#417, #432).+ case battlenet(product: String)/// A launcher (Steam, Epic, …) by recipe id: `highball://open/launcher/steam`. Opens it,/// installing it first if needed (issue #53: Mac icons for launchers too).case launcher(id: String)@@ -21,6 +23,7 @@ public enum PlayLink {case let .steam(appid): return "steam:\(appid)"case let .epic(name): return "epic:\(name)"case let .pin(bottle, id): return "pin:\(bottle):\(id.uuidString)"+ case let .battlenet(product): return "battlenet:\(product)"case let .launcher(id): return "launcher:\(id)"}}@@ -44,6 +47,9 @@ public enum PlayLink {let bottle = String(rest[..<last])guard !bottle.isEmpty, let uuid = UUID(uuidString: String(rest[rest.index(after: last)...])) else { return nil }self = .pin(bottle: bottle, id: uuid)+ case "battlenet":+ guard Self.isProductCode(rest) else { return nil }+ self = .battlenet(product: rest)case "launcher":guard rest.range(of: "^[a-z0-9-]+$", options: .regularExpression) != nil else { return nil }self = .launcher(id: rest)@@ -51,6 +57,11 @@ public enum PlayLink {return nil}}++ /// Blizzard's product codes are short words of letters, digits and underscores (wow_classic).+ static func isProductCode(_ s: String) -> Bool {+ s.range(of: "^[A-Za-z0-9_]+$", options: .regularExpression) != nil+ }}public struct Request: Equatable, Sendable {@@ -81,6 +92,9 @@ public enum PlayLink {case "pin":guard parts.count == 3, !parts[1].isEmpty, let id = UUID(uuidString: parts[2]) else { return nil }return Request(target: .pin(bottle: parts[1], id: id), token: token)+ case "battlenet":+ guard parts.count == 2, Target.isProductCode(parts[1]) else { return nil }+ return Request(target: .battlenet(product: parts[1]), token: token)default:return nil}@@ -93,6 +107,7 @@ public enum PlayLink {case let .steam(appid): c.path = "/steam/\(appid)"case let .epic(name): c.path = "/epic/\(name)"case let .pin(bottle, id): c.path = "/pin/\(bottle)/\(id.uuidString)"+ case let .battlenet(product): c.path = "/battlenet/\(product)"case let .launcher(id): c.host = "open"; c.path = "/launcher/\(id)"}c.queryItems = [URLQueryItem(name: "t", value: token)]@@ -103,6 +118,7 @@ public enum PlayLink {if let appid = item.steamAppID { return .steam(appid: appid) }if let name = item.epicAppName { return .epic(appName: name) }if let id = item.pinID, let bottle = item.bottleName { return .pin(bottle: bottle, id: id) }+ if let product = item.battleNetProduct { return .battlenet(product: product) }return nil}diff --git a/Sources/highball/main.swift b/Sources/highball/main.swiftindex 7dc51b2..2e1b80b 100644--- a/Sources/highball/main.swift+++ b/Sources/highball/main.swift@@ -738,7 +738,7 @@ struct Epic: AsyncParsableCommand {// MARK: - highball library / play (highball#432)/// The library as the app builds it, read from disk: the environments' Steam games, installed and-/// owned, Steam for Mac's installs, the programs added by hand, and with `epic` the Epic account's+/// owned, Steam for Mac's installs, Battle.net's installs, the programs added by hand, and with `epic` the Epic account's/// games, which asks legendary. Not-installed games are homed as the app homes them (AppState's/// defaultBottle: the Games environment, else the first with Steam, else the first).func currentLibrary(paths: HighballPaths, epic: Bool) -> [LibraryItem] {@@ -755,8 +755,10 @@ func currentLibrary(paths: HighballPaths, epic: Bool) -> [LibraryItem] {FileManager.default.fileExists(atPath: b.driveC.appending(path: "Program Files (x86)/Steam/steam.exe").path)}let home = bottles.first { $0.name == "Games" } ?? bottles.first(where: hasSteam) ?? bottles.first+ let battleNet = Dictionary(bottles.map { ($0.name, BattleNetLibrary.games(in: $0)) }, uniquingKeysWith: { a, _ in a })return LibraryIndex.build(bottles: bottles, steamByBottle: steam, steamOwnedByBottle: owned,macInstalled: MacSteam.installedGames(), epicOwned: epicOwned, epicInstalls: epicInstalls,+ battleNetByBottle: battleNet,plays: LibraryStore(paths: paths).load(), defaultBottle: home?.name,pinExists: { b, pin in FileManager.default.fileExists(atPath: pin.executableURL(driveC: b.driveC).path) })}@@ -790,7 +792,7 @@ struct Play: AsyncParsableCommand {abstract: "Start a library game through the Highball app, as its Play button does.",discussion: """The id is one `highball library` lists: steam:<appid>, epic:<app name> or \- pin:<environment>:<uuid>, and launcher:<id> opens a launcher. Highball starts it with \+ pin:<environment>:<uuid>, battlenet:<product code>, and launcher:<id> opens a launcher. Highball starts it with \the game's own settings and stays in the background, the way a game's Mac app does. \With --wait the command returns once the game has quit, for frontends such as ES-DE, \and Highball and Steam keep running. It follows the games Highball runs in its \@@ -802,7 +804,7 @@ struct Play: AsyncParsableCommand {func run() async throws {guard let target = PlayLink.Target(libraryID: id) else {- fail("\(id) is not a library id. `highball library` lists them: steam:<appid>, epic:<app name>, pin:<environment>:<uuid>.")+ fail("\(id) is not a library id. `highball library` lists them: steam:<appid>, epic:<app name>, pin:<environment>:<uuid>, battlenet:<product code>.")}let paths = HighballPaths()// A typo fails here and now, not as an alert in the app and a wait that never ends.@@ -814,7 +816,7 @@ struct Play: AsyncParsableCommand {guard store.isAuthenticated, EpicStore.installMap((try? store.installedGames()) ?? [])[name] != nil else {fail("\(id) is not an installed Epic game in this Highball. `highball library --installed` lists what can be played.")}- case .steam, .pin:+ case .steam, .pin, .battlenet:guard currentLibrary(paths: paths, epic: false).contains(where: { $0.id == target.libraryID }) else {fail("\(id) is not in this Highball's library. `highball library` lists the ids.")}diff --git a/Tests/HighballKitTests/PlayFromCommandLineTests.swift b/Tests/HighballKitTests/PlayFromCommandLineTests.swiftindex 8bf004c..ee29453 100644--- a/Tests/HighballKitTests/PlayFromCommandLineTests.swift+++ b/Tests/HighballKitTests/PlayFromCommandLineTests.swift@@ -8,11 +8,16 @@ final class PlayFromCommandLineTests: XCTestCase {func testEveryLibraryIdNamesTheTargetItsLinkStarts() {let uuid = UUID(uuidString: "B43215E4-3490-4E8A-835B-3668A02B279F")!let targets: [PlayLink.Target] = [.steam(appid: 2420510), .epic(appName: "Fortnite"),- .pin(bottle: "Games", id: uuid), .launcher(id: "ea-app")]+ .pin(bottle: "Games", id: uuid), .battlenet(product: "wow_classic"),+ .launcher(id: "ea-app")]for target in targets {XCTAssertEqual(PlayLink.Target(libraryID: target.libraryID), target, target.libraryID)}XCTAssertEqual(PlayLink.Target(libraryID: "steam:620")?.libraryID, "steam:620")+ // A Battle.net game's link is the one its Mac app would open (highball#417, #432).+ let link = PlayLink.url(for: .battlenet(product: "pro"), token: "t")+ XCTAssertEqual(link.absoluteString, "highball://play/battlenet/pro?t=t")+ XCTAssertEqual(PlayLink.parse(link)?.target, .battlenet(product: "pro"))}/// An environment's name may hold a colon or a space; the program's id ends at its uuid.@@ -29,7 +34,7 @@ final class PlayFromCommandLineTests: XCTestCase {func testAnythingElseIsNotAnId() {for bad in ["", "steam", "steam:", "steam:0", "steam:-3", "steam:abc", "epic:", "pin:Games","pin::B43215E4-3490-4E8A-835B-3668A02B279F", "pin:Games:not-a-uuid", "gog:123",- "launcher:Steam Client", "launcher:../x", "2420510"] {+ "launcher:Steam Client", "launcher:../x", "2420510", "battlenet:", "battlenet:../wow", "battlenet:wow classic"] {XCTAssertNil(PlayLink.Target(libraryID: bad), bad)}}