Subversion Repositories duke3d_hrp

Rev

Rev 333 | Rev 384 | 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
 
375 leod 392
    #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
393
    ## Old style added (except "defineskybox"):
394
    HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|model|voxel|front|right|back|left|top|bottom|down"`
333 leod 395
    #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
320 leod 396
 
324 leod 397
    if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
398
 
399
      COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
400
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
401
 
402
      if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
403
 
404
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
405
 
406
      if [ ! "$HRP_TERM" = "" ] ; then
407
        HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
408
        if [ ! "$HRP_COMMENT" = "" ] ; then
409
          HRP_TERM=""
410
        fi
411
      fi
412
 
413
    fi
414
 
320 leod 415
    case "$HRP_TERM" in
416
      file)
417
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
418
        # Mastering the backslash :-) ... hm, no big performance gain ... :
419
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
420
        # Ignore comments WIP:
421
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
422
        ;;
331 leod 423
      model|voxel)
424
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
320 leod 425
        ;;
333 leod 426
      front|right|back|left|top|bottom|down)
320 leod 427
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
428
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
429
        ;;
375 leod 430
      ## Old Style
431
      definemodel)
432
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
433
        ;;
434
      definemodelskin)
435
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
436
        ;;
437
      definetexture)
438
        # Won't work atm if filename in quotes (too lazy)
439
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
440
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
441
        #echo "DEF_LINE : ${DEF_LINE}"
442
        #echo "HRP_FILE : ${HRP_FILE}"
443
        ;;
320 leod 444
      *)
445
        HRP_FILE=""
446
        ;;
447
    esac
448
 
449
    if [  !   "${HRP_FILE}" = "" ] ; then
450
      if [ -f "${HRP_FILE}" ] ; then
451
        cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
452
      else
453
        echo  "WARNING : ${HRP_FILE} is missing!"
454
      fi
455
    fi
456
 
457
  done
458
} # parse_defs()
459
 
460
 
461
delete_empty_folders()
462
{
463
    if [ -d "${EXTRACTDIR}" ] ; then
464
      rm -rf ${EXTRACTDIR}/.svn
465
      rm -rf ${EXTRACTDIR}/installer
466
      DIRLIST=./EXTRACT_DIRECTORIES.lst
467
      du "${EXTRACTDIR}" > ${DIRLIST}
468
      cat ${DIRLIST} | while read DIR ; do
469
        if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
470
          EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
471
          if [ -d ${EMPTYDIR} ] ; then
472
            rmdir ${EMPTYDIR}
473
          fi
474
        fi
475
      done
476
      rm ${DIRLIST}
477
    else
478
      echo "No ${EXTRACTDIR}."
479
    fi
480
} # delete_empty_folders()
481
 
482
 
483
main()
484
{
485
  EXTRACTDIR=../hrp_${HRPTYPE}_extract
486
  echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
487
 
488
  if [ $FORCE = 0 ] ; then
489
    if ask "Proceed?"
490
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
491
      else exit 0
492
    fi
493
  fi
494
 
495
  date +%F" "%H:%M:%S
496
 
497
  echo "### Deleting ${EXTRACTDIR} ... ###"
498
  rm -rf ${EXTRACTDIR}
499
 
500
  echo "### Copying directory tree ... ###"
501
  copy_folders
502
 
503
  echo "### Copying 'known' files ... ###"
504
  copy_known_files
505
 
506
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ; then
507
    echo "### Creating Polymost maphacks ... ###"
508
    create_polymost_mhk
509
 
324 leod 510
    #echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
511
    #dukeplus_polymost_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
320 leod 512
  fi
513
 
514
  echo "### Parsing DEF file hierarchy ... ###"
324 leod 515
  if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
516
    echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
517
  else
518
    echo "  # Extract commented textures and models: NO"
519
  fi
320 leod 520
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
521
    parse_defs duke3d_hrp_polymost.def
522
  fi
523
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
524
    parse_defs duke3d_hrp.def
525
  fi
330 leod 526
  if [ "${HRPTYPE}" = "voxel" ] ; then
527
    parse_defs duke3d_voxel.def
528
  fi
529
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
333 leod 530
    parse_defs highres/sw_hrp.def
330 leod 531
  fi
532
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
333 leod 533
    parse_defs lowres/sw_lrp.def
330 leod 534
  fi
331 leod 535
  if [ "${HRPTYPE}" = "default" ] ; then
536
    parse_defs "${DEF_TOP}"
537
  fi
320 leod 538
 
539
  echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
540
  delete_empty_folders
541
 
542
  date +%F" "%H:%M:%S
543
 
544
  echo "Command line example for creating a ZIP package:"
545
  echo "sh -c \"cd ${EXTRACTDIR} ; zip -rqn .zip:.jpg:.png ${EXTRACTDIR}.zip *\""
546
} # main()
547
 
