Subversion Repositories duke3d_hrp

Rev

Rev 675 | Rev 709 | 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
 
708 leod 3
# Duke Nukem 3D High Resolution Pack Extractor  v0.8.0  2019-05-07
320 leod 4
#
5
# Author: LeoD
708 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.
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
661 leod 41
      find "${HRPDIR}" -type d | grep -v ".\svn" > ${DIRLIST}
320 leod 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"
657 leod 59
  if [ ! "${SET_VERSION}" = "YES" ] ; then
60
    cp -pv "${VER_FILE}" "${TARGET_FILE}"
61
  else
62
 
63
    V_DATE=`date +%F`
64
    if [ "${VERSION}" = "" ] ; then
65
      if [ -f VERSION ] ; then
66
        VERSION=`grep -owE "[0-9\\.]*" VERSION`
67
      fi
324 leod 68
    fi
69
 
657 leod 70
    echo "copy_set_version ${VER_FILE} -> ${TARGET_FILE}"
324 leod 71
 
657 leod 72
    case "${VER_FILE}" in
73
      hrp_readme.txt)
325 leod 74
        cat "${VER_FILE}" | sed -r --posix \
657 leod 75
          s/\(Version\ *\)\([0-9\.]*\)\(.*\)\(\\\)\)\(.*\)/\\1${VERSION}\ \(${V_DATE}\)\ \ \\5/ \
325 leod 76
          >> "${TARGET_FILE}"
657 leod 77
        ;;
78
      duke3d_hrp.def)
79
        if [ "${HRPTYPE}" = "polymer" ] ; then
80
          cat "${VER_FILE}" | sed -r --posix \
81
            s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\ Polymer\\3/ \
82
            >> "${TARGET_FILE}"
83
        else
84
          cat "${VER_FILE}" | sed -r --posix \
85
            s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
86
            >> "${TARGET_FILE}"
87
        fi
88
        ;;
89
      duke3d_hrp_polymost.def | \
708 leod 90
      tools/polymost_override/duke3d_hrp_polymost_override.def | \
657 leod 91
      duke3d_hrp_megaton.def | \
708 leod 92
      tools/megaton_override/duke3d_hrp_megaton_override.def )
325 leod 93
        cat "${VER_FILE}" | sed -r --posix \
94
          s/\(Version\ *\)\([0-9\.]*\)\(.*\)/\\1${VERSION}\\3/ \
95
          >> "${TARGET_FILE}"
657 leod 96
        ;;
97
      *)
98
        echo "###ERROR: copy_set_version() - BAD FILE: ${VER_FILE}"
99
        exit 1
100
        ;;
101
    esac
102
  fi
103
} # copy_set_version()
324 leod 104
 
330 leod 105
tar_copy_dir()
106
{
107
  (cd ${1}; tar cf - . ) | (cd ${2}; tar xf -)
108
}
109
 
