# =========================================================================
#  IW4X / MW2 dedicated-server base image
#  Extends the Pterodactyl wine yolk and adds the FULL 32-bit Wine tree
#  that MW2 (a 2009 32-bit Windows game) needs but the stock yolk lacks.
#
#  Build:   docker build -t <your-registry>/iw4x-wine:latest .
#  Push:    docker push <your-registry>/iw4x-wine:latest
# =========================================================================
FROM ghcr.io/pterodactyl/yolks:wine_latest

USER root

# ---- 1. Install the 32-bit Wine libraries the stock image is missing -----
# The stock yolk enables i386 but never installs wine32:i386 / libwine:i386,
# which is why a win32 prefix can't load 32-bit kernel32/user32/etc.
# We add the WineHQ repo to get matching 32-bit builds, then install winbind
# (needed for NTLM), cabextract (winetricks needs it) and the 32-bit tree.
RUN dpkg --add-architecture i386 \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        ca-certificates \
        wget \
        gnupg2 \
        cabextract \
        winbind \
        xvfb \
        xauth \
        wine32:i386 \
        libwine:i386 \
        fonts-wine \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# ---- 2. Bake a clean 32-bit prefix + runtimes into the image -------------
# Doing this at BUILD time (as root) avoids the unprivileged-runtime apt wall
# and means every container starts from a known-good win32 prefix.
ENV WINEARCH=win32
ENV WINEPREFIX=/opt/wine-prefix
ENV WINEDEBUG=-all

# winetricks is already present in the yolk; if not, grab it.
RUN if ! command -v winetricks >/dev/null 2>&1; then \
        wget -O /usr/local/bin/winetricks \
        https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks \
        && chmod +x /usr/local/bin/winetricks ; \
    fi

# Initialise the prefix headless, then install the runtimes IW4X/MW2 want.
# vcrun2019 + d3dcompiler_47 are the ones the IW4X Linux docs call for.
RUN xvfb-run -a wineboot --init \
    && xvfb-run -a winetricks -q vcrun2019 d3dcompiler_47 \
    && wineserver -w \
    && chmod -R 777 /opt/wine-prefix

USER container
ENV USER=container HOME=/home/container
WORKDIR /home/container
