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
feat(engine): WineCX 11.15 free engine with msync and optional user GPTK
raymondchins235f2a6d92d3
diff --git a/app/Package.swift b/app/Package.swiftindex 55c8ff1..a8a5c54 100644--- a/app/Package.swift+++ b/app/Package.swift@@ -41,6 +41,8 @@ let package = Package(.copy("Resources/detour2-winehq-11.15.bin"),.copy("Resources/detour32-winehq-11.15.bin"),.copy("Resources/winemac-winehq-11.15.so"),+ .copy("Resources/detour2-winecx-11.15.bin"),+ .copy("Resources/detour32-winecx-11.15.bin"),],swiftSettings: [.swiftLanguageMode(.v6)]),diff --git a/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift b/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swiftnew file mode 100644index 0000000..0720194--- /dev/null+++ b/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift@@ -0,0 +1,283 @@+// The second free engine: WineCX, CodeWeavers' LGPL CrossOver 26.3 Wine changes rebased+// onto wine-11.15 by dappermint (github.com/dappermint/winecx, wine1115 branch) and built+// into a Whisky runtime by dappermint/winecx-gptk's CI. Over the WineHQ engine it adds+// msync and the CrossOver hooks Apple's D3DMetal needs, and it carries DXMT and DXVK as+// backends a game opts into instead of replacing Wine's own Direct3D. docs/WINECX.md.++import Foundation++struct WinecxBackendFile: Sendable, Equatable {+ // Path inside the archive, below Libraries/.+ let source: String+ // Path below lib/notproton-backends/ in the engine.+ let destination: String+ let sha256: String+}++struct WinecxRelease: Sendable {+ let build: String+ // The winecx-gptk runtime version, which is what its WhiskyWineVersion.plist carries.+ let runtime: 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 backends: [WinecxBackendFile]+}++enum FreeEngineWinecx {++ static let step = "Download free WineCX engine"++ // runtime 4.5.125 is the last wine1115 build (winecx 5b45f45, built from winecx-gptk+ // 7a0349b, minos 26.0). It is the 11.15 the bridge components are built against, and+ // the only 11.15 runtime with the msync spin fixes. The same bytes are mirrored on+ // dappermint/Whisky, which is what Whisky itself downloads.+ static let current = WinecxRelease(+ build: "winecx-11.15",+ runtime: "4.5.125",+ archive: "Libraries.tar.gz",+ sha256: "6db83765d9bd9d9941cacf8e09d2b8a3014738305ca4672d2188f3e6e51fae87",+ bases: [+ URL(string: "https://github.com/dappermint/winecx-gptk/releases/download/runtime-v4.5.125")!,+ URL(string: "https://github.com/dappermint/Whisky/releases/download/v4.5.125")!,+ ],+ bundleName: "WineCX 11.15.app",+ wineTree: "Libraries/Wine",+ // The archive's DXMT 0.80 frontends already have the builtin marker stripped, so+ // they load as native DLLs from a prefix. nvapi64 and nvngx are left out for the+ // reason FreeEngine gives. winemetal stays where the archive put it, a builtin in+ // lib/wine beside its unix half. The DXVK-macOS 1.10.3 repack ships no dxgi.+ backends: [+ WinecxBackendFile(source: "DXMT/x64/d3d10core.dll", destination: "dxmt/x86_64-windows/d3d10core.dll",+ sha256: "24ca320249f0683d0bded170ef135f430c5b0f310b461e68108ee3c13e7e0aac"),+ WinecxBackendFile(source: "DXMT/x64/d3d11.dll", destination: "dxmt/x86_64-windows/d3d11.dll",+ sha256: "8d4842aaf4fd3de3f115d1f51da13930f27764dad1bb217fc28e7d154c1612b3"),+ WinecxBackendFile(source: "DXMT/x64/dxgi.dll", destination: "dxmt/x86_64-windows/dxgi.dll",+ sha256: "a9686960d8341a034cdfbb46015592b1d407922f4b2686274b7865bbc4c0683c"),+ WinecxBackendFile(source: "DXMT/x32/d3d10core.dll", destination: "dxmt/i386-windows/d3d10core.dll",+ sha256: "e867d24efe319bbc5e54da8732cc67d4bf975a291a57782d0cf8517af11fca22"),+ WinecxBackendFile(source: "DXMT/x32/d3d11.dll", destination: "dxmt/i386-windows/d3d11.dll",+ sha256: "7002dac2b38c757109c2a661832d90f391a0f5cee9bda469cae539de75ff6eec"),+ WinecxBackendFile(source: "DXMT/x32/dxgi.dll", destination: "dxmt/i386-windows/dxgi.dll",+ sha256: "4ca0246cc6aac9f1d36ac4da495f31adca33c5a02bb42b3231bd84b940514fdd"),+ WinecxBackendFile(source: "DXVK/x64/d3d10core.dll", destination: "dxvk/x86_64-windows/d3d10core.dll",+ sha256: "0fa08bba860c63e3abeeabfc96d0e7aa327411a975f8f23d2dc63594ef5f796e"),+ WinecxBackendFile(source: "DXVK/x64/d3d11.dll", destination: "dxvk/x86_64-windows/d3d11.dll",+ sha256: "0ff0b0835dde29556bd01dfce7b1ae348d7f229cb1e1a37cc71ea1a028beeca4"),+ WinecxBackendFile(source: "DXVK/x32/d3d10core.dll", destination: "dxvk/i386-windows/d3d10core.dll",+ sha256: "2277187a4e13fc2049fe28cb8dd05b34b48c68031c386c3597ba0e18b0c3d327"),+ WinecxBackendFile(source: "DXVK/x32/d3d11.dll", destination: "dxvk/i386-windows/d3d11.dll",+ sha256: "f79d417f675d00008375eb4ea2318af6fcd0b27971d604d3cf345a0dcfa998a0"),+ ]+ )++ // Appended to SupportedRunners.all. The hash-pinned loader is what makes it free, so a+ // CrossOver install can never be taken for it.+ static let runnerBuild = RunnerBuild(+ bundleVersion: "winecx-11.15",+ releaseVersion: "WineCX 11.15",+ flavor: nil,+ loaderSHA256: "a4b677428a6834f97f536a84d32c5da982c9a449e5d483c6be3d1c9b8f308998",+ cleanNtdll: [+ .x86_64Windows: "5710d16382c7a822ed8b1cba58d95fd86fe01905f039c296ca7224abff8f98e8",+ .i386Windows: "e1b208073c804a443e64ada577899d96a5c8eaee435813e4a30e0d143bca6e3c",+ ],+ patchedNtdll: [+ .x86_64Windows: "4efd956e573726777827cddaa89ef3b7f72d6cfd7b8e2049e41f5f5bdf4a6306",+ .i386Windows: "23ee72664f172d38d76ecb8969d5c5af7e6828864dfe298338ed0e773910bc5d",+ ],+ tools: [+ CompatTool(name: "notproton-winecx", flavor: .rosetta, display: "WineCX 11.15 (msync, D3DMetal)"),+ ],+ isFree: true+ )++ // Appended to NtdllPatcher.byBuild. From ntdll-patch/resolve.py on the archive's ntdlls,+ // payloads from build.sh and build32.sh with the variant winecx-11.15. The x86_64 hook is+ // the CrossOver one (cmp [rsp+0xf0], 0), and its .text padding holds the detour; the+ // i386 padding does not, so that one gets the appended section.+ static let ntdllPatches: [NtdllPatch] = [+ NtdllPatch(+ arch: .x86_64Windows,+ payloadResource: "detour2-winecx-11.15",+ payloadSHA256: "fde56854b9a7a32da19babe2427d19ff6a6b83de1917fe8d32aaddd2991fc6b9",+ caveRVA: 0x82b20,+ payloadRVA: 0x82b20,+ hooks: [+ NtdllHook(rva: 0x52e43,+ stolen: [0x48, 0x83, 0xbc, 0x24, 0xf0, 0x00, 0x00, 0x00, 0x00]),+ ],+ caveSize: 1248,+ cavePad: 0x00,+ machine: 0x8664,+ magic: 0x20b,+ imageBase: 0x1_7000_0000+ ),+ NtdllPatch(+ arch: .i386Windows,+ payloadResource: "detour32-winecx-11.15",+ payloadSHA256: "37daf5f795535df91bc8fcbd356f22f4fd1ab379ec4acc97ddff44037d265556",+ caveRVA: 0xb9000,+ payloadRVA: 0xb9000,+ hooks: [+ NtdllHook(rva: 0x4f7c0, stolen: [0xf6, 0x45, 0xb4, 0x02, 0x75, 0x29]),+ ],+ caveSize: 0x1000,+ cavePad: 0x00,+ machine: 0x14c,+ magic: 0x10b,+ imageBase: 0x7bc0_0000,+ placement: .section+ ),+ ]++ // Runtime contract with compat_run.sh: the engine root says it can run msync, and the+ // backends sit outside lib/wine so Wine's own Direct3D stays the builtin.+ static let backendsPath = "lib/notproton-backends"+ static let msyncMarkerPath = ".notproton-msync"++ static var downloads: URL {+ SupportPaths.home.appending(+ path: "Library/Caches/\(SupportPaths.supportDirName)/engines/winecx-\(current.runtime)",+ directoryHint: .isDirectory+ )+ }++ static func bundle(for release: WinecxRelease = current, engines: URL = SupportPaths.engines) -> URL {+ engines.appending(path: release.bundleName, directoryHint: .isDirectory)+ }++ static func isInstalled(_ release: WinecxRelease = 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 hasBackends(root: install.crossOverRoot, release: release)+ }++ static func hasBackends(root: URL, release: WinecxRelease = current) -> Bool {+ release.backends.allSatisfy { file in+ Digest.sha256IfPresent(backend(file.destination, in: root)) == file.sha256+ } && FileManager.default.fileExists(atPath: msyncMarker(in: root).path(percentEncoded: false))+ }++ static func backend(_ path: String, in root: URL) -> URL {+ root.appending(path: "\(backendsPath)/\(path)")+ }++ static func msyncMarker(in root: URL) -> URL {+ root.appending(path: msyncMarkerPath)+ }++ enum Phase: Sendable {+ case downloading(PinnedDownload.Progress)+ case unpacking++ var label: String {+ switch self {+ case .downloading(let progress): progress.label+ case .unpacking: "Unpacking WineCX"+ }+ }+ }++ static func install(+ _ release: WinecxRelease = 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)) }+ )+ report(.unpacking)+ return try unpack(archive, release: release, engines: engines)+ }++ static func unpack(+ _ archive: URL,+ release: WinecxRelease,+ engines: URL,+ gptkRoots: [URL] = WinecxD3DMetal.searchRoots()+ ) 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)++ let libraries = wine.deletingLastPathComponent()+ for file in release.backends {+ let source = libraries.appending(path: file.source)+ guard Digest.sha256IfPresent(source) == file.sha256 else {+ throw StepFailure(step: step, detail: "\(release.archive) has no pinned \(file.source).")+ }+ let destination = backend(file.destination, in: root)+ try fm.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true)+ try? fm.removeItem(at: destination)+ try fm.copyItem(at: source, to: destination)+ }+ try Data("\(release.build)\n".utf8).write(to: msyncMarker(in: root))++ // The winecx tree keeps its unix loader beside the unix libraries the way+ // CrossOver does, so like the WineHQ engine it needs no reshaping inside.+ let info: [String: Any] = [+ "CFBundleIdentifier": "org.winehq.wine.notproton.winecx",+ "CFBundleName": release.bundleName.replacingOccurrences(of: ".app", with: ""),+ "CFBundleShortVersionString": release.build.replacingOccurrences(of: "winecx-", 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."+ )+ }++ // Only links, and only to a Game Porting Toolkit the user installed. An engine+ // without one is complete, it just has no D3DMetal.+ WinecxD3DMetal.refresh(root: install.crossOverRoot, roots: gptkRoots)++ 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/FreeEngineWinecxD3DMetal.swift b/app/Sources/NotProtonApp/Model/FreeEngineWinecxD3DMetal.swiftnew file mode 100644index 0000000..a28c8eb--- /dev/null+++ b/app/Sources/NotProtonApp/Model/FreeEngineWinecxD3DMetal.swift@@ -0,0 +1,218 @@+// Links a Game Porting Toolkit the user installed into a WineCX engine, so D3DMetal can+// run on it. Nothing of Apple's is copied or shipped: every entry is a symlink into the+// user's own copy, and the marker compat_run.sh reads is written only once all of them+// are in place. Apple's payload is the redist/lib tree: external/ (D3DMetal.framework and+// libd3dshared.dylib) and builtin-marked PE forwarders under wine/x86_64-windows. There+// is no i386 half, so D3DMetal is 64-bit only.+//+// Layout in the engine root, beside the stock Direct3D that lib/wine keeps:+// lib/external/{D3DMetal.framework,libd3dshared.dylib} -> the user's external/+// winecx's own lib/external, where its build expects the payload. Also the+// CX_APPLEGPTK_LIBD3DSHARED_PATH winecx's ntdll dlopens for non-native code regions.+// lib/notproton-backends/d3dmetal/x86_64-windows/<forwarder> -> the user's forwarder+// lib/notproton-backends/d3dmetal/x86_64-unix/<name>.so -> ../../../external/libd3dshared.dylib+// Wine takes a builtin's unix half from the x86_64-unix beside the directory the PE+// came from. A symlink rather than a copy, so libd3dshared's @loader_path rpath+// still lands beside D3DMetal.framework.+// lib/notproton-backends/d3dmetal.enabled++import Foundation++enum WinecxD3DMetal {++ static let forwarders = ["d3d10.dll", "d3d11.dll", "d3d12.dll", "dxgi.dll"]+ static let sharedLibrary = "libd3dshared.dylib"+ static let framework = "D3DMetal.framework"++ static let externalPath = "lib/external"+ static let backendPath = "\(FreeEngineWinecx.backendsPath)/d3dmetal"+ static let enabledMarkerPath = "\(FreeEngineWinecx.backendsPath)/d3dmetal.enabled"+ static let unixLinkDestination = "../../../external/\(sharedLibrary)"++ struct Payload: Sendable, Equatable {+ // The folder holding external/ and wine/.+ let libRoot: URL+ // D3DMetal.framework's CFBundleShortVersionString, when it has one.+ let version: String?+ }++ // Where the user puts a copy by hand: GPTK's redist/lib, or the whole redist folder.+ static var userFolder: URL {+ SupportPaths.support.appending(path: "gptk", directoryHint: .isDirectory)+ }++ // In order of preference. The user's own folder wins over an installed app.+ static func searchRoots(home: URL = SupportPaths.home) -> [URL] {+ [+ home.appending(path: "Library/Application Support/\(SupportPaths.supportDirName)/gptk",+ directoryHint: .isDirectory),+ // Gcenx's game-porting-toolkit cask installs here.+ URL(filePath: "/Applications/Game Porting Toolkit.app", directoryHint: .isDirectory),+ home.appending(path: "Applications/Game Porting Toolkit.app", directoryHint: .isDirectory),+ ]+ }++ // Accepts the lib folder itself, a redist folder, an evaluation-environment volume+ // root, or a Game Porting Toolkit.app.+ static func payloadRoot(under url: URL) -> URL? {+ [+ url,+ url.appending(path: "lib"),+ url.appending(path: "redist/lib"),+ url.appending(path: "Contents/Resources/wine/lib"),+ ].first(where: isPayloadRoot)+ }++ static func isPayloadRoot(_ lib: URL) -> Bool {+ let fm = FileManager.default+ let external = lib.appending(path: "external")+ var isDirectory: ObjCBool = false+ guard fm.fileExists(atPath: external.appending(path: sharedLibrary).path(percentEncoded: false)),+ fm.fileExists(atPath: external.appending(path: framework).path(percentEncoded: false),+ isDirectory: &isDirectory),+ isDirectory.boolValue+ else { return false }+ return forwarders.allSatisfy { isBuiltin(lib.appending(path: "wine/x86_64-windows/\($0)")) }+ }++ // Apple's forwarders are winebuild builtins, and only a builtin gets a unix half, so a+ // forwarder without the marker could never reach D3DMetal. Wine compares the 17 bytes+ // at 0x40 against the marker and its terminator.+ static func isBuiltin(_ dll: URL) -> Bool {+ guard let handle = try? FileHandle(forReadingFrom: dll) else { return false }+ defer { try? handle.close() }+ guard let head = try? handle.read(upToCount: 0x51), head.count == 0x51 else { return false }+ let marker = Array("Wine builtin DLL".utf8) + [0]+ return Array(head[0x40 ..< 0x51]) == marker+ }++ static func locate(in roots: [URL] = searchRoots()) -> Payload? {+ for root in roots {+ guard let lib = payloadRoot(under: root) else { continue }+ return Payload(libRoot: lib, version: version(ofExternal: lib.appending(path: "external")))+ }+ return nil+ }++ static func version(ofExternal external: URL) -> String? {+ let bundle = external.appending(path: framework)+ for plist in [bundle.appending(path: "Versions/A/Resources/Info.plist"),+ bundle.appending(path: "Resources/Info.plist")] {+ guard let data = try? Data(contentsOf: plist),+ let dict = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],+ let version = dict["CFBundleShortVersionString"] as? String, !version.isEmpty+ else { continue }+ return version+ }+ return nil+ }++ static func enabledMarker(in root: URL) -> URL { root.appending(path: enabledMarkerPath) }++ // Every link the layout needs, as (link, destination it must resolve to).+ static func links(for payload: Payload, root: URL) -> [(link: URL, target: String)] {+ let source = payload.libRoot.standardizedFileURL+ let external = root.appending(path: externalPath)+ let backend = root.appending(path: backendPath)+ var links: [(link: URL, target: String)] = [+ (external.appending(path: framework),+ source.appending(path: "external/\(framework)").path(percentEncoded: false)),+ (external.appending(path: sharedLibrary),+ source.appending(path: "external/\(sharedLibrary)").path(percentEncoded: false)),+ ]+ for name in forwarders {+ links.append((backend.appending(path: "x86_64-windows/\(name)"),+ source.appending(path: "wine/x86_64-windows/\(name)").path(percentEncoded: false)))+ let unix = (name as NSString).deletingPathExtension + ".so"+ links.append((backend.appending(path: "x86_64-unix/\(unix)"), unixLinkDestination))+ }+ return links+ }++ static func link(_ payload: Payload, root: URL) throws {+ let fm = FileManager.default+ unlink(root: root)+ do {+ for entry in links(for: payload, root: root) {+ try fm.createDirectory(at: entry.link.deletingLastPathComponent(), withIntermediateDirectories: true)+ if isSymlink(entry.link) { try fm.removeItem(at: entry.link) }+ try fm.createSymbolicLink(atPath: entry.link.path(percentEncoded: false),+ withDestinationPath: entry.target)+ }+ guard linksResolve(root: root) else {+ throw StepFailure(step: FreeEngineWinecx.step,+ detail: "The Game Porting Toolkit links in the engine do not resolve.")+ }+ let marker = [+ "source=\(payload.libRoot.standardizedFileURL.path(percentEncoded: false))",+ "version=\(payload.version ?? "unknown")",+ "libd3dshared=\(externalPath)/\(sharedLibrary)",+ "dllpath=\(backendPath)",+ ].joined(separator: "\n") + "\n"+ try Data(marker.utf8).write(to: enabledMarker(in: root))+ } catch {+ unlink(root: root)+ throw error+ }+ }++ // Removes what link made and nothing else: the marker goes first so a consumer never+ // sees it over a half-removed layout, and lib/external keeps winecx's own README.+ static func unlink(root: URL) {+ let fm = FileManager.default+ try? fm.removeItem(at: enabledMarker(in: root))+ try? fm.removeItem(at: root.appending(path: backendPath))+ for name in [framework, sharedLibrary] {+ let link = root.appending(path: "\(externalPath)/\(name)")+ if isSymlink(link) { try? fm.removeItem(at: link) }+ }+ }++ static func isLinked(root: URL) -> Bool {+ FileManager.default.fileExists(atPath: enabledMarker(in: root).path(percentEncoded: false))+ && linksResolve(root: root)+ }++ // fileExists follows links, so a GPTK that was moved or deleted shows up here.+ private static func linksResolve(root: URL) -> Bool {+ let backend = root.appending(path: backendPath)+ let external = root.appending(path: externalPath)+ let paths = [external.appending(path: framework), external.appending(path: sharedLibrary)]+ + forwarders.flatMap { name in+ [backend.appending(path: "x86_64-windows/\(name)"),+ backend.appending(path: "x86_64-unix/\((name as NSString).deletingPathExtension).so")]+ }+ return paths.allSatisfy { FileManager.default.fileExists(atPath: $0.path(percentEncoded: false)) }+ }++ private static func isSymlink(_ url: URL) -> Bool {+ let attributes = try? FileManager.default.attributesOfItem(atPath: url.path(percentEncoded: false))+ return attributes?[.type] as? FileAttributeType == .typeSymbolicLink+ }++ // Links the first Game Porting Toolkit found, or clears the layout when there is none+ // or the old one went away. Only ever touches a WineCX root: a CrossOver bundle has+ // its own D3DMetal and is never written to.+ @discardableResult+ static func refresh(root: URL, roots: [URL] = searchRoots()) -> Payload? {+ guard isWinecx(root: root) else { return nil }+ guard let payload = locate(in: roots) else {+ unlink(root: root)+ return nil+ }+ do {+ try link(payload, root: root)+ AppLog.note("winecx: linked D3DMetal \(payload.version ?? "unknown") from "+ + payload.libRoot.path(percentEncoded: false))+ return payload+ } catch {+ AppLog.note("winecx: could not link D3DMetal: \(error.localizedDescription)")+ return nil+ }+ }++ static func isWinecx(root: URL) -> Bool {+ let loader = Clean.copy(of: CrossOverSource.unixLoader(inRoot: root))+ return Digest.sha256IfPresent(loader) == FreeEngineWinecx.runnerBuild.loaderSHA256+ }+}diff --git a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift b/app/Sources/NotProtonApp/Model/NtdllPatcher.swiftindex 01972df..c8c8713 100644--- a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift+++ b/app/Sources/NotProtonApp/Model/NtdllPatcher.swift@@ -285,6 +285,7 @@ enum NtdllPatcher {imageBase: 0x7bc0_0000),],+ FreeEngineWinecx.runnerBuild.id: FreeEngineWinecx.ntdllPatches,]static func patches(for build: RunnerBuild) -> [NtdllPatch] {diff --git a/app/Sources/NotProtonApp/Model/SupportedRunner.swift b/app/Sources/NotProtonApp/Model/SupportedRunner.swiftindex c3f796a..fc9e06b 100644--- a/app/Sources/NotProtonApp/Model/SupportedRunner.swift+++ b/app/Sources/NotProtonApp/Model/SupportedRunner.swift@@ -251,6 +251,7 @@ enum SupportedRunners {],isFree: true),+ FreeEngineWinecx.runnerBuild,]static func build(loaderSHA256 hash: String) -> RunnerBuild? {diff --git a/app/Sources/NotProtonApp/Resources/detour2-winecx-11.15.bin b/app/Sources/NotProtonApp/Resources/detour2-winecx-11.15.binnew file mode 100644index 0000000..f2183b0Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/detour2-winecx-11.15.bin differdiff --git a/app/Sources/NotProtonApp/Resources/detour32-winecx-11.15.bin b/app/Sources/NotProtonApp/Resources/detour32-winecx-11.15.binnew file mode 100644index 0000000..4c2f7a4Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/detour32-winecx-11.15.bin differdiff --git a/app/Tests/NotProtonAppTests/FreeEngineTests.swift b/app/Tests/NotProtonAppTests/FreeEngineTests.swiftindex 56b3c1d..6177253 100644--- a/app/Tests/NotProtonAppTests/FreeEngineTests.swift+++ b/app/Tests/NotProtonAppTests/FreeEngineTests.swift@@ -18,7 +18,7 @@ struct FreeEngineTests {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])+ #expect(SupportedRunners.all.filter(\.isFree).map(\.id).contains(FreeEngine.current.build))}@Test("A CrossOver-shaped tree whose loader is not a free build still needs a license")diff --git a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swiftnew file mode 100644index 0000000..e26eee5--- /dev/null+++ b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift@@ -0,0 +1,330 @@+import Foundation+import Testing++@testable import NotProtonApp++@Suite("Free WineCX engine")+struct FreeEngineWinecxTests {++ private func makeDirectory(_ label: String) throws -> URL {+ let url = FileManager.default.temporaryDirectory.appending(path: "np-winecx-\(label)-\(UUID().uuidString)")+ try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)+ return url+ }++ @Test("The pinned release names a free build NotProton knows how to patch")+ func releaseIsSupported() throws {+ let build = try #require(SupportedRunners.build(id: FreeEngineWinecx.current.build))+ #expect(build == FreeEngineWinecx.runnerBuild)+ #expect(build.isFree)+ #expect(Set(NtdllPatcher.patches(for: build).map(\.arch)) == [.x86_64Windows, .i386Windows])+ #expect(SupportedRunners.build(loaderSHA256: build.loaderSHA256)?.id == build.id)+ #expect(build.tools.map(\.name) == ["notproton-winecx"])+ #expect(build.tools.first?.display == "WineCX 11.15 (msync, D3DMetal)")+ #expect(build.tools.first?.flavor == .rosetta)+ }++ @Test("Both free engines stay separate builds with their own loaders and tools")+ func coexistsWithWineHQ() throws {+ let free = SupportedRunners.all.filter(\.isFree)+ #expect(Set(free.map(\.id)) == [FreeEngine.current.build, FreeEngineWinecx.current.build])+ #expect(Set(free.map(\.loaderSHA256)).count == free.count)+ #expect(Set(free.flatMap(\.tools).map(\.name)).count == free.flatMap(\.tools).count)+ #expect(FreeEngineWinecx.current.bundleName != FreeEngine.current.bundleName)+ }++ // The license gate keys on the loader hash alone: a CrossOver-shaped tree whose loader+ // is anything else still needs CodeWeavers' license, wherever it sits.+ @Test("A tree that only looks like WineCX is not free")+ func lookalikeNeedsLicense() throws {+ let engines = try makeDirectory("engines")+ defer { try? FileManager.default.removeItem(at: engines) }++ let root = FreeEngineWinecx.bundle(engines: engines).appending(path: "Contents/SharedSupport/CrossOver")+ let loader = CrossOverSource.unixLoader(inRoot: root)+ try FileManager.default.createDirectory(at: loader.deletingLastPathComponent(), withIntermediateDirectories: true)+ try Data("not winecx".utf8).write(to: loader)+ try Data("winecx-11.15\n".utf8).write(to: FreeEngineWinecx.msyncMarker(in: root))++ #expect(CrossOverLicense.freeBuild(at: root) == nil)+ #expect(!CrossOverLicense.check(crossOverRoot: root, searchDirs: []).licensed)+ #expect(!FreeEngineWinecx.isInstalled(engines: engines))+ #expect(!WinecxD3DMetal.isWinecx(root: root))+ }++ @Test("Backends follow the compat_run.sh layout and never shadow lib/wine")+ func backendLayout() {+ let backends = FreeEngineWinecx.current.backends+ #expect(!backends.isEmpty)+ #expect(Set(backends.map(\.destination)).count == backends.count)+ for file in backends {+ let parts = file.destination.split(separator: "/").map(String.init)+ #expect(parts.count == 3, "\(file.destination)")+ #expect(["dxmt", "dxvk"].contains(parts[0]), "\(file.destination)")+ #expect(["x86_64-windows", "i386-windows"].contains(parts[1]), "\(file.destination)")+ #expect(!["nvapi64.dll", "nvngx.dll"].contains(parts[2]))+ #expect(file.sha256.count == 64 && file.sha256.allSatisfy(\.isHexDigit))+ #expect(FreeEngineWinecx.backend(file.destination, in: URL(filePath: "/r")).path(percentEncoded: false)+ == "/r/lib/notproton-backends/\(file.destination)")+ }+ for backend in ["dxmt", "dxvk"] {+ for arch in ["x86_64-windows", "i386-windows"] {+ #expect(backends.contains { $0.destination == "\(backend)/\(arch)/d3d11.dll" })+ }+ }+ #expect(FreeEngineWinecx.msyncMarker(in: URL(filePath: "/r")).path(percentEncoded: false)+ == "/r/.notproton-msync")+ #expect(WinecxD3DMetal.enabledMarker(in: URL(filePath: "/r")).path(percentEncoded: false)+ == "/r/lib/notproton-backends/d3dmetal.enabled")+ }++ @Test("Downloads come only from the pinned GitHub release mirrors")+ func pinnedSources() {+ let release = FreeEngineWinecx.current+ #expect(release.sha256 == "6db83765d9bd9d9941cacf8e09d2b8a3014738305ca4672d2188f3e6e51fae87")+ #expect(release.bases.allSatisfy { $0.host() == "github.com" })+ #expect(release.bases.allSatisfy { $0.path().hasSuffix(release.runtime) })+ #expect(FreeEngineWinecx.downloads.lastPathComponent == "winecx-\(release.runtime)")+ }++ // MARK: - D3DMetal linking++ // A stand-in for Apple's redist/lib: the names and the builtin marker, none of the code.+ private func makePayload(in folder: URL, version: String? = "3.0", builtin: Bool = true) throws -> URL {+ let fm = FileManager.default+ let lib = folder+ let external = lib.appending(path: "external")+ let framework = external.appending(path: "D3DMetal.framework")+ try fm.createDirectory(at: framework.appending(path: "Versions/A/Resources"), withIntermediateDirectories: true)+ if let version {+ let plist = try PropertyListSerialization.data(+ fromPropertyList: ["CFBundleShortVersionString": version], format: .xml, options: 0)+ try plist.write(to: framework.appending(path: "Versions/A/Resources/Info.plist"))+ }+ try Data("dylib".utf8).write(to: external.appending(path: "libd3dshared.dylib"))+ let pe = lib.appending(path: "wine/x86_64-windows")+ try fm.createDirectory(at: pe, withIntermediateDirectories: true)+ var image = Data(repeating: 0, count: 0x80)+ image[0] = 0x4d+ image[1] = 0x5a+ if builtin { image.replaceSubrange(0x40 ..< 0x51, with: Array("Wine builtin DLL".utf8) + [0]) }+ for name in WinecxD3DMetal.forwarders {+ try image.write(to: pe.appending(path: name))+ }+ return lib+ }++ private func makeEngineRoot(in folder: URL) throws -> URL {+ let root = folder.appending(path: "CrossOver")+ let external = root.appending(path: "lib/external")+ try FileManager.default.createDirectory(at: external, withIntermediateDirectories: true)+ try Data("winecx readme".utf8).write(to: external.appending(path: "README"))+ return root+ }++ private func destination(of link: URL) throws -> String {+ try FileManager.default.destinationOfSymbolicLink(atPath: link.path(percentEncoded: false))+ }++ @Test("A Game Porting Toolkit is found in each shape users have it in, user folder first")+ func locatesPayloadShapes() throws {+ let base = try makeDirectory("shapes")+ defer { try? FileManager.default.removeItem(at: base) }++ let lib = try makePayload(in: base.appending(path: "plain"))+ let redist = try makePayload(in: base.appending(path: "volume/redist/lib"))+ let app = try makePayload(in: base.appending(path: "GPTK.app/Contents/Resources/wine/lib"))+ let empty = base.appending(path: "empty")+ try FileManager.default.createDirectory(at: empty, withIntermediateDirectories: true)++ #expect(WinecxD3DMetal.payloadRoot(under: lib) == lib)+ #expect(WinecxD3DMetal.payloadRoot(under: base.appending(path: "volume"))?.standardizedFileURL+ == redist.standardizedFileURL)+ #expect(WinecxD3DMetal.payloadRoot(under: base.appending(path: "GPTK.app"))?.standardizedFileURL+ == app.standardizedFileURL)+ #expect(WinecxD3DMetal.payloadRoot(under: empty) == nil)++ let found = try #require(WinecxD3DMetal.locate(in: [empty, base.appending(path: "volume"), lib]))+ #expect(found.libRoot.standardizedFileURL == redist.standardizedFileURL)+ #expect(found.version == "3.0")++ let roots = WinecxD3DMetal.searchRoots(home: URL(filePath: "/Users/u"))+ #expect(roots.map { $0.path(percentEncoded: false) } == [+ "/Users/u/Library/Application Support/notproton/gptk/",+ "/Applications/Game Porting Toolkit.app/",+ "/Users/u/Applications/Game Porting Toolkit.app/",+ ])+ }++ @Test("Forwarders without the builtin marker, or a payload missing pieces, are refused")+ func rejectsIncompletePayloads() throws {+ let base = try makeDirectory("reject")+ defer { try? FileManager.default.removeItem(at: base) }++ let native = try makePayload(in: base.appending(path: "native"), builtin: false)+ #expect(!WinecxD3DMetal.isPayloadRoot(native))++ let partial = try makePayload(in: base.appending(path: "partial"))+ try FileManager.default.removeItem(at: partial.appending(path: "wine/x86_64-windows/d3d12.dll"))+ #expect(!WinecxD3DMetal.isPayloadRoot(partial))++ let noFramework = try makePayload(in: base.appending(path: "noframework"))+ try FileManager.default.removeItem(at: noFramework.appending(path: "external/D3DMetal.framework"))+ #expect(!WinecxD3DMetal.isPayloadRoot(noFramework))++ #expect(WinecxD3DMetal.locate(in: [native, partial, noFramework]) == nil)+ }++ @Test("Linking writes only symlinks into the user's copy, then the marker")+ func linksPayload() throws {+ let base = try makeDirectory("link")+ defer { try? FileManager.default.removeItem(at: base) }+ let fm = FileManager.default++ let lib = try makePayload(in: base.appending(path: "gptk"))+ let root = try makeEngineRoot(in: base)+ let payload = try #require(WinecxD3DMetal.locate(in: [lib]))+ try WinecxD3DMetal.link(payload, root: root)++ #expect(WinecxD3DMetal.isLinked(root: root))+ let source = lib.standardizedFileURL+ #expect(try destination(of: root.appending(path: "lib/external/libd3dshared.dylib"))+ == source.appending(path: "external/libd3dshared.dylib").path(percentEncoded: false))+ #expect(try destination(of: root.appending(path: "lib/external/D3DMetal.framework"))+ == source.appending(path: "external/D3DMetal.framework").path(percentEncoded: false))+ for name in WinecxD3DMetal.forwarders {+ let pe = root.appending(path: "lib/notproton-backends/d3dmetal/x86_64-windows/\(name)")+ #expect(try destination(of: pe)+ == source.appending(path: "wine/x86_64-windows/\(name)").path(percentEncoded: false))+ let unix = root.appending(+ path: "lib/notproton-backends/d3dmetal/x86_64-unix/\((name as NSString).deletingPathExtension).so")+ #expect(try destination(of: unix) == "../../../external/libd3dshared.dylib")+ // The relative link has to land on the shared library through lib/external.+ #expect(try Data(contentsOf: unix) == Data("dylib".utf8))+ }+ #expect(fm.fileExists(atPath: root.appending(path: "lib/external/README").path(percentEncoded: false)))+ // Nothing lands in lib/wine.+ #expect(!fm.fileExists(atPath: root.appending(path: "lib/wine").path(percentEncoded: false)))++ let marker = try String(contentsOf: WinecxD3DMetal.enabledMarker(in: root), encoding: .utf8)+ #expect(marker.contains("version=3.0\n"))+ #expect(marker.contains("libd3dshared=lib/external/libd3dshared.dylib\n"))+ #expect(marker.contains("dllpath=lib/notproton-backends/d3dmetal\n"))++ // Relinking is idempotent.+ try WinecxD3DMetal.link(payload, root: root)+ #expect(WinecxD3DMetal.isLinked(root: root))+ }++ @Test("A Game Porting Toolkit that went away reads as unlinked, and unlinking keeps winecx's files")+ func unlinksCleanly() throws {+ let base = try makeDirectory("unlink")+ defer { try? FileManager.default.removeItem(at: base) }+ let fm = FileManager.default++ let lib = try makePayload(in: base.appending(path: "gptk"))+ let root = try makeEngineRoot(in: base)+ try WinecxD3DMetal.link(try #require(WinecxD3DMetal.locate(in: [lib])), root: root)++ try fm.removeItem(at: lib)+ #expect(!WinecxD3DMetal.isLinked(root: root))++ WinecxD3DMetal.unlink(root: root)+ #expect(!fm.fileExists(atPath: WinecxD3DMetal.enabledMarker(in: root).path(percentEncoded: false)))+ #expect(!fm.fileExists(atPath: root.appending(path: "lib/notproton-backends/d3dmetal").path(percentEncoded: false)))+ #expect((try? fm.destinationOfSymbolicLink(+ atPath: root.appending(path: "lib/external/libd3dshared.dylib").path(percentEncoded: false))) == nil)+ #expect(fm.fileExists(atPath: root.appending(path: "lib/external/README").path(percentEncoded: false)))++ // A real file in lib/external is never removed, only links are.+ let real = root.appending(path: "lib/external/libd3dshared.dylib")+ try Data("placed by hand".utf8).write(to: real)+ WinecxD3DMetal.unlink(root: root)+ #expect(fm.fileExists(atPath: real.path(percentEncoded: false)))+ }++ @Test("Refresh never writes into a tree that is not WineCX")+ func refreshOnlyTouchesWinecx() throws {+ let base = try makeDirectory("refresh")+ defer { try? FileManager.default.removeItem(at: base) }++ let lib = try makePayload(in: base.appending(path: "gptk"))+ let root = try makeEngineRoot(in: base)+ let loader = CrossOverSource.unixLoader(inRoot: root)+ try FileManager.default.createDirectory(at: loader.deletingLastPathComponent(), withIntermediateDirectories: true)+ try Data("crossover loader".utf8).write(to: loader)++ #expect(WinecxD3DMetal.refresh(root: root, roots: [lib]) == nil)+ #expect(!FileManager.default.fileExists(+ atPath: WinecxD3DMetal.enabledMarker(in: root).path(percentEncoded: false)))+ #expect(!FileManager.default.fileExists(+ atPath: root.appending(path: "lib/notproton-backends").path(percentEncoded: false)))+ }++ // MARK: - Against the real archive++ // Runs once the archive is in NotProton's cache, or at NOTPROTON_WINECX_ARCHIVE.+ private static var realArchive: URL? {+ let candidates = [+ ProcessInfo.processInfo.environment["NOTPROTON_WINECX_ARCHIVE"].map { URL(filePath: $0) },+ FreeEngineWinecx.downloads.appending(path: FreeEngineWinecx.current.archive),+ ].compactMap { $0 }+ return candidates.first { Digest.sha256IfPresent($0) == FreeEngineWinecx.current.sha256 }+ }++ @Test("Unpacking the real archive yields a free, patchable engine with the runtime contract")+ func unpacksRealArchive() throws {+ guard let archive = Self.realArchive else { return }+ let fm = FileManager.default+ let base = try makeDirectory("real")+ defer { try? fm.removeItem(at: base) }++ let engines = base.appending(path: "engines")+ let gptk = try makePayload(in: base.appending(path: "gptk"))+ let install = try FreeEngineWinecx.unpack(+ archive, release: FreeEngineWinecx.current, engines: engines, gptkRoots: [gptk]+ )+ guard case .supported(let build) = install.support else {+ Issue.record("unpacked engine is \(install.support)")+ return+ }+ let root = install.crossOverRoot+ #expect(build.id == FreeEngineWinecx.current.build)+ #expect(install.isFree)+ #expect(FreeEngineWinecx.isInstalled(engines: engines))+ #expect(FreeEngineWinecx.hasBackends(root: root))+ #expect(CrossOverLicense.check(crossOverRoot: root).licensed)+ try RunnerInstaller.verifyClone(build: build, root: root)++ for patch in NtdllPatcher.patches(for: build) {+ let source = NtdllPatcher.cleanSource(inRoot: root, 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])+ }++ // lib/wine keeps Wine's own Direct3D: none of it is a backend copy.+ let pinned = Set(FreeEngineWinecx.current.backends.map(\.sha256))+ for arch in ["x86_64-windows", "i386-windows"] {+ for name in ["d3d11.dll", "dxgi.dll", "d3d10core.dll", "d3d12.dll"] {+ let stock = root.appending(path: "lib/wine/\(arch)/\(name)")+ let hash = try #require(Digest.sha256IfPresent(stock), "\(arch)/\(name)")+ #expect(!pinned.contains(hash), "\(arch)/\(name)")+ }+ }+ // DXMT's builtin half and the unix loader winecx's DXMT and D3DMetal hooks live in.+ #expect(fm.fileExists(atPath: root.appending(path: "lib/wine/x86_64-unix/winemetal.so").path(percentEncoded: false)))+ #expect(try String(contentsOf: FreeEngineWinecx.msyncMarker(in: root), encoding: .utf8) == "winecx-11.15\n")++ // The fixture GPTK was linked into the real tree, through winecx's own lib/external.+ #expect(WinecxD3DMetal.isLinked(root: root))+ #expect(fm.fileExists(atPath: root.appending(path: "lib/external/README").path(percentEncoded: false)))+ WinecxD3DMetal.unlink(root: root)+ #expect(!WinecxD3DMetal.isLinked(root: root))+ #expect(WinecxD3DMetal.refresh(root: root, roots: [gptk]) != nil)+ try fm.removeItem(at: gptk)+ #expect(WinecxD3DMetal.refresh(root: root, roots: [gptk]) == nil)+ #expect(!fm.fileExists(atPath: WinecxD3DMetal.enabledMarker(in: root).path(percentEncoded: false)))+ }+}diff --git a/docs/WINECX.md b/docs/WINECX.mdnew file mode 100644index 0000000..93e6e80--- /dev/null+++ b/docs/WINECX.md@@ -0,0 +1,177 @@+# WineCX engine++NotProton's second free engine. WineCX is CodeWeavers' open-source (LGPL) CrossOver 26.3+Wine changes, rebased by dappermint onto upstream wine-11.15+([dappermint/winecx](https://github.com/dappermint/winecx), branch `wine1115`). It is built in+CI into a Whisky runtime by [dappermint/winecx-gptk](https://github.com/dappermint/winecx-gptk).++Compared with the WineHQ 11.15 engine it adds:++- **msync**, CrossOver's Mach-port synchronisation (`WINEMSYNC=1`), which cuts the wineserver+ round trips that slow down CPU-heavy games.+- **D3DMetal support** through CrossOver's hooks (winemac `macdrv_functions`, the+ `libd3dshared` non-native code regions in ntdll, and the d3dkmt answers). This only works+ with a Game Porting Toolkit you install yourself. NotProton never downloads or ships it.+- **DXMT 0.80 and DXVK-macOS 1.10.3** as backends a game opts into. Wine's own Direct3D stays+ the builtin.++In NotProton it is build `winecx-11.15`, tool `notproton-winecx`, shown as "WineCX 11.15+(msync, D3DMetal)". Like the WineHQ engine it needs no CrossOver license. The licence check+treats it as free only because the loader hash matches the pinned one, so a CrossOver install+can never pass as it.++## Artifact++| | |+|---|---|+| File | `Libraries.tar.gz`, 461,224,571 bytes |+| URL | https://github.com/dappermint/winecx-gptk/releases/download/runtime-v4.5.125/Libraries.tar.gz |+| Mirror | https://github.com/dappermint/Whisky/releases/download/v4.5.125/Libraries.tar.gz (same bytes, the copy Whisky downloads) |+| sha256 | `6db83765d9bd9d9941cacf8e09d2b8a3014738305ca4672d2188f3e6e51fae87` |+| Source | winecx `5b45f4564c4f87fa9c0f958733a5e9bb3918a058` (the tip of `wine1115`), built by winecx-gptk `7a0349b26a04081497ae494027cf69d1a4eeb10c` |+| Base | Wine 11.15 (`VERSION`), the same Wine the bridge components are built against |+| Arch | x86_64 only (Rosetta). PE halves for x86_64 and i386, no arm64/arm64EC |+| Deployment target | minos 26.0 |++Runtime 4.5.125 is the last build on the 11.15 base. Later runtimes (4.6.x, 4.7.x) are+Wine 11.16 and 11.17. It was chosen over frankea/Whisky's+[v4.5.105-beta.1](https://github.com/frankea/Whisky/releases/tag/v4.5.105-beta.1)+(winecx `c2cce0e`) because it carries the msync fixes from 2026-08-21: sleeping instead of+spinning while a wait registers, single-waiter wakeups, and skipping wake syscalls nobody is+waiting on.++Layout inside the archive: `Libraries/Wine` is the Wine tree (`bin/`, `lib/wine/{x86_64-unix,+x86_64-windows,i386-windows}`, bundled dylibs in `lib/`, `share/wine` with wine-mono 11.2.0+and gecko). `Libraries/DXMT/{x64,x32}` holds DXMT's frontends with the builtin marker+stripped. `Libraries/DXVK/{x64,x32}` holds DXVK. DXMT's `winemetal` is already a builtin in+`lib/wine`.++## What NotProton lays out++The engine root (`…/WineCX 11.15.app/Contents/SharedSupport/CrossOver`, cloned into the runner)+is the archive's `Libraries/Wine`, plus:++```+.notproton-msync engine supports msync+lib/notproton-backends/dxmt/{x86_64,i386}-windows/{d3d11,d3d10core,dxgi}.dll+lib/notproton-backends/dxvk/{x86_64,i386}-windows/{d3d11,d3d10core}.dll+lib/notproton-backends/d3dmetal.enabled only when a GPTK is linked in+lib/notproton-backends/d3dmetal/x86_64-windows/{d3d10,d3d11,d3d12,dxgi}.dll -> your GPTK+lib/notproton-backends/d3dmetal/x86_64-unix/{d3d10,d3d11,d3d12,dxgi}.so -> ../../../external/libd3dshared.dylib+lib/external/{D3DMetal.framework,libd3dshared.dylib} -> your GPTK+```++`lib/wine` is left as shipped, with Wine's own `d3d10/d3d11/d3d10core/d3d12/dxgi`. Every+backend file is pinned by sha256 (`FreeEngineWinecx.current.backends`). nvapi64 and nvngx are+left out, as they are for the WineHQ engine. The DXVK repack has no `dxgi.dll`.++`d3dmetal.enabled` is a `key=value` file: `source=` (the GPTK `lib` folder), `version=`+(D3DMetal.framework's version), `libd3dshared=lib/external/libd3dshared.dylib` (the path to+export as `CX_APPLEGPTK_LIBD3DSHARED_PATH`, relative to `CX_ROOT`) and+`dllpath=lib/notproton-backends/d3dmetal`.++DXMT on this engine does **not** need `winemac-patch/`. winecx's `winemac.so` already exports+`_macdrv_functions` (`dlls/winemac.drv/d3dmetal.c`). Its first nine entries and the+`hwnd/cocoa_window/cocoa_view/client_cocoa_view` head of the window data are what DXMT 0.80's+`winemetal_unix.c` reads, and DXMT only uses `client_cocoa_view`.++## Using D3DMetal with your own Game Porting Toolkit++Apple's licence does not let NotProton redistribute D3DMetal, so you supply it. NotProton looks+in this order and links the first complete copy:++1. `~/Library/Application Support/notproton/gptk/`. Copy the **`redist/lib` folder's contents**+ from Apple's "Evaluation environment for Windows games" disk image here, so you end up+ with `gptk/external/` and `gptk/wine/`. The `redist` folder itself, or the whole volume,+ is also accepted. `external/` alone is not enough: D3DMetal also needs Apple's four PE+ forwarders from `wine/x86_64-windows`.+2. `/Applications/Game Porting Toolkit.app`. This is the default location for+ `brew install --cask gcenx/wine/game-porting-toolkit`, which looks in+ `Contents/Resources/wine/lib`.+3. `~/Applications/Game Porting Toolkit.app`.++A copy counts only when `external/libd3dshared.dylib`, `external/D3DMetal.framework` and+`wine/x86_64-windows/{d3d10,d3d11,d3d12,dxgi}.dll` are all present, and each forwarder+carries the `Wine builtin DLL` marker. NotProton creates symlinks only, and writes the marker+last. Linking happens when the engine is installed. After you install or move a GPTK, set+the engine up again (`WinecxD3DMetal.refresh(root:)`). A GPTK that disappears leaves+dangling links, which `isLinked(root:)` reports as unlinked. A refresh then removes the+layout and the marker. D3DMetal has no i386 half, so 32-bit games cannot use it.++## Risks++- **D3DMetal per game is not solved by this layout alone.** Apple's forwarders are winebuild+ builtins and only work when loaded as builtins: only a builtin gets its unix half+ (`get_builtin_unix_funcs`). Wine searches its own `lib/wine` before any `WINEDLLPATH` entry+ (`set_dll_path` in `dlls/ntdll/unix/loader.c`, winecx `5b45f45`). A builtin-marked copy in+ a prefix is swapped for the `lib/wine` builtin of the same name (`load_builtin`), and a+ copy with the marker stripped loads as native with no unix half. So while `lib/wine`+ keeps Wine's `d3d12/dxgi`, neither `WINEDLLPATH` nor prefix overrides reach+ `lib/notproton-backends/d3dmetal`. Whisky gets around this by replacing the `lib/wine`+ builtins outright (`GPTKImporter+Deployment.swift`). DXMT and DXVK do not have this problem+ because they load as natives from the prefix with `n,b` overrides. The consumer+ (`compat_run.sh`) needs one of two things: a per-backend loader tree, meaning a+ `lib/wine` whose `ntdll.so` and loader are real clones with the forwarders in its+ `x86_64-windows`, because Wine derives the DLL directory from `ntdll.so`'s real path; or+ the Whisky model, with D3DMetal as the builtin and DXMT/DXVK/wined3d opted into per game.+- **Upstream maturity.** The runtimes are CI builds from one maintainer, tagged automatically.+ The `runtime-v4.5.1xx` tags carry only a version table. The 11.15 notes+ ([v4.5.0](https://github.com/dappermint/winecx-gptk/releases/tag/v4.5.0),+ [v4.5.1](https://github.com/dappermint/winecx-gptk/releases/tag/v4.5.1)) list one known+ caveat: a non-reproducible Steam renderer wedge under `WINEMSYNC=1` on a heavily loaded+ machine. The workaround is `WINEMSYNC=0`. frankea+ validated Steam's UI, D3D12 via D3DMetal and DXVK D3D11 on 11.15, but not a DX12 game+ launched from Steam+ ([v4.5.105-beta.1](https://github.com/frankea/Whisky/releases/tag/v4.5.105-beta.1)).+- **msync needs the wineserver started with the same `WINEMSYNC`.** Otherwise the client+ aborts with "Server is running with WINEMSYNC but this process is not"+ (`dlls/ntdll/unix/msync.c`). `compat_run.sh` exports `WINEMSYNC` before it starts the+ prefix's server.+- **The CrossOver user profile.** A prefix built by another engine keeps its profile under+ `users/<name>`, while CrossOver-lineage Wine uses `users/crossover`+ ([frankea notes](https://github.com/frankea/Whisky/releases/tag/v4.5.105-beta.1)).+ NotProton prefixes are tied to one build, so this only matters if a prefix is moved+ between engines.+- **Bridge compatibility is inferred, not run.** `ntdll.so` exports a superset of stock+ 11.15's (299 → 302 symbols), so `lsteamclient.so` resolves. The PE `ntdll.dll` exports were+ not compared, because no stock 11.15 `ntdll.dll` was built locally. `RunnerPatcher` replaces+ winecx's own `lsteamclient` with the bridge's. The bridge has no wineserver-protocol+ component. No game was launched in this work.+- **DXVK.** The archive's DXVK has no `dxgi.dll` for either arch. A 32-bit game on DXVK paired+ with Wine's dxgi can fail with "Adapter is not a DXVK adapter" (winecx-gptk `build.yml`+ comment).+- **Licences.** Wine is LGPL-2.1+, DXMT MIT, DXVK zlib, MoltenVK Apache-2.0. The tarball also+ bundles nixpkgs libraries: ffmpeg 7.1.1 built `--enable-gpl` with x264/x265 (GPL-3.0+),+ and gstreamer's fdk-aac plugin. It ships **no licence texts**, and winecx-gptk has no+ licence of its own. NotProton only downloads the upstream release on the user's machine+ and redistributes none of it. Anyone mirroring the archive takes on those obligations.+- **Rosetta.** The engine is x86_64 and Apple has said Rosetta is largely going away in+ macOS 28. D3DMetal is x86_64 only too (winecx-gptk README).+- **GPTK authenticity.** NotProton checks the builtin marker and file presence but not Apple's+ code signature (Whisky checks both, in `GPTKImporter+Authenticity.swift`). The payload is+ a local folder the user chose.++## Regenerating the pins++```+tar -xzf Libraries.tar.gz+cd ntdll-patch+python3 resolve.py ../Libraries/Wine # self-tests against PINNED+./build.sh ../Libraries/Wine/lib/wine/x86_64-windows/ntdll.dll winecx-11.15+./build32.sh ../Libraries/Wine/lib/wine/i386-windows/ntdll.dll winecx-11.15+python3 apply.py <ntdll.dll> <out> <detour bin> # patched hashes+```++| Pin | sha256 |+|---|---|+| loader `lib/wine/x86_64-unix/wine` | `a4b677428a6834f97f536a84d32c5da982c9a449e5d483c6be3d1c9b8f308998` |+| clean x86_64 ntdll | `5710d16382c7a822ed8b1cba58d95fd86fe01905f039c296ca7224abff8f98e8` |+| patched x86_64 ntdll | `4efd956e573726777827cddaa89ef3b7f72d6cfd7b8e2049e41f5f5bdf4a6306` |+| clean i386 ntdll | `e1b208073c804a443e64ada577899d96a5c8eaee435813e4a30e0d143bca6e3c` |+| patched i386 ntdll | `23ee72664f172d38d76ecb8969d5c5af7e6828864dfe298338ed0e773910bc5d` |+| `detour2-winecx-11.15.bin` | `fde56854b9a7a32da19babe2427d19ff6a6b83de1917fe8d32aaddd2991fc6b9` |+| `detour32-winecx-11.15.bin` | `37daf5f795535df91bc8fcbd356f22f4fd1ab379ec4acc97ddff44037d265556` |++The unpack test (`FreeEngineWinecxTests.unpacksRealArchive`) checks all of this against the+real archive when `NOTPROTON_WINECX_ARCHIVE` points at it, or when it sits in NotProton's+download cache.diff --git a/ntdll-patch/apply.py b/ntdll-patch/apply.pyindex 2b0030b..0c5b7f4 100644--- a/ntdll-patch/apply.py+++ b/ntdll-patch/apply.py@@ -23,6 +23,8 @@ PAYLOAD_BY_CLEAN_SHA = {"1b02dcf6ad9d9490870f1127a421c4c0d1471c65ec1574e1e84c05d69801ac7e": "detour2-fex-41069.bin","66b1a244a611795c59a93a9491d17f36c98cd8db9be495004a37864e0e5ed4a5": "detour32-fex-41069.bin","77ca83b2e1a3a1242f9d2d8868328262b2bcfc3f59bacf8b9389ea7e797ea852": "detour64-fex-41069.bin",+ "5710d16382c7a822ed8b1cba58d95fd86fe01905f039c296ca7224abff8f98e8": "detour2-winecx-11.15.bin",+ "e1b208073c804a443e64ada577899d96a5c8eaee435813e4a30e0d143bca6e3c": "detour32-winecx-11.15.bin",}KNOWN_MACHINES = (0x8664, 0x14c, 0xaa64)diff --git a/ntdll-patch/resolve.py b/ntdll-patch/resolve.pyindex 4c2e078..017fceb 100755--- a/ntdll-patch/resolve.py+++ b/ntdll-patch/resolve.py@@ -106,6 +106,21 @@ PINNED = {'exports': {'LdrGetDllHandle': 0x18004390c, 'LdrLoadDll': 0x180041344,'NtProtectVirtualMemory': 0x180067050, 'NtOpenFile': 0x180066cb0,'NtReadFile': 0x180066710, 'NtClose': 0x180066830}},+ # WineCX 11.15 (dappermint winecx-gptk runtime 4.5.125)+ '5710d16382c7a822ed8b1cba58d95fd86fe01905f039c296ca7224abff8f98e8':+ {'hookRVA': 0x52e43, 'stolen': '4883bc24f000000000', 'caveRVA': 0x82b20, 'caveSize': 1248,+ 'resume': 0x52e4c, 'wm': 'rbx', 'load_path': 0xd0,+ 'payload': 'fde56854b9a7a32da19babe2427d19ff6a6b83de1917fe8d32aaddd2991fc6b9',+ 'exports': {'LdrGetDllHandle': 0x170017910, 'LdrLoadDll': 0x170018480,+ 'NtProtectVirtualMemory': 0x17000f640, 'NtOpenFile': 0x17000f2a0,+ 'NtReadFile': 0x17000ed00, 'NtClose': 0x17000ee20}},+ 'e1b208073c804a443e64ada577899d96a5c8eaee435813e4a30e0d143bca6e3c':+ {'hookRVA': 0x4f7c0, 'stolen': 'f645b4027529', 'caveRVA': 0xb9000, 'caveSize': 4096,+ 'resume': 0x4f7c6, 'wm': 'ebx', 'load_path': -0x5c,+ 'payload': '37daf5f795535df91bc8fcbd356f22f4fd1ab379ec4acc97ddff44037d265556',+ 'exports': {'LdrGetDllHandle': 0x7bc12a60, 'LdrLoadDll': 0x7bc13600,+ 'NtProtectVirtualMemory': 0x7bc0d764, 'NtOpenFile': 0x7bc0d594,+ 'NtReadFile': 0x7bc0d2c4, 'NtClose': 0x7bc0d354}},}EXPORTS = ['LdrGetDllHandle', 'LdrLoadDll', 'NtProtectVirtualMemory','NtOpenFile', 'NtReadFile', 'NtClose']