From 09225a07d4265a2ffbf1e91fa0c200a2d75d5188 Mon Sep 17 00:00:00 2001 From: OreoFR <29048345+OreoFR@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:37:13 +0100 Subject: [PATCH] ws2_offline: read the Winsock error through host_proc, so gta6rt links without ws2_32 wrap_extension_lookup (#2533) called WSAGetLastError directly. gta6rt does not link ws2_32 (only ws2_offline_test does), so the MSVC link of gta6rt.exe failed with LNK2019 __imp_WSAGetLastError. The shim reaches the host's Winsock through host_proc everywhere else; wsa_last_error does the same, mirroring set_wsa_error, with GetLastError as the fallback. gta6rt.exe imports the same DLLs as before #2533, no WS2_32. Co-authored-by: Tyrannys <80750971+Tyrannys@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- runtime/shims/ws2_offline.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/shims/ws2_offline.cpp b/runtime/shims/ws2_offline.cpp index fc124af135..309525c546 100644 --- a/runtime/shims/ws2_offline.cpp +++ b/runtime/shims/ws2_offline.cpp @@ -87,6 +87,13 @@ void set_wsa_error(int err) { } } +// The host's WSAGetLastError through host_proc, like set_wsa_error: gta6rt does not link ws2_32. +int wsa_last_error() { + using LastErrFn = int(WSAAPI*)(); + static LastErrFn fn = host_proc("WSAGetLastError"); + return fn ? fn() : static_cast(GetLastError()); +} + uint16_t read_be16(uint16_t net_val) { const auto* b = reinterpret_cast(&net_val); return static_cast((static_cast(b[0]) << 8) | b[1]); @@ -876,7 +883,7 @@ int wrap_extension_lookup(Fn real_fn, SOCKET s, DWORD io_control_code, LPVOID in std::memcpy(out_buf, &wrapped, sizeof(wrapped)); const int rc = real_fn(s, io_control_code, in_buf, in_len, &answer->pointer, sizeof(answer->pointer), &answer->returned, overlapped, completion); - const int error = rc == 0 ? 0 : WSAGetLastError(); + const int error = rc == 0 ? 0 : wsa_last_error(); if (rc == 0) { *bytes_returned = sizeof(wrapped); delete answer;