320 leod 110
copy_known_files()
111
{
657 leod 112
  if [ -f  hrp_readme.txt ] ; then
324 leod 113
    copy_set_version hrp_readme.txt "${EXTRACTDIR}/hrp_readme.txt"
114
  fi
320 leod 115
 
431 leod 116
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 117
     [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "megaton_override" ] ||\
708 leod 118
     [ "${HRPTYPE}" = "maphacks" ] ||\
384 leod 119
     [ "${HRPTYPE}" = "polymer"  ] || [ "${HRPTYPE}" = "full" ] ; then
120
    cp -pv hrp_art_license.txt      "${EXTRACTDIR}"
121
  fi
122
 
708 leod 123
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymer" ] ||\
124
     [ "${HRPTYPE}" = "maphacks" ] || [ "${HRPTYPE}" = "full" ] ; then
125
    cp -pv maphacks/MapHacks.txt    "${EXTRACTDIR}/maphacks/"
126
  fi
127
 
431 leod 128
  if [ "${HRPTYPE}" = "polymost" ] ; then
708 leod 129
    cp -pv           duke3d_hrp_polymost.def "${EXTRACTDIR}"
130
    copy_set_version duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp.def"
131
    cp -pvr tools/polymost_override/dukedc   "${EXTRACTDIR}"
320 leod 132
  fi
133
 
639 leod 134
  if [ "${HRPTYPE}" = "megaton" ] ; then
661 leod 135
    cp -pv           duke3d_hrp_megaton.def "${EXTRACTDIR}"
657 leod 136
    copy_set_version duke3d_hrp_megaton.def "${EXTRACTDIR}/duke3d_hrp.def"
656 leod 137
    cp -pv highres/screen/menu/2492_ver_megaton.png \
138
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
708 leod 139
    cp -pvr tools/megaton_override/dukedc* "${EXTRACTDIR}"
140
    cp -pvr tools/megaton_override/highres "${EXTRACTDIR}"
639 leod 141
  fi
142
 
431 leod 143
  if [ "${HRPTYPE}" = "polymost_override" ] ; then
657 leod 144
    copy_set_version \
708 leod 145
      tools/polymost_override/duke3d_hrp_polymost_override.def \
657 leod 146
      "${EXTRACTDIR}/duke3d_hrp.def"
147
    copy_set_version \
708 leod 148
      tools/polymost_override/duke3d_hrp_polymost_override.def \
657 leod 149
      "${EXTRACTDIR}/duke3d_hrp_polymost.def"
708 leod 150
    cp -pv tools/polymost_override/hrp_polymost_override.txt \
661 leod 151
      "${EXTRACTDIR}"
708 leod 152
    cp -pv tools/polymost_override/2492_ver_polymost_override.png \
661 leod 153
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_polymost.png"
708 leod 154
    cp -pvr tools/polymost_override/dukedc "${EXTRACTDIR}"
431 leod 155
  fi
156
 
639 leod 157
  if [ "${HRPTYPE}" = "megaton_override" ] ; then
657 leod 158
    copy_set_version \
708 leod 159
      tools/megaton_override/duke3d_hrp_megaton_override.def \
657 leod 160
      "${EXTRACTDIR}/duke3d_hrp.def"
161
    copy_set_version \
708 leod 162
      tools/megaton_override/duke3d_hrp_megaton_override.def \
657 leod 163
      "${EXTRACTDIR}/duke3d_hrp_megaton.def"
708 leod 164
    cp -pv tools/megaton_override/hrp_megaton_override.txt \
661 leod 165
      "${EXTRACTDIR}"
708 leod 166
    cp -pv tools/megaton_override/2492_ver_megaton_override.png \
167
      "${EXTRACTDIR}/highres/screen/menu/2492_ver_megaton.png"
168
    cp -pv  tools/megaton_override/*.bat   "${EXTRACTDIR}"
169
    cp -pvr tools/megaton_override/dukedc* "${EXTRACTDIR}"
170
    cp -pvr tools/megaton_override/highres "${EXTRACTDIR}"
657 leod 171
    # Let Megaton Override work on top of Polymost HRP:
708 leod 172
    cp -pv highres/screen_megaton.def          "${EXTRACTDIR}/highres/"
173
    cp -pv highres/screen/menu_megaton.def     "${EXTRACTDIR}/highres/"
174
    cp -pv highres/sprites_megaton.def         "${EXTRACTDIR}/highres/"
175
    cp -pv highres/sprites/effects_megaton.def "${EXTRACTDIR}/highres/sprites/"
639 leod 176
  fi
177
 
178
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "megaton" ] ; then
320 leod 179
    cp -pv duke3d.def "${EXTRACTDIR}"
659 leod 180
    cp -pv highres/screen/menu/2492_polymost.png \
708 leod 181
      "${EXTRACTDIR}/highres/screen/menu/"
320 leod 182
  fi
183
 
184
  if [ "${HRPTYPE}" = "full" ] ; then
657 leod 185
    copy_set_version duke3d_hrp_polymost.def \
186
      "${EXTRACTDIR}/duke3d_hrp_polymost.def"
187
    copy_set_version duke3d_hrp_megaton.def \
188
      "${EXTRACTDIR}/duke3d_hrp_megaton.def"
320 leod 189
  fi
190
 
431 leod 191
  if [ "${HRPTYPE}" = "full" ] ; then
192
    cp -pv highres/screen/menu/2492_ver_polymost.png \
708 leod 193
      "${EXTRACTDIR}/highres/screen/menu/"
320 leod 194
  fi
195
 
196
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
708 leod 197
    cp -pv           duke3d.def     "${EXTRACTDIR}"
657 leod 198
    copy_set_version duke3d_hrp.def "${EXTRACTDIR}/duke3d_hrp.def"
320 leod 199
    #cp -pv highres/screen/menu/2492.png "${EXTRACTDIR}/highres/screen/menu"
200
 
708 leod 201
    #cp -pv highres/common/black.png                          "${EXTRACTDIR}/highres/common/"
202
    #cp -pv highres/screen/fonts/digital/digital_minus.png    "${EXTRACTDIR}/highres/screen/fonts/digital/"
203
    #cp -pv highres/screen/menu/widescreen/*_wide.png         "${EXTRACTDIR}/highres/screen/menu/"
204
    #cp -pv highres/sprites/characters/1357_terminarm.md3     "${EXTRACTDIR}/highres/sprites/characters/"
205
    #cp -pv highres/sprites/firstperson/2510_devastator_n.png "${EXTRACTDIR}/highres/sprites/firstperson/"
206
    #cp -pv highres/sprites/monsters/1960_reconcar_s.png      "${EXTRACTDIR}/highres/sprites/monsters/"
207
    #cp -pv highres/sprites/props/4387.png                    "${EXTRACTDIR}/highres/sprites/props/"
208
    #cp -pv highres/sprites/signs/4378-79.png                 "${EXTRACTDIR}/highres/sprites/signs/"
209
    #cp -pv highres/sprites/signs/4381-85.png                 "${EXTRACTDIR}/highres/sprites/signs/"
320 leod 210
  fi
211
 
708 leod 212
  if [ "${HRPTYPE}" = "maphacks" ] ; then
213
    cp -pv                 maphacks/mhk-extract.def "${EXTRACTDIR}/maphacks/"
214
    cp -pv           duke3d_maphacks_standalone.def "${EXTRACTDIR}"
215
    copy_set_version duke3d_maphacks_standalone.def "${EXTRACTDIR}/duke3d.def"
216
  fi
217
 
330 leod 218
  if [ "${HRPTYPE}" = "voxel" ] ; then
708 leod 219
    cp -pv voxelpack_readme.txt      "${EXTRACTDIR}"
220
    cp -pv voxelpack_art_license.txt "${EXTRACTDIR}"
221
    cp -pv duke3d.def                "${EXTRACTDIR}"
222
    cp -pv duke3d_voxels.def         "${EXTRACTDIR}"
223
    if [ -f  EDUKE.CON ] ; then
224
      cp -pv EDUKE.CON               "${EXTRACTDIR}"
225
    fi
330 leod 226
  fi
227
 
228
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
229
    cp -pv sw.def                   "${EXTRACTDIR}"
708 leod 230
    cp -pv highres/sw_hrp.def       "${EXTRACTDIR}/highres/"
330 leod 231
    cp -pv HRP.bat                  "${EXTRACTDIR}"
232
    cp -pv HRP_Readme.txt           "${EXTRACTDIR}"
233
    cp -pv HRP_Changes.txt          "${EXTRACTDIR}"
234
    echo "Copying skyboxes ..."
235
    tar_copy_dir "highres/skyboxes" "${EXTRACTDIR}/highres/skyboxes"
236
    cd "${WORKDIR}"
237
  fi
238
 
239
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
384 leod 240
    echo "Creating sw.def for lowres HRP ..."
241
    echo "include lowres/sw_lrp.def" > "${EXTRACTDIR}/sw.def"
708 leod 242
    cp -pv lowres/sw_lrp.def           "${EXTRACTDIR}/lowres/"
384 leod 243
    cp -pv LRP.bat                     "${EXTRACTDIR}"
244
    cp -pv LRP_Readme.txt              "${EXTRACTDIR}"
245
    cp -pv LRP_Changes.txt             "${EXTRACTDIR}"
330 leod 246
    echo "Copying skyboxes ..."
384 leod 247
    tar_copy_dir "highres/skyboxes"    "${EXTRACTDIR}/highres/skyboxes"
330 leod 248
    cd "${WORKDIR}"
249
  fi
250
 
331 leod 251
  if [ "${HRPTYPE}" = "default" ] ; then
252
    cp -pv  "${DEF_TOP}"          "${EXTRACTDIR}/${DEF_TOP}"
253
    echo            "\`*.txt' -> \`${EXTRACTDIR}/*.txt'"
254
    cp -p  *.txt                  "${EXTRACTDIR}"
255
  fi
256
 
320 leod 257
} # copy_known_files()
258
 
259
 
656 leod 260
copy_polymost_mhk()
320 leod 261
{
708 leod 262
  cp -p maphacks/3drealms/E?L*_polymost.mhk "${EXTRACTDIR}"
263
  cp -p maphacks/dukedc/DUKEDC*-megaton.mhk "${EXTRACTDIR}"
656 leod 264
  rm -f "${EXTRACTDIR}"/*_13d_*.mhk
265
  # bashism:
662 leod 266
  for i in "${EXTRACTDIR}"/*_polymost.mhk ; do mv "$i" "${i/_polymost}" ; done
267
  for i in "${EXTRACTDIR}"/*-megaton.mhk  ; do mv "$i" "${i/-megaton}"  ; done
656 leod 268
} # copy_polymost_mhk()
320 leod 269
 
270
 
412 leod 271
# I really don't know yet if this will become necessary, or if it does make
324 leod 272
# sense at all, but at least the files involved are listed.
412 leod 273
dukeplus_polymost_hrp_compatibility()
320 leod 274
{
324 leod 275
  # dukeplus.def expects some files to be present in the HRP
276
  #
277
  # model "highres/sprites/characters/1405_duke.md3" { // all OK, no action required
278
  #    skin { pal 0 surface 0 file "highres/sprites/pickups/0057_jetpack.png" }
279
  #    skin { pal 0 surface 1 file "highres/sprites/characters/1405_duke.png" }
280
  #    skin { pal 10 surface 1 file "highres/sprites/characters/1405_duke_10.png" }
281
  #    skin { pal 11 surface 1 file "highres/sprites/characters/1405_duke_11.png" }
282
  #    skin { pal 12 surface 1 file "highres/sprites/characters/1405_duke_12.png" }
283
  #    skin { pal 13 surface 1 file "highres/sprites/characters/1405_duke_13.png" }
284
  #    skin { pal 14 surface 1 file "highres/sprites/characters/1405_duke_14.png" }
285
  #    skin { pal 15 surface 1 file "highres/sprites/characters/1405_duke_15.png" }
286
  #    skin { pal 16 surface 1 file "highres/sprites/characters/1405_duke_16.png" }
287
  #    skin { pal 21 surface 1 file "highres/sprites/characters/1405_duke_21.png" }
288
  #    skin { pal 23 surface 1 file "highres/sprites/characters/1405_duke_23.png" }
289
  #    skin { pal 0 surface 2 file "highres/sprites/pickups/0023_rpg.png" }
290
  #
291
  # model "highres/sprites/firstperson/2510_devastator.md3" { // since Imperium, not Eternity
292
  #    skin { pal 0 file "highres/sprites/firstperson/2510_devastator.png" specfactor 0.5 specpower 35 }
293
  #    specular { file "highres/sprites/firstperson/2510_devastator_s.png" }
294
  #    glow { file "highres/sprites/firstperson/2510_devastator_g.png" }
295
  #
296
  # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295
297
  #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
298
  #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
299
  # model "highres/sprites/firstperson/2530_clip.md3" {                  // most/mer : diff MD3, same skin
300
  #    skin { pal 0 file "highres/sprites/pickups/0040_pistolammo.jpg" }
301
  # model "highres/sprites/firstperson/2532_cliphand.md3" {  // most/mer : same MD3 + same skin til r295
302
  #    skin { pal 0 file "highres/sprites/firstperson/2532_cliphand.png" } // til r295, then duke_hand_*
303
  #
320 leod 304
 
324 leod 305
  SPR="highres/sprites"
306
  SPRE="${EXTRACTDIR}/highres/sprites"
307
  PATCHTYPE=$1
320 leod 308
 
324 leod 309
  case "$PATCHTYPE" in
310
    polymer)
412 leod 311
      echo "  # (Using \"Polymer approach\")"
708 leod 312
      cp -pi $SPR/firstperson/2510_devastator.md3            "$SPRE/firstperson/"
313
      cp -pi $SPR/firstperson/2510_devastator.png            "$SPRE/firstperson/"
314
      cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson/"
315
      cp -pi $SPR/firstperson/2510_devastator_g.png          "$SPRE/firstperson/"
316
      cp -pi $SPR/firstperson/2524_pistol.md3                "$SPRE/firstperson/"
317
      cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
318
      cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
319
      cp -pi $SPR/firstperson/2530_clip.md3                  "$SPRE/firstperson/"
320
      cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups/"
321
      cp -pi $SPR/firstperson/2532_cliphand.md3              "$SPRE/firstperson/"
322
      cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson/"
323
      cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson/"
324
      cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson/"
325
      cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson/"
324 leod 326
      ;;
327
    polymost)
412 leod 328
      echo "  # (Using \"Polymost approach\")"
708 leod 329
      #cp -pi $SPR/firstperson_polymost/2510_devastator.md3   "$SPRE/firstperson/"
330
      #cp -pi $SPR/firstperson_polymost/2510_devastator.png   "$SPRE/firstperson/"
331
      ##cp -pi $SPR/firstperson/2510_devastator_s.png          "$SPRE/firstperson/"
332
      #cp -pi $SPR/firstperson_polymost/2510_devastator_g.png "$SPRE/firstperson/"
333
      cp -pi $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
334
      #cp -pi $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
335
      #cp -pi $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
336
      #cp -pi $SPR/firstperson_polymost/2530_clip.md3         "$SPRE/firstperson/"
337
      #cp -pi $SPR/pickups/0040_pistolammo.jpg                "$SPRE/pickups/"
338
      #cp -pi $SPR/firstperson_polymost/2532_cliphand.md3     "$SPRE/firstperson/"
339
      #cp -pi $SPR/firstperson/2532_cliphand.png              "$SPRE/firstperson/"
340
      #cp -pi $SPR/firstperson/duke_hand_d.png                "$SPRE/firstperson/"
341
      #cp -pi $SPR/firstperson/duke_hand_n.png                "$SPRE/firstperson/"
342
      #cp -pi $SPR/firstperson/duke_hand_s.png                "$SPRE/firstperson/"
324 leod 343
      ;;
344
    mixed)
412 leod 345
      echo "  # (Using \"Mixed approach\")"
324 leod 346
      echo "    # Not applied / Not yet implemented"
347
      ;;
348
    none)
407 leod 349
      echo "  Not applied"
350
      #echo "  # Not yet implemented"
324 leod 351
      ;;
352
    *)
353
      echo "  # Bad parameter"
354
      ;;
355
  esac
356
 
412 leod 357
} # dukeplus_polymost_hrp_compatibility()
324 leod 358
 
359
 
412 leod 360
attrition_polymost_hrp_compatibility()
361
{
362
  # attr_hrp.def expects some files to be present in the HRP
363
  #
364
  # model "highres/sprites/firstperson/2524_pistol.md3" {    // most/mer : same MD3 + same skin til r295
365
  #    skin { pal 0 file "highres/sprites/firstperson/2524_pistol.png" } // up to DP2.30 DNE/IMP only
366
  #    glow { file "highres/sprites/firstperson/2524_pistol_g.png" }     // up to DP2.30 DNE/IMP only
367
 
368
  SPR="highres/sprites"
369
  SPRE="${EXTRACTDIR}/highres/sprites"
370
  PATCHTYPE=$1
371
 
372
  case "$PATCHTYPE" in
373
    polymer)
374
      echo "  # (Using \"Polymer approach\")"
375
      ;;
376
    polymost)
377
      echo "  # (Using \"Polymost approach\")"
708 leod 378
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3      "$SPRE/firstperson/"
379
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png      "$SPRE/firstperson/"
380
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png    "$SPRE/firstperson/"
381
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
382
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
383
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
412 leod 384
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
385
      ;;
386
    mixed)
387
      echo "  # (Using \"Mixed approach\")"
708 leod 388
      cp -piu $SPR/firstperson_polymost/2524_pistol.md3       "$SPRE/firstperson/"
389
      cp -pi  $SPR/firstperson_polymost/2524_pistol.png       "$SPRE/firstperson/"
390
      cp -pi  $SPR/firstperson_polymost/2524_pistol_g.png     "$SPRE/firstperson/"
391
      cp -pi  $SPR/firstperson/2530_clip.md3                 "$SPRE/firstperson/"
392
      #cp -pi  $SPR/firstperson/2532_cliphand.md3             "$SPRE/firstperson/"
393
      ##cp -pi  $SPR/firstperson/2532_cliphand.png             "$SPRE/firstperson/"
412 leod 394
      #cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/2532_cliphand.png"
708 leod 395
      cp -pi  $SPR/firstperson/2544_rpg.md3                  "$SPRE/firstperson/"
412 leod 396
      cp -pi  $SPR/firstperson/2544_rpg_d.png                "$SPRE/firstperson/2544_rpg.png"
708 leod 397
      cp -pi  $SPR/firstperson/2544_rpg_n.png                "$SPRE/firstperson/"
398
      cp -pi  $SPR/firstperson/2544_rpg_s.png                "$SPRE/firstperson/"
399
      cp -pi  $SPR/firstperson/duke_hand_d.png               "$SPRE/firstperson/"
400
      cp -pi  $SPR/firstperson/duke_hand_n.png               "$SPRE/firstperson/"
401
      cp -pi  $SPR/firstperson/duke_hand_s.png               "$SPRE/firstperson/"
402
      cp -pi  $SPR/firstperson/muzzle_flash_01.png           "$SPRE/firstperson/"
412 leod 403
      cp -pi  highres/common/transp.png                      "${EXTRACTDIR}/highres/common"
404
      ;;
405
    none)
406
      echo "  Not applied"
407
      #echo "  # Not yet implemented"
408
      ;;
409
    *)
410
      echo "  # Bad parameter"
411
      ;;
412
  esac
413
 
414
} # attrition_polymost_hrp_compatibility()
415
 
416
 
320 leod 417
parse_defs()
418
{
419
  echo "$1"
324 leod 420
  BLOCK_COMMENT="OFF"
320 leod 421
  cat $1 | while read DEF_LINE; do
422
 
423
    #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
415 leod 424
    #DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
506 leod 425
#    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\/\\\/.*// | sed s/\\\r//`
426
    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | awk '{ print $2 }' | sed 's/\r//'`
320 leod 427
    if [ "${DEF_FILE}" != "" ] ; then
428
      cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
429
      parse_defs "${DEF_FILE}"
430
    fi
431
 
375 leod 432
    #HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|voxel|front|right|back|left|top|bottom|down"`
433
    ## Old style added (except "defineskybox"):
415 leod 434
    HRP_TERM=`echo "${DEF_LINE}" | grep -owE "definetexture|definemodel|definemodelskin|file|mhkfile|model|voxel|front|right|back|left|top|bottom|down"`
333 leod 435
    #More skybox tokens: tile, pal, ft|rt|bk|lf|up|dn|forward|lt|ceiling|floor|ceil
320 leod 436
 
324 leod 437
    if [ ! "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
438
 
439
      COMMENT_TERM=`echo "${DEF_LINE}" | grep -oE "\\/\\*|\\*\\/"`
440
      if [ "$COMMENT_TERM"  = "/*" ] ; then BLOCK_COMMENT="ON" ; fi
441
 
442
      if [ "$BLOCK_COMMENT" = "ON" ] ; then HRP_TERM="" ; fi
443
 
444
      if [ "$COMMENT_TERM"  = "*/" ] ; then BLOCK_COMMENT="OFF" ; fi
445
 
446
      if [ ! "$HRP_TERM" = "" ] ; then
447
        HRP_COMMENT=`echo "${DEF_LINE}" | grep -E "//.*$HRP_TERM"`
448
        if [ ! "$HRP_COMMENT" = "" ] ; then
449
          HRP_TERM=""
450
        fi
451
      fi
452
 
453
    fi
454
 
320 leod 455
    case "$HRP_TERM" in
415 leod 456
      file|mhkfile)
320 leod 457
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
458
        # Mastering the backslash :-) ... hm, no big performance gain ... :
459
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
460
        # Ignore comments WIP:
461
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
462
        ;;
331 leod 463
      model|voxel)
