| 1 |
// |
| 2 |
// Copyright(C) 2022 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 Extended Demo |
| 16 |
// |
| 17 |
|
| 18 |
#include <string.h> |
| 19 |
|
| 20 |
#include "d_main.h" |
| 21 |
#include "doomstat.h" |
| 22 |
#include "g_overflow.h" |
| 23 |
#include "i_system.h" |
| 24 |
#include "lprintf.h" |
| 25 |
#include "m_argv.h" |
| 26 |
#include "m_file.h" |
| 27 |
#include "wadtbl.h" |
| 28 |
#include "z_zone.h" |
| 29 |
#include "e6y.h" |
| 30 |
|
| 31 |
#include "dsda/args.h" |
| 32 |
#include "dsda/demo.h" |
| 33 |
#include "dsda/features.h" |
| 34 |
#include "dsda/playback.h" |
| 35 |
#include "dsda/utility.h" |
| 36 |
|
| 37 |
#include "exdemo.h" |
| 38 |
|
| 39 |
typedef struct { |
| 40 |
const char* name; |
| 41 |
byte* demo; |
| 42 |
byte* footer; |
| 43 |
size_t demo_size; |
| 44 |
size_t footer_size; |
| 45 |
byte features[FEATURE_SLOTS]; |
| 46 |
int is_signed; |
| 47 |
} exdemo_t; |
| 48 |
|
| 49 |
static exdemo_t exdemo; |
| 50 |
|
| 51 |
#define DEMOEX_PORTNAME_LUMPNAME "PORTNAME" |
| 52 |
#define DEMOEX_PARAMS_LUMPNAME "CMDLINE" |
| 53 |
#define DEMOEX_FEATURE_LUMPNAME "FEATURES" |
| 54 |
|
| 55 |
static void ForgetExDemo(void) { |
| 56 |
if (exdemo.demo) |
| 57 |
Z_Free(exdemo.demo); |
| 58 |
|
| 59 |
memset(&exdemo, 0, sizeof(exdemo)); |
| 60 |
} |
| 61 |
|
| 62 |
static const filelump_t* DemoEx_LumpForName(const char* name, const wadinfo_t* header) { |
| 63 |
int i; |
| 64 |
const filelump_t* lump_info; |
| 65 |
const byte* buffer; |
| 66 |
|
| 67 |
buffer = (const byte*) header; |
| 68 |
lump_info = (const filelump_t*)(buffer + header->infotableofs); |
| 69 |
for (i = 0; i < header->numlumps; i++, lump_info++) |
| 70 |
if (!strncmp(lump_info->name, name, 8)) |
| 71 |
return lump_info; |
| 72 |
|
| 73 |
return NULL; |
| 74 |
} |
| 75 |
|
| 76 |
static char* DemoEx_LumpAsString(const char* name, const wadinfo_t* header) { |
| 77 |
char* str; |
| 78 |
const char* lump_data; |
| 79 |
const char* buffer; |
| 80 |
const filelump_t* lump_info; |
| 81 |
|
| 82 |
lump_info = DemoEx_LumpForName(name, header); |
| 83 |
if (!lump_info || !lump_info->size) |
| 84 |
return NULL; |
| 85 |
|
| 86 |
str = Z_Calloc(lump_info->size + 1, 1); |
| 87 |
|
| 88 |
buffer = (const char*) header; |
| 89 |
lump_data = buffer + lump_info->filepos; |
| 90 |
strncpy(str, lump_data, lump_info->size); |
| 91 |
|
| 92 |
return str; |
| 93 |
} |
| 94 |
|
| 95 |
static void DemoEx_GetParams(const wadinfo_t* header) { |
| 96 |
char* str; |
| 97 |
char** params; |
| 98 |
int i, p, paramscount; |
| 99 |
|
| 100 |
str = DemoEx_LumpAsString(DEMOEX_PARAMS_LUMPNAME, header); |
| 101 |
if (!str) |
| 102 |
return; |
| 103 |
|
| 104 |
M_ParseCmdLine(str, NULL, NULL, ¶mscount, &i); |
| 105 |
|
| 106 |
params = Z_Malloc(paramscount * sizeof(char*) + i * sizeof(char) + 1); |
| 107 |
if (params) { |
| 108 |
struct { |
| 109 |
const char* param; |
| 110 |
wad_source_t source; |
| 111 |
} files[] = { |
| 112 |
{ "-iwad", source_iwad }, |
| 113 |
{ "-file", source_pwad }, |
| 114 |
{ "-deh", source_deh }, |
| 115 |
{ NULL } |
| 116 |
}; |
| 117 |
|
| 118 |
M_ParseCmdLine(str, params, ((char*) params) + sizeof(char*) * paramscount, ¶mscount, &i); |
| 119 |
|
| 120 |
if (!dsda_Flag(dsda_arg_iwad) && !dsda_Flag(dsda_arg_file)) { |
| 121 |
for (i = 0; files[i].param; ++i) { |
| 122 |
p = M_CheckParmEx(files[i].param, params, paramscount); |
| 123 |
if (p >= 0) { |
| 124 |
while (++p != paramscount && *params[p] != '-') { |
| 125 |
char* filename; |
| 126 |
|
| 127 |
if (files[i].source == source_deh) |
| 128 |
filename = I_FindDeh(params[p]); |
| 129 |
else |
| 130 |
filename = I_FindWad(params[p]); |
| 131 |
|
| 132 |
if (!filename) |
| 133 |
continue; |
| 134 |
|
| 135 |
if (files[i].source == source_iwad) |
| 136 |
AddIWAD(filename); |
| 137 |
else if (files[i].source == source_pwad) |
| 138 |
dsda_AppendStringArg(dsda_arg_file, filename); |
| 139 |
else if (files[i].source == source_deh) |
| 140 |
dsda_AppendStringArg(dsda_arg_deh, filename); |
| 141 |
|
| 142 |
Z_Free(filename); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
if (!dsda_Arg(dsda_arg_complevel)->found) { |
| 149 |
p = M_CheckParmEx("-complevel", params, paramscount); |
| 150 |
if (p >= 0 && p < (int) paramscount - 1) |
| 151 |
dsda_UpdateIntArg(dsda_arg_complevel, params[p + 1]); |
| 152 |
} |
| 153 |
|
| 154 |
//for recording or playback using "single-player coop" mode |
| 155 |
if (!dsda_Flag(dsda_arg_solo_net)) { |
| 156 |
p = M_CheckParmEx("-solo-net", params, paramscount); |
| 157 |
if (p >= 0) |
| 158 |
dsda_UpdateFlag(dsda_arg_solo_net, true); |
| 159 |
} |
| 160 |
|
| 161 |
//for recording or playback using "coop in single-player" mode |
| 162 |
if (!dsda_Flag(dsda_arg_coop_spawns)) { |
| 163 |
p = M_CheckParmEx("-coop_spawns", params, paramscount); |
| 164 |
if (p >= 0) |
| 165 |
dsda_UpdateFlag(dsda_arg_coop_spawns, true); |
| 166 |
} |
| 167 |
|
| 168 |
//for recording multiple episodes in one demo |
| 169 |
if (!dsda_Flag(dsda_arg_chain_episodes)) { |
| 170 |
p = M_CheckParmEx("-chain_episodes", params, paramscount); |
| 171 |
if (p >= 0) |
| 172 |
dsda_UpdateFlag(dsda_arg_chain_episodes, true); |
| 173 |
} |
| 174 |
|
| 175 |
if (!dsda_Flag(dsda_arg_emulate)) { |
| 176 |
p = M_CheckParmEx("-emulate", params, paramscount); |
| 177 |
if (p >= 0 && p < (int) paramscount - 1) |
| 178 |
dsda_UpdateStringArg(dsda_arg_emulate, params[p + 1]); |
| 179 |
} |
| 180 |
|
| 181 |
// for doom 1.2 |
| 182 |
if (!dsda_Flag(dsda_arg_respawn)) { |
| 183 |
p = M_CheckParmEx("-respawn", params, paramscount); |
| 184 |
if (p >= 0) |
| 185 |
dsda_UpdateFlag(dsda_arg_respawn, true); |
| 186 |
} |
| 187 |
|
| 188 |
// for doom 1.2 |
| 189 |
if (!dsda_Flag(dsda_arg_fast)) { |
| 190 |
p = M_CheckParmEx("-fast", params, paramscount); |
| 191 |
if (p >= 0) |
| 192 |
dsda_UpdateFlag(dsda_arg_fast, true); |
| 193 |
} |
| 194 |
|
| 195 |
// for doom 1.2 |
| 196 |
if (!dsda_Flag(dsda_arg_nomonsters)) { |
| 197 |
p = M_CheckParmEx("-nomonsters", params, paramscount); |
| 198 |
if (p >= 0) |
| 199 |
dsda_UpdateFlag(dsda_arg_nomonsters, true); |
| 200 |
} |
| 201 |
|
| 202 |
p = M_CheckParmEx("-spechit", params, paramscount); |
| 203 |
if (p >= 0 && p < (int) paramscount - 1) { |
| 204 |
spechit_baseaddr = atoi(params[p + 1]); |
| 205 |
} |
| 206 |
|
| 207 |
//overflows |
| 208 |
{ |
| 209 |
overrun_list_t overflow; |
| 210 |
for (overflow = 0; overflow < OVERFLOW_MAX; overflow++) { |
| 211 |
int value; |
| 212 |
char* pstr; |
| 213 |
size_t mask_size = strlen(overflow_cfgname[overflow]) + 16; |
| 214 |
char* mask = Z_Malloc(mask_size); |
| 215 |
|
| 216 |
if (mask) { |
| 217 |
snprintf(mask, mask_size, "-set %s", overflow_cfgname[overflow]); |
| 218 |
pstr = strstr(str, mask); |
| 219 |
|
| 220 |
if (pstr) { |
| 221 |
strcat(mask, " = %d"); |
| 222 |
if (sscanf(pstr, mask, &value) == 1) { |
| 223 |
overflows[overflow].footer = true; |
| 224 |
overflows[overflow].footer_emulate = value; |
| 225 |
} |
| 226 |
} |
| 227 |
Z_Free(mask); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
Z_Free(params); |
| 233 |
} |
| 234 |
|
| 235 |
Z_Free(str); |
| 236 |
} |
| 237 |
|
| 238 |
static void DemoEx_AddParams(wadtbl_t* wadtbl) { |
| 239 |
dsda_arg_t* arg; |
| 240 |
size_t i; |
| 241 |
char buf[200]; |
| 242 |
|
| 243 |
const char* filename_p; |
| 244 |
|
| 245 |
dsda_string_t files; |
| 246 |
dsda_string_t iwad; |
| 247 |
dsda_string_t pwads; |
| 248 |
dsda_string_t dehs; |
| 249 |
|
| 250 |
dsda_InitString(&files, NULL); |
| 251 |
dsda_InitString(&iwad, NULL); |
| 252 |
dsda_InitString(&pwads, NULL); |
| 253 |
dsda_InitString(&dehs, NULL); |
| 254 |
|
| 255 |
for (i = 0; i < numwadfiles; i++) { |
| 256 |
const char* fileext_p; |
| 257 |
dsda_string_t* item = NULL; |
| 258 |
|
| 259 |
filename_p = PathFindFileName(wadfiles[i].name); |
| 260 |
fileext_p = filename_p + strlen(filename_p) - 1; |
| 261 |
|
| 262 |
while (fileext_p != filename_p && *(fileext_p - 1) != '.') |
| 263 |
fileext_p--; |
| 264 |
|
| 265 |
if (fileext_p == filename_p) |
| 266 |
continue; |
| 267 |
|
| 268 |
if (wadfiles[i].src == source_iwad && !iwad.string && !strcasecmp(fileext_p, "wad")) |
| 269 |
item = &iwad; |
| 270 |
|
| 271 |
if (wadfiles[i].src == source_pwad && !strcasecmp(fileext_p, "wad")) |
| 272 |
item = &pwads; |
| 273 |
|
| 274 |
if (item) { |
| 275 |
dsda_StringCat(item, "\""); |
| 276 |
dsda_StringCat(item, filename_p); |
| 277 |
dsda_StringCat(item, "\" "); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
arg = dsda_Arg(dsda_arg_deh); |
| 282 |
if (arg->found) { |
| 283 |
for (i = 0; i < arg->count; ++i) { |
| 284 |
char* file; |
| 285 |
|
| 286 |
file = I_FindDeh(arg->value.v_string_array[i]); |
| 287 |
if (file) { |
| 288 |
filename_p = PathFindFileName(file); |
| 289 |
dsda_StringCat(&dehs, "\""); |
| 290 |
dsda_StringCat(&dehs, filename_p); |
| 291 |
dsda_StringCat(&dehs, "\" "); |
| 292 |
Z_Free(file); |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
if (iwad.string) { |
| 298 |
dsda_StringCat(&files, "-iwad "); |
| 299 |
dsda_StringCat(&files, iwad.string); |
| 300 |
} |
| 301 |
|
| 302 |
if (pwads.string) { |
| 303 |
dsda_StringCat(&files, "-file "); |
| 304 |
dsda_StringCat(&files, pwads.string); |
| 305 |
} |
| 306 |
|
| 307 |
if (dehs.string) { |
| 308 |
dsda_StringCat(&files, "-deh "); |
| 309 |
dsda_StringCat(&files, dehs.string); |
| 310 |
} |
| 311 |
|
| 312 |
// add complevel for formats which do not have it in header |
| 313 |
if (demo_compatibility) { |
| 314 |
snprintf(buf, sizeof(buf), "-complevel %d ", compatibility_level); |
| 315 |
dsda_StringCat(&files, buf); |
| 316 |
} |
| 317 |
|
| 318 |
// for recording or playback using "single-player coop" mode |
| 319 |
if (dsda_Flag(dsda_arg_solo_net)) { |
| 320 |
snprintf(buf, sizeof(buf), "-solo-net "); |
| 321 |
dsda_StringCat(&files, buf); |
| 322 |
} |
| 323 |
|
| 324 |
// for recording or playback using "coop in single-player" mode |
| 325 |
if (dsda_Flag(dsda_arg_coop_spawns)) { |
| 326 |
snprintf(buf, sizeof(buf), "-coop_spawns "); |
| 327 |
dsda_StringCat(&files, buf); |
| 328 |
} |
| 329 |
|
| 330 |
// for recording multiple episodes in one demo |
| 331 |
if (dsda_Flag(dsda_arg_chain_episodes)) { |
| 332 |
snprintf(buf, sizeof(buf), "-chain_episodes "); |
| 333 |
dsda_StringCat(&files, buf); |
| 334 |
} |
| 335 |
|
| 336 |
arg = dsda_Arg(dsda_arg_emulate); |
| 337 |
if (arg->found) { |
| 338 |
snprintf(buf, sizeof(buf), "-emulate %s", arg->value.v_string); |
| 339 |
dsda_StringCat(&files, buf); |
| 340 |
} |
| 341 |
|
| 342 |
// doom 1.2 does not store these params in header |
| 343 |
if (compatibility_level == doom_12_compatibility) { |
| 344 |
if (dsda_Flag(dsda_arg_respawn)) { |
| 345 |
snprintf(buf, sizeof(buf), "-respawn "); |
| 346 |
dsda_StringCat(&files, buf); |
| 347 |
} |
| 348 |
|
| 349 |
if (dsda_Flag(dsda_arg_fast)) { |
| 350 |
snprintf(buf, sizeof(buf), "-fast "); |
| 351 |
dsda_StringCat(&files, buf); |
| 352 |
} |
| 353 |
|
| 354 |
if (dsda_Flag(dsda_arg_nomonsters)) { |
| 355 |
snprintf(buf, sizeof(buf), "-nomonsters "); |
| 356 |
dsda_StringCat(&files, buf); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
if (spechit_baseaddr != 0 && spechit_baseaddr != DEFAULT_SPECHIT_MAGIC) { |
| 361 |
snprintf(buf, sizeof(buf), "-spechit %d ", spechit_baseaddr); |
| 362 |
dsda_StringCat(&files, buf); |
| 363 |
} |
| 364 |
|
| 365 |
//overflows |
| 366 |
{ |
| 367 |
overrun_list_t overflow; |
| 368 |
for (overflow = 0; overflow < OVERFLOW_MAX; overflow++) { |
| 369 |
if (overflows[overflow].happened) { |
| 370 |
snprintf(buf, sizeof(buf), "-set %s=%d ", overflow_cfgname[overflow], overflows[overflow].emulate); |
| 371 |
dsda_StringCat(&files, buf); |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
if (files.string) |
| 377 |
AddPWADTableLump(wadtbl, DEMOEX_PARAMS_LUMPNAME, |
| 378 |
(const byte*) files.string, strlen(files.string)); |
| 379 |
|
| 380 |
dsda_FreeString(&files); |
| 381 |
dsda_FreeString(&iwad); |
| 382 |
dsda_FreeString(&pwads); |
| 383 |
dsda_FreeString(&dehs); |
| 384 |
} |
| 385 |
|
| 386 |
int dsda_IsExDemoSigned(void) { |
| 387 |
return exdemo.is_signed; |
| 388 |
} |
| 389 |
|
| 390 |
void dsda_MergeExDemoFeatures(void) { |
| 391 |
if (!exdemo.is_signed) |
| 392 |
dsda_TrackFeature(uf_unknown); |
| 393 |
else { |
| 394 |
dsda_MergeFeatures(exdemo.features); |
| 395 |
|
| 396 |
if (exdemo.is_signed == -1) |
| 397 |
dsda_TrackFeature(uf_invalid); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
static void DemoEx_GetFeatures(const wadinfo_t* header) { |
| 402 |
char* str; |
| 403 |
char signature[33]; |
| 404 |
char ftext[2 * FEATURE_SLOTS + 1]; |
| 405 |
int ftext_start = 0; |
| 406 |
int ftext_end = 0; |
| 407 |
|
| 408 |
exdemo.is_signed = 0; |
| 409 |
for (int f = 0; f < FEATURE_SLOTS; f++) { |
| 410 |
exdemo.features[f] = 0; |
| 411 |
} |
| 412 |
|
| 413 |
str = DemoEx_LumpAsString(DEMOEX_FEATURE_LUMPNAME, header); |
| 414 |
if (!str) |
| 415 |
return; |
| 416 |
|
| 417 |
if (sscanf(str, "%*[^\n]\n0x%n%[^-]%n-%32s", &ftext_start, ftext, &ftext_end, signature) == 2) { |
| 418 |
dsda_cksum_t cksum; |
| 419 |
int ftext_slots = (ftext_end - ftext_start) / 2; |
| 420 |
byte *features; |
| 421 |
int i; |
| 422 |
|
| 423 |
features = Z_Calloc(ftext_slots, sizeof(byte)); |
| 424 |
|
| 425 |
for (i = 0; i < ftext_slots; i++) { |
| 426 |
char current_text[3]; |
| 427 |
strncpy(current_text, ftext + i * 2, 2); |
| 428 |
current_text[2] = '\0'; |
| 429 |
features[ftext_slots - i - 1] = strtol(current_text, NULL, 16); |
| 430 |
|
| 431 |
// Add it to the padded features as well |
| 432 |
if (i < FEATURE_SLOTS) |
| 433 |
exdemo.features[FEATURE_SLOTS - i - 1] = features[ftext_slots - i - 1]; |
| 434 |
} |
| 435 |
|
| 436 |
dsda_GetDemoCheckSum(&cksum, features, ftext_slots, exdemo.demo, exdemo.demo_size); |
| 437 |
|
| 438 |
if (!strcmp(signature, cksum.string)) |
| 439 |
exdemo.is_signed = 1; |
| 440 |
else |
| 441 |
exdemo.is_signed = -1; |
| 442 |
|
| 443 |
Z_Free(features); |
| 444 |
} |
| 445 |
else |
| 446 |
exdemo.is_signed = -1; |
| 447 |
|
| 448 |
Z_Free(str); |
| 449 |
} |
| 450 |
|
| 451 |
static void DemoEx_AddFeatures(wadtbl_t* wadtbl) { |
| 452 |
dsda_cksum_t cksum; |
| 453 |
char* description; |
| 454 |
char* buffer; |
| 455 |
size_t buffer_length; |
| 456 |
byte *features; |
| 457 |
char current_feature[3]; |
| 458 |
|
| 459 |
dsda_GetDemoRecordingCheckSum(&cksum); |
| 460 |
description = dsda_DescribeFeatures(); |
| 461 |
features = dsda_UsedFeatures(); |
| 462 |
|
| 463 |
// (2 + 2 * FEATURE_SLOTS) for the bitmap size in hex + \n + \0 + \- + extra space :^) |
| 464 |
buffer_length = strlen(cksum.string) + strlen(description) + 8 + 2 * FEATURE_SLOTS; |
| 465 |
buffer = Z_Calloc(buffer_length, 1); |
| 466 |
|
| 467 |
strcpy(buffer, description); |
| 468 |
strcat(buffer, "\n0x"); |
| 469 |
|
| 470 |
for (int f = 0; f < FEATURE_SLOTS; f++) { |
| 471 |
snprintf(current_feature, 3, "%02" PRIx8, features[FEATURE_SLOTS - f - 1]); |
| 472 |
strcat(buffer, current_feature); |
| 473 |
} |
| 474 |
|
| 475 |
strcat(buffer, "-"); |
| 476 |
strcat(buffer, cksum.string); |
| 477 |
|
| 478 |
AddPWADTableLump(wadtbl, DEMOEX_FEATURE_LUMPNAME, (const byte*)buffer, buffer_length); |
| 479 |
|
| 480 |
Z_Free(buffer); |
| 481 |
Z_Free(description); |
| 482 |
} |
| 483 |
|
| 484 |
static void DemoEx_AddPort(wadtbl_t* wadtbl) { |
| 485 |
AddPWADTableLump(wadtbl, DEMOEX_PORTNAME_LUMPNAME, |
| 486 |
(const byte*) PROJECT_STRING, strlen(PROJECT_STRING)); |
| 487 |
} |
| 488 |
|
| 489 |
static void PartitionDemo(const char* filename) { |
| 490 |
size_t file_size; |
| 491 |
|
| 492 |
file_size = M_ReadFile(filename, &exdemo.demo); |
| 493 |
|
| 494 |
if (file_size > 0) { |
| 495 |
const byte* p; |
| 496 |
|
| 497 |
p = dsda_DemoMarkerPosition(exdemo.demo, file_size); |
| 498 |
|
| 499 |
if (p) { |
| 500 |
//skip DEMOMARKER |
| 501 |
p++; |
| 502 |
|
| 503 |
exdemo.demo_size = p - exdemo.demo; |
| 504 |
|
| 505 |
//seach for the "PWAD" signature after ENDDEMOMARKER |
| 506 |
while (p - exdemo.demo + sizeof(wadinfo_t) < file_size) { |
| 507 |
if (!memcmp(p, PWAD_SIGNATURE, strlen(PWAD_SIGNATURE))) { |
| 508 |
exdemo.footer = exdemo.demo + (p - exdemo.demo); |
| 509 |
exdemo.footer_size = file_size - (p - exdemo.demo); |
| 510 |
|
| 511 |
break; |
| 512 |
} |
| 513 |
p++; |
| 514 |
} |
| 515 |
} |
| 516 |
else |
| 517 |
{ |
| 518 |
exdemo.demo_size = file_size; |
| 519 |
} |
| 520 |
} |
| 521 |
else |
| 522 |
ForgetExDemo(); |
| 523 |
} |
| 524 |
|
| 525 |
static void DemoEx_NewLine(wadtbl_t* wadtbl) { |
| 526 |
const char* const separator = "\n"; |
| 527 |
|
| 528 |
AddPWADTableLump(wadtbl, NULL, (const byte*) separator, strlen(separator)); |
| 529 |
} |
| 530 |
|
| 531 |
static void DemoEx_WritePWADTable(wadtbl_t* wadtbl) { |
| 532 |
dsda_WriteToDemo(&wadtbl->header, sizeof(wadtbl->header)); |
| 533 |
dsda_WriteToDemo(wadtbl->data, wadtbl->datasize); |
| 534 |
dsda_WriteToDemo(wadtbl->lumps, wadtbl->header.numlumps * sizeof(wadtbl->lumps[0])); |
| 535 |
} |
| 536 |
|
| 537 |
void dsda_WriteExDemoFooter(void) { |
| 538 |
wadtbl_t demoex; |
| 539 |
|
| 540 |
InitPWADTable(&demoex); |
| 541 |
|
| 542 |
DemoEx_NewLine(&demoex); |
| 543 |
DemoEx_NewLine(&demoex); |
| 544 |
|
| 545 |
DemoEx_AddFeatures(&demoex); |
| 546 |
DemoEx_NewLine(&demoex); |
| 547 |
|
| 548 |
DemoEx_AddPort(&demoex); |
| 549 |
DemoEx_NewLine(&demoex); |
| 550 |
|
| 551 |
DemoEx_AddParams(&demoex); |
| 552 |
DemoEx_NewLine(&demoex); |
| 553 |
|
| 554 |
DemoEx_WritePWADTable(&demoex); |
| 555 |
|
| 556 |
FreePWADTable(&demoex); |
| 557 |
} |
| 558 |
|
| 559 |
void dsda_LoadExDemo(const char* filename) { |
| 560 |
PartitionDemo(filename); |
| 561 |
|
| 562 |
if (exdemo.footer) |
| 563 |
{ |
| 564 |
wadinfo_t* header; |
| 565 |
|
| 566 |
header = ReadPWADTable(exdemo.footer, exdemo.footer_size); |
| 567 |
|
| 568 |
if (!header) |
| 569 |
lprintf(LO_ERROR, "LoadExDemo: demo footer is corrupted\n"); |
| 570 |
else { |
| 571 |
DemoEx_GetFeatures(header); |
| 572 |
|
| 573 |
// get needed wads and dehs |
| 574 |
// restore all critical params like -spechit x |
| 575 |
DemoEx_GetParams(header); |
| 576 |
} |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
int dsda_CopyExDemo(const byte** buffer, int* length) { |
| 581 |
if (exdemo.demo) { |
| 582 |
*buffer = exdemo.demo; |
| 583 |
*length = exdemo.demo_size; |
| 584 |
|
| 585 |
return true; |
| 586 |
} |
| 587 |
|
| 588 |
return false; |
| 589 |
} |