Subversion Repositories duke3d_hrp

Rev

Rev 324 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
320 leod 1
#!/bin/sh
2
 
3
# Duke Nukem 3D High Resolution Pack Extractor  v0.1  2012-03-14
4
#
5
# Author: LeoD
6
# License: ISC license : http://opensource.org/licenses/isc-license.txt
7
#
8
# This script extracts a PolyMER or PolyMOST only HRP from your working copy of
9
# the Duke Nukem 3D High Resolution Pack's Subversion repository.
10
# Note : "//" and "/* */"-like comments in DEF files are currently ingnored and
11
# may lead to false warning messages or copying of actually unused files.
12
# On Windows you need MSYS' zip to create package files.
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.
17
 
18
ask()
19
{
20
  echo -n "$@" '[y/N] ' ; read ans
21
  case "$ans" in
22
    y*|Y*) return 0 ;;
23
    *)     return 1 ;;
24
  esac
25
} # ask
26
 
27
 
28
copy_folders()
29
{
30
  mkdir ${EXTRACTDIR}
31
  for HRPDIR in . ; do
32
    if [ -d "${HRPDIR}" ] ; then
33
      DIRLIST=./HRP_DIRECTORIES.lst
34
      find "${HRPDIR}" -type d > ${DIRLIST}
35
      cat ${DIRLIST} | while read DIR; do
36
        if [ ! -d "${EXTRACTDIR}/${DIR}" ] ; then
37
          mkdir "${EXTRACTDIR}/${DIR}"
38
        fi
39
      done
40
      rm     ${DIRLIST}
41
    else
42
      echo "${HRPDIR} : no HRP."
43
    fi
44
  done
45
} # copy_folders()
46
 
47
 
48
copy_known_files()
49
{
50
  cp -pv *.txt      "${EXTRACTDIR}"
51
 
52
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ; then
53
    cp -pv duke3d_hrp_polymost.def "${EXTRACTDIR}/duke3d_hrp.def"
54
  fi
55
 
56
  if [ "${HRPTYPE}" = "polymost" ] ; then
57
    cp -pv duke3d.def "${EXTRACTDIR}"
58
    #cp -pv duke3d_hrp_polymost.def               "${EXTRACTDIR}"
59
    #cp -pv highres/screen/menu/2492_polymost.png "${EXTRACTDIR}/highres/screen/menu"
60
  fi
61
 
62
  if [ "${HRPTYPE}" = "full" ] ; then
63
    cp -pv duke3d_hrp_polymost.def "${EXTRACTDIR}"
64
  fi
65
 
66
  if [ "${HRPTYPE}" = "polymost_override" ] || [ "${HRPTYPE}" = "full" ] ; then
67
    cp -pv highres/screen/menu/2492_ver_polymost.png "${EXTRACTDIR}/highres/screen/menu"
68
  fi
69
 
70
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
71
    cp -pv duke3d.def                   "${EXTRACTDIR}"
72
    cp -pv duke3d_hrp.def               "${EXTRACTDIR}"
73
    echo                  "\`*.mhk' -> \`${EXTRACTDIR}/*.mhk'"
74
    cp -p  *.mhk                        "${EXTRACTDIR}"
75
    #cp -pv highres/screen/menu/2492.png "${EXTRACTDIR}/highres/screen/menu"
76
 
77
    #cp -pv highres/common/black.png                       "${EXTRACTDIR}/highres/common"
78
    #cp -pv highres/screen/fonts/digital/digital_minus.png "${EXTRACTDIR}/highres/screen/fonts/digital"
79
    #cp -pv highres/screen/menu/2493_old.png               "${EXTRACTDIR}/highres/screen/menu"
80
    #cp -pv highres/sprites/monsters/1960_reconcar_s.png   "${EXTRACTDIR}/highres/sprites/monsters"
81
    #cp -pv highres/sprites/props/4387.png                 "${EXTRACTDIR}/highres/sprites/props"
82
    #cp -pv highres/sprites/signs/4378.png                 "${EXTRACTDIR}/highres/sprites/signs"
83
    #cp -pv highres/sprites/signs/4379.png                 "${EXTRACTDIR}/highres/sprites/signs"
84
    #cp -pv highres/sprites/signs/4381.png                 "${EXTRACTDIR}/highres/sprites/signs"
85
    #cp -pv highres/sprites/signs/4382.png                 "${EXTRACTDIR}/highres/sprites/signs"
86
    #cp -pv highres/sprites/signs/4383.png                 "${EXTRACTDIR}/highres/sprites/signs"
87
    #cp -pv highres/sprites/signs/4384.png                 "${EXTRACTDIR}/highres/sprites/signs"
88
    #cp -pv highres/sprites/signs/4385.png                 "${EXTRACTDIR}/highres/sprites/signs"
89
  fi
90
 
91
} # copy_known_files()
92
 