464
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
320 leod 465
        ;;
333 leod 466
      front|right|back|left|top|bottom|down)
320 leod 467
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
468
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
469
        ;;
375 leod 470
      ## Old Style
471
      definemodel)
472
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
473
        ;;
474
      definemodelskin)
475
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ 0\\ \"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
476
        ;;
477
      definetexture)
478
        # Won't work atm if filename in quotes (too lazy)
479
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\(.*\\)\\($\\)/\\\3/`
480
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(\\.*\\)\\(\\ \\)\\([0-9a-zA-Z\\_\\/\\.]*\\)\\(.*\\)/\\\3/`
481
        #echo "DEF_LINE : ${DEF_LINE}"
482
        #echo "HRP_FILE : ${HRP_FILE}"
483
        ;;
320 leod 484
      *)
485
        HRP_FILE=""
486
        ;;
487
    esac
488
 
489
    if [  !   "${HRP_FILE}" = "" ] ; then
490
      if [ -f "${HRP_FILE}" ] ; then
491
        cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
492
      else
493
        echo  "WARNING : ${HRP_FILE} is missing!"
494
      fi
495
    fi
496
 
497
  done
498
} # parse_defs()
499
 
500
 
501
delete_empty_folders()
502
{
503
    if [ -d "${EXTRACTDIR}" ] ; then
504
      rm -rf ${EXTRACTDIR}/.svn
505
      DIRLIST=./EXTRACT_DIRECTORIES.lst
506
      du "${EXTRACTDIR}" > ${DIRLIST}
507
      cat ${DIRLIST} | while read DIR ; do
508
        if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
509
          EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
645 leod 510
          if [ -d ${EMPTYDIR} ] ; then
511
            rmdir --parents --ignore-fail-on-non-empty ${EMPTYDIR}
320 leod 512
          fi
513
        fi
514
      done
515
      rm ${DIRLIST}
516
    else
517
      echo "No ${EXTRACTDIR}."
518
    fi
519
} # delete_empty_folders()
520
 
