Subversion Repositories duke3d_hrp

Rev

Rev 645 | Rev 657 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
656 leod 1
#!/bin/bash
320 leod 2
 
656 leod 3
# Duke Nukem 3D High Resolution Pack Extractor  v0.7  2014-12-05
320 leod 4
#
5
# Author: LeoD
6
# License: ISC license : http://opensource.org/licenses/isc-license.txt
7
#
408 leod 8
# This script extracts a working copy of your local Duke Nukem 3D High
9
# Resolution Pack's Subversion repository, ready for zipping and distribution.
10
# This is mostly done by hierarchically parsing the *.def files.
11
# PolyMER or PolyMOST only versions can be chosen.
333 leod 12
# On Windows you might want MSYS' zip to create package files.
320 leod 13
# ("mingw-get install msys-zip")
14
# MinGW/MSYS performance is horrible, better go Linux. Even my virtual Debian
15
# machine accessing the Windows drive is 5 to 10 times faster.
16
# But it still sucks. This needs to become a Perl script one day.
333 leod 17
# Or maybe MSYS' bash gets finally updated to 4.* and I'll use its regex engine.
320 leod 18
 
331 leod 19
DEF_TOP=UNDEFINED
20
SET_VERSION=YES            # [YES|NO]
324 leod 21
EXTRACT_COMMENTED_FILES=NO # [YES|NO]
431 leod 22
DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH=polymost  #[none|polymost|polymer|mixed]
23
ATTRITION_POLYMOST_COMPATIBILTY_APPROACH=polymost #[none|polymost|polymer|mixed]
324 leod 24
 
320 leod 25
ask()
26
{
27
  echo -n "$@" '[y/N] ' ; read ans
28
  case "$ans" in
29
    y*|Y*) return 0 ;;
30
    *)     return 1 ;;
31
  esac
32
} # ask
33
 
34
 
35
copy_folders()
36
{
37
  mkdir ${EXTRACTDIR}
38
  for HRPDIR in . ; do
39
    if [ -d "${HRPDIR}" ] ; then
40
      DIRLIST=./HRP_DIRECTORIES.lst
41
      find "${HRPDIR}" -type d > ${DIRLIST}
42
      cat ${DIRLIST} | while read DIR; do
43
        if [ ! -d "${EXTRACTDIR}/${DIR}" ] ; then
44
          mkdir "${EXTRACTDIR}/${DIR}"
45
        fi
46
      done
47
      rm     ${DIRLIST}
48
    else
49
      echo "${HRPDIR} : no HRP."
50
    fi
51
  done
52
} # copy_folders()
53
 
54
 
324 leod 55
copy_set_version()
56
{
57
  VER_FILE="$1"
58
  TARGET_FILE="$2"
59
  V_DATE=`date +%F`
60
  if [ "${VERSION}" = "" ] ; then
61
    if [ -f VERSION ] ; then
62
      VERSION=`grep -owE "[0-9\\.]*" VERSION`
63
    fi
64
  fi
65
 
66
  echo "copy_set_version ${VER_FILE} -> ${TARGET_FILE}"
67
 
68
  case "${VER_FILE}" in
69
    hrp_readme.txt)
70
      cat "${VER_FILE}" | sed -r --posix \
71
        s/\(Version\ *\)\([0-9\.]*\)\(.*\)\(\\\)\)\(.*\)/\\1${VERSION}\ \(${V_DATE}\)\ \ \\5/ \
72
        >> "${TARGET_FILE}"
73
      ;;
74
    duke3d_hrp.def)
325 leod 75
      if [ "${HRPTYPE}" = "polymer" ] ; then
76
        cat "${VER_FILE}" | sed -r --posix \
77
          s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\ Polymer\\3/ \
78
          >> "${TARGET_FILE}"
79
      else
80
        cat "${VER_FILE}" | sed -r --posix \
81
          s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
82
          >> "${TARGET_FILE}"
83
      fi
324 leod 84
      ;;
431 leod 85
    duke3d_hrp_polymost.def | \
639 leod 86
    installer/polymost_override/duke3d_hrp_polymost_override.def | \
656 leod 87
    duke3d_hrp_megaton.def | \
639 leod 88
    installer/megaton_override/duke3d_hrp_megaton_override.def )
431 leod 89
      cat "${VER_FILE}" | sed -r --posix \