93
 
94
polymost_mhk_patch()
95
{
96
  MHKFILE="$1"
97
  MHK_LINE="$2"
98
 
99
  case "${MHKFILE}" in
100
    "E3L1.mhk")
101
      echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
102
      MHK_INSERT=`echo "${MHK_LINE}" | grep -oE "sprite\ 575\ pitch\ 1"`
103
      if [ ! "${MHK_INSERT}" = "" ] ; then
104
        echo "sprite 591 mdxoff 425000 // underwater slimebabe (Polymost HRP)\r" \
105
             >> "${EXTRACTDIR}/${MHKFILE}"
106
        echo "sprite 591 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
107
        echo "sprite 592 mdxoff 425000 // underwater slimebabe (Polymost HRP)\r" \
108
             >> "${EXTRACTDIR}/${MHKFILE}"
109
        echo "sprite 592 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
110
        echo "sprite 593 mdxoff 425000 // underwater slimebabe (Polymost HRP)\r" \
111
             >> "${EXTRACTDIR}/${MHKFILE}"
112
        echo "sprite 593 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
113
      fi
114
      ;;
115
    "E3L3.mhk")
116
      MHK_REPLACE=`echo "${MHK_LINE}" | grep -oE "sprite\ 105\ angoff -128"`
117
      if [ ! "${MHK_REPLACE}" = "" ] ; then
118
        echo "sprite 105 angoff 768 // (Polymost HRP)\r" >> "${EXTRACTDIR}/${MHKFILE}"
119
      else
120
        echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
121
        MHK_INSERT=`echo "${MHK_LINE}" | grep -oE "sprite\ 96\ pitch\ 1"`
122
        if [ ! "${MHK_INSERT}" = "" ] ; then
123
          echo "sprite 105 mdxoff 450000 // underwater slime babe (Polymost HRP)\r" \
124
               >> "${EXTRACTDIR}/${MHKFILE}"
125
          echo "sprite 105 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
126
          echo "sprite 447 mdxoff 462000 // underwater slime babe (Polymost HRP)\r" \
127
               >> "${EXTRACTDIR}/${MHKFILE}"
128
          echo "sprite 447 pitch 1\r" >> "${EXTRACTDIR}/${MHKFILE}"
129
        fi
130
      fi
131
      ;;
132
    "E3L6.mhk")
133
      MHK_REPLACE1=`echo "${MHK_LINE}" | grep -oE "sprite\ 307\ angoff -210"`
134
      MHK_REPLACE2=`echo "${MHK_LINE}" | grep -oE "sprite\ 307\ mdxoff -125000 \\/\\/\ flipped hanging babe"`
135
      MHK_REPLACE3=`echo "${MHK_LINE}" | grep -oE "sprite\ 307\ mdzoff -11000"`
136
      if [ ! "${MHK_REPLACE1}" = "" ] ; then
137
        echo "sprite 307 angoff 200 // (Polymost HRP)\r" >> "${EXTRACTDIR}/${MHKFILE}"
138
      elif [ ! "${MHK_REPLACE2}" = "" ] ; then
139
        echo "sprite 307 mdxoff 750000 // flipped hanging babe (Polymost HRP)\r" \
140
        >> "${EXTRACTDIR}/${MHKFILE}"
141
      elif [ ! "${MHK_REPLACE3}" = "" ] ; then
142
        echo "sprite 307 mdzoff 625000 // flipped hanging babe (Polymost HRP)\r" \
143
        >> "${EXTRACTDIR}/${MHKFILE}"
144
      else
145
        echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
146
      fi
147
      ;;
148
    *)
149
      echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
150
      ;;
