Subversion Repositories duke3d_hrp

Rev

Rev 709 | Rev 711 | 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
 
710 leod 3
# Duke Nukem 3D CON/DEF/HRP File Extractor  v0.9.0  2019-05-27
320 leod 4
#
710 leod 5
# Author:  LeoD
6
# License: ISC License -> https://opensource.org/licenses/isc-license.txt
320 leod 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.
710 leod 12
#
13
# On Windows you may use the Bash shell that comes with either MSYS2 or Git.
14
# Bash's performance of calling executables is horrible, better go Linux. Even
15
# my virtual Debian machine accessing the Windows drive is several times faster.
16
# As of v0.9.0, Bash's builtin regex engine is used for many parts, but it fails
17
# to use the \b word delimiter correctly on Windows ( v4.4.23, x86_64-pc-msys ).
320 leod 18
 
331 leod 19
DEF_TOP=UNDEFINED
710 leod 20
CON_TOP=UNDEFINED
21
GRP_TOP=UNDEFINED
22
GRP=""
331 leod 23
SET_VERSION=YES            # [YES|NO]
324 leod 24
EXTRACT_COMMENTED_FILES=NO # [YES|NO]
431 leod 25
DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH=polymost  #[none|polymost|polymer|mixed]
26
ATTRITION_POLYMOST_COMPATIBILTY_APPROACH=polymost #[none|polymost|polymer|mixed]
324 leod 27
 
710 leod 28
exit_on_error() {
29
  echo -e "\e[0;31mERROR   :\e[0m ${@}"
30
  exit 1
31
}
32
 
33
warning() {
34
  echo -e "\e[1;35mWARNING :\e[0m ${@}"
35
}
36
 
37
info() {
38
  echo -e "\e[0;32mINFO    :\e[0m ${@}"
39
}
40
 
41
ask() {
320 leod 42
  echo -n "$@" '[y/N] ' ; read ans
43
  case "$ans" in
44
    y*|Y*) return 0 ;;
45
    *)     return 1 ;;
46
  esac
47
} # ask
48
 
49
 
710 leod 50
copy_folders() {
51
  mkdir ${EXTRACTDIR} || exit_on_error "Could not create ${EXTRACTDIR}/"
52
  for SUBDIR in . ; do
53
    if [ -d "${SUBDIR}" ] ; then
54
      DIRLIST=${EXTRACTDIR}/DIRECTORIES.lst
55
      find  "${SUBDIR}" -type d | grep -v "\.svn" > ${DIRLIST}
320 leod 56
      cat ${DIRLIST} | while read DIR; do
57
        if [ ! -d "${EXTRACTDIR}/${DIR}" ] ; then
710 leod 58
          mkdir   "${EXTRACTDIR}/${DIR}" || exit_on_error\
59
            "Could not create ${EXTRACTDIR}/${DIR}/"
320 leod 60
        fi
61
      done
710 leod 62
      rm ${DIRLIST}
320 leod 63
    else
710 leod 64
      exit_on_error "${SUBDIR} : Oops."
320 leod 65
    fi
66
  done
67
} # copy_folders()
68
 
69
 
710 leod 70
copy_set_version() {
324 leod 71
  VER_FILE="$1"
72
  TARGET_FILE="$2"
657 leod 73
  if [ ! "${SET_VERSION}" = "YES" ] ; then
74
    cp -pv "${VER_FILE}" "${TARGET_FILE}"
75
  else
76
 
77
    V_DATE=`date +%F`
78
    if [ "${VERSION}" = "" ] ; then
79
      if [ -f VERSION ] ; then
80
        VERSION=`grep -owE "[0-9\\.]*" VERSION`
81
      fi
324 leod 82
    fi
83
 
710 leod 84
    echo "copy_set_version: ${VER_FILE} -> ${TARGET_FILE}"
324 leod 85
 
657 leod 86
    case "${VER_FILE}" in
87
      hrp_readme.txt)
325 leod 88
        cat "${VER_FILE}" | sed -r --posix \
657 leod 89
          s/\(Version\ *\)\([0-9\.]*\)\(.*\)\(\\\)\)\(.*\)/\\1${VERSION}\ \(${V_DATE}\)\ \ \\5/ \
325 leod 90
          >> "${TARGET_FILE}"
657 leod 91
        ;;
92
      duke3d_hrp.def)
93
        if [ "${HRPTYPE}" = "polymer" ] ; then
94
          cat "${VER_FILE}" | sed -r --posix \
95
            s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\ Polymer\\3/ \
96
            >> "${TARGET_FILE}"
97
        else
98
          cat "${VER_FILE}" | sed -r --posix \
99
            s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
100
            >> "${TARGET_FILE}"
101
        fi
102
        ;;
103
      duke3d_hrp_polymost.def | \
708 leod 104
      tools/polymost_override/duke3d_hrp_polymost_override.def | \
657 leod 105
      duke3d_hrp_megaton.def | \
710 leod 106
      tools/megaton_override/duke3d_hrp_megaton_override.def | \
107
      duke3d_maphacks.def )
325 leod 108
        cat "${VER_FILE}" | sed -r --posix \
109
          s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
110
          >> "${TARGET_FILE}"
657 leod 111
        ;;
112
      *)
710 leod 113
        exit_on_error "copy_set_version() - UNKNOWN FILE: ${VER_FILE}"
657 leod 114
        ;;
