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 <noreply@anthropic.com>
This commit is contained in:
OreoFR
2026-11-29 00:37:13 +01:00
parent a9e247cd69
commit 09225a07d4

View File

@ -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<LastErrFn>("WSAGetLastError");
return fn ? fn() : static_cast<int>(GetLastError());
}
uint16_t read_be16(uint16_t net_val) {
const auto* b = reinterpret_cast<const uint8_t*>(&net_val);
return static_cast<uint16_t>((static_cast<uint16_t>(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;