Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

Steam support: switch to wine-stable + steamwebhelper wrapper

mikey926dad14a8cdf0
diff --git a/README.ko.md b/README.ko.md
index 45a52513ebe..40124a42f0b 100644
--- a/README.ko.md
+++ b/README.ko.md
@@ -58,6 +58,18 @@ scripts/play.sh kill # 전부 종료
이미 CrossOver 보틀에 게임이 설치돼 있다면 `scripts/setup-bottle.sh`로 복제하세요 (28GB 재다운로드 회피).
+## Steam 지원 (Steam판 D2R 포함)
+
+D2R은 2026년 2월 Steam에도 *Infernal Edition*으로 출시됐습니다. Steam은 **다른 무료 엔진**을 씁니다: 최신 Steam 클라이언트의 CEF UI는 CrossOver 소스 계열 빌드에서 렌더링되지 않지만(검은 창 — 크로스 프로세스 스왑체인 + CEF 샌드박스 문제), homebrew `wine-stable` 11 + `steamwebhelper` 래퍼(`--disable-gpu --single-process` 강제)로는 동작합니다. 이 해법은 [notpop/steam-on-m1-wine](https://github.com/notpop/steam-on-m1-wine)(MIT, 래퍼 소스는 `third_party/`에 동봉)에서 왔습니다. Steam은 별도 보틀이라 두 스택이 서로 간섭하지 않습니다:
+
+```bash
+scripts/create-steam-bottle.sh # wine-stable + 래퍼 + Valve 공식 설치기
+scripts/play.sh steam # 로그인 → 게임 설치·플레이
+scripts/play.sh steam-kill # Steam 보틀 종료
+```
+
+검증: M4 Pro / macOS 26.5 — 로그인 UI 렌더링·인증 확인. 참고: Steam 입력 시 macOS 입력기를 영어(ABC)로 전환하세요 (한글 IME 조합이 `?`로 보입니다). 게임(D3D11) 렌더링까지 가려면 업스트림 프로젝트의 DXMT 포크 빌드가 추가로 필요할 수 있습니다 — 해당 레포의 `docs/building-for-games.md` 참고.
+
**전제조건**: Apple Silicon 맥, Rosetta 2, Xcode CLT, Homebrew, 본인 배틀넷 계정, GPTK용 무료 Apple ID.
### GPTK가 왜 필요한가?
diff --git a/README.md b/README.md
index 842f9e22ed5..a3b7bca4ac8 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,18 @@ scripts/play.sh kill # stop everything
Already have a CrossOver bottle with games installed? `scripts/setup-bottle.sh` clones it (28 GB game re-download avoided).
+## Steam (including the Steam version of D2R)
+
+D2R shipped on Steam in Feb 2026 as the *Infernal Edition*. Steam support uses a **different free engine**: the modern Steam client's CEF UI does not render on CrossOver-source builds (black window — cross-process swapchain + CEF sandbox issues), but it works on Homebrew's `wine-stable` 11 with a tiny `steamwebhelper` wrapper that forces `--disable-gpu --single-process`. That fix comes from [notpop/steam-on-m1-wine](https://github.com/notpop/steam-on-m1-wine) (MIT — wrapper source vendored in `third_party/`). Steam gets its own bottle so the two stacks never interfere:
+
+```bash
+scripts/create-steam-bottle.sh # installs wine-stable + wrapper + official Valve installer
+scripts/play.sh steam # log in -> install & play
+scripts/play.sh steam-kill # stop the Steam bottle
+```
+
+Verified on M4 Pro / macOS 26.5: login UI renders and authenticates. Notes: switch your macOS input source to English (ABC) when typing in Steam (IME composition shows as `?` otherwise). D3D11 game rendering under this stack may additionally want the DXMT fork from the upstream project — see their `docs/building-for-games.md`.
+
**Prerequisites**: Apple Silicon Mac, Rosetta 2, Xcode Command Line Tools, Homebrew, your own Battle.net account/games, and a free Apple ID for the GPTK download. Nothing from Apple, Blizzard, or CodeWeavers is redistributed by this repo.
### Why is GPTK needed at all?
diff --git a/scripts/create-steam-bottle.sh b/scripts/create-steam-bottle.sh
new file mode 100755
index 00000000000..0ee2d667357
--- /dev/null
+++ b/scripts/create-steam-bottle.sh
@@ -0,0 +1,54 @@
+#!/usr/bin/env bash
+# Steam(Windows판) 설치 — Steam판 D2R(Infernal Edition) 등 Steam 게임용.
+#
+# 중요: Steam은 Battle.net과 달리 CX 소스 엔진이 아니라 homebrew wine-stable로 돌린다.
+# CX 계열 빌드에서는 Steam의 CEF UI가 렌더링되지 않는 문제(검은 화면)가 있고,
+# 검증된 무료 조합은 wine-stable 11 + steamwebhelper 래퍼다.
+# 래퍼 출처: github.com/notpop/steam-on-m1-wine (MIT) — third_party/ 에 소스+라이선스 동봉.
+# 검증: 2026-08-27, M4 Pro / macOS 26.5 — 로그인 화면 렌더링 확인.
+set -euo pipefail
+
+export WINEPREFIX="${WINEPREFIX:-$HOME/.battlenet-macos/steam-bottle}"
+SUPPORT="$HOME/.battlenet-macos/steam-support"
+WORK="${WORK:-$HOME/.battlenet-macos/build}"; mkdir -p "$WORK" "$SUPPORT"
+REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+WINESTABLE_APP="/Applications/Wine Stable.app"
+WINE="$WINESTABLE_APP/Contents/Resources/wine/bin/wine"
+
+# ---------- 1. wine-stable ----------
+if [ ! -x "$WINE" ]; then
+ echo "==> homebrew wine-stable 설치 (무료, ~500MB)"
+ # gstreamer-runtime 의존성이 sudo를 요구하므로 건너뛴다 (Steam UI에는 불필요)
+ brew install --cask --skip-cask-deps wine-stable
+ echo "==> Gatekeeper 격리 해제 (수 분 소요)"
+ xattr -dr com.apple.quarantine "$WINESTABLE_APP" 2>/dev/null || true
+fi
+"$WINE" --version
+
+# ---------- 2. webhelper 래퍼 ----------
+# Steam의 CEF를 --disable-gpu --single-process로 강제해 검은 화면을 우회한다.
+if [ ! -f "$SUPPORT/steamwebhelper-wrapper.exe" ]; then
+ echo "==> 래퍼 빌드 (mingw-w64)"
+ command -v x86_64-w64-mingw32-gcc >/dev/null || brew install mingw-w64
+ x86_64-w64-mingw32-gcc -O2 -Wall -municode -DUNICODE -D_UNICODE \
+ -o "$SUPPORT/steamwebhelper-wrapper.exe" \
+ "$REPO_ROOT/third_party/steam-on-m1-wine/steamwebhelper-wrapper.c" \
+ -static -lshell32 -mwindows
+fi
+
+# ---------- 3. 프리픽스 + Steam 설치 ----------
+echo "==> 프리픽스 초기화: $WINEPREFIX"
+"$WINE" wineboot -u >/dev/null 2>&1 || true
+"$WINESTABLE_APP/Contents/Resources/wine/bin/wineserver" -w 2>/dev/null || true
+
+SETUP="$WORK/SteamSetup.exe"
+[ -f "$SETUP" ] || curl -fL "https://cdn.cloudflare.steamstatic.com/client/installer/SteamSetup.exe" -o "$SETUP"
+echo "==> Steam 무인 설치"
+"$WINE" "$SETUP" /S >/dev/null 2>&1 || true
+"$WINESTABLE_APP/Contents/Resources/wine/bin/wineserver" -w 2>/dev/null || true
+[ -f "$WINEPREFIX/drive_c/Program Files (x86)/Steam/steam.exe" ] || { echo "설치 실패"; exit 1; }
+
+# ---------- 4. 마무리 ----------
+cp -f /etc/ssl/cert.pem "$WINEPREFIX/drive_c/windows/cacert.pem" 2>/dev/null || true
+echo "==> 완료. 실행: scripts/play.sh steam (래퍼는 play.sh가 자동 배치)"
+echo " 입력이 ?? 로 보이면 macOS 입력기를 영어(ABC)로 전환하세요."
diff --git a/scripts/play.sh b/scripts/play.sh
index 3fb02f57f8c..4db635ccc4e 100755
--- a/scripts/play.sh
+++ b/scripts/play.sh
@@ -12,8 +12,14 @@
set -euo pipefail
ENGINE="${ENGINE:-$HOME/.battlenet-macos/cx26-engine}"
-# 보틀(가상 C드라이브) 경로 — setup-bottle.sh로 만든 위치를 지정
-export WINEPREFIX="${WINEPREFIX:-$HOME/.battlenet-macos/bottle}"
+MODE="${1:-battlenet}"
+
+# 보틀(가상 C드라이브) 경로 — 모드별 기본값 (Battle.net과 Steam은 별도 보틀)
+if [[ "$MODE" == steam* ]]; then
+ export WINEPREFIX="${WINEPREFIX:-$HOME/.battlenet-macos/steam-bottle}"
+else
+ export WINEPREFIX="${WINEPREFIX:-$HOME/.battlenet-macos/bottle}"
+fi
export WINEDEBUG="${WINEDEBUG:-fixme-all}"
export WINEMSYNC=1
@@ -31,7 +37,6 @@ if [[ -f "$BN/Battle.net.exe" ]]; then
done
fi
-MODE="${1:-battlenet}"
case "$MODE" in
battlenet) # 배틀넷 런처 (로그인 → Play로 온라인 플레이)
exec "$ENGINE/bin/wine" \
@@ -42,8 +47,37 @@ case "$MODE" in
cd "$WINEPREFIX/drive_c/Program Files (x86)/Diablo II Resurrected"
exec "$ENGINE/bin/wine" "D2R.exe" "${@:2}"
;;
- kill) # 전부 종료
+ steam) # Steam 클라이언트 — wine-stable + webhelper 래퍼 (검증: 2026-08-27)
+ # CX 엔진에선 Steam CEF가 렌더링되지 않는다 (검은 화면 / SEGV 폭풍).
+ # 검증된 조합은 homebrew wine-stable 11 + steamwebhelper 래퍼(--disable-gpu
+ # --single-process 강제) + -no-cef-sandbox -cef-single-process.
+ # 출처: github.com/notpop/steam-on-m1-wine (MIT) — third_party/ 참고.
+ WINESTABLE="/Applications/Wine Stable.app/Contents/Resources/wine/bin/wine"
+ [[ -x "$WINESTABLE" ]] || { echo "wine-stable 없음 — brew install --cask wine-stable"; exit 1; }
+ ST="$WINEPREFIX/drive_c/Program Files (x86)/Steam/steam.exe"
+ [[ -f "$ST" ]] || { echo "Steam 없음 — scripts/create-steam-bottle.sh 먼저"; exit 1; }
+ # 1) 크래시 잔여물 청소 (남으면 다음 실행이 창 없는 --silent 모드로 빠짐)
+ find "$WINEPREFIX/drive_c/users/"*/AppData/Local/Steam/htmlcache -maxdepth 2 \
+ \( -name "Singleton*" -o -name "*.lock" \) -delete 2>/dev/null || true
+ # 2) 래퍼 재배치 (Steam 업데이트가 래퍼를 원본으로 되돌리므로 매번 확인)
+ WRAP="$HOME/.battlenet-macos/steam-support/steamwebhelper-wrapper.exe"
+ for d in "$WINEPREFIX/drive_c/Program Files (x86)/Steam/bin/cef"/cef.win*; do
+ [[ -f "$d/steamwebhelper.exe" ]] || continue
+ if [[ $(stat -f%z "$d/steamwebhelper.exe") -gt 500000 ]]; then
+ mv -f "$d/steamwebhelper.exe" "$d/steamwebhelper_real.exe"
+ cp -f "$WRAP" "$d/steamwebhelper.exe"
+ fi
+ done
+ # 3) 실행 — CX 엔진 env 없이 wine-stable 순정 환경
+ env -u DYLD_FALLBACK_LIBRARY_PATH -u CX_ACTIVE_GRAPHICS_BACKEND -u CX_GRAPHICS_BACKEND \
+ -u CX_APPLEGPTK_LIBD3DSHARED_PATH -u WINEMSYNC -u ROSETTA_ADVERTISE_AVX \
+ WINEPREFIX="$WINEPREFIX" WINEDEBUG="${WINEDEBUG:-fixme-all}" \
+ WINEDLLOVERRIDES="d3d11,d3d10core,dxgi=b;winemetal=d;bcrypt=b;ncrypt=b;gameoverlayrenderer,gameoverlayrenderer64=d" \
+ "$WINESTABLE" "C:\\Program Files (x86)\\Steam\\steam.exe" \
+ -no-cef-sandbox -cef-single-process -noverifyfiles "${@:2}"
+ ;;
+ kill|steam-kill) # 종료 (kill=배틀넷 보틀, steam-kill=Steam 보틀)
"$ENGINE/bin/wineserver" -k 2>/dev/null || true
;;
- *) echo "usage: play.sh [battlenet|d2r|kill]"; exit 1;;
+ *) echo "usage: play.sh [battlenet|d2r|steam|kill|steam-kill]"; exit 1;;
esac
diff --git a/third_party/steam-on-m1-wine/LICENSE b/third_party/steam-on-m1-wine/LICENSE
new file mode 100644
index 00000000000..5ccf4386ba2
--- /dev/null
+++ b/third_party/steam-on-m1-wine/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 notpop
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/third_party/steam-on-m1-wine/NOTICE b/third_party/steam-on-m1-wine/NOTICE
new file mode 100644
index 00000000000..2d4d9e13235
--- /dev/null
+++ b/third_party/steam-on-m1-wine/NOTICE
@@ -0,0 +1,88 @@
+steam-on-m1-wine
+Copyright (c) 2026 notpop
+Licensed under the MIT License (see LICENSE for full text).
+
+================================================================================
+Third-party components
+================================================================================
+
+This project orchestrates several third-party software components,
+each distributed under its own license. THIS REPOSITORY NEITHER
+REDISTRIBUTES NOR BUNDLES ANY OF THEIR BINARIES OR SOURCE — every
+component is either installed through its upstream distribution
+channel (Homebrew cask, GitHub Releases, upstream CDN) or downloaded
+at setup time from the vendor. No third-party source is vendored into
+the repo tree; see `.gitignore`, which excludes `vendor/`, `*.dll`,
+`*.exe`, `*.so`, and `.wine-*`.
+
+--------------------------------------------------------------------------------
+Runtime dependencies
+--------------------------------------------------------------------------------
+
+Wine (stable)
+ License: LGPL-2.1-or-later
+ Source: https://www.winehq.org/
+ Notes: Installed via Homebrew Cask `wine-stable` (Gcenx build).
+ The optional `-fvisibility=default` rebuild clones upstream
+ Wine source from https://gitlab.winehq.org/wine/wine at
+ tag `wine-11.0`, builds locally, and copies only
+ `dlls/winemac.drv/winemac.so` over the Homebrew cask.
+ The original winemac.so is preserved as
+ winemac.so.gcenx-backup.
+
+Winetricks
+ License: LGPL-2.1-or-later
+ Source: https://github.com/Winetricks/winetricks
+
+DXMT
+ License: MIT License
+ Copyright: (c) 2023 Feifan He
+ Source: https://github.com/3Shain/dxmt
+ Notes: `scripts/04-install-dxmt.sh` fetches an official release
+ tarball. `scripts/07-build-dxmt-fork.sh` builds the fork
+ branch `notpop/dxmt@debug/present-path-tracing` from
+ source.
+
+GStreamer runtime
+ License: LGPL-2.1
+ Source: https://gstreamer.freedesktop.org/
+
+Steam client (installed on demand by the end user)
+ License: Steam Subscriber Agreement
+ https://store.steampowered.com/subscriber_agreement/
+ Notes: Fetched from the official Valve CDN at runtime. This
+ repository does not redistribute any Steam binaries.
+
+--------------------------------------------------------------------------------
+Build-time dependencies (only invoked when compiling from source)
+--------------------------------------------------------------------------------
+
+Homebrew
+ License: BSD-2-Clause
+ Source: https://brew.sh/
+
+mingw-w64 toolchain
+ License: runtime is public domain / MIT-like; build tools are GPL
+ Source: https://www.mingw-w64.org/
+ Notes: Only used to cross-compile `wrapper/steamwebhelper.exe`.
+ The resulting binary is not tracked in this repository.
+
+LLVM 15
+ License: Apache-2.0 with LLVM Exceptions
+ Source: https://llvm.org/
+ Notes: Self-built by `scripts/07-build-dxmt-fork.sh` as an
+ x86_64 LLVM needed by the DXMT shader compiler.
+
+3Shain Wine tarball (v8.16-3shain)
+ License: LGPL-2.1-or-later (inherited from Wine)
+ Source: https://github.com/3Shain/wine
+ Notes: Downloaded as a link-time input for the DXMT build.
+
+Meson, Ninja, CMake, Bison, Flex, gettext, pkg-config, freetype
+ Each under its own upstream license. Fetched via Homebrew at
+ install time.
+
+================================================================================
+
+No secrets, no tokens, no game binaries, and no personal data are
+committed to this repository.
diff --git a/third_party/steam-on-m1-wine/steamwebhelper-wrapper.c b/third_party/steam-on-m1-wine/steamwebhelper-wrapper.c
new file mode 100644
index 00000000000..52872000cea
--- /dev/null
+++ b/third_party/steam-on-m1-wine/steamwebhelper-wrapper.c
@@ -0,0 +1,232 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * steamwebhelper-wrapper — prepend Chromium flags and delegate to the
+ * real Steam webhelper binary. Used on macOS / Apple Silicon to work
+ * around black-screen rendering and Wine winsock issues that otherwise
+ * kill Steam's CEF UI on DXMT. See EXTRA_FLAGS below for the current
+ * flag set and the reasoning behind each.
+ *
+ * Build
+ * -----
+ * make -C wrapper
+ * which invokes x86_64-w64-mingw32-gcc (from Homebrew mingw-w64) with:
+ * -municode -O2 -Wall -Wextra -static -lshell32 -mwindows
+ *
+ * Install
+ * -------
+ * 1. Rename Steam's original file:
+ * steamwebhelper.exe -> steamwebhelper_real.exe
+ * 2. Drop the compiled wrapper in its place as steamwebhelper.exe
+ *
+ * Runtime behaviour
+ * -----------------
+ * - Resolves its own directory via GetModuleFileNameW
+ * - Builds the child command line in the form:
+ * "<dir>\\steamwebhelper_real.exe" <EXTRA_FLAGS> <original args>
+ * - Calls CreateProcessW, waits, and returns the child's exit code.
+ *
+ * Notes
+ * -----
+ * - All string handling is wide-character; Chromium's internal args
+ * include Unicode paths like
+ * C:\users\notpop\AppData\Local\Steam\htmlcache.
+ * - Uses -mwindows so Windows treats the wrapper as a GUI app (same
+ * subsystem Steam's original helper declares). Debug prints go to
+ * a log file next to the wrapper if STEAMWEBHELPER_WRAPPER_DEBUG
+ * is set in the environment.
+ */
+
+#ifndef UNICODE
+#define UNICODE
+#endif
+#ifndef _UNICODE
+#define _UNICODE
+#endif
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+/*
+ * Flags prepended to every invocation of steamwebhelper_real.exe.
+ *
+ * --disable-gpu
+ * Force Chromium CPU rasterisation. With the GPU process enabled
+ * CEF hits an ANGLE / D3D-over-OpenGL path that paints the browser
+ * window black on Wine/Apple Silicon (DXMT Issue #141). CPU raster
+ * via Skia is sufficient for Steam's 2D UI.
+ *
+ * --single-process
+ * Collapse renderer / utility / gpu back into the browser process.
+ * Without this flag:
+ * - The renderer process opens its own D3D11 swapchain and hits
+ * the cross-process limitation in DXMT Issue #141, painting the
+ * browser window black.
+ * - The NetworkService runs in a separate utility process and
+ * talks TLS via Wine's winsock implementation, which triggers
+ * the `handshake failed; net_error -100 / -107` cascade.
+ * We tried the narrower `--enable-features=NetworkServiceInProcess`
+ * alone but CEF 126 in Steam ignored it — a utility process
+ * labelled `network.mojom.NetworkService` still spawned, the SSL
+ * cascade still fired, and the renderer still painted black.
+ * Until there is a Chromium-supported single-flag replacement for
+ * `--single-process`, this is the only configuration that keeps
+ * Steam's CEF UI responsive and authenticated on Wine 11.
+ *
+ * On the DXMT side, `winemetal_unix.c::_CreateMetalViewFromHWND`
+ * does its AppKit work directly when it's already on the main
+ * thread (Unity-style engines call CreateSwapChainForHwnd from the
+ * main thread), which avoids the deadlock we hit when naively
+ * dispatching through Wine's `OnMainThread`. See the comment there
+ * for details; the upshot is that `--single-process` does not by
+ * itself block the Metal view handover, contrary to what we
+ * suspected during the v0.5 investigation.
+ */
+#define EXTRA_FLAGS L"--disable-gpu --single-process"
+#define REAL_BINARY L"steamwebhelper_real.exe"
+
+/*
+ * Debug sink. Enabled when the environment variable
+ * STEAMWEBHELPER_WRAPPER_DEBUG is set to a non-empty value.
+ * Opens a file next to the wrapper so we can inspect behaviour
+ * even though the wrapper is a GUI subsystem binary.
+ */
+static FILE *dbg = NULL;
+
+static void debug_open(const wchar_t *self_path)
+{
+ const wchar_t *flag = _wgetenv(L"STEAMWEBHELPER_WRAPPER_DEBUG");
+ if (!flag || !*flag) return;
+
+ wchar_t log_path[MAX_PATH];
+ if (wcslen(self_path) + 16 >= MAX_PATH) return;
+ wcscpy(log_path, self_path);
+
+ wchar_t *slash = wcsrchr(log_path, L'\\');
+ if (!slash) return;
+ wcscpy(slash + 1, L"wrapper-debug.log");
+
+ dbg = _wfopen(log_path, L"a");
+}
+
+static void debug_log(const wchar_t *fmt, ...)
+{
+ if (!dbg) return;
+ va_list ap;
+ va_start(ap, fmt);
+ vfwprintf(dbg, fmt, ap);
+ va_end(ap);
+ fflush(dbg);
+}
+
+/* Allocate a wide string holding "<wrapper_dir>\\steamwebhelper_real.exe". */
+static wchar_t *resolve_real_binary(wchar_t *out_self_dir, size_t out_cap)
+{
+ wchar_t self[MAX_PATH];
+ DWORD len = GetModuleFileNameW(NULL, self, MAX_PATH);
+ if (len == 0 || len >= MAX_PATH) return NULL;
+
+ if (out_self_dir && wcslen(self) < out_cap) {
+ wcscpy(out_self_dir, self);
+ }
+
+ wchar_t *slash = wcsrchr(self, L'\\');
+ if (!slash) return NULL;
+ *(slash + 1) = L'\0';
+
+ size_t cap = wcslen(self) + wcslen(REAL_BINARY) + 1;
+ wchar_t *real = (wchar_t *)calloc(cap, sizeof(wchar_t));
+ if (!real) return NULL;
+ wcscpy(real, self);
+ wcscat(real, REAL_BINARY);
+ return real;
+}
+
+/*
+ * GetCommandLineW returns the whole line, starting with the wrapper
+ * binary's own path. We skip past that first token to return just the
+ * arguments Steam actually passed.
+ */
+static const wchar_t *args_tail(void)
+{
+ const wchar_t *cmd = GetCommandLineW();
+ if (!cmd) return L"";
+
+ int in_quotes = 0;
+ while (*cmd) {
+ wchar_t c = *cmd;
+ if (c == L'"') in_quotes = !in_quotes;
+ else if (c == L' ' && !in_quotes) break;
+ ++cmd;
+ }
+ while (*cmd == L' ') ++cmd;
+ return cmd;
+}
+
+int wmain(void)
+{
+ wchar_t self_path[MAX_PATH] = {0};
+ wchar_t *real = resolve_real_binary(self_path, MAX_PATH);
+ if (!real) {
+ return 1;
+ }
+
+ debug_open(self_path);
+ debug_log(L"[wrapper] self=%ls\n", self_path);
+ debug_log(L"[wrapper] real=%ls\n", real);
+
+ const wchar_t *tail = args_tail();
+ debug_log(L"[wrapper] forwarded args=%ls\n", tail);
+
+ size_t cap = wcslen(real) + wcslen(EXTRA_FLAGS) + wcslen(tail) + 8;
+ wchar_t *cmdline = (wchar_t *)calloc(cap, sizeof(wchar_t));
+ if (!cmdline) {
+ free(real);
+ return 1;
+ }
+ _snwprintf(cmdline, cap, L"\"%ls\" %ls %ls", real, EXTRA_FLAGS, tail);
+ debug_log(L"[wrapper] invoking: %ls\n", cmdline);
+
+ STARTUPINFOW si;
+ PROCESS_INFORMATION pi;
+ ZeroMemory(&si, sizeof(si));
+ si.cb = sizeof(si);
+ ZeroMemory(&pi, sizeof(pi));
+
+ BOOL ok = CreateProcessW(
+ real, /* lpApplicationName */
+ cmdline, /* lpCommandLine */
+ NULL, /* lpProcessAttributes */
+ NULL, /* lpThreadAttributes */
+ TRUE, /* bInheritHandles */
+ 0, /* dwCreationFlags */
+ NULL, /* lpEnvironment */
+ NULL, /* lpCurrentDirectory */
+ &si,
+ &pi
+ );
+
+ if (!ok) {
+ DWORD err = GetLastError();
+ debug_log(L"[wrapper] CreateProcessW failed: %lu\n", err);
+ free(cmdline);
+ free(real);
+ return 1;
+ }
+
+ WaitForSingleObject(pi.hProcess, INFINITE);
+ DWORD code = 0;
+ GetExitCodeProcess(pi.hProcess, &code);
+ debug_log(L"[wrapper] child exited with %lu\n", code);
+
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+ free(cmdline);
+ free(real);
+ if (dbg) fclose(dbg);
+
+ return (int)code;
+}