Subversion Repositories duke3d_hrp

Rev

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