Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

Launch arguments per game: a field on a Steam game's page, kept in library.json beside its graphics mode and passed on every Play after any the database adds (highball#236)

Gauthier Piarrettec787a3bfdd65
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index a36174e..c0c4b06 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -140,6 +140,16 @@ final class AppState {
/// Graphics modes chosen per game (library id), the store's copy for the views.
var libraryOverrides: [String: Renderer] = [:]
func rendererOverride(for item: LibraryItem) -> Renderer? { libraryOverrides[item.id] }
+ /// Launch arguments the player set for a game (highball#236), by library id.
+ var libraryLaunchArgs: [String: [String]] = [:]
+ func launchArguments(for item: LibraryItem) -> [String] { libraryLaunchArgs[item.id] ?? [] }
+ func setLaunchArguments(_ line: String, for item: LibraryItem) {
+ let args = ArgumentLine.split(line)
+ guard args != launchArguments(for: item) else { return }
+ libraryStore.setLaunchArguments(args, for: item.id)
+ libraryLaunchArgs = libraryStore.launchArguments()
+ appendLog(args.isEmpty ? "\(item.id): launch arguments cleared" : "\(item.id): launch arguments set to \(ArgumentLine.join(args))")
+ }
func setRendererOverride(_ renderer: Renderer?, for id: String) {
libraryStore.setRendererOverride(renderer, for: id)
libraryOverrides = libraryStore.rendererOverrides()
@@ -863,6 +873,7 @@ final class AppState {
startDiscordWatch()
libraryPlays = libraryStore.load()
libraryOverrides = libraryStore.rendererOverrides()
+ libraryLaunchArgs = libraryStore.launchArguments()
rebuildLibrary()
steamOwnedRefresh()
epicRefresh()
@@ -2240,8 +2251,9 @@ final class AppState {
// A mode the user set on the environment is respected, as the page promises; the row's
// verified mode applies otherwise, and a forced mode (the D3DMetal ask) beats both.
let renderer = preferred ?? (bottle.settings.rendererExplicit ? nil : entry?.effectiveRenderer())
- // Per-game launch args ride the db (e.g. windowed for legacy CS:GO on macOS 26, #21).
- let extraArgs = entry?.effectiveLaunchArgs() ?? []
+ // Per-game launch args ride the db (e.g. windowed for legacy CS:GO on macOS 26, #21), then
+ // the ones the player set on the game's page (highball#236).
+ let extraArgs = (entry?.effectiveLaunchArgs() ?? []) + (libraryLaunchArgs["steam:\(game.appid)"] ?? [])
// The variables this game's recipe scoped to it (highball#198); other games get none of them.
let gameEnvironment = bottle.settings.environment(forGame: entry?.id)
let markers = SessionWatch.markers(installdir: game.installdir)
diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swift
index c7218e3..7b0eea8 100644
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@ -8,6 +8,10 @@ struct GameDetailView: View {
let passedItem: LibraryItem
@State private var showBottleSettings = false
@State private var coverDropTargeted = false
+ /// The launch arguments being typed; saved on Return and when the page closes, so a space
+ /// typed between two arguments is not normalised away mid-word.
+ @State private var argsText = ""
+ @State private var argsLoaded = false
/// The live row: after an install, a delete or a rename, the passed-in copy goes stale.
private var item: LibraryItem { state.libraryItems.first { $0.id == passedItem.id } ?? passedItem }
@State private var showWhy = false
@@ -342,6 +346,23 @@ struct GameDetailView: View {
}
}
}
+ if item.source == .steam {
+ HStack(alignment: .top, spacing: 12) {
+ Text(L("Launch arguments")).font(.caption).foregroundStyle(.secondary).frame(width: 110, alignment: .leading).padding(.top, 4)
+ VStack(alignment: .leading, spacing: 4) {
+ TextField("", text: $argsText, prompt: Text(verbatim: "-dx11 -windowed"))
+ .font(.body.monospaced()).frame(maxWidth: 360)
+ .onSubmit { state.setLaunchArguments(argsText, for: item) }
+ Text(L("Passed to the game on every Play from Highball, after any its fix adds. Quote arguments that contain spaces."))
+ .font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
+ }
+ }
+ .onAppear {
+ guard !argsLoaded else { return }
+ argsText = ArgumentLine.join(state.launchArguments(for: item)); argsLoaded = true
+ }
+ .onDisappear { state.setLaunchArguments(argsText, for: item) }
+ }
// The engine is the environment's, so the page says so and can change it
// through the same switch page as the environment's settings, which lists
// every program that moves along (highball#262: an engine shown here that
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 1573aee..6522cde 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -522,6 +522,7 @@ enum L10n {
// An environment that already fits a game's engine, and the windows Highball brings forward (highball-db#318, highball#264)
"%d installed": "%d installés",
"Play there": "Y jouer",
+ "Passed to the game on every Play from Highball, after any its fix adds. Quote arguments that contain spaces.": "Transmis au jeu à chaque lancement depuis Highball, après ceux qu'ajoute son correctif. Mettez entre guillemets les arguments qui contiennent des espaces.",
"The engine belongs to the environment '%@', so a change here applies to every game in it. The page that opens lists them before anything moves.": "Le moteur appartient à l'environnement « %@ » : le changer ici l'applique à tous ses jeux. La page qui s'ouvre les liste avant tout changement.",
"Choose the program on the disc": "Choisissez le programme du disque",
"Usually the disc's setup or install program.": "En général le programme d'installation du disque.",
diff --git a/Sources/HighballKit/Library.swift b/Sources/HighballKit/Library.swift
index ccf2964..ea03a0d 100644
--- a/Sources/HighballKit/Library.swift
+++ b/Sources/HighballKit/Library.swift
@@ -257,6 +257,10 @@ public struct LibraryStore: Sendable {
/// to change one game without changing the whole environment). Optional so files written
/// before it still decode.
var overrides: [String: Renderer]?
+ /// Launch arguments the player set for one game, by library id, passed after any the
+ /// database adds (highball#236: the only ways were Steam's own Launch Options or a program
+ /// entry). Optional so older files still decode.
+ var launchArgs: [String: [String]]?
}
public let paths: HighballPaths
@@ -283,6 +287,18 @@ public struct LibraryStore: Sendable {
if let data = try? JSONEncoder.highball.encode(shape) { try? data.write(to: fileURL, options: .atomic) }
}
+ public func launchArguments() -> [String: [String]] { loadShape().launchArgs ?? [:] }
+
+ /// Sets, or with an empty list clears, the launch arguments of one game.
+ public func setLaunchArguments(_ args: [String], for id: String) {
+ var shape = loadShape()
+ var all = shape.launchArgs ?? [:]
+ all[id] = args.isEmpty ? nil : args
+ shape.launchArgs = all.isEmpty ? nil : all
+ try? paths.ensure()
+ if let data = try? JSONEncoder.highball.encode(shape) { try? data.write(to: fileURL, options: .atomic) }
+ }
+
private func loadShape() -> FileShape {
guard let data = try? Data(contentsOf: fileURL),
let shape = try? JSONDecoder.highball.decode(FileShape.self, from: data) else { return FileShape() }
diff --git a/Tests/HighballKitTests/LibraryTests.swift b/Tests/HighballKitTests/LibraryTests.swift
index 4546b04..cf7f1f6 100644
--- a/Tests/HighballKitTests/LibraryTests.swift
+++ b/Tests/HighballKitTests/LibraryTests.swift
@@ -150,4 +150,18 @@ final class LibraryTests: XCTestCase {
try? Data(acf.replacingOccurrences(of: "1756300000", with: "0").utf8).write(to: tmp)
XCTAssertNil(SteamLibrary.parseManifest(tmp)?.lastPlayed)
}
+
+ // highball#236: launch arguments for one game, kept beside its graphics mode.
+ func testLaunchArgumentsPerGameRoundTripAndClear() throws {
+ let home = FileManager.default.temporaryDirectory.appending(path: "hb-args-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: home) }
+ let store = LibraryStore(paths: HighballPaths(home: home))
+ XCTAssertTrue(store.launchArguments().isEmpty)
+ store.setLaunchArguments(["-dx11", "-windowed"], for: "steam:1174180")
+ store.setRendererOverride(.d3dmetal, for: "steam:1174180")
+ XCTAssertEqual(store.launchArguments()["steam:1174180"], ["-dx11", "-windowed"])
+ XCTAssertEqual(store.rendererOverrides()["steam:1174180"], .d3dmetal, "the two settings live side by side")
+ store.setLaunchArguments([], for: "steam:1174180")
+ XCTAssertNil(store.launchArguments()["steam:1174180"])
+ }
}