Subversion Repositories duke3d_hrp

Rev

Rev 491 | Rev 639 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
320 leod 1
#!/bin/sh
2
 
506 leod 3
# Duke Nukem 3D High Resolution Pack Extractor  v0.5.2  2013-06-08
320 leod 4
#
5
# Author: LeoD
6
# License: ISC license : http://opensource.org/licenses/isc-license.txt
7
#
408 leod 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.
333 leod 12
# On Windows you might want MSYS' zip to create package files.
320 leod 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.
333 leod 17
# Or maybe MSYS' bash gets finally updated to 4.* and I'll use its regex engine.
320 leod 18
 
331 leod 19
DEF_TOP=UNDEFINED
20
SET_VERSION=YES            # [YES|NO]
324 leod 21
EXTRACT_COMMENTED_FILES=NO # [YES|NO]
431 leod 22
DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH=polymost  #[none|polymost|polymer|mixed]
23
ATTRITION_POLYMOST_COMPATIBILTY_APPROACH=polymost #[none|polymost|polymer|mixed]
324 leod 24
 
320 leod 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
 
324 leod 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)
325 leod 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
324 leod 84
      ;;
431 leod 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}"
324 leod 90
      ;;
91
    *)
92
      echo "###ERROR: copy_set_version() - BAD FILE: ${VER_FILE}"
93
      exit 1
94
      ;;
95
  esac
96
}
97
 
330 leod 98
tar_copy_dir()
99
{
100
  (cd ${1}; tar cf - . ) | (cd ${2}; tar xf -)
101
}
102
 
320 leod 103
copy_known_files()
104
{
324 leod 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
320 leod 110
 
431 leod 111
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
384 leod 112
     [ "${HRPTYPE}" = "polymer"  ] || [ "${HRPTYPE}" = "full" ] ; then
113
    cp -pv hrp_art_license.txt      "${EXTRACTDIR}"
114
  fi
115
 
431 leod 116
  if [ "${HRPTYPE}" = "polymost" ] ; then
324 leod 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
320 leod 122
  fi
123
 
431 leod 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
 
320 leod 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
324 leod 142
    if [ "${SET_VERSION}" = "YES" ] ; then
431 leod 143
      copy_set_version duke3d_hrp_polymost.def \
144
        "${EXTRACTDIR}/duke3d_hrp_polymost.def"
324 leod 145
    else
146
      cp -pv           duke3d_hrp_polymost.def "${EXTRACTDIR}"
147
    fi
320 leod 148
  fi
149
 
431 leod 150
  if [ "${HRPTYPE}" = "full" ] ; then
151
    cp -pv highres/screen/menu/2492_ver_polymost.png \
152
      "${EXTRACTDIR}/highres/screen/menu"
320 leod 153
  fi
154
 
431 leod 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
 
320 leod 162
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
163
    cp -pv duke3d.def                   "${EXTRACTDIR}"
324 leod 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
320 leod 169
    echo                  "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
170
    cp -p  *.mhk                        "${EXTRACTDIR}"
171
    #cp -pv highres/screen/menu/2492.png "${EXTRACTDIR}/highres/screen/menu"
172
 
324 leod 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"
408 leod 180
    #cp -pv highres/sprites/signs/4378-79.png                 "${EXTRACTDIR}/highres/sprites/signs"
324 leod 181
    #cp -pv highres/sprites/signs/4381-85.png                 "${EXTRACTDIR}/highres/sprites/signs"
320 leod 182
  fi
183
 
330 leod 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}"
333 leod 195
    cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres"
330 leod 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
384 leod 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}"
330 leod 211
    echo "Copying skyboxes ..."
384 leod 212
    tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
330 leod 213
    cd "${WORKDIR}"
214
  fi
215
 
331 leod 216
  if [ "${HRPTYPE}" = "default" ] ; then
217
    cp -pv  "${DEF_TOP}"          "${EXTRACTDIR}/${DEF_TOP}"
408 leod 218
    echo            "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
219
    cp -p  *.mhk                  "${EXTRACTDIR}"
331 leod 220
    echo            "\`*.txt' -> \`${EXTRACTDIR}/*.txt'"
221
    cp -p  *.txt                  "${EXTRACTDIR}"
222
  fi
223
 
320 leod 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}"
491 leod 235
      MHK_INSERT=`echo "${MHK_LINE}" | grep -oE "Fixes\ for\ badly\ aligned\ sprites"`
320 leod 236
      if [ ! "${MHK_INSERT}" = "" ] ; then
491 leod 237
        echo "sprite   591 mdxoff     425000     // tile0603 naked1 hangbabe (Polymost HRP)\r" \
320 leod 238
             >> "${EXTRACTDIR}/${MHKFILE}"
491 leod 239
        echo "sprite   591 pitch      1          // tile0603 naked1 hangbabe (Polymost HRP)\r" \
320 leod 240
             >> "${EXTRACTDIR}/${MHKFILE}"
491 leod 241
        echo "sprite   592 mdxoff     425000     // tile0603 naked1 hangbabe (Polymost HRP)\r" \
320 leod 242
             >> "${EXTRACTDIR}/${MHKFILE}"
491 leod 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}"
320 leod 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" \
324 leod 260
                                      >> "${EXTRACTDIR}/${MHKFILE}"