90
        s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
91
        >> "${TARGET_FILE}"
324 leod 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
643 leod 110
    if [ -f  hrp_readme.txt ] ; then
111
      cp -pv hrp_readme.txt         "${EXTRACTDIR}"
112
    fi
324 leod 113
  fi
320 leod 114
 
431 leod 115
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 116
     [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "megaton_override" ] ||\
384 leod 117
     [ "${HRPTYPE}" = "polymer"  ] || [ "${HRPTYPE}" = "full" ] ; then
118
    cp -pv hrp_art_license.txt      "${EXTRACTDIR}"
119
  fi
120
 
431 leod 121
  if [ "${HRPTYPE}" = "polymost" ] ; then
324 leod 122
    if [ "${SET_VERSION}" = "YES" ] ; then
123
      copy_set_version duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp.def"
124
    else
125
      cp -pv           duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp.def"
126
    fi
656 leod 127
    cp -pv duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp_polymost.def"
128
    cp -rpv installer/polymost_override/dukedc "${EXTRACTDIR}"
320 leod 129
  fi
130
 
639 leod 131
  if [ "${HRPTYPE}" = "megaton" ] ; then
132
    if [ "${SET_VERSION}" = "YES" ] ; then
133
      copy_set_version duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp.def"
134
    else
135
      cp -pv           duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp.def"
136
    fi
656 leod 137
    cp -pv duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp_megaton.def"
138
    cp -pv highres/screen/menu/2492_ver_megaton.png \
139
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
140
    cp -rpv installer/megaton_override/dukedc* "${EXTRACTDIR}"
141
    cp -rpv installer/megaton_override/highres "${EXTRACTDIR}"
639 leod 142
  fi
143
 
431 leod 144
  if [ "${HRPTYPE}" = "polymost_override" ] ; then
145
    if [ "${SET_VERSION}" = "YES" ] ; then
146
      copy_set_version \
147
        installer/polymost_override/duke3d_hrp_polymost_override.def \
148
        "${EXTRACTDIR}/duke3d_hrp.def"
656 leod 149
      copy_set_version \
150
        installer/polymost_override/duke3d_hrp_polymost_override.def \
151
        "${EXTRACTDIR}/duke3d_hrp_polymost.def"
431 leod 152
    else
153
      cp -pv installer/polymost_override/duke3d_hrp_polymost_override.def \
154
        "${EXTRACTDIR}/duke3d_hrp.def"
656 leod 155
       cp -pv installer/polymost_override/duke3d_hrp_polymost_override.def \
156
        "${EXTRACTDIR}/duke3d_hrp_polymost.def"
431 leod 157
    fi
656 leod 158
    cp -rpv installer/polymost_override/dukedc "${EXTRACTDIR}"
431 leod 159
  fi
160
 
639 leod 161
  if [ "${HRPTYPE}" = "megaton_override" ] ; then
162
    if [ "${SET_VERSION}" = "YES" ] ; then
163
      copy_set_version \
164
        installer/megaton_override/duke3d_hrp_megaton_override.def \
165
        "${EXTRACTDIR}/duke3d_hrp.def"
656 leod 166
      copy_set_version \
167
        installer/megaton_override/duke3d_hrp_megaton_override.def \
168
        "${EXTRACTDIR}/duke3d_hrp_megaton.def"
639 leod 169
    else
170
      cp -pv installer/megaton_override/duke3d_hrp_megaton_override.def \
171
        "${EXTRACTDIR}/duke3d_hrp.def"
656 leod 172
      cp -pv installer/megaton_override/duke3d_hrp_megaton_override.def \
173
        "${EXTRACTDIR}/duke3d_hrp_megaton.def"
639 leod 174
    fi