548
 
549
 
550
PRGPATH=$0
551
HRPTYPE=$1
552
if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
325 leod 553
if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
554
  VERSION="$3"
555
  echo "${VERSION}" > VERSION
556
fi
320 leod 557
HRPROOT=.
330 leod 558
WORKDIR=`pwd`
320 leod 559
 
560
cd               "${HRPROOT}"
330 leod 561
echo  "PWD     :  ${WORKDIR}"
562
echo  "HRPROOT :  ${HRPROOT}"
320 leod 563
 
333 leod 564
#if [ ! -f "./duke3d.def" ] && [ ! "${HRPTYPE}" = "default" ] ; then
565
#  echo "ERROR : ./duke3d.def not found. This is no HRP root directory. Exit."
566
#  exit 1
567
#fi
320 leod 568
 
569
case "$HRPTYPE" in
570
  polymer|polymost_override|polymost)
571
    main $HRPTYPE
572
    ;;
573
  full)
574
    if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Pack)?"
575
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
576
      else exit 0
577
    fi ; fi
578
    ${PRGPATH} polymost_override y
579
    main $HRPTYPE
580
    ;;
581
  both)
582
    if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
583
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
584
      else exit 0
585
    fi ; fi
586
    ${PRGPATH} polymer  y
587
    ${PRGPATH} polymost y
588
    ;;
589
  all)
590
    if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
591
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
592
      else exit 0
593
    fi ; fi
594
    ${PRGPATH} both y
595
    ${PRGPATH} full y
596
    ;;
330 leod 597
  voxel)
598
    SET_VERSION=NO
599
    main $HRPTYPE
600
    ;;
601
  sw_highres|sw_lowres)
602
    SET_VERSION=NO
603
    main $HRPTYPE
604
    ;;
605
  sw_both)
606
    if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
607
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
608
      else exit 0
609
    fi ; fi
610
    ${PRGPATH} sw_lowres  y
611
    ${PRGPATH} sw_highres y
612
    ;;
320 leod 613
  unused)
614
    echo "Option \"$1\" not yet implemented."
615
    ;;
616
  debug)
617
    echo "Nothing to debug."
618
    ;;
619
  *)
333 leod 620
    #if [ ! -f "./${HRPTYPE}.def" ] ; then
621
    #  echo "ERROR : ./${HRPTYPE}.def not found. This is no HRP root directory. Exit."
622
    #  exit 1
623
    #fi
331 leod 624
    if [ -f "${HRPTYPE}.def" ] ; then
625
      DEF_TOP="${HRPTYPE}.def"
626
      HRPTYPE=default
627
      SET_VERSION=NO
628
      EXTRACT_COMMENTED_FILES=NO
629
      main $HRPTYPE
630
    else
631
      echo "Usage: ${0} {HRPTYPE|TOP_DEF} [v VERSION]"
632
      echo "HRPTYPEs: {full|polymer|polymost_override|polymost|both|all}"
633
      echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
634
      echo "TOP_DEF:  {Filename without extension}"
635
      exit 1
636
    fi
320 leod 637
    ;;
638
esac
639
 
640
exit 0