Subversion Repositories duke3d_hrp

Rev

Rev 714 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
656 leod 1
#!/bin/bash
320 leod 2
 
715 leod 3
# Duke Nukem 3D CON/DEF/HRP File Extractor  v0.9.3  2020-03-21
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/ \
715 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/ \
715 leod 96
            > "${TARGET_FILE}"
657 leod 97
        else
98
          cat "${VER_FILE}" | sed -r --posix \
99
            s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
715 leod 100
            > "${TARGET_FILE}"
657 leod 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/ \
715 leod 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}"
711 leod 239
    cp -pv dukegdx.def               "${EXTRACTDIR}"
240
    cp -pv voxels/pickups_gdx.def    "${EXTRACTDIR}/voxels/"
714 leod 241
    #cp -pv voxels/monsters.def       "${EXTRACTDIR}/voxels/"
242
    #cp -pv voxels/monsters/*.kvx     "${EXTRACTDIR}/voxels/monsters/"
243
    cp -pv voxels/hrp_undefines.def  "${EXTRACTDIR}/voxels/"
711 leod 244
    cp -pv eduke.con                 "${EXTRACTDIR}"
245
    if [ -d  scripts/ ] ; then
246
      cp -pv scripts/*.con           "${EXTRACTDIR}/scripts/"
247
    fi
248
    ### LeoD ###
708 leod 249
    if [ -f  EDUKE.CON ] ; then
250
      cp -pv EDUKE.CON               "${EXTRACTDIR}"
251
    fi
711 leod 252
    if [ -d   voxels/scripts/ ] ; then
714 leod 253
      #cp -pv voxels/scripts/faucet2.con    "${EXTRACTDIR}/voxels/scripts/"
711 leod 254
      #cp -pv voxels/scripts/freezeammo.con "${EXTRACTDIR}/voxels/scripts/"
255
      #cp -pv voxels/scripts/holoduke.con   "${EXTRACTDIR}/voxels/scripts/"
256
      #cp -pv voxels/scripts/pigtank.con    "${EXTRACTDIR}/voxels/scripts/"
257
      #cp -pv voxels/scripts/rotation.con   "${EXTRACTDIR}/voxels/scripts/"
258
      cp  -pv voxels/scripts/*.con          "${EXTRACTDIR}/voxels/scripts/"
259
    fi
330 leod 260
  fi
261
 
262
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
263
    cp -pv sw.def                   "${EXTRACTDIR}"
708 leod 264
    cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres/"
330 leod 265
    cp -pv HRP.bat                  "${EXTRACTDIR}"
266
    cp -pv HRP_Readme.txt           "${EXTRACTDIR}"
267
    cp -pv HRP_Changes.txt          "${EXTRACTDIR}"
710 leod 268
    info "Copying  skyboxes ..."
330 leod 269
    tar_copy_dir "highres/skyboxes" "${EXTRACTDIR}/highres/skyboxes"
270
    cd "${WORKDIR}"
271
  fi
272
 
273
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
710 leod 274
    info "Creating sw.def for lowres HRP ..."
384 leod 275
    echo "include lowres/sw_lrp.def" > "${EXTRACTDIR}/sw.def"
708 leod 276
    cp -pv lowres/sw_lrp.def           "${EXTRACTDIR}/lowres/"
384 leod 277
    cp -pv LRP.bat                     "${EXTRACTDIR}"
278
    cp -pv LRP_Readme.txt              "${EXTRACTDIR}"
279
    cp -pv LRP_Changes.txt             "${EXTRACTDIR}"
710 leod 280
    info "Copying  skyboxes ..."
384 leod 281
    tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
330 leod 282
    cd "${WORKDIR}"
283
  fi
284
 
710 leod 285
  if [ "${HRPTYPE}" = "auto" ] ; then
286
    for txtfile in *.txt; do
287
      cp -pv "$txtfile" "${EXTRACTDIR}"
288
    done
331 leod 289
  fi
290
 
320 leod 291
} # copy_known_files()
292
 
293
 
710 leod 294
copy_polymost_mhk() {
708 leod 295
  cp -p maphacks/3drealms/E?L*_polymost.mhk "${EXTRACTDIR}"
296
  cp -p maphacks/dukedc/DUKEDC*-megaton.mhk "${EXTRACTDIR}"
656 leod 297
  rm -f "${EXTRACTDIR}"/*_13d_*.mhk
710 leod 298
  rm -f "${EXTRACTDIR}"/*_worldtour_*.mhk
656 leod 299
  # bashism:
662 leod 300
  for i in "${EXTRACTDIR}"/*_polymost.mhk ; do mv "$i" "${i/_polymost}" ; done
301
  for i in "${EXTRACTDIR}"/*-megaton.mhk  ; do mv "$i" "${i/-megaton}"  ; done
656 leod 302
} # copy_polymost_mhk()
320 leod 303
 
304
 
412 leod 305
# I really don't know yet if this will become necessary, or if it does make
324 leod 306
# sense at all, but at least the files involved are listed.
412 leod 307
dukeplus_polymost_hrp_compatibility()
320 leod 308
{
324 leod 309
  # dukeplus.def expects some files to be present in the HRP
310
  #
311
  # model "highres/sprites/characters/1405_duke.md3" { // all OK, no action required
312
  #    skin { pal 0 surface 0 file "highres/sprites/pickups/0057_jetpack.png" }
313
  #    skin { pal 0 surface 1 file "highres/sprites/characters/1405_duke.png" }
314
  #    skin { pal 10 surface 1 file "highres/sprites/characters/1405_duke_10.png" }
315
  #    skin { pal 11 surface 1 file "highres/sprites/characters/1405_duke_11.png" }
316
  #    skin { pal 12 surface 1 file "highres/sprites/characters/1405_duke_12.png" }
317
  #    skin { pal 13 surface 1 file "highres/sprites/characters/1405_duke_13.png" }
318
  #    skin { pal 14 surface 1 file "highres/sprites/characters/1405_duke_14.png" }
319
  #    skin { pal 15 surface 1 file "highres/sprites/characters/1405_duke_15.png" }
320
  #    skin { pal 16 surface 1 file "highres/sprites/characters/1405_duke_16.png" }
321
  #    skin { pal 21 surface 1 file "highres/sprites/characters/1405_duke_21.png" }
322
  #    skin { pal 23 surface 1 file "highres/sprites/characters/1405_duke_23.png" }
323
  #    skin { pal 0 surface 2 file "highres/sprites/pickups/0023_rpg.png" }
324
  #
325
  # model "highres/sprites/firstperson/2510_devastator.md3" { // since Imperium, not Eternity
326
  #    skin { pal 0 file "highres/sprites/firstperson/2510_devastator.png" specfactor 0.5 specpower 35 }
327
  #    specular { file "highres/sprites/firstperson/2510_devastator_s.png" }
328
  #    glow { file "highres/sprites/firstperson/2510_devastator_g.png" }
329
  #
330
  # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295     
331
  #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
332
  #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
333
  # model "highres/sprites/firstperson/2530_clip.md3" {                  // most/mer : diff MD3, same skin
334
  #    skin { pal 0 file "highres/sprites/pickups/0040_pistolammo.jpg" }
335
  # model "highres/sprites/firstperson/2532_cliphand.md3" {  // most/mer : same MD3 + same skin til r295
336
  #    skin { pal 0 file "highres/sprites/firstperson/2532_cliphand.png" } // til r295, then duke_hand_*
337
  #
320 leod 338
 
324 leod 339
  SPR="highres/sprites"
340
  SPRE="${EXTRACTDIR}/highres/sprites"
341
  PATCHTYPE=$1
320 leod 342
 
324 leod 343
  case "$PATCHTYPE" in
344
    polymer)
710 leod 345
      echo "          (Using \"Polymer approach\")"
708 leod 346
      cp -pi $SPR/firstperson/2510_devastator.md3            "$SPRE/firstperson/"
347
      cp -pi $SPR/firstperson/2510_devastator.png            "$SPRE/firstperson/"
348
      cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson/"
349
      cp -pi $SPR/firstperson/2510_devastator_g.png          "$SPRE/firstperson/"
350
      cp -pi $SPR/firstperson/2524_pistol.md3                "$SPRE/firstperson/"
351
      cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
352
      cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
353
      cp -pi $SPR/firstperson/2530_clip.md3                  "$SPRE/firstperson/"
354
      cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups/"
355
      cp -pi $SPR/firstperson/2532_cliphand.md3              "$SPRE/firstperson/"
356
      cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson/"
357
      cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson/"
358
      cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson/"
359
      cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson/"
324 leod 360
      ;;
361
    polymost)
710 leod 362
      echo "          (Using \"Polymost approach\")"
708 leod 363
      #cp -pi $SPR/firstperson_polymost/2510_devastator.md3   "$SPRE/firstperson/"
364
      #cp -pi $SPR/firstperson_polymost/2510_devastator.png   "$SPRE/firstperson/"
365
      ##cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson/"
366
      #cp -pi $SPR/firstperson_polymost/2510_devastator_g.png "$SPRE/firstperson/"
367
      cp -pi $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
368
      #cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
369
      #cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
370
      #cp -pi $SPR/firstperson_polymost/2530_clip.md3         "$SPRE/firstperson/"
371
      #cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups/"
372
      #cp -pi $SPR/firstperson_polymost/2532_cliphand.md3     "$SPRE/firstperson/"
373
      #cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson/"
374
      #cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson/"
375
      #cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson/"
376
      #cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson/"
324 leod 377
      ;;
378
    mixed)
710 leod 379
      echo "          (Using \"Mixed approach\")"
380
      echo "          Not applied / Not yet implemented"
324 leod 381
      ;;
382
    none)
710 leod 383
      info "  Not applied"
407 leod 384
      #echo "  # Not yet implemented"
324 leod 385
      ;;
386
    *)
710 leod 387
      warning "  Bad parameter"
324 leod 388
      ;;
389
  esac
390
 
412 leod 391
} # dukeplus_polymost_hrp_compatibility()
324 leod 392
 
393
 
710 leod 394
attrition_polymost_hrp_compatibility() {
412 leod 395
  # attr_hrp.def expects some files to be present in the HRP
396
  #
397
  # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295     
398
  #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
399
  #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
400
 
401
  SPR="highres/sprites"
402
  SPRE="${EXTRACTDIR}/highres/sprites"
403
  PATCHTYPE=$1
404
 
405
  case "$PATCHTYPE" in
406
    polymer)
710 leod 407
      echo "          (Using \"Polymer approach\")"
412 leod 408
      ;;
409
    polymost)
710 leod 410
      echo "          (Using \"Polymost approach\")"
708 leod 411
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson/"
412
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson/"
413
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson/"
414
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
415
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
416
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
412 leod 417
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
418
      ;;
419
    mixed)
710 leod 420
      echo "          (Using \"Mixed approach\")"
708 leod 421
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
422
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
423
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
424
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
425
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
426
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
412 leod 427
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
708 leod 428
      cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson/"
412 leod 429
      cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
708 leod 430
      cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson/"
431
      cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson/"
432
      cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/"
433
      cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson/"
434
      cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson/"
435
      cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson/"
412 leod 436
      cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
437
      ;;
438
    none)
710 leod 439
      info "  Not applied"
412 leod 440
      #echo "  # Not yet implemented"
441
      ;;
442
    *)
710 leod 443
      warning "  Bad parameter"
412 leod 444
      ;;
445
  esac
446
 
447
} # attrition_polymost_hrp_compatibility()
448
 
449
 
710 leod 450
extract_file() {
451
  local FILE="$1"
452
  if [ -f "${FILE}" ] ; then
453
    cp -p "${FILE}" "${EXTRACTDIR}/${FILE}"
454
  elif [ ${GRP} ] ; then
455
    cd "${EXTRACTDIR}/${GRP}"
456
      kextract "${WORKDIR}/${GRP}" "${FILE}" > /dev/null
457
    cd "${WORKDIR}"
458
    if [ ! -f "${EXTRACTDIR}/${GRP}/${FILE}" ] ; then
459
      warning "${FILE} is missing!"
460
    #else
461
    #  echo -e "${FILE} -> \e[0;33m${GRP}/\e[0m${FILE^^}"
462
    fi
463
  else
464
    warning "${FILE} is missing!"
465
  fi
466
}
467
 
468
 
469
parse_defs() {
470
  local DEF_FILE="$1"
471
  extract_file "${DEF_FILE}"
472
  if [ -f "${DEF_FILE}" ] ; then
473
    echo  "${DEF_FILE}"
474
  elif [  -f "${EXTRACTDIR}/${GRP}/${DEF_FILE}" ] ; then
475
    echo   -e "${DEF_FILE} -> \e[0;33m${GRP}/\e[0m${DEF_FILE^^}"
476
    DEF_FILE="${EXTRACTDIR}/${GRP}/${DEF_FILE^^}"
477
  else
478
    return
479
  fi
480
 
324 leod 481
  BLOCK_COMMENT="OFF"
320 leod 482
 
710 leod 483
  cat "${DEF_FILE}" | while read DEF_LINE; do
320 leod 484
 
710 leod 485
    #echo "DEF_LINE1: ${DEF_LINE}"
486
    #DEF_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
375 leod 487
    ## Old style added (except "defineskybox"):
710 leod 488
    #DEF_TERM=`echo "${DEF_LINE}" | grep -owE "include|definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down|\\/\\*|\\*\\/"`
333 leod 489
    #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
710 leod 490
    #echo "DEF_TERM1: ${DEF_TERM}"
320 leod 491
 
710 leod 492
    local TOKEN_LIST='\b(include\b'
493
    local TOKEN_LIST='^(include)'
494
    local TOKEN_LIST='(^include|file|^definetexture|^definemodel|^definemodelskin|^mhkfile|^model|^voxel|^front|^right|^back|^left|^top|^bottom|^down|\/\*|\*\/)'
324 leod 495
 
710 leod 496
    if [[ ${DEF_LINE} =~ ${TOKEN_LIST} ]] ; then
497
      DEF_TERM="${BASH_REMATCH}"
498
    else
499
      DEF_TERM=""
500
    fi
501
 
502
    if [ "${DEF_TERM}" ] && [ "$EXTRACT_COMMENTED_FILES" = "NO" ] ; then
503
      #COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
504
      COMMENT_TERM="${DEF_TERM}"
324 leod 505
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
506
 
710 leod 507
      if [ "$BLOCK_COMMENT" = "ON" ] ; then DEF_TERM="" ; fi
324 leod 508
 
509
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
510
 
710 leod 511
      if [ $DEF_TERM ] ; then
512
        if [[ ${DEF_LINE} =~ //.*$DEF_TERM ]] ; then
513
          DEF_TERM=""
324 leod 514
        fi
515
      fi
516
    fi
517
 
710 leod 518
    if [ "${DEF_TERM}" ] ; then case "$DEF_TERM" in
519
      include)
520
        local SUB_DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
521
        if [          ${SUB_DEF_FILE} ] ; then
522
          parse_defs "${SUB_DEF_FILE}"
523
        fi
320 leod 524
        ;;
710 leod 525
      file)
526
        if [[ ${DEF_LINE} =~ \ file\  ]] ; then
527
          HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
528
        elif [[ ! ${DEF_LINE} =~ mapfile ]] ; then
529
          warning "Bad 'file' statement: ${DEF_LINE}"
530
        fi
320 leod 531
        ;;
710 leod 532
      mhkfile|model|voxel)
533
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
534
        ;;
333 leod 535
      front|right|back|left|top|bottom|down)
710 leod 536
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
320 leod 537
        ;;
375 leod 538
      ## Old Style
539
      definemodel)
710 leod 540
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
375 leod 541
        ;;
542
      definemodelskin)
710 leod 543
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${DEF_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
375 leod 544
        ;;
545
      definetexture)
546
        # Won't work atm if filename in quotes (too lazy)
547
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
548
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
549
        #echo "DEF_LINE : ${DEF_LINE}"
550
        #echo "HRP_FILE : ${HRP_FILE}"
551
        ;;
320 leod 552
      *)
553
        HRP_FILE=""
554
        ;;
710 leod 555
    esac ; fi
320 leod 556
 
710 leod 557
    if [ "${HRP_FILE}" ] ; then
558
      extract_file "${HRP_FILE}"
714 leod 559
      HRP_FILE=""
320 leod 560
    fi
561
 
562
  done
563
} # parse_defs()
564
 
565
 
710 leod 566
parse_cons() {
567
  local CON_FILE="$1"
568
  extract_file "${CON_FILE}"
569
  if [ -f "${CON_FILE}" ] ; then
570
    echo  "${CON_FILE}"
571
  elif [  -f "${EXTRACTDIR}/${GRP}/${CON_FILE}" ] ; then
572
    echo   -e "${CON_FILE} -> \e[0;33m${GRP}/\e[0m${CON_FILE^^}"
573
    CON_FILE="${EXTRACTDIR}/${GRP}/${CON_FILE^^}"
574
  else
575
    return
576
  fi
577
 
578
  MUSIC_FLAG=""
579
  MUSIC_POS=""
580
 
581
  BLOCK_COMMENT="OFF"
582
 
583
  cat "${CON_FILE}" | while read CON_LINE; do
584
 
585
    #echo "CON_LINE : ${CON_LINE}"
586
    #CON_TERM=`echo "${CON_LINE}" | grep -owE "include|setdefname|definelevelname|definesound|music|\\/\\*|\\*\\/"`
587
    #echo "CON_TERM : ${CON_TERM}"
588
 
589
    #if [[ ${CON_LINE} =~ include|setdefname|definelevelname|definesound|music|\/\*|\*\/ ]] ; then
590
    local TOKEN_LIST='\b(include\b'
591
    local TOKEN_LIST='^(include)'
592
    local TOKEN_LIST='(include|setdefname|definelevelname|definesound|music|\/\*|\*\/)'
593
    if [[ ${CON_LINE} =~ ${TOKEN_LIST} ]] ; then
594
      #echo "Rematch  : ${BASH_REMATCH}"
595
      CON_TERM="${BASH_REMATCH}"
596
    else
597
      CON_TERM=""
598
    fi
599
 
600
    if [ ${MUSIC_FLAG} ] && [ "${CON_TERM}" = "" ] ; then
601
      MUSIC_POS="1"
602
	  MUSIC_FLAG=""
603
    else
604
      MUSIC_POS=""
605
    fi
606
 
607
    if [ "${CON_TERM}" ] && [ "$EXTRACT_COMMENTED_FILES" = "NO" ] ; then
608
      COMMENT_TERM="${CON_TERM}"
609
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON"  ; fi
610
 
611
      if [ "$BLOCK_COMMENT" = "ON" ] ; then CON_TERM=""         ; fi
612
 
613
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
614
 
615
      if [ $CON_TERM ] ; then
616
        if [[ ${CON_LINE} =~ //.*$CON_TERM ]] ; then
617
          CON_TERM=""
618
        fi
619
      fi
620
    fi
621
 
622
    if [ "${CON_TERM}" ] ; then case "$CON_TERM" in
623
      include)
624
        local SUB_CON_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $2 }' | sed 's/\r//'`
625
        if [          ${SUB_CON_FILE} ] ; then
626
          parse_cons "${SUB_CON_FILE}"
627
        fi
628
        ;;
629
      setdefname)
630
        local     DEF_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $2 }' | sed 's/\r//'`
631
        if [       ${DEF_FILE} ] ; then
632
          DEF_TOP="${DEF_FILE}"
633
          info "Toplevel DEF set to ${DEF_TOP}"
634
          echo "${DEF_TOP}"  >   "${EXTRACTDIR}/DEF_TOP.tmp"
635
        fi
636
        ;;
637
      definesound)
638
        SOUND_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $3 }' | sed 's/\r//'`
639
        if [            ${SOUND_FILE} ] ; then
640
          extract_file "${SOUND_FILE}"
641
        fi
642
        ;;
643
      definelevelname)
644
          MAP_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | awk '{ print $4 }' | sed 's/\r//'`
645
        if [            ${MAP_FILE} ] ; then
646
          extract_file "${MAP_FILE}"
647
        fi
648
        ;;
649
      music)
650
        MUSIC_POS=3
651
        while [ ${MUSIC_POS} ] ; do
652
          MUSIC_FILE=`echo "${CON_LINE}" | grep -wE "$CON_TERM" | 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
710 leod 660
        done
661
        ;;
662
      *)
663
        ;;
664
    esac ; fi
665
 
666
    if [ ${MUSIC_POS} ] ; then
667
      while [ ${MUSIC_POS} ] ; do
668
        MUSIC_FILE=`echo "${CON_LINE}" | grep -wE ".*\\.mid" | awk "{ print \\$$MUSIC_POS }" | sed 's/\r//'`
669
        if [            ${MUSIC_FILE} ] ; then
670
          extract_file "${MUSIC_FILE}"
671
          MUSIC_POS=$(($MUSIC_POS + 1))
672
          MUSIC_FLAG=true
673
        else
674
          MUSIC_POS=""
320 leod 675
        fi
676
      done
677
    fi
710 leod 678
 
679
  done
680
} # parse_cons()
681
 
682
 
683
delete_empty_folders() {
711 leod 684
  if [  -d "${EXTRACTDIR}" ] ; then
685
    rm -rf  ${EXTRACTDIR}/.svn
686
    DIRLIST=${EXTRACTDIR}/EXTRACT_DIRECTORIES.lst
687
    du     "${EXTRACTDIR}" > ${DIRLIST}
710 leod 688
    cat ${DIRLIST} | while read DIR ; do
689
      if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
690
        EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
691
        if [ -d ${EMPTYDIR} ] ; then
692
          rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
693
        fi
694
      fi
695
    done
696
    rm ${DIRLIST}
697
  else
698
    warning "No ${EXTRACTDIR}."
699
  fi
320 leod 700
} # delete_empty_folders()
701
 
702
 
710 leod 703
main() {
320 leod 704
 
710 leod 705
  EXTRACTDIR=../${HRPTYPE}_extract
706
  [[ ${HRPTYPE} =~ (.*)(/)(.*) ]] # greedy first .* required
707
  if [ ${BASH_REMATCH[3]} ] ; then
708
    EXTRACTDIR=../${BASH_REMATCH[3]}_extract
709
  fi
710
  echo "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
711
 
320 leod 712
  if [ $FORCE = 0 ] ; then
713
    if ask "Proceed?"
714
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
715
      else exit 0
716
    fi
717
  fi
718
 
710 leod 719
  #date +%F" "%H:%M:%S
320 leod 720
 
710 leod 721
  info "Deleting ${EXTRACTDIR} ..."
320 leod 722
  rm -rf ${EXTRACTDIR}
723
 
710 leod 724
  info "Copying  directory tree ..."
320 leod 725
  copy_folders
726
 
643 leod 727
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 728
    [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ] ; then
320 leod 729
 
710 leod 730
    info "DukePlus<>Polymost HRP compatibility patch ..."
412 leod 731
    dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
732
 
710 leod 733
    info "Attrition<>Polymost HRP compatibility patch ..."
412 leod 734
    attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
320 leod 735
  fi
736
 
660 leod 737
 
661 leod 738
  if [ "${HRPTYPE}" = "polymost" ]||[ "${HRPTYPE}" = "polymost_override" ]; then
739
    # Some people prefer unusual setups ... 
740
    zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip \
741
    maphacks/3drealms/*.mhk
742
  fi
743
 
660 leod 744
  if [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ]; then
710 leod 745
    info "Copying  maphacks for Megaton ..."
660 leod 746
    copy_polymost_mhk
747
  fi
748
 
710 leod 749
  info "Extract  commented items - $EXTRACT_COMMENTED_FILES"
750
  info "Parsing  file hierarchy :"
751
 
645 leod 752
  if [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "full" ] ; then
753
    parse_defs duke3d_hrp_megaton.def
754
  fi
320 leod 755
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
756
    parse_defs duke3d_hrp_polymost.def
757
  fi
645 leod 758
  if [ "${HRPTYPE}" = "polymer" ]  || [ "${HRPTYPE}" = "full" ] ; then
320 leod 759
    parse_defs duke3d_hrp.def
760
  fi
710 leod 761
  #if [ "${HRPTYPE}" = "voxels" ]   || [ "${HRPTYPE}" = "full" ] ; then
762
  if [ "${HRPTYPE}" = "voxels" ] ; then
763
    parse_defs duke3d_voxels.def
330 leod 764
  fi
765
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
333 leod 766
    parse_defs highres/sw_hrp.def
330 leod 767
  fi
768
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
333 leod 769
    parse_defs lowres/sw_lrp.def
330 leod 770
  fi
708 leod 771
  if [ "${HRPTYPE}" = "maphacks" ] ; then
772
    parse_defs maphacks/mhk-extract.def
773
  fi
710 leod 774
  if [ "${HRPTYPE}" = "${DEF_TOP}" ] ; then
331 leod 775
    parse_defs "${DEF_TOP}"
776
  fi
710 leod 777
  if [ "${HRPTYPE}" = "${CON_TOP}" ] ; then
778
    parse_cons "${CON_TOP}"
779
    if [ -f        "${EXTRACTDIR}/DEF_TOP.tmp" ] ; then
780
      DEF_TOP=`cat "${EXTRACTDIR}/DEF_TOP.tmp"`
781
      rm           "${EXTRACTDIR}/DEF_TOP.tmp"
782
      if [ -f      "${DEF_TOP}" ] ; then
783
        cp -p      "${DEF_TOP}" "${EXTRACTDIR}/${DEF_TOP}"
784
        parse_defs "${DEF_TOP}"
785
      else
786
        warning "${DEF_TOP} is missing!"
787
      fi
788
    fi
789
  fi
790
  if [ "${HRPTYPE}" = "${GRP_TOP}" ] ; then
791
    GRP="${GRP_TOP}"
792
    #parse_grp "${GRP}"
793
    if hash kextract 2>/dev/null; then
794
      #echo "kextract ${GRP} : "
795
      #kextract "${GRP}" | wc -l
796
      #kextract "${GRP}" > "${EXTRACTDIR}/${GRP}.lst"
797
      mkdir    "${EXTRACTDIR}/${GRP}" || exit_on_error\
798
        "Could not create ${EXTRACTDIR}/${GRP}"
799
      cd       "${EXTRACTDIR}/${GRP}"
800
      kextract "${WORKDIR}/${GRP}" "GAME.CON"  > /dev/null
801
      kextract "${WORKDIR}/${GRP}" "EDUKE.CON" > /dev/null
802
      cd "${WORKDIR}"
803
      if [ -f    "${EXTRACTDIR}/${GRP}/EDUKE.CON" ] ; then
804
        CON_FILE="EDUKE.CON"
805
        rm -f    "${EXTRACTDIR}/${GRP}/GAME.CON"
806
      elif [ -f  "${EXTRACTDIR}/${GRP}/GAME.CON" ] ; then
807
        CON_FILE="GAME.CON"
808
      else
809
        exit_on_error "No EDUKE.CON or GAME.CON in ${GRP}!"
810
      fi
811
      parse_cons "${CON_FILE}"
320 leod 812
 
710 leod 813
    else
814
      exit_on_error "No 'kextract' executable found."
815
    fi
816
  fi
817
  if [ "${HRPTYPE}" = "auto" ] ; then
818
 
819
    if [ -f "duke3d.grp" ] ; then GRP="duke3d.grp" ; fi
820
    if [ -f "DUKE3D.GRP" ] ; then GRP="DUKE3D.GRP" ; fi
821
    if [ ${GRP} ] ; then
822
      info "Auto mode found ${GRP}"
823
      if hash kextract 2>/dev/null; then
824
        mkdir "${EXTRACTDIR}/${GRP}"
825
      else
826
        info "No 'kextract' executable found."
827
        GRP=""
828
      fi
829
    fi
830
 
831
    if [     -f "EDUKE.CON" ] || [ -f "GAME.CON" ] ; then
832
      if [   -f "EDUKE.CON" ] ; then
833
        CON_TOP="EDUKE.CON"
834
      else
835
        CON_TOP="GAME.CON"
836
      fi
837
      info "Auto mode found ${CON_TOP}"
838
      parse_cons "${CON_TOP}"
839
      if [ -f        "${EXTRACTDIR}/DEF_TOP.tmp" ] ; then
840
        DEF_TOP=`cat "${EXTRACTDIR}/DEF_TOP.tmp"`
841
        rm           "${EXTRACTDIR}/DEF_TOP.tmp"
842
        if [ -f      "${DEF_TOP}" ] ; then
843
          cp -p      "${DEF_TOP}" "${EXTRACTDIR}/${DEF_TOP}"
844
          parse_defs "${DEF_TOP}"
845
        else
846
          warning "${DEF_TOP} is missing!"
847
        fi
848
      elif [ -f "duke3d.def" ] ; then
849
        DEF_TOP="duke3d.def"
850
        info "Auto mode found ${DEF_TOP}"
851
        parse_defs "${DEF_TOP}"
714 leod 852
      elif [ -f "dukegdx.def" ] ; then
853
        DEF_TOP="dukegdx.def"
854
        info "Auto mode found ${DEF_TOP}"
855
        parse_defs "${DEF_TOP}"
710 leod 856
      fi
857
    elif [ -f "duke3d.def" ] ; then
858
      DEF_TOP="duke3d.def"
859
      info "Auto mode found ${DEF_TOP}"
860
      parse_defs "${DEF_TOP}"
714 leod 861
    elif [ -f "dukegdx.def" ] ; then
862
      DEF_TOP="dukegdx.def"
863
      info "Auto mode found ${DEF_TOP}"
864
      parse_defs "${DEF_TOP}"
710 leod 865
    else
866
      exit_on_error "Please report to LeoD"
867
    fi
714 leod 868
 
710 leod 869
  fi
870
 
871
  info "Copying  'known' files ..."
656 leod 872
  copy_known_files
873
 
710 leod 874
  info "Deleting empty directories in ${EXTRACTDIR}/ ..."
320 leod 875
  delete_empty_folders
876
 
710 leod 877
  #date +%F" "%H:%M:%S
320 leod 878
 
710 leod 879
  #echo "Command line example for creating a ZIP package:"
714 leod 880
  #echo "sh -c \"cd ${EXTRACTDIR}; zip -9rqn .jpg:.png:.svn:.zip \
881
  #      ${EXTRACTDIR}.zip highpal highres maphacks *.def *.txt\""
320 leod 882
} # main()
883
 
884
 
885
 
886
PRGPATH=$0
887
HRPTYPE=$1
888
if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
325 leod 889
if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
890
  VERSION="$3"
710 leod 891
  info "${VERSION}" > VERSION
325 leod 892
fi
320 leod 893
HRPROOT=.
330 leod 894
WORKDIR=`pwd`
320 leod 895
 
710 leod 896
cd              "${HRPROOT}"
897
echo  "PWD     : ${WORKDIR}"
898
echo  "HRPROOT : ${HRPROOT}"
320 leod 899
 
900
case "$HRPTYPE" in
708 leod 901
  polymer|polymost_override|polymost|megaton_override|megaton|maphacks)
320 leod 902
    main $HRPTYPE
903
    ;;
904
  full)
639 leod 905
    if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Packs)?"
320 leod 906
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
907
      else exit 0
908
    fi ; fi
909
    ${PRGPATH} polymost_override y
708 leod 910
    ${PRGPATH} megaton_override  y
715 leod 911
    FORCE=1
320 leod 912
    main $HRPTYPE
913
    ;;
914
  both)
915
    if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
916
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
917
      else exit 0
918
    fi ; fi
919
    ${PRGPATH} polymer  y
920
    ${PRGPATH} polymost y
921
    ;;
639 leod 922
  ovr)
923
    ${PRGPATH} polymost_override y
708 leod 924
    ${PRGPATH} megaton_override  y
639 leod 925
    ;;
320 leod 926
  all)
927
    if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
928
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
929
      else exit 0
930
    fi ; fi
708 leod 931
    ${PRGPATH} both     y
932
    ${PRGPATH} megaton  y
933
    ${PRGPATH} maphacks y
934
    ${PRGPATH} full     y
320 leod 935
    ;;
710 leod 936
  voxels)
330 leod 937
    SET_VERSION=NO
938
    main $HRPTYPE
939
    ;;
940
  sw_highres|sw_lowres)
941
    SET_VERSION=NO
942
    main $HRPTYPE
943
    ;;
944
  sw_both)
945
    if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
946
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
947
      else exit 0
948
    fi ; fi
949
    ${PRGPATH} sw_lowres  y
950
    ${PRGPATH} sw_highres y
951
    ;;
710 leod 952
  auto)
953
    SET_VERSION=NO
954
    EXTRACT_COMMENTED_FILES=NO
714 leod 955
    if [ -f "EDUKE.CON" ] || [ -f "GAME.CON" ] || [ -f "duke3d.def" ] || [ -f "dukegdx.def" ] ; then
710 leod 956
      main $HRPTYPE
957
    else
714 leod 958
      exit_on_error "Auto mode found no suitable toplevel file (EDUKE.CON|GAME.CON|duke3d.def|dukegdx.def)."
710 leod 959
    fi
960
    ;;
320 leod 961
  unused)
710 leod 962
    exit_on_error "Option \"$1\" not yet implemented."
320 leod 963
    ;;
964
  debug)
710 leod 965
    exit_on_error "Nothing to debug."
320 leod 966
    ;;
967
  *)
710 leod 968
    if [ -f "${HRPTYPE}" ] ; then
331 leod 969
      SET_VERSION=NO
970
      EXTRACT_COMMENTED_FILES=NO
710 leod 971
      #EXTRACT_COMMENTED_FILES=YES
972
      if [      "${HRPTYPE##*.}" = "def" ] ; then
973
        DEF_TOP="${HRPTYPE}"
974
      elif [    "${HRPTYPE##*.}" = "CON" ] || [ "${HRPTYPE##*.}" = "con" ]; then
975
        CON_TOP="${HRPTYPE}"
976
      elif [    "${HRPTYPE##*.}" = "GRP" ] || [ "${HRPTYPE##*.}" = "grp" ]; then
977
        GRP_TOP="${HRPTYPE}"
978
      else
979
        exit_on_error "Bad file type: ${HRPTYPE##*.}."
980
      fi
331 leod 981
      main $HRPTYPE
982
    else
710 leod 983
      echo "Usage   : ${0} {auto|TOP_CON_FILE|TOP_DEF_FILE|GRP_FILE|HRPTYPE [v VERSION]}"
639 leod 984
      echo "HRPTYPEs: {full|ovr|all}"
985
      echo "HRPTYPEs: {polymer|polymost_override|polymost|both}"
986
      echo "HRPTYPEs: {megaton_override|megaton}"
710 leod 987
      echo "HRPTYPEs: {maphacks|voxels}"
331 leod 988
      echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
989
      exit 1
990
    fi
320 leod 991
    ;;
992
esac
993
 
994
exit 0