Subversion Repositories duke3d_hrp

Rev

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