diff --git a/.install/Magic: The Gathering Arena.sh b/.install/Magic: The Gathering Arena.sh new file mode 100644 index 0000000..9008807 --- /dev/null +++ b/.install/Magic: The Gathering Arena.sh @@ -0,0 +1,94 @@ +export WINEARCH=win64 +# shellcheck disable=SC2154 # installer is sourced by audiogame-manager with shared globals +export winVer="win10" +game="${game:-Magic: The Gathering Arena}" + +mtgaVersionUrl="https://mtgarena.downloads.wizards.com/Live/Windows32/version" +accessibleArenaDllUrl="https://github.com/JeanStiletto/AccessibleArena/releases/latest/download/AccessibleArena.dll" +melonLoaderZipUrl="https://github.com/LavaGang/MelonLoader/releases/latest/download/MelonLoader.x64.zip" +tolkDllUrl="https://stormgames.wolfe.casa/downloads/Tolk.dll" + +get_mtga_installer_url() { + local versionJson="" + local installerUrl="" + + if ! versionJson="$(curl -fsSL "$mtgaVersionUrl")"; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "Could not fetch the current MTG Arena installer URL." + exit 1 + fi + + installerUrl="$(sed -n 's/.*"CurrentInstallerURL"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' <<< "$versionJson" | head -n1)" + if [[ -z "$installerUrl" ]]; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "Could not parse the current MTG Arena installer URL." + exit 1 + fi + + printf '%s\n' "$installerUrl" +} + +download_mtga_installer() { + local installerUrl="$1" + local installerFile="${installerUrl##*/}" + installerFile="${installerFile%%\?*}" + [[ -n "$installerFile" ]] || installerFile="MTGAInstaller.msi" + + # shellcheck disable=SC2154 # cache is set by audiogame-manager before installers are sourced + if [[ "${redownload:-}" == "true" ]] || [[ ! -s "${cache}/${installerFile}" ]]; then + if ! curl -L4 -C - --retry 10 --output "${cache}/${installerFile}" "$installerUrl" 2>&1 | agm_progressbox "Magic: The Gathering Arena" "Downloading MTG Arena installer..."; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "Could not download the MTG Arena installer." + exit 1 + fi + fi + + mtgaInstallerPath="${cache}/${installerFile}" +} + +configure_accessible_arena_loader() { + local mtgaRoot="$1" + local userDataPath="${mtgaRoot}/UserData" + local loaderConfig="${userDataPath}/Loader.cfg" + + mkdir -p "$userDataPath" + if [[ -f "$loaderConfig" ]]; then + if grep -Fq "hide_console = false" "$loaderConfig"; then + sed -i 's/hide_console = false/hide_console = true/g' "$loaderConfig" + elif ! grep -Fq "hide_console" "$loaderConfig"; then + printf '\n[console]\nhide_console = true\n' >> "$loaderConfig" + fi + else + printf '[console]\nhide_console = true\n' > "$loaderConfig" + fi +} + +install_accessible_arena_support() { + local mtgaRoot="$1" + + if [[ -z "${nvdaControllerClient64Dll:-}" ]]; then + # shellcheck disable=SC2154 # ipfs is sourced through audiogame-manager helpers + nvdaControllerClient64Dll="${ipfs[nvdaControllerClient64]}" + fi + + download "$accessibleArenaDllUrl" "$melonLoaderZipUrl" "$tolkDllUrl" "$nvdaControllerClient64Dll" + + install_with_progress unzip "Installing MelonLoader..." -d "$mtgaRoot" "${cache}/MelonLoader.x64.zip" + mkdir -p "${mtgaRoot}/Mods" + install_with_progress cp "Installing Accessible Arena..." "${cache}/AccessibleArena.dll" "${mtgaRoot}/Mods/AccessibleArena.dll" + install_with_progress cp "Installing screen reader support DLLs..." "${cache}/Tolk.dll" "${cache}/nvdaControllerClient64.dll" "$mtgaRoot" + configure_accessible_arena_loader "$mtgaRoot" +} + +install_wine_bottle dxvk + +mtgaRoot="${WINEPREFIX}/drive_c/Program Files (x86)/Wizards of the Coast/MTGA" +mtgaInstallerUrl="$(get_mtga_installer_url)" +download_mtga_installer "$mtgaInstallerUrl" + +wine msiexec /i "$mtgaInstallerPath" /q + +if [[ ! -f "${mtgaRoot}/MTGA.exe" ]]; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "MTG Arena installation did not finish at the expected location: ${mtgaRoot}" + exit 1 +fi + +install_accessible_arena_support "$mtgaRoot" +add_launcher 'c:\Program Files (x86)\Wizards of the Coast\MTGA\MTGA.exe' 'export WINEDLLOVERRIDES=version=n,b' diff --git a/game-scripts/magic-the-gathering-arena-update.sh b/game-scripts/magic-the-gathering-arena-update.sh new file mode 100755 index 0000000..3f6de6f --- /dev/null +++ b/game-scripts/magic-the-gathering-arena-update.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +# shellcheck disable=SC1091,SC2034,SC2154 + +export game="Magic: The Gathering Arena" +export WINEARCH=win64 +export DIALOGOPTS='--no-lines --visit-items' +export ipfsGateway="${ipfsGateway:-https://ipfs.stormux.org}" + +cache="${XDG_CACHE_HOME:-$HOME/.cache}/audiogame-manager" +winetricksPath="${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager" +mkdir -p "$cache" "$winetricksPath" + +if [[ -z "$DISPLAY" ]]; then + dialogType="dialog" + export DISPLAY=":0" +elif command -v yad &> /dev/null; then + dialogType="yad" +else + dialogType="dialog" +fi + +source "${0%/*}/../.includes/dialog-interface.sh" +source "${0%/*}/../.includes/functions.sh" +source "${0%/*}/../.includes/bottle.sh" + +export nvdaControllerClient64Dll="${ipfs[nvdaControllerClient64]}" + +mtgaVersionUrl="https://mtgarena.downloads.wizards.com/Live/Windows32/version" +accessibleArenaDllUrl="https://github.com/JeanStiletto/AccessibleArena/releases/latest/download/AccessibleArena.dll" +melonLoaderZipUrl="https://github.com/LavaGang/MelonLoader/releases/latest/download/MelonLoader.x64.zip" +tolkDllUrl="https://stormgames.wolfe.casa/downloads/Tolk.dll" + +get_mtga_installer_url() { + local versionJson="" + local installerUrl="" + + if ! versionJson="$(curl -fsSL "$mtgaVersionUrl")"; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "Could not fetch the current MTG Arena installer URL." + exit 1 + fi + + installerUrl="$(sed -n 's/.*"CurrentInstallerURL"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' <<< "$versionJson" | head -n1)" + if [[ -z "$installerUrl" ]]; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "Could not parse the current MTG Arena installer URL." + exit 1 + fi + + printf '%s\n' "$installerUrl" +} + +download_mtga_installer() { + local installerUrl="$1" + local installerFile="${installerUrl##*/}" + installerFile="${installerFile%%\?*}" + [[ -n "$installerFile" ]] || installerFile="MTGAInstaller.msi" + + rm -f "${cache}/${installerFile}" 2> /dev/null + if ! curl -L4 -C - --retry 10 --output "${cache}/${installerFile}" "$installerUrl" 2>&1 | agm_progressbox "Magic: The Gathering Arena Update" "Downloading MTG Arena update..."; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "Could not download the MTG Arena update." + exit 1 + fi + + mtgaInstallerPath="${cache}/${installerFile}" +} + +configure_accessible_arena_loader() { + local mtgaRoot="$1" + local userDataPath="${mtgaRoot}/UserData" + local loaderConfig="${userDataPath}/Loader.cfg" + + mkdir -p "$userDataPath" + if [[ -f "$loaderConfig" ]]; then + if grep -Fq "hide_console = false" "$loaderConfig"; then + sed -i 's/hide_console = false/hide_console = true/g' "$loaderConfig" + elif ! grep -Fq "hide_console" "$loaderConfig"; then + printf '\n[console]\nhide_console = true\n' >> "$loaderConfig" + fi + else + printf '[console]\nhide_console = true\n' > "$loaderConfig" + fi +} + +install_accessible_arena_support() { + local mtgaRoot="$1" + + download "$accessibleArenaDllUrl" "$melonLoaderZipUrl" "$tolkDllUrl" "$nvdaControllerClient64Dll" + + install_with_progress unzip "Reinstalling MelonLoader..." -d "$mtgaRoot" "${cache}/MelonLoader.x64.zip" + mkdir -p "${mtgaRoot}/Mods" + install_with_progress cp "Installing Accessible Arena..." "${cache}/AccessibleArena.dll" "${mtgaRoot}/Mods/AccessibleArena.dll" + install_with_progress cp "Installing screen reader support DLLs..." "${cache}/Tolk.dll" "${cache}/nvdaControllerClient64.dll" "$mtgaRoot" + configure_accessible_arena_loader "$mtgaRoot" +} + +check_requirements || exit 1 +install_wine_bottle dxvk + +mtgaRoot="${WINEPREFIX}/drive_c/Program Files (x86)/Wizards of the Coast/MTGA" +mtgaInstallerUrl="$(get_mtga_installer_url)" +download_mtga_installer "$mtgaInstallerUrl" + +wine msiexec /i "$mtgaInstallerPath" /q + +if [[ ! -f "${mtgaRoot}/MTGA.exe" ]]; then + alert "Magic: The Gathering Arena" "Magic: The Gathering Arena" "MTG Arena was not found at the expected location: ${mtgaRoot}" + exit 1 +fi + +install_accessible_arena_support "$mtgaRoot" +agm_msgbox "Magic: The Gathering Arena Update" "Magic: The Gathering Arena Update" "Magic: The Gathering Arena and Accessible Arena have been updated."