Files
DroidDeck/tools/dirt-ws2/ws2_32.c
T
MaxsTechReview c5577478ca chore: remove source comments and unused code, translate every missing string (#1965)
* chore(i18n): translate every missing string in all locales

Adds the 87 strings the bottom-screen Dashboard and in-game stats pages
introduced to all 32 locales, plus the 51 older settings strings Japanese
and the 50 Chinese locales were still missing. Every locale now has all
3456 translatable strings with the same placeholders as English.

Also translates 36 entries that were still English where the language
does not use the English word, and makes es-419 touch_app_id use the same
%1$s placeholder as English.

* chore(patches): drop comments from the lines downstream patches add

Removes comment lines and trailing comments from lines our patches add,
with hunk headers recounted. Lines that a later patch uses as context
and the upstream backport 0123 are left as they are.

The gamescope, FEX, proot and xodus series still apply to their pinned
sources, and the patched trees differ only in those comments.
test_hud_frames now finds the HUD writer by its first declaration.

* docs: credit Greenlight, Better xCloud, viture-v2, GameNative and DiRTTelemetryErrorFix

These were credited only in source headers and NOTICE files.

* chore: remove source comments and unused functions

Removes explanatory comments from first-party Kotlin, Java, C, C++,
Rust, TypeScript, Python, shell, Gradle, CMake and workflow files.
License and attribution headers stay, and vendored third-party trees,
generated files and license files are untouched. A shellcheck directive
is kept, and udevmon's fallthrough comments became fallthrough attributes.

Syntax trees and token streams match the previous sources apart from the
comments and Python docstrings. Module docstrings that argparse prints
are kept, and device-smoke.sh prints the same --help text from a heredoc.

Also removes 37 functions and 4 fields that nothing referenced.

* chore: remove comments from the Syncthing integration and the latest main sources

* docs: credit Syncthing and the syncthing-android fork

* chore(i18n): translate the Syncthing strings in all locales

The 107 strings the Syncthing integration added are now in all 32 locales.
sync_web_path_locked names the Syncthing tab by its label.

* docs: credit @xXJSONDeruloXx for the HUD metric readers

The CPU, GPU load, thermal and battery readers come from their
PerformanceHudView pull requests #777, #877, #991, #1406 and #1573.
The FusionHUD credit line is unchanged.

* docs: credit the HUD metric readers to @xXJSONDeruloXx's work
2026-11-01 16:27:27 -05:00

96 lines
3.1 KiB
C

/* 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);
__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);
}
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;
}