656 leod 175
    cp -pv  installer/megaton_override/*.bat   "${EXTRACTDIR}"
176
    cp -rpv installer/megaton_override/dukedc* "${EXTRACTDIR}"
177
    cp -rpv installer/megaton_override/highres "${EXTRACTDIR}"
639 leod 178
  fi
179
 
180
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "megaton" ] ; then
320 leod 181
    cp -pv duke3d.def "${EXTRACTDIR}"
182
    #cp -pv duke3d_hrp_polymost.def               "${EXTRACTDIR}"
183
    #cp -pv highres/screen/menu/2492_polymost.png "${EXTRACTDIR}/highres/screen/menu"
184
  fi
185
 
186
  if [ "${HRPTYPE}" = "full" ] ; then
324 leod 187
    if [ "${SET_VERSION}" = "YES" ] ; then
431 leod 188
      copy_set_version duke3d_hrp_polymost.def \
189
        "${EXTRACTDIR}/duke3d_hrp_polymost.def"
639 leod 190
      copy_set_version duke3d_hrp_megaton.def \
191
        "${EXTRACTDIR}/duke3d_hrp_megaton.def"
324 leod 192
    else
193
      cp -pv           duke3d_hrp_polymost.def "${EXTRACTDIR}"
639 leod 194
      cp -pv           duke3d_hrp_megaton.def "${EXTRACTDIR}"
324 leod 195
    fi
320 leod 196
  fi
197
 
431 leod 198
  if [ "${HRPTYPE}" = "full" ] ; then
199
    cp -pv highres/screen/menu/2492_ver_polymost.png \
200
      "${EXTRACTDIR}/highres/screen/menu"
320 leod 201
  fi
202
 
431 leod 203
  if [ "${HRPTYPE}" = "polymost_override" ] ; then
204
    cp -pv installer/polymost_override/hrp_polymost_override.txt \
205
      "${EXTRACTDIR}"
206
    cp -pv installer/polymost_override/2492_ver_polymost_override.png \
207
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
208
  fi
209
 
639 leod 210
  if [ "${HRPTYPE}" = "megaton_override" ] ; then
211
    cp -pv installer/megaton_override/hrp_megaton_override.txt \
212
      "${EXTRACTDIR}"
213
    cp -pv installer/megaton_override/2492_ver_megaton_override.png \
656 leod 214
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
639 leod 215
  fi
216
 
320 leod 217
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
218
    cp -pv duke3d.def                   "${EXTRACTDIR}"
324 leod 219
    if [ "${SET_VERSION}" = "YES" ] ; then
220
      copy_set_version duke3d_hrp.def "${EXTRACTDIR}/duke3d_hrp.def"
221
    else
222
      cp -pv           duke3d_hrp.def "${EXTRACTDIR}"
223
    fi
320 leod 224
    echo                  "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
225
    cp -p  *.mhk                        "${EXTRACTDIR}"
226
    #cp -pv highres/screen/menu/2492.png "${EXTRACTDIR}/highres/screen/menu"
227
 
324 leod 228
    #cp -pv highres/common/black.png                          "${EXTRACTDIR}/highres/common"
229
    #cp -pv highres/screen/fonts/digital/digital_minus.png    "${EXTRACTDIR}/highres/screen/fonts/digital"
230
    #cp -pv highres/screen/menu/widescreen/*_wide.png         "${EXTRACTDIR}/highres/screen/menu"
231
    #cp -pv highres/sprites/characters/1357_terminarm.md3     "${EXTRACTDIR}/highres/sprites/characters"
232
    #cp -pv highres/sprites/firstperson/2510_devastator_n.png "${EXTRACTDIR}/highres/sprites/firstperson"
233
    #cp -pv highres/sprites/monsters/1960_reconcar_s.png      "${EXTRACTDIR}/highres/sprites/monsters"
234
    #cp -pv highres/sprites/props/4387.png                    "${EXTRACTDIR}/highres/sprites/props"
408 leod 235
    #cp -pv highres/sprites/signs/4378-79.png                 "${EXTRACTDIR}/highres/sprites/signs"
324 leod 236
    #cp -pv highres/sprites/signs/4381-85.png                 "${EXTRACTDIR}/highres/sprites/signs"
320 leod 237
  fi
238
 
330 leod 239
  if [ "${HRPTYPE}" = "voxel" ] ; then
240
    cp -pv readme.txt             "${EXTRACTDIR}"
241
    cp -pv voxelp_art_license.txt "${EXTRACTDIR}"
242
    cp -pv duke3d.def             "${EXTRACTDIR}"
243
    cp -pv duke3d_voxel.def       "${EXTRACTDIR}"
244
    echo            "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
245
    cp -p  *.mhk                  "${EXTRACTDIR}"
246
  fi
247
 
248
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
249
    cp -pv sw.def                   "${EXTRACTDIR}"
333 leod 250
    cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres"
330 leod 251
    cp -pv HRP.bat                  "${EXTRACTDIR}"
252
    cp -pv HRP_Readme.txt           "${EXTRACTDIR}"
253
    cp -pv HRP_Changes.txt          "${EXTRACTDIR}"
254
    echo "Copying skyboxes ..."
255
    tar_copy_dir "highres/skyboxes" "${EXTRACTDIR}/highres/skyboxes"
256
    cd "${WORKDIR}"
257
  fi
258
 
259
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
384 leod 260
    echo "Creating sw.def for lowres HRP ..."
261
    echo "include lowres/sw_lrp.def" > "${EXTRACTDIR}/sw.def"
262
    cp -pv lowres/sw_lrp.def           "${EXTRACTDIR}/lowres"
263
    cp -pv LRP.bat                     "${EXTRACTDIR}"
264
    cp -pv LRP_Readme.txt              "${EXTRACTDIR}"
265
    cp -pv LRP_Changes.txt             "${EXTRACTDIR}"
330 leod 266
    echo "Copying skyboxes ..."
384 leod 267
    tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
330 leod 268
    cd "${WORKDIR}"
269
  fi
270
 
331 leod 271
  if [ "${HRPTYPE}" = "default" ] ; then
272
    cp -pv  "${DEF_TOP}"          "${EXTRACTDIR}/${DEF_TOP}"
408 leod 273
    echo            "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
274
    cp -p  *.mhk                  "${EXTRACTDIR}"
331 leod 275
    echo            "\`*.txt' -> \`${EXTRACTDIR}/*.txt'"
276
    cp -p  *.txt                  "${EXTRACTDIR}"
277
  fi
278
 
320 leod 279
} # copy_known_files()
280
 
281
 
656 leod 282
copy_polymost_mhk()
320 leod 283
{
656 leod 284
  cp -p maphacks/3drealms_polymost/E?L*.mhk "${EXTRACTDIR}"
285
  rm -f "${EXTRACTDIR}"/*_13d_*.mhk
286
  # bashism:
287
  for i in "${EXTRACTDIR}"/*.mhk ; do mv "$i" "${i/_polymost.mhk}".mhk ; done
288
  for i in "${EXTRACTDIR}"/*_atomic.mhk ; do mv "$i" "${i/_atomic}" ; done
289
  # Some people prefer unusual setups ... 
290
  if [ "${HRPTYPE}" = "polymost" ]||[ "${HRPTYPE}" = "polymost_override" ];then
291
    zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip *.mhk
292
  fi
293
} # copy_polymost_mhk()
320 leod 294
 
295
 
412 leod 296
# I really don't know yet if this will become necessary, or if it does make
324 leod 297
# sense at all, but at least the files involved are listed.
412 leod 298
dukeplus_polymost_hrp_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)
412 leod 336
      echo "  # (Using \"Polymer approach\")"
324 leod 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)
412 leod 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)
412 leod 370
      echo "  # (Using \"Mixed approach\")"
324 leod 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
 
412 leod 382
} # dukeplus_polymost_hrp_compatibility()
324 leod 383
 
384
 
412 leod 385
attrition_polymost_hrp_compatibility()
386
{
387
  # attr_hrp.def expects some files to be present in the HRP
388
  #
389
  # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295     
390
  #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
391
  #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
392
 
393
  SPR="highres/sprites"
394
  SPRE="${EXTRACTDIR}/highres/sprites"
395
  PATCHTYPE=$1
396
 
397
  case "$PATCHTYPE" in
398
    polymer)
399
      echo "  # (Using \"Polymer approach\")"
400
      ;;
401
    polymost)
402
      echo "  # (Using \"Polymost approach\")"
403
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson"
404
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson"
405
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson"
406
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson"
407
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson"
408
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson"
409
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
410
      ;;
411
    mixed)
412
      echo "  # (Using \"Mixed approach\")"
413
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson"
414
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson"
415
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson"
416
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson"
417
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson"
418
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson"
419
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
420
      cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson"
421
      cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
422
      cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson"
423
      cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson"
424
      cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson"
425
      cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson"
426
      cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson"
427
      cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson"
428
      cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
429
      ;;
430
    none)
431
      echo "  Not applied"
432
      #echo "  # Not yet implemented"
433
      ;;
434
    *)
435
      echo "  # Bad parameter"
436
      ;;
437
  esac
438
 
439
} # attrition_polymost_hrp_compatibility()
440
 
441
 
320 leod 442
parse_defs()
443
{
444
  echo "$1"
324 leod 445
  BLOCK_COMMENT="OFF"
320 leod 446
  cat $1 | while read DEF_LINE; do
447
 
448
    #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
415 leod 449
    #DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
506 leod 450
#    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\/\\\/.*// | sed s/\\\r//`
451
    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
