diff --git a/scripts/setup-wine-prefix.sh b/scripts/setup-wine-prefix.sh new file mode 100755 index 00000000..56b80d76 --- /dev/null +++ b/scripts/setup-wine-prefix.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Set up a Wine prefix for running the Metin2 client on Linux. +# Idempotent: re-running on an existing prefix skips steps that are already done. +# +# Usage: +# ./scripts/setup-wine-prefix.sh +# +# Example: +# ./scripts/setup-wine-prefix.sh /mnt/windows_c/Users/me/metin/client ~/metin-wine +# +# Result layout: +# /client/ — writable copy of the client deploy folder +# /prefix/ — Wine prefix with required runtime deps installed + +set -euo pipefail + +if [[ $# -lt 2 ]]; then + echo "usage: $0 " >&2 + echo " source-client-dir: path containing Metin2.exe, assets/, pack/, etc." >&2 + echo " target-dir: directory to create (holds client/ and prefix/)" >&2 + exit 2 +fi + +SRC=$1 +DEST=$2 + +if [[ ! -f "$SRC/Metin2.exe" && ! -f "$SRC/Metin2_Debug.exe" ]]; then + echo "error: $SRC does not look like a client folder (no Metin2.exe or Metin2_Debug.exe)" >&2 + exit 1 +fi + +for tool in wine winetricks; do + if ! command -v "$tool" >/dev/null 2>&1; then + echo "error: $tool not found in PATH. Install it via your package manager." >&2 + exit 1 + fi +done + +CLIENT_DIR=$DEST/client +PREFIX_DIR=$DEST/prefix + +mkdir -p "$DEST" + +if [[ -d "$CLIENT_DIR" && -f "$CLIENT_DIR/Metin2.exe" ]] || [[ -d "$CLIENT_DIR" && -f "$CLIENT_DIR/Metin2_Debug.exe" ]]; then + echo "[1/3] client already present at $CLIENT_DIR, skipping copy" +else + echo "[1/3] copying client from $SRC to $CLIENT_DIR (this can take a minute)" + cp -a "$SRC" "$CLIENT_DIR" +fi + +export WINEPREFIX=$PREFIX_DIR +export WINEARCH=win64 + +if [[ -f "$PREFIX_DIR/system.reg" ]]; then + echo "[2/3] wine prefix already exists at $PREFIX_DIR, skipping wineboot" +else + echo "[2/3] creating wine prefix at $PREFIX_DIR" + mkdir -p "$PREFIX_DIR" + wineboot --init >/dev/null 2>&1 || true +fi + +# vcrun2022 — MSVC 2015-2022 runtime, required because the client is an MSVC build +# d3dx9 — D3DX9 helper DLLs (Wine implements d3d9 but not the d3dx9 helpers) +# corefonts — Arial/Courier/Times/etc., needed by some UI elements +# tahoma — the client hard-codes Tahoma as the UI font; without it, all text renders invisibly +VERBS=(vcrun2022 d3dx9 corefonts tahoma) +TO_INSTALL=() +for v in "${VERBS[@]}"; do + case $v in + vcrun2022) + if [[ -f "$PREFIX_DIR/drive_c/windows/system32/msvcp140.dll" ]]; then continue; fi ;; + d3dx9) + if [[ -f "$PREFIX_DIR/drive_c/windows/system32/d3dx9_43.dll" ]]; then continue; fi ;; + corefonts) + if [[ -f "$PREFIX_DIR/drive_c/windows/Fonts/arial.ttf" ]]; then continue; fi ;; + tahoma) + if [[ -f "$PREFIX_DIR/drive_c/windows/Fonts/tahoma.ttf" ]]; then continue; fi ;; + esac + TO_INSTALL+=("$v") +done + +if [[ ${#TO_INSTALL[@]} -eq 0 ]]; then + echo "[3/3] all winetricks verbs already installed" +else + echo "[3/3] installing winetricks verbs: ${TO_INSTALL[*]}" + winetricks -q "${TO_INSTALL[@]}" +fi + +echo +echo "done. to launch:" +echo +echo " cd $CLIENT_DIR" +echo " WINEPREFIX=$PREFIX_DIR wine Metin2.exe" +echo +echo "or with verbose client logging:" +echo +echo " WINEPREFIX=$PREFIX_DIR WINEDEBUG=-all,+err,+seh wine Metin2_Debug.exe"