Subversion Repositories duke3d_hrp

Rev

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