Subversion Repositories duke3d_hrp

Rev

Details | Last modification | View Log | RSS feed

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