Debian Codegraph @

debian/doomsday-compat

raw
1 #!/bin/sh
2
3 # doomsday-compat: This script translates between the "-iwad" parameter
4 # as expected by vanilla Doom and the one expected by the Doomsday Engine:
5 # - Vanilla Doom expects the -iwad parameter to give an IWAD file.
6 # - Doomsday expects the -iwad parameter to give a directory containing
7 # IWAD files and loads one depending on the additional -game parameter.
8
9 # Copyright © 2013-2015 Fabian Greffrath <[email protected]>
10 # This package is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14
15 # This package is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>
22
23 # On Debian systems, the complete text of the GNU General
24 # Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
25
26 DOOMSDAY="doomsday"
27
28 next_is_iwad=0
29 next_is_pwad=0
30
31 iwaddir="$(awk '/^iwaddir/{print $2}' /etc/doomsday/paths)"
32 gamemode="doom2"
33
34 for arg in "$@"
35 do
36 if [ $arg = "-iwad" ]
37 then
38 next_is_iwad=1
39 continue
40 fi
41
42 if [ $arg = "-file" ]
43 then
44 next_is_pwad=1
45 continue
46 fi
47
48 if [ $next_is_iwad = 1 ]
49 then
50 next_is_iwad=0
51 iwadpath=$arg
52 iwadfile=$(basename $arg)
53 iwaddir=$(dirname $arg)
54 continue
55 fi
56
57 if [ $next_is_pwad = 1 ]
58 then
59 next_is_pwad=0
60 pwadpath=$arg
61 pwadfile=$(basename $arg)
62 if [ ! -f $pwadpath -a -f $iwaddir/$pwadpath ]
63 then
64 pwadpath=$iwaddir/$pwadpath
65 fi
66 continue
67 fi
68
69 cmdline="$cmdline $arg"
70 done
71
72 # if no -iwad parameter is given, guess from executable name
73 if [ -z "$iwadfile" ]
74 then
75 case "$(basename $0)" in
76 heretic)
77 iwadfile=heretic.wad
78 iwadpath=$iwaddir/$iwadfile
79 ;;
80 hexen)
81 iwadfile=hexen.wad
82 iwadpath=$iwaddir/$iwadfile
83 ;;
84 esac
85 fi
86
87 case "$(echo $iwadfile | tr '[:upper:]' '[:lower:]')" in
88 doom1.wad)
89 gamemode=doom1-share
90 ;;
91 doomu.wad|doom.wad)
92 case "$(md5sum $iwadpath | awk '{print $1}')" in
93 1cd63c5ddff1bf8ce844237f580e9cf3)
94 gamemode=doom1
95 ;;
96 *)
97 gamemode=doom1-ultimate
98 ;;
99 esac
100 ;;
101 doom2f.wad|doom2.wad)
102 gamemode=doom2
103 ;;
104 freedoomu.wad|freedoom1.wad)
105 gamemode=freedoom1
106 ;;
107 freedoom.wad|freedoom2.wad)
108 gamemode=freedoom2
109 ;;
110 freedm.wad)
111 gamemode=freedm
112 ;;
113 plutonia.wad)
114 gamemode=doom2-plut
115 ;;
116 tnt.wad)
117 gamemode=doom2-tnt
118 ;;
119 chex.wad)
120 gamemode=chex
121 ;;
122 hacx.wad)
123 gamemode=hacx
124 ;;
125 heretic1.wad)
126 gamemode=heretic-share
127 ;;
128 heretic.wad)
129 case "$(md5sum $iwadpath | awk '{print $1}')" in
130 3117e399cdb4298eaa3941625f4b2923|1e4cb4ef075ad344dd63971637307e04)
131 gamemode=heretic
132 ;;
133 *)
134 gamemode=heretic-ext
135 ;;
136 esac
137 ;;
138 hexendemo.wad|machexendemo.wad|hexenbeta.wad|hexen.wad)
139 case "$(md5sum $iwadpath | awk '{print $1}')" in
140 876a5a44c7b68f04b3bb9bc7a5bd69d6)
141 gamemode=hexen-demo
142 ;;
143 *)
144 gamemode=hexen
145 ;;
146 esac
147 ;;
148 esac
149
150 case "$(echo $pwadfile | tr '[:upper:]' '[:lower:]')" in
151 hexdd.wad)
152 gamemode=hexen-dk
153 ;;
154 esac
155
156 # fall back to alternatives
157 if [ $gamemode = "doom2" \
158 -a ! -f $iwaddir/doom2.wad \
159 -a ! -f $iwaddir/doom2f.wad \
160 -a -f $iwaddir/freedoom2.wad ]
161 then
162 gamemode=freedoom2
163 elif [ \( $gamemode = "heretic" -o $gamemode = "heretic-ext" \) \
164 -a ! -f $iwaddir/heretic.wad \
165 -a -f $iwaddir/heretic1.wad ]
166 then
167 gamemode=heretic-share
168 elif [ $gamemode = "hexen" \
169 -a ! -f $iwaddir/hexen.wad \
170 -a -f $iwaddir/hexendemo.wad ]
171 then
172 gamemode=hexen-demo
173 fi
174
175 if [ -n "$pwadpath" ]
176 then
177 cmdline="-file $pwadpath $cmdline"
178 fi
179
180 if [ -n "$iwaddir" -a -n "$gamemode" ]
181 then
182 eval $DOOMSDAY -iwad $iwaddir -game $gamemode $cmdline
183 elif [ -n "$gamemode" ]
184 then
185 eval $DOOMSDAY -game $gamemode $cmdline
186 else
187 eval $DOOMSDAY "$@"
188 fi
189
190