Skip to content

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

Play applies the tweaks a game's recipe requires that an environment lacks, also when it applied the recipe before, and restarts the environment when one of them sets a driver's options. Play applies a recipe once, so a dependency added later never reached the environments that played the game already: Microsoft Flight Simulator 2024's recipe now requires Flight controls as on Windows (highball-db), which makes Wine's controller driver read Honeycomb devices as raw HID because through SDL a Bravo throttle came through as a gamepad (highball#397). Those options (registry values under HKLM\System\CurrentControlSet\Services) are read when the driver starts, with the environment, so stopping the Steam client alone is not enough: after such a step Play stops Steam and then the environment when only Wine's own processes are left, and logs that a stop is needed otherwise. Recipe.missingRequiredTweaks and Recipe.changesDriverSettings carry the rules, RecipeRequirementsTests covers them. Checked on an M1 Pro: the tweak applied through the recipe runner to an r6 environment, which recorded it, and winebus logged '294b/ffffffff: enabling hidraw' at the next start; HighballApp builds.

Gauthier Piarrettea19e29f3382c
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 1f5d08d..3aa45cd 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -562,13 +562,19 @@ final class AppState {
return
}
if recipe.isAutoApplicable {
+ // The tweaks it brings along count too: a driver setting needs the environment restarted.
+ let driverSettings = recipe.changesDriverSettings
+ || recipe.missingRequiredTweaks(applied: bottle.settings.recipes, resolve: { Self.recipe($0) })
+ .contains(where: \.changesDriverSettings)
Task { @MainActor in
var runner = RecipeRunner(paths: paths, engine: engine, bottle: bottle)
if let notes = try? await runner.apply(recipe, resolve: { Self.recipe($0) }) {
logLines.append("applied the \(recipe.title) fix")
for n in notes { logLines.append("note: \(n)") }
}
- if recipe.changesLaunchEnvironment {
+ if driverSettings {
+ await restartForDriverSettings(engine: engine, bottle: runner.bottle)
+ } else if recipe.changesLaunchEnvironment {
// A running Steam keeps the environment it started with; the game we are
// about to launch through it would never see the recipe's settings. Only
// the client stops: other programs in the environment keep running.
@@ -593,9 +599,55 @@ final class AppState {
}))
return
}
+ // A recipe applied before it gained a dependency: the tweaks it requires now and this environment lacks are
+ // applied before the launch, since Play applies a recipe once (Microsoft Flight Simulator 2024's flight
+ // controls tweak for environments set up on 0.10.22 and earlier, highball#397).
+ if let recipe = fixRecipe(for: item), !recipe.isOptIn, bottle.settings.recipes.contains(recipe.id),
+ let engine = engine(for: bottle) {
+ let missing = recipe.missingRequiredTweaks(applied: bottle.settings.recipes, resolve: { Self.recipe($0) })
+ if !missing.isEmpty, missing.allSatisfy(\.isAutoApplicable) {
+ Task { @MainActor in
+ var runner = RecipeRunner(paths: paths, engine: engine, bottle: bottle)
+ for tweak in missing {
+ if let notes = try? await runner.apply(tweak, resolve: { Self.recipe($0) }) {
+ logLines.append("applied \(tweak.title), which \(recipe.title) now needs")
+ for n in notes { logLines.append("note: \(n)") }
+ }
+ }
+ if missing.contains(where: \.changesDriverSettings) {
+ await restartForDriverSettings(engine: engine, bottle: runner.bottle)
+ } else if missing.contains(where: \.changesLaunchEnvironment) {
+ try? await WineRunner(paths: paths, engine: engine, bottle: runner.bottle).stopSteam()
+ logLines.append("stopped the Steam client so the new settings apply to this launch")
+ }
+ refresh()
+ let fresh = bottles.first { $0.name == bottleName } ?? runner.bottle
+ launch(item, in: fresh, renderer: renderer)
+ }
+ return
+ }
+ }
launch(item, in: bottle, renderer: renderer)
}
+ /// After a recipe or tweak wrote a driver's settings (Recipe.changesDriverSettings). Wine's drivers read them
+ /// when the environment starts, so the environment stops before the launch when, the Steam client aside, only
+ /// Wine's own processes run in it, and the launch starts it again with the new settings. Programs the owner
+ /// started keep running, and the log says to stop the environment once.
+ private func restartForDriverSettings(engine: InstalledEngine, bottle: Bottle) async {
+ guard ProcessTable.liveServer(forPrefix: bottle.url) != nil else { return }
+ let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
+ try? await runner.stopSteam()
+ // Steam's web helpers can outlive the client by a moment.
+ for _ in 0..<10 where !ProcessTable.isIdle(prefix: bottle.url) { try? await Task.sleep(for: .milliseconds(500)) }
+ if ProcessTable.isIdle(prefix: bottle.url) {
+ _ = try? runner.kill()
+ logLines.append("stopped \(bottle.name) so Wine's drivers start with the new settings")
+ } else {
+ logLines.append("\(bottle.name) has programs running, so its drivers keep their old settings until it stops (Stop all processes)")
+ }
+ }
+
private func launch(_ item: LibraryItem, in bottle: Bottle, renderer: Renderer? = nil) {
recordPlay(item)
if !FunnelLog.records(in: paths.logs).contains(where: { $0.event == .firstLaunch }) { funnel(.firstLaunch) }
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swift
index 7f59844..15bd09c 100644
--- a/Sources/HighballKit/Recipe.swift
+++ b/Sources/HighballKit/Recipe.swift
@@ -218,6 +218,28 @@ public struct Recipe: Codable, Sendable, Identifiable {
}
}
+ /// True when a step writes a Windows driver's or service's settings, a registry value under
+ /// HKLM\System\CurrentControlSet\Services. A driver reads them when it starts, and Wine starts its drivers
+ /// with the environment: the controller driver read winebus's device options once, when Steam brought the
+ /// environment up, so stopping the Steam client alone left a Honeycomb Bravo a gamepad (highball#397).
+ public var changesDriverSettings: Bool {
+ steps.contains { if case let .registry(key, _, _, _) = $0 { return Self.isServiceKey(key) } else { return false } }
+ }
+
+ static func isServiceKey(_ key: String) -> Bool {
+ let k = key.lowercased().replacingOccurrences(of: "/", with: "\\")
+ return [#"hklm\system\currentcontrolset\services\"#, #"hkey_local_machine\system\currentcontrolset\services\"#]
+ .contains { k.hasPrefix($0) }
+ }
+
+ /// The tweaks this recipe requires that an environment has not applied, in order. A recipe can gain a
+ /// dependency after environments applied it, and Play applies a recipe once, so without this the
+ /// environments that played the game before never got it (Microsoft Flight Simulator 2024's flight controls
+ /// tweak, highball#397). Launchers in `requires` say where the game comes from and are not applied.
+ public func missingRequiredTweaks(applied: [String], resolve: (String) -> Recipe?) -> [Recipe] {
+ (requires ?? []).filter { !applied.contains($0) }.compactMap { resolve($0) }.filter { $0.kind == .tweak }
+ }
+
public struct KnownIssue: Codable, Sendable {
public var symptom: String
public var cause: String?
diff --git a/Tests/HighballKitTests/RecipeRequirementsTests.swift b/Tests/HighballKitTests/RecipeRequirementsTests.swift
new file mode 100644
index 0000000..1248b9e
--- /dev/null
+++ b/Tests/HighballKitTests/RecipeRequirementsTests.swift
@@ -0,0 +1,49 @@
+import XCTest
+@testable import HighballKit
+
+/// A recipe's later dependencies and the steps that only take effect when Wine's drivers start (highball#397).
+final class RecipeRequirementsTests: XCTestCase {
+ private func recipe(_ json: String) throws -> Recipe {
+ try JSONDecoder.highball.decode(Recipe.self, from: Data(json.utf8))
+ }
+
+ func testMissingRequiredTweaksSkipsAppliedOnesAndLaunchers() throws {
+ let game = try recipe("""
+ {"id": "msfs", "kind": "game", "title": "Flight", "requires": ["steam", "flight-controls-raw-hid", "dotnet48", "gone"],
+ "steps": [{"type": "note", "text": "x"}]}
+ """)
+ let tweaks = [
+ "flight-controls-raw-hid": try recipe("""
+ {"id": "flight-controls-raw-hid", "kind": "tweak", "title": "Flight controls", "steps": [{"type": "note", "text": "x"}]}
+ """),
+ "dotnet48": try recipe("""
+ {"id": "dotnet48", "kind": "tweak", "title": ".NET", "steps": [{"type": "note", "text": "x"}]}
+ """),
+ "steam": try recipe("""
+ {"id": "steam", "kind": "launcher", "title": "Steam", "steps": [{"type": "note", "text": "x"}]}
+ """),
+ ]
+ let missing = game.missingRequiredTweaks(applied: ["msfs", "dotnet48"], resolve: { tweaks[$0] })
+ XCTAssertEqual(missing.map(\.id), ["flight-controls-raw-hid"],
+ "an applied tweak, a launcher and an id this build doesn't ship are not applied again")
+ XCTAssertEqual(game.missingRequiredTweaks(applied: ["flight-controls-raw-hid", "dotnet48"], resolve: { tweaks[$0] }).count, 0)
+ }
+
+ func testDriverSettingsAreRegistryValuesUnderServices() throws {
+ let raw = try recipe("""
+ {"id": "flight-controls-raw-hid", "kind": "tweak", "title": "Flight controls", "steps": [
+ {"type": "registry", "key": "HKLM\\\\System\\\\CurrentControlSet\\\\Services\\\\winebus\\\\Devices\\\\294b", "name": "Hidraw", "valueType": "REG_DWORD", "data": "1"}]}
+ """)
+ XCTAssertTrue(raw.changesDriverSettings)
+ XCTAssertFalse(raw.changesLaunchEnvironment, "a registry value is no launch variable")
+ XCTAssertTrue(Recipe.isServiceKey(#"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\winebus"#))
+ XCTAssertTrue(Recipe.isServiceKey("hklm/system/currentcontrolset/services/winebus"))
+ XCTAssertFalse(Recipe.isServiceKey(#"HKCU\Software\Wine\WineBus"#), "Wine never reads winebus options there")
+ XCTAssertFalse(Recipe.isServiceKey(#"HKLM\System\CurrentControlSet\Control\Session Manager"#))
+ let dll = try recipe("""
+ {"id": "x", "kind": "tweak", "title": "X", "steps": [
+ {"type": "registry", "key": "HKCU\\\\Software\\\\Wine\\\\DllOverrides", "name": "xaudio2_7", "valueType": "REG_SZ", "data": "native"}]}
+ """)
+ XCTAssertFalse(dll.changesDriverSettings)
+ }
+}