diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 609c96e50..472f1c1fd 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6552,19 +6552,6 @@ void HWR_DrawScreenFinalTexture(int width, int height) HWD.pfnDrawScreenFinalTexture(width, height); } -static inline UINT16 HWR_FindShaderDefs(UINT16 wadnum) -{ - UINT16 i; - lumpinfo_t *lump_p; - - lump_p = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < wadfiles[wadnum]->numlumps; i++, lump_p++) - if (memcmp(lump_p->name, "SHADERS", 7) == 0) - return i; - - return INT16_MAX; -} - boolean HWR_CompileShaders(void) { return HWD.pfnCompileShaders(); @@ -6603,7 +6590,7 @@ void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) int shadertype = 0; int i; - lump = HWR_FindShaderDefs(wadnum); + lump = W_CheckNumForNamePwad("SHADERS", wadnum, 0); if (lump == INT16_MAX) return; diff --git a/src/k_brightmap.c b/src/k_brightmap.c index cd213ae5c..edb9f95a0 100644 --- a/src/k_brightmap.c +++ b/src/k_brightmap.c @@ -190,15 +190,9 @@ void K_InitBrightmapsPwad(INT32 wadNum) size_t size = W_LumpLengthPwad(wadNum, lumpNum); char *datacopy; - size_t nameLength = strlen(wadfiles[wadNum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name - char *name = malloc(nameLength + 1); - - sprintf(name, "%s|%s", wadfiles[wadNum]->filename, lump_p->fullname); - name[nameLength] = '\0'; - size = W_LumpLengthPwad(wadNum, lumpNum); - CONS_Printf(M_GetText("Loading BRIGHT from %s\n"), name); + CONS_Printf(M_GetText("Loading BRIGHT from %s|%s\n"), wadfiles[wadNum]->filename, strbuf_get(lumpnamebuf, lump_p->fullname)); datacopy = (char *)Z_Malloc((size+1)*sizeof(char),PU_STATIC,NULL); memmove(datacopy,data,size); @@ -209,8 +203,6 @@ void K_InitBrightmapsPwad(INT32 wadNum) K_BRIGHTLumpParser(datacopy, size); Z_Free(datacopy); - - free(name); } lumpNum = W_CheckNumForNamePwad("BRIGHT", (UINT16)wadNum, lumpNum + 1); diff --git a/src/k_terrain.c b/src/k_terrain.c index 91837a81b..b786ace31 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -2271,7 +2271,7 @@ boolean K_InitTerrainPwad(UINT16 wadNum) { UINT8 *data; - if (memcmp(lump_p->name, "TERRAIN", 8) != 0) + if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname), "TERRAIN", 8) != 0) { continue; } @@ -2288,17 +2288,10 @@ boolean K_InitTerrainPwad(UINT16 wadNum) size_t size = W_LumpLengthPwad(wadNum, lumpNum); char *datacopy; - size_t nameLength = strlen(wadfiles[wadNum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name - char *name = malloc(nameLength + 1); - - sprintf(name, "%s|%s", wadfiles[wadNum]->filename, lump_p->fullname); - name[nameLength] = '\0'; - size = W_LumpLengthPwad(wadNum, lumpNum); - CONS_Printf(M_GetText("Loading TERRAIN from %s\n"), name); + CONS_Printf(M_GetText("Loading TERRAIN from %s|%s\n"), wadfiles[wadNum]->filename, strbuf_get(lumpnamebuf, lump_p->fullname)); terrainLoaded = true; - datacopy = (char *)Z_Malloc((size+1)*sizeof(char),PU_STATIC,NULL); memmove(datacopy,data,size); @@ -2309,8 +2302,6 @@ boolean K_InitTerrainPwad(UINT16 wadNum) K_TERRAINLumpParser(datacopy, size); Z_Free(datacopy); - - free(name); } } diff --git a/src/lua_script.c b/src/lua_script.c index d77ab74a2..f8b2846f5 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -654,7 +654,6 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults) { MYFILE f; char *name; - size_t len; if (M_CheckParm("-nolua")) { @@ -667,21 +666,10 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults) W_ReadLumpPwad(wad, lump, f.data); f.curpos = f.data; - len = strlen(wadfiles[wad]->filename); // length of file name - if (wadfiles[wad]->type == RET_LUA) - { - name = malloc(len+1); - strcpy(name, wadfiles[wad]->filename); - } + name = xva("%s", wadfiles[wad]->filename); else // If it's not a .lua file, copy the lump name in too. - { - lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump]; - len += 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name - name = malloc(len+1); - sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->fullname); - name[len] = '\0'; - } + name = xva("%s|%s", wadfiles[wad]->filename, strbuf_get(lumpnamebuf, wadfiles[wad]->lumpinfo[lump].fullname)); lua_compatmode = wadfiles[wad]->compatmode; diff --git a/src/p_setup.c b/src/p_setup.c index 061c50939..bf31a7ccf 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -9038,11 +9038,11 @@ void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num) // Let's check whether it's replacing an existing sound or it's a brand new one. for (j = 1; j < NUMSFX; j++) { - if (S_sfx[j].name && !strnicmp(S_sfx[j].name, lumpinfo->name + 2, 6)) + if (S_sfx[j].name && !strnicmp(S_sfx[j].name, strbuf_get(lumpnamebuf, lumpinfo->longname) + 2, 6)) { // the sound will be reloaded when needed, // since sfx->data will be NULL - CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", lumpinfo->name); + CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", strbuf_get(lumpnamebuf, lumpinfo->longname)); I_FreeSfx(&S_sfx[j]); break; // there shouldn't be two sounds with the same name, so stop looking @@ -9053,6 +9053,7 @@ void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num) // Auxiliary function for PK3 loading - looks for music and music replacements. // NOTE: does nothing but print debug messages. The code is handled somewhere else. +/* void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num) { lumpinfo_t *lumpinfo = wadfiles[wadnum]->lumpinfo + first; @@ -9071,18 +9072,19 @@ void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num) } return; } +*/ // Auxiliary function - input a folder name and gives us the resource markers positions. static lumpinfo_t* FindFolder(const char *folName, UINT16 *start, UINT16 *end, lumpinfo_t *lumpinfo, UINT16 *pnumlumps, size_t *pi) { UINT16 numlumps = *pnumlumps; size_t i = *pi; - if (!stricmp(lumpinfo->fullname, folName)) + if (!stricmp(strbuf_get(lumpnamebuf, lumpinfo->fullname), folName)) { lumpinfo++; *start = ++i; for (; i < numlumps; i++, lumpinfo++) - if (strnicmp(lumpinfo->fullname, folName, strlen(folName))) + if (strnicmp(strbuf_get(lumpnamebuf, lumpinfo->fullname), folName, strlen(folName))) break; lumpinfo--; *end = i-- - *start; @@ -9316,8 +9318,8 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, wadcompat_t compat) // P_LoadDehackRange(wadnum, socPos, socNum); if (sfxNum) // Sounds. TODO: Function currently only updates already existing sounds, the rest is handled somewhere else. P_LoadSoundsRange(wadnum, sfxPos, sfxNum); - if (musNum) // Music. TODO: Useless function right now. - P_LoadMusicsRange(wadnum, musPos, musNum); +// if (musNum) // Music. TODO: Useless function right now. +// P_LoadMusicsRange(wadnum, musPos, musNum); // if (sprNum) // Sprites. // R_LoadSpritsRange(wadnum, sprPos, sprNum); // if (texNum) // Textures. TODO: R_LoadTextures() does the folder positioning once again. New function maybe? @@ -9329,7 +9331,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, wadcompat_t compat) lumpinfo = wadfiles[wadnum]->lumpinfo; for (i = 0; i < numlumps; i++, lumpinfo++) { - name = lumpinfo->name; + name = strbuf_get(lumpnamebuf, lumpinfo->longname); if (name[0] == 'D') { if (name[1] == 'S') diff --git a/src/r_picformats.c b/src/r_picformats.c index db33c33d6..bb131a25d 100644 --- a/src/r_picformats.c +++ b/src/r_picformats.c @@ -1860,7 +1860,7 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps) for (i = 0; i < numlumps; i++, lumpinfo++) { - name = lumpinfo->name; + name = strbuf_get(lumpnamebuf, lumpinfo->longname); // Load SPRTINFO and SPR_ lumps as SpriteInfo if (!memcmp(name, "SPRTINFO", 8) || !memcmp(name, "SPR_", 4)) R_ParseSPRTINFOLump(wadnum, i); diff --git a/src/r_skins.c b/src/r_skins.c index 15f2034a7..e02fec575 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -362,7 +362,7 @@ static UINT16 W_CheckForSkinMarkerInPwad(UINT16 wadid, UINT16 startlump) { lump_p = wadfiles[wadid]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wadid]->numlumps; i++, lump_p++) - if (memcmp(lump_p->name,S_SKIN,6)==0) + if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname),S_SKIN,6)==0) return i; } return INT16_MAX; // not found @@ -393,7 +393,7 @@ static UINT16 W_CheckForPatchSkinMarkerInPwad(UINT16 wadid, UINT16 startlump) { lump_p = wadfiles[wadid]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wadid]->numlumps; i++, lump_p++) - if (memcmp(lump_p->name,P_SKIN,6)==0) + if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname),P_SKIN,6)==0) return i; } return INT16_MAX; // not found diff --git a/src/r_textures.c b/src/r_textures.c index d8c57b49d..9cf14c778 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -287,7 +287,7 @@ static boolean R_CheckTextureLumpLength(texture_t *texture, size_t patch) texture->name, sizeu1(offsetof(softwarepatch_t, columnofs)), sizeu2(lumplength), - wadfiles[wadnum]->lumpinfo[lumpnum].fullname + strbuf_get(lumpnamebuf, wadfiles[wadnum]->lumpinfo[lumpnum].fullname) ); return false; diff --git a/src/r_things.cpp b/src/r_things.cpp index 682768d2d..66e1674e6 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -329,7 +329,8 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 for (l = startlump; l < endlump; l++) { - if (memcmp(lumpinfo[l].name,sprname,4)) + const char *longname = strbuf_get(lumpnamebuf, lumpinfo[l].longname); + if (memcmp(longname,sprname,4)) continue; { @@ -339,8 +340,8 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 boolean isPNG = false; #endif - frame = R_Char2Frame(lumpinfo[l].name[4], compat); - rotation = R_Char2Rotation(lumpinfo[l].name[5]); + frame = R_Char2Frame(longname[4], compat); + rotation = R_Char2Rotation(longname[5]); if (frame >= 64 || rotation == 255) // Give an actual NAME error -_-... { @@ -391,10 +392,10 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 R_InstallSpriteLump(wadnum, l, numspritelumps, frame, rotation, 0); - if (lumpinfo[l].name[6]) + if (longname[6]) { - frame = R_Char2Frame(lumpinfo[l].name[6], compat); - rotation = R_Char2Rotation(lumpinfo[l].name[7]); + frame = R_Char2Frame(longname[6], compat); + rotation = R_Char2Rotation(longname[7]); if (frame >= 64 || rotation == 255) // Give an actual NAME error -_-... { diff --git a/src/s_sound.c b/src/s_sound.c index 306e7bac3..332657f36 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1392,7 +1392,7 @@ MusicDefError CONS_Alert(level, va("%%s|%%s: %s (line %%d)\n", description), wad->filename, - lump->fullname, + strbuf_get(lumpnamebuf, lump->fullname), field, line ); diff --git a/src/strbuf.h b/src/strbuf.h index 85bef9860..0a17a55cb 100644 --- a/src/strbuf.h +++ b/src/strbuf.h @@ -9,6 +9,9 @@ /// \file strbuf.h /// \brief string buffer library, for making chunks of many small strings +#ifndef __STRBUF_H__ +#define __STRBUF_H__ + #ifdef __cplusplus extern "C" { #endif @@ -36,3 +39,5 @@ FUNCINLINE static ATTRINLINE char *strbuf_get(strbuf_t *strbuf, UINT32 ofs) #ifdef __cplusplus } #endif + +#endif diff --git a/src/w_wad.c b/src/w_wad.c index 2d669bd37..bbe7a1d22 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -101,6 +101,8 @@ typedef struct lumpnum_cache_s static lumpnum_cache_t lumpnumcache[LUMPNUMCACHESIZE]; static UINT16 lumpnumcacheindex = 0; +strbuf_t *lumpnamebuf; + //=========================================================================== // GLOBALS //=========================================================================== @@ -120,18 +122,11 @@ void W_Shutdown(void) fclose(wad->handle); Z_Free(wad->filename); - while (wad->numlumps--) - { - Z_Free(wad->lumpinfo[wad->numlumps].longname); - if (wad->lumpinfo[wad->numlumps].fullname != wad->lumpinfo[wad->numlumps].longname) - { - Z_Free(wad->lumpinfo[wad->numlumps].fullname); - } - } - Z_Free(wad->lumpinfo); Z_Free(wad); } + + Z_Free(lumpnamebuf); } //=========================================================================== @@ -257,14 +252,8 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum, boolean mainfile) for(; posStart < posEnd; posStart++) { - lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart]; - size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name - char *name = malloc(length + 1); - sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname); - name[length] = '\0'; - CONS_Printf(M_GetText("Loading SOC from %s\n"), name); + CONS_Printf(M_GetText("Loading SOC from %s|%s\n"), wadfiles[wadnum]->filename, strbuf_get(lumpnamebuf, wadfiles[wadnum]->lumpinfo[posStart].fullname)); DEH_LoadDehackedLumpPwad(wadnum, posStart, mainfile); - free(name); } } } @@ -278,30 +267,24 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile) { lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo; for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) - if (memcmp(lump_p->name,"LUA_",4)==0) + if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname),"LUA_",4)==0) LUA_LoadLump(wadnum, lump, true); } { lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo; for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) - if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump + if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname),"SOC_",4)==0) // Check for generic SOC lump { // shameless copy+paste of code from LUA_LoadLump - size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name - char *name = malloc(length + 1); - sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname); - name[length] = '\0'; - - CONS_Printf(M_GetText("Loading SOC from %s\n"), name); + CONS_Printf(M_GetText("Loading SOC from %s|%s\n"), wadfiles[wadnum]->filename, strbuf_get(lumpnamebuf, lump_p->fullname)); DEH_LoadDehackedLumpPwad(wadnum, lump, mainfile); - free(name); } - else if (memcmp(lump_p->name,"MAINCFG",8)==0) // Check for MAINCFG + else if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname),"MAINCFG",8)==0) // Check for MAINCFG { CONS_Printf(M_GetText("Loading main config from %s\n"), wadfiles[wadnum]->filename); DEH_LoadDehackedLumpPwad(wadnum, lump, mainfile); } - else if (memcmp(lump_p->name,"OBJCTCFG",8)==0) // Check for OBJCTCFG + else if (memcmp(strbuf_get(lumpnamebuf, lump_p->longname),"OBJCTCFG",9)==0) // Check for OBJCTCFG { CONS_Printf(M_GetText("Loading object config from %s\n"), wadfiles[wadnum]->filename); DEH_LoadDehackedLumpPwad(wadnum, lump, mainfile); @@ -455,19 +438,10 @@ static lumpinfo_t* ResGetLumpsStandalone (FILE* handle, UINT16* numlumps, const fseek(handle, 0, SEEK_END); lumpinfo->size = ftell(handle); fseek(handle, 0, SEEK_SET); - strcpy(lumpinfo->name, lumpname); + + lumpinfo->longname = lumpinfo->fullname = strbuf_append(&lumpnamebuf, lumpname); lumpinfo->hash = quickncasehash(lumpname, 8); - // Allocate the lump's long name. - lumpinfo->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strcpy(lumpinfo->longname, lumpname); - lumpinfo->longname[8] = '\0'; - - // Allocate the lump's full name. - lumpinfo->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strcpy(lumpinfo->fullname, lumpname); - lumpinfo->fullname[8] = '\0'; - *numlumps = 1; return lumpinfo; } @@ -553,9 +527,6 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen else lump_p->compression = CM_NOCOMPRESSION; - memset(lump_p->name, 0x00, 9); - strncpy(lump_p->name, fileinfo->name, 8); - if (WADNAMECHECK(fileinfo->name)) { size_t namelen; @@ -601,26 +572,28 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen namelen = strlen(trimname); // Allocate the lump's long and full name (save on memory). - lump_p->longname = lump_p->fullname = Z_Calloc(namelen * sizeof(char), PU_STATIC, NULL); - strncpy(lump_p->longname, trimname, namelen); - lump_p->longname[namelen-1] = '\0'; + char *name = strdup(trimname); + name[namelen-1] = '\0'; + lump_p->longname = lump_p->fullname = strbuf_append(&lumpnamebuf, name); - CONS_Debug(DBG_SETUP, "WADNAME handling:\n -- path %s\n -- interpreted lumpname %s\n", filename, lump_p->longname); + CONS_Debug(DBG_SETUP, "WADNAME handling:\n -- path %s\n -- interpreted lumpname %s\n", filename, trimname); // Grab the hash from the first part - lump_p->hash = quickncasehash(lump_p->longname, 8); + lump_p->hash = quickncasehash(name, 8); + free(name); wadnamelump = i | (numwadfiles << 16); } else { - // Set up true hash - lump_p->hash = quickncasehash(lump_p->name, 8); - // Allocate the lump's long and full name (save on memory). - lump_p->longname = lump_p->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); - strncpy(lump_p->longname, fileinfo->name, 8); - lump_p->longname[8] = '\0'; + char name[9]; + strncpy(name, fileinfo->name, 8); + name[8] = '\0'; + lump_p->longname = lump_p->fullname = strbuf_append(&lumpnamebuf, name); + + // Set up true hash + lump_p->hash = quickncasehash(name, 8); } } free(fileinfov); @@ -784,15 +757,15 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) if ((dotpos = strrchr(trimname, '.')) == 0) dotpos = fullname + strlen(fullname); // Watch for files without extension. - memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? - strncpy(lump_p->name, trimname, min(8, dotpos - trimname)); - lump_p->hash = quickncasehash(lump_p->name, 8); + char backup = trimname[dotpos - trimname]; + trimname[dotpos - trimname] = '\0'; + lump_p->longname = strbuf_append(&lumpnamebuf, trimname); + char name[8]; + strncpy(name, trimname, 8); + lump_p->hash = quickncasehash(name, 8); + trimname[dotpos - trimname] = backup; - lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL); - strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); - - lump_p->fullname = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL); - strncpy(lump_p->fullname, fullname, zentry.namelen); + lump_p->fullname = strbuf_append(&lumpnamebuf, fullname); switch(zentry.compression) { @@ -830,7 +803,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) // skip and ignore comments/extra fields if ((fseek(handle, lump_p->position, SEEK_SET) != 0) || (fread(&zlentry, 1, sizeof(zlentry_t), handle) < sizeof(zlentry_t))) { - CONS_Alert(CONS_ERROR, "Local headers for lump %s are corrupt\n", lump_p->fullname); + CONS_Alert(CONS_ERROR, "Local headers for lump %s are corrupt\n", strbuf_get(lumpnamebuf, lump_p->fullname)); Z_Free(lumpinfo); return NULL; } @@ -1064,6 +1037,10 @@ INT32 W_InitMultipleFiles(char **filenames, boolean addons) INT32 rc = 1; INT32 overallrc = 1; + // this is the first W_ function called so put this here I guess + if (lumpnamebuf == NULL) + lumpnamebuf = strbuf_alloc(); + // will be realloced as lumps are added for (; *filenames; filenames++) { @@ -1105,7 +1082,7 @@ const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump) if (lump >= wadfiles[wad]->numlumps || !TestValidLump(wad, 0)) return NULL; - return wadfiles[wad]->lumpinfo[lump].name; + return strbuf_get(lumpnamebuf, wadfiles[wad]->lumpinfo[lump].longname); } const char *W_CheckNameForNum(lumpnum_t lumpnum) @@ -1118,7 +1095,7 @@ static const char *W_CheckFullNameForNumPwad(UINT16 wad, UINT16 lump) if (lump >= wadfiles[wad]->numlumps || !TestValidLump(wad, 0)) return NULL; - return wadfiles[wad]->lumpinfo[lump].fullname; + return strbuf_get(lumpnamebuf, wadfiles[wad]->lumpinfo[lump].fullname); } static const char *W_CheckFullNameForNum(lumpnum_t lumpnum) @@ -1170,7 +1147,7 @@ UINT16 W_CheckNumForMapPwad(const char *name, UINT32 hash, UINT16 wad, UINT16 st continue; // Not the name? (always use longname, even in wads, to accomodate WADNAME) - if (strcasecmp(name, (wadfiles[wad]->lumpinfo + i)->longname)) + if (strcasecmp(name, strbuf_get(lumpnamebuf, wadfiles[wad]->lumpinfo[i].longname))) continue; // Not a header? @@ -1196,7 +1173,7 @@ UINT16 W_CheckNumForMapPwad(const char *name, UINT32 hash, UINT16 wad, UINT16 st continue; // Not the name? - if (strcasecmp(name, (wadfiles[wad]->lumpinfo + i)->longname)) + if (strcasecmp(name, strbuf_get(lumpnamebuf, wadfiles[wad]->lumpinfo[i].longname))) continue; #if 0 @@ -1242,7 +1219,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) - if (lump_p->hash == hash && !strncmp(lump_p->name, uname, sizeof(uname) - 1)) + if (lump_p->hash == hash && !strncmp(strbuf_get(lumpnamebuf, lump_p->longname), uname, sizeof(uname) - 1)) return i; } @@ -1281,7 +1258,7 @@ UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) { if (lump_p->hash != hash) continue; - if (strcmp(lump_p->longname, uname)) + if (strcmp(strbuf_get(lumpnamebuf, lump_p->longname), uname)) continue; return i; } @@ -1320,7 +1297,7 @@ UINT16 W_CheckNumForLongNamePwadNoUpper(const char *name, UINT16 wad, UINT16 sta { if (lump_p->hash != hash) continue; - if (strcmp(lump_p->longname, name)) + if (strcmp(strbuf_get(lumpnamebuf, lump_p->longname), name)) continue; return i; } @@ -1350,10 +1327,10 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum name_length = strlen(name); for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) { - if (strnicmp(name, lump_p->fullname, name_length) == 0) + if (strnicmp(name, strbuf_get(lumpnamebuf, lump_p->fullname), name_length) == 0) { /* SLADE is special and puts a single directory entry. Skip that. */ - if (strlen(lump_p->fullname) == name_length) + if (strlen(strbuf_get(lumpnamebuf, lump_p->fullname)) == name_length) i++; break; } @@ -1370,7 +1347,7 @@ UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump) lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) { - if (strnicmp(name, lump_p->fullname, strlen(name))) + if (strnicmp(name, strbuf_get(lumpnamebuf, lump_p->fullname), strlen(name))) break; } return i; @@ -1384,7 +1361,7 @@ UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump) lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) { - if (!strnicmp(name, lump_p->fullname, strlen(name))) + if (!strnicmp(name, strbuf_get(lumpnamebuf, lump_p->fullname), strlen(name))) { return i; } @@ -1659,7 +1636,7 @@ UINT8 W_LumpExists(const char *name) { lumpinfo_t *lump_p = wadfiles[i]->lumpinfo; for (j = 0; j < wadfiles[i]->numlumps; ++j, ++lump_p) - if (fastcmp(lump_p->longname, name)) + if (fastcmp(strbuf_get(lumpnamebuf, lump_p->longname), name)) return true; } return false; @@ -1690,7 +1667,7 @@ boolean W_IsLumpWad(lumpnum_t lumpnum) { if (wadfiles[WADFILENUM(lumpnum)]->type == RET_PK3) { - const char *lumpfullName = (wadfiles[WADFILENUM(lumpnum)]->lumpinfo + LUMPNUM(lumpnum))->fullname; + const char *lumpfullName = strbuf_get(lumpnamebuf, (wadfiles[WADFILENUM(lumpnum)]->lumpinfo + LUMPNUM(lumpnum))->fullname); if (strlen(lumpfullName) < 4) return false; // can't possibly be a WAD can it? @@ -1708,7 +1685,7 @@ boolean W_IsLumpFolder(UINT16 wad, UINT16 lump) { if (wadfiles[wad]->type == RET_PK3) { - const char *name = wadfiles[wad]->lumpinfo[lump].fullname; + const char *name = strbuf_get(lumpnamebuf, wadfiles[wad]->lumpinfo[lump].fullname); return (name[strlen(name)-1] == '/'); // folders end in '/' } @@ -1751,7 +1728,7 @@ boolean W_NeedPaletteRemapPwad(UINT16 wad, UINT16 lump, boolean ignorecache) // ugh, palette textures... // never do remapping on them; PaletteTextureHack handles that unsigned num; - const char *name = (wadfiles[wad]->lumpinfo + lump)->longname; + const char *name = strbuf_get(lumpnamebuf, (wadfiles[wad]->lumpinfo + lump)->longname); if (sscanf(name, "~%03u", &num) && num < 256) return false; else diff --git a/src/w_wad.h b/src/w_wad.h index 6449027e3..4c37d989f 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -18,6 +18,8 @@ #include "hardware/hw_data.h" #endif +#include "strbuf.h" + #ifdef __cplusplus extern "C" { #endif @@ -66,11 +68,10 @@ struct lumpinfo_t { unsigned long position; // filelump_t filepos unsigned long disksize; // filelump_t size - char name[9]; // filelump_t name[] e.g. "LongEntr" - UINT32 hash; - char *longname; // e.g. "LongEntryName" - char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension" size_t size; // real (uncompressed) size + UINT32 hash; + UINT32 longname; // e.g. "LongEntryName" + UINT32 fullname; // e.g. "Folder/Subfolder/LongEntryName.extension" compmethod compression; // lump compression method }; @@ -106,6 +107,8 @@ void* vres_GetPatch(virtlump_t *vlump, INT32 tag); #define lumpcache_t void * +extern strbuf_t *lumpnamebuf; + // Resource type of the WAD. Yeah, I know this sounds dumb, but I'll leave it like this until I clean up the code further. typedef enum restype {