521
 
522
main()
523
{
524
  EXTRACTDIR=../hrp_${HRPTYPE}_extract
525
  echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
526
 
527
  if [ $FORCE = 0 ] ; then
528
    if ask "Proceed?"
529
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
530
      else exit 0
531
    fi
532
  fi
533
 
534
  date +%F" "%H:%M:%S
535
 
536
  echo "### Deleting ${EXTRACTDIR} ... ###"
537
  rm -rf ${EXTRACTDIR}
538
 
539
  echo "### Copying directory tree ... ###"
540
  copy_folders
541
 
643 leod 542
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ||\
639 leod 543
    [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ] ; then
320 leod 544
 
408 leod 545
    echo "### DukePlus<>Polymost HRP compatibility patch ... ###"
412 leod 546
    dukeplus_polymost_hrp_compatibility $DUKEPLUS_POLYMOST_COMPATIBILTY_APPROACH
547
 
548
    echo "### Attrition<>Polymost HRP compatibility patch ... ###"
549
    attrition_polymost_hrp_compatibility $ATTRITION_POLYMOST_COMPATIBILTY_APPROACH
320 leod 550
  fi
551
 
660 leod 552
 
661 leod 553
  if [ "${HRPTYPE}" = "polymost" ]||[ "${HRPTYPE}" = "polymost_override" ]; then
554
    # Some people prefer unusual setups ...
555
    zip -rq9 ${EXTRACTDIR}/polymost_hrp_polymer_maphacks.zip \
556
    maphacks/3drealms/*.mhk
557
  fi
558
 
660 leod 559
  if [ "${HRPTYPE}" = "megaton" ] || [ "${HRPTYPE}" = "megaton_override" ]; then
661 leod 560
    echo "### Copying maphacks for Megaton ... ###"
660 leod 561
    copy_polymost_mhk
562
  fi
563
 
320 leod 564
  echo "### Parsing DEF file hierarchy ... ###"
324 leod 565
  if [ "$EXTRACT_COMMENTED_FILES" = "YES" ] ; then
566
    echo "  # Extract commented textures and models: $EXTRACT_COMMENTED_FILES"
567
  else
568
    echo "  # Extract commented textures and models: NO"
569
  fi
645 leod 570
  if [ "${HRPTYPE}" = "megaton" ]  || [ "${HRPTYPE}" = "full" ] ; then
571
    parse_defs duke3d_hrp_megaton.def
572
  fi
320 leod 573
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
574
    parse_defs duke3d_hrp_polymost.def
575
  fi
645 leod 576
  if [ "${HRPTYPE}" = "polymer" ]  || [ "${HRPTYPE}" = "full" ] ; then
320 leod 577
    parse_defs duke3d_hrp.def
578
  fi
330 leod 579
  if [ "${HRPTYPE}" = "voxel" ] ; then
580
    parse_defs duke3d_voxel.def
581
  fi
582
  if [ "${HRPTYPE}" = "sw_highres" ] ; then
333 leod 583
    parse_defs highres/sw_hrp.def
330 leod 584
  fi
585
  if [ "${HRPTYPE}" = "sw_lowres" ] ; then
333 leod 586
    parse_defs lowres/sw_lrp.def
330 leod 587
  fi
708 leod 588
  if [ "${HRPTYPE}" = "maphacks" ] ; then
589
    parse_defs maphacks/mhk-extract.def
590
  fi
331 leod 591
  if [ "${HRPTYPE}" = "default" ] ; then
592
    parse_defs "${DEF_TOP}"
593
  fi
320 leod 594
 
656 leod 595
  echo "### Copying 'known' files ... ###"
596
  copy_known_files
597
 
320 leod 598
  echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
599
  delete_empty_folders
600
 
601
  date +%F" "%H:%M:%S
602
 
603
  echo "Command line example for creating a ZIP package:"
675 leod 604
  echo "sh -c \"cd ${EXTRACTDIR}; zip -9rqn .jpg:.png:.zip ${EXTRACTDIR}.zip\
605
  highpal highres maphacks *.def *.txt\""
320 leod 606
} # main()
607
 
608
 
609
 
610
PRGPATH=$0
611
HRPTYPE=$1
612
if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
325 leod 613
if [ "$2" = "v" ] && [ ! "$3" = "" ] ; then
614
  VERSION="$3"
615
  echo "${VERSION}" > VERSION
616
fi
320 leod 617
HRPROOT=.
330 leod 618
WORKDIR=`pwd`
320 leod 619
 
620
cd               "${HRPROOT}"
330 leod 621
echo  "PWD     :  ${WORKDIR}"
622
echo  "HRPROOT :  ${HRPROOT}"
320 leod 623
 
624
case "$HRPTYPE" in
708 leod 625
  polymer|polymost_override|polymost|megaton_override|megaton|maphacks)
320 leod 626
    main $HRPTYPE
627
    ;;
628
  full)
639 leod 629
    if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Packs)?"
320 leod 630
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
631
      else exit 0
632
    fi ; fi
633
    ${PRGPATH} polymost_override y
708 leod 634
    ${PRGPATH} megaton_override  y
320 leod 635
    main $HRPTYPE
636
    ;;
637
  both)
638
    if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
639
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
640
      else exit 0
641
    fi ; fi
642
    ${PRGPATH} polymer  y
643
    ${PRGPATH} polymost y
644
    ;;
639 leod 645
  ovr)
646
    ${PRGPATH} polymost_override y
708 leod 647
    ${PRGPATH} megaton_override  y
639 leod 648
    ;;
320 leod 649
  all)
650
    if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
651
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
652
      else exit 0
653
    fi ; fi
708 leod 654
    ${PRGPATH} both     y
655
    ${PRGPATH} megaton  y
656
    ${PRGPATH} maphacks y
657
    ${PRGPATH} full     y
320 leod 658
    ;;
330 leod 659
  voxel)
660
    SET_VERSION=NO
661
    main $HRPTYPE
662
    ;;
663
  sw_highres|sw_lowres)
664
    SET_VERSION=NO
665
    main $HRPTYPE
666
    ;;
667
  sw_both)
668
    if [ $FORCE = 0 ] ; then if ask "Extract both Shadow Warrior HRP/LRP?"
669
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
670
      else exit 0
671
    fi ; fi
672
    ${PRGPATH} sw_lowres  y
673
    ${PRGPATH} sw_highres y
674
    ;;
320 leod 675
  unused)
676
    echo "Option \"$1\" not yet implemented."
677
    ;;
678
  debug)
679
    echo "Nothing to debug."
680
    ;;
681
  *)
408 leod 682
    if [ -f "${HRPTYPE}" ] && [ "${HRPTYPE##*.}" = "def" ] ; then
683
      DEF_TOP="${HRPTYPE}"
331 leod 684
      HRPTYPE=default
685
      SET_VERSION=NO
686
      EXTRACT_COMMENTED_FILES=NO
687
      main $HRPTYPE
688
    else
408 leod 689
      echo "Usage: ${0} {HRPTYPE|TOP_DEF_FILE} [v VERSION]"
639 leod 690
      echo "HRPTYPEs: {full|ovr|all}"
691
      echo "HRPTYPEs: {polymer|polymost_override|polymost|both}"
692
      echo "HRPTYPEs: {megaton_override|megaton}"
708 leod 693
      echo "HRPTYPEs: {maphacks}"
331 leod 694
      echo "HRPTYPEs: {sw_highres|sw_lowres|sw_both}"
695
      exit 1
696
    fi
320 leod 697
    ;;
698
esac
699
 
700
exit 0