Skip to content

Instantly share code, notes, and snippets.

@AlexTMjugador
Last active February 3, 2024 12:54
Show Gist options
  • Save AlexTMjugador/6e2750d782a30b9806adf8bbcad16733 to your computer and use it in GitHub Desktop.
Save AlexTMjugador/6e2750d782a30b9806adf8bbcad16733 to your computer and use it in GitHub Desktop.
FFXIV Proton launch script with XIVLauncher. Supports both launching the game outside of Steam via protontricks and from Steam, as a non-Steam game shortcut.
#!/bin/sh -e
# Script to setup and launch FFXIV using XIVLauncher on a Proton >= 8 Wine
# prefix. Can be used by adding this script as a non-Steam game to Steam and
# choosing the right Proton compatibility layer. Do not modify the default
# target directory, which matches the directory where this script is.
# XIVLauncher files must be installed in the "xivlauncher" subdirectory at the
# script directory. After launching FFXIV for a first time using Steam to set up
# the Proton prefix, launching it outside of Steam via protontricks is supported.
# Modifying PATH is needed to find host binaries on the Pressure Vessel
# container runtime launched by Steam. Has no effect if such a runtime is not
# used. References:
# - https://candide-guevara.github.io/cs_related/2020/12/16/steam-odyssey-fcntl.html
# - README.md at steamapps/common/SteamLinuxRuntime_sniper
# - https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/docs/container-runtime.md
# The /run/host path was found by using `PRESSURE_VESSEL_SHELL=instead`
export PATH="$PATH:/run/host/usr/bin:/run/host/bin"
# STEAM_COMPAT_DATA_PATH is the resolved path to the Proton prefix directory for
# this game, whose name matches the app ID. To support launching the game with
# Proton outside of Steam, fall back to a hardcoded app ID, which will be
# different for each non-Steam game shortcut. Replace it according to the output
# of protontricks -l if needed. Reference:
# https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/c725b09c9c193860f8726edc3f4a805cfd62a56b/docs/steam-compat-tool-interface.md#non-steam-games
APP_ID="${STEAM_COMPAT_DATA_PATH##*/}"
readonly APP_ID="${APP_ID:-2682226531}"
readonly PROTON_PREFIX_DIR="${HOME:-/nonexistent}/.steam/steam/steamapps/compatdata/$APP_ID/pfx"
# Set up XIVLauncher (optional)
GAME_PATCH_DIR="$(mktemp -d --tmpdir 'ffxiv-patches.XXX')"
readonly GAME_PATCH_DIR
trap 'rm -rf "$GAME_PATCH_DIR" || true' EXIT INT TERM
XIVLAUNCHER_CONFIG_DIR="$PROTON_PREFIX_DIR/drive_c/users/steamuser/AppData/Roaming/XIVLauncher"
readonly XIVLAUNCHER_CONFIG_DIR
toWinePathJsonString() {
printf 'Z:%s' "$1" | sed 's;/;\\\\;g'
}
# Assume the game directory is the parent of the directory where this script is located
GAME_DIR="$(pwd)"
GAME_DIR="${GAME_DIR%/*}"
readonly GAME_DIR
mkdir -p "$XIVLAUNCHER_CONFIG_DIR"
cat <<XIVLAUNCHER_CONFIG > "$XIVLAUNCHER_CONFIG_DIR/launcherConfigV3.json"
{
"AcceptLanguage": "en",
"LauncherLanguage": "English",
"AddonList": "[]",
"PatchAcquisitionMethod": "Aria",
"InGameAddonLoadMethod": "DllInject",
"EncryptArguments": "true",
"AskBeforePatchInstall": "true",
"DpiAwareness": "Unaware",
"TreatNonZeroExitCodeAsFailure": "false",
"ExitLauncherAfterGameExit": "true",
"IsFt": "false",
"AutoStartSteam": "false",
"ForceNorthAmerica": "false",
"VersionUpgradeLevel": "2",
"GamePath": "$(toWinePathJsonString "$GAME_DIR")",
"IsDx11": "true",
"Language": "English",
"InGameAddonEnabled": "true",
"DalamudRolloutBucket": "Control",
"PatchPath": "$(toWinePathJsonString "$GAME_PATCH_DIR")",
"KeepPatches": "false",
"DalamudInjectionDelayMs": "0",
"OtpServerEnabled": "false",
"AdditionalLaunchArgs": "",
"SpeedLimitBytes": "0"
}
XIVLAUNCHER_CONFIG
# Symlink shell folders to host's to share e.g. game configuration outside
# Proton (optional)
while read -r dir_basename; do
dir="${dir_basename% *}"
basename="${dir_basename#* }"
rm -rf "$PROTON_PREFIX_DIR/drive_c/users/steamuser/$basename" >/dev/null 2>&1 || true
ln -s "$(xdg-user-dir "$dir")" "$PROTON_PREFIX_DIR/drive_c/users/steamuser/$basename"
done <<'DIR_BASENAMES'
DESKTOP Desktop
DOCUMENTS Documents
DOWNLOAD Downloads
MUSIC Music
PICTURES Pictures
VIDEOS Videos
DIR_BASENAMES
# If outside of Steam, use protontricks. Else, run the usual Proton game launch
# command. Here, we assume that the innermost compat tool is indeed Proton (the
# outermost would be the Steam Linux Runtime). It is not a good idea to
# unconditionally use protontricks because protontricks is a Python script, and
# the host and Runtime Python versions may differ, causing errors if we set
# PYTHONHOME to reuse the host's protontricks install. The Runtime also lacks
# pip or apt
if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then
exec "${STEAM_COMPAT_TOOL_PATHS%%:*}/proton" waitforexitandrun xivlauncher/XIVLauncher.exe
else
exec protontricks-launch --appid "$APP_ID" xivlauncher/XIVLauncher.exe
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment