Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Add free WineHQ engine with DXMT as an alternative to CrossOver
Leon Seemannbd8737ddf96b
diff --git a/README.md b/README.mdindex 1d75f70..957f64e 100644--- a/README.md+++ b/README.md@@ -9,6 +9,31 @@ This tool is intended to be used with Steam Client 1788652215 or 1790121765 and20261006 or 2026082**. Both the FEX build and the Rosetta build are supported. The Rosetta build isthe recommended version, as the FEX one is in an early state.+## Free Wine engine (no CrossOver needed)++NotProton can also run entirely on free software. Under Compatibility Tool, **Download & Set Up**+fetches the WineHQ 11.15 macOS build from [Gcenx/macOS_Wine_builds](https://github.com/Gcenx/macOS_Wine_builds)+(hash pinned), unpacks it into `~/Library/Application Support/notproton/engines/` and sets the+compatibility tool up from it exactly like a CrossOver copy. No CrossOver license is involved; the+license check is skipped only for loaders whose hash pins the free build.++11.15 is chosen because it is the Wine the bridge components (`lsteamclient`, `steam.exe`) are built+against. Differences from CrossOver to be aware of:++- It is an x86_64 build and runs under Rosetta 2, like the Rosetta build of CrossOver.+- Direct3D 10/11 goes through [DXMT](https://github.com/3Shain/dxmt) (MIT), downloaded and pinned+ alongside Wine, which translates straight to Metal. Wine's own wined3d cannot reach feature level 11+ on macOS OpenGL. D3DMetal is Apple's and only works with CrossOver's Wine, so it is not used.+- DXMT needs macdrv functions upstream Wine hides; NotProton ships a rebuilt `winemac.so`+ that exports them (see `winemac-patch/`).+- D3D 12 has no fast path; vkd3d over the bundled MoltenVK is limited.+- WineHQ has no msync/esync, so CPU-heavy games can run slower than under CrossOver or Sikarugir.+- The graphics backend options in the Steam panel have no effect on this engine.++To support another WineHQ build, run `ntdll-patch/resolve.py` against its Wine tree, build the+payloads with `ntdll-patch/build.sh` / `build32.sh`, and add the hashes to `SupportedRunners`,+`NtdllPatcher.byBuild` and `FreeEngine`.+The macOS app itself is located in the ```app``` folder. The core logic is in ```dylib```.```lsteamclient``` is a macOS port of Valve's lsteamclient. ```steam-shim```is a port of Valve'ssteam-helper from Proton 9. ntdll-patch patches the copy of CrossOver that the appdiff --git a/app/Package.swift b/app/Package.swiftindex 1d35684..2b2e4b2 100644--- a/app/Package.swift+++ b/app/Package.swift@@ -34,6 +34,9 @@ let package = Package(.copy("Resources/detour32-41069.bin"),.copy("Resources/detour32-fex-41069.bin"),.copy("Resources/detour64-fex-41069.bin"),+ .copy("Resources/detour2-winehq-11.15.bin"),+ .copy("Resources/detour32-winehq-11.15.bin"),+ .copy("Resources/winemac-winehq-11.15.so"),],swiftSettings: [.swiftLanguageMode(.v6)]),diff --git a/app/Sources/NotProtonApp/Model/CrossOverLicense.swift b/app/Sources/NotProtonApp/Model/CrossOverLicense.swiftindex 07155f1..d50055a 100644--- a/app/Sources/NotProtonApp/Model/CrossOverLicense.swift+++ b/app/Sources/NotProtonApp/Model/CrossOverLicense.swift@@ -35,6 +35,15 @@ enum CrossOverLicense {searchDirs: [URL] = defaultSearchDirs,openssl: String = defaultOpenssl) -> Status {+ if let build = freeBuild(at: crossOverRoot) {+ let status = Status(+ licensed: true,+ detail: "\(build.releaseVersion) is free software and needs no license.",+ diagnostic: "free engine \(build.id), no license required"+ )+ AppLog.note("license: \(status.diagnostic)")+ return status+ }let status = evaluate(crossOverRoot: crossOverRoot, searchDirs: searchDirs, openssl: openssl)@@ -123,6 +132,16 @@ enum CrossOverLicense {)}+ // Only a loader whose hash pins a free build counts, so this never applies to+ // a CrossOver install, wherever it sits.+ static func freeBuild(at root: URL) -> RunnerBuild? {+ let loader = Clean.copy(of: CrossOverSource.unixLoader(inRoot: root))+ guard let hash = Digest.sha256IfPresent(loader),+ let build = SupportedRunners.build(loaderSHA256: hash), build.isFree+ else { return nil }+ return build+ }+static func requireValid(for install: CrossOverInstall) throws {let status = check(crossOverRoot: install.crossOverRoot)guard status.licensed else {diff --git a/app/Sources/NotProtonApp/Model/CrossOverSource.swift b/app/Sources/NotProtonApp/Model/CrossOverSource.swiftindex ade792d..8ee452a 100644--- a/app/Sources/NotProtonApp/Model/CrossOverSource.swift+++ b/app/Sources/NotProtonApp/Model/CrossOverSource.swift@@ -22,6 +22,11 @@ struct CrossOverInstall: Sendable, Identifiable {var isPreview: Bool { name.localizedCaseInsensitiveContains("Preview") }+ var isFree: Bool {+ if case .supported(let build) = support { return build.isFree }+ return false+ }+var isUsable: Bool {if case .supported = support { return true }return false@@ -35,6 +40,8 @@ enum CrossOverSource {SupportPaths.home.appending(path: "Applications", directoryHint: .isDirectory),]+ static var engineRoot: URL { SupportPaths.engines }+private static let manualKey = "manualCrossOverPath"static var manualBundle: URL? {@@ -75,12 +82,18 @@ enum CrossOverSource {}}+ let engines = (try? fm.contentsOfDirectory(at: engineRoot, includingPropertiesForKeys: nil)) ?? []+ for entry in engines where entry.pathExtension == "app" {+ consider(entry, isManual: false)+ }+return found.sorted(by: preferred)}static func preferred(_ a: CrossOverInstall, _ b: CrossOverInstall) -> Bool {if a.isManual != b.isManual { return a.isManual }if a.isUsable != b.isUsable { return a.isUsable }+ if a.isFree != b.isFree { return a.isFree }if a.isPreview != b.isPreview { return a.isPreview }if a.name != b.name { return a.name < b.name }return a.id < b.iddiff --git a/app/Sources/NotProtonApp/Model/FreeEngine.swift b/app/Sources/NotProtonApp/Model/FreeEngine.swiftnew file mode 100644index 0000000..9884fc0--- /dev/null+++ b/app/Sources/NotProtonApp/Model/FreeEngine.swift@@ -0,0 +1,217 @@+// Downloads a free WineHQ build and lays it out like a CrossOver bundle, so the+// rest of the runner setup treats it as just another source to clone from.++import Foundation++struct FreeEngineRelease: Sendable {+ let build: String+ let archive: String+ let sha256: String+ let bases: [URL]+ let bundleName: String+ // Path of the Wine tree inside the archive.+ let wineTree: String+ let renderer: RendererRelease+ // sha256 of the winemac.so NotProton ships for this build (winemac-patch/), which+ // exports the macdrv entry points DXMT needs to put Metal into a window.+ let macDriver: String+}++// DXMT replaces Wine's own D3D10/11 and DXGI. Wine's wined3d goes through macOS+// OpenGL 4.1, which tops out below feature level 11 and so fails any Unreal or+// Unity game that needs it, and DXVK pays for a second translation through+// MoltenVK. DXMT goes to Metal directly, the way D3DMetal does, and is MIT licensed.+struct RendererRelease: Sendable {+ let name: String+ let archive: String+ let sha256: String+ let bases: [URL]+ let tree: String+ // arch/file -> sha256 of the file the engine should end up carrying under lib/wine.+ let files: [String: String]+}++enum FreeEngine {++ static let step = "Download free Wine engine"++ // Gcenx's WineHQ packages. 11.15 is the Wine the bridge components are built+ // against (bridge/setup-wine-tree.sh), so the unix halves speak its protocol.+ static let current = FreeEngineRelease(+ build: "winehq-11.15",+ archive: "wine-devel-11.15-osx64.tar.xz",+ sha256: "3f8e89a4874953a69e7be3dcdcc262d0346e462a9374bd116770fffb9e2a99d2",+ bases: [URL(string: "https://github.com/Gcenx/macOS_Wine_builds/releases/download/11.15")!],+ bundleName: "WineHQ 11.15.app",+ wineTree: "Wine Devel.app/Contents/Resources/wine",+ renderer: RendererRelease(+ name: "DXMT 0.80",+ archive: "dxmt-v0.80-builtin.tar.gz",+ sha256: "8f260e36b5739e68f3bad613381441385c4dc7b85b78ba8de653d5a6a264529d",+ bases: [URL(string: "https://github.com/3Shain/dxmt/releases/download/v0.80")!],+ tree: "v0.80",+ // nvapi64 and nvngx are left out: they only serve DLSS to MetalFX, and an+ // nvapi that answers makes some games take NVIDIA-only paths.+ files: [+ "x86_64-unix/winemetal.so": "3d50d7f39c64778c71d0af2fce1cde818d09ffbce7c4f7b8ae24ae1df567c0ca",+ "x86_64-windows/d3d10core.dll": "833d26971abc8661efc8b5cc18548c70ce8e482e4ea4b1d3f69a367612264d26",+ "x86_64-windows/d3d11.dll": "7ca382af0eb32d8a432f6efb14d594fefb45673663be1f7e6682254bff885c47",+ "x86_64-windows/dxgi.dll": "fc58aae0aba511a1ec4d2417e5bba6adb888bb14315d0f59cccdfd27f670d544",+ "x86_64-windows/winemetal.dll": "514245d533c750599614311a792c45ed600aef52948571d98c0fc70fd3df16e0",+ "i386-windows/d3d10core.dll": "c5a26310d14a30c3e1700a4d0c9865be28a11351a5c4dc5b83ab1bd8fcf7662f",+ "i386-windows/d3d11.dll": "9afc2b3419818618c4c87274435a28935b0df002caa4b9a8d3a88d3dc846b17d",+ "i386-windows/dxgi.dll": "7df8cdf66e12a108410002abc77b01f70aa59b8a36a70fa0bc6ae3b056841319",+ "i386-windows/winemetal.dll": "20a6865facebdaac92b6c06fadf37d2efb5a242b22ca1c349bb57d7ad43df8e3",+ ]+ ),+ macDriver: "68d1c10cb4ec80beb2e97dcb8df5f81768f4f6e62848932d6bee5270dcf54982"+ )++ static let macDriverPath = "lib/wine/x86_64-unix/winemac.so"++ static var downloads: URL {+ SupportPaths.home.appending(path: "Library/Caches/\(SupportPaths.supportDirName)/engines")+ }++ static func bundle(for release: FreeEngineRelease = current, engines: URL = SupportPaths.engines) -> URL {+ engines.appending(path: release.bundleName, directoryHint: .isDirectory)+ }++ static func isInstalled(_ release: FreeEngineRelease = current, engines: URL = SupportPaths.engines) -> Bool {+ let install = CrossOverSource.inspect(bundle: bundle(for: release, engines: engines))+ guard case .supported(let build) = install.support, build.id == release.build else { return false }+ return hasRenderer(root: install.crossOverRoot, release: release)+ }++ // An engine unpacked before this renderer was part of it still runs, but D3D11+ // games either fail on it or run slowly.+ static func hasRenderer(root: URL, release: FreeEngineRelease = current) -> Bool {+ release.renderer.files.allSatisfy { path, hash in+ Digest.sha256IfPresent(root.appending(path: "lib/wine/\(path)")) == hash+ } && Digest.sha256IfPresent(root.appending(path: macDriverPath)) == release.macDriver+ }++ // Upstream Wine hides the macdrv functions DXMT looks up, so without this DXMT can+ // create a device but no swapchain, and games abort on their first window.+ static func installMacDriver(root: URL, release: FreeEngineRelease) throws {+ guard let source = Bundle.module.url(forResource: "winemac-\(release.build)", withExtension: "so"),+ Digest.sha256IfPresent(source) == release.macDriver+ else {+ throw StepFailure(step: step, detail: "NotProton is missing its winemac.so for \(release.build).")+ }+ let destination = root.appending(path: macDriverPath)+ try? FileManager.default.removeItem(at: destination)+ try FileManager.default.copyItem(at: source, to: destination)+ }++ enum Phase: Sendable {+ case downloading(PinnedDownload.Progress)+ case unpacking++ var label: String {+ switch self {+ case .downloading(let progress): progress.label+ case .unpacking: "Unpacking Wine"+ }+ }+ }++ static func install(+ _ release: FreeEngineRelease = current,+ engines: URL = SupportPaths.engines,+ report: @escaping @Sendable (Phase) -> Void = { _ in }+ ) async throws -> CrossOverInstall {+ let archive = try await PinnedDownload.obtain(+ file: release.archive, sha256: release.sha256, bases: release.bases,+ into: downloads, step: step, source: "GitHub",+ report: { report(.downloading($0)) }+ )+ let renderer = try await PinnedDownload.obtain(+ file: release.renderer.archive, sha256: release.renderer.sha256, bases: release.renderer.bases,+ into: downloads, step: step, source: "GitHub",+ report: { report(.downloading($0)) }+ )+ report(.unpacking)+ return try unpack(archive, renderer: renderer, release: release, engines: engines)+ }++ static func unpack(+ _ archive: URL, renderer: URL?, release: FreeEngineRelease, engines: URL+ ) throws -> CrossOverInstall {+ let fm = FileManager.default+ let target = bundle(for: release, engines: engines)+ let staging = engines.appending(path: ".\(release.bundleName).new", directoryHint: .isDirectory)+ try? fm.removeItem(at: staging)+ try fm.createDirectory(at: staging, withIntermediateDirectories: true)+ defer { try? fm.removeItem(at: staging) }++ let extracted = staging.appending(path: "extract", directoryHint: .isDirectory)+ try fm.createDirectory(at: extracted, withIntermediateDirectories: true)+ try untar(archive, into: extracted)++ let wine = extracted.appending(path: release.wineTree, directoryHint: .isDirectory)+ guard fm.fileExists(atPath: wine.appending(path: "lib/wine").path(percentEncoded: false)) else {+ throw StepFailure(step: step, detail: "\(release.archive) has no Wine tree at \(release.wineTree).")+ }++ let shaped = staging.appending(path: release.bundleName, directoryHint: .isDirectory)+ let root = SupportPaths.crossOverRoot(inBundle: shaped)+ try fm.createDirectory(at: root.deletingLastPathComponent(), withIntermediateDirectories: true)+ try fm.moveItem(at: wine, to: root)++ if let renderer {+ try untar(renderer, into: extracted)+ let tree = extracted.appending(path: release.renderer.tree, directoryHint: .isDirectory)+ for (path, hash) in release.renderer.files.sorted(by: { $0.key < $1.key }) {+ let source = tree.appending(path: path)+ guard Digest.sha256IfPresent(source) == hash else {+ throw StepFailure(step: step, detail: "\(release.renderer.archive) has no pinned \(path).")+ }+ let destination = root.appending(path: "lib/wine/\(path)")+ try? fm.removeItem(at: destination)+ try fm.copyItem(at: source, to: destination)+ }+ try installMacDriver(root: root, release: release)+ }++ // WineHQ already keeps its unix loader beside the unix libraries, where+ // CrossOver keeps its own, so the Wine tree needs no reshaping inside.+ let info: [String: Any] = [+ "CFBundleIdentifier": "org.winehq.wine.notproton",+ "CFBundleName": release.bundleName.replacingOccurrences(of: ".app", with: ""),+ "CFBundleShortVersionString": release.build.replacingOccurrences(of: "winehq-", with: ""),+ "CFBundleVersion": release.build,+ ]+ let plist = try PropertyListSerialization.data(fromPropertyList: info, format: .xml, options: 0)+ try plist.write(to: shaped.appending(path: "Contents/Info.plist"))+ RunnerInstaller.scrubDownloadMarkers(at: shaped)++ let install = CrossOverSource.inspect(bundle: shaped)+ guard case .supported(let build) = install.support, build.id == release.build else {+ throw StepFailure(+ step: step,+ detail: "The unpacked Wine loader is not the \(release.build) build NotProton was made for."+ )+ }++ try fm.createDirectory(at: engines, withIntermediateDirectories: true)+ if fm.fileExists(atPath: target.path(percentEncoded: false)) {+ try fm.removeItem(at: target)+ }+ try fm.moveItem(at: shaped, to: target)+ return CrossOverSource.inspect(bundle: target)+ }++ private static func untar(_ archive: URL, into directory: URL) throws {+ let result = try Shell.run("/usr/bin/tar", [+ "-xf", archive.path(percentEncoded: false), "-C", directory.path(percentEncoded: false),+ ])+ guard result.status == 0 else {+ throw StepFailure(+ step: step,+ detail: "Unpacking \(archive.lastPathComponent) failed. "+ + result.stderr.trimmingCharacters(in: .whitespacesAndNewlines)+ )+ }+ }+}diff --git a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift b/app/Sources/NotProtonApp/Model/NtdllPatcher.swiftindex f92a824..dab11b1 100644--- a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift+++ b/app/Sources/NotProtonApp/Model/NtdllPatcher.swift@@ -185,6 +185,39 @@ enum NtdllPatcher {imageBase: 0x1_8000_0000),],+ "winehq-11.15": [+ NtdllPatch(+ arch: .x86_64Windows,+ payloadResource: "detour2-winehq-11.15",+ payloadSHA256: "d394a6b7f4c55e2bb8b99aeb51cd4555527f8e10fa49339e95a8156486c5e2e5",+ caveRVA: 0xb3000,+ payloadRVA: 0xb3000,+ hooks: [+ NtdllHook(rva: 0x3512c, stolen: [0x48, 0x8b, 0x85, 0x90, 0x00, 0x00, 0x00]),+ ],+ caveSize: 0x1000,+ cavePad: 0x00,+ machine: 0x8664,+ magic: 0x20b,+ imageBase: 0x1_7000_0000,+ placement: .section+ ),+ NtdllPatch(+ arch: .i386Windows,+ payloadResource: "detour32-winehq-11.15",+ payloadSHA256: "527431a3a74e9dff7bc3582277ddfa7b44bcac6fba285c028fd2c94fd9202418",+ caveRVA: 0x6a075,+ payloadRVA: 0x6a080,+ hooks: [+ NtdllHook(rva: 0x2edcd, stolen: [0x8b, 0x45, 0x14, 0xa8, 0x02]),+ ],+ caveSize: 3979,+ cavePad: 0xcc,+ machine: 0x14c,+ magic: 0x10b,+ imageBase: 0x7bc0_0000+ ),+ ],]static func patches(for build: RunnerBuild) -> [NtdllPatch] {diff --git a/app/Sources/NotProtonApp/Model/RunnerPatcher.swift b/app/Sources/NotProtonApp/Model/RunnerPatcher.swiftindex 988c526..834fc2b 100644--- a/app/Sources/NotProtonApp/Model/RunnerPatcher.swift+++ b/app/Sources/NotProtonApp/Model/RunnerPatcher.swift@@ -72,7 +72,7 @@ enum RunnerPatcher {}}- for loader in unixLoaders(in: root) {+ for loader in unixLoaders(in: root) where isHardened(loader) {let granted = entitlements(of: loader)if granted?.contains(restrictedEntitlement) == true {if !signatureIsValid(signingTarget(for: loader)) {@@ -139,7 +139,7 @@ enum RunnerPatcher {private static func grantLoaderEntitlement(root: URL) throws -> [String] {var signed: [String] = []- for loader in unixLoaders(in: root) {+ for loader in unixLoaders(in: root) where isHardened(loader) {let existing = entitlements(of: loader)if existing?.contains(restrictedEntitlement) == true { continue }if existing?.contains(dyldEntitlement) == true,@@ -237,6 +237,19 @@ enum RunnerPatcher {return nil}+ // WineHQ's loader is ad hoc signed without the hardened runtime, so dyld already+ // honours the DYLD_* variables and there is nothing to grant. Re-signing it+ // with the runtime on would take away the JIT and library freedoms Wine needs.+ static func isHardened(_ loader: URL) -> Bool {+ guard let result = try? Shell.run(+ "/usr/bin/codesign", ["-dv", signingTarget(for: loader).path(percentEncoded: false)]+ ), result.status == 0 else { return true }+ let described = result.stderr + result.stdout+ return described.split(separator: "\n").contains {+ $0.hasPrefix("CodeDirectory") && $0.contains("runtime")+ }+ }+static let restrictedEntitlement = "com.apple.developer.cross-architecture-support"private static func signatureIsValid(_ target: URL) -> Bool {diff --git a/app/Sources/NotProtonApp/Model/RunnerSetup.swift b/app/Sources/NotProtonApp/Model/RunnerSetup.swiftindex fd182f4..fb1ce21 100644--- a/app/Sources/NotProtonApp/Model/RunnerSetup.swift+++ b/app/Sources/NotProtonApp/Model/RunnerSetup.swift@@ -12,7 +12,7 @@ enum RunnerSetup {var label: String {switch self {- case .cloning: "Copying CrossOver"+ case .cloning: "Copying Wine"case .staging: "Patching"case .patching: "Installing compatibility tool"case .finished: "Done"diff --git a/app/Sources/NotProtonApp/Model/SupportedRunner.swift b/app/Sources/NotProtonApp/Model/SupportedRunner.swiftindex af7e201..60f6e94 100644--- a/app/Sources/NotProtonApp/Model/SupportedRunner.swift+++ b/app/Sources/NotProtonApp/Model/SupportedRunner.swift@@ -28,6 +28,10 @@ struct RunnerBuild: Sendable, Equatable, Identifiable {let cleanNtdll: [WineArch: String]let patchedNtdll: [WineArch: String]+ // A free WineHQ engine NotProton downloads itself rather than a CrossOver+ // install. It has no license to check.+ var isFree = false+var id: String { flavor.map { "\(bundleVersion)-\($0)" } ?? bundleVersion }var flavorName: String { flavor?.uppercased() ?? "Rosetta" }@@ -94,6 +98,21 @@ enum SupportedRunners {.aarch64Windows: "89e4c9e7f0a0a60462c0231ec393168f8bdb04bc8ea1dc22211f25bf3ff2c6b3",]),+ RunnerBuild(+ bundleVersion: "winehq-11.15",+ releaseVersion: "WineHQ 11.15",+ flavor: nil,+ loaderSHA256: "8aa25e55f28a0634a7df04c02dd719d4bc20de645cf42b9ba7d0e3b7d8f66a80",+ cleanNtdll: [+ .x86_64Windows: "682181234a55f5b7eed5b2ffa691fbdef1b488734337ef67ea7b5ce17adf43a2",+ .i386Windows: "49396e7ad804a5345b1b968d02fdb6697ddbb7428e61e20e62806c50c37589d1",+ ],+ patchedNtdll: [+ .x86_64Windows: "08a825e8236e79c909fae3934ca5e8a195a344d06f8affb6e13cdf1bd9ffa783",+ .i386Windows: "88f9a1d16dd7127100eab902156390ec2a5ec67770cfddd3fd3f1237c9965309",+ ],+ isFree: true+ ),]static func build(loaderSHA256 hash: String) -> RunnerBuild? {diff --git a/app/Sources/NotProtonApp/Resources/detour2-winehq-11.15.bin b/app/Sources/NotProtonApp/Resources/detour2-winehq-11.15.binnew file mode 100755index 0000000..739b7f6Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/detour2-winehq-11.15.bin differdiff --git a/app/Sources/NotProtonApp/Resources/detour32-winehq-11.15.bin b/app/Sources/NotProtonApp/Resources/detour32-winehq-11.15.binnew file mode 100755index 0000000..a11b6b1Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/detour32-winehq-11.15.bin differdiff --git a/app/Sources/NotProtonApp/Resources/winemac-winehq-11.15.so b/app/Sources/NotProtonApp/Resources/winemac-winehq-11.15.sonew file mode 100755index 0000000..3b4db17Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/winemac-winehq-11.15.so differdiff --git a/app/Sources/NotProtonApp/Support/PinnedDownload.swift b/app/Sources/NotProtonApp/Support/PinnedDownload.swiftindex 02bb019..0147ee7 100644--- a/app/Sources/NotProtonApp/Support/PinnedDownload.swift+++ b/app/Sources/NotProtonApp/Support/PinnedDownload.swift@@ -22,6 +22,7 @@ enum PinnedDownload {bases: [URL],into downloads: URL,step: String,+ source: String = "Valve",report: @Sendable (Progress) -> Void = { _ in }) async throws -> URL {let archive = downloads.appending(path: file)@@ -65,7 +66,7 @@ enum PinnedDownload {}AppLog.note("\(file) refused by all \(bases.count) hosts: \(refusals.joined(separator: ". "))")- throw StepFailure(step: step, detail: reason(kinds))+ throw StepFailure(step: step, detail: reason(kinds, source: source))}private enum Refusal {@@ -74,14 +75,14 @@ enum PinnedDownload {case answered}- private static func reason(_ kinds: Set<Refusal>) -> String {+ private static func reason(_ kinds: Set<Refusal>, source: String) -> String {if kinds == [.mismatch] {return "Something is wrong with the downloaded files. Please check for a NotProton update."}if kinds == [.unreachable] {- return "NotProton could not reach Valve's servers. Please check your internet "+ return "NotProton could not reach \(source)'s servers. Please check your internet "+ "connection and try again."}- return "NotProton could not download the files it needs from Valve. Please try again later."+ return "NotProton could not download the files it needs from \(source). Please try again later."}}diff --git a/app/Sources/NotProtonApp/Support/SupportPaths.swift b/app/Sources/NotProtonApp/Support/SupportPaths.swiftindex d6adbc4..fdb9cff 100644--- a/app/Sources/NotProtonApp/Support/SupportPaths.swift+++ b/app/Sources/NotProtonApp/Support/SupportPaths.swift@@ -24,6 +24,8 @@ enum SupportPaths {static var runners: URL { support.appending(path: "runners") }static var backups: URL { support.appending(path: "backups") }static var launchers: URL { support.appending(path: "launchers") }+ // Free WineHQ engines NotProton downloaded, laid out like a CrossOver bundle.+ static var engines: URL { support.appending(path: "engines") }static var signatures: URL {support.appending(path: "signatures/macos.arm64")diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swiftindex 19cf1e5..433297b 100644--- a/app/Sources/NotProtonApp/SystemStatus.swift+++ b/app/Sources/NotProtonApp/SystemStatus.swift@@ -336,7 +336,7 @@ final class SystemStatus {private func setUpRunner(from install: CrossOverInstall?, replacingExisting: Bool = false) async {guard let install else {- setFailure("No supported copy of CrossOver found.")+ setFailure("No supported Wine engine found. Download the free WineHQ engine first.")AppLog.note("run refused: no supported CrossOver")outcome = nilreturn@@ -353,6 +353,23 @@ final class SystemStatus {}}+ var freeEngineInstalled: Bool {+ snapshot?.crossOver.contains { $0.isFree && FreeEngine.hasRenderer(root: $0.crossOverRoot) } ?? false+ }++ // Downloads the free WineHQ engine and sets the compatibility tool up from it,+ // so no CrossOver install or license is needed.+ func installFreeEngine() async {+ guard isIdle else { return }+ await perform(from: FreeEngine.step) { progress in+ let install = try await FreeEngine.install { progress($0.label) }+ let result = try await Task.detached(priority: .userInitiated) {+ try RunnerSetup.run(from: install, replacingExisting: true) { progress($0.label) }+ }.value+ return runnerOutcome(result)+ }+ }+func fetchValveBinaries() async {await perform(from: ValveFetcher.Phase.verifying.label) { progress inlet result = try await ValveFetcher.run { progress($0.label) }diff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swiftindex e752e22..50937c0 100644--- a/app/Sources/NotProtonApp/Views/StatusView.swift+++ b/app/Sources/NotProtonApp/Views/StatusView.swift@@ -442,25 +442,43 @@ struct StatusView: View {}} else {StatusRow(- title: "CrossOver",- value: "Not found. Supported: \(SupportedRunners.versionList).",+ title: "Wine Engine",+ value: "None found. Download the free WineHQ engine, or use CrossOver "+ + "(\(SupportedRunners.versionList)).",tone: .bad,action: crossOverAction())}+ if !status.freeEngineInstalled {+ let outdated = installs.contains(where: \.isFree)+ StatusRow(+ title: "Free Wine Engine",+ value: outdated+ ? "Needs \(FreeEngine.current.renderer.name) for fast Direct3D 11."+ : "\(FreeEngine.current.bundleName.replacingOccurrences(of: ".app", with: "")) with \(FreeEngine.current.renderer.name), "+ + "no CrossOver license needed.",+ tone: outdated ? .warning : .neutral,+ action: StatusAction(+ label: outdated ? "Update & Set Up" : "Download & Set Up",+ isProminent: installs.isEmpty,+ help: "Download WineHQ and set the compatibility tool up from it.",+ isEnabled: status.isIdle+ ) { Task { await status.installFreeEngine() } }+ )+ }}private func crossOverAction(chooseLabel: String = "Choose\u{2026}") -> StatusAction {if status.chosenCrossOver != nil {return StatusAction(label: "Use Search",- help: "Use the default CrossOver.",+ help: "Use the default Wine engine search.",isEnabled: status.isIdle) { Task { await status.clearCrossOverChoice() } }}return StatusAction(label: chooseLabel,- help: "Pick a CrossOver install.",+ help: "Pick a CrossOver install or Wine engine.",isEnabled: status.isIdle) { Task { await status.chooseCrossOver() } }}@@ -540,7 +558,7 @@ struct StatusView: View {StatusAction(label: "Copy",isProminent: true,- help: "Copy this CrossOver build and use it.",+ help: "Copy this Wine build and use it.",isEnabled: status.isIdle) {Task { await status.requestCompatibilityTool(from: available.install) }@@ -550,7 +568,7 @@ struct StatusView: View {private func useAction(_ build: RunnerBuild) -> StatusAction {StatusAction(label: "Use",- help: "Launch games with this CrossOver build.",+ help: "Launch games with this Wine build.",isEnabled: status.isIdle) {Task { await status.switchRunner(to: build) }@@ -574,7 +592,7 @@ struct StatusView: View {StatusAction(label: label,isProminent: true,- help: "Set up the compatibility tool from CrossOver.",+ help: "Set up the compatibility tool from the selected Wine engine.",isEnabled: status.isIdle && status.setupSource != nil) {Task { await status.requestCompatibilityTool(replacingExisting: replacingExisting) }diff --git a/app/Tests/NotProtonAppTests/FreeEngineTests.swift b/app/Tests/NotProtonAppTests/FreeEngineTests.swiftnew file mode 100644index 0000000..56b3c1d--- /dev/null+++ b/app/Tests/NotProtonAppTests/FreeEngineTests.swift@@ -0,0 +1,74 @@+import Foundation+import Testing++@testable import NotProtonApp++@Suite("Free WineHQ engine")+struct FreeEngineTests {++ private func makeEngines() throws -> URL {+ let engines = FileManager.default.temporaryDirectory+ .appending(path: "np-engines-\(UUID().uuidString)")+ try FileManager.default.createDirectory(at: engines, withIntermediateDirectories: true)+ return engines+ }++ @Test("The pinned release names a free build NotProton knows how to patch")+ func releaseIsSupported() throws {+ let build = try #require(SupportedRunners.build(id: FreeEngine.current.build))+ #expect(build.isFree)+ #expect(!NtdllPatcher.patches(for: build).isEmpty)+ #expect(SupportedRunners.all.filter(\.isFree).map(\.id) == [FreeEngine.current.build])+ }++ @Test("A CrossOver-shaped tree whose loader is not a free build still needs a license")+ func crossOverKeepsItsLicenseCheck() throws {+ let engines = try makeEngines()+ defer { try? FileManager.default.removeItem(at: engines) }++ let root = engines.appending(path: "Fake.app/Contents/SharedSupport/CrossOver")+ let loader = CrossOverSource.unixLoader(inRoot: root)+ try FileManager.default.createDirectory(+ at: loader.deletingLastPathComponent(), withIntermediateDirectories: true+ )+ try Data("not wine".utf8).write(to: loader)++ #expect(CrossOverLicense.freeBuild(at: root) == nil)+ #expect(!CrossOverLicense.check(crossOverRoot: root, searchDirs: []).licensed)+ }++ // Runs against the real archive once it has been downloaded, by NotProton or by hand+ // into the cache NotProton uses.+ @Test("Unpacking the real archive yields a supported, license-free, patchable engine")+ func unpacksRealArchive() throws {+ let archive = FreeEngine.downloads.appending(path: FreeEngine.current.archive)+ guard Digest.sha256IfPresent(archive) == FreeEngine.current.sha256 else { return }++ let engines = try makeEngines()+ defer { try? FileManager.default.removeItem(at: engines) }++ let renderer = FreeEngine.downloads.appending(path: FreeEngine.current.renderer.archive)+ let haveRenderer = Digest.sha256IfPresent(renderer) == FreeEngine.current.renderer.sha256+ let install = try FreeEngine.unpack(+ archive, renderer: haveRenderer ? renderer : nil, release: FreeEngine.current, engines: engines+ )+ guard case .supported(let build) = install.support else {+ Issue.record("unpacked engine is \(install.support)")+ return+ }+ #expect(build.id == FreeEngine.current.build)+ #expect(install.isFree)+ #expect(FreeEngine.isInstalled(engines: engines) == haveRenderer)+ #expect(FreeEngine.hasRenderer(root: install.crossOverRoot) == haveRenderer)+ #expect(CrossOverLicense.check(crossOverRoot: install.crossOverRoot).licensed)+ try RunnerInstaller.verifyClone(build: build, root: install.crossOverRoot)++ for patch in NtdllPatcher.patches(for: build) {+ let source = NtdllPatcher.cleanSource(inRoot: install.crossOverRoot, arch: patch.arch)+ let patched = try NtdllPatcher.apply(+ patch, to: try Data(contentsOf: source), payload: try NtdllPatcher.payload(for: patch)+ )+ #expect(Digest.sha256(of: patched) == build.patchedNtdll[patch.arch])+ }+ }+}diff --git a/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift b/app/Tests/NotProtonAppTests/NtdllPatcherTests.swiftindex 58d0c80..69da35e 100644--- a/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift+++ b/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift@@ -324,9 +324,13 @@ struct NtdllPatcherTests {// The point of the port: the same input has to come out as the bytes apply.py and// apply32.py produced, which SupportedRunners records. Needs an unpatched CrossOver.- @Test("Patching the unpatched ntdll reproduces the recorded hashes")- func realNtdllReproducesRecordedHashes() throws {- let root = URL(filePath: "/Applications/CrossOver Preview.app/Contents/SharedSupport/CrossOver")+ @Test("Patching the unpatched ntdll reproduces the recorded hashes", arguments: [+ URL(filePath: "/Applications/CrossOver Preview.app/Contents/SharedSupport/CrossOver"),+ // The free engine, once NotProton or NOTPROTON_WINEHQ_ROOT has provided one.+ ProcessInfo.processInfo.environment["NOTPROTON_WINEHQ_ROOT"].map { URL(filePath: $0) }+ ?? SupportPaths.crossOverRoot(inBundle: FreeEngine.bundle()),+ ])+ func realNtdllReproducesRecordedHashes(root: URL) throws {guard FileManager.default.fileExists(atPath: root.path(percentEncoded: false)),let installed = Digest.sha256IfPresent(CrossOverSource.unixLoader(inRoot: root)),let build = SupportedRunners.build(loaderSHA256: installed)diff --git a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift b/app/Tests/NotProtonAppTests/PrefixToolsTests.swiftindex 9f522b3..2d75c35 100644--- a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift+++ b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift@@ -227,7 +227,7 @@ struct PrefixToolsTests {func dialogNamesBothBuilds() throws {let source = try Self.compatSource()- // Written in compat_run.sh as: aa64) printf 'the FEX build of CrossOver' ;;+ // Written in compat_run.sh as: aa64) printf 'an arm64 (FEX) Wine engine' ;;func name(of word: String) throws -> String {let match = try #require(source.firstMatch(of: try Regex("\(word)\\) printf '([^']+)'")),diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 4274884..53dfee1 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -107,8 +107,8 @@ prefix_machine() {tool_name() {case "$1" in- aa64) printf 'the FEX build of CrossOver' ;;- 8664) printf 'the Rosetta build of CrossOver' ;;+ aa64) printf 'an arm64 (FEX) Wine engine' ;;+ 8664) printf 'a Rosetta (x86_64) Wine engine' ;;*) printf 'an older 32-bit setup' ;;esac}@@ -348,6 +348,27 @@ install_lsteamclient_trigger() {fi}+# A builtin Wine only finds through a placeholder in the prefix, and prefixes made+# before the runner carried it have none. DXMT's dxgi imports winemetal, so without+# it every D3D11 game fails to start in such a prefix.+install_runner_builtins() {+ for pair in x86_64-windows:system32 i386-windows:syswow64; do+ arch=${pair%%:*}+ dir="$WINEPREFIX/drive_c/windows/${pair##*:}"+ [ -d "$dir" ] || continue+ for name in winemetal.dll; do+ src="$CX_ROOT/lib/wine/$arch/$name"+ [ -f "$src" ] || continue+ cmp -s "$src" "$dir/$name" && continue+ if cp -f "$src" "$dir/$name"; then+ echo "=== installed $arch/$name into the prefix ===" >> "$log" 2>&1 || true+ else+ echo "=== could not install $arch/$name into the prefix ===" >> "$log" 2>&1 || true+ fi+ done+ done+}+# A fix to match Protoninstall_legacy_steam_dll() {src="$bridge_src/legacycompat/Steam.dll"@@ -405,6 +426,7 @@ if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; thenverify_runnerinstall_lsteamclient_triggerinstall_legacy_steam_dll+ install_runner_builtinsexport WINEDLLPATH="$prefix_steam:$WINEDLLPATH"export WINEDLLOVERRIDES="steamclient=n;steamclient64=n;lsteamclient=b"native_client="$STEAM_COMPAT_CLIENT_INSTALL_PATH"diff --git a/ntdll-patch/build.sh b/ntdll-patch/build.shindex cfef057..29f4057 100755--- a/ntdll-patch/build.sh+++ b/ntdll-patch/build.sh@@ -9,7 +9,7 @@ ntdll="${1:?usage: build.sh <target ntdll.dll> [variant]}"variant="${2:-rosetta}"[ "$variant" = rosetta ] && out=detour2.bin || out="detour2-$variant.bin"-eval "$(python3 resolve.py --sh "$ntdll")"+eval "$(${PYTHON:-python3} resolve.py --sh "$ntdll")"[ "$NP_MACHINE" = 0x8664 ] || { echo "$ntdll is machine $NP_MACHINE, not x86_64" >&2; exit 1; }CC=x86_64-w64-mingw32-gccdiff --git a/ntdll-patch/build32.sh b/ntdll-patch/build32.shindex dde8717..152ec1e 100755--- a/ntdll-patch/build32.sh+++ b/ntdll-patch/build32.sh@@ -9,7 +9,7 @@ ntdll="${1:?usage: build32.sh <target ntdll.dll> [variant]}"variant="${2:-rosetta}"[ "$variant" = rosetta ] && out=detour32.bin || out="detour32-$variant.bin"-eval "$(python3 resolve.py --sh "$ntdll")"+eval "$(${PYTHON:-python3} resolve.py --sh "$ntdll")"[ "$NP_MACHINE" = 0x14c ] || { echo "$ntdll is machine $NP_MACHINE, not i386" >&2; exit 1; }CC=i686-w64-mingw32-gccdiff --git a/ntdll-patch/build64.sh b/ntdll-patch/build64.shindex e9b1dfa..68b9e3b 100755--- a/ntdll-patch/build64.sh+++ b/ntdll-patch/build64.sh@@ -9,7 +9,7 @@ ntdll="${1:?usage: build64.sh <target ntdll.dll> [variant]}"variant="${2:-fex}"out="detour64-$variant.bin"-eval "$(python3 resolve.py --sh "$ntdll")"+eval "$(${PYTHON:-python3} resolve.py --sh "$ntdll")"[ "$NP_MACHINE" = 0xaa64 ] || { echo "$ntdll is machine $NP_MACHINE, not aarch64" >&2; exit 1; }[ "${NP_SITES:-0}" = 2 ] || { echo "$ntdll has ${NP_SITES:-0} hooks, shim64.S serves two" >&2; exit 1; }diff --git a/ntdll-patch/resolve.py b/ntdll-patch/resolve.pyindex 26b7abf..083227f 100755--- a/ntdll-patch/resolve.py+++ b/ntdll-patch/resolve.py@@ -275,10 +275,16 @@ def amd64_load_path(pe, body, hook):# Neither build keeps the argument in rcx. One spills it to the stack right away,# the other stashes it in a callee-saved register and reuses that a few instructions# later.- src, slot, stored_at = 'rcx', None, None+ # WineHQ builds spill it rbp-relative instead, with rbp pinned to rsp+N by the+ # prologue, so the slot is translated back to rsp.+ src, slot, stored_at, rbp_off = 'rcx', None, None, Nonefor i in body:if i.address >= hook:break+ m = re.fullmatch(r'rbp, \[rsp \+ (0x[0-9a-f]+)\]', i.op_str)+ if i.mnemonic == 'lea' and m:+ rbp_off = int(m.group(1), 16)+ continueif i.mnemonic != 'mov' or ',' not in i.op_str:continuedst, rhs = (x.strip() for x in i.op_str.split(',', 1))@@ -288,6 +294,12 @@ def amd64_load_path(pe, body, hook):slot = 0 if '+' not in dst else int(dst.split('+')[1].strip().rstrip(']'), 16)stored_at = i.addressbreak+ m = re.fullmatch(r'qword ptr \[rbp(?: ([+-]) (0x[0-9a-f]+))?\]', dst)+ if m and rbp_off is not None:+ disp = int(m.group(2), 16) * (-1 if m.group(1) == '-' else 1) if m.group(2) else 0+ slot = rbp_off + disp+ stored_at = i.address+ breakif re.fullmatch(r'r[a-z0-9]+', dst):src = dstif slot is None:@@ -300,7 +312,11 @@ def amd64_load_path(pe, body, hook):continueif i.mnemonic in ('push', 'pop') or (i.mnemonic in ('sub', 'add') and i.op_str.startswith('rsp,')):raise SystemExit(f"{pe.path}: rsp moves at {i.address:#x}, load_path slot not rsp-stable")- if i.mnemonic == 'mov' and i.op_str.startswith(f'qword ptr [rsp + {slot:#x}],'):+ aliases = [f'qword ptr [rsp + {slot:#x}],']+ if rbp_off is not None:+ d = slot - rbp_off+ aliases.append(f'qword ptr [rbp {"-" if d < 0 else "+"} {abs(d):#x}],' if d else 'qword ptr [rbp],')+ if i.mnemonic == 'mov' and any(i.op_str.startswith(a) for a in aliases):raise SystemExit(f"{pe.path}: load_path slot rewritten at {i.address:#x}")return slotdiff --git a/winemac-patch/README.md b/winemac-patch/README.mdnew file mode 100644index 0000000..8ba4ace--- /dev/null+++ b/winemac-patch/README.md@@ -0,0 +1,19 @@+# winemac-patch++Upstream Wine builds hide the macdrv functions DXMT's `winemetal.so` looks up with+`dlsym`, so DXMT can create a D3D11 device but no swapchain. `dxmt_export.c` exports+them as the `macdrv_functions` table DXMT checks first, translating `struct macdrv_win_data`+to the older layout DXMT expects and creating the window's client view on demand.++To rebuild `app/Sources/NotProtonApp/Resources/winemac-winehq-11.15.so`:++ tar xf wine-11.15.tar.xz && cd wine-11.15+ cp ../winemac-patch/dxmt_export.c dlls/winemac.drv/+ # add "dxmt_export.c \" to SOURCES in dlls/winemac.drv/Makefile.in+ PATH="$(brew --prefix bison)/bin:$PATH" arch -x86_64 ./configure --enable-win64 \+ --enable-archs=x86_64 --without-x --without-freetype CC="clang -arch x86_64" \+ OBJC="clang -arch x86_64"+ arch -x86_64 make dlls/winemac.drv/winemac.so+ codesign -fs - dlls/winemac.drv/winemac.so++Then update `macDriver` in `FreeEngine.swift` with its sha256.diff --git a/winemac-patch/dxmt_export.c b/winemac-patch/dxmt_export.cnew file mode 100644index 0000000..0030c52--- /dev/null+++ b/winemac-patch/dxmt_export.c@@ -0,0 +1,88 @@+/*+ * Exports the macdrv entry points DXMT's winemetal.so looks up with dlsym. Upstream Wine+ * hides them, and DXMT's view of struct macdrv_win_data predates the client_view rename,+ * so get_win_data hands out a copy in the layout DXMT expects.+ */++#if 0+#pragma makedep unix+#endif++#include "config.h"++#include <stdlib.h>++#include "macdrv.h"++struct dxmt_win_data+{+ HWND hwnd;+ macdrv_window cocoa_window;+ macdrv_view cocoa_view;+ macdrv_view client_cocoa_view;+ struct macdrv_win_data *real;+};++static struct dxmt_win_data *dxmt_get_win_data(HWND hwnd)+{+ struct macdrv_win_data *real = get_win_data(hwnd);+ struct dxmt_win_data *data;++ if (!real) return NULL;+ if (!real->client_view)+ {+ /* Wine 11 only gives a window a client view once something renders into it. Make+ * one the way the GL and Vulkan paths do; the surface lives as long as the window. */+ release_win_data(real);+ macdrv_CreateClientSurface(hwnd, 0);+ if (!(real = get_win_data(hwnd))) return NULL;+ }+ if (!(data = calloc(1, sizeof(*data))))+ {+ release_win_data(real);+ return NULL;+ }+ data->hwnd = real->hwnd;+ data->cocoa_window = real->cocoa_window;+ data->cocoa_view = real->client_view;+ data->client_cocoa_view = real->client_view;+ data->real = real;+ return data;+}++static void dxmt_release_win_data(struct dxmt_win_data *data)+{+ if (!data) return;+ release_win_data(data->real);+ free(data);+}++static void dxmt_init_display_devices(BOOL force)+{+}++struct macdrv_functions_t+{+ void (*macdrv_init_display_devices)(BOOL);+ struct dxmt_win_data *(*get_win_data)(HWND hwnd);+ void (*release_win_data)(struct dxmt_win_data *data);+ macdrv_window (*macdrv_get_cocoa_window)(HWND hwnd, BOOL require_on_screen);+ macdrv_metal_device (*macdrv_create_metal_device)(void);+ void (*macdrv_release_metal_device)(macdrv_metal_device d);+ macdrv_metal_view (*macdrv_view_create_metal_view)(macdrv_view v, macdrv_metal_device d);+ macdrv_metal_layer (*macdrv_view_get_metal_layer)(macdrv_metal_view v);+ void (*macdrv_view_release_metal_view)(macdrv_metal_view v);+};++__attribute__((visibility("default"))) struct macdrv_functions_t macdrv_functions =+{+ dxmt_init_display_devices,+ dxmt_get_win_data,+ dxmt_release_win_data,+ macdrv_get_cocoa_window,+ macdrv_create_metal_device,+ macdrv_release_metal_device,+ macdrv_view_create_metal_view,+ macdrv_view_get_metal_layer,+ macdrv_view_release_metal_view,+};