Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Merge remote-tracking branch 'upstream/main' into integrate

raymondchins41acf3c3f904
diff --cc Makefile
index 97e4121,0fa0800..8e66584
--- a/Makefile
+++ b/Makefile
@@@ -336,7 -334,7 +343,8 @@@ panel-behavior
node $(PANEL_TESTS)/launch-options.js $(OUT_DIR)/panel-emit && \
node $(PANEL_TESTS)/shell.js $(OUT_DIR)/panel-emit && \
node $(PANEL_TESTS)/migration.js $(OUT_DIR)/panel-emit && \
+ node $(PANEL_TESTS)/effective.js $(OUT_DIR)/panel-emit && \
+ node $(PANEL_TESTS)/localization.js $(OUT_DIR)/panel-emit && \
echo "==> panel behavior: renders as expected, no stale arguments"
CX_ROOT ?= /Applications/CrossOver Preview.app
diff --cc README.md
index e072f7d,6864fdb..e068d5c
--- a/README.md
+++ b/README.md
@@@ -32,48 -5,25 +32,50 @@@ NotProton enables the Steam Play experi
This is done by forcibly enabling the Steam Play functionality in macOS Steam (which is
present and inert) as well as by porting some components of Valve's Proton to macOS.
- This tool is intended to be used with Steam Client 1788652215 or 1790121765 and **CrossOver 26.3 or CrossOver Preview
- 20261006 or 2026082**. Both the FEX and the Rosetta versions are supported. I recommend using the FEX version of the
+ This tool is intended to be used with the stable Steam Client (version 1788652215) as well as the beta Steam Client (version 1791686101) paired with **CrossOver 26.3 or CrossOver Preview
+ 20261006 or 2026082**, with more supported versions to come.
+
+ Supporting specifically CrossOver is a design goal of this project. Better support for modifying CrossOver (using custom builds of DXMT/patched D3DMetal/MacGameVideoFix) will come in a future update, but support for alternatives to CrossOver itself is not planned.
+
+ Both the FEX and the Rosetta versions are supported. I recommend using the FEX version of the
Preview 20261006, as it includes both the FEX version as well as the Rosetta one.
+ I further recommend going into Steam Settings - Compatibility and selecting the Rosetta version as your default compatibility tool. You can select FEX on a per game basis by right clicking a game in Steam, going into Properties - Compatibility and selecting FEX there.
+
+ If a game has a native macOS version as well as a Windows one, Steam will download the macOS version. To override this behavior, right click on the game, select Properties, select Compatibility. Enable 'Force the use of a specific Steam Play compatibility tool'. Select whichever version of CrossOver you want to do use. That will make Steam download the Windows version. Unchecking the 'Force the use...' box or selecting 'No Compatibility Tool' in the drop down list will revert to the macOS version of the game, with the specifics there varying based on your Steam version.
+
+ **Valve Anti-Cheat is not supported.** Proton itself does not support VAC in Valve titles; Valve ships native Linux ports instead. VAC titles will launch in Insecure Mode and will not allow matchmaking.
+
-**This project now has a brew cask.** For brew users, you can install via ``brew install --cask notprotonnot/notproton/notproton``
+## 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) (master `e94c312`, LGPL-2.1+,
+ see `docs/DXMT.md`), 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 needs
+ CrossOver's Wine changes, so this engine does not use it; the WineCX engine can, with a Game
+ Porting Toolkit you supply (`docs/WINECX.md`).
+- 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`.
- I recommend going into Steam Settings - Compatibility and selecting the Rosetta version as your default compatibility tool, selecting FEX on a per game basis by right clicking a game in Steam, going into Properties - Compatibility and selecting FEX there.
+ Please read NOTICE for license information.
- As far as the source structure goes, 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's
- steam-helper from Proton 9. ntdll-patch patches the copy of CrossOver that the app
- makes/places in the ```~/Library/Application Support/notproton/runners/``` folder so that
- lsteamclient is loaded.
-
- Written documentation is quite sparse, I intend to write more today. Please read NOTICE for license information.
-
- Please open issue reports with any issues. PRs are welcome and encouraged. Contributions policy to come shortly.
+ Please open issue reports with any issues. PRs are welcome and encouraged.
There are many people who worked on similar ideas, similar projects. I did not base NotProton on their work, but I still want to
give thanks to the people who came before me:
diff --cc app/Sources/NotProtonApp/Model/FreeEngine.swift
index 4bca13e,0000000..fcdccff
mode 100644,000000..100644
--- a/app/Sources/NotProtonApp/Model/FreeEngine.swift
+++ b/app/Sources/NotProtonApp/Model/FreeEngine.swift
@@@ -1,393 -1,0 +1,393 @@@
+// 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
+ // arch/file -> sha256 of Wine's own file, which stays in lib/wine untouched.
+ let stock: [String: String]
+ // DXVK-macOS, staged beside DXMT for games that do better on it.
+ let dxvk: BackendRelease
+}
+
+// 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. Both free engines take
+// the same build: DXMT master e94c312 (https://github.com/3Shain/dxmt/tree/e94c312f5c054263acf261cfa109edf13e757587),
+// LGPL-2.1-or-later since ec357fd (v0.80 was the last MIT release), built by
+// scripts/build-dxmt.sh as docs/DXMT.md describes.
+struct RendererRelease: Sendable {
+ let name: String
+ let archive: String
+ let sha256: String
+ let bases: [URL]
+ let tree: String
+ // Path inside the archive tree -> sha256 as shipped. The winemetal pair goes into
+ // lib/wine, where the unix half and its PE stub are found by the loader; the D3D DLLs
+ // go to FreeEngine.dxmtDirectory, so lib/wine keeps Wine's own.
+ let files: [String: String]
+ // The D3D DLLs again, path -> sha256 once FreeEngine.stripBuiltinMarker has run. The
+ // launcher copies them into a prefix as natives, and Wine swaps any file carrying the
+ // builtin marker for the lib/wine builtin of the same name (load_builtin in
+ // dlls/ntdll/unix/loader.c), which would quietly run wined3d instead of DXMT.
+ let natives: [String: String]
+
+ static func isWinemetal(_ path: String) -> Bool {
+ path.hasSuffix("/winemetal.dll") || path.hasSuffix("/winemetal.so")
+ }
+
+ func installPath(of path: String) -> String {
+ Self.isWinemetal(path) ? "lib/wine/\(path)" : "\(FreeEngine.dxmtDirectory)/\(path)"
+ }
+
+ // The sha256 the file has once installed: the winemetal pair as shipped, the D3D DLLs
+ // with the builtin marker stripped.
+ func installedHash(of path: String) -> String? {
+ Self.isWinemetal(path) ? files[path] : natives[path]
+ }
+}
+
+// A set of D3D DLLs the launcher can swap in per game. Nothing here is loaded by default.
+struct BackendRelease: Sendable {
+ let name: String
+ let archive: String
+ let sha256: String
+ let bases: [URL]
+ let tree: String
+ // Path inside the archive tree -> sha256, installed at FreeEngine.dxvkDirectory/<path>.
+ 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: dxmt,
+ macDriver: "68d1c10cb4ec80beb2e97dcb8df5f81768f4f6e62848932d6bee5270dcf54982",
+ stock: [
+ "x86_64-windows/d3d10core.dll": "ff08e21a331e4160779ae140b0fd67c25f1557803b0f865467025a55e6133800",
+ "x86_64-windows/d3d11.dll": "66d08df71bdb897b55d6f5d12f44b90846dec362641baab2100c0cdf6615c809",
+ "x86_64-windows/d3d12.dll": "7dfa70d5b9ac50541c81801d8539be4cd31f37079ea1d93a495fe70c93f95d9a",
+ "x86_64-windows/dxgi.dll": "ed8d22612d121415063e54283e7284ae294a07a6b6d83b65dcd91abaadde2e49",
+ "i386-windows/d3d10core.dll": "7f9d10eaf361d7d7ad0a76fcedda037014184df9abe3ef0a65c4966a74bcd98d",
+ "i386-windows/d3d11.dll": "9f7a4f6ed76c75e902b8f27c45ba9a8d7cadb3205d3e4ab16a6f8a29aedfd30e",
+ "i386-windows/d3d12.dll": "501a94c7f2689f996b658ceee101b5b7bd44845dfc53a9336b4ece848ed343e1",
+ "i386-windows/dxgi.dll": "5e7310cc1c80650a467a4022e924d34ec07ce58933383ad06f530a61c82afc9d",
+ ],
+ // Gcenx's repack carries d3d10core and d3d11 only: it drops dxgi and d3d9 as
+ // unwanted on macOS, so DXVK games run on Wine's stock dxgi.
+ dxvk: BackendRelease(
+ name: "DXVK-macOS 1.10.3",
+ archive: "dxvk-macOS-async-v1.10.3-20230507-repack-builtin.tar.gz",
+ sha256: "810b1e5caf8ce975b784fae866a130ad23fa0ea233b0e5609cbc4a45f3ef6f00",
+ bases: [URL(string: "https://github.com/Gcenx/DXVK-macOS/releases/download/v1.10.3-20230507-repack")!],
+ tree: "dxvk-macOS-async-v1.10.3-20230507-repack-builtin",
+ files: [
+ "x86_64-windows/d3d10core.dll": "225562562050d9fae1d4d5d2ca0537020bac268c80dec9aa0633dc0d338a2840",
+ "x86_64-windows/d3d11.dll": "173980cb6c51fdd53dc37b9a17f0de7c5dfdebda18f52059aa7d5a6f1871299c",
+ "i386-windows/d3d10core.dll": "9e0202437af13a6d0acdb992954321f00a641b2eb98897908c41635ffddc1fc8",
+ "i386-windows/d3d11.dll": "2173b081a8660dd70a089dac875a829da6cd1a6230b23fd1daa2a7d7baa1cb03",
+ ]
+ )
+ )
+
+ // Shared by both free engines. Hosted on NotProton's own release, since upstream
+ // publishes no build of master; the per-file hashes are in docs/DXMT.md. d3d12.dll
+ // (x86_64-windows-d3d12/ in the tarball) is the unfinished backend and is never staged.
+ static let dxmt = RendererRelease(
+ name: "DXMT e94c312",
+ archive: "dxmt-e94c312.tar.gz",
+ sha256: "8de0d5b7eb2b96315f6ec8e259c05423ab43212e776196147b30d9f44927f7f0",
+ bases: [URL(string: "https://github.com/raymondchins/NotProton-WineHQ/releases/download/dxmt-e94c312")!],
+ tree: "e94c312",
+ // 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": "1d0a1258cbb696e1323d1fde77ebef7fedf5ea32a554bb777a9916321dedc195",
+ "x86_64-windows/d3d10core.dll": "14fef5785b9c83ab1d440d9d8de9d2d875420b9ae468c282737fcd44bb75336b",
+ "x86_64-windows/d3d11.dll": "f2ee8959c19548fb66c5b2a3802ff84967107d2faa3391bafb38c1363ece8a8b",
+ "x86_64-windows/dxgi.dll": "75436305876c11f4b7e8535fc32b0007e157b062dbd1534c1757c310a44bd99e",
+ "x86_64-windows/winemetal.dll": "33dd95086ab29ed03f876c47589b04a1e4a5891c6cbb5af6129309414aa8b0f7",
+ "i386-windows/d3d10core.dll": "7cbefea0f3b766024b85413ec75a2cc32e0431bbcc5f966b0b7515b4d785f3e7",
+ "i386-windows/d3d11.dll": "842b5a3868230e1b3eb829581b362f4ff56c86b318a3ce5b5307fa071485b58d",
+ "i386-windows/dxgi.dll": "51d01ce7f2b9edacaaa3490d838a95bf060ff04db7f42fe746cb62174c484bca",
+ "i386-windows/winemetal.dll": "6ddeb053c5510cffafdabfd27c8a67950f2e37308e6b9f9d1a0c44b9119ac456",
+ ],
+ natives: [
+ "x86_64-windows/d3d10core.dll": "aeb43e1ca7d9f221b9f0070c8654fa3579fd767006272cf675a9113e27bc6e72",
+ "x86_64-windows/d3d11.dll": "c1c8c4779686990bf343162a8804dd2d1564b2a893e64e5ddcc7db5e76ce409e",
+ "x86_64-windows/dxgi.dll": "1bb4939ff43e676eac8b3f3cb0583985ab8f7b1a8e11760d14931da3fc44223b",
+ "i386-windows/d3d10core.dll": "e851c39641f66d64a3e4460e7046900cd234b11f44d793826d2f094e9d2166d9",
+ "i386-windows/d3d11.dll": "a654ea3851ccc128a1f33d978462872e22fa6430ea85eff6ba9549de95788652",
+ "i386-windows/dxgi.dll": "91f38df103412235793f84efe06b87f6f6fc3a4791d4f8d9f8cc2e16bc137d53",
+ ]
+ )
+
+ static let macDriverPath = "lib/wine/x86_64-unix/winemac.so"
+
+ // Wine keeps its own dxgi, d3d11 and d3d10core in lib/wine. The launcher picks a
+ // backend per game from these, so no game is forced onto one by the engine itself.
+ static let backendsDirectory = "lib/notproton-backends"
+ static let dxmtDirectory = "\(backendsDirectory)/dxmt"
+ static let dxvkDirectory = "\(backendsDirectory)/dxvk"
+
+ 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)
+ }
+
+ // Every file the engine should carry, relative to its root, with its sha256: Wine's
+ // stock D3D DLLs, DXMT's winemetal pair, both backends and the patched winemac.so.
+ static func expectedFiles(_ release: FreeEngineRelease = current) -> [String: String] {
+ var table: [String: String] = [macDriverPath: release.macDriver]
+ for (path, hash) in release.stock { table["lib/wine/\(path)"] = hash }
+ for path in release.renderer.files.keys {
+ table[release.renderer.installPath(of: path)] = release.renderer.installedHash(of: path)
+ }
+ for (path, hash) in release.dxvk.files { table["\(dxvkDirectory)/\(path)"] = hash }
+ return table
+ }
+
+ // Files that are absent or differ from the pinned hash.
+ static func layoutProblems(root: URL, release: FreeEngineRelease = current) -> [String] {
+ expectedFiles(release).filter { path, hash in
+ Digest.sha256IfPresent(root.appending(path: path)) != hash
+ }.keys.sorted()
+ }
+
+ // An engine unpacked before the backends were split out still runs, but it needs
+ // the new layout before the launcher can choose a renderer per game.
+ static func hasRenderer(root: URL, release: FreeEngineRelease = current) -> Bool {
+ layoutProblems(root: root, release: release).isEmpty
+ }
+
+ // The first layout baked DXMT's dxgi, d3d11 and d3d10core over Wine's in lib/wine.
+ static func hasLegacyLayout(root: URL, release: FreeEngineRelease = current) -> Bool {
+ release.renderer.files.contains { path, hash in
+ !RendererRelease.isWinemetal(path)
+ && Digest.sha256IfPresent(root.appending(path: "lib/wine/\(path)")) == hash
+ }
+ }
+
+ // 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 {
+ try installMacDriver(root: root, build: release.build, sha256: release.macDriver, step: step)
+ }
+
+ // Puts the bundled winemac-<build>.so, checked against its pin, over the engine's own.
+ static func installMacDriver(root: URL, build: String, sha256: String, step: String) throws {
+ guard let source = Bundle.module.url(forResource: "winemac-\(build)", withExtension: "so"),
+ Digest.sha256IfPresent(source) == sha256
+ else {
+ throw StepFailure(step: step, detail: "NotProton is missing its winemac.so for \(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",
++ into: downloads, step: step, from: "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",
++ into: downloads, step: step, from: "GitHub",
+ report: { report(.downloading($0)) }
+ )
+ let dxvk = try await PinnedDownload.obtain(
+ file: release.dxvk.archive, sha256: release.dxvk.sha256, bases: release.dxvk.bases,
- into: downloads, step: step, source: "GitHub",
++ into: downloads, step: step, from: "GitHub",
+ report: { report(.downloading($0)) }
+ )
+ report(.unpacking)
+ // The engine is always rebuilt from the pinned archives, so an engine from the
+ // first layout (DXMT over Wine's DLLs) is replaced rather than patched in place.
+ return try unpack(archive, renderer: renderer, dxvk: dxvk, release: release, engines: engines)
+ }
+
+ static func unpack(
+ _ archive: URL, renderer: URL?, dxvk: URL? = nil, 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)
+ try installRenderer(release.renderer, from: tree, root: root, step: step)
+ try installMacDriver(root: root, release: release)
+ }
+
+ if let dxvk {
+ try untar(dxvk, into: extracted)
+ let tree = extracted.appending(path: release.dxvk.tree, directoryHint: .isDirectory)
+ for (path, hash) in release.dxvk.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.dxvk.archive) has no pinned \(path).")
+ }
+ try place(source, at: root.appending(path: "\(dxvkDirectory)/\(path)"))
+ }
+ }
+
+ // 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)
+ }
+
+ // Lays the renderer out under root: the winemetal pair as shipped into lib/wine, the
+ // D3D DLLs with the builtin marker stripped into dxmtDirectory. Every file is checked
+ // against its pin before and after, so a winemetal from another build never lands
+ // beside these DLLs (they share one unix-call table).
+ static func installRenderer(_ renderer: RendererRelease, from tree: URL, root: URL, step: String) throws {
+ for (path, hash) in 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: "\(renderer.archive) has no pinned \(path).")
+ }
+ let destination = root.appending(path: renderer.installPath(of: path))
+ if RendererRelease.isWinemetal(path) {
+ try place(source, at: destination)
+ continue
+ }
+ var image = try Data(contentsOf: source)
+ try stripBuiltinMarker(&image)
+ guard Digest.sha256(of: image) == renderer.natives[path] else {
+ throw StepFailure(step: step, detail: "\(path) from \(renderer.archive) does not match its native pin.")
+ }
+ try FileManager.default.createDirectory(
+ at: destination.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try? FileManager.default.removeItem(at: destination)
+ try image.write(to: destination)
+ }
+ }
+
+ static let builtinMarker = Array("Wine builtin DLL".utf8) + [0]
+ // The bytes winecx-gptk writes over the marker (a plain DOS stub), so DXMT 0.80 stripped
+ // here hashes the same as the copy in the WineCX archive.
+ static let dosStub: [UInt8] = [0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
+ 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x90, 0x90]
+
+ // Wine reads the 17 bytes at 0x40 as the builtin marker. Without it the DLL is an
+ // ordinary native, which is what a per-game backend in a prefix has to be.
+ static func stripBuiltinMarker(_ image: inout Data) throws {
+ let start = image.startIndex
+ guard image.count > 0x51, image[start] == 0x4d, image[start + 1] == 0x5a,
+ Array(image[(start + 0x40) ..< (start + 0x51)]) == builtinMarker
+ else {
+ throw StepFailure(step: step, detail: "A DXMT DLL does not carry the Wine builtin marker.")
+ }
+ image.replaceSubrange((start + 0x40) ..< (start + 0x50), with: dosStub)
+ }
+
+ private static func place(_ source: URL, at destination: URL) throws {
+ let fm = FileManager.default
+ try fm.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try? fm.removeItem(at: destination)
+ try fm.copyItem(at: source, to: destination)
+ }
+
+ 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 --cc app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift
index 77b9239,0000000..f170315
mode 100644,000000..100644
--- a/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift
+++ b/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift
@@@ -1,509 -1,0 +1,509 @@@
+// The second free engine: WineCX, CodeWeavers' LGPL CrossOver 26.3 Wine changes rebased
+// onto upstream Wine by dappermint (github.com/dappermint/winecx) and built into a Whisky
+// runtime by dappermint/winecx-gptk's CI. The current release is Wine 11.17; the 11.15 one
+// stays installable and selectable beside it. Over the WineHQ engine it adds
+// msync and the CrossOver hooks Apple's D3DMetal needs. DXMT (the same master build as the
+// WineHQ engine, not the archive's 0.80) and DXVK are backends a game opts into; Wine's own
+// Direct3D, or D3DMetal once a user's Game Porting Toolkit is linked, is the builtin.
+// 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
+}
+
+// A file NotProton ships in its own bundle and lays into the engine, checked against its pin.
+struct WinecxBundledFile: Sendable, Equatable {
+ // Resource name and extension in the app bundle.
+ let resource: String
+ let ext: String
+ // Path below the engine root.
+ let path: 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
+ // DXVK, copied out of the archive. The archive's DXMT 0.80 is not used.
+ let backends: [WinecxBackendFile]
+ // DXMT, from its own tarball: the D3D DLLs as natives under lib/notproton-backends/dxmt,
+ // the winemetal pair over the archive's in lib/wine.
+ let renderer: RendererRelease
+ // lib/wine/x86_64-windows/<name> -> sha256 of Wine's own copy, for the four DLLs a linked
+ // Game Porting Toolkit replaces (WinecxD3DMetal.forwarders).
+ let d3dStock: [String: String]
+ // sha256 of the winemac.so NotProton ships for this build: winecx's own with
+ // winemac-patch/winecx-d3dmetal-retina.patch, so D3DMetal sizes a Retina-mode
+ // swapchain in Win32 pixels rather than points.
+ let macDriver: String
+ // Controller support. The runtime's CI built winebus.so without SDL2, so a controller
+ // only reached Wine through the IOHID bus, as a raw HID device XInput does not open.
+ // NotProton ships winecx's winebus.so rebuilt with SDL2 and the x86_64 libSDL2 it
+ // dlopens by leaf name, which dyld finds through winebus.so's @loader_path/../../
+ // rpath, i.e. in lib/.
+ let gamepad: [WinecxBundledFile]
+ // ws2_32 rebuilt so getaddrinfo on this machine's own host name drops the loopback and
+ // link-local addresses macOS lists first, as Windows never returns them
+ // (ws2_32-patch/). Empty where the runtime's own ws2_32 is kept.
+ let network: [WinecxBundledFile]
+ // The runner build this release unpacks to, keyed by its pinned loader, and the ntdll
+ // detours for it (NtdllPatcher.byBuild).
+ let runner: RunnerBuild
+ let ntdllPatches: [NtdllPatch]
+}
+
+enum FreeEngineWinecx {
+
+ static let step = "Download free WineCX engine"
+
+ // What the WineCX row installs. It gets its own tool, notproton-winecx-11.17, beside
+ // the 11.15 release, which keeps notproton-winecx: every existing prefix is claimed by
+ // winecx-11.15, so the default tool only moves once 11.17 is verified on real games.
+ static let current = v1117
+ static let previous = v1115
+ static let releases = [current, previous]
+
+ // The runner build of the current release.
+ static var runnerBuild: RunnerBuild { current.runner }
+ static var ntdllPatches: [NtdllPatch] { current.ntdllPatches }
+ static var runnerBuilds: [RunnerBuild] { releases.map(\.runner) }
+
+ static func release(build id: String) -> WinecxRelease? {
+ releases.first { $0.build == id }
+ }
+
+ // The release whose pinned loader a tree carries, which is what makes it that WineCX.
+ static func release(forRoot root: URL) -> WinecxRelease? {
+ let loader = Clean.copy(of: CrossOverSource.unixLoader(inRoot: root))
+ guard let hash = Digest.sha256IfPresent(loader) else { return nil }
+ return releases.first { $0.runner.loaderSHA256 == hash }
+ }
+
+ // DXVK-macOS 1.10.3 is the same repack in both runtimes. nvapi64 and nvngx are left out
+ // for the reason FreeEngine gives. The repack ships no dxgi, and its DLLs carry no
+ // builtin marker.
+ private static let dxvk: [WinecxBackendFile] = [
+ 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"),
+ ]
+
+ // SDL 2.32.10 (zlib license, NOTICE) built x86_64 with winemac-patch/sdl2-iokit-gamepad-collection.patch
+ // (pads whose gamepad is a secondary HID collection, e.g. GameSir G7 Pro over Bluetooth),
+ // signed ad hoc, since a release build strips unsigned Mach-O resources and would break the pin.
+ private static let sdl = WinecxBundledFile(
+ resource: "libSDL2-2.0.0", ext: "dylib", path: "lib/libSDL2-2.0.0.dylib",
+ sha256: "aeeec088bf51f9eac0dbd8e26ae994c7b8568fb42fc676835d6dc2109fc559d1")
+
+ // runtime 4.7.3: winecx e0aa380 (Wine 11.17), built by winecx-gptk 0bf3eab, minos 26.0.
+ // Over 4.5.125 it carries the later msync fixes, kernelbase's FlsGetValue2 for Unity
+ // 6000.3, dxgi's CheckInterfaceSupport, the winemac client-view flush fix and the
+ // Wine 11.16 and 11.17 merges.
+ static let v1117 = WinecxRelease(
+ build: "winecx-11.17",
+ runtime: "4.7.3",
+ archive: "Libraries.tar.gz",
+ sha256: "a4b5d63493f80698cce5cad8e7212d9a51c8292037b00c478f4652636fcfd331",
+ bases: [
+ URL(string: "https://github.com/dappermint/winecx-gptk/releases/download/runtime-v4.7.3")!,
+ ],
+ bundleName: "WineCX 11.17.app",
+ wineTree: "Libraries/Wine",
+ backends: dxvk,
+ renderer: FreeEngine.dxmt,
+ d3dStock: [
+ "d3d10.dll": "9a9efe0cdaad2f41b0c5fe0f216c97720cdf82b21fbbb6e59f361112cdc4ccc3",
+ "d3d11.dll": "0a3d9e758a491c99d34dce1aa4ee744671d1faeef498c6dfc5d26eecb9dff7ec",
+ "d3d12.dll": "974e132bcafb150bb97f33fa63199346a3b942b3e09d6d06c0cbc1755f30afa5",
+ "dxgi.dll": "6f7cf2d60c991ad26b60316935bb9d3587b0c83cc01991bf55564bcfbfa47e09",
+ ],
+ macDriver: "aa192f846ad15d56de200fc92752eaf2d455700846ae2cf1ccc7b27b535f1c00",
+ // winebus.so: winecx e0aa380 built with SONAME_LIBSDL2. winebus.sys: the same tree's
+ // PE half with sdl_bus_load_mappings fixed (winebus-patch/), so a winebus "map" key
+ // no longer writes past the array and takes every pad down with it.
+ gamepad: [
+ WinecxBundledFile(resource: "winebus-winecx-11.17", ext: "so", path: "lib/wine/x86_64-unix/winebus.so",
+ sha256: "6223c035c824c90708abbc3e733f8d1d6ed6b8b4e9a3e1a5c813493ceba50473"),
+ WinecxBundledFile(resource: "winebus-winecx-11.17", ext: "sys",
+ path: "lib/wine/x86_64-windows/winebus.sys",
+ sha256: "da108d1c3788fa32807ef08c4d26d8a89812c230317ffa7ba5111e126bda607c"),
+ sdl,
+ ],
+ // ws2_32.dll: winecx e0aa380's PE half with ws2_32-patch/winecx-own-hostname.patch.
+ network: [
+ WinecxBundledFile(resource: "ws2_32-winecx-11.17", ext: "dll",
+ path: "lib/wine/x86_64-windows/ws2_32.dll",
+ sha256: "cb0a5670ce6dbf949ed25cca54e9f1c4930cd4c2ade895836d518d3d9073079c"),
+ ],
+ runner: RunnerBuild(
+ bundleVersion: "winecx-11.17",
+ releaseVersion: "WineCX 11.17",
+ flavor: nil,
+ loaderSHA256: "a680abba30b4888355adb39d8b62255e43546eb33d163897260627f7741ef648",
+ cleanNtdll: [
+ .x86_64Windows: "8b32c9f6f71b4f15fcaccb19b0f2adab9391ae73ad539cae9e136f8ee7d24128",
+ .i386Windows: "cc8a9035cea0e26c5d333ef220f1becefc27ae44d2cdcdaea3278e8739d26fd9",
+ ],
+ patchedNtdll: [
+ .x86_64Windows: "4573d521671a48212670e7543aa9ebf0921e383dada69477f677f435df2bef5a",
+ .i386Windows: "8ad83740df2da5e79ed435e4bc57e82b4b6a4b984fbec73e1160ca81dfce1b44",
+ ],
+ tools: [
+ CompatTool(name: "notproton-winecx-11.17", flavor: .rosetta, display: "WineCX 11.17 (msync, D3DMetal)"),
+ ],
+ isFree: true
+ ),
+ ntdllPatches: [
+ // From ntdll-patch/resolve.py on the archive's ntdlls, payloads from build.sh and
+ // build32.sh with the variant winecx-11.17. Both detours fit in .text padding.
+ NtdllPatch(
+ arch: .x86_64Windows,
+ payloadResource: "detour2-winecx-11.17",
+ payloadSHA256: "e1bbd185b19de3e23d627ae3a8bf25ed1b767bff5690102c5312a5ed3813e736",
+ caveRVA: 0x83360,
+ payloadRVA: 0x83360,
+ hooks: [
+ NtdllHook(rva: 0x52de3,
+ stolen: [0x48, 0x83, 0xbc, 0x24, 0xf0, 0x00, 0x00, 0x00, 0x00]),
+ ],
+ caveSize: 3232,
+ cavePad: 0x00,
+ machine: 0x8664,
+ magic: 0x20b,
+ imageBase: 0x1_7000_0000
+ ),
+ NtdllPatch(
+ arch: .i386Windows,
+ payloadResource: "detour32-winecx-11.17",
+ payloadSHA256: "0676104e0bd56c4a1e8c473d9cbcd21fb2ba105fc7dc6cf5a70d37692c129e28",
+ caveRVA: 0x808a0,
+ payloadRVA: 0x808a0,
+ hooks: [
+ NtdllHook(rva: 0x4f880, stolen: [0xf6, 0x45, 0xb4, 0x02, 0x75, 0x29]),
+ ],
+ caveSize: 1888,
+ cavePad: 0x00,
+ machine: 0x14c,
+ magic: 0x10b,
+ imageBase: 0x7bc0_0000
+ ),
+ ]
+ )
+
+ // runtime 4.5.125 is the last wine1115 build (winecx 5b45f45, built from winecx-gptk
+ // 7a0349b, minos 26.0). The same bytes are mirrored on dappermint/Whisky, which is what
+ // Whisky itself downloads. It keeps the notproton-winecx tool.
+ static let v1115 = 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",
+ backends: dxvk,
+ // winecx's winemac.so already exports the macdrv_functions DXMT reads, and that
+ // table is unchanged between 0.80 and master, so DXMT needs no winemac-patch.
+ renderer: FreeEngine.dxmt,
+ d3dStock: [
+ "d3d10.dll": "bcbd3fb8a59a5992bd3035babc5c046327f19cdc0669ce9e7c438c3ce3a9546d",
+ "d3d11.dll": "84f5a337fdd7405bbbee5f0542427842a22aff749a3d061ba6334f10cf01dee4",
+ "d3d12.dll": "c6e285308bb3241efca3d94da4746b16a526a9fb5113f61922e7bd86694bebf9",
+ "dxgi.dll": "f1f24da777c65a583b29f74475c6a9464da35068d75def6cee806268def9ecbb",
+ ],
+ macDriver: "76d8f93839386f37e8badf0c82bb31b5ead22ac580f17896f9d2a729af0fc147",
+ // winebus.so: winecx 5b45f45 built with SONAME_LIBSDL2 (docs/WINECX.md).
+ gamepad: [
+ WinecxBundledFile(resource: "winebus-winecx-11.15", ext: "so", path: "lib/wine/x86_64-unix/winebus.so",
+ sha256: "1bc53184f5d026ab84a26cf6ef721348fc3b028c019ff969e69eb6cf9b9d1af9"),
+ sdl,
+ ],
+ network: [],
+ // The hash-pinned loader is what makes it free, so a CrossOver install can never be
+ // taken for it.
+ runner: 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
+ ),
+ // 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.
+ ntdllPatches: [
+ 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, whose Direct3D builtins are Wine's own or, with
+ // d3dmetal.enabled, Apple's (WinecxD3DMetal).
+ static let backendsPath = "lib/notproton-backends"
+ static let msyncMarkerPath = ".notproton-msync"
+
+ static func downloads(for release: WinecxRelease = current) -> URL {
+ SupportPaths.home.appending(
+ path: "Library/Caches/\(SupportPaths.supportDirName)/engines/winecx-\(release.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 {
+ layoutProblems(root: root, release: release).isEmpty
+ }
+
+ // Every pinned file NotProton lays out, relative to the engine root, with its sha256. The
+ // four Direct3D DLLs D3DMetal can replace are not in here: WinecxD3DMetal.layoutProblems
+ // checks them, since they are either Wine's own or links into a Game Porting Toolkit.
+ static func expectedFiles(_ release: WinecxRelease = current) -> [String: String] {
+ var table: [String: String] = [FreeEngine.macDriverPath: release.macDriver]
+ for file in release.gamepad + release.network { table[file.path] = file.sha256 }
+ for file in release.backends { table["\(backendsPath)/\(file.destination)"] = file.sha256 }
+ for path in release.renderer.files.keys {
+ table[release.renderer.installPath(of: path)] = release.renderer.installedHash(of: path)
+ }
+ return table
+ }
+
+ // Files that are absent or differ from their pin, the msync marker, and a Direct3D
+ // layout that is neither stock nor a complete D3DMetal link.
+ static func layoutProblems(root: URL, release: WinecxRelease = current) -> [String] {
+ var problems = expectedFiles(release).filter { path, hash in
+ Digest.sha256IfPresent(root.appending(path: path)) != hash
+ }.keys.sorted()
+ if !FileManager.default.fileExists(atPath: msyncMarker(in: root).path(percentEncoded: false)) {
+ problems.append(msyncMarkerPath)
+ }
+ return problems + WinecxD3DMetal.layoutProblems(root: root, stock: release.d3dStock)
+ }
+
+ 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(for: release), step: step, source: "GitHub",
++ into: downloads(for: release), step: step, from: "GitHub",
+ report: { report(.downloading($0)) }
+ )
+ let renderer = try await PinnedDownload.obtain(
+ file: release.renderer.archive, sha256: release.renderer.sha256, bases: release.renderer.bases,
- into: FreeEngine.downloads, step: step, source: "GitHub",
++ into: FreeEngine.downloads, step: step, from: "GitHub",
+ report: { report(.downloading($0)) }
+ )
+ report(.unpacking)
+ return try unpack(archive, renderer: renderer, release: release, engines: engines)
+ }
+
+ // Without a renderer archive (tests only) the engine gets no DXMT and does not count
+ // as installed.
+ static func unpack(
+ _ archive: URL,
+ renderer: 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)
+ try FreeEngine.installMacDriver(root: root, build: release.build, sha256: release.macDriver, step: step)
+ try installBundled(release.gamepad + release.network, root: 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)
+ }
+ // The archive's own DXMT 0.80 frontends stay out, and its winemetal pair is replaced
+ // with master's: the two halves share one unix-call table and never mix versions.
+ if let renderer {
+ let unpacked = staging.appending(path: "renderer", directoryHint: .isDirectory)
+ try fm.createDirectory(at: unpacked, withIntermediateDirectories: true)
+ try untar(renderer, into: unpacked)
+ try FreeEngine.installRenderer(
+ release.renderer, from: unpacked.appending(path: release.renderer.tree, directoryHint: .isDirectory),
+ root: root, step: step)
+ }
+ 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 keeps Wine's own Direct3D and 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)
+ }
+
+ // Puts each bundled file, checked against its pin, over or beside the engine's own.
+ static func installBundled(_ files: [WinecxBundledFile], root: URL) throws {
+ let fm = FileManager.default
+ for file in files {
+ guard let source = Bundle.module.url(forResource: file.resource, withExtension: file.ext),
+ Digest.sha256IfPresent(source) == file.sha256
+ else {
+ throw StepFailure(step: step, detail: "NotProton is missing its \(file.resource).\(file.ext).")
+ }
+ let destination = root.appending(path: file.path)
+ try fm.createDirectory(at: destination.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try? fm.removeItem(at: destination)
+ try fm.copyItem(at: source, to: destination)
+ }
+ }
+
+ 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 --cc app/Sources/NotProtonApp/Model/RunnerSetup.swift
index 609afb5,8708617..5be58d2
--- a/app/Sources/NotProtonApp/Model/RunnerSetup.swift
+++ b/app/Sources/NotProtonApp/Model/RunnerSetup.swift
@@@ -12,10 -12,10 +12,10 @@@ enum RunnerSetup
var label: String {
switch self {
- case .cloning: "Copying Wine"
- case .staging: "Patching"
- case .patching: "Installing compatibility tool"
- case .finished: "Done"
- case .cloning: String(localized: "Copying CrossOver")
++ case .cloning: String(localized: "Copying Wine")
+ case .staging: String(localized: "Patching")
+ case .patching: String(localized: "Installing compatibility tool")
+ case .finished: String(localized: "Done")
}
}
}
diff --cc app/Sources/NotProtonApp/SystemStatus.swift
index 06f99d5,f15e27c..11e6c93
--- a/app/Sources/NotProtonApp/SystemStatus.swift
+++ b/app/Sources/NotProtonApp/SystemStatus.swift
@@@ -391,7 -341,7 +391,7 @@@ final class SystemStatus
private func setUpRunner(from install: CrossOverInstall?, replacingExisting: Bool = false) async {
guard let install else {
- setFailure("No supported Wine engine found. Download the free WineHQ or WineCX engine first.")
- setFailure(String(localized: "No supported copy of CrossOver found."))
++ setFailure(String(localized: "No supported Wine engine found. Download the free WineHQ or WineCX engine first."))
AppLog.note("run refused: no supported CrossOver")
outcome = nil
return
diff --cc app/Sources/NotProtonApp/Views/StatusView.swift
index 0249779,51dcac6..3d42a26
--- a/app/Sources/NotProtonApp/Views/StatusView.swift
+++ b/app/Sources/NotProtonApp/Views/StatusView.swift
@@@ -531,9 -523,8 +523,8 @@@ struct StatusView: View
let rows = status.crossOverRows
if rows.isEmpty {
StatusRow(
- title: "CrossOver",
- value: String(localized: "Not found. Supported: \(SupportedRunners.versionList)."),
+ title: "Wine Engine",
- value: "None found. Download the free WineHQ or WineCX engine, or use CrossOver "
- + "(\(SupportedRunners.versionList)).",
++ value: String(localized: "None found. Download the free WineHQ or WineCX engine, or use CrossOver (\(SupportedRunners.versionList))."),
tone: .bad
)
}
diff --cc app/Tests/NotProtonAppTests/FreeEngineTests.swift
index 06ee819,0000000..96c45ba
mode 100644,000000..100644
--- a/app/Tests/NotProtonAppTests/FreeEngineTests.swift
+++ b/app/Tests/NotProtonAppTests/FreeEngineTests.swift
@@@ -1,341 -1,0 +1,341 @@@
+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).contains(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 dxvkArchive = FreeEngine.downloads.appending(path: FreeEngine.current.dxvk.archive)
+ let haveRenderer = Digest.sha256IfPresent(renderer) == FreeEngine.current.renderer.sha256
+ && Digest.sha256IfPresent(dxvkArchive) == FreeEngine.current.dxvk.sha256
+ let install = try FreeEngine.unpack(
+ archive, renderer: haveRenderer ? renderer : nil, dxvk: haveRenderer ? dxvkArchive : 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(!FreeEngine.hasLegacyLayout(root: install.crossOverRoot))
+ if haveRenderer { #expect(FreeEngine.layoutProblems(root: install.crossOverRoot).isEmpty) }
+ #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])
+ }
+ }
+
+ private func touch(_ root: URL, _ path: String, _ text: String) throws {
+ let url = root.appending(path: path)
+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data(text.utf8).write(to: url)
+ }
+
+ // Builds a tree whose files hash to whatever the test hands in.
+ private func release(table: [String: String]) -> FreeEngineRelease {
+ FreeEngineRelease(
+ build: "t", archive: "a", sha256: "", bases: [], bundleName: "T.app", wineTree: "w",
+ renderer: RendererRelease(
+ name: "r", archive: "r", sha256: "", bases: [], tree: "r",
+ files: ["x86_64-windows/d3d11.dll": table["dxmt-shipped"] ?? table["dxmt-d3d11"]!,
+ "x86_64-windows/winemetal.dll": table["winemetal"]!],
+ natives: ["x86_64-windows/d3d11.dll": table["dxmt-d3d11"]!]),
+ macDriver: table["mac"]!,
+ stock: ["x86_64-windows/d3d11.dll": table["stock-d3d11"]!],
+ dxvk: BackendRelease(
+ name: "d", archive: "d", sha256: "", bases: [], tree: "d",
+ files: ["x86_64-windows/d3d11.dll": table["dxvk-d3d11"]!])
+ )
+ }
+
+ private func hash(_ text: String) -> String { Digest.sha256(of: Data(text.utf8)) }
+
+ @Test("Layout paths keep Wine's D3D DLLs in lib/wine and put the backends beside it")
+ func layoutPaths() {
+ let r = FreeEngine.current.renderer
+ #expect(r.installPath(of: "x86_64-windows/winemetal.dll") == "lib/wine/x86_64-windows/winemetal.dll")
+ #expect(r.installPath(of: "i386-windows/winemetal.dll") == "lib/wine/i386-windows/winemetal.dll")
+ #expect(r.installPath(of: "x86_64-unix/winemetal.so") == "lib/wine/x86_64-unix/winemetal.so")
+ for name in ["dxgi", "d3d11", "d3d10core"] {
+ for arch in ["x86_64-windows", "i386-windows"] {
+ #expect(r.installPath(of: "\(arch)/\(name).dll")
+ == "lib/notproton-backends/dxmt/\(arch)/\(name).dll")
+ }
+ }
+ #expect(FreeEngine.dxvkDirectory == "lib/notproton-backends/dxvk")
+ }
+
+ @Test("The hash table covers stock Wine, DXMT, DXVK and the mac driver, with no overlap")
+ func hashTableCoverage() {
+ let release = FreeEngine.current
+ let table = FreeEngine.expectedFiles(release)
+ for arch in ["x86_64-windows", "i386-windows"] {
+ for name in ["dxgi", "d3d11", "d3d10core", "d3d12"] {
+ #expect(table["lib/wine/\(arch)/\(name).dll"] == release.stock["\(arch)/\(name).dll"])
+ }
+ for name in ["dxgi", "d3d11", "d3d10core"] {
+ #expect(table["lib/notproton-backends/dxmt/\(arch)/\(name).dll"] != nil)
+ }
+ for name in ["d3d11", "d3d10core"] {
+ #expect(table["lib/notproton-backends/dxvk/\(arch)/\(name).dll"] != nil)
+ }
+ #expect(table["lib/wine/\(arch)/winemetal.dll"] != nil)
+ }
+ #expect(table["lib/wine/x86_64-unix/winemetal.so"] != nil)
+ #expect(table[FreeEngine.macDriverPath] == release.macDriver)
+ #expect(table.count == release.stock.count + release.renderer.files.count + release.dxvk.files.count + 1)
+ // DXMT's D3D DLLs must differ from Wine's, or the migration check could not tell them apart.
+ for (path, hash) in release.renderer.files where !path.contains("winemetal") {
+ #expect(release.stock[path] != hash)
+ // Installed without the builtin marker, so the table pins the stripped copy.
+ #expect(table[release.renderer.installPath(of: path)] == release.renderer.natives[path])
+ }
+ }
+
+ @Test("Verification reports a tampered, missing or legacy file")
+ func detectsTampering() throws {
+ let root = try makeEngines()
+ defer { try? FileManager.default.removeItem(at: root) }
+ let r = release(table: [
+ "dxmt-d3d11": hash("dxmt"), "winemetal": hash("wm"), "mac": hash("mac"),
+ "stock-d3d11": hash("stock"), "dxvk-d3d11": hash("dxvk"),
+ ])
+ #expect(!FreeEngine.hasRenderer(root: root, release: r))
+
+ try touch(root, "lib/wine/x86_64-windows/d3d11.dll", "stock")
+ try touch(root, "lib/wine/x86_64-windows/winemetal.dll", "wm")
+ try touch(root, "lib/notproton-backends/dxmt/x86_64-windows/d3d11.dll", "dxmt")
+ try touch(root, "lib/notproton-backends/dxvk/x86_64-windows/d3d11.dll", "dxvk")
+ try touch(root, FreeEngine.macDriverPath, "mac")
+ #expect(FreeEngine.hasRenderer(root: root, release: r))
+ #expect(!FreeEngine.hasLegacyLayout(root: root, release: r))
+
+ try touch(root, "lib/wine/x86_64-windows/d3d11.dll", "tampered")
+ #expect(FreeEngine.layoutProblems(root: root, release: r) == ["lib/wine/x86_64-windows/d3d11.dll"])
+ try touch(root, "lib/wine/x86_64-windows/d3d11.dll", "stock")
+ try touch(root, "lib/notproton-backends/dxvk/x86_64-windows/d3d11.dll", "tampered")
+ #expect(!FreeEngine.hasRenderer(root: root, release: r))
+ try touch(root, "lib/notproton-backends/dxvk/x86_64-windows/d3d11.dll", "dxvk")
+ try FileManager.default.removeItem(at: root.appending(path: "lib/notproton-backends/dxmt"))
+ #expect(!FreeEngine.hasRenderer(root: root, release: r))
+ }
+
+ @Test("An engine with DXMT's DLLs baked into lib/wine is the old layout and no longer counts as installed")
+ func migrationDetection() throws {
+ let root = try makeEngines()
+ defer { try? FileManager.default.removeItem(at: root) }
+ let r = release(table: [
+ "dxmt-d3d11": hash("dxmt"), "winemetal": hash("wm"), "mac": hash("mac"),
+ "stock-d3d11": hash("stock"), "dxvk-d3d11": hash("dxvk"),
+ ])
+ try touch(root, "lib/wine/x86_64-windows/d3d11.dll", "dxmt")
+ try touch(root, "lib/wine/x86_64-windows/winemetal.dll", "wm")
+ try touch(root, FreeEngine.macDriverPath, "mac")
+ #expect(FreeEngine.hasLegacyLayout(root: root, release: r))
+ #expect(!FreeEngine.hasRenderer(root: root, release: r))
+ #expect(FreeEngine.layoutProblems(root: root, release: r).contains("lib/wine/x86_64-windows/d3d11.dll"))
+ // A stock engine that simply has no backends yet is not "legacy", only incomplete.
+ try touch(root, "lib/wine/x86_64-windows/d3d11.dll", "stock")
+ #expect(!FreeEngine.hasLegacyLayout(root: root, release: r))
+ }
+
+ @Test("DXVK is pinned to a GitHub release asset with a hash for every DLL, both architectures")
+ func dxvkPins() {
+ let dxvk = FreeEngine.current.dxvk
+ #expect(dxvk.bases.allSatisfy { $0.host() == "github.com" && $0.path().contains("Gcenx/DXVK-macOS") })
+ #expect(dxvk.sha256.count == 64)
+ #expect(dxvk.archive.hasSuffix(".tar.gz"))
+ #expect(Set(dxvk.files.keys) == [
+ "x86_64-windows/d3d10core.dll", "x86_64-windows/d3d11.dll",
+ "i386-windows/d3d10core.dll", "i386-windows/d3d11.dll",
+ ])
+ #expect(dxvk.files.values.allSatisfy { $0.count == 64 })
+ #expect(Set(dxvk.files.values).count == dxvk.files.count)
+ }
+
+ @Test("Runs against the real DXVK archive when cached")
+ func unpacksRealDxvk() throws {
+ let archive = FreeEngine.downloads.appending(path: FreeEngine.current.dxvk.archive)
+ guard Digest.sha256IfPresent(archive) == FreeEngine.current.dxvk.sha256 else { return }
+ let work = try makeEngines()
+ defer { try? FileManager.default.removeItem(at: work) }
+ let result = try Shell.run("/usr/bin/tar", ["-xf", archive.path(percentEncoded: false), "-C", work.path(percentEncoded: false)])
+ #expect(result.status == 0)
+ for (path, hash) in FreeEngine.current.dxvk.files {
+ #expect(Digest.sha256IfPresent(work.appending(path: "\(FreeEngine.current.dxvk.tree)/\(path)")) == hash)
+ }
+ }
+
+ @Test("DXMT is the pinned master build on NotProton's release, shared by both free engines")
+ func dxmtPins() {
+ let dxmt = FreeEngine.current.renderer
+ #expect(dxmt.archive == "dxmt-e94c312.tar.gz")
+ #expect(dxmt.sha256 == "8de0d5b7eb2b96315f6ec8e259c05423ab43212e776196147b30d9f44927f7f0")
+ #expect(dxmt.tree == "e94c312")
+ #expect(dxmt.bases.map(\.absoluteString)
+ == ["https://github.com/raymondchins/NotProton-WineHQ/releases/download/dxmt-e94c312"])
+ // docs/DXMT.md, minus nvapi64, nvngx and the WIP d3d12.
+ #expect(dxmt.files == [
+ "x86_64-unix/winemetal.so": "1d0a1258cbb696e1323d1fde77ebef7fedf5ea32a554bb777a9916321dedc195",
+ "x86_64-windows/d3d10core.dll": "14fef5785b9c83ab1d440d9d8de9d2d875420b9ae468c282737fcd44bb75336b",
+ "x86_64-windows/d3d11.dll": "f2ee8959c19548fb66c5b2a3802ff84967107d2faa3391bafb38c1363ece8a8b",
+ "x86_64-windows/dxgi.dll": "75436305876c11f4b7e8535fc32b0007e157b062dbd1534c1757c310a44bd99e",
+ "x86_64-windows/winemetal.dll": "33dd95086ab29ed03f876c47589b04a1e4a5891c6cbb5af6129309414aa8b0f7",
+ "i386-windows/d3d10core.dll": "7cbefea0f3b766024b85413ec75a2cc32e0431bbcc5f966b0b7515b4d785f3e7",
+ "i386-windows/d3d11.dll": "842b5a3868230e1b3eb829581b362f4ff56c86b318a3ce5b5307fa071485b58d",
+ "i386-windows/dxgi.dll": "51d01ce7f2b9edacaaa3490d838a95bf060ff04db7f42fe746cb62174c484bca",
+ "i386-windows/winemetal.dll": "6ddeb053c5510cffafdabfd27c8a67950f2e37308e6b9f9d1a0c44b9119ac456",
+ ])
+ #expect(!dxmt.files.keys.contains { $0.contains("d3d12") || $0.contains("nv") })
+ #expect(Set(dxmt.natives.keys) == Set(dxmt.files.keys.filter { !RendererRelease.isWinemetal($0) }))
+ #expect(FreeEngineWinecx.current.renderer.sha256 == dxmt.sha256)
+ #expect(FreeEngineWinecx.current.renderer.files == dxmt.files)
+ }
+
+ @Test("Stripping the builtin marker turns a builtin PE into a native one and refuses anything else")
+ func stripsBuiltinMarker() throws {
+ var image = Data(repeating: 0, count: 0x80)
+ image[0] = 0x4d
+ image[1] = 0x5a
+ image.replaceSubrange(0x40 ..< 0x51, with: FreeEngine.builtinMarker)
+ var stripped = image
+ try FreeEngine.stripBuiltinMarker(&stripped)
+ #expect(Array(stripped[0x40 ..< 0x50]) == FreeEngine.dosStub)
+ #expect(stripped.count == image.count)
+ #expect(stripped[0x50...] == image[0x50...])
+ #expect(!WinecxD3DMetal.isBuiltin(try write(stripped)))
+ #expect(WinecxD3DMetal.isBuiltin(try write(image)))
+ // Already native: refused, so a pin mismatch cannot be papered over.
+ #expect(throws: StepFailure.self) { try FreeEngine.stripBuiltinMarker(&stripped) }
+ }
+
+ private func write(_ data: Data) throws -> URL {
+ let url = FileManager.default.temporaryDirectory.appending(path: "np-pe-\(UUID().uuidString).dll")
+ try data.write(to: url)
+ return url
+ }
+
+ // Downloads the real tarball into NotProton's engine cache (where the app and the other
+ // real-archive tests look for it) unless it is already there. NOTPROTON_OFFLINE=1 skips
+ // the download, and the test then runs only against a cached copy.
+ @Test("The real DXMT master tarball downloads, matches every pin and installs as natives")
+ func downloadsAndUnpacksRealDxmt() async throws {
+ let dxmt = FreeEngine.current.renderer
+ let cached = FreeEngine.downloads.appending(path: dxmt.archive)
+ if Digest.sha256IfPresent(cached) != dxmt.sha256,
+ ProcessInfo.processInfo.environment["NOTPROTON_OFFLINE"] == "1" { return }
+ let archive = try await PinnedDownload.obtain(
+ file: dxmt.archive, sha256: dxmt.sha256, bases: dxmt.bases,
- into: FreeEngine.downloads, step: FreeEngine.step, source: "GitHub"
++ into: FreeEngine.downloads, step: FreeEngine.step, from: "GitHub"
+ )
+ #expect(Digest.sha256IfPresent(archive) == dxmt.sha256)
+
+ let work = try makeEngines()
+ defer { try? FileManager.default.removeItem(at: work) }
+ let result = try Shell.run("/usr/bin/tar", ["-xf", archive.path(percentEncoded: false), "-C", work.path(percentEncoded: false)])
+ #expect(result.status == 0)
+ let tree = work.appending(path: dxmt.tree)
+ for (path, hash) in dxmt.files {
+ #expect(Digest.sha256IfPresent(tree.appending(path: path)) == hash, "\(path)")
+ }
+
+ let root = work.appending(path: "root")
+ try FreeEngine.installRenderer(dxmt, from: tree, root: root, step: FreeEngine.step)
+ for path in dxmt.files.keys {
+ let installed = root.appending(path: dxmt.installPath(of: path))
+ #expect(Digest.sha256IfPresent(installed) == dxmt.installedHash(of: path), "\(path)")
+ // winemetal stays a builtin beside its unix half; the D3D DLLs load as natives.
+ if path.hasSuffix(".dll") {
+ #expect(WinecxD3DMetal.isBuiltin(installed) == RendererRelease.isWinemetal(path), "\(path)")
+ }
+ }
+ // The WIP D3D12 backend and the DLSS pair are never staged.
+ let staged = try FileManager.default.subpathsOfDirectory(atPath: root.path(percentEncoded: false))
+ #expect(!staged.contains { $0.hasSuffix("d3d12.dll") || $0.contains("nvapi") || $0.contains("nvngx") })
+ }
+
+ @Test("Shipped game fixes are located in the payload and installed beside the user's own")
+ func gamefixesDefaultInstall() throws {
+ let work = try makeEngines()
+ defer { try? FileManager.default.removeItem(at: work) }
+ let payload = work.appending(path: "payload")
+ try touch(payload, "gamefixes/1245620.conf", "BACKEND=dxmt\n")
+ try touch(payload, "gamefixes/42.conf", "BACKEND=dxvk\n")
+ try touch(payload, "gamefixes/.gitkeep", "")
+ try touch(payload, "gamefixes/README", "x")
+
+ let located = try InstallPayload.locateGamefixes(in: payload)
+ #expect(located.map(\.lastPathComponent) == ["1245620.conf", "42.conf"])
+
+ let support = work.appending(path: "support")
+ let defaults = support.appending(path: "gamefixes-default")
+ try touch(support, "gamefixes-default/stale.conf", "old")
+ try touch(support, "gamefixes/mine.conf", "KEEP=1")
+ for source in located {
+ try SteamInstaller.installIfChanged(DeploymentContent.File(
+ source: source, destination: defaults.appending(path: source.lastPathComponent),
+ name: source.lastPathComponent))
+ }
+ SteamInstaller.pruneGamefixes(keeping: located.map(\.lastPathComponent), in: defaults)
+
+ let names = try FileManager.default.contentsOfDirectory(atPath: defaults.path(percentEncoded: false)).sorted()
+ #expect(names == ["1245620.conf", "42.conf"])
+ #expect(try String(contentsOf: defaults.appending(path: "42.conf"), encoding: .utf8) == "BACKEND=dxvk\n")
+ #expect(FileManager.default.fileExists(atPath: support.appending(path: "gamefixes/mine.conf").path(percentEncoded: false)))
+ #expect(SupportPaths.gamefixesDefault.lastPathComponent == "gamefixes-default")
+ #expect(SupportPaths.gamefixesDefault.path(percentEncoded: false)
+ == SupportPaths.support.path(percentEncoded: false) + "/gamefixes-default")
+ }
+}
diff --cc app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift
index 31f221a,0000000..76b134d
mode 100644,000000..100644
--- a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift
+++ b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift
@@@ -1,637 -1,0 +1,637 @@@
+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("Each pinned release names a free build NotProton knows how to patch",
+ arguments: FreeEngineWinecx.releases.map(\.build))
+ func releaseIsSupported(id: String) throws {
+ let release = try #require(FreeEngineWinecx.release(build: id))
+ let build = try #require(SupportedRunners.build(id: id))
+ #expect(build == release.runner)
+ #expect(build.isFree)
+ #expect(Set(NtdllPatcher.patches(for: build).map(\.arch)) == [.x86_64Windows, .i386Windows])
+ #expect(NtdllPatcher.patches(for: build).map(\.payloadResource).allSatisfy { $0.hasSuffix(id) })
+ #expect(SupportedRunners.build(loaderSHA256: build.loaderSHA256)?.id == build.id)
+ #expect(build.tools.count == 1)
+ #expect(build.tools.first?.display == "\(build.releaseVersion) (msync, D3DMetal)")
+ #expect(build.tools.first?.flavor == .rosetta)
+ #expect(release.bundleName == "\(build.releaseVersion).app")
+ }
+
+ @Test("11.17 is the current release with its own tool; 11.15 keeps notproton-winecx")
+ func currentAndPrevious() throws {
+ #expect(FreeEngineWinecx.current.build == "winecx-11.17")
+ #expect(FreeEngineWinecx.previous.build == "winecx-11.15")
+ #expect(FreeEngineWinecx.runnerBuild == FreeEngineWinecx.current.runner)
+ #expect(FreeEngineWinecx.current.runner.tools.map(\.name) == ["notproton-winecx-11.17"])
+ #expect(FreeEngineWinecx.previous.runner.tools.map(\.name) == ["notproton-winecx"])
+ let current = FreeEngineWinecx.current.runner
+ let previous = FreeEngineWinecx.previous.runner
+
+ // Installing 11.17 adds a tool and never moves notproton-winecx, which every
+ // existing prefix's build record ties to winecx-11.15. 11.17 lists first, so it is
+ // what games without a mapping get.
+ let both = SupportedRunners.tools(for: [current, previous])
+ #expect(both.map(\.name) == ["notproton-winecx-11.17", "notproton-winecx"])
+ #expect(both.map(\.build) == ["winecx-11.17", "winecx-11.15"])
+ #expect(SupportedRunners.tools(for: [previous]).map(\.build) == ["winecx-11.15"])
+ #expect(SupportedRunners.tools(for: [current]).map(\.name) == ["notproton-winecx-11.17"])
+ }
+
+ @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)) == Set([FreeEngine.current.build] + FreeEngineWinecx.releases.map(\.build)))
+ #expect(Set(free.map(\.loaderSHA256)).count == free.count)
+ #expect(Set(free.flatMap(\.tools).map(\.name)).count == free.flatMap(\.tools).count)
+ #expect(Set(FreeEngineWinecx.releases.map(\.bundleName) + [FreeEngine.current.bundleName]).count
+ == FreeEngineWinecx.releases.count + 1)
+ }
+
+ // 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) }
+
+ for release in FreeEngineWinecx.releases {
+ let root = FreeEngineWinecx.bundle(for: release, 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("\(release.build)\n".utf8).write(to: FreeEngineWinecx.msyncMarker(in: root))
+
+ #expect(CrossOverLicense.freeBuild(at: root) == nil)
+ #expect(!CrossOverLicense.check(crossOverRoot: root, searchDirs: []).licensed)
+ #expect(!FreeEngineWinecx.isInstalled(release, engines: engines))
+ #expect(!WinecxD3DMetal.isWinecx(root: root))
+ #expect(FreeEngineWinecx.release(forRoot: root) == nil)
+ }
+ }
+
+ @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)")
+ // DXMT comes from the master tarball, never the archive's 0.80.
+ #expect(parts[0] == "dxvk", "\(file.destination)")
+ #expect(!file.source.hasPrefix("DXMT/"))
+ #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)")
+ }
+ let table = FreeEngineWinecx.expectedFiles()
+ for arch in ["x86_64-windows", "i386-windows"] {
+ for backend in ["dxmt", "dxvk"] {
+ #expect(table["lib/notproton-backends/\(backend)/\(arch)/d3d11.dll"] != nil)
+ }
+ #expect(table["lib/notproton-backends/dxmt/\(arch)/d3d11.dll"]
+ == FreeEngine.dxmt.natives["\(arch)/d3d11.dll"])
+ #expect(table["lib/wine/\(arch)/winemetal.dll"] == FreeEngine.dxmt.files["\(arch)/winemetal.dll"])
+ }
+ #expect(table["lib/wine/x86_64-unix/winemetal.so"] == FreeEngine.dxmt.files["x86_64-unix/winemetal.so"])
+ #expect(table[FreeEngine.macDriverPath] == FreeEngineWinecx.current.macDriver)
+ #expect(Set(FreeEngineWinecx.current.d3dStock.keys) == Set(WinecxD3DMetal.forwarders))
+ #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")
+ }
+
+ // winemac-patch/winecx-d3dmetal-retina.patch: an engine with winecx's own winemac.so is
+ // outdated, and the copy NotProton installs is the one it pins.
+ @Test("The patched winemac.so ships with the app and replaces winecx's own",
+ arguments: FreeEngineWinecx.releases.map(\.build))
+ func patchedMacDriver(id: String) throws {
+ let release = try #require(FreeEngineWinecx.release(build: id))
+ let bundled = try #require(Bundle.module.url(forResource: "winemac-\(release.build)", withExtension: "so"))
+ #expect(Digest.sha256IfPresent(bundled) == release.macDriver)
+
+ let root = try makeDirectory("macdriver")
+ defer { try? FileManager.default.removeItem(at: root) }
+ let driver = root.appending(path: FreeEngine.macDriverPath)
+ try FileManager.default.createDirectory(at: driver.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data("winecx's own winemac.so".utf8).write(to: driver)
+ #expect(FreeEngineWinecx.layoutProblems(root: root, release: release).contains(FreeEngine.macDriverPath))
+
+ try FreeEngine.installMacDriver(root: root, build: release.build, sha256: release.macDriver,
+ step: FreeEngineWinecx.step)
+ #expect(Digest.sha256IfPresent(driver) == release.macDriver)
+ #expect(!FreeEngineWinecx.layoutProblems(root: root, release: release).contains(FreeEngine.macDriverPath))
+ #expect(throws: StepFailure.self) {
+ try FreeEngine.installMacDriver(root: root, build: release.build, sha256: String(repeating: "0", count: 64),
+ step: FreeEngineWinecx.step)
+ }
+ }
+
+ // docs/WINECX.md, Controllers: winebus.so with SDL2 in lib/wine, and the libSDL2 it
+ // dlopens by leaf name in lib/, where its @loader_path/../../ rpath points.
+ @Test("The SDL2 winebus.so and its libSDL2 ship with the app and are laid into the engine",
+ arguments: FreeEngineWinecx.releases.map(\.build))
+ func gamepadSupport(id: String) throws {
+ let release = try #require(FreeEngineWinecx.release(build: id))
+ let files = release.gamepad
+ var paths: Set<String> = ["lib/wine/x86_64-unix/winebus.so", "lib/libSDL2-2.0.0.dylib"]
+ // 11.17 also ships winebus.sys with sdl_bus_load_mappings fixed (winebus-patch/).
+ if release.build == "winecx-11.17" { paths.insert("lib/wine/x86_64-windows/winebus.sys") }
+ #expect(Set(files.map(\.path)) == paths)
+ let table = FreeEngineWinecx.expectedFiles(release)
+ for file in files {
+ let bundled = try #require(Bundle.module.url(forResource: file.resource, withExtension: file.ext))
+ #expect(Digest.sha256IfPresent(bundled) == file.sha256, "\(file.resource)")
+ #expect(table[file.path] == file.sha256, "\(file.path)")
+ }
+
+ let root = try makeDirectory("gamepad")
+ defer { try? FileManager.default.removeItem(at: root) }
+ let bus = root.appending(path: "lib/wine/x86_64-unix/winebus.so")
+ try FileManager.default.createDirectory(at: bus.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data("winecx's own winebus.so, built without SDL2".utf8).write(to: bus)
+ let before = FreeEngineWinecx.layoutProblems(root: root, release: release)
+ for file in files { #expect(before.contains(file.path), "\(file.path)") }
+
+ try FreeEngineWinecx.installBundled(files, root: root)
+ let after = FreeEngineWinecx.layoutProblems(root: root, release: release)
+ for file in files {
+ #expect(Digest.sha256IfPresent(root.appending(path: file.path)) == file.sha256, "\(file.path)")
+ #expect(!after.contains(file.path), "\(file.path)")
+ }
+ let wrong = files.map {
+ WinecxBundledFile(resource: $0.resource, ext: $0.ext, path: $0.path, sha256: String(repeating: "0", count: 64))
+ }
+ #expect(throws: StepFailure.self) { try FreeEngineWinecx.installBundled(wrong, root: root) }
+ }
+
+ // docs/WINECX.md, Own host name: 11.17 ships ws2_32.dll with getaddrinfo on the local
+ // host name returning no loopback first (ws2_32-patch/); 11.15 keeps the runtime's.
+ @Test("The own-host-name ws2_32 ships with the app and is laid into the 11.17 engine",
+ arguments: FreeEngineWinecx.releases.map(\.build))
+ func ownHostNameNetwork(id: String) throws {
+ let release = try #require(FreeEngineWinecx.release(build: id))
+ let files = release.network
+ let expected: Set<String> = release.build == "winecx-11.17" ? ["lib/wine/x86_64-windows/ws2_32.dll"] : []
+ #expect(Set(files.map(\.path)) == expected)
+ let table = FreeEngineWinecx.expectedFiles(release)
+ for file in files {
+ let bundled = try #require(Bundle.module.url(forResource: file.resource, withExtension: file.ext))
+ #expect(Digest.sha256IfPresent(bundled) == file.sha256, "\(file.resource)")
+ #expect(table[file.path] == file.sha256, "\(file.path)")
+ }
+ guard !files.isEmpty else { return }
+
+ let root = try makeDirectory("network")
+ defer { try? FileManager.default.removeItem(at: root) }
+ let dll = root.appending(path: "lib/wine/x86_64-windows/ws2_32.dll")
+ try FileManager.default.createDirectory(at: dll.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data("winecx's own ws2_32.dll".utf8).write(to: dll)
+ #expect(FreeEngineWinecx.layoutProblems(root: root, release: release).contains(files[0].path))
+
+ try FreeEngineWinecx.installBundled(files, root: root)
+ #expect(Digest.sha256IfPresent(dll) == files[0].sha256)
+ #expect(!FreeEngineWinecx.layoutProblems(root: root, release: release).contains(files[0].path))
+ }
+
+ @Test("Each free engine is current, outdated or missing on its own pins")
+ func perEngineState() throws {
+ let winehqBuild = try #require(SupportedRunners.build(id: FreeEngine.current.build))
+ let winecxBuild = try #require(SupportedRunners.build(id: FreeEngineWinecx.current.build))
+ let winehq = CrossOverInstall(bundle: URL(filePath: "/e/WineHQ 11.15.app"), releaseVersion: nil,
+ support: .supported(winehqBuild))
+ let winecx = CrossOverInstall(bundle: URL(filePath: "/e/WineCX 11.17.app"), releaseVersion: nil,
+ support: .supported(winecxBuild))
+ let both = [winehq, winecx]
+ #expect(FreeEngineStatus.state(build: winehqBuild.id, installs: both, current: [winecxBuild.id]) == .outdated)
+ #expect(FreeEngineStatus.state(build: winecxBuild.id, installs: both, current: [winecxBuild.id]) == .current)
+ #expect(FreeEngineStatus.state(build: winecxBuild.id, installs: [winehq], current: [winehqBuild.id]) == .missing)
+ // Neither engine is judged by the other's pins: these empty trees match neither.
+ #expect(!FreeEngineStatus.isCurrent(winehq) && !FreeEngineStatus.isCurrent(winecx))
+ #expect(FreeEngineStatus.capture(both).current.isEmpty)
+ // Steam lists one tool per engine.
+ let tools = SupportedRunners.tools(for: [winehqBuild, winecxBuild]).map(\.display)
+ #expect(Set(tools) == ["WineHQ 11.15 - Rosetta", "WineCX 11.17 (msync, D3DMetal)"])
+ // The 11.15 engine is judged by its own pins, not by 11.17's.
+ let previousBuild = try #require(SupportedRunners.build(id: FreeEngineWinecx.previous.build))
+ let previous = CrossOverInstall(bundle: URL(filePath: "/e/WineCX 11.15.app"), releaseVersion: nil,
+ support: .supported(previousBuild))
+ #expect(!FreeEngineStatus.isCurrent(previous))
+ #expect(FreeEngineStatus.state(build: previousBuild.id, installs: [previous], current: [previousBuild.id])
+ == .current)
+ }
+
+ @Test("Downloads come only from the pinned GitHub release mirrors")
+ func pinnedSources() {
+ #expect(FreeEngineWinecx.current.sha256 == "a4b5d63493f80698cce5cad8e7212d9a51c8292037b00c478f4652636fcfd331")
+ #expect(FreeEngineWinecx.previous.sha256 == "6db83765d9bd9d9941cacf8e09d2b8a3014738305ca4672d2188f3e6e51fae87")
+ for release in FreeEngineWinecx.releases {
+ #expect(release.bases.allSatisfy { $0.host() == "github.com" })
+ #expect(release.bases.allSatisfy { $0.path().hasSuffix(release.runtime) })
+ #expect(FreeEngineWinecx.downloads(for: release).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]) }
+ let unix = lib.appending(path: "wine/x86_64-unix")
+ try fm.createDirectory(at: unix, withIntermediateDirectories: true)
+ // GPTK 4.0 beta 2: the four forwarders plus nvapi64 and nvngx-on-metalfx, each unix
+ // half a relative link to libd3dshared.
+ for name in WinecxD3DMetal.forwarders + ["nvapi64.dll", "nvngx-on-metalfx.dll"] {
+ try image.write(to: pe.appending(path: name))
+ try fm.createSymbolicLink(
+ atPath: unix.appending(path: WinecxD3DMetal.unixName(of: name)).path(percentEncoded: false),
+ withDestinationPath: "../../external/libd3dshared.dylib")
+ }
+ return lib
+ }
+
+ // Wine's four originals, as text whose hashes the test pins.
+ private static let stockText = Dictionary(uniqueKeysWithValues: WinecxD3DMetal.forwarders.map { ($0, "wine's own \($0)") })
+ private static let stock = stockText.mapValues { Digest.sha256(of: Data($0.utf8)) }
+
+ private func makeEngineRoot(in folder: URL) throws -> URL {
+ let fm = FileManager.default
+ let root = folder.appending(path: "CrossOver")
+ let external = root.appending(path: "lib/external")
+ try fm.createDirectory(at: external, withIntermediateDirectories: true)
+ try Data("winecx readme".utf8).write(to: external.appending(path: "README"))
+ let builtins = root.appending(path: "lib/wine/x86_64-windows")
+ try fm.createDirectory(at: builtins, withIntermediateDirectories: true)
+ try fm.createDirectory(at: root.appending(path: "lib/wine/x86_64-unix"), withIntermediateDirectories: true)
+ for (name, text) in Self.stockText {
+ try Data(text.utf8).write(to: builtins.appending(path: name))
+ }
+ 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 makes Apple's forwarders the builtins, as links, with Wine's originals set aside")
+ 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)
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+ let payload = try #require(WinecxD3DMetal.locate(in: [lib]))
+ try WinecxD3DMetal.link(payload, root: root, stock: Self.stock)
+
+ #expect(WinecxD3DMetal.isLinked(root: root))
+ #expect(WinecxD3DMetal.linkedSource(root: root) == lib.standardizedFileURL.path(percentEncoded: false))
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+ 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 + ["nvapi64.dll"] {
+ #expect(try destination(of: root.appending(path: "lib/wine/x86_64-windows/\(name)"))
+ == source.appending(path: "wine/x86_64-windows/\(name)").path(percentEncoded: false))
+ let so = WinecxD3DMetal.unixName(of: name)
+ #expect(try destination(of: root.appending(path: "lib/wine/x86_64-unix/\(so)"))
+ == source.appending(path: "wine/x86_64-unix/\(so)").path(percentEncoded: false))
+ // Through Apple's own relative link, onto the shared library.
+ #expect(try Data(contentsOf: root.appending(path: "lib/wine/x86_64-unix/\(so)")) == Data("dylib".utf8))
+ }
+ for name in WinecxD3DMetal.forwarders {
+ let saved = root.appending(path: "lib/notproton-backends/wine-stock/x86_64-windows/\(name)")
+ #expect(Digest.sha256IfPresent(saved) == Self.stock[name])
+ }
+ // nvngx-on-metalfx is left out.
+ #expect(!fm.fileExists(atPath: root.appending(path: "lib/wine/x86_64-windows/nvngx-on-metalfx.dll").path(percentEncoded: false)))
+ #expect(!fm.fileExists(atPath: root.appending(path: "lib/notproton-backends/d3dmetal").path(percentEncoded: false)))
+ #expect(fm.fileExists(atPath: root.appending(path: "lib/external/README").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("model=builtin\n"))
+
+ // Relinking is idempotent.
+ try WinecxD3DMetal.link(payload, root: root, stock: Self.stock)
+ #expect(WinecxD3DMetal.isLinked(root: root))
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+ }
+
+ @Test("Unlinking puts Wine's originals back byte for byte and removes only links")
+ 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, stock: Self.stock)
+
+ try fm.removeItem(at: lib)
+ #expect(!WinecxD3DMetal.isLinked(root: root))
+ // Still the linked shape, only dangling: refresh is what clears it.
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+
+ WinecxD3DMetal.unlink(root: root)
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+ #expect(!fm.fileExists(atPath: WinecxD3DMetal.enabledMarker(in: root).path(percentEncoded: false)))
+ for (name, text) in Self.stockText {
+ let live = root.appending(path: "lib/wine/x86_64-windows/\(name)")
+ #expect((try? fm.destinationOfSymbolicLink(atPath: live.path(percentEncoded: false))) == nil)
+ #expect(try Data(contentsOf: live) == Data(text.utf8))
+ }
+ #expect(try fm.contentsOfDirectory(atPath: root.appending(path: "lib/wine/x86_64-unix").path(percentEncoded: false)).isEmpty)
+ #expect(!fm.fileExists(atPath: root.appending(path: "lib/notproton-backends/wine-stock").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("Only the stock and the linked layout pass; a tampered builtin blocks linking")
+ func toleratesExactlyTwoStates() throws {
+ let base = try makeDirectory("states")
+ 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]))
+
+ let dxgi = root.appending(path: "lib/wine/x86_64-windows/dxgi.dll")
+ try Data("tampered".utf8).write(to: dxgi)
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock) == ["lib/wine/x86_64-windows/dxgi.dll"])
+ #expect(throws: StepFailure.self) { try WinecxD3DMetal.link(payload, root: root, stock: Self.stock) }
+ // The failed link left nothing behind and moved nothing aside.
+ #expect(!fm.fileExists(atPath: WinecxD3DMetal.enabledMarker(in: root).path(percentEncoded: false)))
+ for name in ["d3d10.dll", "d3d11.dll", "d3d12.dll"] {
+ #expect(Digest.sha256IfPresent(root.appending(path: "lib/wine/x86_64-windows/\(name)")) == Self.stock[name])
+ }
+ try Data(Self.stockText["dxgi.dll"]!.utf8).write(to: dxgi)
+
+ // A stray unix half or a set-aside copy without the marker is neither state.
+ let stray = root.appending(path: "lib/wine/x86_64-unix/d3d12.so")
+ try fm.createSymbolicLink(at: stray, withDestinationURL: lib.appending(path: "external/libd3dshared.dylib"))
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock) == ["lib/wine/x86_64-unix/d3d12.so"])
+ try fm.removeItem(at: stray)
+
+ try WinecxD3DMetal.link(payload, root: root, stock: Self.stock)
+ // Linked, but one forwarder swapped for a real file: refused.
+ let d3d11 = root.appending(path: "lib/wine/x86_64-windows/d3d11.dll")
+ try fm.removeItem(at: d3d11)
+ try Data("copied apple file".utf8).write(to: d3d11)
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock) == ["lib/wine/x86_64-windows/d3d11.dll"])
+ }
+
+ @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 a release's archive is in NotProton's cache, or at NOTPROTON_WINECX_ARCHIVE.
+ private static func realArchive(_ release: WinecxRelease) -> URL? {
+ let candidates = [
+ ProcessInfo.processInfo.environment["NOTPROTON_WINECX_ARCHIVE"].map { URL(filePath: $0) },
+ FreeEngineWinecx.downloads(for: release).appending(path: release.archive),
+ ].compactMap { $0 }
+ return candidates.first { Digest.sha256IfPresent($0) == release.sha256 }
+ }
+
+ @Test("Unpacking the real archive yields a free, patchable engine with the runtime contract",
+ arguments: FreeEngineWinecx.releases.map(\.build))
+ func unpacksRealArchive(id: String) async throws {
+ let release = try #require(FreeEngineWinecx.release(build: id))
+ guard let archive = Self.realArchive(release) else { return }
+ // Fetched into the engine cache the way FreeEngineWinecx.install does, when missing.
+ let dxmt = FreeEngine.dxmt
+ let renderer = try await PinnedDownload.obtain(
+ file: dxmt.archive, sha256: dxmt.sha256, bases: dxmt.bases,
- into: FreeEngine.downloads, step: FreeEngineWinecx.step, source: "GitHub"
++ into: FreeEngine.downloads, step: FreeEngineWinecx.step, from: "GitHub"
+ )
+ 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, renderer: renderer, release: release, 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 == release.build)
+ #expect(install.isFree)
+ #expect(FreeEngineWinecx.isInstalled(release, engines: engines))
+ #expect(FreeEngineWinecx.hasBackends(root: root, release: release))
+ #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])
+ }
+
+ #expect(FreeEngineWinecx.layoutProblems(root: root, release: release).isEmpty)
+ // Master's winemetal replaced the archive's, and its DLLs are natives.
+ for (path, hash) in FreeEngineWinecx.expectedFiles(release) {
+ #expect(Digest.sha256IfPresent(root.appending(path: path)) == hash, "\(path)")
+ }
+ #expect(!WinecxD3DMetal.isBuiltin(root.appending(path: "lib/notproton-backends/dxmt/x86_64-windows/d3d11.dll")))
+ #expect(WinecxD3DMetal.isBuiltin(root.appending(path: "lib/wine/x86_64-windows/winemetal.dll")))
+ #expect(try String(contentsOf: FreeEngineWinecx.msyncMarker(in: root), encoding: .utf8) == "\(release.build)\n")
+
+ // The fixture GPTK was linked as the builtins, with Wine's own set aside under their pins.
+ #expect(WinecxD3DMetal.isLinked(root: root))
+ #expect(fm.fileExists(atPath: root.appending(path: "lib/external/README").path(percentEncoded: false)))
+ for (name, hash) in release.d3dStock {
+ #expect(Digest.sha256IfPresent(root.appending(path: "\(WinecxD3DMetal.stockPath)/\(name)")) == hash)
+ }
+
+ // A runner cloned from it carries the same links, and a rescan reaches both trees.
+ let runners = base.appending(path: "runners")
+ let cloned = try RunnerInstaller.clone(from: install, runners: runners)
+ let runnerRoot = SupportPaths.clonedRoot(forBuild: cloned.id, runners: runners)
+ #expect(WinecxD3DMetal.isLinked(root: runnerRoot))
+ #expect(FreeEngineWinecx.layoutProblems(root: runnerRoot, release: release).isEmpty)
+ try fm.removeItem(at: gptk)
+ #expect(SystemStatus.relinkGameportingToolkit(engines: engines, runners: runners, roots: [gptk]) == nil)
+ for tree in [root, runnerRoot] {
+ #expect(!WinecxD3DMetal.isLinked(root: tree))
+ #expect(!fm.fileExists(atPath: WinecxD3DMetal.enabledMarker(in: tree).path(percentEncoded: false)))
+ #expect(FreeEngineWinecx.layoutProblems(root: tree, release: release).isEmpty, "\(tree)")
+ for (name, hash) in release.d3dStock {
+ #expect(Digest.sha256IfPresent(tree.appending(path: "lib/wine/x86_64-windows/\(name)")) == hash)
+ }
+ }
+ let again = try makePayload(in: base.appending(path: "gptk2"))
+ #expect(SystemStatus.relinkGameportingToolkit(engines: engines, runners: runners, roots: [again])
+ == again.standardizedFileURL.path(percentEncoded: false))
+ #expect(WinecxD3DMetal.isLinked(root: root) && WinecxD3DMetal.isLinked(root: runnerRoot))
+ }
+
+ // MARK: - Against the user's own Game Porting Toolkit
+
+ // Runs only when a GPTK sits in NotProton's gptk folder. It is only read: the links go
+ // into a throwaway engine tree under the repository's scratch/.
+ @Test("Linking the real Game Porting Toolkit resolves every link and leaves it untouched")
+ func linksRealGameportingToolkit() throws {
+ let gptk = WinecxD3DMetal.userFolder
+ guard WinecxD3DMetal.payloadRoot(under: gptk) != nil else { return }
+ let fm = FileManager.default
+ let before = try snapshot(of: gptk)
+
+ let scratch = URL(filePath: #filePath).deletingLastPathComponent()
+ .appending(path: "../../../scratch/gptk-link-test-\(UUID().uuidString)").standardizedFileURL
+ try fm.createDirectory(at: scratch, withIntermediateDirectories: true)
+ defer { try? fm.removeItem(at: scratch) }
+ let root = try makeEngineRoot(in: scratch)
+
+ let payload = try #require(WinecxD3DMetal.locate(in: [gptk]))
+ #expect(payload.version != nil)
+ try WinecxD3DMetal.link(payload, root: root, stock: Self.stock)
+ #expect(WinecxD3DMetal.isLinked(root: root))
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+ let shared = try Data(contentsOf: payload.libRoot.appending(path: "external/libd3dshared.dylib"))
+ for name in WinecxD3DMetal.forwarders + ["nvapi64.dll"] {
+ let pe = root.appending(path: "lib/wine/x86_64-windows/\(name)")
+ #expect(WinecxD3DMetal.isBuiltin(pe), "\(name)")
+ #expect(try Data(contentsOf: root.appending(path: "lib/wine/x86_64-unix/\(WinecxD3DMetal.unixName(of: name))"))
+ == shared, "\(name)")
+ }
+ #expect(!fm.fileExists(atPath: root.appending(path: "lib/wine/x86_64-windows/nvngx-on-metalfx.dll").path(percentEncoded: false)))
+ // Only links: no file in the engine tree holds Apple's bytes.
+ let walker = try #require(fm.enumerator(atPath: root.path(percentEncoded: false)))
+ for case let path as String in walker {
+ let attributes = try fm.attributesOfItem(atPath: root.appending(path: path).path(percentEncoded: false))
+ if attributes[.type] as? FileAttributeType == .typeRegular {
+ #expect(!path.contains("D3DMetal") && !path.hasSuffix(".dylib"), "\(path)")
+ }
+ }
+
+ WinecxD3DMetal.unlink(root: root)
+ #expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)
+ #expect(try snapshot(of: gptk) == before)
+ }
+
+ // Path, type, size and modification time of everything below a folder.
+ private func snapshot(of folder: URL) throws -> [String] {
+ let fm = FileManager.default
+ let walker = try #require(fm.enumerator(atPath: folder.path(percentEncoded: false)))
+ var lines: [String] = []
+ for case let path as String in walker {
+ let a = try fm.attributesOfItem(atPath: folder.appending(path: path).path(percentEncoded: false))
+ lines.append("\(path) \(a[.type] ?? "") \(a[.size] ?? "") \(a[.modificationDate] ?? "")")
+ }
+ return lines.sorted()
+ }
+}
diff --cc dylib/feats/webpatch.c
index 1066391,5564932..134bad4
--- a/dylib/feats/webpatch.c
+++ b/dylib/feats/webpatch.c
@@@ -157,11 -155,25 +157,25 @@@ static int out_expand(np_out_t *o, cons
"else{const w=wd();if(!c.length&&/^(if|then|else|elif|do|while|until|!|\\{)$/" \
".test(o.slice(w.start,w.end)))cs.push(c=[]);else c.push(w)}}" \
"const m=w=>/%command%/i.test(o.slice(w.start,w.end)),G=cs.find(c=>c.some(m));" \
- "if(!G)return{p:0,e:[]};" \
+ "if(!G)return{p:0,e:[],G:[],c:-1};" \
"const n=G.findIndex(w=>m(w)||!/^[A-Za-z_]\\w*=/.test(o.slice(w.start,w.end)));" \
- "return{p:G[0].start,e:G.slice(0,n<0?G.length:n)}})(),"
+ "return{p:G[0].start,e:G.slice(0,n<0?G.length:n),G:G,c:G.findIndex(m)}})(),"
// CrossOver options panel. Not in great shape, but it'll do
+ #define NP_WEB_IS_ZH \
+ "(()=>{const l=(globalThis.document?.documentElement?.lang||" \
+ "globalThis.navigator?.language||\"\").toLowerCase().replace(/_/g,\"-\");" \
+ "return /^(zh(-hans(-[a-z0-9]+)*|-cn|-sg)?|schinese)$/.test(l)})()"
+
+ #define NP_WEB_TEXT(EN, ZH) "(" NP_WEB_IS_ZH "?\"" ZH "\":\"" EN "\")"
+
+ #define NP_COMPAT_HINT NP_WEB_TEXT( \
+ "Enable CrossOver under Properties > Compatibility to install and run the Windows version.", \
+ "请在“属性 > 兼容性”中启用 CrossOver,以安装并运行 Windows 版本。")
+
+ #define NP_IMAGE_FILES_LABEL NP_WEB_TEXT( \
+ "Image Files (*.tga,*.png,*.exe)", "图像文件 (*.tga,*.png,*.exe)")
+
#define NP_CX_OPTIONS_CSS \
"\".MSCXPanel{margin-top:10px}" \
".MSCXPanel .MSCXRow{display:flex;flex-direction:row;padding:9px;margin:0;" \
@@@ -172,14 -184,12 +186,15 @@@
#define NP_CX_OPTIONS_BODY(ARG, RT, BARREL) \
ARG "=>{" \
"const t=" ARG ".details,o=t.strLaunchOptions||\"\"," \
+ "npZh=" NP_WEB_IS_ZH ",npL=(en,zh)=>npZh?zh:en," \
NP_CX_LAUNCH_PARSE \
- "g=k=>{const p=E.e.filter(w=>o.startsWith(k+\"=\",w.start)).pop();" \
- "return p?(p.value===null?o.slice(p.start+k.length+1,p.end):p.value.slice(k.length+1)):\"\"}," \
+ "nat=t.unAppID<2147483648&&(t.vecPlatforms||[]).indexOf(\"osx\")>=0&&!t.strCompatToolName," \
+ "wv=w=>w.value===null?o.slice(w.start,w.end):w.value," \
+ "NE=E.c<0?[]:E.G.slice(0,E.c).filter(w=>/^[A-Za-z_]\\w*=/.test(wv(w)))," \
+ "A=k=>(nat?NE.filter(w=>wv(w).startsWith(k+\"=\")):E.e.filter(w=>o.startsWith(k+\"=\",w.start))).pop()," \
+ "g=k=>{const p=A(k);return p?wv(p).slice(k.length+1):\"\"}," \
"qv=v=>/^[\\w.,:=\\/+@%-]*$/.test(v)?v:\"'\"+v.replace(/'/g,\"'\\\\''\")+\"'\"," \
- "s=ps=>{const add=ps.filter(p=>p[1]).map(p=>p[0]+\"=\"+qv(p[1])).join(\" \");let r;" \
+ "sl=ps=>{const add=ps.filter(p=>p[1]).map(p=>p[0]+\"=\"+qv(p[1])).join(\" \");let r;" \
"if(!/%command%/i.test(o)){if(!add)return;r=add+\" %command%\"+(o.trim()?\" \"+o:\"\")}" \
"else{let at=E.p;r=o.slice(0,at)+(add?add+\" \":\"\");" \
"E.e.forEach(w=>{if(ps.some(p=>o.startsWith(p[0]+\"=\",w.start))){" \
@@@ -246,16 -218,11 +261,16 @@@
"{data:\"dxmt\",label:\"DXMT\"}," \
"{data:\"dxvk\",label:\"DXVK\"}," \
"{data:\"wined3d\",label:\"WineD3D\"}];" \
- "if(t.unAppID<2147483648&&(t.vecPlatforms||[]).indexOf(\"osx\")>=0" \
- "&&!t.strCompatToolName)return null;" \
+ "if(nat)return(0," RT ".jsx)(\"div\",{className:\"MSCXPanel\",children:(0," RT ".jsxs)(" RT ".Fragment,{children:[" \
+ "(0," RT ".jsx)(\"style\",{children:" NP_CX_OPTIONS_CSS "})," \
+ "T([\"MTL_HUD_ENABLED\"],\"Metal HUD\",\"1\"),FG()," \
+ "(0," RT ".jsx)(" BARREL ".XY,{label:\"Controllers\",children:" \
+ "D(\"NP_PAD_MODE\",\"Controller layer\",[{data:\"\",label:\"Automatic\"},{data:\"hid\",label:\"Raw HID (Unity, SDL, Unreal)\"}," \
+ "{data:\"gc\",label:\"GameController\"},{data:\"off\",label:\"Off\"}],lc(\"\"))},\"ctl\")" \
+ "]})});" \
"return(0," RT ".jsx)(\"div\",{className:\"MSCXPanel\",children:(0," RT ".jsxs)(" RT ".Fragment,{children:[" \
"(0," RT ".jsx)(\"style\",{children:" NP_CX_OPTIONS_CSS "})," \
- "(0," RT ".jsxs)(" BARREL ".XY,{label:\"Graphics\",children:[" \
+ "(0," RT ".jsxs)(" BARREL ".XY,{label:npL(\"Graphics\",\"图形\"),children:[" \
"(0," RT ".jsx)(" BARREL ".m,{rgOptions:B,selectedOption:b," \
"onChange:v=>s([[\"CX_GRAPHICS_BACKEND\",v.data]]" \
".concat(\"\"===v.data||\"d3dmetal\"===v.data?[]:[[\"D3DM_ENABLE_METALFX\",\"\"]])" \
@@@ -274,9 -242,10 +290,11 @@@
"children:(0," RT ".jsx)(" BARREL ".m,{rgOptions:U," \
"selectedOption:sw?(U.find(u=>u.data&&+u.data===fn)||{data:String(fn)}).data:\"\"," \
"onChange:v=>s([[\"DXMT_METALFX_SPATIAL_SWAPCHAIN\",v.data?\"1\":\"\"],[\"DXMT_CONFIG\",fx(v.data)]])})},\"usf\")," \
+ "FG()," \
- "(0," RT ".jsx)(" BARREL ".XY,{label:\"Controllers (May break Steam Input. Not recommended)\",children:" \
- "T([\"NOTPROTON_RAW_CONTROLLERS\"],\"Let games read controllers directly\",\"1\",\"\")},\"ctl\")" \
+ "(0," RT ".jsx)(" BARREL ".XY,{label:npL(\"Controllers (May break Steam Input. Not recommended)\"," \
+ "\"控制器(可能导致 Steam Input 失效,不推荐)\"),children:" \
+ "T([\"NOTPROTON_RAW_CONTROLLERS\"],npL(\"Let games read controllers directly\"," \
+ "\"允许游戏直接读取控制器\"),\"1\",\"\")},\"ctl\")" \
"]})})}"
#define NP_CX_OPTIONS_COMPONENT \
diff --cc dylib/tests/panel-behavior/emit.c
index 1478629,e511034..135d711
--- a/dylib/tests/panel-behavior/emit.c
+++ b/dylib/tests/panel-behavior/emit.c
@@@ -22,25 -22,14 +22,33 @@@ int main(int argc, char **argv)
fputs(NP_LAUNCH_MIGRATION, stdout);
return 0;
}
+ // The chunk as Steam is served it, defaults included, read from $HOME like the hook.
+ if (argc == 4 && strcmp(argv[1], "transform") == 0) {
+ FILE *f = fopen(argv[2], "rb");
+ if (!f) return 1;
+ fseek(f, 0, SEEK_END);
+ long n = ftell(f);
+ rewind(f);
+ uint8_t *src = malloc(n > 0 ? (size_t)n : 1);
+ if (!src || fread(src, 1, (size_t)n, f) != (size_t)n) { fclose(f); return 1; }
+ fclose(f);
+ np_webpatch_set_fallback_tool(argv[3]);
+ size_t out_len = 0;
+ char *out = np_webpatch_transform(src, (size_t)n, &out_len, NULL);
+ free(src);
+ if (!out) return 1;
+ fwrite(out, 1, out_len, stdout);
+ free(out);
+ return 0;
+ }
- fputs("usage: emit component|statement|migration|transform <chunk> <fallback tool>\n", stderr);
+ if (argc == 2 && strcmp(argv[1], "compat-hint") == 0) {
+ fputs(NP_COMPAT_HINT, stdout);
+ return 0;
+ }
+ if (argc == 2 && strcmp(argv[1], "image-files-label") == 0) {
+ fputs(NP_IMAGE_FILES_LABEL, stdout);
+ return 0;
+ }
- fputs("usage: emit component|statement|migration|compat-hint|image-files-label\n", stderr);
++ fputs("usage: emit component|statement|migration|transform <chunk> <fallback tool>|compat-hint|image-files-label\n", stderr);
return 2;
}
diff --cc dylib/version.h
index 1cea766,7e4071a..3cc04ae
--- a/dylib/version.h
+++ b/dylib/version.h
@@@ -2,6 -2,6 +2,6 @@@
#ifndef NOTPROTON_VERSION_H
#define NOTPROTON_VERSION_H
- #define NOTPROTON_VERSION "1.1.5-winehq.1-ray.15"
-#define NOTPROTON_VERSION "1.1.7"
++#define NOTPROTON_VERSION "1.1.7-winehq.1-ray.16"
#endif // NOTPROTON_VERSION_H