Skip to content

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

A game's variables follow its recipe as the database has it now. A recipe's variables are written into the environment when it is applied, so a database fix that changed or dropped one never reached an environment set up before it. Planet Coaster 2's recipe dropped two Metal validation variables that froze two Macs, and both players' environments still carried them (highball-db#115, #356). Play now brings the game's variables in line with its recipe and says so in the log. A pin the recipe added follows where it still holds the recipe's old value, so a hand edit stays. Unit-tested (473 tests pass), not yet exercised through Play in the app

Gauthier Piarrette88562e57ab07
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 3bf5f88..43b6a7f 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -397,14 +397,22 @@ final class AppState {
var bottle = found
// A game whose recipe was applied before variables were scoped still has them bottle-wide,
// where every other program inherits them (highball#198). Move them to the game once; the
- // launch below then carries them for this game only, and the log says what moved.
+ // launch below then carries them for this game only, and the log says what moved. Then the
+ // game's variables follow its recipe as the database has it now, so a fix that changed or
+ // dropped one reaches environments set up before it (highball-db#115, #356).
if let recipe = fixRecipe(for: item), bottle.settings.recipes.contains(recipe.id) {
var settings = bottle.settings
let moved = HighballKit.Recipe.scopeLeakedEnvironment(of: recipe, in: &settings)
- if !moved.isEmpty {
+ let synced = HighballKit.Recipe.syncScopedEnvironment(of: recipe, in: &settings)
+ if !moved.isEmpty || !synced.isEmpty {
bottle.settings = settings
try? bottle.save()
- appendLog("\(item.title): \(moved.joined(separator: ", ")) now applies to this game only, not to everything in \(bottle.name).")
+ if !moved.isEmpty {
+ appendLog("\(item.title): \(moved.joined(separator: ", ")) now applies to this game only, not to everything in \(bottle.name).")
+ }
+ if !synced.isEmpty {
+ appendLog("\(item.title): the fix's variables now match the database (\(synced.joined(separator: ", "))).")
+ }
refresh()
}
}
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swift
index 17cf9dc..871c0ca 100644
--- a/Sources/HighballKit/Recipe.swift
+++ b/Sources/HighballKit/Recipe.swift
@@ -649,4 +649,36 @@ public extension Recipe {
}
return moved
}
+
+ /// Brings the variables a game recipe scoped to its game in line with the recipe as it is
+ /// now. They are written when the recipe is applied, so a database update that changed or
+ /// dropped one never reached an environment set up before it: Planet Coaster 2's recipe
+ /// dropped two Metal validation variables after they froze two Macs, and both players'
+ /// environments kept them (highball-db#115, #356, 2026-10-06). Only the recipe writes
+ /// `gameEnvironment[recipe.id]`, so it follows the recipe exactly. A pin the recipe added
+ /// carries a copy, which follows only where it still holds the recipe's old value: a value
+ /// changed by hand stays. Returns the names added, changed or dropped, sorted, empty when
+ /// the environment already matches.
+ static func syncScopedEnvironment(of recipe: Recipe, in settings: inout BottleSettings) -> [String] {
+ guard recipe.kind == .game else { return [] }
+ var wanted: [String: String] = [:]
+ var pinPaths: [String] = []
+ for step in recipe.steps {
+ switch step {
+ case let .environment(name, value): wanted[name] = value
+ case let .pin(p): pinPaths.append(p.path)
+ default: break
+ }
+ }
+ let had = settings.gameEnvironment[recipe.id] ?? [:]
+ let changed = Set(had.keys).union(wanted.keys).filter { had[$0] != wanted[$0] }.sorted()
+ guard !changed.isEmpty else { return [] }
+ settings.gameEnvironment[recipe.id] = wanted.isEmpty ? nil : wanted
+ for i in settings.pins.indices where pinPaths.contains(settings.pins[i].path) {
+ for name in changed where settings.pins[i].environment[name] == had[name] {
+ settings.pins[i].environment[name] = wanted[name]
+ }
+ }
+ return changed
+ }
}
diff --git a/Tests/HighballKitTests/RecipeScopeTests.swift b/Tests/HighballKitTests/RecipeScopeTests.swift
index 1431f2e..d720607 100644
--- a/Tests/HighballKitTests/RecipeScopeTests.swift
+++ b/Tests/HighballKitTests/RecipeScopeTests.swift
@@ -84,6 +84,57 @@ final class RecipeScopeTests: XCTestCase {
XCTAssertEqual(Recipe.scopeLeakedEnvironment(of: try recipe(launcher), in: &l), [])
}
+ /// Planet Coaster 2's recipe dropped its two Metal validation variables after they froze two
+ /// Macs, and environments set up before kept them (highball-db#115, #356). Play brings a
+ /// game's variables in line with its recipe as the database has it now.
+ func testGameVariablesFollowTheRecipeAsItIsNow() throws {
+ let coaster = try recipe("""
+ {"id": "planet-coaster-2", "kind": "game", "title": "Planet Coaster 2", "requires": ["steam"],
+ "renderer": "d3dmetal", "steps": [{"type": "renderer", "renderer": "d3dmetal"}],
+ "knownIssues": [], "lastVerified": null}
+ """)
+ var settings = BottleSettings(name: "t", engineID: "e")
+ settings.gameEnvironment["planet-coaster-2"] = ["MTL_DEBUG_LAYER": "1", "MTL_DEBUG_LAYER_ERROR_MODE": "nslog"]
+ settings.gameEnvironment["the-sims-legacy-collection"] = ["MVK_SHADOW_IMPORT": "1"]
+ settings.environment = ["MY_OWN": "x"]
+ XCTAssertEqual(Recipe.syncScopedEnvironment(of: coaster, in: &settings), ["MTL_DEBUG_LAYER", "MTL_DEBUG_LAYER_ERROR_MODE"])
+ XCTAssertNil(settings.gameEnvironment["planet-coaster-2"], "dropped from the recipe, dropped here")
+ XCTAssertEqual(settings.gameEnvironment["the-sims-legacy-collection"], ["MVK_SHADOW_IMPORT": "1"], "another game's stay")
+ XCTAssertEqual(settings.environment, ["MY_OWN": "x"], "the environment's own list is the owner's")
+ XCTAssertEqual(Recipe.syncScopedEnvironment(of: coaster, in: &settings), [], "already in line")
+ // A changed value comes back to the recipe's, and one the recipe never set goes.
+ var old = BottleSettings(name: "t", engineID: "e")
+ old.gameEnvironment["the-sims-legacy-collection"] = ["MVK_SHADOW_IMPORT": "0", "OLD": "x"]
+ XCTAssertEqual(Recipe.syncScopedEnvironment(of: try recipe(sims), in: &old), ["MVK_SHADOW_IMPORT", "OLD"])
+ XCTAssertEqual(old.gameEnvironment["the-sims-legacy-collection"], ["MVK_SHADOW_IMPORT": "1"])
+ // A variable the recipe gained since arrives.
+ var none = BottleSettings(name: "t", engineID: "e")
+ XCTAssertEqual(Recipe.syncScopedEnvironment(of: try recipe(sims), in: &none), ["MVK_SHADOW_IMPORT"])
+ XCTAssertEqual(none.gameEnvironment["the-sims-legacy-collection"], ["MVK_SHADOW_IMPORT": "1"])
+ // A launcher's variables are bottle-wide and never touched here.
+ var l = BottleSettings(name: "t", engineID: "e")
+ l.environment = ["DXMT_ALLOW_CROSS_PROCESS_SWAPCHAIN": "1"]
+ XCTAssertEqual(Recipe.syncScopedEnvironment(of: try recipe(launcher), in: &l), [])
+ XCTAssertEqual(l.environment, ["DXMT_ALLOW_CROSS_PROCESS_SWAPCHAIN": "1"])
+ }
+
+ func testAPinsCopyFollowsOnlyWhereItHoldsTheRecipesOldValue() throws {
+ let game = try recipe("""
+ {"id": "some-game", "kind": "game", "title": "Some Game", "requires": [], "renderer": null,
+ "steps": [{"type": "environment", "name": "A", "value": "2"},
+ {"type": "pin", "pin": {"name": "Some Game", "path": "Games/some.exe"}}],
+ "knownIssues": [], "lastVerified": null}
+ """)
+ var settings = BottleSettings(name: "t", engineID: "e")
+ settings.gameEnvironment["some-game"] = ["A": "1", "B": "1"]
+ settings.pins = [Pin(name: "Some Game", path: "Games/some.exe", environment: ["A": "1", "B": "mine", "C": "3"]),
+ Pin(name: "Other", path: "Games/other.exe", environment: ["A": "1"])]
+ XCTAssertEqual(Recipe.syncScopedEnvironment(of: game, in: &settings), ["A", "B"])
+ XCTAssertEqual(settings.gameEnvironment["some-game"], ["A": "2"])
+ XCTAssertEqual(settings.pins[0].environment, ["A": "2", "B": "mine", "C": "3"], "the recipe's old value follows, a hand edit stays")
+ XCTAssertEqual(settings.pins[1].environment, ["A": "1"], "a pin the recipe did not add is not its")
+ }
+
func testSteamRestartsWhenTheClientCarriesAnotherGamesVariable() {
var settings = BottleSettings(name: "t", engineID: "e")
settings.gameEnvironment["the-sims-legacy-collection"] = ["MVK_SHADOW_IMPORT": "1"]