From 1d6ad4415a5d3706c49a90808e1f27dbd592ac44 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 16 Oct 2025 11:02:34 -0400 Subject: [PATCH] Move rival insertion to R_ProcessPatchableFields --- src/r_skins.c | 89 ++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/src/r_skins.c b/src/r_skins.c index 78b0ecda0..f0c6605a1 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -786,8 +786,56 @@ static boolean R_ProcessPatchableFields(skin_t *skin, char *stoken, char *value) { boolean compat = wadfiles[skin->wadnum]->compatmode; + if (!stricmp(stoken, "rivals")) + { + size_t len = strlen(value); + size_t i; + char rivalname[SKINNAMESIZE+1] = {0}; + UINT8 pos = 0; + UINT8 numrivals = 0; + + // Can't use strtok, because the above function's already using it. + // Using it causes it to upset the saved pointer, + // corrupting the reading for the rest of the file. + + // So instead we get to crawl through the value, character by character, + // and write it down as we go, until we hit a comma or the end of the string. + // Yaaay. + + for (i = 0; i <= len; i++) + { + if (numrivals >= SKINRIVALS) + { + break; + } + + if (value[i] == ',' || i == len) + { + if (pos == 0) + continue; + + STRBUFCPY(skin->rivals[numrivals], rivalname); + strlwr(skin->rivals[numrivals]); + numrivals++; + + if (i == len) + break; + + for (; pos > 0; pos--) + { + rivalname[pos] = '\0'; + } + + continue; + } + + rivalname[pos] = value[i]; + pos++; + } + } + // custom translation table - if (!stricmp(stoken, "startcolor")) + else if (!stricmp(stoken, "startcolor")) skin->starttranscolor = compat ? R_GetPaletteRemap(atoi(value)) : atoi(value); #define FULLPROCESS(field) else if (!stricmp(stoken, #field)) skin->field = get_number(value); @@ -983,45 +1031,6 @@ void R_AddSkins(UINT16 wadnum) STRBUFCPY(skin->realname, value); SYMBOLCONVERT(skin->realname) } - else if (!stricmp(stoken, "rivals")) - { - size_t len = strlen(value); - size_t i; - char rivalname[SKINNAMESIZE] = ""; - UINT8 pos = 0; - UINT8 numrivals = 0; - - // Can't use strtok, because this function's already using it. - // Using it causes it to upset the saved pointer, - // corrupting the reading for the rest of the file. - - // So instead we get to crawl through the value, character by character, - // and write it down as we go, until we hit a comma or the end of the string. - // Yaaay. - - for (i = 0; i <= len; i++) - { - if (numrivals >= SKINRIVALS) - { - break; - } - - if (value[i] == ',' || i == len) - { - STRBUFCPY(skin->rivals[numrivals], rivalname); - strlwr(skin->rivals[numrivals]); - numrivals++; - - memset(rivalname, 0, sizeof (rivalname)); - pos = 0; - - continue; - } - - rivalname[pos] = value[i]; - pos++; - } - } else if (!R_ProcessPatchableFields(skin, stoken, value)) CONS_Debug(DBG_SETUP, "R_AddSkins: Unknown keyword '%s' in S_SKIN lump #%d (WAD %s)\n", stoken, lump, wadfiles[wadnum]->filename);