Subversion Repositories duke3d_hrp

Rev

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