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(ws2_32): own host name no longer resolves to loopback first (TEKKEN 8 ranked)
raymondchinsef24f57694ef
diff --git a/app/Package.swift b/app/Package.swiftindex 8baf44e..af95a05 100644--- a/app/Package.swift+++ b/app/Package.swift@@ -50,6 +50,7 @@ let package = Package(.copy("Resources/winemac-winecx-11.17.so"),.copy("Resources/winebus-winecx-11.17.so"),.copy("Resources/winebus-winecx-11.17.sys"),+ .copy("Resources/ws2_32-winecx-11.17.dll"),.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 a644dec..acf2d93 100644--- a/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift+++ b/app/Sources/NotProtonApp/Model/FreeEngineWinecx.swift@@ -55,6 +55,10 @@ struct WinecxRelease: Sendable {// 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@@ -143,6 +147,12 @@ enum FreeEngineWinecx {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",@@ -229,6 +239,7 @@ enum FreeEngineWinecx {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(@@ -321,7 +332,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.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)@@ -410,7 +421,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)+ try installBundled(release.gamepad + release.network, root: root)let libraries = wine.deletingLastPathComponent()for file in release.backends {diff --git a/app/Sources/NotProtonApp/Resources/ws2_32-winecx-11.17.dll b/app/Sources/NotProtonApp/Resources/ws2_32-winecx-11.17.dllnew file mode 100755index 0000000..69e6d59Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/ws2_32-winecx-11.17.dll differdiff --git a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swiftindex 8f71de9..31f221a 100644--- a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift+++ b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift@@ -180,6 +180,35 @@ struct FreeEngineWinecxTests {#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))diff --git a/docs/WINECX.md b/docs/WINECX.mdindex 1bf5f67..6ca7b35 100644--- a/docs/WINECX.md+++ b/docs/WINECX.md@@ -97,6 +97,7 @@ lib/notproton-backends/dxvk/{x86_64,i386}-windows/{d3d11,d3d10core}.dll flib/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/wine/x86_64-windows/winebus.sys 11.17 only: map-key fix, replacing the archive's (Controllers)+lib/wine/x86_64-windows/ws2_32.dll 11.17 only: own host name without loopback, replacing the archive's (Own host name)lib/libSDL2-2.0.0.dylib SDL 2.32.8, x86_64, for winebus.so (Controllers)```@@ -175,6 +176,29 @@ then corrupted the heap and took winebus, and every pad, down. Wine master stillis byte-identical to the runtime's `winebus.sys` except the PE timestamp, checksum and buildid. 11.15 keeps the runtime's own `winebus.sys`, so the `map` key is still unsafe there.+## Own host name++macOS resolves the machine's own name (`gethostname()`, `<name>.local`) to lo0's addresses+first: `getaddrinfo` in a Windows program returned `::1`, `fe80::1`, `127.0.0.1`, `127.0.2.2`,+`127.0.2.3`, then the LAN address. Windows never returns loopback for its own name. TEKKEN 8's+online SDK takes the first result as its local IP and ranked matchmaking hangs; a hand-made+`/etc/hosts` line for the LAN address fixed it, but that pins a DHCP address.++11.17 ships `ws2_32-winecx-11.17.dll` as `lib/wine/x86_64-windows/ws2_32.dll`: winecx+`e0aa380`'s PE half with `ws2_32-patch/winecx-own-hostname.patch`. For the own host name+(case-insensitive, with or without `.local`, or its first label, and `""`) `getaddrinfo`, and+through it `GetAddrInfoW` and `GetAddrInfoExW`, drops loopback and IPv6 link-local results+while a routable one remains, keeping the order (`ws2_32-patch/README.md`). `localhost` and+`NULL` still return loopback, as on Windows. The unix half is unchanged. The pin is the+release's `network`.++Built by the tree's own rule in a tree configured as in `winemac-patch/README.md` (mingw-w64+gcc 16.2, `make dlls/ws2_32/x86_64-windows/ws2_32.dll`), then+`x86_64-w64-mingw32-strip --strip-debug` as the CI does. Built without the patch, every section+is byte-identical to the runtime's `ws2_32.dll`; only the PE timestamp, checksum and build id+differ, and the runtime's `.eh_frame` section name is cut to `.eh_fram` (10 bytes of string+table). 11.15 keeps the runtime's own `ws2_32.dll`, so it still answers loopback first.+## D3DMetal: the builtin modelApple's forwarders only work as builtins: only a builtin gets its unix half@@ -325,6 +349,7 @@ python3 apply.py <ntdll.dll> <out> <detour bin> # patched hashes| `winemac-winecx-11.17.so` | `aa192f846ad15d56de200fc92752eaf2d455700846ae2cf1ccc7b27b535f1c00` || `winebus-winecx-11.17.so` | `6223c035c824c90708abbc3e733f8d1d6ed6b8b4e9a3e1a5c813493ceba50473` || `winebus-winecx-11.17.sys` | `da108d1c3788fa32807ef08c4d26d8a89812c230317ffa7ba5111e126bda607c` |+| `ws2_32-winecx-11.17.dll` | `cb0a5670ce6dbf949ed25cca54e9f1c4930cd4c2ade895836d518d3d9073079c` |4.5.125 (`winecx-11.15`):diff --git a/ws2_32-patch/README.md b/ws2_32-patch/README.mdnew file mode 100644index 0000000..d460abf--- /dev/null+++ b/ws2_32-patch/README.md@@ -0,0 +1,18 @@+# ws2_32-patch++`winecx-own-hostname.patch` changes `getaddrinfo()` in `dlls/ws2_32/protocol.c` (the PE half).+On macOS the host's resolver answers this machine's own name (`gethostname()`, e.g.+`<name>.local`) with lo0's addresses first (`::1`, `fe80::1`, `127.0.0.1`, `127.0.2.x`) and the+real ones after them. Windows never returns loopback for its own name, and programs take the+first result as their local address: TEKKEN 8's online SDK then hangs in ranked matchmaking.++When the queried name is the local host name (as `gethostname()` or the DNS FQDN returns it,+case-insensitive, with or without `.local`, or its first label; `""` too, which Wine already+maps to the FQDN), the patch drops loopback (`127.0.0.0/8`, `::1`, `::ffff:127.x`) and IPv6+link-local (`fe80::/10`) results while a routable one remains, else only loopback while any+other remains, else changes nothing. Order is kept. `localhost`, other names, numeric hosts+and `NULL` are untouched. `GetAddrInfoW`, `GetAddrInfoExW` and their async forms go through+the same `getaddrinfo()`. `gethostbyname()` of the own name already answers from the routing+table (`get_local_ips`) and is unchanged. Wine master and Proton 10 have no such change+(checked 2026-10-11). Against winecx `e0aa380`; the build and pin are in `docs/WINECX.md`+(Own host name).diff --git a/ws2_32-patch/winecx-own-hostname.patch b/ws2_32-patch/winecx-own-hostname.patchnew file mode 100644index 0000000..393a211--- /dev/null+++ b/ws2_32-patch/winecx-own-hostname.patch@@ -0,0 +1,118 @@+diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c+index cdc01a8..e2168ae 100644+--- a/dlls/ws2_32/protocol.c++++ b/dlls/ws2_32/protocol.c+@@ -67,6 +67,103 @@ static int do_getaddrinfo( const char *node, const char *service,+ }+ }+++/* strip a trailing ".local" (the mDNS domain macOS appends to the host name) */++static size_t hostname_len_without_local( const char *name )++{++ size_t len = strlen( name );++++ if (len > 6 && !strcasecmp( name + len - 6, ".local" )) len -= 6;++ return len;++}++++/* whether name is this machine's own host name: the same as host (case-insensitive, with++ * or without ".local"), or its first label */++static BOOL hostname_matches( const char *name, const char *host )++{++ size_t name_len = hostname_len_without_local( name ), host_len = hostname_len_without_local( host );++++ if (!name_len || !host_len || name_len > host_len) return FALSE;++ if (strncasecmp( name, host, name_len )) return FALSE;++ return name_len == host_len || host[name_len] == '.';++}++++static BOOL is_own_hostname( const char *node, const char *fqdn )++{++ char hostname[256];++ struct gethostname_params params = { hostname, sizeof(hostname) };++++ if (!node || !node[0]) return FALSE;++ if (fqdn && hostname_matches( node, fqdn )) return TRUE;++ if (WS_CALL( gethostname, ¶ms )) return FALSE;++ return hostname_matches( node, hostname );++}++++static BOOL is_loopback_addr( const struct sockaddr *addr )++{++ if (addr->sa_family == AF_INET)++ return ((const struct sockaddr_in *)addr)->sin_addr.S_un.S_un_b.s_b1 == 127;++ if (addr->sa_family == AF_INET6)++ {++ const IN6_ADDR *a = &((const struct sockaddr_in6 *)addr)->sin6_addr;++ static const BYTE v4mapped[12] = {0,0,0,0,0,0,0,0,0,0,0xff,0xff};++ static const BYTE loopback6[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};++++ if (!memcmp( a->u.Byte, loopback6, 16 )) return TRUE;++ return !memcmp( a->u.Byte, v4mapped, 12 ) && a->u.Byte[12] == 127;++ }++ return FALSE;++}++++static BOOL is_linklocal6_addr( const struct sockaddr *addr )++{++ const IN6_ADDR *a = &((const struct sockaddr_in6 *)addr)->sin6_addr;++++ return addr->sa_family == AF_INET6 && a->u.Byte[0] == 0xfe && (a->u.Byte[1] & 0xc0) == 0x80;++}++++/* NotProton: on macOS the host's resolver answers this machine's own name (<host>.local)++ * with lo0's addresses first (::1, fe80::1, 127.0.0.1, ...), then the real ones. Windows++ * never returns loopback for its own name, and programs take the first result as their++ * local address (TEKKEN 8's matchmaking SDK then hangs). Drop loopback and IPv6 link-local++ * results while a routable one remains, else only loopback while any other remains,++ * keeping the order. The list is one block freed through its head, so the kept entries++ * are copied into the leading nodes and the list is cut after them. */++static void filter_own_host_addrinfo( struct addrinfo *info )++{++ struct addrinfo **nodes, *kept, *ai;++ char *canonname = info->ai_canonname;++ unsigned int count = 0, keep = 0, i, pass;++++ for (ai = info; ai; ai = ai->ai_next) count++;++ if (!(nodes = malloc( count * (sizeof(*nodes) + sizeof(*kept)) ))) return;++ kept = (struct addrinfo *)(nodes + count);++++ for (i = 0, ai = info; ai; ai = ai->ai_next) nodes[i++] = ai;++ for (pass = 0; pass < 2 && !keep; pass++)++ {++ for (i = 0; i < count; i++)++ {++ const struct sockaddr *addr = nodes[i]->ai_addr;++++ if (!addr || is_loopback_addr( addr )) continue;++ if (!pass && is_linklocal6_addr( addr )) continue;++ kept[keep++] = *nodes[i];++ }++ }++++ if (keep && keep < count)++ {++ TRACE( "dropping %u loopback/link-local results of %u for the local host name\n", count - keep, count );++ for (i = 0; i < keep; i++)++ {++ *nodes[i] = kept[i];++ nodes[i]->ai_next = i + 1 < keep ? nodes[i + 1] : NULL;++ }++ if (!info->ai_canonname) info->ai_canonname = canonname;++ }++ free( nodes );++}+++ static int dns_only_query( const char *node, const struct addrinfo *hints, struct addrinfo **result )+ {+ DNS_STATUS status;+@@ -219,6 +316,9 @@ int WINAPI getaddrinfo( const char *node, const char *service,+ }+ }+++ if (!ret && *info && is_own_hostname( node, fqdn ))++ filter_own_host_addrinfo( *info );+++ free( fqdn );+ free( nodev6 );+