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" accessibleArenaPrismUrl="https://stormgames.wolfe.casa/downloads/prism.dll" melonLoaderZipUrl="https://github.com/LavaGang/MelonLoader/releases/latest/download/MelonLoader.x64.zip" byctrlDllUrl="https://stormgames.wolfe.casa/downloads/byctrl-x64.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" rm "$cache/AccessibleArena.dll" download "$accessibleArenaDllUrl" "$melonLoaderZipUrl" "$accessibleArenaPrismUrl" "$byctrlDllUrl" "$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}/prism.dll" "${cache}/byctrl-x64.dll" "$mtgaRoot" configure_accessible_arena_loader "$mtgaRoot" } install_wine_bottle dxvk winetricks -q $winVer 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'