115
    esac
116
  fi
117
} # copy_set_version()
324 leod 118
 
710 leod 119
tar_copy_dir() {
330 leod 120
  (cd ${1}; tar cf - . ) | (cd ${2}; tar xf -)
121
}
122
 
710 leod 123
copy_known_files() {
124
 
125
  if [ -f hrp_readme.txt ] ; then
324 leod 126
    copy_set_version hrp_readme.txt "${EXTRACTDIR}/hrp_readme.txt"
127
  fi
320 leod 128
 
431 leod 129
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 130
     [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "megaton_override" ] ||\
708 leod 131
     [ "${HRPTYPE}" = "maphacks" ] ||\
384 leod 132
     [ "${HRPTYPE}" = "polymer"  ] || [ "${HRPTYPE}" = "full" ] ; then
133
    cp -pv hrp_art_license.txt      "${EXTRACTDIR}"
134
  fi
135
 
708 leod 136
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymer" ] ||\
710 leod 137
     [ "${HRPTYPE}" = "maphacks" ] || [ "${HRPTYPE}" = "full" ] ||\
138
     [ "${HRPTYPE}" = "voxels" ] ; then
708 leod 139
    cp -pv maphacks/MapHacks.txt    "${EXTRACTDIR}/maphacks/"
140
  fi
141
 
431 leod 142
  if [ "${HRPTYPE}" = "polymost" ] ; then
708 leod 143
    cp -pv           duke3d_hrp_polymost.def "${EXTRACTDIR}"
144
    copy_set_version duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp.def"
145
    cp -pvr tools/polymost_override/dukedc   "${EXTRACTDIR}"
320 leod 146
  fi
147
 
639 leod 148
  if [ "${HRPTYPE}" = "megaton" ] ; then
661 leod 149
    cp -pv           duke3d_hrp_megaton.def "${EXTRACTDIR}"
657 leod 150
    copy_set_version duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp.def"
656 leod 151
    cp -pv highres/screen/menu/2492_ver_megaton.png \
152
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
708 leod 153
    cp -pvr tools/megaton_override/dukedc* "${EXTRACTDIR}"
154
    cp -pvr tools/megaton_override/highres "${EXTRACTDIR}"
639 leod 155
  fi
156
 
431 leod 157
  if [ "${HRPTYPE}" = "polymost_override" ] ; then
657 leod 158
    copy_set_version \
708 leod 159
      tools/polymost_override/duke3d_hrp_polymost_override.def \
657 leod 160
      "${EXTRACTDIR}/duke3d_hrp.def"
161
    copy_set_version \
708 leod 162
      tools/polymost_override/duke3d_hrp_polymost_override.def \
657 leod 163
      "${EXTRACTDIR}/duke3d_hrp_polymost.def"
708 leod 164
    cp -pv tools/polymost_override/hrp_polymost_override.txt \
661 leod 165
      "${EXTRACTDIR}"
708 leod 166
    cp -pv tools/polymost_override/2492_ver_polymost_override.png \
661 leod 167
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
708 leod 168
    cp -pvr tools/polymost_override/dukedc "${EXTRACTDIR}"
431 leod 169
  fi
170
 
639 leod 171
  if [ "${HRPTYPE}" = "megaton_override" ] ; then
657 leod 172
    copy_set_version \
708 leod 173
      tools/megaton_override/duke3d_hrp_megaton_override.def \
657 leod 174
      "${EXTRACTDIR}/duke3d_hrp.def"
175
    copy_set_version \
708 leod 176
      tools/megaton_override/duke3d_hrp_megaton_override.def \
657 leod 177
      "${EXTRACTDIR}/duke3d_hrp_megaton.def"
708 leod 178
    cp -pv tools/megaton_override/hrp_megaton_override.txt \
661 leod 179
      "${EXTRACTDIR}"
708 leod 180
    cp -pv tools/megaton_override/2492_ver_megaton_override.png \
181
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_megaton.png"
182
    cp -pv  tools/megaton_override/*.bat   "${EXTRACTDIR}"
183
    cp -pvr tools/megaton_override/dukedc* "${EXTRACTDIR}"
184
    cp -pvr tools/megaton_override/highres "${EXTRACTDIR}"
657 leod 185
    # Let Megaton Override work on top of Polymost HRP:
710 leod 186
    #cp -pv highres/screen_megaton.def          "${EXTRACTDIR}/highres/"
187
    #cp -pv highres/screen/menu_megaton.def     "${EXTRACTDIR}/highres/screen/"
188
    #cp -pv highres/sprites_megaton.def         "${EXTRACTDIR}/highres/"
189
    #cp -pv highres/sprites/effects_megaton.def "${EXTRACTDIR}/highres/sprites/"
639 leod 190
  fi
191
 
192
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "megaton" ] ; then
320 leod 193
    cp -pv duke3d.def "${EXTRACTDIR}"
659 leod 194
    cp -pv highres/screen/menu/2492_polymost.png \
708 leod 195
      "${EXTRACTDIR}/highres/screen/menu/"
320 leod 196
  fi
197
 
198
  if [ "${HRPTYPE}" = "full" ] ; then
657 leod 199
    copy_set_version duke3d_hrp_polymost.def \
200
      "${EXTRACTDIR}/duke3d_hrp_polymost.def"
201
    copy_set_version duke3d_hrp_megaton.def \
202
      "${EXTRACTDIR}/duke3d_hrp_megaton.def"
320 leod 203
  fi
204
 
431 leod 205
  if [ "${HRPTYPE}" = "full" ] ; then
206
    cp -pv highres/screen/menu/2492_ver_polymost.png \
708 leod 207
      "${EXTRACTDIR}/highres/screen/menu/"
320 leod 208
  fi
209
 
210
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
708 leod 211
    cp -pv           duke3d.def     "${EXTRACTDIR}"
657 leod 212
    copy_set_version duke3d_hrp.def "${EXTRACTDIR}/duke3d_hrp.def"
320 leod 213
    #cp -pv highres/screen/menu/2492.png "${EXTRACTDIR}/highres/screen/menu"
214
 
708 leod 215
    #cp -pv highres/common/black.png                          "${EXTRACTDIR}/highres/common/"
216
    #cp -pv highres/screen/fonts/digital/digital_minus.png    "${EXTRACTDIR}/highres/screen/fonts/digital/"
217
    #cp -pv highres/screen/menu/widescreen/*_wide.png         "${EXTRACTDIR}/highres/screen/menu/"
218
    #cp -pv highres/sprites/characters/1357_terminarm.md3     "${EXTRACTDIR}/highres/sprites/characters/"
219
    #cp -pv highres/sprites/firstperson/2510_devastator_n.png "${EXTRACTDIR}/highres/sprites/firstperson/"
220
    #cp -pv highres/sprites/monsters/1960_reconcar_s.png      "${EXTRACTDIR}/highres/sprites/monsters/"
221
    #cp -pv highres/sprites/props/4387.png                    "${EXTRACTDIR}/highres/sprites/props/"
222
    #cp -pv highres/sprites/signs/4378-79.png                 "${EXTRACTDIR}/highres/sprites/signs/"
223
    #cp -pv highres/sprites/signs/4381-85.png                 "${EXTRACTDIR}/highres/sprites/signs/"
320 leod 224
  fi
225
 
708 leod 226
  if [ "${HRPTYPE}" = "maphacks" ] ; then
709 leod 227
    cp -pv           maphacks/MapHacks.txt          "${EXTRACTDIR}"
228
    cp -pv           maphacks/mhk-extract.def       "${EXTRACTDIR}/maphacks/"
229
    cp -pv           maphacks/maphacks_polymost.def "${EXTRACTDIR}/maphacks/"
710 leod 230
    cp -pv           duke3d_maphacks.def            "${EXTRACTDIR}"
231
    copy_set_version duke3d_maphacks.def            "${EXTRACTDIR}/duke3d.def"
708 leod 232
  fi
233
 
710 leod 234
  if [ "${HRPTYPE}" = "voxels" ] ; then
708 leod 235
    cp -pv voxelpack_readme.txt      "${EXTRACTDIR}"
236
    cp -pv voxelpack_art_license.txt "${EXTRACTDIR}"
237
    cp -pv duke3d.def                "${EXTRACTDIR}"
238
    cp -pv duke3d_voxels.def         "${EXTRACTDIR}"
239
    if [ -f  EDUKE.CON ] ; then
240
      cp -pv EDUKE.CON               "${EXTRACTDIR}"
710 leod 241
      #cp -pv scripts/animation.con   "${EXTRACTDIR}/scripts/"
242
      #cp -pv scripts/rotation.con    "${EXTRACTDIR}/scripts/"
243
      cp -pv scripts/*.con           "${EXTRACTDIR}/scripts/"
708 leod 244
    fi
330 leod 245
  fi
246
 
247
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
248
    cp -pv sw.def                   "${EXTRACTDIR}"
708 leod 249
    cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres/"
330 leod 250
    cp -pv HRP.bat                  "${EXTRACTDIR}"
251
    cp -pv HRP_Readme.txt           "${EXTRACTDIR}"
252
    cp -pv HRP_Changes.txt          "${EXTRACTDIR}"
710 leod 253
    info "Copying  skyboxes ..."
330 leod 254
    tar_copy_dir "highres/skyboxes" "${EXTRACTDIR}/highres/skyboxes"
255
    cd "${WORKDIR}"
256
  fi
257
 
258
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
710 leod 259
    info "Creating sw.def for lowres HRP ..."
384 leod 260
    echo "include lowres/sw_lrp.def" > "${EXTRACTDIR}/sw.def"
708 leod 261
    cp -pv lowres/sw_lrp.def           "${EXTRACTDIR}/lowres/"
384 leod 262
    cp -pv LRP.bat                     "${EXTRACTDIR}"
263
    cp -pv LRP_Readme.txt              "${EXTRACTDIR}"
264
    cp -pv LRP_Changes.txt             "${EXTRACTDIR}"
710 leod 265
    info "Copying  skyboxes ..."
384 leod 266
    tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
330 leod 267
    cd "${WORKDIR}"
268
  fi
269
 
710 leod 270
  if [ "${HRPTYPE}" = "auto" ] ; then
271
    for txtfile in *.txt; do
272
      cp -pv "$txtfile" "${EXTRACTDIR}"
273
    done
331 leod 274
  fi
275
 
320 leod 276
} # copy_known_files()
277
 
278
 
710 leod 279
copy_polymost_mhk() {
708 leod 280
  cp -p maphacks/3drealms/E?L*_polymost.mhk "${EXTRACTDIR}"
281
  cp -p maphacks/dukedc/DUKEDC*-megaton.mhk "${EXTRACTDIR}"
656 leod 282
  rm -f "${EXTRACTDIR}"/*_13d_*.mhk
710 leod 283
  rm -f "${EXTRACTDIR}"/*_worldtour_*.mhk
656 leod 284
  # bashism:
662 leod 285
  for i in "${EXTRACTDIR}"/*_polymost.mhk ; do mv "$i" "${i/_polymost}" ; done
286
  for i in "${EXTRACTDIR}"/*-megaton.mhk  ; do mv "$i" "${i/-megaton}"  ; done
656 leod 287
} # copy_polymost_mhk()
320 leod 288
 
289
 
412 leod 290
# I really don't know yet if this will become necessary, or if it does make
324 leod 291
# sense at all, but at least the files involved are listed.
412 leod 292
dukeplus_polymost_hrp_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)
710 leod 330
      echo "          (Using \"Polymer approach\")"
708 leod 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/"
324 leod 345
      ;;
346
    polymost)
710 leod 347
      echo "          (Using \"Polymost approach\")"
708 leod 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/"
324 leod 362
      ;;
363
    mixed)
710 leod 364
      echo "          (Using \"Mixed approach\")"
365
      echo "          Not applied / Not yet implemented"
324 leod 366
      ;;
367
    none)
710 leod 368
      info "  Not applied"
407 leod 369
      #echo "  # Not yet implemented"
324 leod 370
      ;;
371
    *)
710 leod 372
      warning "  Bad parameter"
324 leod 373
      ;;
374
  esac
375
 
412 leod 376
} # dukeplus_polymost_hrp_compatibility()
324 leod 377
 
378
 
710 leod 379
attrition_polymost_hrp_compatibility() {
412 leod 380
  # attr_hrp.def expects some files to be present in the HRP
381
  #
382
  # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295
383
  #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
384
  #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
385
 
386
  SPR="highres/sprites"
387
  SPRE="${EXTRACTDIR}/highres/sprites"
388
  PATCHTYPE=$1
389
 
390
  case "$PATCHTYPE" in
391
    polymer)
710 leod 392
      echo "          (Using \"Polymer approach\")"
412 leod 393
      ;;
394
    polymost)
710 leod 395
      echo "          (Using \"Polymost approach\")"
708 leod 396
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson/"
397
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson/"
398
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson/"
399
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
400
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
401
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
412 leod 402
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
403
      ;;
404
    mixed)
710 leod 405
      echo "          (Using \"Mixed approach\")"
708 leod 406
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
407
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
408
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
409
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
410
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
411
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
412 leod 412
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
708 leod 413
      cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson/"
412 leod 414
      cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
708 leod 415
      cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson/"
416
      cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson/"
417
      cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/"
418
      cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson/"
419
      cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson/"
420
      cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson/"
412 leod 421
      cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
422
      ;;
423
    none)
710 leod 424
      info "  Not applied"
412 leod 425
      #echo "  # Not yet implemented"
426
      ;;
427
    *)
710 leod 428
      warning "  Bad parameter"
412 leod 429
      ;;
430
  esac
431
 
432
} # attrition_polymost_hrp_compatibility()
433
 
434
 
710 leod 435
extract_file() {
436
  local FILE="$1"
437
  if [ -f "${FILE}" ] ; then
438
    cp -p "${FILE}" "${EXTRACTDIR}/${FILE}"
439
  elif [ ${GRP} ] ; then
440
    cd "${EXTRACTDIR}/${GRP}"
441
      kextract "${WORKDIR}/${GRP}" "${FILE}" > /dev/null
442
    cd "${WORKDIR}"
443
    if [ ! -f "${EXTRACTDIR}/${GRP}/${FILE}" ] ; then
444
      warning "${FILE} is missing!"
445
    #else
446
    #  echo -e "${FILE} -> \e[0;33m${GRP}/\e[0m${FILE^^}"
447
    fi
448
  else
449
    warning "${FILE} is missing!"
450
  fi
451
}
452
 
453
 
454
parse_defs() {
455
  local DEF_FILE="$1"
456
  extract_file "${DEF_FILE}"
457
  if [ -f "${DEF_FILE}" ] ; then
458
    echo  "${DEF_FILE}"
459
  elif [  -f "${EXTRACTDIR}/${GRP}/${DEF_FILE}" ] ; then
460
    echo   -e "${DEF_FILE} -> \e[0;33m${GRP}/\e[0m${DEF_FILE^^}"
461
    DEF_FILE="${EXTRACTDIR}/${GRP}/${DEF_FILE^^}"
462
  else
463
    return
464
  fi
465
 
324 leod 466
  BLOCK_COMMENT="OFF"
320 leod 467
 
710 leod 468
  cat "${DEF_FILE}" | while read DEF_LINE; do
320 leod 469
 
710 leod 470
    #echo "DEF_LINE1: ${DEF_LINE}"
471
    #DEF_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
375 leod 472
    ## Old style added (except "defineskybox"):
710 leod 473
    #DEF_TERM=`echo "${DEF_LINE}" | grep -owE "include|definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down|\\/\\*|\\*\\/"`
333 leod 474
    #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
710 leod 475
    #echo "DEF_TERM1: ${DEF_TERM}"
320 leod 476
 
710 leod 477
    local TOKEN_LIST='\b(include\b'
478
    local TOKEN_LIST='^(include)'
479
    local TOKEN_LIST='(^include|file|^definetexture|^definemodel|^definemodelskin|^mhkfile|^model|^voxel|^front|^right|^back|^left|^top|^bottom|^down|\/\*|\*\/)'
324 leod 480
 
710 leod 481
    if [[ ${DEF_LINE} =~ ${TOKEN_LIST} ]] ; then
482
      DEF_TERM="${BASH_REMATCH}"
483
    else
484
      DEF_TERM=""
485
    fi
486
 
487
    if [ "${DEF_TERM}" ] && [ "$EXTRACT_COMMENTED_FILES" = "NO" ] ; then
488
      #COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
489
      COMMENT_TERM="${DEF_TERM}"
324 leod 490
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
491
 
710 leod 492
      if [ "$BLOCK_COMMENT" = "ON" ] ; then DEF_TERM="" ; fi
324 leod 493
 
494
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
495
 
710 leod 496
      if [ $DEF_TERM ] ; then
497
        if [[ ${DEF_LINE} =~ //.*$DEF_TERM ]] ; then
498
          DEF_TERM=""
324 leod 499
        fi
500
      fi
501
    fi
502
 
710 leod 503
    if [ "${DEF_TERM}" ] ; then case "$DEF_TERM" in
504
      include)
505
        local SUB_DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
506
        if [          ${SUB_DEF_FILE} ] ; then
507
          parse_defs "${SUB_DEF_FILE}"
508
        fi
320 leod 509
        ;;
710 leod 510
      file)
511
        if [[ ${DEF_LINE} =~ \ file\  ]] ; then
512
          HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
513
        elif [[ ! ${DEF_LINE} =~ mapfile ]] ; then
514
          warning "Bad 'file' statement: ${DEF_LINE}"
515
        fi
320 leod 516
        ;;
710 leod 517
      mhkfile|model|voxel)
518
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
519
        ;;
333 leod 520
      front|right|back|left|top|bottom|down)
710 leod 521
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
320 leod 522
        ;;
375 leod 523
      ## Old Style
524
      definemodel)
710 leod 525
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
375 leod 526
        ;;
527
      definemodelskin)
710 leod 528
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
375 leod 529
        ;;
530
      definetexture)
531
        # Won't work atm if filename in quotes (too lazy)
532
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
533
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
534
        #echo "DEF_LINE : ${DEF_LINE}"
535
        #echo "HRP_FILE : ${HRP_FILE}"
536
        ;;
320 leod 537
      *)
538
        HRP_FILE=""
539
        ;;
710 leod 540
    esac ; fi
320 leod 541
 
710 leod 542
    if [ "${HRP_FILE}" ] ; then
543
      extract_file "${HRP_FILE}"
320 leod 544
    fi
545
 
546
  done
547
} # parse_defs()
548
 
549
 
710 leod 550
parse_cons() {
551
  local CON_FILE="$1"
552
  extract_file "${CON_FILE}"
553
  if [ -f "${CON_FILE}" ] ; then
554
    echo  "${CON_FILE}"
555
  elif [  -f "${EXTRACTDIR}/${GRP}/${CON_FILE}" ] ; then
556
    echo   -e "${CON_FILE} -> \e[0;33m${GRP}/\e[0m${CON_FILE^^}"
557
    CON_FILE="${EXTRACTDIR}/${GRP}/${CON_FILE^^}"
558
  else
559
    return
560
  fi
561
 
562
  MUSIC_FLAG=""
563
  MUSIC_POS=""
564
 
565
  BLOCK_COMMENT="OFF"
566
 
567
  cat "${CON_FILE}" | while read CON_LINE; do
568
 
569
    #echo "CON_LINE : ${CON_LINE}"
570
    #CON_TERM=`echo "${CON_LINE}" | grep -owE "include|setdefname|definelevelname|definesound|music|\\/\\*|\\*\\/"`
571
    #echo "CON_TERM : ${CON_TERM}"
572
 
573
    #if [[ ${CON_LINE} =~ include|setdefname|definelevelname|definesound|music|\/\*|\*\/ ]] ; then
574
    local TOKEN_LIST='\b(include\b'
575
    local TOKEN_LIST='^(include)'
576
    local TOKEN_LIST='(include|setdefname|definelevelname|definesound|music|\/\*|\*\/)'
577
    if [[ ${CON_LINE} =~ ${TOKEN_LIST} ]] ; then
578
      #echo "Rematch  : ${BASH_REMATCH}"
579
      CON_TERM="${BASH_REMATCH}"
580
    else
581
      CON_TERM=""
582
    fi
583
 
584
    if [ ${MUSIC_FLAG} ] && [ "${CON_TERM}" = "" ] ; then
585
      MUSIC_POS="1"
586
	  MUSIC_FLAG=""
587
    else
588
      MUSIC_POS=""
589
    fi
590
 
591
    if [ "${CON_TERM}" ] && [ "$EXTRACT_COMMENTED_FILES" = "NO" ] ; then
592
      COMMENT_TERM="${CON_TERM}"
593
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON"  ; fi
594
 
595
      if [ "$BLOCK_COMMENT" = "ON" ] ; then CON_TERM=""         ; fi
596
 
597
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
598
 
599
      if [ $CON_TERM ] ; then
600
        if [[ ${CON_LINE} =~ //.*$CON_TERM ]] ; then
601
          CON_TERM=""
602
        fi
603
      fi
604
    fi
605
 
606
    if [ "${CON_TERM}" ] ; then case "$CON_TERM" in
607
      include)
608
        local SUB_CON_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $2 }' | sed 's/\r//'`
609
        if [          ${SUB_CON_FILE} ] ; then
610
          parse_cons "${SUB_CON_FILE}"
611
        fi
612
        ;;
613
      setdefname)
614
        local     DEF_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $2 }' | sed 's/\r//'`
615
        if [       ${DEF_FILE} ] ; then
616
          DEF_TOP="${DEF_FILE}"
617
          info "Toplevel DEF set to ${DEF_TOP}"
618
          echo "${DEF_TOP}"  >   "${EXTRACTDIR}/DEF_TOP.tmp"
619
        fi
620
        ;;
621
      definesound)
622
        SOUND_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $3 }' | sed 's/\r//'`
623
        if [            ${SOUND_FILE} ] ; then
624
          extract_file "${SOUND_FILE}"
625
        fi
626
        ;;
627
      definelevelname)
628
          MAP_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $4 }' | sed 's/\r//'`
629
        if [            ${MAP_FILE} ] ; then
630
          extract_file "${MAP_FILE}"
631
        fi
632
        ;;
633
      music)
634
        MUSIC_POS=3
635
        while [ ${MUSIC_POS} ] ; do
636
          MUSIC_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk "{ print \\$$MUSIC_POS }" | sed 's/\r//'`
637
          if [            ${MUSIC_FILE} ] ; then
638
            extract_file "${MUSIC_FILE}"
639
            MUSIC_POS=$(($MUSIC_POS + 1))
640
            MUSIC_FLAG=true
641
          else
642
            MUSIC_POS=""
320 leod 643
          fi
710 leod 644
        done
645
        ;;
646
      *)
647
        ;;
648
    esac ; fi
649
 
650
    if [ ${MUSIC_POS} ] ; then
651
      while [ ${MUSIC_POS} ] ; do
652
        MUSIC_FILE=`echo "${CON_LINE}" | grep -wE ".*\\.mid" | awk "{ print \\$$MUSIC_POS }" | sed 's/\r//'`
653
        if [            ${MUSIC_FILE} ] ; then
654
          extract_file "${MUSIC_FILE}"
655
          MUSIC_POS=$(($MUSIC_POS + 1))
656
          MUSIC_FLAG=true
657
        else
658
          MUSIC_POS=""
320 leod 659
        fi
660
      done
661
    fi
710 leod 662
 
663
  done
664
} # parse_cons()
665
 
666
 
667
delete_empty_folders() {
668
  if [ -d "${EXTRACTDIR}" ] ; then
669
    rm -rf ${EXTRACTDIR}/.svn
670
    DIRLIST=./EXTRACT_DIRECTORIES.lst
671
    du "${EXTRACTDIR}" > ${DIRLIST}
672
    cat ${DIRLIST} | while read DIR ; do
673
      if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
674
        EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
675
        if [ -d ${EMPTYDIR} ] ; then
676
          rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
677
        fi
678
      fi
679
    done
680
    rm ${DIRLIST}
681
  else
682
    warning "No ${EXTRACTDIR}."
683
  fi
320 leod 684
} # delete_empty_folders()
685
 
686
 
710 leod 687
main() {
320 leod 688
 
710 leod 689
  EXTRACTDIR=../${HRPTYPE}_extract
690
  [[ ${HRPTYPE} =~ (.*)(/)(.*) ]] # greedy first .* required
691
  if [ ${BASH_REMATCH[3]} ] ; then
692
    EXTRACTDIR=../${BASH_REMATCH[3]}_extract
693
  fi
694
  echo "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
695
 
320 leod 696
  if [ $FORCE = 0 ] ; then
697
    if ask "Proceed?"
698
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
699
      else exit 0
700
    fi
701
  fi
702
 
710 leod 703
  #date +%F" "%H:%M:%S
320 leod 704
 
710 leod 705
  info "Deleting ${EXTRACTDIR} ..."
320 leod 706
  rm -rf ${EXTRACTDIR}
707
 
710 leod 708
  info "Copying  directory tree ..."
320 leod 709
  copy_folders
710
 
643 leod 711
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 712
    [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ] ; then
320 leod 713
 
710 leod 714
    info "DukePlus<>Polymost HRP compatibility patch ..."
412 leod 715
    dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
716
 
710 leod 717
    info "Attrition<>Polymost HRP compatibility patch ..."
412 leod 718
    attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
320 leod 719
  fi
720
 
660 leod 721
 
661 leod 722
  if [ "${HRPTYPE}" = "polymost" ]||[ "${HRPTYPE}" = "polymost_override" ]; then
723
    # Some people prefer unusual setups ...
724
    zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip \
725
    maphacks/3drealms/*.mhk
726
  fi
727
 
660 leod 728
  if [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ]; then
710 leod 729
    info "Copying  maphacks for Megaton ..."
660 leod 730
    copy_polymost_mhk
731
  fi
732
 
710 leod 733
  info "Extract  commented items - $EXTRACT_COMMENTED_FILES"
734
  info "Parsing  file hierarchy :"
735
 
645 leod 736
  if [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "full" ] ; then
737
    parse_defs duke3d_hrp_megaton.def
738
  fi
320 leod 739
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
740
    parse_defs duke3d_hrp_polymost.def
741
  fi
645 leod 742
  if [ "${HRPTYPE}" = "polymer" ]  || [ "${HRPTYPE}" = "full" ] ; then
320 leod 743
    parse_defs duke3d_hrp.def
744
  fi
710 leod 745
  #if [ "${HRPTYPE}" = "voxels" ]   || [ "${HRPTYPE}" = "full" ] ; then
746
  if [ "${HRPTYPE}" = "voxels" ] ; then
747
    parse_defs duke3d_voxels.def
330 leod 748
  fi
749
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
333 leod 750
    parse_defs highres/sw_hrp.def
330 leod 751
  fi
752
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
333 leod 753
    parse_defs lowres/sw_lrp.def
330 leod 754
  fi
708 leod 755
  if [ "${HRPTYPE}" = "maphacks" ] ; then
756
    parse_defs maphacks/mhk-extract.def
757
  fi
710 leod 758
  if [ "${HRPTYPE}" = "${DEF_TOP}" ] ; then
331 leod 759
    parse_defs "${DEF_TOP}"
760
  fi
710 leod 761
  if [ "${HRPTYPE}" = "${CON_TOP}" ] ; then
762
    parse_cons "${CON_TOP}"
763
    if [ -f        "${EXTRACTDIR}/DEF_TOP.tmp" ] ; then
764
      DEF_TOP=`cat "${EXTRACTDIR}/DEF_TOP.tmp"`
765
      rm           "${EXTRACTDIR}/DEF_TOP.tmp"
766
      if [ -f      "${DEF_TOP}" ] ; then
767
        cp -p      "${DEF_TOP}" "${EXTRACTDIR}/${DEF_TOP}"
768
        parse_defs "${DEF_TOP}"
769
      else
770
        warning "${DEF_TOP} is missing!"
771
      fi
772
    fi
773
  fi
774
  if [ "${HRPTYPE}" = "${GRP_TOP}" ] ; then
775
    GRP="${GRP_TOP}"
776
    #parse_grp "${GRP}"
777
    if hash kextract 2>/dev/null; then
778
      #echo "kextract ${GRP} : "
779
      #kextract "${GRP}" | wc -l
780
      #kextract "${GRP}" > "${EXTRACTDIR}/${GRP}.lst"
781
      mkdir    "${EXTRACTDIR}/${GRP}" || exit_on_error\
782
        "Could not create ${EXTRACTDIR}/${GRP}"
783
      cd       "${EXTRACTDIR}/${GRP}"
784
      kextract "${WORKDIR}/${GRP}" "GAME.CON"  > /dev/null
785
      kextract "${WORKDIR}/${GRP}" "EDUKE.CON" > /dev/null
786
      cd "${WORKDIR}"
787
      if [ -f    "${EXTRACTDIR}/${GRP}/EDUKE.CON" ] ; then
788
        CON_FILE="EDUKE.CON"
789
        rm -f    "${EXTRACTDIR}/${GRP}/GAME.CON"
790
      elif [ -f  "${EXTRACTDIR}/${GRP}/GAME.CON" ] ; then
791
        CON_FILE="GAME.CON"
792
      else
793
        exit_on_error "No EDUKE.CON or GAME.CON in ${GRP}!"
794
      fi
795
      parse_cons "${CON_FILE}"
320 leod 796
 
710 leod 797
    else
798
      exit_on_error "No 'kextract' executable found."
799
    fi
800
  fi
801
  if [ "${HRPTYPE}" = "auto" ] ; then
802
 
803
    if [ -f "duke3d.grp" ] ; then GRP="duke3d.grp" ; fi
804
    if [ -f "DUKE3D.GRP" ] ; then GRP="DUKE3D.GRP" ; fi
805
    if [ ${GRP} ] ; then
806
      info "Auto mode found ${GRP}"
807
      if hash kextract 2>/dev/null; then
808
        mkdir "${EXTRACTDIR}/${GRP}"
809
      else
810
        info "No 'kextract' executable found."
811
        GRP=""
812
      fi
813
    fi
814
 
815
    if [     -f "EDUKE.CON" ] || [ -f "GAME.CON" ] ; then
816
      if [   -f "EDUKE.CON" ] ; then
817
        CON_TOP="EDUKE.CON"
818
      else
819
        CON_TOP="GAME.CON"
820
      fi
821
      info "Auto mode found ${CON_TOP}"
822
      parse_cons "${CON_TOP}"
823
      if [ -f        "${EXTRACTDIR}/DEF_TOP.tmp" ] ; then
824
        DEF_TOP=`cat "${EXTRACTDIR}/DEF_TOP.tmp"`
825
        rm           "${EXTRACTDIR}/DEF_TOP.tmp"
826
        if [ -f      "${DEF_TOP}" ] ; then
827
          cp -p      "${DEF_TOP}" "${EXTRACTDIR}/${DEF_TOP}"
828
          parse_defs "${DEF_TOP}"
829
        else
830
          warning "${DEF_TOP} is missing!"
831
        fi
832
      elif [ -f "duke3d.def" ] ; then
833
        DEF_TOP="duke3d.def"
834
        info "Auto mode found ${DEF_TOP}"
835
        parse_defs "${DEF_TOP}"
836
      fi
837
    elif [ -f "duke3d.def" ] ; then
838
      DEF_TOP="duke3d.def"
839
      info "Auto mode found ${DEF_TOP}"
840
      parse_defs "${DEF_TOP}"
841
    else
842
      exit_on_error "Please report to LeoD"
843
    fi
844
  fi
845
 
846
  info "Copying  'known' files ..."
656 leod 847
  copy_known_files
848
 
710 leod 849
  info "Deleting empty directories in ${EXTRACTDIR}/ ..."
320 leod 850
  delete_empty_folders
851
 
710 leod 852
  #date +%F" "%H:%M:%S
320 leod 853
 
710 leod 854
  #echo "Command line example for creating a ZIP package:"
855
  #echo "sh -c \"cd ${EXTRACTDIR}; zip -9rqn .jpg:.png:.zip ${EXTRACTDIR}.zip\
856
  #highpal highres maphacks *.def *.txt\""
320 leod 857
} # main()
858
 
859
 
860
 
861
PRGPATH=$0
862
HRPTYPE=$1
863
if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
325 leod 864
if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
865
  VERSION="$3"
710 leod 866
  info "${VERSION}" > VERSION
325 leod 867
fi
320 leod 868
HRPROOT=.
330 leod 869
WORKDIR=`pwd`
320 leod 870
 
710 leod 871
cd              "${HRPROOT}"
872
echo  "PWD     : ${WORKDIR}"
873
echo  "HRPROOT : ${HRPROOT}"
320 leod 874
 
875
case "$HRPTYPE" in
708 leod 876
  polymer|polymost_override|polymost|megaton_override|megaton|maphacks)
320 leod 877
    main $HRPTYPE
878
    ;;
879
  full)
639 leod 880
    if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Packs)?"
320 leod 881
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
882
      else exit 0
883
    fi ; fi
884
    ${PRGPATH} polymost_override y
708 leod 885
    ${PRGPATH} megaton_override  y
320 leod 886
    main $HRPTYPE
887
    ;;
888
  both)
889
    if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
890
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
891
      else exit 0
892
    fi ; fi
893
    ${PRGPATH} polymer  y
894
    ${PRGPATH} polymost y
895
    ;;
639 leod 896
  ovr)
897
    ${PRGPATH} polymost_override y
708 leod 898
    ${PRGPATH} megaton_override  y
639 leod 899
    ;;
320 leod 900
  all)
901
    if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
902
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
903
      else exit 0
904
    fi ; fi
708 leod 905
    ${PRGPATH} both     y
906
    ${PRGPATH} megaton  y
907
    ${PRGPATH} maphacks y
908
    ${PRGPATH} full     y
320 leod 909
    ;;
710 leod 910
  voxels)
330 leod 911
    SET_VERSION=NO
912
    main $HRPTYPE
913
    ;;
914
  sw_highres|sw_lowres)
915
    SET_VERSION=NO
916
    main $HRPTYPE
917
    ;;
918
  sw_both)
919
    if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
920
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
921
      else exit 0
922
    fi ; fi
923
    ${PRGPATH} sw_lowres  y
924
    ${PRGPATH} sw_highres y
925
    ;;
710 leod 926
  auto)
927
    SET_VERSION=NO
928
    EXTRACT_COMMENTED_FILES=NO
929
    if [ -f "EDUKE.CON" ] || [ -f "GAME.CON" ] || [ -f "duke3d.def" ] ; then
930
      main $HRPTYPE
931
    else
932
      exit_on_error "Auto mode found no suitable toplevel file (EDUKE.CON|GAME.CON|duke3d.def)."
933
    fi
934
    ;;
320 leod 935
  unused)
710 leod 936
    exit_on_error "Option \"$1\" not yet implemented."
320 leod 937
    ;;
938
  debug)
710 leod 939
    exit_on_error "Nothing to debug."
320 leod 940
    ;;
941
  *)
710 leod 942
    if [ -f "${HRPTYPE}" ] ; then
331 leod 943
      SET_VERSION=NO
944
      EXTRACT_COMMENTED_FILES=NO
710 leod 945
      #EXTRACT_COMMENTED_FILES=YES
946
      if [      "${HRPTYPE##*.}" = "def" ] ; then
947
        DEF_TOP="${HRPTYPE}"
948
      elif [    "${HRPTYPE##*.}" = "CON" ] || [ "${HRPTYPE##*.}" = "con" ]; then
949
        CON_TOP="${HRPTYPE}"
950
      elif [    "${HRPTYPE##*.}" = "GRP" ] || [ "${HRPTYPE##*.}" = "grp" ]; then
951
        GRP_TOP="${HRPTYPE}"
952
      else
953
        exit_on_error "Bad file type: ${HRPTYPE##*.}."
954
      fi
331 leod 955
      main $HRPTYPE
956
    else
710 leod 957
      echo "Usage   : ${0} {auto|TOP_CON_FILE|TOP_DEF_FILE|GRP_FILE|HRPTYPE [v VERSION]}"
639 leod 958
      echo "HRPTYPEs: {full|ovr|all}"
959
      echo "HRPTYPEs: {polymer|polymost_override|polymost|both}"
960
      echo "HRPTYPEs: {megaton_override|megaton}"
710 leod 961
      echo "HRPTYPEs: {maphacks|voxels}"
331 leod 962
      echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
963
      exit 1
964
    fi
320 leod 965
    ;;
966
esac
967
 
968
exit 0