320 leod 452
    if [ "${DEF_FILE}" != "" ] ; then
453
      cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
454
      parse_defs "${DEF_FILE}"
455
    fi
456
 
375 leod 457
    #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
458
    ## Old style added (except "defineskybox"):
415 leod 459
    HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
333 leod 460
    #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
320 leod 461
 
324 leod 462
    if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
463
 
464
      COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
465
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
466
 
467
      if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
468
 
469
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
470
 
471
      if [ ! "$HRP_TERM" = "" ] ; then
472
        HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
473
        if [ ! "$HRP_COMMENT" = "" ] ; then
474
          HRP_TERM=""
475
        fi
476
      fi
477
 
478
    fi
479
 
320 leod 480
    case "$HRP_TERM" in
415 leod 481
      file|mhkfile)
320 leod 482
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
483
        # Mastering the backslash :-) ... hm, no big performance gain ... :
484
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
485
        # Ignore comments WIP:
486
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
487
        ;;
331 leod 488
      model|voxel)
489
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
320 leod 490
        ;;
333 leod 491
      front|right|back|left|top|bottom|down)
320 leod 492
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
493
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
494
        ;;
375 leod 495
      ## Old Style
496
      definemodel)
497
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
498
        ;;
499
      definemodelskin)
500
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
501
        ;;
