PhysixCat

glb_launcher

May 25th, 2020 (edited)
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.68 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # GLBoom+ launching script
  3. # Author: PhysixCat
  4.  
  5. printf '\e[1m%s\e[0m\n' "GLBoom+ launching script"
  6. printf '%s\n\n' "----------------------------------------------------------"
  7.  
  8. # User should edit $glb_path to point to their glb binary
  9. # If it was installed through your distro's repo, the binary name is enough
  10.  
  11. glb_path="glboom-plus"
  12. #glb_path="$HOME/Vidya/Native/Doom/prboomfork-umapinfo/prboom2/build/glboom-plus"
  13.  
  14. # I use "libstrangle" to limit GLB+'s FPS to 60 without vsync
  15. # https://gitlab.com/torkel104/libstrangle
  16. # If you don't, simply leave this commented out
  17.  
  18. #libstrangle="strangle 62"
  19.  
  20. # Initializing script variables
  21. interactive="true"
  22. strict_check="false"
  23. fancy_check="false"
  24. verbose_check="false"
  25. dry_check="false"
  26. playdemo_check="false"
  27. recorddemo_check="false"
  28.  
  29. righthand_status="righthanded"
  30.  
  31. valid_iwads=( 'doom' 'doom2' 'tnt' 'plutonia' 'miniwad' 'freedoom' 'freedoom2' )
  32.  
  33. # Suggestion: Don't bother string-checking, run true or false as commands
  34. # Suggestion: Another common trick for booleans is string length checks
  35. # Suggestion: heredocs and herestrings could replace printf/echo in many places
  36. # Suggestion: replace tr with ${//} and extglob expressions
  37.  
  38. showhelp () {
  39.     echo "Usage: glb [OPTION]... [FILE]..."
  40.     echo
  41.     echo "Launches GLBoom+, a source port for Doom & Doom 2."
  42.     echo "Auto-applies sprite fixes and dssecret sounds."
  43.     echo "Additional mods such as DoomSFX or DEH patches are optional"
  44.     echo "Can be ran interactively or by using launch arguments"
  45.     echo
  46.     echo "If WAD is not recognized, user is prompted to specify complevel and IWAD."
  47.     echo
  48.     echo "  -d, --dry           Dry test run of script (doesn't launch GLB+)."
  49.     echo "  -f, --fancy         Apply vsmooth DEH patch by fraggle."
  50.     echo "  -h, --help          Display this help and exit."
  51.     echo "  -p, --play          Play specified demo file."
  52.     echo "  -r, --record        Record specified demo file."
  53.     echo "  -s, --strict        Guarantee no DEH lumps are loaded before WAD."
  54.     echo "  -v, --verbose       Display GLB+ output to console after launch."
  55.     echo "  -w, --wad           Load specified WAD file."
  56.     echo
  57.     echo "Anything not recognized by this script will be passed through to"
  58.     echo "GLBoom+ verbatim (such as -skill #, -warp ##, etc...)"
  59.     echo
  60.     echo "script by PhysixCat"
  61. }
  62.  
  63. # Suggestion: Loop should be while [ $# -gt 0 ]
  64. # Suggestion: Use getopt !!!
  65.  
  66. # Loop until all parameters are used up
  67. while [ "$1" != "" ]; do
  68.     case "$1" in
  69.         -d|--dry)
  70.             dry_check="true"
  71.             printf '%s\n' "This is a dry run of the script"
  72.             ;;
  73.         -f|--fancy)
  74.             fancy_check="true"
  75.             smooth='vsmooth'
  76.             unset righthand_status
  77.             ;;
  78.         -h|--help)
  79.             showhelp
  80.             exit 0
  81.             ;;
  82.         -p|--play)
  83.             shift
  84.             cvars+=( '-playdemo' "$1" )
  85.             playdemo_check="true"
  86.             interactive="false"
  87.             ;;
  88.         -r|--record)
  89.             shift
  90.             cvars+=( '-record' "$1" )
  91.             recorddemo_check="true"
  92.             interactive="false"
  93.             ;;
  94.         -s|--strict)
  95.             strict_check="true"
  96.             ;;
  97.         -v|--verbose)
  98.             verbose_check="true"
  99.             ;;
  100.         -w|--wad)
  101.             shift
  102.             map="$1"
  103.             interactive="false"
  104.             ;;
  105.         *)
  106.             cvars+=( "$1" )
  107.             ;;
  108.     esac
  109.     shift
  110.  
  111. done
  112.  
  113. # Check for contradictions in the arguments
  114. [[ $strict_check == 'true' && $fancy_check == 'true' ]] && printf '%s\n\n' "what the fug" && exit 1
  115. [[ $playdemo_check == 'true' && $recorddemo_check == 'true' ]] && printf '%s\n\n' "what the fug" && exit 1
  116. [[ $verbose_check == 'true' && $dry_check == 'true' ]] && printf '%s\n' "can't be very verbose on a dry run..."
  117.  
  118. case $interactive in
  119.     true)
  120.         # Ask user for desired map
  121.         read -r -p 'wad?'$'\n> ' map
  122.         ;;
  123. esac
  124.  
  125. # Requested map is checked against some hardcoded WAD names. If not recognized, ask user for corresponding complevel and IWAD
  126. case $map in
  127.     # Maps for Doom 2 and limit-removing source ports
  128.     ''|doom2|scythe*|av|hr*|btsx*|aterfier|d2twid|dbp*|jpcp|*minvr|remnant|manolaik|bstain|comatose|dmonfear|doom2_maps|dv|eviltech|freedoom2_maps|gravity|intercep|ksutra|lilium|marswar|miasma|nuts|akeldama|mutiny|ndcp|nova*|oceansde|sid|strg|syringe|tvr|cchest|nerve|masterlevels|uyane3|kuchitsu)
  129.         iwad='doom2'
  130.         complevel='2'
  131.         case $map in
  132.             av)
  133.                 dehpatch='av.deh'
  134.                 ;;
  135.             hr)
  136.                 postpatch='hr_mus'
  137.                 ;;
  138.             btsx)
  139.                 map='btsx_e1a btsx_e1b'
  140.                 ;;
  141.             btsx2)
  142.                 map='btsx_e2a btsx_e2b'
  143.                 ;;
  144.             jpcp)
  145.                 postpatch='jpcp_hud'
  146.                 ;;
  147.             mutiny)
  148.                 dehpatch='mutiny.deh'
  149.                 ;;
  150.             tvr)
  151.                 postpatch='tvrmidi'
  152.                 ;;
  153.         esac
  154.         ;;
  155.     # Maps for The Ultimate Doom and limit-removing source ports
  156.     doom|dtwid|dtwid-*|sigil|neis|dbimpact|sgnsym|deathless|dmpurge|draftex|hadron|indifference|doom_maps|freedoom_maps|git|nihility|nmdu|shpo1|e1m4b|e1m8b)
  157.         iwad='doom'
  158.         complevel='3'
  159.         case $map in
  160.             dtwid)
  161.                 map='dtwid udtwid'
  162.                 ;;
  163.             dtwid-e5)
  164.                 map='dtwid-le dtwid-e5'
  165.                 ;;
  166.             hadron)
  167.                 map='hadron hadrone2'
  168.                 ;;
  169.             sigil)
  170.                 postpatch='d1spfx_sigil'
  171.                 map='sigil_compat'
  172.                 ;;
  173.             git)
  174.                 dehpatch='git.deh'
  175.                 ;;
  176.         esac
  177.         ;;
  178.     # Maps for TNT: Evilution
  179.     tnt|tntr)
  180.         iwad='tnt'
  181.         complevel='4'
  182.         ;;
  183.     # Maps for The Plutonia Experiment
  184.     plutonia|plutonia_maps|prcp|pl2|urania)
  185.         iwad='plutonia'
  186.         complevel='4'
  187.         case $map in
  188.             plutonia)
  189.                 postpatch='plutmidi'
  190.                 ;;
  191.         esac
  192.         ;;
  193.     # Maps for The Plutonia Experiment but that also require Boom
  194.     c-shock)
  195.         iwad='plutonia'
  196.         complevel='9'
  197.         ;;
  198.     # Maps for Boom-compatible source ports
  199.     ayy|aaliens|vanguard|gd|swtw|stardate*|sod|preacher|sunlust|jenesis|catk|crumpets|fcff|magnolia|sunder|cchest2|cchest3|cchest4|avactor|c-shock2|mayhem*|cryogenics|demonastery|disjunct|dmdclockout|dmnsns|dv2|epic|flotsam|frozent|hg|jadearth|joi_lstcv15|legher|lunatic|maskimxul|memorial|oku2v31|mohu*|moonbld|ngmvmt1|portglacia|resurge|rush|sf2012|thtthren|uacultra|vrack|wos|2s1k)
  200.         iwad='doom2'
  201.         complevel='9'
  202.         case $map in
  203.             ayy|aaliens)
  204.                 postpatch='d2spfx_aaliens'
  205.                 map='aaliens'
  206.                 ;;
  207.             mayhem17)
  208.                 postpatch='d2spfx_mayhem17'
  209.                 map='mayhem17 mayhem17_updatev1'
  210.                 ;;
  211.             sunlust)
  212.                 postpatch='d2spfx_sunlust'
  213.                 ;;
  214.             catk)
  215.                 postpatch='catk_bar'
  216.                 ;;
  217.         esac
  218.         ;;
  219.     # Maps for MBF-compatible source ports
  220.     valiant|eviternity*|exomoon|dotb|motm|sawdust)
  221.         iwad='doom2'
  222.         complevel='11'
  223.         case $map in
  224.             dotb)
  225.                 postpatch='d2spfx_dotb'
  226.                 ;;
  227.             eviternity*)
  228.                 righthand_status='righthanded_fist'
  229.                 ;;
  230.         esac
  231.         ;;
  232.     *)
  233.         # Ask user for complevel
  234.         printf '%s\n' "2 = Doom2, 3 = UltimateDoom, 4 = FinalDoom, 9 = Boom, 11 = MBF"
  235.         read -r -p 'complevel?'$'\n> ' complevel
  236.         if ! [[ "$complevel" =~ ^[0-9]+$ ]] || ! ((complevel >= 0 && complevel <=17)); then
  237.             echo "complevel must be an integer between 0 and 17"
  238.             exit 1
  239.         fi
  240.  
  241.         # Old way of determining correct IWAD
  242.         # Abandoned because of possible weird edge cases
  243.         #case $complevel in
  244.         #    2|9|11)
  245.         #        iwad='doom2'
  246.         #        ;;
  247.         #    3)
  248.         #        iwad='doom'
  249.         #        ;;
  250.         #    4)
  251.         #        read -r -p 'tnt or plutonia based?'$'\n> ' iwad
  252.         #        case $iwad in
  253.         #            tnt|plutonia)
  254.         #                ;;
  255.         #            *)
  256.         #                printf '%s\n\n' "what the fug"
  257.         #                exit 1
  258.         #                ;;
  259.         #        esac
  260.         #        ;;
  261.         #    *)
  262.         #        printf '%s\n\n' "what the fug"
  263.         #        exit 1
  264.         #        ;;
  265.         #esac
  266.  
  267.         # Ask user for IWAD
  268.         printf '%s\n' "doom, doom2, tnt, plutonia, miniwad, freedoom, freedoom2"
  269.         read -r -p 'IWAD?'$'\n> ' iwad
  270.         if [[ " ${valid_iwads[*]} " != *" $iwad "* ]]; then
  271.             echo "not a valid IWAD"
  272.             exit 1
  273.         fi
  274.         printf '\n'
  275.         ;;
  276. esac
  277.  
  278. case $interactive in
  279.     true)
  280.         # Ask user for cvars
  281.         read -r -p 'map# & cvars?'$'\n> ' -a cvars_raw
  282.         [[ -n "${cvars_raw[*]}" ]] && cvars=( '-skill 4' '-warp' "${cvars_raw[*]}" )
  283.         # Ask user if they want smooth weapons
  284.         [[ $strict_check == 'false' && $fancy_check == 'false' ]] &&
  285.         read -r -p 'apply smooth DEH? [y/N] - WARNING: may cause bugs/crashes if map also includes DEH lump'$'\n> ' fancy_check &&
  286.         case $fancy_check in
  287.             ''|n)
  288.                 ;;
  289.             y)
  290.                 smooth='vsmooth'
  291.                 unset righthand_status
  292.                 ;;
  293.             *)
  294.                 printf '%s\n\n' "what the fug"
  295.                 exit 1
  296.                 ;;
  297.         esac
  298.         ;;
  299. esac
  300.  
  301. # Make sure map is unset if it's an IWAD
  302. [[ "$iwad" == "$map" ]] && unset map
  303.  
  304. # Determine whether to load DEH lumps in the sprite fixes or not
  305. case $iwad in
  306.     doom)
  307.         case $strict_check in
  308.             true)
  309.                 prepatch=( 'd1spfx19_nodeh' 'dssecret' )
  310.                 ;;
  311.             false)
  312.                 prepatch=( 'd1spfx19' 'doomsfx' 'doom3_plasma' 'dssecret' )
  313.                 ;;
  314.         esac
  315.         ;;
  316.     doom2|tnt|plutonia)
  317.         case $strict_check in
  318.             true)
  319.                 prepatch=( 'd2spfx19_nodeh' 'dssecret' )
  320.                 ;;
  321.             false)
  322.                 prepatch=( 'd2spfx19' 'doomsfx' 'doom3_plasma' 'dssecret' )
  323.                 ;;
  324.         esac
  325.         ;;
  326.     *)
  327.         prepatch=( 'dssecret' )
  328.         ;;
  329. esac
  330.  
  331. # Show selected variables
  332. glb_arguments=( '-iwad' "$iwad" '-file' "${prepatch[@]}" "$righthand_status" "$smooth" "$map" "$postpatch" '-deh' 'trans_on.deh' "$dehpatch" "${cvars[@]}" '-shorttics' '-complevel' "$complevel" )
  333. printf '%s' "iwad      = [$iwad]"
  334. printf '\n%s' "prepatch  = [${prepatch[*]}]" "righthand = [$righthand_status]" "smooth    = [$smooth]" "map       = [$map]" "postpatch = [$postpatch]" "dehpatch  = [$dehpatch]" "cvars     = [${cvars[*]}]" "complevel = [$complevel]"
  335. printf '\n\n%s\n\n' "----------------------------------------------------------"
  336. printf '\e[1m%s\e[0m' "here we go..."
  337. # Determine if using libstrangle or not
  338. if [ -v libstrangle ]; then
  339.     launch_var=$(printf '%s' "$libstrangle $glb_path ${glb_arguments[*]}" | tr -s ' ')
  340. else
  341.     launch_var=$(printf '%s' "$glb_path ${glb_arguments[*]}" | tr -s ' ')
  342. fi
  343. # Copy final launch command to the clipboard, so you may return easily after quitting
  344. printf '%s' "$launch_var" | tr -d '\n' | xclip
  345. # Display final launch command without binary path
  346. printf '\n%s\n' "glboom-plus ${glb_arguments[*]}" | tr -s ' '
  347. printf '\n%s\n' "----------------------------------------------------------"
  348.  
  349. # Launch GLBoom+ with selected variables
  350. case $dry_check in
  351.     false)
  352.         case $verbose_check in
  353.             false)
  354.                 # Hide GLBoom+'s output
  355.                 eval "$launch_var" > /dev/null 2>&1
  356.                 ;;
  357.             true)
  358.                 # Show GLBoom+'s output
  359.                 eval "$launch_var"
  360.                 ;;
  361.         esac
  362.         ;;
  363. esac
  364.  
  365. # Copyright 2020 PhysixCat
  366.  
  367. # Licensed under the Apache License, Version 2.0 (the "License");
  368. # you may not use this file except in compliance with the License.
  369. # You may obtain a copy of the License at
  370.  
  371. # http://www.apache.org/licenses/LICENSE-2.0
  372.  
  373. # Unless required by applicable law or agreed to in writing, software
  374. # distributed under the License is distributed on an "AS IS" BASIS,
  375. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  376. # See the License for the specific language governing permissions and
  377. # limitations under the License.
  378.  
Add Comment
Please, Sign In to add comment