From 91a9f20af7948bd48368c4db2fe6b94b6a335b9a Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 24 Sep 2024 00:08:48 +0300 Subject: [PATCH] Skip map marker in vres_GetMap --- src/w_wad.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 5e2f4ce10..118c5011f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2169,8 +2169,16 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) if (vsizecache[realentry] == 0) continue; vlumps[i].size = vsizecache[realentry]; + + const char *name = (fileinfo + realentry)->name; + if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + { + numlumps--; // We skip map marker, so 1 of entries becomes empty + continue; // This will skip i++ so we will write to same entry + } + // Play it safe with the name in this case. - memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8); + memcpy(vlumps[i].name, name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that. memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); @@ -2196,8 +2204,17 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); for (i = 0; i < numlumps; i++, lumpnum++) { + // Check if it is map marker. It is not always first lump sadly, so we need to expect it anywhere + const char *name = W_CheckNameForNum(lumpnum); + if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + { + --i; // Decrement so on next iteration we write on same i, so we don't leave corrupted vlumps entry + numlumps--; // Just so we don't try to access the leftover vlumps entry + continue; + } + vlumps[i].size = W_LumpLength(lumpnum); - memcpy(vlumps[i].name, W_CheckNameForNum(lumpnum), 8); + memcpy(vlumps[i].name, name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = W_CacheLumpNum(lumpnum, PU_LEVEL); }