Skip to content

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

fix: DLL overrides reach games launched by an already-running Steam client (#22, #25)

Gauthier Piarrette0a38e56fbdd2
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index b49f55f..495a4d8 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -163,6 +163,11 @@ public struct BottleSettings: Codable, Sendable {
/// Extra WINEDLLOVERRIDES entries, e.g. "version=n,b" for Cyber Engine Tweaks. Appended to
/// whatever the renderer sets, semicolon separated.
public var dllOverrides: String = ""
+ /// The dllOverrides value last mirrored into the prefix registry. The env var only reaches
+ /// process trees Highball spawns itself; a game started by an already-running Steam client
+ /// inherits Steam's environment from before the setting changed and never sees it
+ /// (issues #22/#25). Launches re-mirror when this differs from dllOverrides.
+ public var dllOverridesSynced: String?
public var environment: [String: String] = [:]
public var pins: [Pin] = []
public var recipes: [String] = []
@@ -194,6 +199,7 @@ public struct BottleSettings: Codable, Sendable {
dpiScale = legacyRetina == true ? 192 : 96
}
dllOverrides = try c.decodeIfPresent(String.self, forKey: .dllOverrides) ?? ""
+ dllOverridesSynced = try c.decodeIfPresent(String.self, forKey: .dllOverridesSynced)
environment = try c.decodeIfPresent([String: String].self, forKey: .environment) ?? [:]
pins = try c.decodeIfPresent([Pin].self, forKey: .pins) ?? []
recipes = try c.decodeIfPresent([String].self, forKey: .recipes) ?? []
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 63d8a5d..df5a7ab 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -85,7 +85,8 @@ public struct WineRunner: Sendable {
/// everything it and its children print lands in the log. The call returns when the program exits.
@discardableResult
public func start(_ executable: URL, arguments: [String] = [], renderer: Renderer? = nil, extraEnvironment: [String: String] = [:], workingDirectory: URL? = nil, onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
- try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, onOutput: onOutput)
+ await syncDllOverridesRegistry()
+ return try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, onOutput: onOutput)
}
/// Runs the pinned program, honouring its own renderer/env/args.
@@ -136,6 +137,10 @@ public struct WineRunner: Sendable {
_ = try await run(["reg", "add", key, "/v", name, "/t", type, "/d", data, "/f"], renderer: .wined3d, label: "reg")
}
+ public func regDelete(key: String, name: String) async throws {
+ _ = try await run(["reg", "delete", key, "/v", name, "/f"], renderer: .wined3d, label: "reg")
+ }
+
public func regQuery(key: String, name: String) async throws -> String? {
var lines: [String] = []
let collector = Collector()
@@ -145,6 +150,58 @@ public struct WineRunner: Sendable {
return line.split(whereSeparator: \.isWhitespace).last.map(String.init)
}
+ /// Parses a WINEDLLOVERRIDES-style string ("version=n,b;dxgi,d3d9=n") into per-dll registry
+ /// entries. Anything that isn't override syntax (pasted Proton launch options, quotes, spaces)
+ /// is skipped: the env var still carries the raw string, only the registry mirror filters.
+ /// Pure so it's unit-tested without a prefix.
+ public static func parseDllOverrides(_ overrides: String) -> [(name: String, order: String)] {
+ var entries: [(String, String)] = []
+ for entry in overrides.split(separator: ";") {
+ let parts = entry.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
+ guard parts.count == 2 else { continue }
+ let order = parts[1].trimmingCharacters(in: .whitespaces)
+ // n / b / native / builtin, optionally comma-paired; empty or d = disabled.
+ guard order.range(of: "^((n|b|native|builtin)(,(n|b|native|builtin))?|d|disabled)?$", options: .regularExpression) != nil else { continue }
+ for rawName in parts[0].split(separator: ",") {
+ var name = rawName.trimmingCharacters(in: .whitespaces).lowercased()
+ if name.hasSuffix(".dll") { name = String(name.dropLast(4)) }
+ guard !name.isEmpty, name.range(of: "^[a-z0-9_.+-]+$", options: .regularExpression) != nil else { continue }
+ entries.append((name, order))
+ }
+ }
+ return entries
+ }
+
+ static let dllOverridesKey = #"HKCU\Software\Wine\DllOverrides"#
+
+ /// Mirrors the bottle's DLL-overrides field into the prefix registry. The env var reaches only
+ /// process trees Highball spawns itself; a game launched through an already-running Steam client
+ /// inherits Steam's environment from before the setting changed and never sees the override, so
+ /// mods like Cyber Engine Tweaks stay silent (issues #22/#25). Every new Wine process reads this
+ /// registry key live, no matter who spawned it. No-ops unless the field changed since the last
+ /// successful sync; on failure the marker stays stale so the next launch retries.
+ public func syncDllOverridesRegistry() async {
+ let current = bottle.settings.dllOverrides
+ guard current != (bottle.settings.dllOverridesSynced ?? "") else { return }
+ let entries = Self.parseDllOverrides(current)
+ let previous = Self.parseDllOverrides(bottle.settings.dllOverridesSynced ?? "")
+ let names = Set(entries.map(\.name))
+ // Removals are best-effort: a value that's already gone makes reg exit non-zero anyway.
+ for old in previous where !names.contains(old.name) {
+ try? await regDelete(key: Self.dllOverridesKey, name: old.name)
+ }
+ var allAdded = true
+ for entry in entries {
+ let status = try? await run(["reg", "add", Self.dllOverridesKey, "/v", entry.name, "/t", "REG_SZ", "/d", entry.order, "/f"],
+ renderer: .wined3d, label: "reg").exitStatus
+ if status != 0 { allAdded = false }
+ }
+ guard allAdded else { return }
+ var copy = bottle
+ copy.settings.dllOverridesSynced = current
+ try? copy.save()
+ }
+
/// Windows UI scaling. LogPixels is the Windows system DPI (96 = 100%, 240 = 250%): DPI-aware
/// apps and launchers follow it, though many full-screen games set their own render resolution and
/// ignore it. At 96 the Mac driver renders at 1x; above that it switches to native Retina pixels
diff --git a/Tests/HighballKitTests/EnvironmentTests.swift b/Tests/HighballKitTests/EnvironmentTests.swift
index 36710a3..e4e23eb 100644
--- a/Tests/HighballKitTests/EnvironmentTests.swift
+++ b/Tests/HighballKitTests/EnvironmentTests.swift
@@ -61,6 +61,21 @@ final class EnvironmentTests: XCTestCase {
XCTAssertTrue(v.contains(";"), "WINEDLLOVERRIDES parts must be ';'-joined, got \(v)")
}
+ // The registry mirror (issues #22/#25) parses only real override syntax: multi-name
+ // entries fan out, ".dll" is stripped, and pasted Proton launch options never leak
+ // garbage value names into HKCU\Software\Wine\DllOverrides.
+ func testDllOverridesRegistryParse() {
+ func flat(_ s: String) -> [String] { WineRunner.parseDllOverrides(s).map { "\($0.name)=\($0.order)" } }
+ XCTAssertEqual(flat("version=n,b"), ["version=n,b"])
+ XCTAssertEqual(flat("dxgi,D3D9.dll=n"), ["dxgi=n", "d3d9=n"])
+ XCTAssertEqual(flat("winmm="), ["winmm="]) // empty = disabled
+ XCTAssertEqual(flat("libglesv2=d"), ["libglesv2=d"]) // explicit disable
+ XCTAssertEqual(flat("version=native,builtin;winmm=b"), ["version=native,builtin", "winmm=b"])
+ XCTAssertEqual(flat(#"WINEDLLOVERRIDES="version=n,b" %command%"#), [])
+ XCTAssertEqual(flat("just some words"), [])
+ XCTAssertEqual(flat(""), [])
+ }
+
// extra (per-pin environment from the program settings sheet) wins over bottle env.
func testExtraEnvironmentWins() throws {
var (engine, bottle) = try fixtures()