320 leod 261
          echo "sprite 105 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
262
          echo "sprite 447 mdxoff 462000 // underwater slime babe (Polymost HRP)\r" \
324 leod 263
                                      >> "${EXTRACTDIR}/${MHKFILE}"
320 leod 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"`
324 leod 272
      if   [ ! "${MHK_REPLACE1}" = "" ] ; then
320 leod 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" \
324 leod 276
             >> "${EXTRACTDIR}/${MHKFILE}"
320 leod 277
      elif [ ! "${MHK_REPLACE3}" = "" ] ; then
278
        echo "sprite 307 mdzoff 625000 // flipped hanging babe (Polymost HRP)\r" \
324 leod 279
             >> "${EXTRACTDIR}/${MHKFILE}"
320 leod 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
431 leod 312
  # Some people prefer unusual setups ... polymost_mhk_patch not applied automatically
313
  zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip *.mhk
320 leod 314
} # create_polymost_mhk()
315
 
316
 
412 leod 317
# I really don't know yet if this will become necessary, or if it does make
324 leod 318
# sense at all, but at least the files involved are listed.
412 leod 319
dukeplus_polymost_hrp_compatibility()
320 leod 320
{
324 leod 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
  #
320 leod 350
 
324 leod 351
  SPR="highres/sprites"
352
  SPRE="${EXTRACTDIR}/highres/sprites"
353
  PATCHTYPE=$1
320 leod 354
 
324 leod 355
  case "$PATCHTYPE" in
356
    polymer)
412 leod 357
      echo "  # (Using \"Polymer approach\")"
324 leod 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)
412 leod 374
      echo "  # (Using \"Polymost approach\")"
407 leod 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"
324 leod 379
      cp -pi $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson"
407 leod 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"
324 leod 389
      ;;
390
    mixed)
412 leod 391
      echo "  # (Using \"Mixed approach\")"
324 leod 392
      echo "    # Not applied / Not yet implemented"
393
      ;;
394
    none)
407 leod 395
      echo "  Not applied"
396
      #echo "  # Not yet implemented"
324 leod 397
      ;;
398
    *)
399
      echo "  # Bad parameter"
400
      ;;
401
  esac
402
 
412 leod 403
} # dukeplus_polymost_hrp_compatibility()
324 leod 404
 
405
 
412 leod 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
 
320 leod 463
parse_defs()
464
{
465
  echo "$1"
324 leod 466
  BLOCK_COMMENT="OFF"
320 leod 467
  cat $1 | while read DEF_LINE; do
468
 
469
    #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
415 leod 470
    #DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
506 leod 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//'`
320 leod 473
    if [ "${DEF_FILE}" != "" ] ; then
474
      cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
475
      parse_defs "${DEF_FILE}"
476
    fi
477
 
375 leod 478
    #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
479
    ## Old style added (except "defineskybox"):
415 leod 480
    HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
333 leod 481
    #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
320 leod 482
 
324 leod 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
 
320 leod 501
    case "$HRP_TERM" in
415 leod 502
      file|mhkfile)
320 leod 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
        ;;
331 leod 509
      model|voxel)
510
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
320 leod 511
        ;;
333 leod 512
      front|right|back|left|top|bottom|down)
320 leod 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
        ;;
375 leod 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
        ;;
320 leod 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
431 leod 557
            rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
320 leod 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
 
408 leod 595
    echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
412 leod 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
320 leod 600
  fi
601
 
602
  echo "### Parsing DEF file hierarchy ... ###"
324 leod 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
320 leod 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
330 leod 614
  if [ "${HRPTYPE}" = "voxel" ] ; then
615
    parse_defs duke3d_voxel.def
616
  fi
617
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
333 leod 618
    parse_defs highres/sw_hrp.def
330 leod 619
  fi
620
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
333 leod 621
    parse_defs lowres/sw_lrp.def
330 leod 622
  fi
331 leod 623
  if [ "${HRPTYPE}" = "default" ] ; then
624
    parse_defs "${DEF_TOP}"
625
  fi
320 leod 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
325 leod 641
if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
642
  VERSION="$3"
643
  echo "${VERSION}" > VERSION
644
fi
320 leod 645
HRPROOT=.
330 leod 646
WORKDIR=`pwd`
320 leod 647
 
648
cd               "${HRPROOT}"
330 leod 649
echo  "PWD     :  ${WORKDIR}"
650
echo  "HRPROOT :  ${HRPROOT}"
320 leod 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
    ;;
330 leod 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
    ;;
320 leod 696
  unused)
697
    echo "Option \"$1\" not yet implemented."
698
    ;;
699
  debug)
700
    echo "Nothing to debug."
701
    ;;
702
  *)
408 leod 703
    if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
704
      DEF_TOP="${HRPTYPE}"
331 leod 705
      HRPTYPE=default
706
      SET_VERSION=NO
707
      EXTRACT_COMMENTED_FILES=NO
708
      main $HRPTYPE
709
    else
408 leod 710
      echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
331 leod 711
      echo "HRPTYPEs: {full|polymer|polymost_override|polymost|both|all}"
712
      echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
713
      exit 1
714
    fi
320 leod 715
    ;;
716
esac
717
 
718
exit 0