502
      definetexture)
503
        # Won't work atm if filename in quotes (too lazy)
504
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
505
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
506
        #echo "DEF_LINE : ${DEF_LINE}"
507
        #echo "HRP_FILE : ${HRP_FILE}"
508
        ;;
320 leod 509
      *)
510
        HRP_FILE=""
511
        ;;
512
    esac
513
 
514
    if [  !   "${HRP_FILE}" = "" ] ; then
515
      if [ -f "${HRP_FILE}" ] ; then
516
        cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
517
      else
518
        echo  "WARNING : ${HRP_FILE} is missing!"
519
      fi
520
    fi
521
 
522
  done
523
} # parse_defs()
524
 
525
 
526
delete_empty_folders()
527
{
528
    if [ -d "${EXTRACTDIR}" ] ; then
529
      rm -rf ${EXTRACTDIR}/.svn
530
      DIRLIST=./EXTRACT_DIRECTORIES.lst
531
      du "${EXTRACTDIR}" > ${DIRLIST}
532
      cat ${DIRLIST} | while read DIR ; do
533
        if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
534
          EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
645 leod 535
          if [ -d ${EMPTYDIR} ] ; then
536
            rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
320 leod 537
          fi
538
        fi
539
      done
540
      rm ${DIRLIST}
541
    else
542
      echo "No ${EXTRACTDIR}."
543
    fi
544
} # delete_empty_folders()
545
 
546
 
