Subversion Repositories duke3d_hrp

Rev

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

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