Skip to content

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

play: an Unreal 5 build counts as needing Direct3D 12, and the pick defers to rows and per-game choices (#138)

Gauthier Piarretteb38c4fb48786
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 6d71237..a753039 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -248,13 +248,16 @@ final class AppState {
var wanted = Renderer.choose(requested: renderer, gameOverride: rendererOverride(for: item), row: entry?.effectiveRenderer(),
environmentExplicit: bottle.settings.rendererExplicit, pin: pinMode,
environment: bottle.settings.renderer, nativeVulkan: entry?.nativeVulkan == true)
- // A program with only Direct3D 12 cannot run on DXMT, DXVK or Wine's Direct3D, so a
+ // A program that needs Direct3D 12 cannot run on DXMT, DXVK or Wine's Direct3D, so a
// mode that has it takes over before the launch, and the log says so (Farming
- // Simulator 22 stopped at "Shader model 6.0 is required" on DXMT, highball#139).
- if !wanted.servesDirect3D12, entry?.nativeVulkan != true, programNeedsDirect3D12Only(item) {
+ // Simulator 22 stopped at "Shader model 6.0 is required" on DXMT, highball#139;
+ // Unreal 5 titles stop before their menu, highball#138). Only when nothing more
+ // specific chose the mode: a row's verified mode or a per-game choice stands.
+ if !wanted.servesDirect3D12, renderer == nil, rendererOverride(for: item) == nil, entry?.effectiveRenderer() == nil,
+ entry?.nativeVulkan != true, programNeedsDirect3D12(item) {
let instead = Renderer.forDirect3D12Only(chosen: wanted, engine: engine)
if instead != wanted {
- appendLog("\(item.title) only has Direct3D 12 and \(GamePageCopy.plainName(wanted)) has none, playing with \(GamePageCopy.plainName(instead)).")
+ appendLog("\(item.title) needs Direct3D 12 and \(GamePageCopy.plainName(wanted)) has none, playing with \(GamePageCopy.plainName(instead)).")
wanted = instead
renderer = instead
}
@@ -1085,15 +1088,15 @@ final class AppState {
}
}
- /// Whether the item's program links Direct3D 12 and nothing else to draw with, remembered
+ /// Whether the item's program needs Direct3D 12 (`ProgramNeeds.wantsDirect3D12`), remembered
/// per executable and modification date: finding the executable walks the game's folder.
- private var direct3D12OnlyCache: [String: (exe: URL, modified: Date, verdict: Bool)] = [:]
- func programNeedsDirect3D12Only(_ item: LibraryItem) -> Bool {
+ private var direct3D12Cache: [String: (exe: URL, modified: Date, verdict: Bool)] = [:]
+ func programNeedsDirect3D12(_ item: LibraryItem) -> Bool {
guard let exe = programExecutable(for: item) else { return false }
let modified = (try? exe.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
- if let hit = direct3D12OnlyCache[item.id], hit.exe == exe, hit.modified == modified { return hit.verdict }
- let verdict = ProgramNeeds.direct3D12Only(program: exe)
- direct3D12OnlyCache[item.id] = (exe, modified, verdict)
+ if let hit = direct3D12Cache[item.id], hit.exe == exe, hit.modified == modified { return hit.verdict }
+ let verdict = ProgramNeeds.wantsDirect3D12(program: exe)
+ direct3D12Cache[item.id] = (exe, modified, verdict)
return verdict
}
diff --git a/Sources/HighballKit/PEImports.swift b/Sources/HighballKit/PEImports.swift
index f652001..a6587c2 100644
--- a/Sources/HighballKit/PEImports.swift
+++ b/Sources/HighballKit/PEImports.swift
@@ -93,4 +93,32 @@ public enum ProgramNeeds {
}
return names.contains(direct3D12) && names.isDisjoint(with: otherGraphics)
}
+
+ /// An Unreal Engine 5 packaged build: `<root>/<Game>/Binaries/Win64/<exe>` with the engine's
+ /// own `Engine/Binaries` beside it and IoStore containers (`.utoc`) under the game's Paks.
+ /// Unreal links every renderer into one executable and loads d3d12.dll at run time, so its
+ /// imports say nothing (The Last Caretaker's name dxgi and opengl32 only), and its choice of
+ /// API sits in a config file inside the pak. Unreal 5 defaults to Direct3D 12 with Shader
+ /// Model 6 and most titles ship no Direct3D 11 shaders, so on a mode without Direct3D 12
+ /// they stop before the menu (highball#138, highball-db#105). Unreal 4 packages without
+ /// IoStore and defaults to Direct3D 11, so it is left alone.
+ public static func isUnreal5Build(program exe: URL) -> Bool {
+ let win64 = exe.deletingLastPathComponent()
+ let binaries = win64.deletingLastPathComponent()
+ guard win64.lastPathComponent.lowercased() == "win64", binaries.lastPathComponent.lowercased() == "binaries" else { return false }
+ let game = binaries.deletingLastPathComponent()
+ let root = game.deletingLastPathComponent()
+ let fm = FileManager.default
+ guard fm.fileExists(atPath: root.appending(path: "Engine/Binaries").path) else { return false }
+ let paks = game.appending(path: "Content/Paks")
+ let entries = (try? fm.contentsOfDirectory(at: paks, includingPropertiesForKeys: nil)) ?? []
+ return entries.contains { $0.pathExtension.lowercased() == "utoc" }
+ }
+
+ /// Whether the program needs a mode with Direct3D 12: its imports say so, or it is an
+ /// Unreal 5 build. Used only when nothing more specific (a row, a per-game choice) says
+ /// which mode to run.
+ public static func wantsDirect3D12(program exe: URL) -> Bool {
+ direct3D12Only(program: exe) || isUnreal5Build(program: exe)
+ }
}
diff --git a/Tests/HighballKitTests/PEImportsTests.swift b/Tests/HighballKitTests/PEImportsTests.swift
index ff88d4c..f383fcf 100644
--- a/Tests/HighballKitTests/PEImportsTests.swift
+++ b/Tests/HighballKitTests/PEImportsTests.swift
@@ -87,6 +87,30 @@ final class PEImportsTests: XCTestCase {
XCTAssertFalse(ProgramNeeds.direct3D12Only(program: dir.appending(path: "missing.exe")))
}
+ func testUnreal5LayoutCountsAsDirect3D12() throws {
+ let root = FileManager.default.temporaryDirectory.appending(path: "hb-ue5-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: root) }
+ let fm = FileManager.default
+ let exe = root.appending(path: "Voyage/Binaries/Win64/VoyageSteam-Win64-Shipping.exe")
+ try fm.createDirectory(at: exe.deletingLastPathComponent(), withIntermediateDirectories: true)
+ // Unreal's executable names dxgi and opengl32 only; d3d12.dll is loaded at run time.
+ try Self.makePE(imports: ["KERNEL32.dll", "dxgi.dll", "OPENGL32.dll"]).write(to: exe)
+ XCTAssertFalse(ProgramNeeds.direct3D12Only(program: exe), "imports alone say nothing")
+ XCTAssertFalse(ProgramNeeds.isUnreal5Build(program: exe), "no engine tree yet")
+ try fm.createDirectory(at: root.appending(path: "Engine/Binaries/Win64"), withIntermediateDirectories: true)
+ try fm.createDirectory(at: root.appending(path: "Voyage/Content/Paks"), withIntermediateDirectories: true)
+ try Data().write(to: root.appending(path: "Voyage/Content/Paks/pakchunk0-Windows.pak"))
+ XCTAssertFalse(ProgramNeeds.isUnreal5Build(program: exe), "a pak without IoStore is Unreal 4's layout, Direct3D 11 by default")
+ try Data().write(to: root.appending(path: "Voyage/Content/Paks/pakchunk0-Windows.utoc"))
+ XCTAssertTrue(ProgramNeeds.isUnreal5Build(program: exe))
+ XCTAssertTrue(ProgramNeeds.wantsDirect3D12(program: exe))
+ // A Unity build in a similar-looking folder is not Unreal.
+ let unity = root.appending(path: "Other/Binaries/Win64/Game.exe")
+ try fm.createDirectory(at: unity.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Self.makePE(imports: ["UnityPlayer.dll"]).write(to: unity)
+ XCTAssertFalse(ProgramNeeds.isUnreal5Build(program: unity), "no Paks with IoStore under it")
+ }
+
func testRealBinariesOnThisMac() throws {
// GameOverlayRenderer64.dll delay-loads KERNEL32; UnityPlayer.dll (PEAK) links Direct3D 11 and OpenGL.
let steam = URL(fileURLWithPath: NSHomeDirectory()).appending(path: "Library/Application Support/Highball/bottles/Gaming/drive_c/Program Files (x86)/Steam")
@@ -97,7 +121,15 @@ final class PEImportsTests: XCTestCase {
let peak = steam.appending(path: "steamapps/common/PEAK/PEAK.exe")
if FileManager.default.fileExists(atPath: peak.path) {
XCTAssertFalse(ProgramNeeds.direct3D12Only(program: peak))
+ XCTAssertFalse(ProgramNeeds.wantsDirect3D12(program: peak), "Unity with a Direct3D 11 player")
XCTAssertTrue(PEImports.dllNames(of: peak).contains("UnityPlayer.dll"))
}
+ // The Last Caretaker demo (Unreal 5, highball#138): imports say dxgi and opengl32 only, the layout says Unreal 5.
+ let caretaker = steam.appending(path: "steamapps/common/TheLastCaretakerDemo/Voyage/Binaries/Win64/VoyageSteam-Win64-Shipping.exe")
+ if FileManager.default.fileExists(atPath: caretaker.path) {
+ XCTAssertFalse(ProgramNeeds.direct3D12Only(program: caretaker))
+ XCTAssertTrue(ProgramNeeds.isUnreal5Build(program: caretaker))
+ XCTAssertTrue(ProgramNeeds.wantsDirect3D12(program: caretaker))
+ }
}
}