Debian Codegraph @

prboom2/src/dsda/compatibility.c

raw
1 //
2 // Copyright(C) 2021 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Compatibility
16 //
17
18 #include "md5.h"
19 #include "doomdata.h"
20 #include "doomstat.h"
21 #include "doomtype.h"
22 #include "w_wad.h"
23 #include "lprintf.h"
24
25 #include "dsda/utility.h"
26
27 #include "compatibility.h"
28
29 typedef struct {
30 const char* cksum_string;
31 const signed char options[];
32 } dsda_compatibility_t;
33
34 static const dsda_compatibility_t eternal_doom_25 = {
35 "6da6fcba8089161bdec6a1d3f6c8d60f",
36 { comp_stairs, comp_vile, -1, -1 }
37 };
38
39 static const dsda_compatibility_t doomsday_of_uac_e1m8 = {
40 "32fc3115a3162b623f0d0f4e7dee6861",
41 { comp_666, -1, -1 }
42 };
43
44 static const dsda_compatibility_t hell_revealed_map19 = {
45 "811a0c97777a198bc9b2bb558cb46e6a",
46 { comp_pain, -1, -1 }
47 };
48
49 static const dsda_compatibility_t roger_ritenour_phobos_map03 = {
50 "8fa29398776146189396aa1ac6bb9e13",
51 { comp_floors, -1, -1 }
52 };
53
54 static const dsda_compatibility_t hell_revealed_map26 = {
55 "145c4dfcf843f2b92c73036ba0e1d98a",
56 { comp_vile, -1, -1 }
57 };
58
59 static const dsda_compatibility_t hell_to_pay_map14 = {
60 "5379c080299eb961792b50ad96821543",
61 { comp_vile, -1, -1 }
62 };
63
64 static const dsda_compatibility_t hell_to_pay_map22 = {
65 "7837b5334a277f107515d649bcefb682",
66 { comp_vile, -1, -1 }
67 };
68
69 static const dsda_compatibility_t icarus_map24 = {
70 "2eeb1e12fa9f9545de9d99990a4a78e5",
71 { comp_vile, -1, -1 }
72 };
73
74 static const dsda_compatibility_t plutonia2_map32 = {
75 "65a53a09a09525ae42ea210bf879cd37",
76 { comp_vile, -1, -1 }
77 };
78
79 static const dsda_compatibility_t requiem_map23 = {
80 "2499cf9a9351be9bc4e9c66fc9f291a7",
81 { comp_vile, -1, -1 }
82 };
83
84 static const dsda_compatibility_t the_waterfront_map01 = {
85 "3ca5493feff2e27bfd4181e6c4a3c2bf",
86 { comp_vile, -1, -1 }
87 };
88
89 static const dsda_compatibility_t gather2_map05_and_darkside_map01 = {
90 "cbdfefac579a62de8f1b48ca4a09d381",
91 { comp_vile, -1, -1 }
92 };
93
94 static const dsda_compatibility_t reverie_map18 = {
95 "c7a2fafb0afb2632c50ad625cdb50e51",
96 { comp_vile, -1, -1 }
97 };
98
99 static const dsda_compatibility_t project_x_map14 = {
100 "9e5724bc6135aa6f86ee54fd4d91f1e2",
101 { comp_vile, -1, -1 }
102 };
103
104 static const dsda_compatibility_t archie_map01 = {
105 "01899825ffeae016d39c02a7da4b218f",
106 { comp_vile, -1, -1 }
107 };
108
109 static const dsda_compatibility_t seej_map01 = {
110 "1d9f3afdc2517c2e450491ed13896712",
111 { comp_vile, -1, -1 }
112 };
113
114 static const dsda_compatibility_t sixpack2_map02 = {
115 "0ae745a3ab86d15fb2fb74489962c421",
116 { comp_vile, -1, -1 }
117 };
118
119 static const dsda_compatibility_t squadron_417_map21 = {
120 "2ea635c6b6aec76b6bc77448dab22f9a",
121 { comp_vile, -1, -1 }
122 };
123
124 static const dsda_compatibility_t mayhem_2013_map05 = {
125 "1e998262ee319b7d088e01de782e6b41",
126 { comp_vile, -1, -1 }
127 };
128
129 static const dsda_compatibility_t imps_are_ghost_gods_map01 = {
130 "a81e2734f735a82720d8e0f1442ba0c9",
131 { comp_vile, -1, -1 }
132 };
133
134 static const dsda_compatibility_t confinement_map31 = {
135 "aad7502cb39bc050445e17b15f72356f",
136 { comp_vile, -1, -1 }
137 };
138
139 static const dsda_compatibility_t conf256b_map07 = {
140 "5592ea1ca3b8ee0dbb2cb352aaa00911",
141 { comp_pain, -1, -1 }
142 };
143
144 static const dsda_compatibility_t conf256b_map12 = {
145 "cecedae33b970f2bf7f8b8631da0c8dd",
146 { comp_vile, -1, -1 }
147 };
148
149 static const dsda_compatibility_t sunlust_map30 = {
150 "41efe03223e41935849f64114c5cb471",
151 { comp_telefrag, -1, -1 }
152 };
153
154 static const dsda_compatibility_t tnt_map30 = {
155 "42b68b84ff8e55f264c31e6f4cfea82d",
156 { comp_stairs, -1, -1 }
157 };
158
159 static const dsda_compatibility_t intercep2_map03 = {
160 "86587e4f8c8086991c8fc5c1ccfd30b9",
161 { -1, comp_ledgeblock, -1 }
162 };
163
164 static const dsda_compatibility_t skulltiverse_map02 = {
165 "b3fa4a18b31bd96e724f9aab101776a1",
166 { -1, comp_ledgeblock, -1 }
167 };
168
169 static const dsda_compatibility_t tntr_map30 = {
170 "1d3c6d456bfcf360ce14aeecc155a96c",
171 { comp_telefrag, -1, -1 }
172 };
173
174 static const dsda_compatibility_t roomblow_e1m1 = {
175 "68ffa69f2eaa5ced3dc4da5a300d022a",
176 { comp_stairs, -1, -1 }
177 };
178
179 static const dsda_compatibility_t esp_map21 = {
180 "97088f2849904bc1cd5ae1d92d163b13",
181 { comp_stairs, -1, -1 }
182 };
183
184 static const dsda_compatibility_t av_map07 = {
185 "941e4cb56ee4184e0b1ed43486ab0bbf",
186 { comp_model, -1, -1 }
187 };
188
189 static const dsda_compatibility_t sin2_9_map02 = {
190 "9aa5aa3020434f824624eba88916ee23",
191 { comp_vile, -1, -1 }
192 };
193
194 static const dsda_compatibility_t d2reload_map09 = {
195 "c8de798a4d658ffc94151884c6c2bf37",
196 { comp_vile, -1, -1 }
197 };
198
199 static const dsda_compatibility_t amoreupho_map02 = {
200 "66a8310a0a7d2af99e3a0089b2d6c897",
201 { comp_vile, -1, -1 }
202 };
203
204 static const dsda_compatibility_t dbp20_dnd_map07 = {
205 "e26c1b6f4dfd90bb6533e6381bf61be5",
206 { comp_vile, -1, -1 }
207 };
208
209 static const dsda_compatibility_t arch_map01 = {
210 "1d37cbd32a1ecf4763437631e7b3c29a",
211 { comp_vile, -1, -1 }
212 };
213
214 static const dsda_compatibility_t ur_map06 = {
215 "cfb054683af1ed187d0565942d3dbb8f",
216 { comp_vile, -1, -1 }
217 };
218
219 static const dsda_compatibility_t* entry_0[] = {
220 &archie_map01,
221 &sixpack2_map02,
222 NULL
223 };
224
225 static const dsda_compatibility_t* entry_1[] = {
226 &hell_revealed_map26,
227 &seej_map01,
228 &mayhem_2013_map05,
229 &tntr_map30,
230 &arch_map01,
231 NULL
232 };
233
234 static const dsda_compatibility_t* entry_2[] = {
235 &icarus_map24,
236 &requiem_map23,
237 &squadron_417_map21,
238 NULL
239 };
240
241 static const dsda_compatibility_t* entry_3[] = {
242 &doomsday_of_uac_e1m8,
243 &the_waterfront_map01,
244 NULL
245 };
246
247 static const dsda_compatibility_t* entry_4[] = {
248 &sunlust_map30,
249 &tnt_map30,
250 NULL
251 };
252
253 static const dsda_compatibility_t* entry_5[] = {
254 &hell_to_pay_map14,
255 &conf256b_map07,
256 NULL
257 };
258
259 static const dsda_compatibility_t* entry_6[] = {
260 &eternal_doom_25,
261 &plutonia2_map32,
262 &roomblow_e1m1,
263 &amoreupho_map02,
264 NULL
265 };
266
267 static const dsda_compatibility_t* entry_7[] = {
268 &hell_to_pay_map22,
269 NULL
270 };
271
272 static const dsda_compatibility_t* entry_8[] = {
273 &hell_revealed_map19,
274 &roger_ritenour_phobos_map03,
275 &intercep2_map03,
276 NULL
277 };
278
279 static const dsda_compatibility_t* entry_9[] = {
280 &project_x_map14,
281 &esp_map21,
282 &av_map07,
283 &sin2_9_map02,
284 NULL
285 };
286
287 static const dsda_compatibility_t* entry_a[] = {
288 &imps_are_ghost_gods_map01,
289 &confinement_map31,
290 NULL
291 };
292
293 static const dsda_compatibility_t* entry_b[] = {
294 &skulltiverse_map02,
295 NULL
296 };
297
298 static const dsda_compatibility_t* entry_c[] = {
299 &gather2_map05_and_darkside_map01,
300 &reverie_map18,
301 &conf256b_map12,
302 &d2reload_map09,
303 &ur_map06,
304 NULL
305 };
306
307 static const dsda_compatibility_t* entry_d[] = {
308 NULL
309 };
310
311 static const dsda_compatibility_t* entry_e[] = {
312 &dbp20_dnd_map07,
313 NULL
314 };
315
316 static const dsda_compatibility_t* entry_f[] = {
317 NULL
318 };
319
320 // This is clumsy but I couldn't figure out how to inline everything
321 static const dsda_compatibility_t** level_compatibilities[16] = {
322 entry_0,
323 entry_1,
324 entry_2,
325 entry_3,
326 entry_4,
327 entry_5,
328 entry_6,
329 entry_7,
330 entry_8,
331 entry_9,
332 entry_a,
333 entry_b,
334 entry_c,
335 entry_d,
336 entry_e,
337 entry_f,
338 };
339
340 static void dsda_MD5UpdateLump(int lump, struct MD5Context *md5)
341 {
342 MD5Update(md5, W_LumpByNum(lump), W_LumpLength(lump));
343 }
344
345 static void dsda_GetLevelCheckSum(int lump, dsda_cksum_t* cksum)
346 {
347 struct MD5Context md5;
348
349 MD5Init(&md5);
350
351 dsda_MD5UpdateLump(lump + ML_LABEL, &md5);
352 dsda_MD5UpdateLump(lump + ML_THINGS, &md5);
353 dsda_MD5UpdateLump(lump + ML_LINEDEFS, &md5);
354 dsda_MD5UpdateLump(lump + ML_SIDEDEFS, &md5);
355 dsda_MD5UpdateLump(lump + ML_SECTORS, &md5);
356
357 // ML_BEHAVIOR when it becomes applicable to comp options
358
359 MD5Final(cksum->bytes, &md5);
360
361 dsda_TranslateCheckSum(cksum);
362 }
363
364 // For casual players that aren't careful about setting complevels,
365 // this function will apply comp options to automatically fix some issues
366 // that appear when playing wads in mbf21 (since this is the default).
367 void dsda_ApplyLevelCompatibility(int lump) {
368 unsigned int i;
369 dsda_cksum_t cksum;
370 const dsda_compatibility_t** level_compatibility;
371
372 if (demorecording || demoplayback || !mbf21) return;
373
374 dsda_GetLevelCheckSum(lump, &cksum);
375
376 lprintf(LO_DEBUG, "Level checksum: %s\n", cksum.string);
377
378 if (cksum.string[0] >= 'a')
379 i = cksum.string[0] - 'a' + 10;
380 else
381 i = cksum.string[0] - '0';
382
383 level_compatibility = level_compatibilities[i];
384
385 while (*level_compatibility) {
386 if (!strncmp((*level_compatibility)->cksum_string, cksum.string, 32)) {
387 const signed char* option;
388
389 for (option = (*level_compatibility)->options; *option != -1; option++) {
390 comp[*option] = 1;
391 lprintf(LO_INFO, "Automatically setting comp option %d on\n", *option);
392 }
393
394 for (option++; *option != -1; option++) {
395 comp[*option] = 0;
396 lprintf(LO_INFO, "Automatically setting comp option %d off\n", *option);
397 }
398
399 return;
400 }
401
402 level_compatibility++;
403 }
404 }