#!/bin/bash

# Exit on error to avoid silent failures
set -euo pipefail

# Create/use a subfolder for Hawakening in the current directory
mkdir Hawakening
cd Hawakening

# Download files
wget https://cdn.hwkn.dev/Hawken-CL142579.zip
wget "$(wget -q -O - https://hawakening.com/api/game-update/latest | grep -o '"url":[^,]*' | sed 's/"//g' | sed 's/url://')"

# Extract 
unzip \*.zip

# Patch files
cp -R client_files/* .

# Clear up
rm *.zip
rm -rf client_files
rm -rf upk-patches

echo -e '\n\e[32mAll done! HAWaKENing is now installed.\n'
echo -e '\e[43m\e[30m // READ BEFORE LAUNCHING // \e[0m'
echo -e '\e[0mThe recommended way to play is by adding the executable at \e[1m./Hawakening/Binaries/Win32/HawkenGame-Win32-Shipping.exe\e[0m as a non-Steam game (click "Add a Game" in the bottom left corner).\n'
echo -e 'Make sure to enforce the usage of a specific Proton version for Hawakening (e.g. Proton 9.0-4).\nTo do this, right click on the external Hawakening game entry in Steam, select properties and navigate to compatibility.'
echo -e 'If you want to apply client-side tweaks like ultrawide monitor support or unlocked internals and items, you must override the builtin version.dll.\nTo do this, set WINEDLLOVERRIDES=version=n in either the Steam launch options or your Wine environment variables.\n\e[34m(tip: you can write \e[1mWINEDLLOVERRIDES=version=n %command% --login="MyUsername" --password="MyPassword"\e[0m\e[34m in your Steam launch options to log in automatically!)\e[0m\n'
echo -e "Lastly, don't forget to request account activation in the Linux Support thread in the feedback section on the HAWaKENing Discord!"
echo -e '\e[44m\e[30m // READ BEFORE LAUNCHING // \e[0m'
exit 0