151
  esac
152
} # polymost_mhk_patch()
153
 
154
 
155
create_polymost_mhk()
156
{
157
  for MHKFILE in *.mhk ; do
158
    MHKSTOP="0"
159
    cat   ${MHKFILE} | while read MHK_LINE; do
160
      if [ "${MHKSTOP}" = "0" ] ; then
161
 
162
        if [ "${MHKFILE}" = "E3L1.mhk" ] || [ "${MHKFILE}" = "E3L3.mhk" ] || \
163
           [ "${MHKFILE}" = "E3L6.mhk" ] ; then
164
          polymost_mhk_patch ${MHKFILE} "${MHK_LINE}"
165
        else
166
          echo "${MHK_LINE}" >> "${EXTRACTDIR}/${MHKFILE}"
167
        fi
168
 
169
        MHK_TERM=`echo "${MHK_LINE}" | grep -owE "\\/\\/\\ LIGHTS"`
170
        if [ "${MHK_TERM}" = "// LIGHTS" ] ; then
171
          MHKSTOP="1"
172
        fi
173
      fi
174
    done
175
  done
176
  # Some people prefer unusual setups ...
177
  zip -rq9 ${EXTRACTDIR}/polymost_hrp_update_polymer_maphacks.zip *.mhk
178
} # create_polymost_mhk()
179
 
180
 
181
duke_plus_compatibility()
182
{
183
  echo "DukePlus compatibility patch for Polymost HRP export is not yet implemented."
184
} # duke_plus_compatibility()
185
 
186
 
187
parse_defs()
188
{
189
  echo "$1"
190
  cat $1 | while read DEF_LINE; do
191
 
192
    #DOS only: DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ //`
193
    DEF_FILE=`echo "${DEF_LINE}" | grep -wE "^include" | sed s/include\ // | sed s/\\\r//`
194
    if [ "${DEF_FILE}" != "" ] ; then
195
      cp -p      "${DEF_FILE}" "${EXTRACTDIR}/${DEF_FILE}"
196
      parse_defs "${DEF_FILE}"
197
    fi
198
 
199
    HRP_TERM=`echo "${DEF_LINE}" | grep -owE "file|model|front|right|back|left|top|down"`
200
 
201
    case "$HRP_TERM" in
202
      file)
203
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*file\ *\"//g | sed s/\".*//`
204
        # Mastering the backslash :-) ... hm, no big performance gain ... :
205
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
206
        # Ignore comments WIP:
207
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*file\\ *\\)\\(\\"\\(.*\\)\\"\\)\\(.*\\)/\\\3/`
208
        ;;
209
      model)
210
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*model\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
211
        ;;
212
      front|right|back|left|top|down)
213
        #HRP_FILE=`echo "${DEF_LINE}" | sed -r s/^.*${HRP_TERM}\ *\"//g | sed s/\".*//`
214
        HRP_FILE=`echo "${DEF_LINE}" | sed -r --posix s/\\(^.*${HRP_TERM}\\ *\"\\)\\([^\"]*\\)\\(.*\\)/\\\2/`
215
        ;;
216
      *)
217
        HRP_FILE=""
218
        ;;
219
    esac
220
 
221
    if [  !   "${HRP_FILE}" = "" ] ; then
222
      if [ -f "${HRP_FILE}" ] ; then
223
        cp -p "${HRP_FILE}" "${EXTRACTDIR}/${HRP_FILE}"
224
      else
225
        echo  "WARNING : ${HRP_FILE} is missing!"
226
      fi
227
    fi
228
 
229
  done
230
} # parse_defs()
231
 
232
 
233
delete_empty_folders()
234
{
235
    if [ -d "${EXTRACTDIR}" ] ; then
236
      rm -rf ${EXTRACTDIR}/.svn
237
      rm -rf ${EXTRACTDIR}/installer
238
      DIRLIST=./EXTRACT_DIRECTORIES.lst
239
      du "${EXTRACTDIR}" > ${DIRLIST}
240
      cat ${DIRLIST} | while read DIR ; do
241
        if [ "0" = "`echo \"${DIR}\" | grep -owE \"0\"`" ] ; then
242
          EMPTYDIR="`echo \"${DIR}\" | sed -r --posix s/0//`"
243
          if [ -d ${EMPTYDIR} ] ; then
244
            rmdir ${EMPTYDIR}
245
          fi
246
        fi
247
      done
248
      rm ${DIRLIST}
249
    else
250
      echo "No ${EXTRACTDIR}."
251
    fi
252
} # delete_empty_folders()
253
 
