Subversion Repositories duke3d_hrp

Rev

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

  1. #!/bin/bash
  2.  
  3. # Duke Nukem 3D High Resolution Pack Extractor  v0.8.0  2019-05-07
  4. #
  5. # Author: LeoD
  6. # License: ISC license : https://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 | grep -v ".\svn" > ${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.       tools/polymost_override/duke3d_hrp_polymost_override.def | \
  91.       duke3d_hrp_megaton.def | \
  92.       tools/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}" = "maphacks" ] ||\
  119.      [ "${HRPTYPE}" = "polymer"  ] || [ "${HRPTYPE}" = "full" ] ; then
  120.     cp -pv hrp_art_license.txt      "${EXTRACTDIR}"
  121.   fi
  122.  
  123.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymer" ] ||\
  124.      [ "${HRPTYPE}" = "maphacks" ] || [ "${HRPTYPE}" = "full" ] ; then
  125.     cp -pv maphacks/MapHacks.txt    "${EXTRACTDIR}/maphacks/"
  126.   fi
  127.  
  128.   if [ "${HRPTYPE}" = "polymost" ] ; then
  129.     cp -pv           duke3d_hrp_polymost.def "${EXTRACTDIR}"
  130.     copy_set_version duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp.def"
  131.     cp -pvr tools/polymost_override/dukedc   "${EXTRACTDIR}"
  132.   fi
  133.  
  134.   if [ "${HRPTYPE}" = "megaton" ] ; then
  135.     cp -pv           duke3d_hrp_megaton.def "${EXTRACTDIR}"
  136.     copy_set_version duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp.def"
  137.     cp -pv highres/screen/menu/2492_ver_megaton.png \
  138.       "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
  139.     cp -pvr tools/megaton_override/dukedc* "${EXTRACTDIR}"
  140.     cp -pvr tools/megaton_override/highres "${EXTRACTDIR}"
  141.   fi
  142.  
  143.   if [ "${HRPTYPE}" = "polymost_override" ] ; then
  144.     copy_set_version \
  145.       tools/polymost_override/duke3d_hrp_polymost_override.def \
  146.       "${EXTRACTDIR}/duke3d_hrp.def"
  147.     copy_set_version \
  148.       tools/polymost_override/duke3d_hrp_polymost_override.def \
  149.       "${EXTRACTDIR}/duke3d_hrp_polymost.def"
  150.     cp -pv tools/polymost_override/hrp_polymost_override.txt \
  151.       "${EXTRACTDIR}"
  152.     cp -pv tools/polymost_override/2492_ver_polymost_override.png \
  153.       "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
  154.     cp -pvr tools/polymost_override/dukedc "${EXTRACTDIR}"
  155.   fi
  156.  
  157.   if [ "${HRPTYPE}" = "megaton_override" ] ; then
  158.     copy_set_version \
  159.       tools/megaton_override/duke3d_hrp_megaton_override.def \
  160.       "${EXTRACTDIR}/duke3d_hrp.def"
  161.     copy_set_version \
  162.       tools/megaton_override/duke3d_hrp_megaton_override.def \
  163.       "${EXTRACTDIR}/duke3d_hrp_megaton.def"
  164.     cp -pv tools/megaton_override/hrp_megaton_override.txt \
  165.       "${EXTRACTDIR}"
  166.     cp -pv tools/megaton_override/2492_ver_megaton_override.png \
  167.       "${EXTRACTDIR}/highres/screen/menu/2492_ver_megaton.png"
  168.     cp -pv  tools/megaton_override/*.bat   "${EXTRACTDIR}"
  169.     cp -pvr tools/megaton_override/dukedc* "${EXTRACTDIR}"
  170.     cp -pvr tools/megaton_override/highres "${EXTRACTDIR}"
  171.     # Let Megaton Override work on top of Polymost HRP:
  172.     cp -pv highres/screen_megaton.def          "${EXTRACTDIR}/highres/"
  173.     cp -pv highres/screen/menu_megaton.def     "${EXTRACTDIR}/highres/"
  174.     cp -pv highres/sprites_megaton.def         "${EXTRACTDIR}/highres/"
  175.     cp -pv highres/sprites/effects_megaton.def "${EXTRACTDIR}/highres/sprites/"
  176.   fi
  177.  
  178.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "megaton" ] ; then
  179.     cp -pv duke3d.def "${EXTRACTDIR}"
  180.     cp -pv highres/screen/menu/2492_polymost.png \
  181.       "${EXTRACTDIR}/highres/screen/menu/"
  182.   fi
  183.  
  184.   if [ "${HRPTYPE}" = "full" ] ; then
  185.     copy_set_version duke3d_hrp_polymost.def \
  186.       "${EXTRACTDIR}/duke3d_hrp_polymost.def"
  187.     copy_set_version duke3d_hrp_megaton.def \
  188.       "${EXTRACTDIR}/duke3d_hrp_megaton.def"
  189.   fi
  190.  
  191.   if [ "${HRPTYPE}" = "full" ] ; then
  192.     cp -pv highres/screen/menu/2492_ver_polymost.png \
  193.       "${EXTRACTDIR}/highres/screen/menu/"
  194.   fi
  195.  
  196.   if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
  197.     cp -pv           duke3d.def     "${EXTRACTDIR}"
  198.     copy_set_version duke3d_hrp.def "${EXTRACTDIR}/duke3d_hrp.def"
  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}" = "maphacks" ] ; then
  213.     cp -pv                 maphacks/mhk-extract.def "${EXTRACTDIR}/maphacks/"
  214.     cp -pv           duke3d_maphacks_standalone.def "${EXTRACTDIR}"
  215.     copy_set_version duke3d_maphacks_standalone.def "${EXTRACTDIR}/duke3d.def"
  216.   fi
  217.  
  218.   if [ "${HRPTYPE}" = "voxel" ] ; then
  219.     cp -pv voxelpack_readme.txt      "${EXTRACTDIR}"
  220.     cp -pv voxelpack_art_license.txt "${EXTRACTDIR}"
  221.     cp -pv duke3d.def                "${EXTRACTDIR}"
  222.     cp -pv duke3d_voxels.def         "${EXTRACTDIR}"
  223.     if [ -f  EDUKE.CON ] ; then
  224.       cp -pv EDUKE.CON               "${EXTRACTDIR}"
  225.     fi
  226.   fi
  227.  
  228.   if [ "${HRPTYPE}" = "sw_highres" ] ; then
  229.     cp -pv sw.def                   "${EXTRACTDIR}"
  230.     cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres/"
  231.     cp -pv HRP.bat                  "${EXTRACTDIR}"
  232.     cp -pv HRP_Readme.txt           "${EXTRACTDIR}"
  233.     cp -pv HRP_Changes.txt          "${EXTRACTDIR}"
  234.     echo "Copying skyboxes ..."
  235.     tar_copy_dir "highres/skyboxes" "${EXTRACTDIR}/highres/skyboxes"
  236.     cd "${WORKDIR}"
  237.   fi
  238.  
  239.   if [ "${HRPTYPE}" = "sw_lowres" ] ; then
  240.     echo "Creating sw.def for lowres HRP ..."
  241.     echo "include lowres/sw_lrp.def" > "${EXTRACTDIR}/sw.def"
  242.     cp -pv lowres/sw_lrp.def           "${EXTRACTDIR}/lowres/"
  243.     cp -pv LRP.bat                     "${EXTRACTDIR}"
  244.     cp -pv LRP_Readme.txt              "${EXTRACTDIR}"
  245.     cp -pv LRP_Changes.txt             "${EXTRACTDIR}"
  246.     echo "Copying skyboxes ..."
  247.     tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
  248.     cd "${WORKDIR}"
  249.   fi
  250.  
  251.   if [ "${HRPTYPE}" = "default" ] ; then
  252.     cp -pv  "${DEF_TOP}"          "${EXTRACTDIR}/${DEF_TOP}"
  253.     echo            "\`*.txt' -> \`${EXTRACTDIR}/*.txt'"
  254.     cp -p  *.txt                  "${EXTRACTDIR}"
  255.   fi
  256.  
  257. } # copy_known_files()
  258.  
  259.  
  260. copy_polymost_mhk()
  261. {
  262.   cp -p maphacks/3drealms/E?L*_polymost.mhk "${EXTRACTDIR}"
  263.   cp -p maphacks/dukedc/DUKEDC*-megaton.mhk "${EXTRACTDIR}"
  264.   rm -f "${EXTRACTDIR}"/*_13d_*.mhk
  265.   # bashism:
  266.   for i in "${EXTRACTDIR}"/*_polymost.mhk ; do mv "$i" "${i/_polymost}" ; done
  267.   for i in "${EXTRACTDIR}"/*-megaton.mhk  ; do mv "$i" "${i/-megaton}"  ; done
  268. } # copy_polymost_mhk()
  269.  
  270.  
  271. # I really don't know yet if this will become necessary, or if it does make
  272. # sense at all, but at least the files involved are listed.
  273. dukeplus_polymost_hrp_compatibility()
  274. {
  275.   # dukeplus.def expects some files to be present in the HRP
  276.   #
  277.   # model "highres/sprites/characters/1405_duke.md3" { // all OK, no action required
  278.   #    skin { pal 0 surface 0 file "highres/sprites/pickups/0057_jetpack.png" }
  279.   #    skin { pal 0 surface 1 file "highres/sprites/characters/1405_duke.png" }
  280.   #    skin { pal 10 surface 1 file "highres/sprites/characters/1405_duke_10.png" }
  281.   #    skin { pal 11 surface 1 file "highres/sprites/characters/1405_duke_11.png" }
  282.   #    skin { pal 12 surface 1 file "highres/sprites/characters/1405_duke_12.png" }
  283.   #    skin { pal 13 surface 1 file "highres/sprites/characters/1405_duke_13.png" }
  284.   #    skin { pal 14 surface 1 file "highres/sprites/characters/1405_duke_14.png" }
  285.   #    skin { pal 15 surface 1 file "highres/sprites/characters/1405_duke_15.png" }
  286.   #    skin { pal 16 surface 1 file "highres/sprites/characters/1405_duke_16.png" }
  287.   #    skin { pal 21 surface 1 file "highres/sprites/characters/1405_duke_21.png" }
  288.   #    skin { pal 23 surface 1 file "highres/sprites/characters/1405_duke_23.png" }
  289.   #    skin { pal 0 surface 2 file "highres/sprites/pickups/0023_rpg.png" }
  290.   #
  291.   # model "highres/sprites/firstperson/2510_devastator.md3" { // since Imperium, not Eternity
  292.   #    skin { pal 0 file "highres/sprites/firstperson/2510_devastator.png" specfactor 0.5 specpower 35 }
  293.   #    specular { file "highres/sprites/firstperson/2510_devastator_s.png" }
  294.   #    glow { file "highres/sprites/firstperson/2510_devastator_g.png" }
  295.   #
  296.   # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295    
  297.   #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
  298.   #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
  299.   # model "highres/sprites/firstperson/2530_clip.md3" {                  // most/mer : diff MD3, same skin
  300.   #    skin { pal 0 file "highres/sprites/pickups/0040_pistolammo.jpg" }
  301.   # model "highres/sprites/firstperson/2532_cliphand.md3" {  // most/mer : same MD3 + same skin til r295
  302.   #    skin { pal 0 file "highres/sprites/firstperson/2532_cliphand.png" } // til r295, then duke_hand_*
  303.   #
  304.  
  305.   SPR="highres/sprites"
  306.   SPRE="${EXTRACTDIR}/highres/sprites"
  307.   PATCHTYPE=$1
  308.  
  309.   case "$PATCHTYPE" in
  310.     polymer)
  311.       echo "  # (Using \"Polymer approach\")"
  312.       cp -pi $SPR/firstperson/2510_devastator.md3            "$SPRE/firstperson/"
  313.       cp -pi $SPR/firstperson/2510_devastator.png            "$SPRE/firstperson/"
  314.       cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson/"
  315.       cp -pi $SPR/firstperson/2510_devastator_g.png          "$SPRE/firstperson/"
  316.       cp -pi $SPR/firstperson/2524_pistol.md3                "$SPRE/firstperson/"
  317.       cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
  318.       cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
  319.       cp -pi $SPR/firstperson/2530_clip.md3                  "$SPRE/firstperson/"
  320.       cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups/"
  321.       cp -pi $SPR/firstperson/2532_cliphand.md3              "$SPRE/firstperson/"
  322.       cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson/"
  323.       cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson/"
  324.       cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson/"
  325.       cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson/"
  326.       ;;
  327.     polymost)
  328.       echo "  # (Using \"Polymost approach\")"
  329.       #cp -pi $SPR/firstperson_polymost/2510_devastator.md3   "$SPRE/firstperson/"
  330.       #cp -pi $SPR/firstperson_polymost/2510_devastator.png   "$SPRE/firstperson/"
  331.       ##cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson/"
  332.       #cp -pi $SPR/firstperson_polymost/2510_devastator_g.png "$SPRE/firstperson/"
  333.       cp -pi $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
  334.       #cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
  335.       #cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
  336.       #cp -pi $SPR/firstperson_polymost/2530_clip.md3         "$SPRE/firstperson/"
  337.       #cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups/"
  338.       #cp -pi $SPR/firstperson_polymost/2532_cliphand.md3     "$SPRE/firstperson/"
  339.       #cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson/"
  340.       #cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson/"
  341.       #cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson/"
  342.       #cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson/"
  343.       ;;
  344.     mixed)
  345.       echo "  # (Using \"Mixed approach\")"
  346.       echo "    # Not applied / Not yet implemented"
  347.       ;;
  348.     none)
  349.       echo "  Not applied"
  350.       #echo "  # Not yet implemented"
  351.       ;;
  352.     *)
  353.       echo "  # Bad parameter"
  354.       ;;
  355.   esac
  356.  
  357. } # dukeplus_polymost_hrp_compatibility()
  358.  
  359.  
  360. attrition_polymost_hrp_compatibility()
  361. {
  362.   # attr_hrp.def expects some files to be present in the HRP
  363.   #
  364.   # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295    
  365.   #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
  366.   #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
  367.  
  368.   SPR="highres/sprites"
  369.   SPRE="${EXTRACTDIR}/highres/sprites"
  370.   PATCHTYPE=$1
  371.  
  372.   case "$PATCHTYPE" in
  373.     polymer)
  374.       echo "  # (Using \"Polymer approach\")"
  375.       ;;
  376.     polymost)
  377.       echo "  # (Using \"Polymost approach\")"
  378.       cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson/"
  379.       cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson/"
  380.       cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson/"
  381.       cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
  382.       #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
  383.       ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
  384.       #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
  385.       ;;
  386.     mixed)
  387.       echo "  # (Using \"Mixed approach\")"
  388.       cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
  389.       cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
  390.       cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
  391.       cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
  392.       #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
  393.       ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
  394.       #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
  395.       cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson/"
  396.       cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
  397.       cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson/"
  398.       cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson/"
  399.       cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/"
  400.       cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson/"
  401.       cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson/"
  402.       cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson/"
  403.       cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
  404.       ;;
  405.     none)
  406.       echo "  Not applied"
  407.       #echo "  # Not yet implemented"
  408.       ;;
  409.     *)
  410.       echo "  # Bad parameter"
  411.       ;;
  412.   esac
  413.  
  414. } # attrition_polymost_hrp_compatibility()
  415.  
  416.  
  417. parse_defs()
  418. {
  419.   echo "$1"
  420.   BLOCK_COMMENT="OFF"
  421.   cat $1 | while read DEF_LINE; do
  422.  
  423.     #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
  424.     #DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
  425. #    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\/\\\/.*// | sed s/\\\r//`
  426.     DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
  427.     if [ "${DEF_FILE}" != "" ] ; then
  428.       cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
  429.       parse_defs "${DEF_FILE}"
  430.     fi
  431.  
  432.     #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
  433.     ## Old style added (except "defineskybox"):
  434.     HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
  435.     #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
  436.  
  437.     if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  438.  
  439.       COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
  440.       if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
  441.  
  442.       if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
  443.  
  444.       if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
  445.  
  446.       if [ ! "$HRP_TERM" = "" ] ; then
  447.         HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
  448.         if [ ! "$HRP_COMMENT" = "" ] ; then
  449.           HRP_TERM=""
  450.         fi
  451.       fi
  452.  
  453.     fi
  454.  
  455.     case "$HRP_TERM" in
  456.       file|mhkfile)
  457.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
  458.         # Mastering the backslash :-) ... hm, no big performance gain ... :
  459.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  460.         # Ignore comments WIP:
  461.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
  462.         ;;
  463.       model|voxel)
  464.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  465.         ;;
  466.       front|right|back|left|top|bottom|down)
  467.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
  468.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  469.         ;;
  470.       ## Old Style
  471.       definemodel)
  472.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  473.         ;;
  474.       definemodelskin)
  475.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  476.         ;;
  477.       definetexture)
  478.         # Won't work atm if filename in quotes (too lazy)
  479.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
  480.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
  481.         #echo "DEF_LINE : ${DEF_LINE}"
  482.         #echo "HRP_FILE : ${HRP_FILE}"
  483.         ;;
  484.       *)
  485.         HRP_FILE=""
  486.         ;;
  487.     esac
  488.  
  489.     if [  !   "${HRP_FILE}" = "" ] ; then
  490.       if [ -f "${HRP_FILE}" ] ; then
  491.         cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
  492.       else
  493.         echo  "WARNING : ${HRP_FILE} is missing!"
  494.       fi
  495.     fi
  496.  
  497.   done
  498. } # parse_defs()
  499.  
  500.  
  501. delete_empty_folders()
  502. {
  503.     if [ -d "${EXTRACTDIR}" ] ; then
  504.       rm -rf ${EXTRACTDIR}/.svn
  505.       DIRLIST=./EXTRACT_DIRECTORIES.lst
  506.       du "${EXTRACTDIR}" > ${DIRLIST}
  507.       cat ${DIRLIST} | while read DIR ; do
  508.         if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
  509.           EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
  510.           if [ -d ${EMPTYDIR} ] ; then
  511.             rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
  512.           fi
  513.         fi
  514.       done
  515.       rm ${DIRLIST}
  516.     else
  517.       echo "No ${EXTRACTDIR}."
  518.     fi
  519. } # delete_empty_folders()
  520.  
  521.  
  522. main()
  523. {
  524.   EXTRACTDIR=../hrp_${HRPTYPE}_extract
  525.   echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
  526.  
  527.   if [ $FORCE = 0 ] ; then
  528.     if ask "Proceed?"
  529.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  530.       else exit 0
  531.     fi
  532.   fi
  533.  
  534.   date +%F" "%H:%M:%S
  535.  
  536.   echo "### Deleting ${EXTRACTDIR} ... ###"
  537.   rm -rf ${EXTRACTDIR}
  538.  
  539.   echo "### Copying directory tree ... ###"
  540.   copy_folders
  541.  
  542.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
  543.     [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ] ; then
  544.  
  545.     echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
  546.     dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
  547.  
  548.     echo "### Attrition<>Polymost HRP compatibility patch ... ###"
  549.     attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
  550.   fi
  551.  
  552.  
  553.   if [ "${HRPTYPE}" = "polymost" ]||[ "${HRPTYPE}" = "polymost_override" ]; then
  554.     # Some people prefer unusual setups ...
  555.     zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip \
  556.     maphacks/3drealms/*.mhk
  557.   fi
  558.  
  559.   if [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ]; then
  560.     echo "### Copying maphacks for Megaton ... ###"
  561.     copy_polymost_mhk
  562.   fi
  563.  
  564.   echo "### Parsing DEF file hierarchy ... ###"
  565.   if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  566.     echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
  567.   else
  568.     echo "  # Extract commented textures and models: NO"
  569.   fi
  570.   if [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "full" ] ; then
  571.     parse_defs duke3d_hrp_megaton.def
  572.   fi
  573.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
  574.     parse_defs duke3d_hrp_polymost.def
  575.   fi
  576.   if [ "${HRPTYPE}" = "polymer" ]  || [ "${HRPTYPE}" = "full" ] ; then
  577.     parse_defs duke3d_hrp.def
  578.   fi
  579.   if [ "${HRPTYPE}" = "voxel" ] ; then
  580.     parse_defs duke3d_voxel.def
  581.   fi
  582.   if [ "${HRPTYPE}" = "sw_highres" ] ; then
  583.     parse_defs highres/sw_hrp.def
  584.   fi
  585.   if [ "${HRPTYPE}" = "sw_lowres" ] ; then
  586.     parse_defs lowres/sw_lrp.def
  587.   fi
  588.   if [ "${HRPTYPE}" = "maphacks" ] ; then
  589.     parse_defs maphacks/mhk-extract.def
  590.   fi
  591.   if [ "${HRPTYPE}" = "default" ] ; then
  592.     parse_defs "${DEF_TOP}"
  593.   fi
  594.  
  595.   echo "### Copying 'known' files ... ###"
  596.   copy_known_files
  597.  
  598.   echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
  599.   delete_empty_folders
  600.  
  601.   date +%F" "%H:%M:%S
  602.  
  603.   echo "Command line example for creating a ZIP package:"
  604.   echo "sh -c \"cd ${EXTRACTDIR}; zip -9rqn .jpg:.png:.zip ${EXTRACTDIR}.zip\
  605.  highpal highres maphacks *.def *.txt\""
  606. } # main()
  607.  
  608.  
  609.  
  610. PRGPATH=$0
  611. HRPTYPE=$1
  612. if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
  613. if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
  614.   VERSION="$3"
  615.   echo "${VERSION}" > VERSION
  616. fi
  617. HRPROOT=.
  618. WORKDIR=`pwd`
  619.  
  620. cd               "${HRPROOT}"
  621. echo  "PWD     :  ${WORKDIR}"
  622. echo  "HRPROOT :  ${HRPROOT}"
  623.  
  624. case "$HRPTYPE" in
  625.   polymer|polymost_override|polymost|megaton_override|megaton|maphacks)
  626.     main $HRPTYPE
  627.     ;;
  628.   full)
  629.     if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Packs)?"
  630.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  631.       else exit 0
  632.     fi ; fi
  633.     ${PRGPATH} polymost_override y
  634.     ${PRGPATH} megaton_override  y
  635.     main $HRPTYPE
  636.     ;;
  637.   both)
  638.     if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
  639.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  640.       else exit 0
  641.     fi ; fi
  642.     ${PRGPATH} polymer  y
  643.     ${PRGPATH} polymost y
  644.     ;;
  645.   ovr)
  646.     ${PRGPATH} polymost_override y
  647.     ${PRGPATH} megaton_override  y
  648.     ;;
  649.   all)
  650.     if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
  651.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  652.       else exit 0
  653.     fi ; fi
  654.     ${PRGPATH} both     y
  655.     ${PRGPATH} megaton  y
  656.     ${PRGPATH} maphacks y
  657.     ${PRGPATH} full     y
  658.     ;;
  659.   voxel)
  660.     SET_VERSION=NO
  661.     main $HRPTYPE
  662.     ;;
  663.   sw_highres|sw_lowres)
  664.     SET_VERSION=NO
  665.     main $HRPTYPE
  666.     ;;
  667.   sw_both)
  668.     if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
  669.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  670.       else exit 0
  671.     fi ; fi
  672.     ${PRGPATH} sw_lowres  y
  673.     ${PRGPATH} sw_highres y
  674.     ;;
  675.   unused)
  676.     echo "Option \"$1\" not yet implemented."
  677.     ;;
  678.   debug)
  679.     echo "Nothing to debug."
  680.     ;;
  681.   *)
  682.     if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
  683.       DEF_TOP="${HRPTYPE}"
  684.       HRPTYPE=default
  685.       SET_VERSION=NO
  686.       EXTRACT_COMMENTED_FILES=NO
  687.       main $HRPTYPE
  688.     else
  689.       echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
  690.       echo "HRPTYPEs: {full|ovr|all}"
  691.       echo "HRPTYPEs: {polymer|polymost_override|polymost|both}"
  692.       echo "HRPTYPEs: {megaton_override|megaton}"
  693.       echo "HRPTYPEs: {maphacks}"
  694.       echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
  695.       exit 1
  696.     fi
  697.     ;;
  698. esac
  699.  
  700. exit 0
  701.