fix(dual-screen): DiRT 3 and DiRT Showdown telemetry no longer stops the game (error 10038)

DiRT 3 and DiRT Showdown keep sending motion telemetry on the UDP socket they
closed at the end of a race (and when leaving Joyride); sendto() fails with
WSAENOTSOCK and the game stops with "sendto failed with error 10038".

- tools/dirt-ws2: a 32-bit ws2_32.dll stand-in. Every export jumps to the
  same-ordinal export of Wine's own ws2_32.dll; only a sendto() failing with
  10038 reports 0 bytes sent. Built in CI (components recipe dirt-ws2, clang +
  lld) with its exports checked against Wine 11's list, staged to
  /usr/local/lib/droiddeck-dirt.
- droiddeck-game-env: for dirt3_game.exe / showdown.exe / showdown_avx.exe
  with the game's UDP/motion output on, and a Proton whose own ws2_32.dll lacks
  the fix, the stand-in replaces the prefix's syswow64/ws2_32.dll (Wine loads
  ws2_32 as a KnownDLL from there, so a copy beside the game is ignored) with
  WINEDLLOVERRIDES=ws2_32=n,b; the launch waits for the game and puts the
  prefix's own file back. A copy left by a killed launch is put back at the
  next launch in that prefix.
- Automatic turns DiRT 3 and DiRT Showdown on like the other games again; the
  crash warning and the switched-on-by-hand memory from the previous build
  are gone.

Same behaviour as DiRTTelemetryErrorFix by RoccoC (MIT), based on the fix by
Carsten Gottschling. DroidDeck-Proton gets the same rule in its own ws2_32
(branch fix/dirt-telemetry-sendto); the swap is skipped there.
This commit is contained in:
The412Banner committed 2026-10-31 21:55:36 +00:00
1 parent 66abf0c707
commit 268dcef559
19 files changed
+664 -53

No files matched your search

