Subversion Repositories duke3d_hrp

Rev

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