fant0men

Resolution set script

Apr 1st, 2020
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # This script is meant to test the resolution function of my game installer.
  3.  
  4. distro='fedora'
  5. bin_dir="${HOME}/bin"
  6. install_dir="${HOME}/id_games"
  7. width='1111'
  8. height='2222'
  9. width_out='0'
  10. height_out='0'
  11.  
  12. get_distro () {
  13.     true
  14. }
  15.  
  16. wolf4sdl_res () {
  17.  
  18.     switch='0'
  19.     n='0'
  20.  
  21.     width_base='320'
  22.     height_base[0]='200'
  23.     height_base[1]='240'
  24.  
  25.     set_tmp_var () {
  26.         width_tmp=$(( width_base * n ))
  27.         height_tmp[0]=$(( ${height_base[0]} * n ))
  28.         height_tmp[1]=$(( ${height_base[1]} * n ))
  29.     }
  30.  
  31.     while [[ $switch -eq 0 ]]; do
  32.  
  33.         n=$(( n + 1 ))
  34.         set_tmp_var
  35.  
  36.         if [[ $width_tmp -ge $width ]]; then
  37.             switch='1'
  38.         elif [[ ${height_tmp[0]} -ge $height ]]; then
  39.             switch='1'
  40.         fi
  41.     done
  42.  
  43.     if [[ $width_tmp -gt $width ]]; then
  44.  
  45.         n=$(( n - 1 ))
  46.         set_tmp_var
  47.     elif [[ ${height_tmp[0]} -gt $height ]]; then
  48.  
  49.         n=$(( n - 1 ))
  50.         set_tmp_var
  51.     fi
  52.  
  53.     width_out="$width_tmp"
  54.  
  55.     if [[ ${height_tmp[1]} -le $height ]]; then
  56.         height_out="${height_tmp[1]}"
  57.     else
  58.         height_out="${height_tmp[0]}"
  59.     fi
  60. }
  61.  
  62. rott_res () {
  63.  
  64.     declare -A res_tmp
  65.  
  66.     res_tmp[320]='200'
  67.     res_tmp[640]='480'
  68.     res_tmp[800]='600'
  69.     res_list=(320 640 800)
  70.  
  71.     for width_tmp in ${res_list[@]}; do
  72.         if [[ $width_tmp -le $width ]]; then
  73.             width_out="$width_tmp"
  74.             height_out="${res_tmp[${width_tmp}]}"
  75.         fi
  76.     done
  77. }
  78.  
  79. change_res () {
  80.  
  81.     declare -a config
  82.     prboom_plus='0'
  83.     wolf3d='0'
  84.     sod='0'
  85.     rott='0'
  86.  
  87.     read_config () {
  88.         mapfile -t config <"$if"
  89.     }
  90.  
  91.     change_config () {
  92.         for (( i = 0; i < ${#config[@]}; i++ )); do
  93.             if [[ ${config[${i}]} =~ $regex ]]; then
  94.                 if [[ $prboom_plus -eq 1 ]]; then
  95.                     line_edit=$(sed -E "s/\"[0-9]+x[0-9]+\"/\"${width}x${height}\"/" <<<"${config[${i}]}")
  96.                     prboom_plus='0'
  97.                 fi
  98.  
  99.                 if [[ $wolf3d -eq 1 ]]; then
  100.                     line_edit=$(sed -E "s/--res [0-9]+ [0-9]+/--res ${width_out}x${height_out}/" <<<"${config[${i}]}")
  101.                     wolf3d='0'
  102.                 fi
  103.  
  104.                 if [[ $sod -eq 1 ]]; then
  105.                     line_edit=$(sed -E "s/--res [0-9]+ [0-9]+/--res ${width_out}x${height_out}/" <<<"${config[${i}]}")
  106.                     sod='0'
  107.                 fi
  108.  
  109.                 if [[ $rott -eq 1 ]]; then
  110.                     line_edit=$(sed -E "s/resolution [0-9]+x[0-9]+/resolution ${width_out}x${height_out}/" <<<"${config[${i}]}")
  111.                     rott='0'
  112.                 fi
  113.  
  114.                 config[${i}]="$line_edit"
  115.             fi
  116.         done
  117.     }
  118.  
  119.     write_config () {
  120.         touch "$of" || exit
  121.  
  122.         for (( i = 0; i < ${#config[@]}; i++ )); do
  123.             echo "${config[${i}]}" >> "$of" || exit
  124.         done
  125.  
  126.         mv "$of" "$if" || exit
  127.     }
  128.  
  129.     # Changing the config file for Quake...
  130.  
  131.     if="${install_dir}/quake/ID1/config.cfg"
  132.     of="${if}-${RANDOM}"
  133.     regex='"vid_width" "[0-9]+"'
  134.     line_edit="\"vid_width\" \"${width}\""
  135.  
  136.     read_config
  137.     change_config
  138.  
  139.     regex='"vid_height" "[0-9]+"'
  140.     line_edit="\"vid_height\" \"${height}\""
  141.  
  142.     change_config
  143.     write_config
  144.  
  145.     of="${install_dir}/quake/HIPNOTIC/config.cfg"
  146.     cp "$if" "$of" || exit
  147.  
  148.     of="${install_dir}/quake/ROGUE/config.cfg"
  149.     cp "$if" "$of" || exit
  150.  
  151.     # Changing the config file for Quake 2...
  152.  
  153.     if="${install_dir}/quake2/baseq2/config.cfg"
  154.     of="${if}-${RANDOM}"
  155.     regex='set gl_mode ".*"'
  156.     line_edit='set gl_mode "-1"'
  157.  
  158.     read_config
  159.     change_config
  160.  
  161.     regex='set gl_customwidth "[0-9]+"'
  162.     line_edit="set gl_customwidth \"${width}\""
  163.  
  164.     change_config
  165.  
  166.     regex='set gl_customheight "[0-9]+"'
  167.     line_edit="set gl_customheight \"${height}\""
  168.  
  169.     change_config
  170.     write_config
  171.  
  172.     of="${install_dir}/quake2/xatrix/config.cfg"
  173.     cp "$if" "$of" || exit
  174.  
  175.     of="${install_dir}/quake2/rogue/config.cfg"
  176.     cp "$if" "$of" || exit
  177.  
  178.     # Changing the config file for Quake 3...
  179.  
  180.     if="${install_dir}/quake3/baseq3/q3config.cfg"
  181.     of="${if}-${RANDOM}"
  182.     regex='seta r_customwidth "[0-9]+"'
  183.     line_edit="seta r_customwidth \"${width}\""
  184.  
  185.     read_config
  186.     change_config
  187.  
  188.     regex='seta r_customheight "[0-9]+"'
  189.     line_edit="seta r_customheight \"${height}\""
  190.  
  191.     change_config
  192.     write_config
  193.  
  194.     # Changing the config file for PrBoom-plus...
  195.  
  196.     if="${install_dir}/prboom-plus/prboom-plus.cfg"
  197.     of="${if}-${RANDOM}"
  198.     regex='screen_resolution[[:blank:]]+"[0-9]+x[0-9]+"'
  199.     prboom_plus='1'
  200.  
  201.     read_config
  202.     change_config
  203.     write_config
  204.  
  205.     # Changing the config file for Doom 64 EX...
  206.  
  207.     if="${install_dir}/doom64ex/local/share/doom64ex/config.cfg"
  208.     of="${if}-${RANDOM}"
  209.     regex='seta "v_Width" "[0-9]+"'
  210.     line_edit="seta \"v_Width\" \"${width}\""
  211.  
  212.     read_config
  213.     change_config
  214.  
  215.     regex='seta "v_Height" "[0-9]+"'
  216.     line_edit="seta \"v_Height\" \"${height}\""
  217.  
  218.     change_config
  219.     write_config
  220.  
  221.     # Changing the run commands for Wolf3D, SoD, and RotT...
  222.  
  223.     wolf4sdl_res
  224.  
  225.     if="${bin_dir}/id_games.sh"
  226.     of="${if}-${RANDOM}"
  227.  
  228.     wolf3d='1'
  229.  
  230.     if [[ $distro == 'fedora' ]]; then
  231.         regex='[[:blank:]]*wolf4sdl-registered-id --res [0-9]+ [0-9]+.*'
  232.     elif [[ $distro == 'ubuntu' ]]; then
  233.         regex='[[:blank:]]*wolf4sdl --res [0-9]+ [0-9]+.*'
  234.     fi
  235.  
  236.     read_config
  237.     change_config
  238.  
  239.     sod='1'
  240.  
  241.     if [[ $distro == 'fedora' ]]; then
  242.         regex='[[:blank:]]*wolf4sdl-spear --res [0-9]+ [0-9]+ --goodtimes.*'
  243.     elif [[ $distro == 'ubuntu' ]]; then
  244.         regex='[[:blank:]]*wolf4sdl-sod --res [0-9]+ [0-9]+ --goodtimes.*'
  245.     fi
  246.  
  247.     change_config
  248.  
  249.     rott_res
  250.  
  251.     rott='1'
  252.  
  253.     if [[ $distro == 'fedora' ]]; then
  254.         regex='[[:blank:]]*rott-registered fullscreen resolution [0-9]+x[0-9]+.*'
  255.     elif [[ $distro == 'ubuntu' ]]; then
  256.         regex='[[:blank:]]*rott-commercial fullscreen resolution [0-9]+x[0-9]+.*'
  257.     fi
  258.  
  259.     change_config
  260.     write_config
  261.  
  262.     chmod +x "$if" || exit
  263. }
  264.  
  265. change_res
RAW Paste Data