Subversion Repositories duke3d_hrp

Rev

Rev 656 | Blame | Last modification | View Log | RSS feed

  1. #!/bin/bash
  2.  
  3. # Duke Nukem 3D High Resolution Pack Extractor  v0.7  2014-12-05
  4. #
  5. # Author: LeoD
  6. # License: ISC license : http://opensource.org/licenses/isc-license.txt
  7. #
  8. # This script extracts a working copy of your local Duke Nukem 3D High
  9. # Resolution Pack's Subversion repository, ready for zipping and distribution.
  10. # This is mostly done by hierarchically parsing the *.def files.
  11. # PolyMER or PolyMOST only versions can be chosen.
  12. # On Windows you might want MSYS' zip to create package files.
  13. # ("mingw-get install msys-zip")
  14. # MinGW/MSYS performance is horrible, better go Linux. Even my virtual Debian
  15. # machine accessing the Windows drive is 5 to 10 times faster.
  16. # But it still sucks. This needs to become a Perl script one day.
  17. # Or maybe MSYS' bash gets finally updated to 4.* and I'll use its regex engine.
  18.  
  19. DEF_TOP=UNDEFINED
  20. SET_VERSION=YES            # [YES|NO]
  21. EXTRACT_COMMENTED_FILES=NO # [YES|NO]
  22. DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH=polymost  #[none|polymost|polymer|mixed]
  23. ATTRITION_POLYMOST_COMPATIBILTY_APPROACH=polymost #[none|polymost|polymer|mixed]
  24.  
  25. ask()
  26. {
  27.   echo -n "$@" '[y/N] ' ; read ans
  28.   case "$ans" in
  29.     y*|Y*) return 0 ;;
  30.     *)     return 1 ;;
  31.   esac
  32. } # ask
  33.  
  34.  
  35. copy_folders()
  36. {
  37.   mkdir ${EXTRACTDIR}
  38.   for HRPDIR in . ; do
  39.     if [ -d "${HRPDIR}" ] ; then
  40.       DIRLIST=./HRP_DIRECTORIES.lst
  41.       find "${HRPDIR}" -type d > ${DIRLIST}
  42.       cat ${DIRLIST} | while read DIR; do
  43.         if [ ! -d "${EXTRACTDIR}/${DIR}" ] ; then
  44.           mkdir "${EXTRACTDIR}/${DIR}"
  45.         fi
  46.       done
  47.       rm     ${DIRLIST}
  48.     else
  49.       echo "${HRPDIR} : no HRP."
  50.     fi
  51.   done
  52. } # copy_folders()
  53.  
  54.  
  55. copy_set_version()
  56. {
  57.   VER_FILE="$1"
  58.   TARGET_FILE="$2"
  59.   if [ ! "${SET_VERSION}" = "YES" ] ; then
  60.     cp -pv "${VER_FILE}" "${TARGET_FILE}"
  61.   else
  62.  
  63.     V_DATE=`date +%F`
  64.     if [ "${VERSION}" = "" ] ; then
  65.       if [ -f VERSION ] ; then
  66.         VERSION=`grep -owE "[0-9\\.]*" VERSION`
  67.       fi
  68.     fi
  69.  
  70.     echo "copy_set_version ${VER_FILE} -> ${TARGET_FILE}"
  71.  
  72.     case "${VER_FILE}" in
  73.       hrp_readme.txt)
  74.         cat "${VER_FILE}" | sed -r --posix \
  75.           s/\(Version\ *\)\([0-9\.]*\)\(.*\)\(\\\)\)\(.*\)/\\1${VERSION}\ \(${V_DATE}\)\ \ \\5/ \
  76.           >> "${TARGET_FILE}"
  77.         ;;
  78.       duke3d_hrp.def)
  79.         if [ "${HRPTYPE}" = "polymer" ] ; then
  80.           cat "${VER_FILE}" | sed -r --posix \
  81.             s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\ Polymer\\3/ \
  82.             >> "${TARGET_FILE}"
  83.         else
  84.           cat "${VER_FILE}" | sed -r --posix \
  85.             s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
  86.             >> "${TARGET_FILE}"
  87.         fi
  88.         ;;
  89.       duke3d_hrp_polymost.def | \
  90.       installer/polymost_override/duke3d_hrp_polymost_override.def | \
  91.       duke3d_hrp_megaton.def | \
  92.       installer/megaton_override/duke3d_hrp_megaton_override.def )
  93.         cat "${VER_FILE}" | sed -r --posix \
  94.           s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
  95.           >> "${TARGET_FILE}"
  96.         ;;
  97.       *)
  98.         echo "###ERROR: copy_set_version() - BAD FILE: ${VER_FILE}"
  99.         exit 1
  100.         ;;
  101.     esac
  102.   fi
  103. } # copy_set_version()
  104.  
  105. tar_copy_dir()
  106. {
  107.   (cd ${1}; tar cf - . ) | (cd ${2}; tar xf -)
  108. }
  109.  
  110. copy_known_files()
  111. {
  112.   if [ -f  hrp_readme.txt ] ; then
  113.     copy_set_version hrp_readme.txt "${EXTRACTDIR}/hrp_readme.txt"
  114.   fi
  115.  
  116.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
  117.      [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "megaton_override" ] ||\
  118.      [ "${HRPTYPE}" = "polymer"  ] || [ "${HRPTYPE}" = "full" ] ; then
  119.     cp -pv hrp_art_license.txt      "${EXTRACTDIR}"
  120.   fi
  121.  
  122.   if [ "${HRPTYPE}" = "polymost" ] ; then
  123.     cp -pv  duke3d_hrp_polymost.def            "${EXTRACTDIR}"
  124.     copy_set_version duke3d_hrp_polymost.def   "${EXTRACTDIR}/duke3d_hrp.def"
  125.     cp -pvr installer/polymost_override/dukedc "${EXTRACTDIR}"
  126.   fi
  127.  
  128.   if [ "${HRPTYPE}" = "megaton" ] ; then
  129.     cp -pv duke3d_hrp_megaton.def           "${EXTRACTDIR}"
  130.     copy_set_version duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp.def"
  131.     cp -pv highres/screen/menu/2492_ver_megaton.png \
  132.       "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
  133.     cp -pvr installer/megaton_override/dukedc* "${EXTRACTDIR}"
  134.     cp -pvr installer/megaton_override/highres "${EXTRACTDIR}"
  135.   fi
  136.  
  137.   if [ "${HRPTYPE}" = "polymost_override" ] ; then
  138.     copy_set_version \
  139.       installer/polymost_override/duke3d_hrp_polymost_override.def \
  140.       "${EXTRACTDIR}/duke3d_hrp.def"
  141.     copy_set_version \
  142.       installer/polymost_override/duke3d_hrp_polymost_override.def \
  143.       "${EXTRACTDIR}/duke3d_hrp_polymost.def"
  144.     cp -pvr installer/polymost_override/dukedc "${EXTRACTDIR}"
  145.   fi
  146.  
  147.   if [ "${HRPTYPE}" = "megaton_override" ] ; then
  148.     copy_set_version \
  149.       installer/megaton_override/duke3d_hrp_megaton_override.def \
  150.       "${EXTRACTDIR}/duke3d_hrp.def"
  151.     copy_set_version \
  152.       installer/megaton_override/duke3d_hrp_megaton_override.def \
  153.       "${EXTRACTDIR}/duke3d_hrp_megaton.def"
  154.     cp -pv  installer/megaton_override/*.bat   "${EXTRACTDIR}"
  155.     cp -pvr installer/megaton_override/dukedc* "${EXTRACTDIR}"
  156.     cp -pvr installer/megaton_override/highres "${EXTRACTDIR}"
  157.     # Let Megaton Override work on top of Polymost HRP:
  158.     cp -pv highres/sprites_megaton.def         "${EXTRACTDIR}/highres"
  159.     cp -pv highres/sprites/effects_megaton.def "${EXTRACTDIR}/highres/sprites"
  160.   fi
  161.  
  162.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "megaton" ] ; then
  163.     cp -pv duke3d.def "${EXTRACTDIR}"
  164.     cp -pv highres/screen/menu/2492_polymost.png \\
  165.       "${EXTRACTDIR}/highres/screen/menu"
  166.   fi
  167.  
  168.   if [ "${HRPTYPE}" = "full" ] ; then
  169.     copy_set_version duke3d_hrp_polymost.def \
  170.       "${EXTRACTDIR}/duke3d_hrp_polymost.def"
  171.     copy_set_version duke3d_hrp_megaton.def \
  172.       "${EXTRACTDIR}/duke3d_hrp_megaton.def"
  173.   fi
  174.  
  175.   if [ "${HRPTYPE}" = "full" ] ; then
  176.     cp -pv highres/screen/menu/2492_ver_polymost.png \
  177.       "${EXTRACTDIR}/highres/screen/menu"
  178.   fi
  179.  
  180.   if [ "${HRPTYPE}" = "polymost_override" ] ; then
  181.     cp -pv installer/polymost_override/hrp_polymost_override.txt \
  182.       "${EXTRACTDIR}"
  183.     cp -pv installer/polymost_override/2492_ver_polymost_override.png \
  184.       "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
  185.   fi
  186.  
  187.   if [ "${HRPTYPE}" = "megaton_override" ] ; then
  188.     cp -pv installer/megaton_override/hrp_megaton_override.txt \
  189.       "${EXTRACTDIR}"
  190.     cp -pv installer/megaton_override/2492_ver_megaton_override.png \
  191.       "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
  192.   fi
  193.  
  194.   if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
  195.     cp -pv duke3d.def                   "${EXTRACTDIR}"
  196.     copy_set_version duke3d_hrp.def "${EXTRACTDIR}/duke3d_hrp.def"
  197.     echo                  "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
  198.     cp -p  *.mhk                        "${EXTRACTDIR}"
  199.     #cp -pv highres/screen/menu/2492.png "${EXTRACTDIR}/highres/screen/menu"
  200.  
  201.     #cp -pv highres/common/black.png                          "${EXTRACTDIR}/highres/common"
  202.     #cp -pv highres/screen/fonts/digital/digital_minus.png    "${EXTRACTDIR}/highres/screen/fonts/digital"
  203.     #cp -pv highres/screen/menu/widescreen/*_wide.png         "${EXTRACTDIR}/highres/screen/menu"
  204.     #cp -pv highres/sprites/characters/1357_terminarm.md3     "${EXTRACTDIR}/highres/sprites/characters"
  205.     #cp -pv highres/sprites/firstperson/2510_devastator_n.png "${EXTRACTDIR}/highres/sprites/firstperson"
  206.     #cp -pv highres/sprites/monsters/1960_reconcar_s.png      "${EXTRACTDIR}/highres/sprites/monsters"
  207.     #cp -pv highres/sprites/props/4387.png                    "${EXTRACTDIR}/highres/sprites/props"
  208.     #cp -pv highres/sprites/signs/4378-79.png                 "${EXTRACTDIR}/highres/sprites/signs"
  209.     #cp -pv highres/sprites/signs/4381-85.png                 "${EXTRACTDIR}/highres/sprites/signs"
  210.   fi
  211.  
  212.   if [ "${HRPTYPE}" = "voxel" ] ; then
  213.     cp -pv readme.txt             "${EXTRACTDIR}"
  214.     cp -pv voxelp_art_license.txt "${EXTRACTDIR}"
  215.     cp -pv duke3d.def             "${EXTRACTDIR}"
  216.     cp -pv duke3d_voxel.def       "${EXTRACTDIR}"
  217.     echo            "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
  218.     cp -p  *.mhk                  "${EXTRACTDIR}"
  219.   fi
  220.  
  221.   if [ "${HRPTYPE}" = "sw_highres" ] ; then
  222.     cp -pv sw.def                   "${EXTRACTDIR}"
  223.     cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres"
  224.     cp -pv HRP.bat                  "${EXTRACTDIR}"
  225.     cp -pv HRP_Readme.txt           "${EXTRACTDIR}"
  226.     cp -pv HRP_Changes.txt          "${EXTRACTDIR}"
  227.     echo "Copying skyboxes ..."
  228.     tar_copy_dir "highres/skyboxes" "${EXTRACTDIR}/highres/skyboxes"
  229.     cd "${WORKDIR}"
  230.   fi
  231.  
  232.   if [ "${HRPTYPE}" = "sw_lowres" ] ; then
  233.     echo "Creating sw.def for lowres HRP ..."
  234.     echo "include lowres/sw_lrp.def" > "${EXTRACTDIR}/sw.def"
  235.     cp -pv lowres/sw_lrp.def           "${EXTRACTDIR}/lowres"
  236.     cp -pv LRP.bat                     "${EXTRACTDIR}"
  237.     cp -pv LRP_Readme.txt              "${EXTRACTDIR}"
  238.     cp -pv LRP_Changes.txt             "${EXTRACTDIR}"
  239.     echo "Copying skyboxes ..."
  240.     tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
  241.     cd "${WORKDIR}"
  242.   fi
  243.  
  244.   if [ "${HRPTYPE}" = "default" ] ; then
  245.     cp -pv  "${DEF_TOP}"          "${EXTRACTDIR}/${DEF_TOP}"
  246.     echo            "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
  247.     cp -p  *.mhk                  "${EXTRACTDIR}"
  248.     echo            "\`*.txt' -> \`${EXTRACTDIR}/*.txt'"
  249.     cp -p  *.txt                  "${EXTRACTDIR}"
  250.   fi
  251.  
  252. } # copy_known_files()
  253.  
  254.  
  255. copy_polymost_mhk()
  256. {
  257.   cp -p maphacks/3drealms_polymost/E?L*.mhk "${EXTRACTDIR}"
  258.   rm -f "${EXTRACTDIR}"/*_13d_*.mhk
  259.   # bashism:
  260.   for i in "${EXTRACTDIR}"/*.mhk ; do mv "$i" "${i/_polymost.mhk}".mhk ; done
  261.   # Some people prefer unusual setups ...
  262.   if [ "${HRPTYPE}" = "polymost" ]||[ "${HRPTYPE}" = "polymost_override" ];then
  263.     zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip *.mhk
  264.   fi
  265. } # copy_polymost_mhk()
  266.  
  267.  
  268. # I really don't know yet if this will become necessary, or if it does make
  269. # sense at all, but at least the files involved are listed.
  270. dukeplus_polymost_hrp_compatibility()
  271. {
  272.   # dukeplus.def expects some files to be present in the HRP
  273.   #
  274.   # model "highres/sprites/characters/1405_duke.md3" { // all OK, no action required
  275.   #    skin { pal 0 surface 0 file "highres/sprites/pickups/0057_jetpack.png" }
  276.   #    skin { pal 0 surface 1 file "highres/sprites/characters/1405_duke.png" }
  277.   #    skin { pal 10 surface 1 file "highres/sprites/characters/1405_duke_10.png" }
  278.   #    skin { pal 11 surface 1 file "highres/sprites/characters/1405_duke_11.png" }
  279.   #    skin { pal 12 surface 1 file "highres/sprites/characters/1405_duke_12.png" }
  280.   #    skin { pal 13 surface 1 file "highres/sprites/characters/1405_duke_13.png" }
  281.   #    skin { pal 14 surface 1 file "highres/sprites/characters/1405_duke_14.png" }
  282.   #    skin { pal 15 surface 1 file "highres/sprites/characters/1405_duke_15.png" }
  283.   #    skin { pal 16 surface 1 file "highres/sprites/characters/1405_duke_16.png" }
  284.   #    skin { pal 21 surface 1 file "highres/sprites/characters/1405_duke_21.png" }
  285.   #    skin { pal 23 surface 1 file "highres/sprites/characters/1405_duke_23.png" }
  286.   #    skin { pal 0 surface 2 file "highres/sprites/pickups/0023_rpg.png" }
  287.   #
  288.   # model "highres/sprites/firstperson/2510_devastator.md3" { // since Imperium, not Eternity
  289.   #    skin { pal 0 file "highres/sprites/firstperson/2510_devastator.png" specfactor 0.5 specpower 35 }
  290.   #    specular { file "highres/sprites/firstperson/2510_devastator_s.png" }
  291.   #    glow { file "highres/sprites/firstperson/2510_devastator_g.png" }
  292.   #
  293.   # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295    
  294.   #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
  295.   #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
  296.   # model "highres/sprites/firstperson/2530_clip.md3" {                  // most/mer : diff MD3, same skin
  297.   #    skin { pal 0 file "highres/sprites/pickups/0040_pistolammo.jpg" }
  298.   # model "highres/sprites/firstperson/2532_cliphand.md3" {  // most/mer : same MD3 + same skin til r295
  299.   #    skin { pal 0 file "highres/sprites/firstperson/2532_cliphand.png" } // til r295, then duke_hand_*
  300.   #
  301.  
  302.   SPR="highres/sprites"
  303.   SPRE="${EXTRACTDIR}/highres/sprites"
  304.   PATCHTYPE=$1
  305.  
  306.   case "$PATCHTYPE" in
  307.     polymer)
  308.       echo "  # (Using \"Polymer approach\")"
  309.       cp -pi $SPR/firstperson/2510_devastator.md3            "$SPRE/firstperson"
  310.       cp -pi $SPR/firstperson/2510_devastator.png            "$SPRE/firstperson"
  311.       cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson"
  312.       cp -pi $SPR/firstperson/2510_devastator_g.png          "$SPRE/firstperson"
  313.       cp -pi $SPR/firstperson/2524_pistol.md3                "$SPRE/firstperson"
  314.       cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
  315.       cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
  316.       cp -pi $SPR/firstperson/2530_clip.md3                  "$SPRE/firstperson"
  317.       cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups"
  318.       cp -pi $SPR/firstperson/2532_cliphand.md3              "$SPRE/firstperson"
  319.       cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson"
  320.       cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson"
  321.       cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson"
  322.       cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson"
  323.       ;;
  324.     polymost)
  325.       echo "  # (Using \"Polymost approach\")"
  326.       #cp -pi $SPR/firstperson_polymost/2510_devastator.md3   "$SPRE/firstperson"
  327.       #cp -pi $SPR/firstperson_polymost/2510_devastator.png   "$SPRE/firstperson"
  328.       ##cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson"
  329.       #cp -pi $SPR/firstperson_polymost/2510_devastator_g.png "$SPRE/firstperson"
  330.       cp -pi $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson"
  331.       #cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
  332.       #cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
  333.       #cp -pi $SPR/firstperson_polymost/2530_clip.md3         "$SPRE/firstperson"
  334.       #cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups"
  335.       #cp -pi $SPR/firstperson_polymost/2532_cliphand.md3     "$SPRE/firstperson"
  336.       #cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson"
  337.       #cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson"
  338.       #cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson"
  339.       #cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson"
  340.       ;;
  341.     mixed)
  342.       echo "  # (Using \"Mixed approach\")"
  343.       echo "    # Not applied / Not yet implemented"
  344.       ;;
  345.     none)
  346.       echo "  Not applied"
  347.       #echo "  # Not yet implemented"
  348.       ;;
  349.     *)
  350.       echo "  # Bad parameter"
  351.       ;;
  352.   esac
  353.  
  354. } # dukeplus_polymost_hrp_compatibility()
  355.  
  356.  
  357. attrition_polymost_hrp_compatibility()
  358. {
  359.   # attr_hrp.def expects some files to be present in the HRP
  360.   #
  361.   # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295    
  362.   #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
  363.   #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
  364.  
  365.   SPR="highres/sprites"
  366.   SPRE="${EXTRACTDIR}/highres/sprites"
  367.   PATCHTYPE=$1
  368.  
  369.   case "$PATCHTYPE" in
  370.     polymer)
  371.       echo "  # (Using \"Polymer approach\")"
  372.       ;;
  373.     polymost)
  374.       echo "  # (Using \"Polymost approach\")"
  375.       cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson"
  376.       cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson"
  377.       cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson"
  378.       cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson"
  379.       #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson"
  380.       ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson"
  381.       #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
  382.       ;;
  383.     mixed)
  384.       echo "  # (Using \"Mixed approach\")"
  385.       cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson"
  386.       cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
  387.       cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
  388.       cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson"
  389.       #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson"
  390.       ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson"
  391.       #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
  392.       cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson"
  393.       cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
  394.       cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson"
  395.       cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson"
  396.       cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson"
  397.       cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson"
  398.       cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson"
  399.       cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson"
  400.       cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
  401.       ;;
  402.     none)
  403.       echo "  Not applied"
  404.       #echo "  # Not yet implemented"
  405.       ;;
  406.     *)
  407.       echo "  # Bad parameter"
  408.       ;;
  409.   esac
  410.  
  411. } # attrition_polymost_hrp_compatibility()
  412.  
  413.  
  414. parse_defs()
  415. {
  416.   echo "$1"
  417.   BLOCK_COMMENT="OFF"
  418.   cat $1 | while read DEF_LINE; do
  419.  
  420.     #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
  421.     #DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
  422. #    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\/\\\/.*// | sed s/\\\r//`
  423.     DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
  424.     if [ "${DEF_FILE}" != "" ] ; then
  425.       cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
  426.       parse_defs "${DEF_FILE}"
  427.     fi
  428.  
  429.     #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
  430.     ## Old style added (except "defineskybox"):
  431.     HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
  432.     #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
  433.  
  434.     if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  435.  
  436.       COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
  437.       if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
  438.  
  439.       if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
  440.  
  441.       if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
  442.  
  443.       if [ ! "$HRP_TERM" = "" ] ; then
  444.         HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
  445.         if [ ! "$HRP_COMMENT" = "" ] ; then
  446.           HRP_TERM=""
  447.         fi
  448.       fi
  449.  
  450.     fi
  451.  
  452.     case "$HRP_TERM" in
  453.       file|mhkfile)
  454.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
  455.         # Mastering the backslash :-) ... hm, no big performance gain ... :
  456.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  457.         # Ignore comments WIP:
  458.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
  459.         ;;
  460.       model|voxel)
  461.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  462.         ;;
  463.       front|right|back|left|top|bottom|down)
  464.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
  465.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  466.         ;;
  467.       ## Old Style
  468.       definemodel)
  469.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  470.         ;;
  471.       definemodelskin)
  472.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  473.         ;;
  474.       definetexture)
  475.         # Won't work atm if filename in quotes (too lazy)
  476.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
  477.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
  478.         #echo "DEF_LINE : ${DEF_LINE}"
  479.         #echo "HRP_FILE : ${HRP_FILE}"
  480.         ;;
  481.       *)
  482.         HRP_FILE=""
  483.         ;;
  484.     esac
  485.  
  486.     if [  !   "${HRP_FILE}" = "" ] ; then
  487.       if [ -f "${HRP_FILE}" ] ; then
  488.         cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
  489.       else
  490.         echo  "WARNING : ${HRP_FILE} is missing!"
  491.       fi
  492.     fi
  493.  
  494.   done
  495. } # parse_defs()
  496.  
  497.  
  498. delete_empty_folders()
  499. {
  500.     if [ -d "${EXTRACTDIR}" ] ; then
  501.       rm -rf ${EXTRACTDIR}/.svn
  502.       DIRLIST=./EXTRACT_DIRECTORIES.lst
  503.       du "${EXTRACTDIR}" > ${DIRLIST}
  504.       cat ${DIRLIST} | while read DIR ; do
  505.         if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
  506.           EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
  507.           if [ -d ${EMPTYDIR} ] ; then
  508.             rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
  509.           fi
  510.         fi
  511.       done
  512.       rm ${DIRLIST}
  513.     else
  514.       echo "No ${EXTRACTDIR}."
  515.     fi
  516. } # delete_empty_folders()
  517.  
  518.  
  519. main()
  520. {
  521.   EXTRACTDIR=../hrp_${HRPTYPE}_extract
  522.   echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
  523.  
  524.   if [ $FORCE = 0 ] ; then
  525.     if ask "Proceed?"
  526.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  527.       else exit 0
  528.     fi
  529.   fi
  530.  
  531.   date +%F" "%H:%M:%S
  532.  
  533.   echo "### Deleting ${EXTRACTDIR} ... ###"
  534.   rm -rf ${EXTRACTDIR}
  535.  
  536.   echo "### Copying directory tree ... ###"
  537.   copy_folders
  538.  
  539.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
  540.     [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ] ; then
  541.     echo "### Copying Polymost maphacks ... ###"
  542.     copy_polymost_mhk
  543.  
  544.     echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
  545.     dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
  546.  
  547.     echo "### Attrition<>Polymost HRP compatibility patch ... ###"
  548.     attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
  549.   fi
  550.  
  551.   echo "### Parsing DEF file hierarchy ... ###"
  552.   if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  553.     echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
  554.   else
  555.     echo "  # Extract commented textures and models: NO"
  556.   fi
  557.   if [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "full" ] ; then
  558.     parse_defs duke3d_hrp_megaton.def
  559.   fi
  560.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
  561.     parse_defs duke3d_hrp_polymost.def
  562.   fi
  563.   if [ "${HRPTYPE}" = "polymer" ]  || [ "${HRPTYPE}" = "full" ] ; then
  564.     parse_defs duke3d_hrp.def
  565.   fi
  566.   if [ "${HRPTYPE}" = "voxel" ] ; then
  567.     parse_defs duke3d_voxel.def
  568.   fi
  569.   if [ "${HRPTYPE}" = "sw_highres" ] ; then
  570.     parse_defs highres/sw_hrp.def
  571.   fi
  572.   if [ "${HRPTYPE}" = "sw_lowres" ] ; then
  573.     parse_defs lowres/sw_lrp.def
  574.   fi
  575.   if [ "${HRPTYPE}" = "default" ] ; then
  576.     parse_defs "${DEF_TOP}"
  577.   fi
  578.  
  579.   echo "### Copying 'known' files ... ###"
  580.   copy_known_files
  581.  
  582.   echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
  583.   delete_empty_folders
  584.  
  585.   date +%F" "%H:%M:%S
  586.  
  587.   echo "Command line example for creating a ZIP package:"
  588.   echo "sh -c \"cd ${EXTRACTDIR} ; zip -rqn .zip:.jpg:.png ${EXTRACTDIR}.zip *\""
  589. } # main()
  590.  
  591.  
  592.  
  593. PRGPATH=$0
  594. HRPTYPE=$1
  595. if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
  596. if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
  597.   VERSION="$3"
  598.   echo "${VERSION}" > VERSION
  599. fi
  600. HRPROOT=.
  601. WORKDIR=`pwd`
  602.  
  603. cd               "${HRPROOT}"
  604. echo  "PWD     :  ${WORKDIR}"
  605. echo  "HRPROOT :  ${HRPROOT}"
  606.  
  607. case "$HRPTYPE" in
  608.   polymer|polymost_override|polymost|megaton_override|megaton)
  609.     main $HRPTYPE
  610.     ;;
  611.   full)
  612.     if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Packs)?"
  613.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  614.       else exit 0
  615.     fi ; fi
  616.     ${PRGPATH} polymost_override y
  617.     ${PRGPATH} megaton_override y
  618.     main $HRPTYPE
  619.     ;;
  620.   both)
  621.     if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
  622.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  623.       else exit 0
  624.     fi ; fi
  625.     ${PRGPATH} polymer  y
  626.     ${PRGPATH} polymost y
  627.     ;;
  628.   ovr)
  629.     ${PRGPATH} polymost_override y
  630.     ${PRGPATH} megaton_override y
  631.     ;;
  632.   all)
  633.     if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
  634.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  635.       else exit 0
  636.     fi ; fi
  637.     ${PRGPATH} both    y
  638.     ${PRGPATH} megaton y
  639.     ${PRGPATH} full    y
  640.     ;;
  641.   voxel)
  642.     SET_VERSION=NO
  643.     main $HRPTYPE
  644.     ;;
  645.   sw_highres|sw_lowres)
  646.     SET_VERSION=NO
  647.     main $HRPTYPE
  648.     ;;
  649.   sw_both)
  650.     if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
  651.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  652.       else exit 0
  653.     fi ; fi
  654.     ${PRGPATH} sw_lowres  y
  655.     ${PRGPATH} sw_highres y
  656.     ;;
  657.   unused)
  658.     echo "Option \"$1\" not yet implemented."
  659.     ;;
  660.   debug)
  661.     echo "Nothing to debug."
  662.     ;;
  663.   *)
  664.     if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
  665.       DEF_TOP="${HRPTYPE}"
  666.       HRPTYPE=default
  667.       SET_VERSION=NO
  668.       EXTRACT_COMMENTED_FILES=NO
  669.       main $HRPTYPE
  670.     else
  671.       echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
  672.       echo "HRPTYPEs: {full|ovr|all}"
  673.       echo "HRPTYPEs: {polymer|polymost_override|polymost|both}"
  674.       echo "HRPTYPEs: {megaton_override|megaton}"
  675.       echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
  676.       exit 1
  677.     fi
  678.     ;;
  679. esac
  680.  
  681. exit 0
  682.