547
main()
548
{
549
  EXTRACTDIR=../hrp_${HRPTYPE}_extract
550
  echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
551
 
552
  if [ $FORCE = 0 ] ; then
553
    if ask "Proceed?"
554
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
555
      else exit 0
556
    fi
557
  fi
558
 
559
  date +%F" "%H:%M:%S
560
 
561
  echo "### Deleting ${EXTRACTDIR} ... ###"
562
  rm -rf ${EXTRACTDIR}
563
 
564
  echo "### Copying directory tree ... ###"
565
  copy_folders
566
 
643 leod 567
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 568
    [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ] ; then
320 leod 569
    echo "### Creating Polymost maphacks ... ###"
656 leod 570
    copy_polymost_mhk
320 leod 571
 
408 leod 572
    echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
412 leod 573
    dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
574
 
575
    echo "### Attrition<>Polymost HRP compatibility patch ... ###"
576
    attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
320 leod 577
  fi
578
 
579
  echo "### Parsing DEF file hierarchy ... ###"
324 leod 580
  if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
581
    echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
582
  else
583
    echo "  # Extract commented textures and models: NO"
584
  fi
645 leod 585
  if [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "full" ] ; then
586
    parse_defs duke3d_hrp_megaton.def
587
  fi
320 leod 588
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
589
    parse_defs duke3d_hrp_polymost.def
590
  fi
645 leod 591
  if [ "${HRPTYPE}" = "polymer" ]  || [ "${HRPTYPE}" = "full" ] ; then
320 leod 592
    parse_defs duke3d_hrp.def
593
  fi
330 leod 594
  if [ "${HRPTYPE}" = "voxel" ] ; then
595
    parse_defs duke3d_voxel.def
596
  fi
597
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
333 leod 598
    parse_defs highres/sw_hrp.def
330 leod 599
  fi
600
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
333 leod 601
    parse_defs lowres/sw_lrp.def
330 leod 602
  fi
331 leod 603
  if [ "${HRPTYPE}" = "default" ] ; then
604
    parse_defs "${DEF_TOP}"
605
  fi
320 leod 606
 
656 leod 607
  echo "### Copying 'known' files ... ###"
608
  copy_known_files
609
 
320 leod 610
  echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
611
  delete_empty_folders
612
 
613
  date +%F" "%H:%M:%S
614
 
615
  echo "Command line example for creating a ZIP package:"
616
  echo "sh -c \"cd ${EXTRACTDIR} ; zip -rqn .zip:.jpg:.png ${EXTRACTDIR}.zip *\""
617
} # main()
618
 
619
 
620
 
621
PRGPATH=$0
622
HRPTYPE=$1
623
if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
325 leod 624
if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
625
  VERSION="$3"
626
  echo "${VERSION}" > VERSION
627
fi
320 leod 628
HRPROOT=.
330 leod 629
WORKDIR=`pwd`
320 leod 630
 
631
cd               "${HRPROOT}"
330 leod 632
echo  "PWD     :  ${WORKDIR}"
633
echo  "HRPROOT :  ${HRPROOT}"
320 leod 634
 
635
case "$HRPTYPE" in
639 leod 636
  polymer|polymost_override|polymost|megaton_override|megaton)
320 leod 637
    main $HRPTYPE
638
    ;;
639
  full)
639 leod 640
    if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Packs)?"
320 leod 641
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
642
      else exit 0
643
    fi ; fi
644
    ${PRGPATH} polymost_override y
639 leod 645
    ${PRGPATH} megaton_override y
320 leod 646
    main $HRPTYPE
647
    ;;
648
  both)
649
    if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
650
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
651
      else exit 0
652
    fi ; fi
653
    ${PRGPATH} polymer  y
654
    ${PRGPATH} polymost y
655
    ;;
639 leod 656
  ovr)
657
    ${PRGPATH} polymost_override y
658
    ${PRGPATH} megaton_override y
659
    ;;
320 leod 660
  all)
661
    if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
662
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
663
      else exit 0
664
    fi ; fi
639 leod 665
    ${PRGPATH} both    y
666
    ${PRGPATH} megaton y
667
    ${PRGPATH} full    y
320 leod 668
    ;;
330 leod 669
  voxel)
670
    SET_VERSION=NO
671
    main $HRPTYPE
672
    ;;
673
  sw_highres|sw_lowres)
674
    SET_VERSION=NO
675
    main $HRPTYPE
676
    ;;
677
  sw_both)
678
    if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
679
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
680
      else exit 0
681
    fi ; fi
682
    ${PRGPATH} sw_lowres  y
683
    ${PRGPATH} sw_highres y
684
    ;;
320 leod 685
  unused)
686
    echo "Option \"$1\" not yet implemented."
687
    ;;
688
  debug)
689
    echo "Nothing to debug."
690
    ;;
691
  *)
408 leod 692
    if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
693
      DEF_TOP="${HRPTYPE}"
331 leod 694
      HRPTYPE=default
695
      SET_VERSION=NO
696
      EXTRACT_COMMENTED_FILES=NO
697
      main $HRPTYPE
698
    else
408 leod 699
      echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
639 leod 700
      echo "HRPTYPEs: {full|ovr|all}"
701
      echo "HRPTYPEs: {polymer|polymost_override|polymost|both}"
702
      echo "HRPTYPEs: {megaton_override|megaton}"
331 leod 703
      echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
704
      exit 1
705
    fi
320 leod 706
    ;;
707
esac
708
 
709
exit 0