Subversion Repositories duke3d_hrp

Rev

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

  1. #!/bin/sh
  2.  
  3. # Duke Nukem 3D High Resolution Pack Extractor  v0.5.2  2013-06-08
  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 "Fixes\ for\ badly\ aligned\ sprites"`
  236.       if [ ! "${MHK_INSERT}" = "" ] ; then
  237.         echo "sprite   591 mdxoff     425000     // tile0603 naked1 hangbabe (Polymost HRP)\r" \
  238.              >> "${EXTRACTDIR}/${MHKFILE}"
  239.         echo "sprite   591 pitch      1          // tile0603 naked1 hangbabe (Polymost HRP)\r" \
  240.              >> "${EXTRACTDIR}/${MHKFILE}"
  241.         echo "sprite   592 mdxoff     425000     // tile0603 naked1 hangbabe (Polymost HRP)\r" \
  242.              >> "${EXTRACTDIR}/${MHKFILE}"
  243.         echo "sprite   592 pitch      1          // tile0603 naked1 hangbabe (Polymost HRP)\r" \
  244.              >> "${EXTRACTDIR}/${MHKFILE}"
  245.         echo "sprite   593 mdxoff     425000     // tile0603 naked1 hangbabe (Polymost HRP)\r" \
  246.              >> "${EXTRACTDIR}/${MHKFILE}"
  247.         echo "sprite   593 pitch      1          // tile0603 naked1 hangbabe (Polymost HRP)\r" \
  248.              >> "${EXTRACTDIR}/${MHKFILE}"
  249.       fi
  250.       ;;
  251.     "E3L3.mhk")
  252.       MHK_REPLACE=`echo "${MHK_LINE}" | grep -oE "sprite\ 105\ angoff -128"`
  253.       if [ ! "${MHK_REPLACE}" = "" ] ; then
  254.         echo "sprite 105 angoff 768 // (Polymost HRP)\r" >> "${EXTRACTDIR}/${MHKFILE}"
  255.       else
  256.         echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
  257.         MHK_INSERT=`echo "${MHK_LINE}" | grep -oE "sprite\ 96\ pitch\ 1"`
  258.         if [ ! "${MHK_INSERT}" = "" ] ; then
  259.           echo "sprite 105 mdxoff 450000 // underwater slime babe (Polymost HRP)\r" \
  260.                                       >> "${EXTRACTDIR}/${MHKFILE}"
  261.           echo "sprite 105 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
  262.           echo "sprite 447 mdxoff 462000 // underwater slime babe (Polymost HRP)\r" \
  263.                                       >> "${EXTRACTDIR}/${MHKFILE}"
  264.           echo "sprite 447 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
  265.         fi
  266.       fi
  267.       ;;
  268.     "E3L6.mhk")
  269.       MHK_REPLACE1=`echo "${MHK_LINE}" | grep -oE "sprite\ 307\ angoff -210"`
  270.       MHK_REPLACE2=`echo "${MHK_LINE}" | grep -oE "sprite\ 307\ mdxoff -125000 \\/\\/\ flipped hanging babe"`
  271.       MHK_REPLACE3=`echo "${MHK_LINE}" | grep -oE "sprite\ 307\ mdzoff -11000"`
  272.       if   [ ! "${MHK_REPLACE1}" = "" ] ; then
  273.         echo "sprite 307 angoff 200 // (Polymost HRP)\r" >> "${EXTRACTDIR}/${MHKFILE}"
  274.       elif [ ! "${MHK_REPLACE2}" = "" ] ; then
  275.         echo "sprite 307 mdxoff 750000 // flipped hanging babe (Polymost HRP)\r" \
  276.              >> "${EXTRACTDIR}/${MHKFILE}"
  277.       elif [ ! "${MHK_REPLACE3}" = "" ] ; then
  278.         echo "sprite 307 mdzoff 625000 // flipped hanging babe (Polymost HRP)\r" \
  279.              >> "${EXTRACTDIR}/${MHKFILE}"
  280.       else
  281.         echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
  282.       fi
  283.       ;;
  284.     *)
  285.       echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
  286.       ;;
  287.   esac
  288. } # polymost_mhk_patch()
  289.  
  290.  
  291. create_polymost_mhk()
  292. {
  293.   for MHKFILE in *.mhk ; do
  294.     MHKSTOP="0"
  295.     cat   ${MHKFILE} | while read MHK_LINE; do
  296.       if [ "${MHKSTOP}" = "0" ] ; then
  297.  
  298.         if [ "${MHKFILE}" = "E3L1.mhk" ] || [ "${MHKFILE}" = "E3L3.mhk" ] || \
  299.            [ "${MHKFILE}" = "E3L6.mhk" ] ; then
  300.           polymost_mhk_patch ${MHKFILE} "${MHK_LINE}"
  301.         else
  302.           echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
  303.         fi
  304.  
  305.         MHK_TERM=`echo "${MHK_LINE}" | grep -owE "\\/\\/\\ LIGHTS"`
  306.         if [ "${MHK_TERM}" = "// LIGHTS" ] ; then
  307.           MHKSTOP="1"
  308.         fi
  309.       fi
  310.     done
  311.   done
  312.   # Some people prefer unusual setups ... polymost_mhk_patch not applied automatically
  313.   zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip *.mhk
  314. } # create_polymost_mhk()
  315.  
  316.  
  317. # I really don't know yet if this will become necessary, or if it does make
  318. # sense at all, but at least the files involved are listed.
  319. dukeplus_polymost_hrp_compatibility()
  320. {
  321.   # dukeplus.def expects some files to be present in the HRP
  322.   #
  323.   # model "highres/sprites/characters/1405_duke.md3" { // all OK, no action required
  324.   #    skin { pal 0 surface 0 file "highres/sprites/pickups/0057_jetpack.png" }
  325.   #    skin { pal 0 surface 1 file "highres/sprites/characters/1405_duke.png" }
  326.   #    skin { pal 10 surface 1 file "highres/sprites/characters/1405_duke_10.png" }
  327.   #    skin { pal 11 surface 1 file "highres/sprites/characters/1405_duke_11.png" }
  328.   #    skin { pal 12 surface 1 file "highres/sprites/characters/1405_duke_12.png" }
  329.   #    skin { pal 13 surface 1 file "highres/sprites/characters/1405_duke_13.png" }
  330.   #    skin { pal 14 surface 1 file "highres/sprites/characters/1405_duke_14.png" }
  331.   #    skin { pal 15 surface 1 file "highres/sprites/characters/1405_duke_15.png" }
  332.   #    skin { pal 16 surface 1 file "highres/sprites/characters/1405_duke_16.png" }
  333.   #    skin { pal 21 surface 1 file "highres/sprites/characters/1405_duke_21.png" }
  334.   #    skin { pal 23 surface 1 file "highres/sprites/characters/1405_duke_23.png" }
  335.   #    skin { pal 0 surface 2 file "highres/sprites/pickups/0023_rpg.png" }
  336.   #
  337.   # model "highres/sprites/firstperson/2510_devastator.md3" { // since Imperium, not Eternity
  338.   #    skin { pal 0 file "highres/sprites/firstperson/2510_devastator.png" specfactor 0.5 specpower 35 }
  339.   #    specular { file "highres/sprites/firstperson/2510_devastator_s.png" }
  340.   #    glow { file "highres/sprites/firstperson/2510_devastator_g.png" }
  341.   #
  342.   # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295    
  343.   #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
  344.   #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
  345.   # model "highres/sprites/firstperson/2530_clip.md3" {                  // most/mer : diff MD3, same skin
  346.   #    skin { pal 0 file "highres/sprites/pickups/0040_pistolammo.jpg" }
  347.   # model "highres/sprites/firstperson/2532_cliphand.md3" {  // most/mer : same MD3 + same skin til r295
  348.   #    skin { pal 0 file "highres/sprites/firstperson/2532_cliphand.png" } // til r295, then duke_hand_*
  349.   #
  350.  
  351.   SPR="highres/sprites"
  352.   SPRE="${EXTRACTDIR}/highres/sprites"
  353.   PATCHTYPE=$1
  354.  
  355.   case "$PATCHTYPE" in
  356.     polymer)
  357.       echo "  # (Using \"Polymer approach\")"
  358.       cp -pi $SPR/firstperson/2510_devastator.md3            "$SPRE/firstperson"
  359.       cp -pi $SPR/firstperson/2510_devastator.png            "$SPRE/firstperson"
  360.       cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson"
  361.       cp -pi $SPR/firstperson/2510_devastator_g.png          "$SPRE/firstperson"
  362.       cp -pi $SPR/firstperson/2524_pistol.md3                "$SPRE/firstperson"
  363.       cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
  364.       cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
  365.       cp -pi $SPR/firstperson/2530_clip.md3                  "$SPRE/firstperson"
  366.       cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups"
  367.       cp -pi $SPR/firstperson/2532_cliphand.md3              "$SPRE/firstperson"
  368.       cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson"
  369.       cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson"
  370.       cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson"
  371.       cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson"
  372.       ;;
  373.     polymost)
  374.       echo "  # (Using \"Polymost approach\")"
  375.       #cp -pi $SPR/firstperson_polymost/2510_devastator.md3   "$SPRE/firstperson"
  376.       #cp -pi $SPR/firstperson_polymost/2510_devastator.png   "$SPRE/firstperson"
  377.       ##cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson"
  378.       #cp -pi $SPR/firstperson_polymost/2510_devastator_g.png "$SPRE/firstperson"
  379.       cp -pi $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson"
  380.       #cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
  381.       #cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
  382.       #cp -pi $SPR/firstperson_polymost/2530_clip.md3         "$SPRE/firstperson"
  383.       #cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups"
  384.       #cp -pi $SPR/firstperson_polymost/2532_cliphand.md3     "$SPRE/firstperson"
  385.       #cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson"
  386.       #cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson"
  387.       #cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson"
  388.       #cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson"
  389.       ;;
  390.     mixed)
  391.       echo "  # (Using \"Mixed approach\")"
  392.       echo "    # Not applied / Not yet implemented"
  393.       ;;
  394.     none)
  395.       echo "  Not applied"
  396.       #echo "  # Not yet implemented"
  397.       ;;
  398.     *)
  399.       echo "  # Bad parameter"
  400.       ;;
  401.   esac
  402.  
  403. } # dukeplus_polymost_hrp_compatibility()
  404.  
  405.  
  406. attrition_polymost_hrp_compatibility()
  407. {
  408.   # attr_hrp.def expects some files to be present in the HRP
  409.   #
  410.   # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295    
  411.   #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
  412.   #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
  413.  
  414.   SPR="highres/sprites"
  415.   SPRE="${EXTRACTDIR}/highres/sprites"
  416.   PATCHTYPE=$1
  417.  
  418.   case "$PATCHTYPE" in
  419.     polymer)
  420.       echo "  # (Using \"Polymer approach\")"
  421.       ;;
  422.     polymost)
  423.       echo "  # (Using \"Polymost approach\")"
  424.       cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson"
  425.       cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson"
  426.       cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson"
  427.       cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson"
  428.       #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson"
  429.       ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson"
  430.       #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
  431.       ;;
  432.     mixed)
  433.       echo "  # (Using \"Mixed approach\")"
  434.       cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson"
  435.       cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
  436.       cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
  437.       cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson"
  438.       #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson"
  439.       ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson"
  440.       #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
  441.       cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson"
  442.       cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
  443.       cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson"
  444.       cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson"
  445.       cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson"
  446.       cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson"
  447.       cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson"
  448.       cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson"
  449.       cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
  450.       ;;
  451.     none)
  452.       echo "  Not applied"
  453.       #echo "  # Not yet implemented"
  454.       ;;
  455.     *)
  456.       echo "  # Bad parameter"
  457.       ;;
  458.   esac
  459.  
  460. } # attrition_polymost_hrp_compatibility()
  461.  
  462.  
  463. parse_defs()
  464. {
  465.   echo "$1"
  466.   BLOCK_COMMENT="OFF"
  467.   cat $1 | while read DEF_LINE; do
  468.  
  469.     #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
  470.     #DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
  471. #    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\/\\\/.*// | sed s/\\\r//`
  472.     DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
  473.     if [ "${DEF_FILE}" != "" ] ; then
  474.       cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
  475.       parse_defs "${DEF_FILE}"
  476.     fi
  477.  
  478.     #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
  479.     ## Old style added (except "defineskybox"):
  480.     HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
  481.     #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
  482.  
  483.     if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  484.  
  485.       COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
  486.       if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
  487.  
  488.       if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
  489.  
  490.       if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
  491.  
  492.       if [ ! "$HRP_TERM" = "" ] ; then
  493.         HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
  494.         if [ ! "$HRP_COMMENT" = "" ] ; then
  495.           HRP_TERM=""
  496.         fi
  497.       fi
  498.  
  499.     fi
  500.  
  501.     case "$HRP_TERM" in
  502.       file|mhkfile)
  503.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
  504.         # Mastering the backslash :-) ... hm, no big performance gain ... :
  505.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  506.         # Ignore comments WIP:
  507.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
  508.         ;;
  509.       model|voxel)
  510.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  511.         ;;
  512.       front|right|back|left|top|bottom|down)
  513.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
  514.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  515.         ;;
  516.       ## Old Style
  517.       definemodel)
  518.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  519.         ;;
  520.       definemodelskin)
  521.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  522.         ;;
  523.       definetexture)
  524.         # Won't work atm if filename in quotes (too lazy)
  525.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
  526.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
  527.         #echo "DEF_LINE : ${DEF_LINE}"
  528.         #echo "HRP_FILE : ${HRP_FILE}"
  529.         ;;
  530.       *)
  531.         HRP_FILE=""
  532.         ;;
  533.     esac
  534.  
  535.     if [  !   "${HRP_FILE}" = "" ] ; then
  536.       if [ -f "${HRP_FILE}" ] ; then
  537.         cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
  538.       else
  539.         echo  "WARNING : ${HRP_FILE} is missing!"
  540.       fi
  541.     fi
  542.  
  543.   done
  544. } # parse_defs()
  545.  
  546.  
  547. delete_empty_folders()
  548. {
  549.     if [ -d "${EXTRACTDIR}" ] ; then
  550.       rm -rf ${EXTRACTDIR}/.svn
  551.       DIRLIST=./EXTRACT_DIRECTORIES.lst
  552.       du "${EXTRACTDIR}" > ${DIRLIST}
  553.       cat ${DIRLIST} | while read DIR ; do
  554.         if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
  555.           EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
  556.           if [ -d ${EMPTYDIR} ] ; then
  557.             rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
  558.           fi
  559.         fi
  560.       done
  561.       rm ${DIRLIST}
  562.     else
  563.       echo "No ${EXTRACTDIR}."
  564.     fi
  565. } # delete_empty_folders()
  566.  
  567.  
  568. main()
  569. {
  570.   EXTRACTDIR=../hrp_${HRPTYPE}_extract
  571.   echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
  572.  
  573.   if [ $FORCE = 0 ] ; then
  574.     if ask "Proceed?"
  575.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  576.       else exit 0
  577.     fi
  578.   fi
  579.  
  580.   date +%F" "%H:%M:%S
  581.  
  582.   echo "### Deleting ${EXTRACTDIR} ... ###"
  583.   rm -rf ${EXTRACTDIR}
  584.  
  585.   echo "### Copying directory tree ... ###"
  586.   copy_folders
  587.  
  588.   echo "### Copying 'known' files ... ###"
  589.   copy_known_files
  590.  
  591.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ; then
  592.     echo "### Creating Polymost maphacks ... ###"
  593.     create_polymost_mhk
  594.  
  595.     echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
  596.     dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
  597.  
  598.     echo "### Attrition<>Polymost HRP compatibility patch ... ###"
  599.     attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
  600.   fi
  601.  
  602.   echo "### Parsing DEF file hierarchy ... ###"
  603.   if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  604.     echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
  605.   else
  606.     echo "  # Extract commented textures and models: NO"
  607.   fi
  608.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
  609.     parse_defs duke3d_hrp_polymost.def
  610.   fi
  611.   if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
  612.     parse_defs duke3d_hrp.def
  613.   fi
  614.   if [ "${HRPTYPE}" = "voxel" ] ; then
  615.     parse_defs duke3d_voxel.def
  616.   fi
  617.   if [ "${HRPTYPE}" = "sw_highres" ] ; then
  618.     parse_defs highres/sw_hrp.def
  619.   fi
  620.   if [ "${HRPTYPE}" = "sw_lowres" ] ; then
  621.     parse_defs lowres/sw_lrp.def
  622.   fi
  623.   if [ "${HRPTYPE}" = "default" ] ; then
  624.     parse_defs "${DEF_TOP}"
  625.   fi
  626.  
  627.   echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
  628.   delete_empty_folders
  629.  
  630.   date +%F" "%H:%M:%S
  631.  
  632.   echo "Command line example for creating a ZIP package:"
  633.   echo "sh -c \"cd ${EXTRACTDIR} ; zip -rqn .zip:.jpg:.png ${EXTRACTDIR}.zip *\""
  634. } # main()
  635.  
  636.  
  637.  
  638. PRGPATH=$0
  639. HRPTYPE=$1
  640. if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
  641. if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
  642.   VERSION="$3"
  643.   echo "${VERSION}" > VERSION
  644. fi
  645. HRPROOT=.
  646. WORKDIR=`pwd`
  647.  
  648. cd               "${HRPROOT}"
  649. echo  "PWD     :  ${WORKDIR}"
  650. echo  "HRPROOT :  ${HRPROOT}"
  651.  
  652. case "$HRPTYPE" in
  653.   polymer|polymost_override|polymost)
  654.     main $HRPTYPE
  655.     ;;
  656.   full)
  657.     if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Pack)?"
  658.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  659.       else exit 0
  660.     fi ; fi
  661.     ${PRGPATH} polymost_override y
  662.     main $HRPTYPE
  663.     ;;
  664.   both)
  665.     if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
  666.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  667.       else exit 0
  668.     fi ; fi
  669.     ${PRGPATH} polymer  y
  670.     ${PRGPATH} polymost y
  671.     ;;
  672.   all)
  673.     if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
  674.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  675.       else exit 0
  676.     fi ; fi
  677.     ${PRGPATH} both y
  678.     ${PRGPATH} full y
  679.     ;;
  680.   voxel)
  681.     SET_VERSION=NO
  682.     main $HRPTYPE
  683.     ;;
  684.   sw_highres|sw_lowres)
  685.     SET_VERSION=NO
  686.     main $HRPTYPE
  687.     ;;
  688.   sw_both)
  689.     if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
  690.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  691.       else exit 0
  692.     fi ; fi
  693.     ${PRGPATH} sw_lowres  y
  694.     ${PRGPATH} sw_highres y
  695.     ;;
  696.   unused)
  697.     echo "Option \"$1\" not yet implemented."
  698.     ;;
  699.   debug)
  700.     echo "Nothing to debug."
  701.     ;;
  702.   *)
  703.     if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
  704.       DEF_TOP="${HRPTYPE}"
  705.       HRPTYPE=default
  706.       SET_VERSION=NO
  707.       EXTRACT_COMMENTED_FILES=NO
  708.       main $HRPTYPE
  709.     else
  710.       echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
  711.       echo "HRPTYPEs: {full|polymer|polymost_override|polymost|both|all}"
  712.       echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
  713.       exit 1
  714.     fi
  715.     ;;
  716. esac
  717.  
  718. exit 0
  719.