Subversion Repositories duke3d_hrp

Rev

Rev 431 | 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 "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.     if [ "${DEF_FILE}" != "" ] ; then
  473.       cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
  474.       parse_defs "${DEF_FILE}"
  475.     fi
  476.  
  477.     #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
  478.     ## Old style added (except "defineskybox"):
  479.     HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
  480.     #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
  481.  
  482.     if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  483.  
  484.       COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
  485.       if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
  486.  
  487.       if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
  488.  
  489.       if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
  490.  
  491.       if [ ! "$HRP_TERM" = "" ] ; then
  492.         HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
  493.         if [ ! "$HRP_COMMENT" = "" ] ; then
  494.           HRP_TERM=""
  495.         fi
  496.       fi
  497.  
  498.     fi
  499.  
  500.     case "$HRP_TERM" in
  501.       file|mhkfile)
  502.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
  503.         # Mastering the backslash :-) ... hm, no big performance gain ... :
  504.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  505.         # Ignore comments WIP:
  506.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
  507.         ;;
  508.       model|voxel)
  509.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  510.         ;;
  511.       front|right|back|left|top|bottom|down)
  512.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
  513.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  514.         ;;
  515.       ## Old Style
  516.       definemodel)
  517.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  518.         ;;
  519.       definemodelskin)
  520.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
  521.         ;;
  522.       definetexture)
  523.         # Won't work atm if filename in quotes (too lazy)
  524.         #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
  525.         HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
  526.         #echo "DEF_LINE : ${DEF_LINE}"
  527.         #echo "HRP_FILE : ${HRP_FILE}"
  528.         ;;
  529.       *)
  530.         HRP_FILE=""
  531.         ;;
  532.     esac
  533.  
  534.     if [  !   "${HRP_FILE}" = "" ] ; then
  535.       if [ -f "${HRP_FILE}" ] ; then
  536.         cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
  537.       else
  538.         echo  "WARNING : ${HRP_FILE} is missing!"
  539.       fi
  540.     fi
  541.  
  542.   done
  543. } # parse_defs()
  544.  
  545.  
  546. delete_empty_folders()
  547. {
  548.     if [ -d "${EXTRACTDIR}" ] ; then
  549.       rm -rf ${EXTRACTDIR}/.svn
  550.       DIRLIST=./EXTRACT_DIRECTORIES.lst
  551.       du "${EXTRACTDIR}" > ${DIRLIST}
  552.       cat ${DIRLIST} | while read DIR ; do
  553.         if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
  554.           EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
  555.           if [ -d ${EMPTYDIR} ] ; then
  556.             rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
  557.           fi
  558.         fi
  559.       done
  560.       rm ${DIRLIST}
  561.     else
  562.       echo "No ${EXTRACTDIR}."
  563.     fi
  564. } # delete_empty_folders()
  565.  
  566.  
  567. main()
  568. {
  569.   EXTRACTDIR=../hrp_${HRPTYPE}_extract
  570.   echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
  571.  
  572.   if [ $FORCE = 0 ] ; then
  573.     if ask "Proceed?"
  574.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  575.       else exit 0
  576.     fi
  577.   fi
  578.  
  579.   date +%F" "%H:%M:%S
  580.  
  581.   echo "### Deleting ${EXTRACTDIR} ... ###"
  582.   rm -rf ${EXTRACTDIR}
  583.  
  584.   echo "### Copying directory tree ... ###"
  585.   copy_folders
  586.  
  587.   echo "### Copying 'known' files ... ###"
  588.   copy_known_files
  589.  
  590.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ; then
  591.     echo "### Creating Polymost maphacks ... ###"
  592.     create_polymost_mhk
  593.  
  594.     echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
  595.     dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
  596.  
  597.     echo "### Attrition<>Polymost HRP compatibility patch ... ###"
  598.     attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
  599.   fi
  600.  
  601.   echo "### Parsing DEF file hierarchy ... ###"
  602.   if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
  603.     echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
  604.   else
  605.     echo "  # Extract commented textures and models: NO"
  606.   fi
  607.   if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
  608.     parse_defs duke3d_hrp_polymost.def
  609.   fi
  610.   if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
  611.     parse_defs duke3d_hrp.def
  612.   fi
  613.   if [ "${HRPTYPE}" = "voxel" ] ; then
  614.     parse_defs duke3d_voxel.def
  615.   fi
  616.   if [ "${HRPTYPE}" = "sw_highres" ] ; then
  617.     parse_defs highres/sw_hrp.def
  618.   fi
  619.   if [ "${HRPTYPE}" = "sw_lowres" ] ; then
  620.     parse_defs lowres/sw_lrp.def
  621.   fi
  622.   if [ "${HRPTYPE}" = "default" ] ; then
  623.     parse_defs "${DEF_TOP}"
  624.   fi
  625.  
  626.   echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
  627.   delete_empty_folders
  628.  
  629.   date +%F" "%H:%M:%S
  630.  
  631.   echo "Command line example for creating a ZIP package:"
  632.   echo "sh -c \"cd ${EXTRACTDIR} ; zip -rqn .zip:.jpg:.png ${EXTRACTDIR}.zip *\""
  633. } # main()
  634.  
  635.  
  636.  
  637. PRGPATH=$0
  638. HRPTYPE=$1
  639. if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
  640. if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
  641.   VERSION="$3"
  642.   echo "${VERSION}" > VERSION
  643. fi
  644. HRPROOT=.
  645. WORKDIR=`pwd`
  646.  
  647. cd               "${HRPROOT}"
  648. echo  "PWD     :  ${WORKDIR}"
  649. echo  "HRPROOT :  ${HRPROOT}"
  650.  
  651. case "$HRPTYPE" in
  652.   polymer|polymost_override|polymost)
  653.     main $HRPTYPE
  654.     ;;
  655.   full)
  656.     if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Pack)?"
  657.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  658.       else exit 0
  659.     fi ; fi
  660.     ${PRGPATH} polymost_override y
  661.     main $HRPTYPE
  662.     ;;
  663.   both)
  664.     if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
  665.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  666.       else exit 0
  667.     fi ; fi
  668.     ${PRGPATH} polymer  y
  669.     ${PRGPATH} polymost y
  670.     ;;
  671.   all)
  672.     if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
  673.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  674.       else exit 0
  675.     fi ; fi
  676.     ${PRGPATH} both y
  677.     ${PRGPATH} full y
  678.     ;;
  679.   voxel)
  680.     SET_VERSION=NO
  681.     main $HRPTYPE
  682.     ;;
  683.   sw_highres|sw_lowres)
  684.     SET_VERSION=NO
  685.     main $HRPTYPE
  686.     ;;
  687.   sw_both)
  688.     if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
  689.       then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
  690.       else exit 0
  691.     fi ; fi
  692.     ${PRGPATH} sw_lowres  y
  693.     ${PRGPATH} sw_highres y
  694.     ;;
  695.   unused)
  696.     echo "Option \"$1\" not yet implemented."
  697.     ;;
  698.   debug)
  699.     echo "Nothing to debug."
  700.     ;;
  701.   *)
  702.     if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
  703.       DEF_TOP="${HRPTYPE}"
  704.       HRPTYPE=default
  705.       SET_VERSION=NO
  706.       EXTRACT_COMMENTED_FILES=NO
  707.       main $HRPTYPE
  708.     else
  709.       echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
  710.       echo "HRPTYPEs: {full|polymer|polymost_override|polymost|both|all}"
  711.       echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
  712.       exit 1
  713.     fi
  714.     ;;
  715. esac
  716.  
  717. exit 0
  718.