+15
View File
@@ -222,5 +222,20 @@
"cmake",
"xz-utils"
]
},
"dirt-ws2": {
"script": "tools/components/recipes/dirt-ws2.sh",
"inputs": [
"tools/dirt-ws2",
"tools/components/recipes/dirt-ws2.sh"
],
"outputs": [
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-dirt/ws2_32.dll"
],
"packages": [
"clang",
"lld",
"llvm"
]
}
}
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
bash tools/dirt-ws2/build.sh app/src/main/assets/linuxfs/usr/local/lib/droiddeck-dirt
+19
View File
@@ -0,0 +1,19 @@
# DiRT 3 / DiRT Showdown ws2_32 stand-in
DiRT 3 (`dirt3_game.exe`) and DiRT Showdown (`showdown.exe`, `showdown_avx.exe`) close their motion telemetry UDP
socket at the end of a race, and when leaving Joyride, but keep calling `sendto()` on it. `sendto()` fails with
WSAENOTSOCK and the game stops with "sendto failed with error 10038". The same happens on Windows.
`ws2_32.dll` here is a 32-bit stand-in: every export jumps to the same-ordinal export of Wine's own `ws2_32.dll`;
only a `sendto()` that fails with 10038 reports 0 bytes sent instead. Same behaviour as
[DiRTTelemetryErrorFix](https://github.com/RoccoC/DiRTTelemetryErrorFix) by RoccoC (MIT), based on the original fix
by Carsten Gottschling.
Wine loads `ws2_32` as a KnownDLL, so a copy beside the game is ignored. `droiddeck-game-env` puts the stand-in in
place of the prefix's `syswow64/ws2_32.dll` for these games while their telemetry output is on, adds
`WINEDLLOVERRIDES=ws2_32=n,b`, and puts Wine's file back when the game exits. It skips the swap when the game's
Proton already has the fix in its own `ws2_32.dll` (DroidDeck-Proton patch
`dirt-telemetry-sendto-closed-socket.patch`).
`build.sh OUT` builds it with clang, lld and llvm-dlltool and checks its exports against `ws2_32-exports.txt`
(taken from Wine 11's `ws2_32.dll`).
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Builds the 32-bit ws2_32.dll stand-in for DiRT 3 and DiRT Showdown into the given folder.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
mkdir -p "$1"
out=$(cd "$1" && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
tool() {
local found
found=$(command -v "$1" || ls /usr/lib/llvm-*/bin/"$1" 2>/dev/null | sort -V | tail -n1 || true)
[ -n "$found" ] || { echo "dirt-ws2: $1 not found" >&2; exit 1; }
echo "$found"
}
clang=$(tool clang)
dlltool=$(tool llvm-dlltool)
tool ld.lld > /dev/null
python3 "$here/gen.py" generate "$here" "$work"
"$dlltool" -m i386 -k -d "$here/kernel32.def" -l "$work/libkernel32.a"
"$clang" --target=i686-w64-mingw32 -O2 -Wall -Wextra -Werror -ffreestanding -fno-stack-protector -fno-builtin \
-nostdlib -shared -fuse-ld=lld -o "$work/ws2_32.dll" "$here/ws2_32.c" "$work/thunks.c" "$work/ws2_32.def" \
-L"$work" -lkernel32 -Wl,--entry,DllMain@12 -Wl,--no-insert-timestamp
python3 "$here/gen.py" verify "$here" "$work/ws2_32.dll"
install -m 644 "$work/ws2_32.dll" "$out/ws2_32.dll"
+74
View File
@@ -0,0 +1,74 @@
"""ws2_32 stand-in helpers.
gen.py generate SRC OUT writes OUT/thunks.c (one jump per export) and OUT/ws2_32.def from SRC/ws2_32-exports.txt.
gen.py verify SRC DLL checks that DLL exports exactly the ordinals and names in SRC/ws2_32-exports.txt.
"""
import struct
import sys
from pathlib import Path
def exports_list(src):
rows = []
for line in (Path(src) / 'ws2_32-exports.txt').read_text().splitlines():
ordinal, name = line.split()
rows.append((int(ordinal), name))
return rows
def generate(src, out):
rows = exports_list(src)
passed = [(o, n) for o, n in rows if n != 'sendto']
c = ['/* Generated by tools/dirt-ws2/gen.py. */',
'const unsigned short dirtfix_ordinals[%d] = {%s};' % (len(passed), ', '.join(str(o) for o, _ in passed)),
'const unsigned int dirtfix_count = %d;' % len(passed),
'void *dirtfix_real[%d];' % len(passed),
'__asm__(".text\\n"']
for i, (o, _) in enumerate(passed):
c.append(' ".globl _dirtfix_t%d\\n_dirtfix_t%d:\\n\\tjmp *_dirtfix_real+%d\\n"' % (o, o, 4 * i))
c.append(');')
(Path(out) / 'thunks.c').write_text('\n'.join(c) + '\n')
d = ['LIBRARY ws2_32.dll', 'EXPORTS']
d += [' %s=%s @%d' % (n, 'dirtfix_sendto@24' if n == 'sendto' else 'dirtfix_t%d' % o, o) for o, n in rows]
(Path(out) / 'ws2_32.def').write_text('\n'.join(d) + '\n')
def pe_exports(path):
data = Path(path).read_bytes()
pe = struct.unpack_from('<I', data, 0x3c)[0]
machine, sections = struct.unpack_from('<HH', data, pe + 4)
optional_size = struct.unpack_from('<H', data, pe + 20)[0]
optional = pe + 24
export_rva = struct.unpack_from('<I', data, optional + 96)[0]
table = [struct.unpack_from('<IIII', data, optional + optional_size + 40 * i + 8) for i in range(sections)]
def offset(rva):
for size, address, raw_size, raw in table:
if address <= rva < address + max(size, raw_size):
return rva - address + raw
raise ValueError('RVA %#x outside the sections' % rva)
base, functions, names, function_rva, name_rva, ordinal_rva = struct.unpack_from('<IIIIII', data, offset(export_rva) + 16)
named = {}
for i in range(names):
text = struct.unpack_from('<I', data, offset(name_rva) + 4 * i)[0]
index = struct.unpack_from('<H', data, offset(ordinal_rva) + 2 * i)[0]
named[index] = data[offset(text):].split(b'\0')[0].decode()
result = [(base + i, named.get(i)) for i in range(functions) if struct.unpack_from('<I', data, offset(function_rva) + 4 * i)[0]]
return machine, result
def verify(src, dll):
machine, found = pe_exports(dll)
if machine != 0x14c:
sys.exit('%s is not a 32-bit x86 DLL (machine %#x)' % (dll, machine))
expected = exports_list(src)
if found != expected:
sys.exit('%s exports differ from ws2_32-exports.txt: %d found, %d expected' % (dll, len(found), len(expected)))
if b'droiddeck-dirt-ws2_32' not in Path(dll).read_bytes():
sys.exit('%s lacks the stand-in marker' % dll)
print('%s: %d exports match, marker present' % (dll, len(found)))
if __name__ == '__main__':
{'generate': generate, 'verify': verify}[sys.argv[1]](sys.argv[2], sys.argv[3])
+7
View File
@@ -0,0 +1,7 @@
LIBRARY kernel32.dll
EXPORTS
LoadLibraryW@4
GetProcAddress@8
GetSystemDirectoryW@8
GetEnvironmentVariableW@12
GetFileAttributesW@4
+135
View File
@@ -0,0 +1,135 @@
1 accept
2 bind
3 closesocket
4 connect
5 getpeername
6 getsockname
7 getsockopt
8 htonl
9 htons
10 ioctlsocket
11 inet_addr
12 inet_ntoa
13 listen
14 ntohl
15 ntohs
16 recv
17 recvfrom
18 select
19 send
20 sendto
21 setsockopt
22 shutdown
23 socket
24 FreeAddrInfoEx
25 FreeAddrInfoExW
26 FreeAddrInfoW
27 GetAddrInfoExCancel
28 GetAddrInfoExOverlappedResult
29 GetAddrInfoExW
30 GetAddrInfoW
31 GetHostNameW
32 GetNameInfoW
33 InetNtopW
34 InetPtonW
35 WSApSetPostRoutine
36 WPUCompleteOverlappedRequest
37 WSAAccept
38 WSAAddressToStringA
39 WSAAddressToStringW
40 WSACloseEvent
41 WSAConnect
42 WSAConnectByNameA
43 WSAConnectByNameW
44 WSACreateEvent
45 WSADuplicateSocketA
46 WSADuplicateSocketW
47 WSAEnumNameSpaceProvidersA
48 WSAEnumNameSpaceProvidersW
49 WSAEnumNetworkEvents
50 WSAEnumProtocolsA
51 gethostbyaddr
52 gethostbyname
53 getprotobyname
54 getprotobynumber
55 getservbyname
56 getservbyport
57 gethostname
58 WSAEnumProtocolsW
59 WSAEventSelect
60 WSAGetOverlappedResult
61 WSAGetQOSByName
62 WSAGetServiceClassInfoA
63 WSAGetServiceClassInfoW
64 WSAGetServiceClassNameByClassIdA
65 WSAGetServiceClassNameByClassIdW
66 WSAHtonl
67 WSAHtons
68 WSAInstallServiceClassA
69 WSAInstallServiceClassW
70 WSAIoctl
71 WSAJoinLeaf
72 WSALookupServiceBeginA
73 WSALookupServiceBeginW
74 WSALookupServiceEnd
75 WSALookupServiceNextA
76 WSALookupServiceNextW
77 WSANSPIoctl
78 WSANtohl
79 WSANtohs
80 WSAPoll
81 WSAProviderConfigChange
82 WSARecv
83 WSARecvDisconnect
84 WSARecvFrom
85 WSARemoveServiceClass
86 WSAResetEvent
87 WSASend
88 WSASendDisconnect
89 WSASendMsg
90 WSASendTo
91 WSASetEvent
92 WSASetServiceA
93 WSASetServiceW
94 WSASocketA
95 WSASocketW
96 WSAStringToAddressA
97 WSAStringToAddressW
98 WSAWaitForMultipleEvents
99 WSCDeinstallProvider
100 WSCEnableNSProvider
101 WSAAsyncSelect
102 WSAAsyncGetHostByAddr
103 WSAAsyncGetHostByName
104 WSAAsyncGetProtoByNumber
105 WSAAsyncGetProtoByName
106 WSAAsyncGetServByPort
107 WSAAsyncGetServByName
108 WSACancelAsyncRequest
109 WSASetBlockingHook
110 WSAUnhookBlockingHook
111 WSAGetLastError
112 WSASetLastError
113 WSACancelBlockingCall
114 WSAIsBlocking
115 WSAStartup
116 WSACleanup
117 WSCEnumProtocols
118 WSCEnumProtocols32
119 WSCGetApplicationCategory
120 WSCGetProviderInfo
121 WSCGetProviderPath
122 WSCInstallNameSpace
123 WSCInstallProvider
124 WSCSetApplicationCategory
125 WSCUnInstallNameSpace
126 WSCUpdateProvider
127 WSCWriteNameSpaceOrder
128 WSCWriteProviderOrder
129 freeaddrinfo
130 getaddrinfo
131 getnameinfo
132 inet_ntop
133 inet_pton
151 __WSAFDIsSet
500 WEP
+103
View File
@@ -0,0 +1,103 @@
/* ws2_32.dll stand-in for DiRT 3 and DiRT Showdown (32-bit).
*
* Both games close their motion telemetry UDP socket at the end of a race (and when leaving Joyride) and keep
* calling sendto() on it; the WSAENOTSOCK (10038) failure stops the game. Every export here jumps to the
* same-ordinal export of Wine's own ws2_32.dll, except that a sendto() failing with 10038 reports 0 bytes sent.
* Same behaviour as DiRTTelemetryErrorFix by RoccoC (MIT), based on the fix by Carsten Gottschling. */
typedef unsigned short WCHAR;
typedef unsigned long DWORD;
typedef unsigned int UINT;
typedef unsigned int UINT_PTR;
typedef int BOOL;
typedef void *HMODULE;
#define WINAPI __attribute__((stdcall))
#define WSAENOTSOCK 10038
#define ORDINAL(n) ((const char *)(UINT_PTR)(n))
__attribute__((dllimport)) HMODULE WINAPI LoadLibraryW(const WCHAR *name);
__attribute__((dllimport)) void *WINAPI GetProcAddress(HMODULE module, const char *name);
__attribute__((dllimport)) UINT WINAPI GetSystemDirectoryW(WCHAR *buffer, UINT size);
__attribute__((dllimport)) DWORD WINAPI GetEnvironmentVariableW(const WCHAR *name, WCHAR *buffer, DWORD size);
__attribute__((dllimport)) DWORD WINAPI GetFileAttributesW(const WCHAR *name);
/* droiddeck-game-env recognises a swapped-in copy by this text. */
__attribute__((used)) const char dirtfix_marker[] = "droiddeck-dirt-ws2_32";
extern const unsigned short dirtfix_ordinals[];
extern const unsigned int dirtfix_count;
extern void *dirtfix_real[];
static int (WINAPI *real_sendto)(UINT_PTR, const char *, int, int, const void *, int);
static int (WINAPI *real_WSAGetLastError)(void);
static void (WINAPI *real_WSASetLastError)(int);
int WINAPI dirtfix_sendto(UINT_PTR s, const char *buf, int len, int flags, const void *to, int tolen)
{
int ret = real_sendto(s, buf, len, flags, to, tolen);
if (ret == -1 && real_WSAGetLastError() == WSAENOTSOCK)
{
real_WSASetLastError(0);
return 0;
}
return ret;
}
static void append(WCHAR *dst, const char *src)
{
while (*dst) dst++;
while ((*dst++ = (WCHAR)(unsigned char)*src++));
}
static void append_number(WCHAR *dst, UINT n)
{
char digits[12];
int i = 11;
digits[i] = 0;
do digits[--i] = (char)('0' + n % 10); while (n /= 10);
append(dst, digits + i);
}
/* When this file replaces the prefix's syswow64\ws2_32.dll, Wine's own copy is the i386-windows\ws2_32.dll in one
* of the builtin DLL folders Wine lists in WINEDLLDIR0, WINEDLLDIR1, ... as NT paths (\??\Z:\...). */
static HMODULE load_wine_ws2_32(HMODULE self)
{
WCHAR name[24], path[600];
HMODULE real;
UINT n, d;
for (d = 0; d < 16; d++)
{
name[0] = 0;
append(name, "WINEDLLDIR");
append_number(name, d);
n = GetEnvironmentVariableW(name, path, 500);
if (!n || n >= 500) continue;
if (path[0] == '\\' && path[1] == '?' && path[2] == '?' && path[3] == '\\') path[1] = '\\';
append(path, "\\i386-windows\\ws2_32.dll");
if (GetFileAttributesW(path) == (DWORD)-1) continue;
if ((real = LoadLibraryW(path)) && real != self) return real;
}
n = GetSystemDirectoryW(path, 280);
if (!n || n >= 280) return 0;
path[n] = 0;
append(path, "\\ws2_32.dll");
real = LoadLibraryW(path);
return real != self ? real : 0;
}
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *reserved)
{
HMODULE real;
UINT i;
(void)reserved;
if (reason != 1) return 1;
if (!(real = load_wine_ws2_32(self))) return 0;
for (i = 0; i < dirtfix_count; i++) dirtfix_real[i] = GetProcAddress(real, ORDINAL(dirtfix_ordinals[i]));
real_sendto = GetProcAddress(real, ORDINAL(20));
real_WSAGetLastError = GetProcAddress(real, ORDINAL(111));
real_WSASetLastError = GetProcAddress(real, ORDINAL(112));
return real_sendto && real_WSAGetLastError && real_WSASetLastError;
}
@@ -4,6 +4,7 @@ import json
import os
import re
import runpy
import signal
import subprocess
import sys
import tempfile
@@ -735,7 +736,121 @@ def directaudio_settings(env):
return env
def start(launch, launch_env, digest):
DIRT_GAMES = {"dirt3_game": "dirt3", "showdown": "dirtshowdown", "showdown_avx": "dirtshowdown"}
DIRT_WS2 = "/usr/local/lib/droiddeck-dirt/ws2_32.dll"
DIRT_MARKER = b"droiddeck-dirt-ws2_32"
DIRT_FIXED = "showdown_avx.exe".encode("utf-16-le")
DIRT_SAVED = ".droiddeck-original"
def dirt_telemetry_on(prefix, game):
"""Whether the game's UDP/motion output is on, as In-game stats or another listener sets it ("dbox" is its default)."""
try:
folders = [f for f in (Path(prefix) / "pfx/drive_c/users/steamuser/Documents/My Games").iterdir()
if f.name.lower().replace(" ", "") == game]
except OSError:
return False
for folder in folders:
try:
text = (folder / "hardwaresettings/hardware_settings_config.xml").read_text(encoding="latin-1")
except OSError:
continue
for tag in ("udp", "motion"):
element = re.search(r"<%s\s[^>]*>" % tag, text)
if element:
attrs = dict(re.findall(r'\s(\w+)="([^"]*)"', element.group(0)))
return attrs.get("enabled") == "true" and attrs.get("ip", "").lower() not in ("", "dbox")
return False
def proton_ws2(proton):
return Path(proton).parent / "files/lib/wine/i386-windows/ws2_32.dll"
def proton_has_dirt_fix(proton):
try:
return DIRT_FIXED in proton_ws2(proton).read_bytes()
except OSError:
return False
def prefix_ws2(prefix):
return Path(prefix) / "pfx/drive_c/windows/syswow64/ws2_32.dll"
def is_dirt_stand_in(path):
try:
return not path.is_symlink() and DIRT_MARKER in path.read_bytes()
except OSError:
return False
def dirt_ws2_wanted(command, env):
"""The prefix to give the ws2_32 stand-in: a DiRT 3 / Showdown launch with telemetry on and a Proton without the fix."""
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
if len(command) < 3 or not prefix or not os.path.isfile(DIRT_WS2):
return None
game = DIRT_GAMES.get(os.path.splitext(os.path.basename(command[2]))[0].lower())
if not game or not dirt_telemetry_on(prefix, game) or proton_has_dirt_fix(command[0]):
return None
return prefix if os.path.lexists(prefix_ws2(prefix)) else None
def swap_dirt_ws2(prefix):
"""Puts the stand-in where the prefix's syswow64/ws2_32.dll is; that file is kept beside it."""
target = prefix_ws2(prefix)
saved = target.with_name(target.name + DIRT_SAVED)
data = Path(DIRT_WS2).read_bytes()
if not is_dirt_stand_in(target):
if os.path.lexists(saved):
os.unlink(saved)
os.replace(target, saved)
staged = target.with_name(target.name + ".droiddeck-tmp")
staged.write_bytes(data)
os.replace(staged, target)
def restore_dirt_ws2(prefix, proton):
"""Puts the prefix's own syswow64/ws2_32.dll back if the stand-in is still there; true when it changed something."""
target = prefix_ws2(prefix)
saved = target.with_name(target.name + DIRT_SAVED)
if os.path.lexists(saved):
if is_dirt_stand_in(target) or not os.path.lexists(target):
os.replace(saved, target)
return True
os.unlink(saved)
return False
own = proton_ws2(proton)
if is_dirt_stand_in(target) and own.is_file():
link = target.with_name(target.name + ".droiddeck-tmp")
if os.path.lexists(link):
os.unlink(link)
os.symlink(own, link)
os.replace(link, target)
return True
return False
def wait_forwarding_signals(process):
def forward(signum, frame):
try:
process.send_signal(signum)
except OSError:
pass
for signum in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
signal.signal(signum, forward)
code = process.wait()
return 128 - code if code < 0 else code
def start(launch, launch_env, digest, after=None):
if after:
process = subprocess.Popen(launch, env=launch_env)
try:
return wait_forwarding_signals(process)
finally:
after()
if digest:
code = subprocess.run(launch, env=launch_env, check=False).returncode
if code == 0:
@@ -760,6 +875,7 @@ def main():
except OSError:
digest = None
app_id = game_id(env)
dirt_prefix = None
if app_id:
gl_default = gl_vsync(env)
waiting = len(command) > 1 and command[1] == "waitforexitandrun"
@@ -779,6 +895,10 @@ def main():
if components:
own = fixes.get("WINEDLLOVERRIDES")
fixes["WINEDLLOVERRIDES"] = components + ";" + own if own else components
dirt_prefix = dirt_ws2_wanted(command, env)
if dirt_prefix:
own = fixes.get("WINEDLLOVERRIDES")
fixes["WINEDLLOVERRIDES"] = own + ";ws2_32=n,b" if own else "ws2_32=n,b"
path = Path.home() / ".config/droiddeck/game-environment.json"
config = {}
try:
@@ -823,16 +943,29 @@ def main():
return 1
if xbox_result is not None:
return xbox_result
after = None
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
if app_id and prefix and len(command) > 1 and command[1] == "waitforexitandrun":
try:
if dirt_prefix:
swap_dirt_ws2(dirt_prefix)
after = lambda: restore_dirt_ws2(dirt_prefix, command[0])
print("droiddeck-game-env: DiRT telemetry fix: ws2_32 stand-in in the prefix until the game exits",
file=sys.stderr)
elif restore_dirt_ws2(prefix, command[0]):
print("droiddeck-game-env: DiRT telemetry fix: put the prefix's own ws2_32 back", file=sys.stderr)
except OSError as error:
print("droiddeck-game-env: DiRT telemetry fix not applied (%s)" % error, file=sys.stderr)
sync = load_sync()
launch, launch_env = select_sync(command, env, sync)
if launch[0] != command[0]:
try:
return start(launch, launch_env, digest)
return start(launch, launch_env, digest, after)
except OSError as error:
print("droiddeck-game-env: %s could not start (%s); stock launch" % (launch[0], error), file=sys.stderr)
launch, launch_env = command, without_pack(launch_env, env)
record_stock(sync, launch, launch_env)
return start(launch, launch_env, digest)
return start(launch, launch_env, digest, after)
if __name__ == "__main__":
+1 -1
View File
@@ -23,7 +23,7 @@ PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet', 'butler']
SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app/src/main/assets/pulseaudio.tzst',
'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs',
'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env',
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/components', 'tools/ci', 'tools/build_local.sh',
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/dirt-ws2', 'tools/components', 'tools/ci', 'tools/build_local.sh',
'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal',
'tools/quest', 'tools/vr/src', 'tools/vr/driver_droiddeck', 'tools/vr/layer', 'tools/vr/build.sh',
'app/src/main/cpp/waylandcomp/src/headpose_shm.h',
+132
View File
@@ -29,6 +29,138 @@ def config_text(entries):
return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping
class DirtTelemetryFixTest(unittest.TestCase):
SHOWDOWN_ON = '<x><motion enabled="true" ip="127.0.0.1" port="20777" delay="1" extradata="3" /></x>'
SHOWDOWN_DEFAULT = '<x><motion enabled="true" ip="dbox" port="20777" delay="1" extradata="0" /></x>'
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
root = Path(self.tmp.name)
self.prefix = root / "compatdata/2848447563"
self.proton = root / "Proton/proton"
self.own = root / "Proton/files/lib/wine/i386-windows/ws2_32.dll"
self.own.parent.mkdir(parents=True)
self.own.write_bytes(b"MZ wine ws2_32")
self.proton.write_text("")
self.target = self.prefix / "pfx/drive_c/windows/syswow64/ws2_32.dll"
self.target.parent.mkdir(parents=True)
self.target.symlink_to(self.own)
self.stand_in = root / "droiddeck-dirt/ws2_32.dll"
self.stand_in.parent.mkdir()
self.stand_in.write_bytes(b"MZ droiddeck-dirt-ws2_32 stand-in")
self.patch = mock.patch.dict(MODULE["dirt_ws2_wanted"].__globals__, {"DIRT_WS2": str(self.stand_in)})
self.patch.start()
def tearDown(self):
self.patch.stop()
self.tmp.cleanup()
def config(self, folder, text):
path = self.prefix / "pfx/drive_c/users/steamuser/Documents/My Games" / folder / "hardwaresettings/hardware_settings_config.xml"
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text)
def command(self, exe="showdown.exe"):
return [str(self.proton), "waitforexitandrun", "/root/Storage/games/DiRT Showdown/" + exe]
def env(self):
return {"STEAM_COMPAT_DATA_PATH": str(self.prefix)}
def test_telemetry_counts_as_on_when_the_game_sends_somewhere(self):
self.config("DiRT Showdown", self.SHOWDOWN_DEFAULT)
self.assertFalse(MODULE["dirt_telemetry_on"](self.prefix, "dirtshowdown"))
self.config("DiRT Showdown", self.SHOWDOWN_ON)
self.assertTrue(MODULE["dirt_telemetry_on"](self.prefix, "dirtshowdown"))
self.config("DiRT Showdown", self.SHOWDOWN_ON.replace('enabled="true"', 'enabled="false"'))
self.assertFalse(MODULE["dirt_telemetry_on"](self.prefix, "dirtshowdown"))
self.config("DiRT3", '<x><motion enabled="true" ip="192.168.1.20" port="20777" /></x>')
self.assertTrue(MODULE["dirt_telemetry_on"](self.prefix, "dirt3"))
def test_stand_in_is_wanted_only_for_the_dirt_games_with_telemetry_on_and_a_proton_without_the_fix(self):
wanted = MODULE["dirt_ws2_wanted"]
self.config("DiRT Showdown", self.SHOWDOWN_DEFAULT)
self.assertIsNone(wanted(self.command(), self.env()))
self.config("DiRT Showdown", self.SHOWDOWN_ON)
self.assertEqual(wanted(self.command(), self.env()), str(self.prefix))
self.assertEqual(wanted(self.command("Showdown_AVX.exe"), self.env()), str(self.prefix))
self.assertIsNone(wanted(self.command("DiRTRally2.exe"), self.env()))
self.own.write_bytes(b"MZ wine ws2_32 " + "showdown_avx.exe".encode("utf-16-le"))
self.assertIsNone(wanted(self.command(), self.env()))
def test_swap_keeps_the_prefix_link_and_restore_puts_it_back(self):
MODULE["swap_dirt_ws2"](self.prefix)
saved = self.target.with_name("ws2_32.dll.droiddeck-original")
self.assertFalse(self.target.is_symlink())
self.assertEqual(self.target.read_bytes(), self.stand_in.read_bytes())
self.assertEqual(os.readlink(saved), str(self.own))
self.assertEqual(self.own.read_bytes(), b"MZ wine ws2_32")
MODULE["swap_dirt_ws2"](self.prefix)
self.assertEqual(os.readlink(saved), str(self.own))
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
self.assertEqual(os.readlink(self.target), str(self.own))
self.assertFalse(os.path.lexists(saved))
self.assertFalse(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
def test_restore_keeps_a_file_proton_put_back_meanwhile(self):
MODULE["swap_dirt_ws2"](self.prefix)
newer = self.own.with_name("ws2_32-newer.dll")
newer.write_bytes(b"MZ newer wine ws2_32")
self.target.unlink()
self.target.symlink_to(newer)
self.assertFalse(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
self.assertEqual(os.readlink(self.target), str(newer))
self.assertFalse(os.path.lexists(self.target.with_name("ws2_32.dll.droiddeck-original")))
def test_a_stand_in_left_without_the_saved_link_is_replaced_by_protons_own_file(self):
self.target.unlink()
self.target.write_bytes(self.stand_in.read_bytes())
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
self.assertEqual(os.readlink(self.target), str(self.own))
def test_launch_swaps_the_stand_in_in_for_the_game_and_back_afterwards(self):
self.config("DiRT Showdown", self.SHOWDOWN_ON)
self.proton.write_text("#!" + sys.executable + "\nimport os, sys\n"
"target = os.path.join(os.environ['STEAM_COMPAT_DATA_PATH'], 'pfx/drive_c/windows/syswow64/ws2_32.dll')\n"
"print(os.environ.get('WINEDLLOVERRIDES', ''))\n"
"print(os.path.islink(target), b'droiddeck-dirt-ws2_32' in open(target, 'rb').read())\n")
self.proton.chmod(0o755)
runner = Path(self.tmp.name) / "run.py"
runner.write_text("import runpy, sys\nmain = runpy.run_path(sys.argv[1])['main']\nmain.__globals__['DIRT_WS2'] = sys.argv[2]\n"
"sys.argv = [sys.argv[1]] + sys.argv[3:]\nsys.exit(main())\n")
home = Path(self.tmp.name) / "home"
home.mkdir()
result = subprocess.run([sys.executable, str(runner), str(BIN / "droiddeck-game-env"), str(self.stand_in), *self.command()],
env={**os.environ, "HOME": str(home), "STEAM_COMPAT_DATA_PATH": str(self.prefix)}, text=True, capture_output=True)
self.assertEqual(result.returncode, 0, result.stderr)
overrides, state = result.stdout.splitlines()[-2:]
self.assertIn("ws2_32=n,b", overrides.split(";"))
self.assertEqual(state, "False True")
self.assertIn("DiRT telemetry fix: ws2_32 stand-in", result.stderr)
self.assertEqual(os.readlink(self.target), str(self.own))
self.assertFalse(os.path.lexists(self.target.with_name("ws2_32.dll.droiddeck-original")))
def test_launch_with_telemetry_off_leaves_the_prefix_alone(self):
self.config("DiRT Showdown", self.SHOWDOWN_DEFAULT)
self.proton.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ.get('WINEDLLOVERRIDES', ''))\n")
self.proton.chmod(0o755)
home = Path(self.tmp.name) / "home"
home.mkdir()
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), *self.command()],
env={**os.environ, "HOME": str(home), "STEAM_COMPAT_DATA_PATH": str(self.prefix)}, text=True, capture_output=True)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertNotIn("ws2_32=n,b", result.stdout)
self.assertEqual(os.readlink(self.target), str(self.own))
def test_start_puts_the_file_back_after_the_game_exits(self):
calls = []
code = MODULE["start"]([sys.executable, "-c", "raise SystemExit(3)"], dict(os.environ), None, lambda: calls.append("restored"))
self.assertEqual(code, 3)
self.assertEqual(calls, ["restored"])
with self.assertRaises(OSError):
MODULE["start"]([str(Path(self.tmp.name) / "missing")], dict(os.environ), None, lambda: calls.append("again"))
self.assertEqual(calls, ["restored"])
class GameDebugLoggingTest(unittest.TestCase):
def test_maintenance_precision_survives_run_with_performance_game_settings(self):
with tempfile.TemporaryDirectory() as tmp: