Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
fix(winecx): SDL-enabled winebus so Xbox pads reach XInput
raymondchins9a0cbf5053d6
diff --git a/.gitignore b/.gitignoreindex 6339ee1..5fe2f49 100644--- a/.gitignore+++ b/.gitignore@@ -4,6 +4,8 @@ out/*.o*.a*.dylib+# The x86_64 SDL2 FreeEngineWinecx installs for winebus.so (docs/WINECX.md).+!app/Sources/NotProtonApp/Resources/libSDL2-2.0.0.dylib.DS_Storevendor/dobby/diff --git a/NOTICE b/NOTICEindex 1e1f761..1391369 100644--- a/NOTICE+++ b/NOTICE@@ -36,3 +36,16 @@ These third party files carry their original notices from the project authors:steam-shim/json/json-forwards.h JsonCpp, public domain / MIT (header)vendor/cJSON.c cJSON, MIT (header)vendor/cJSON.h cJSON, MIT (header)++The WineCX engine gets an x86_64 SDL2 from the app bundle, for controller support+in winebus.so (docs/WINECX.md):++ app/Sources/NotProtonApp/Resources/libSDL2-2.0.0.dylib+ Simple DirectMedia Layer 2.32.8 (SDL-release-2.32.8-0-g98d1f3a45),+ https://github.com/libsdl-org/SDL/tree/release-2.32.8, binary unmodified+ except for an ad-hoc code signature.+ Copyright (C) 1997-2025 Sam Lantinga <[email protected]>.+ zlib license, https://github.com/libsdl-org/SDL/blob/release-2.32.8/LICENSE.txt++ app/Sources/NotProtonApp/Resources/winebus-winecx-11.15.so+ winecx 5b45f45 (Wine, LGPL-2.1-or-later), built with SDL2 support.diff --git a/app/Package.swift b/app/Package.swiftindex 9f99a4d..b756b75 100644--- a/app/Package.swift+++ b/app/Package.swift@@ -44,6 +44,8 @@ let package = Package(.copy("Resources/detour2-winecx-11.15.bin"),.copy("Resources/detour32-winecx-11.15.bin"),.copy("Resources/winemac-winecx-11.15.so"),+ .copy("Resources/winebus-winecx-11.15.so"),+ .copy("Resources/libSDL2-2.0.0.dylib"),],swiftSettings: [.swiftLanguageMode(.v6)]),diff --git a/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift b/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swiftindex 687483a..e1f7eb0 100644--- a/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift+++ b/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift@@ -16,6 +16,16 @@ struct WinecxBackendFile: Sendable, Equatable {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.@@ -38,6 +48,12 @@ struct WinecxRelease: Sendable {// 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]}enum FreeEngineWinecx {@@ -80,7 +96,16 @@ enum FreeEngineWinecx {"d3d12.dll": "c6e285308bb3241efca3d94da4746b16a526a9fb5113f61922e7bd86694bebf9","dxgi.dll": "f1f24da777c65a583b29f74475c6a9464da35068d75def6cee806268def9ecbb",],- macDriver: "c611031855e596b2aeb2d2ea2c2ddef8cb843376d85ccf8bbe10c4fc727a527e"+ macDriver: "c611031855e596b2aeb2d2ea2c2ddef8cb843376d85ccf8bbe10c4fc727a527e",+ // winebus.so: winecx 5b45f45 built with SONAME_LIBSDL2 (docs/WINECX.md). libSDL2:+ // SDL 2.32.8 (zlib license, NOTICE), the WineHQ engine runner's copy signed ad hoc,+ // since a release build strips unsigned Mach-O resources and would break the pin.+ gamepad: [+ WinecxBundledFile(resource: "winebus-winecx-11.15", ext: "so", path: "lib/wine/x86_64-unix/winebus.so",+ sha256: "1bc53184f5d026ab84a26cf6ef721348fc3b028c019ff969e69eb6cf9b9d1af9"),+ WinecxBundledFile(resource: "libSDL2-2.0.0", ext: "dylib", path: "lib/libSDL2-2.0.0.dylib",+ sha256: "605724f463875e945ca4a79a1db7bf35384d912fa5387f3042a27a42e878db19"),+ ])// Appended to SupportedRunners.all. The hash-pinned loader is what makes it free, so a@@ -175,6 +200,7 @@ enum FreeEngineWinecx {// 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 { 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)@@ -263,6 +289,7 @@ enum FreeEngineWinecx {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, root: root)let libraries = wine.deletingLastPathComponent()for file in release.backends {@@ -319,6 +346,22 @@ enum FreeEngineWinecx {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),diff --git a/app/Sources/NotProtonApp/Resources/libSDL2-2.0.0.dylib b/app/Sources/NotProtonApp/Resources/libSDL2-2.0.0.dylibnew file mode 100755index 0000000..914827aBinary files /dev/null and b/app/Sources/NotProtonApp/Resources/libSDL2-2.0.0.dylib differdiff --git a/app/Sources/NotProtonApp/Resources/winebus-winecx-11.15.so b/app/Sources/NotProtonApp/Resources/winebus-winecx-11.15.sonew file mode 100755index 0000000..b82d43aBinary files /dev/null and b/app/Sources/NotProtonApp/Resources/winebus-winecx-11.15.so differdiff --git a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swiftindex 0c8f603..6eacf6f 100644--- a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift+++ b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift@@ -112,6 +112,39 @@ struct FreeEngineWinecxTests {}}+ // 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")+ func gamepadSupport() throws {+ let files = FreeEngineWinecx.current.gamepad+ #expect(Set(files.map(\.path)) == ["lib/wine/x86_64-unix/winebus.so", "lib/libSDL2-2.0.0.dylib"])+ let table = FreeEngineWinecx.expectedFiles()+ 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)+ for file in files { #expect(before.contains(file.path), "\(file.path)") }++ try FreeEngineWinecx.installBundled(files, root: root)+ let after = FreeEngineWinecx.layoutProblems(root: root)+ 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) }+ }+@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))diff --git a/docs/WINECX.md b/docs/WINECX.mdindex fab4d25..b14b275 100644--- a/docs/WINECX.md+++ b/docs/WINECX.md@@ -58,6 +58,9 @@ lib/wine/x86_64-unix/winemetal.so DXMT master, replacing the arclib/wine/{x86_64,i386}-windows/winemetal.dll DXMT master, replacing the archive'slib/notproton-backends/dxmt/{x86_64,i386}-windows/{d3d11,d3d10core,dxgi}.dll DXMT master, marker strippedlib/notproton-backends/dxvk/{x86_64,i386}-windows/{d3d11,d3d10core}.dll from the archive+lib/wine/x86_64-unix/winemac.so Retina fix, replacing the archive's (below)+lib/wine/x86_64-unix/winebus.so built with SDL2, replacing the archive's (Controllers)+lib/libSDL2-2.0.0.dylib SDL 2.32.8, x86_64, for winebus.so (Controllers)```DXMT comes from `dxmt-e94c312.tar.gz` (the WineHQ engine's pin, shared download cache).@@ -81,6 +84,46 @@ half-size drawable and showed only the top-left quarter. NotProton installs`winemac-patch/winecx-d3dmetal-retina.patch` (`winemac-patch/README.md`), pinned as`FreeEngineWinecx.current.macDriver`.+## Controllers++The runtime's CI built `winebus.so` without SDL2 (`SONAME_LIBSDL2` undefined, its log says+`sdl_bus_init SDL support not compiled in!`), and its XBOX bus needs `IOUSBLib.h`, which the+macOS 26 SDK lacks. A gamepad then had no path into Wine: winebus ignores the IOHID bus's raw+HID device for a gamepad unless that device has `Hidraw=1`, and with it the pad comes in as+`is_hidraw 1, is_gamepad 0`, which XInput never opens.++NotProton installs `winebus-winecx-11.15.so`: winecx `5b45f45`'s own, built with+`SONAME_LIBSDL2` = `libSDL2-2.0.0.dylib`, the name the WineHQ engine's `winebus.so` dlopens.+SDL's bus then presents the pad as a gamepad (`is_gamepad 1`), the device XInput opens.+dyld resolves the leaf name through the caller's `LC_RPATH`s, and `winebus.so` carries+`@loader_path/../../` (the CI adds it to every unix module), so the library sits in `lib/`.+That `libSDL2-2.0.0.dylib` is the WineHQ engine runner's x86_64 SDL 2.32.8 (zlib license,+`NOTICE`), signed ad hoc and otherwise unchanged: a SwiftPM release build runs `strip` on+every unsigned Mach-O resource, which would change its bytes and break the pin. The PE half `winebus.sys` is unchanged: it starts the SDL bus+either way, and only the unix half lacked it.++A per-device `Hidraw=1` under `HKLM\System\CurrentControlSet\Services\winebus\Devices\<vid>/<pid>`+makes winebus take the raw IOHID device and ignore SDL's for that pad, so XInput loses it+again; leave that key off for XInput pads.++To rebuild it, in the configured winecx build tree from `winemac-patch/README.md` (same+flags, `MACOSX_DEPLOYMENT_TARGET=26.0`), compile the unix objects of+`dlls/winebus.sys/winebus.so` with `-DSONAME_LIBSDL2=\"libSDL2-2.0.0.dylib\"` added to+`CFLAGS` and SDL2 2.32 headers on the include path (`SDL2_CFLAGS`; only `bus_sdl.o`+changes), then link and sign the way the runtime's was:++ clang -arch x86_64 -o winebus.so -dynamiclib -install_name @rpath/winebus.so \+ -Wl,-rpath,@loader_path/ dlls/winebus.sys/{bus_iohid,bus_sdl,bus_udev,bus_xbox360,hid,unixlib}.o \+ <runtime>/ntdll.so -framework IOKit -framework CoreFoundation+ codesign -fs - winebus.so+ install_name_tool -add_rpath @loader_path/../../ winebus.so+ codesign -fs - winebus.so++Built this way without the define, the result matches the runtime's `winebus.so` in every+section and in all 171 symbols and their addresses, with the same load commands in the same+order; only `__LINKEDIT`, the UUID and the linker's tool version differ. The pins are+`FreeEngineWinecx.current.gamepad`.+## D3DMetal: the builtin modelApple's forwarders only work as builtins: only a builtin gets its unix half