Subversion Repositories duke3d_hrp

Rev

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

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