Migrate to the new Toby Doom Launcher.
This commit is contained in:
		| @@ -1,417 +1,11 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| launch_game() { | ||||
| gamePath=~/.local/games/doom | ||||
| check_dependencies python-pyside6:PySide6 python-setproctitle:setproctitle | ||||
| pushd "${gamePath}" | ||||
|     #echo "exec stdbuf -oL ${gzdoom} ${@} | speak" | ||||
|     exec stdbuf -oL ${gzdoom} ${@} | speak | ||||
|     popd | ||||
| } | ||||
|  | ||||
| speak() { | ||||
|     if pgrep cthulhu ; then | ||||
|         speechProvider="socat - UNIX-CLIENT:/tmp/cthulhu.sock" | ||||
| if ! [[ -d "toby-doom-launcher" ]]; then | ||||
|     git clone https://git.stormux.org/storm/toby-doom-launcher.git | ||||
| else | ||||
|         speechProvider="spd-say -e ${spd_module} ${spd_pitch} ${spd_rate} ${spd_voice} ${spd_volume} --" | ||||
|     git -C "${gamePath}/toby-doom-launcher" pull | ||||
| fi | ||||
|     startSpeech=1 | ||||
|     while IFS= read -r line; do | ||||
|         echo "$line" | ||||
|         if [[ $startSpeech -eq 1 ]] && [[ "$line" =~ ^-{5,}$ ]]; then | ||||
|             startSpeech=0 | ||||
|             continue | ||||
|         fi | ||||
|         if [[ $startSpeech -eq 0 ]]; then | ||||
|             line=$(echo "${line}" | | ||||
|                 grep "${antiGrepStrings[@]}" | | ||||
|                 sed "${sedStrings[@]}") | ||||
|             if [[ "$doomLanguage" != "en" ]]; then | ||||
|                 line=$(translate_text "$line") | ||||
|             fi | ||||
|             echo "${line}" | $speechProvider | ||||
|         fi | ||||
|     done | ||||
| } | ||||
|  | ||||
|  | ||||
| audio_manual() { | ||||
|     if command -v mpv &> /dev/null ; then | ||||
|         mediaPlayer=("mpv" "--really-quiet" "--no-video") | ||||
|     else | ||||
|         mediaPlayer=("play" "-qV0") | ||||
|     fi | ||||
|     local manualPath="${gamePath}/Manual" | ||||
|     declare -a menuList | ||||
|     for i in "${manualPath}"/*/ ; do | ||||
|         local path="${i%/}" | ||||
|         local name="${i/${manualPath}\//}" | ||||
|         local name="${name% *}" | ||||
|         menuList+=("$path" "$name") | ||||
|     done | ||||
|     manualPath="$(dialog --backtitle "Select a Manual" \ | ||||
|         --clear \ | ||||
|         --no-tags \ | ||||
|         --menu "Please select one" 0 0 0 "${menuList[@]}" --stdout)" | ||||
|     [[ $? -ne 0 ]] && exit 0 | ||||
|     # If user selected a manual, show the audio file menu | ||||
|     if [[ -n "$manualPath" ]]; then | ||||
|         declare -a audioList=("all" "Play All")  # Start with "All" option | ||||
|         # Add all mp3 files to the menu | ||||
|         while IFS= read -r file; do | ||||
|             local filename="${file##*/}" | ||||
|             local menuname="${filename%.mp3}" | ||||
|             audioList+=("$file" "$menuname") | ||||
|         done < <(find "$manualPath" -name "*.mp3" | sort) | ||||
|         local selection | ||||
|         selection="$(dialog --backtitle "Select Audio Track" \ | ||||
|             --clear \ | ||||
|             --no-tags \ | ||||
|             --menu "Please select one" 0 0 0 "${audioList[@]}" --stdout)" | ||||
|         [[ $? -ne 0 ]] && exit 0 | ||||
|         if [[ -n "$selection" ]]; then | ||||
|             if [[ "$selection" == "all" ]]; then | ||||
|                 # Play all files in order | ||||
|                 find "$manualPath" -name "*.mp3" -print0 | sort -z | \ | ||||
|                     while IFS= read -r -d '' file; do | ||||
|                         "${mediaPlayer[@]}" "$file" | ||||
|                     done | ||||
|             else | ||||
|                 # Play selected file | ||||
|                 "${mediaPlayer[@]}" "$selection" | ||||
|                 return | ||||
|             fi | ||||
|         fi | ||||
|     fi | ||||
| } | ||||
|  | ||||
|  | ||||
| # Dialog setup: | ||||
| DIALOG_ITEM_HELP="" | ||||
| export DIALOGOPTS='--no-lines --visit-items' | ||||
|  | ||||
|  | ||||
| # Toby games path | ||||
| export gamePath=~/.local/games/doom | ||||
| # Path where doom wads are stored | ||||
| export doomPath="$(find /usr/share -type d -name "doom" 2> /dev/null | head -1)" | ||||
|  | ||||
| # Path to gzdoom or yadoom. | ||||
| if [[ -x "${BASH_SOURCE[0]%/*}/yadoom" ]]; then | ||||
|     export gzdoom="$(readlink -f "${BASH_SOURCE[0]%/*}/yadoom")" | ||||
| else | ||||
|     export gzdoom="$(command -v gzdoom)" | ||||
| fi | ||||
|  | ||||
| # Version of the accessibility mod | ||||
| export tobyVersion="8-0" | ||||
|  | ||||
|  | ||||
| # Doom Addons | ||||
| mapfile -t doomAddons < <(find "$gamePath/Addons/DOOM/" -type f -name "Toby*.pk3" | ||||
|     find "$gamePath/Addons/MENU/" -type f -name "Toby*.pk3" | ||||
| ) | ||||
| # Heretic Addons | ||||
| mapfile -t hereticAddons < <(find "$gamePath/Addons/HERETIC/" -type f -name "TobyHeretic*.pk3" | ||||
|     find "$gamePath/Addons/MENU/" -type f -name "Toby*.pk3" | ||||
| ) | ||||
| # Hexen Addons | ||||
| mapfile -t hexenAddons < <(find "$gamePath/Addons/HEXEN/" -type f -name "TobyHexen*.pk3" | ||||
|     find "$gamePath/Addons/MENU/" -type f -name "Toby*.pk3" | ||||
| ) | ||||
|  | ||||
| doomGames=( | ||||
|     # Toby demo map | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${gamePath}/Addons/MAPS/Toby-Demo-Level.wad ${doomAddons[*]}" "Freedoom Toby Demo Map" | ||||
|     # Unmodified Doom with accessibility. | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${doomAddons[*]}" "Freedoom" | ||||
|     # Toby accessibility mods | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${gamePath}/Addons/MAPS/TobyDoomLevels.wad ${doomAddons[*]}" "Freedoom Toby Delux Map Pack" | ||||
|     # OperationMDK | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${gamePath}/OpMDK.wad ${doomAddons[*]}" "Freedoom OperationMDK" | ||||
|     # Unmodified Heretic with accessibility | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${hereticAddons[*]}" "Classic Heretic" | ||||
|     # Heretic accessibility mods | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${gamePath}/Addons/MAPS/TobyHereticLevels.wad ${hereticAddons[*]}" "Toby Heretic" | ||||
|     # Unmodified Hexen with accessibility | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${hexenAddons[*]}" "Classic Hexen" | ||||
|     # Heretic accessibility mods | ||||
|     "${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${gamePath}/Addons/MAPS/TobyHexen.pk3 ${hexenAddons[*]}" "Toby Hexen" | ||||
|     "custom_game" "Custom Game" | ||||
| ) | ||||
|  | ||||
| export antiGrepStrings=( | ||||
|     '-E' '-v' | ||||
|     '-e' '^----+$' | ||||
|     '-e' '^$' | ||||
|     '-e' '^[0-9]' | ||||
|     '-e' '^P_StartScript:' | ||||
|     '-e' '^(Facing |fluidsynth |INTRO|MAP[0-9]+|Music "|Unknown)' | ||||
|     '-e' '^(\[Toby Accessibility Mod\] )?READ.*' | ||||
|     '-e' '^ *TITLEMAP' | ||||
|     '-e' '^\[Toby Accessibility Mod\] (INTRO|READMe)([0-9]+).*' | ||||
|     '-e' 'key card' | ||||
|     '-e' '^New PDA Entry:' | ||||
|     '-e' "^(As |Computer Voice:|Holy|I |I've|Monorail|Sector |Ugh|What|Where)" | ||||
|     '-e' 'Script warning, "' | ||||
|     '-e' 'Tried to define' | ||||
| ) | ||||
|  | ||||
| export sedStrings=('-E' | ||||
|         '-e' 's/^\[Toby Accessibility Mod\] M_/[Toby Accessibility Mod] /' | ||||
|         '-e' 's/^\[Toby Accessibility Mod\] //' | ||||
|         '-e' 's/^MessageBoxMenu$/Confirmation menu: Press Y for yes or N for no/' | ||||
|         '-e' 's/^Mainmenu$/Main menu/' | ||||
|         '-e' 's/^Skillmenu$/Difficulty menu/' | ||||
|         '-e' 's/^NGAME$/New game/' | ||||
|         '-e' 's/^(LOAD|SAVE|QUIT)G$/\1 game/' | ||||
|         '-e' 's/"cl_run" = "true"/run/' | ||||
|         '-e' 's/"cl_run" = "false"/walk/' | ||||
|         #'-e' 's:.*/:Game saved. \(:' | ||||
|         '-e' 's/UAC/U A C/' | ||||
|         '-e' 's/^\+//' | ||||
|         '-e' 's/ ?\*+ ?//g' | ||||
| ) | ||||
|  | ||||
| # Translation stuff | ||||
| doomLanguage="${doomLanguage:-en}" | ||||
| cache="${cache:-${XDG_CACHE_HOME:-$HOME/.cache}/linux-game-manager}" | ||||
| translationDB="${cache}/doom_${doomLanguage}.sqlite" | ||||
|  | ||||
| # Function to initialize SQLite database | ||||
| init_translation_db() { | ||||
|     mkdir -p "$cache" | ||||
|     if [[ ! -f "$translationDB" ]]; then | ||||
|         sqlite3 "$translationDB" <<EOF | ||||
| CREATE TABLE translations ( | ||||
|     original TEXT PRIMARY KEY, | ||||
|     translated TEXT | ||||
| ); | ||||
| EOF | ||||
|     fi | ||||
| } | ||||
|  | ||||
| # Function to translate text | ||||
| translate_text() { | ||||
|     local text="$1" | ||||
|     local translatedText | ||||
|     # Check if translation exists in database | ||||
|     translatedText=$(sqlite3 "$translationDB" "SELECT translated FROM translations WHERE original = ?;" "$text") | ||||
|     if [[ -n "$translatedText" ]]; then | ||||
|         echo "$translatedText" | ||||
|         return 0 | ||||
|     fi | ||||
|     translatedText=$(trans -b -t "$doomLanguage" "$text") | ||||
|     # Store new translation in database | ||||
|     sqlite3 "$translationDB" "INSERT INTO translations (original, translated) VALUES (?, ?);" "$text" "$translatedText" | ||||
|     echo "$translatedText" | ||||
| } | ||||
|  | ||||
|  | ||||
| custom_game() { | ||||
|     mapfile -t customGames < <(find "${BASH_SOURCE[0]%/*}/TobyCustom/" -type f -iname '*.sh') | ||||
|     declare -a customMenu | ||||
|     for i in "${customGames[@]}" ; do | ||||
|     customMenu+=("$i") | ||||
|     title="${i##*/}" | ||||
|     title="${title//_/ }" | ||||
|     title="${title%.*}" | ||||
|     customMenu+=("$title") | ||||
|     done | ||||
|     customGame="$(dialog --backtitle "Select your Custom Doom!" \ | ||||
|         --clear \ | ||||
|         --no-tags \ | ||||
|         --menu "Please select one" 0 0 0 "${customMenu[@]}" --stdout)" | ||||
|     buttonCode=$? | ||||
|     if [[ $buttonCode -eq 1 ]]; then | ||||
|         exit 0 | ||||
|     fi | ||||
|     source "${customGame}" | ||||
| } | ||||
|  | ||||
|  | ||||
| if [[ "$doomLanguage" != "en" ]]; then | ||||
|     init_translation_db | ||||
| fi | ||||
|  | ||||
| doomGames+=("manual" "Audio Manual") | ||||
| while [[ -z "${gameOption}" ]] || [[ "${gameOption}" == "manual" ]]; do | ||||
|     gameOption="$(dialog --backtitle "Select your Doom!" \ | ||||
|             --clear \ | ||||
|             --no-tags \ | ||||
|             --ok-label "Single Player" \ | ||||
|             --cancel-label "Death Match" \ | ||||
|             --extra-button \ | ||||
|             --extra-label "co-op" \ | ||||
|             --help-button \ | ||||
|             --help-label "Exit" \ | ||||
|             --menu "Please select one" 0 0 0 "${doomGames[@]}" --stdout)" | ||||
|     buttonCode=$? | ||||
|     [[ $buttonCode -ne 0 ]] && break | ||||
|     if [[ "${gameOption}" == "manual" ]]; then | ||||
|         audio_manual | ||||
|     fi | ||||
| done | ||||
| if [[ -e "${gamePath}/DoomMetalVol7.wad" ]]; then | ||||
|     gameOption+=" DoomMetalVol7.wad" | ||||
| elif [[ -e "${gamePath}/DoomMetalVol6.wad" ]]; then | ||||
|     gameOption+=" DoomMetalVol6.wad" | ||||
| fi | ||||
|  | ||||
| case ${buttonCode} in | ||||
|     1) | ||||
|         # Death match setup | ||||
|         # Ignore the choice of map made above | ||||
|         gameOption="${gamePath}/TobyAccMod_V${tobyVersion}.pk3 ${gamePath}/Addons/MAPS/TobyDeathArena_V1-5.wad ""$gamePath/Addons/DOOM/TobyV*_"* | ||||
|         ipAddress="$(dialog --backtitle "Deathmatch Options" \ | ||||
|             --clear \ | ||||
|             --no-tags \ | ||||
|             --ok-label "Join" \ | ||||
|             --cancel-label "Exit" \ | ||||
|             --extra-button \ | ||||
|             --extra-label "Host" \ | ||||
|             --inputbox "Enter ip or URL, required for join." -1 -1 --stdout)" | ||||
|         buttonCode=$? | ||||
|         [[ $buttonCode -eq 1 ]] && exit 0 | ||||
|         if [[ $buttonCode -eq 0 ]]; then | ||||
|             if [[ "${#ipAddress}" -lt 3 ]]; then | ||||
|                 dialog --backtitle "Deathmatch" --clear --msgbox "No ip address or URL given." -1 -1 --stdout | ||||
|                 exit 1 | ||||
|             fi | ||||
|             flags=('-join' "${ipAddress}" '+Toby_SnapToTargetTargetingMode' '0') | ||||
|         else | ||||
|             # List of maps included: | ||||
|             maps=( | ||||
|                 "1" "Com Station (2-4 players)" | ||||
|                 "2" "Warehouse (2-4 players)" | ||||
|                 "3" "Sector 3 (2-4 players)" | ||||
|                 "4" "Dungeon of Doom (2-4 players)" | ||||
|                 "5" "Ocean Fortress (2-4 players)" | ||||
|                 "6" "Water Treatment Facility (2-4 players)" | ||||
|                 "7" "Phobos Base Site 4 (2-4 players)" | ||||
|                 "8" "Hangar Bay 18 (2-4 players)" | ||||
|                 "9" "Garden of Demon (2-4 players)" | ||||
|                 "10" "Outpost 69 (2-4 players)") | ||||
|             # Array of how many players a given map supports in dialog rangebox syntax | ||||
|             declare -a mapPlayers=( | ||||
|                 [1]="2 4" | ||||
|                 [2]="2 4" | ||||
|                 [3]="2 4" | ||||
|                 [4]="2 4" | ||||
|                 [5]="2 4" | ||||
|                 [6]="2 4" | ||||
|                 [7]="2 4" | ||||
|                 [8]="2 4" | ||||
|                 [9]="2 4" | ||||
|                 [10]="2 4") | ||||
|             map="$(dialog --backtitle "Select Map" \ | ||||
|                 --clear \ | ||||
|                 --no-tags \ | ||||
|                 --cancel-label "Exit" \ | ||||
|                 --ok-label "Next" \ | ||||
|                 --menu "Please select one" 0 0 0 "${maps[@]}" --stdout)" | ||||
|             fraglimit="$(dialog --backtitle "Fraglimit" \ | ||||
|                 --clear \ | ||||
|                 --ok-label "Next" \ | ||||
|                 --cancel-label "Exit" \ | ||||
|                 --rangebox "Select Fraglimit" -1 -1 1 500 20 --stdout)" | ||||
|             [[ $? -eq 1 ]] && exit 0 | ||||
|             # Get ip address | ||||
|             yourIpAddress="$(curl -4s https://icanhazip.com)" | ||||
|             players="$(dialog --backtitle "Host Deathmatch Game" \ | ||||
|                 --clear \ | ||||
|                 --ok-label "Next" \ | ||||
|                 --cancel-label "Exit" \ | ||||
|                 --rangebox "Select number of players. Remember to give them your IP address: ${yourIpAddress}" -1 -1 ${mapPlayers[$map]} --stdout)" | ||||
|             [[ $? -eq 1 ]] && exit 0 | ||||
|             skillLevel="$(dialog --backtitle "Host Deathmatch Game" \ | ||||
|                 --clear \ | ||||
|                 --ok-label "Start" \ | ||||
|                 --cancel-label "Exit" \ | ||||
|                 --extra-button \ | ||||
|                 --extra-label "Bots Only" \ | ||||
|                 --rangebox "Select difficulty. 1 easiest, 5 hardest." -1 -1 1 5 3 --stdout)" | ||||
|             code=$? | ||||
|             [[ $code -eq 1 ]] && exit 0 | ||||
|             if [[ $code -eq 3 ]]; then | ||||
|                 players=1 | ||||
|                 dialog --backtitle "Preparing to Launch" \ | ||||
|                     --msgbox "When the game starts, press \` to open the console. Type addbot, press enter. Repeat addbot for as many bots as you would like. Press \` again to close the console." -1 -1 --stdout | ||||
|             fi | ||||
|             flags=( | ||||
|                     '-host' "${players}" | ||||
|                     '-skill' "${skillLevel}" | ||||
|                     '-deathmatch' | ||||
|                     '+Toby_SnapToTargetTargetingMode' '0' | ||||
|                     '+set' 'sv_cheats' '1' | ||||
|                     '+fraglimit' "$fraglimit" | ||||
|                     '+dmflags' '16384' '+dmflags' '4' '+dmflags' '128' '+dmflags' '4096' | ||||
|                     '+dmflags2' '512'	'+dmflags2' '1024' | ||||
|                     '-extratic' '-dup' '3' | ||||
|                     '-warp' "$map" | ||||
|             ) | ||||
|         fi | ||||
|         launch_game ${gameOption} "${flags[@]}" | ||||
|     ;; | ||||
|     2) | ||||
|         # Exit was pressed, so exit. | ||||
|         exit 0 | ||||
|     ;; | ||||
|     3) | ||||
|         # Co-op setup | ||||
|         ipAddress="$(dialog --backtitle "Co-op Options" \ | ||||
|             --clear \ | ||||
|             --no-tags \ | ||||
|             --ok-label "Join" \ | ||||
|             --cancel-label "Exit" \ | ||||
|             --extra-button \ | ||||
|             --extra-label "Host" \ | ||||
|             --inputbox "Enter ip or URL, required for join." -1 -1 --stdout)" | ||||
|         buttonCode=$? | ||||
|         [[ $buttonCode -eq 1 ]] && exit 0 | ||||
|         if [[ $buttonCode -eq 0 ]]; then | ||||
|             if [[ "${#ipAddress}" -lt 3 ]]; then | ||||
|                 dialog --backtitle "Co-op" --clear --msgbox "No ip address or URL given." -1 -1 --stdout | ||||
|                 exit 1 | ||||
|             fi | ||||
|             flags=("keyshare-universal.pk3" '-join' "${ipAddress}") | ||||
|         else | ||||
|             # Get ip address | ||||
|             yourIpAddress="$(curl -4s https://icanhazip.com)" | ||||
|             players="$(dialog --backtitle "Host Co-op Game" \ | ||||
|                 --clear \ | ||||
|                 --ok-label "Next" \ | ||||
|                 --cancel-label "Exit" \ | ||||
|                 --rangebox "Select number of players. Remember to give them your IP address: ${yourIpAddress}" -1 -1 2 10 --stdout)" | ||||
|             [[ $? -eq 1 ]] && exit 0 | ||||
|             skillLevel="$(dialog --backtitle "Host Co-op Game" \ | ||||
|                 --clear \ | ||||
|                 --ok-label "Start" \ | ||||
|                 --cancel-label "Exit" \ | ||||
|                 --rangebox "Select difficulty. 1 easiest, 5 hardest." -1 -1 1 5 3 --stdout)" | ||||
|             [[ $? -eq 1 ]] && exit 0 | ||||
|             flags=( | ||||
|                     "keyshare-universal.pk3" | ||||
|                     '-host' "${players}" | ||||
|                     '-skill' "${skillLevel}" | ||||
|                     '+set' 'sv_cheats' '1' | ||||
|                     '+set' 'sv_weaponsstay' '1' | ||||
|                     '+set'  'sv_respawnprotect' '1' | ||||
|                     '+set' 'sv_respawnsuper' '1' | ||||
|                     '+set' 'alwaysapplydmflags' ''1 | ||||
|                     '-extratic' '-dup' '3' | ||||
|             ) | ||||
|         fi | ||||
|         pushd "${gamePath}" | ||||
|         launch_game ${gameOption} "${flags[@]}" | ||||
|     ;; | ||||
|     0) | ||||
|     if [[ "${gameOption%% *}" == "custom_game" ]]; then | ||||
|         custom_game | ||||
|     fi | ||||
|     if [[ -e "${gamePath}/Toby-Doom-Level-Music-Renamer.pk3" ]] && [[ "${gameOption}" =~ TobyDoomLevels.wad ]]; then | ||||
|         gameOption+=("${gamePath}/Toby-Doom-Level-Music-Renamer.pk3") | ||||
|     fi | ||||
|         launch_game ${gameOption[@]} "${flags[@]}" | ||||
|     ;; | ||||
| esac | ||||
|  | ||||
| exit 0 | ||||
| "toby-doom-launcher/Toby Doom Launcher.py" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user