254
 
255
main()
256
{
257
  EXTRACTDIR=../hrp_${HRPTYPE}_extract
258
  echo  "EXTRACT :" ${HRPROOT}/${EXTRACTDIR}
259
 
260
  if [ $FORCE = 0 ] ; then
261
    if ask "Proceed?"
262
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
263
      else exit 0
264
    fi
265
  fi
266
 
267
  date +%F" "%H:%M:%S
268
 
269
  echo "### Deleting ${EXTRACTDIR} ... ###"
270
  rm -rf ${EXTRACTDIR}
271
 
272
  echo "### Copying directory tree ... ###"
273
  copy_folders
274
 
275
  echo "### Copying 'known' files ... ###"
276
  copy_known_files
277
 
278
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "polymost_override" ] ; then
279
    echo "### Creating Polymost maphacks ... ###"
280
    create_polymost_mhk
281
 
282
    #echo "### Duke Plus compatibility patch ... ###"
283
    #duke_plus_compatibility
284
  fi
285
 
286
  echo "### Parsing DEF file hierarchy ... ###"
287
  if [ "${HRPTYPE}" = "polymost" ] || [ "${HRPTYPE}" = "full" ] ; then
288
    parse_defs duke3d_hrp_polymost.def
289
  fi
290
  if [ "${HRPTYPE}" = "polymer" ] || [ "${HRPTYPE}" = "full" ] ; then
291
    parse_defs duke3d_hrp.def
292
  fi
293
 
294
  echo "### Deleting empty directories in ${EXTRACTDIR} ... ###"
295
  delete_empty_folders
296
 
297
  date +%F" "%H:%M:%S
298
 
299
  echo "Command line example for creating a ZIP package:"
300
  echo "sh -c \"cd ${EXTRACTDIR} ; zip -rqn .zip:.jpg:.png ${EXTRACTDIR}.zip *\""
301
} # main()
302
 
303
 
304
 
305
PRGPATH=$0
306
HRPTYPE=$1
307
if [ "$2" = "y" ] ; then FORCE=1 ; else FORCE=0 ; fi
308
HRPROOT=.
309
 
310
cd               "${HRPROOT}"
311
echo  "PWD     :" `pwd`
312
echo  "HRPROOT :" ${HRPROOT}
313
 
314
if [ ! -f "./duke3d.def" ] ; then
315
  echo "ERROR : ./duke3d.def not found. This is no HRP root directory. Exit."
316
  exit 1
317
fi
318
 
319
case "$HRPTYPE" in
320
  polymer|polymost_override|polymost)
321
    main $HRPTYPE
322
    ;;
323
  full)
324
    if [ $FORCE = 0 ] ; then if ask "Extract full HRP (+ Override Pack)?"
325
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
326
      else exit 0
327
    fi ; fi
328
    ${PRGPATH} polymost_override y
329
    main $HRPTYPE
330
    ;;
331
  both)
332
    if [ $FORCE = 0 ] ; then if ask "Extract both pure HRP?"
333
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
334
      else exit 0
335
    fi ; fi
336
    ${PRGPATH} polymer  y
337
    ${PRGPATH} polymost y
338
    ;;
339
  all)
340
    if [ $FORCE = 0 ] ; then if ask "Extract all packs from the repository?"
341
      then echo "Extracting ${HRPTYPE} from \"${HRPROOT}\" "
342
      else exit 0
343
    fi ; fi
344
    ${PRGPATH} both y
345
    ${PRGPATH} full y
346
    ;;
347
  unused)
348
    echo "Option \"$1\" not yet implemented."
349
    ##(cd ${1}; tar cf - . ) | (cd ${2}; tar xf -)
350
    ;;
351
  debug)
352
    echo "Nothing to debug."
353
    ;;
354
  *)
355
    echo "Usage: ${0} {full|polymer|polymost_override|polymost|both|all}"
356
    exit 1
357
    ;;
358
esac
359
 
360
exit 0