From 1a84f1bcba730c5924debce96473639f0ca7fb67 Mon Sep 17 00:00:00 2001 From: Jaime Ita Passos Date: Tue, 10 Aug 2021 15:17:22 -0300 Subject: [PATCH] Minor changes and fixes --- src/d_player.h | 4 +- src/deh_soc.c | 103 +++++++++++++++++++++++------------------ src/dehacked.c | 22 ++++++--- src/dehacked.h | 1 + src/doomdef.h | 7 +-- src/g_game.c | 2 +- src/hardware/hw_main.c | 2 +- src/hardware/hw_md2.c | 2 +- src/m_menu.h | 4 +- src/r_picformats.c | 9 ++-- src/r_skins.c | 2 +- src/r_skins.h | 4 +- src/r_things.c | 2 +- src/y_inter.c | 8 ++-- 14 files changed, 96 insertions(+), 76 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 54ab34288..1418b7c52 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -375,10 +375,10 @@ typedef struct player_s UINT16 flashcount; UINT16 flashpal; - // Player skin colorshift, 0-15 for which color to draw player. + // Player skin colorshift, which color to draw player. UINT16 skincolor; - INT32 skin; + UINT8 skin; UINT32 availabilities; UINT32 score; // player score diff --git a/src/deh_soc.c b/src/deh_soc.c index 4c63a4d6a..2624d183c 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -187,7 +187,7 @@ void clear_levels(void) P_AllocMapHeader(gamemap-1); } -static boolean findFreeSlot(INT32 *num) +static boolean findCharacterSlot(INT32 *num) { if (description) { @@ -213,30 +213,43 @@ void readPlayer(MYFILE *f, INT32 num) char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); char *word; char *word2; - char *displayname = ZZ_Alloc(MAXLINELEN+1); - INT32 i; boolean slotfound = false; + boolean failure = false; + INT32 i; + + if (num < 0 || num >= MAXCHARACTERSLOTS) + { + deh_warning("Character %d out of range (0 - %d)", num, MAXCHARACTERSLOTS-1); + failure = true; + } + + #define FINDSLOT \ + if (!failure && !slotfound && (slotfound = findCharacterSlot(&num)) == false) { \ + failure = true; \ + deh_warning("Too many characters, ignoring"); \ + } #define SLOTFOUND \ - if (!slotfound && (slotfound = findFreeSlot(&num)) == false) \ - goto done; - - displayname[MAXLINELEN] = '\0'; + FINDSLOT \ + if (failure) \ + continue; do { if (myfgets(s, MAXLINELEN, f)) { + char stringvalue[MAXLINELEN]; + if (s[0] == '\n') break; - for (i = 0; i < MAXLINELEN-3; i++) + stringvalue[0] = '\0'; + + for (i = 0; i < MAXLINELEN-3 && !failure; i++) { - char *tmp; if (s[i] == '=') { - tmp = &s[i+2]; - strncpy(displayname, tmp, SKINNAMESIZE); + strlcpy(stringvalue, &s[i+2], sizeof stringvalue); break; } } @@ -251,7 +264,13 @@ void readPlayer(MYFILE *f, INT32 num) { char *playertext = NULL; - SLOTFOUND + FINDSLOT + + if (failure) + { + ignorelinesuntilhash(f); + continue; + } // A friendly neighborhood alias for brevity's sake #define NOTE_SIZE sizeof(description[num].notes) @@ -271,7 +290,7 @@ void readPlayer(MYFILE *f, INT32 num) myhashfgets(playertext, NOTE_SIZE, f), NOTE_SIZE); } else - strcpy(description[num].notes, ""); + description[num].notes[0] = '\0'; // For some reason, cutting the string did not work above. Most likely due to strcpy or strcat... // It works down here, though. @@ -300,37 +319,32 @@ void readPlayer(MYFILE *f, INT32 num) if (word2[strlen(word2)-1] == '\n') word2[strlen(word2)-1] = '\0'; - i = atoi(word2); if (fastcmp(word, "PICNAME")) { SLOTFOUND strncpy(description[num].picname, word2, 8); } - // new character select else if (fastcmp(word, "DISPLAYNAME")) { + char *cur = NULL; + SLOTFOUND - // replace '#' with line breaks - // (also remove any '\n') + + // Remove any line breaks + cur = strchr(stringvalue, '\n'); + if (cur) + *cur = '\0'; + + // Turn '#' into line breaks + cur = strchr(stringvalue, '#'); + while (cur) { - char *cur = NULL; - - // remove '\n' - cur = strchr(displayname, '\n'); - if (cur) - *cur = '\0'; - - // turn '#' into '\n' - cur = strchr(displayname, '#'); - while (cur) - { - *cur = '\n'; - cur = strchr(cur, '#'); - } + *cur = '\n'; + cur = strchr(cur, '#'); } - // copy final string - strncpy(description[num].displayname, displayname, SKINNAMESIZE); + + strlcpy(description[num].displayname, stringvalue, sizeof description[num].displayname); } else if (fastcmp(word, "OPPOSITECOLOR") || fastcmp(word, "OPPOSITECOLOUR")) { @@ -361,10 +375,12 @@ void readPlayer(MYFILE *f, INT32 num) Because of this, you are allowed to edit any previous entries you like, but only if you signal that you are purposely doing so by disabling and then reenabling the slot. */ - if (i && !slotfound && (slotfound = findFreeSlot(&num)) == false) - goto done; + i = atoi(word2); + if (i && !slotfound && (slotfound = findCharacterSlot(&num)) == false) + failure = true; - description[num].used = (!!i); + if (!failure) + description[num].used = (!!i); } else if (fastcmp(word, "SKINNAME")) { @@ -373,13 +389,12 @@ void readPlayer(MYFILE *f, INT32 num) strlcpy(description[num].skinname, word2, sizeof description[num].skinname); strlwr(description[num].skinname); } - else + else if (!failure) deh_warning("readPlayer %d: unknown word '%s'", num, word); } } while (!myfeof(f)); // finish when the line is empty + #undef FINDSLOT #undef SLOTFOUND -done: - Z_Free(displayname); Z_Free(s); } @@ -920,7 +935,7 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2) INT32 value; #endif char *lastline; - INT32 *skinnumbers = NULL; + UINT8 *skinnumbers = NULL; INT32 foundskins = 0; // allocate a spriteinfo @@ -1010,8 +1025,8 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2) } if (skinnumbers == NULL) - skinnumbers = Z_Malloc(sizeof(INT32) * numskins, PU_STATIC, NULL); - skinnumbers[foundskins] = skinnum; + skinnumbers = Z_Malloc(sizeof(UINT8) * numskins, PU_STATIC, NULL); + skinnumbers[foundskins] = (UINT8)skinnum; foundskins++; } else if (fastcmp(word, "DEFAULT")) @@ -1054,8 +1069,7 @@ void readspriteinfo(MYFILE *f, INT32 num, boolean sprite2) } for (i = 0; i < foundskins; i++) { - size_t skinnum = skinnumbers[i]; - skin_t *skin = skins[skinnum]; + skin_t *skin = skins[skinnumbers[i]]; spriteinfo_t *sprinfo = skin->sprinfo; M_Memcpy(&sprinfo[num], info, sizeof(spriteinfo_t)); } @@ -1121,7 +1135,6 @@ void readsprite2(MYFILE *f, INT32 num) Z_Free(s); } -// copypasted from readPlayer :] void readgametype(MYFILE *f, char *gtname) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); diff --git a/src/dehacked.c b/src/dehacked.c index 7a8e2e9d6..ac9a4a46a 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -169,6 +169,20 @@ static void ignorelines(MYFILE *f) Z_Free(s); } +void ignorelinesuntilhash(MYFILE *f) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '#') + break; + } + } while (!myfeof(f)); + Z_Free(s); +} + static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); @@ -226,13 +240,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) i = 0; if (fastcmp(word, "CHARACTER")) { - if (i >= 0 && i < MAXCHARACTERSLOTS) - readPlayer(f, i); - else - { - deh_warning("Character %d out of range (0 - 31)", i); - ignorelines(f); - } + readPlayer(f, i); continue; } else if (fastcmp(word, "EMBLEM")) diff --git a/src/dehacked.h b/src/dehacked.h index 1b200e246..23765f8b7 100644 --- a/src/dehacked.h +++ b/src/dehacked.h @@ -61,4 +61,5 @@ typedef struct #define myfeof(a) (a->data + a->size <= a->curpos) char *myfgets(char *buf, size_t bufsize, MYFILE *f); char *myhashfgets(char *buf, size_t bufsize, MYFILE *f); +void ignorelinesuntilhash(MYFILE *f); #endif diff --git a/src/doomdef.h b/src/doomdef.h index 5e7df3ecd..cf209bc8a 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -220,10 +220,11 @@ extern char logfilename[1024]; // NOTE: it needs more than this to increase the number of players... #define MAXPLAYERS 32 -#define MAXSKINS 256 -#define MAXCHARACTERSLOTS (MAXSKINS * 2) -#define PLAYERSMASK (MAXPLAYERS-1) #define MAXPLAYERNAME 21 +#define PLAYERSMASK (MAXPLAYERS-1) + +#define MAXSKINS 256 +#define MAXCHARACTERSLOTS (MAXSKINS * 3) #define COLORRAMPSIZE 16 #define MAXCOLORNAME 32 diff --git a/src/g_game.c b/src/g_game.c index 6b3354de7..2908b9f01 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2488,7 +2488,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps) UINT8 laps; UINT8 mare; UINT16 skincolor; - INT32 skin; + UINT8 skin; UINT32 availabilities; tic_t jointime; tic_t quittime; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 66df7d2cd..4913714b1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5359,7 +5359,7 @@ static void HWR_ProjectSprite(mobj_t *thing) } else if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player! { - INT32 skinnum = ((skin_t*)thing->skin)->skinnum; + UINT8 skinnum = ((skin_t*)thing->skin)->skinnum; vis->colormap = R_GetTranslationColormap(skinnum, thing->color, GTC_CACHE); } else diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index b54e14089..06f2ecf34 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1271,7 +1271,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) // 2. draw model with correct position, rotation,... if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) // Use the player MD2 list if the mobj has a skin and is using the player sprites { - INT32 skinnum = ((skin_t*)spr->mobj->skin)->skinnum; + UINT8 skinnum = ((skin_t*)spr->mobj->skin)->skinnum; md2 = &md2_playermodels[skinnum]; sprinfo = &((skin_t *)spr->mobj->skin)->sprinfo[spr->mobj->sprite2]; } diff --git a/src/m_menu.h b/src/m_menu.h index 3e2f6f9ae..b7c5c797b 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -375,10 +375,8 @@ typedef struct patch_t *charpic; UINT8 prev; UINT8 next; - - // new character select char displayname[SKINNAMESIZE+1]; - SINT8 skinnum[2]; + INT16 skinnum[2]; UINT16 oppositecolor; char nametag[8]; patch_t *namepic; diff --git a/src/r_picformats.c b/src/r_picformats.c index 5c2544a7f..3e1ea8eb9 100644 --- a/src/r_picformats.c +++ b/src/r_picformats.c @@ -1498,7 +1498,7 @@ static void R_ParseSpriteInfo(boolean spr2) spritenum_t sprnum = NUMSPRITES; playersprite_t spr2num = NUMPLAYERSPRITES; INT32 i; - INT32 *skinnumbers = NULL; + UINT8 *skinnumbers = NULL; INT32 foundskins = 0; // Sprite name @@ -1597,8 +1597,8 @@ static void R_ParseSpriteInfo(boolean spr2) I_Error("Error parsing SPRTINFO lump: Unknown skin \"%s\"", skinName); if (skinnumbers == NULL) - skinnumbers = Z_Malloc(sizeof(INT32) * numskins, PU_STATIC, NULL); - skinnumbers[foundskins] = skinnum; + skinnumbers = Z_Malloc(sizeof(UINT8) * numskins, PU_STATIC, NULL); + skinnumbers[foundskins] = (UINT8)skinnum; foundskins++; } else if (stricmp(sprinfoToken, "FRAME")==0) @@ -1611,8 +1611,7 @@ static void R_ParseSpriteInfo(boolean spr2) I_Error("Error parsing SPRTINFO lump: No skins specified in this sprite2 definition"); for (i = 0; i < foundskins; i++) { - size_t skinnum = skinnumbers[i]; - skin_t *skin = skins[skinnum]; + skin_t *skin = skins[skinnumbers[i]]; spriteinfo_t *sprinfo = skin->sprinfo; M_Memcpy(&sprinfo[spr2num], info, sizeof(spriteinfo_t)); } diff --git a/src/r_skins.c b/src/r_skins.c index b0dcda035..c4cac6ce2 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -278,7 +278,7 @@ INT32 R_SkinAvailable(const char *name) { // search in the skin list if (!stricmp(skins[i]->name,name)) - return skins[i]->skinnum; + return i; } return -1; } diff --git a/src/r_skins.h b/src/r_skins.h index 67f34aa66..8cf3f640b 100644 --- a/src/r_skins.h +++ b/src/r_skins.h @@ -31,8 +31,8 @@ /// The skin_t struct typedef struct { - char name[SKINNAMESIZE+1]; // INT16 descriptive name of the skin - UINT32 skinnum; + char name[SKINNAMESIZE+1]; // name of the skin + UINT8 skinnum; UINT16 wadnum; skinflags_t flags; diff --git a/src/r_things.c b/src/r_things.c index 69a9eb5e9..b4a45f966 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -764,7 +764,7 @@ UINT8 *R_GetSpriteTranslation(vissprite_t *vis) } else if (!(vis->cut & SC_PRECIP) && vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // This thing is a player! { - INT32 skinnum = ((skin_t*)vis->mobj->skin)->skinnum; + UINT8 skinnum = ((skin_t*)vis->mobj->skin)->skinnum; return R_GetTranslationColormap(skinnum, vis->mobj->color, GTC_CACHE); } else // Use the defaults diff --git a/src/y_inter.c b/src/y_inter.c index 8897d2b99..8a8fcd425 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1617,7 +1617,7 @@ static void Y_CalculateMatchWinners(void) { data.match.scores[data.match.numplayers] = players[i].score; data.match.color[data.match.numplayers] = &players[i].skincolor; - data.match.character[data.match.numplayers] = &players[i].skin; + data.match.character[data.match.numplayers] = players[i].skin; data.match.name[data.match.numplayers] = player_names[i]; data.match.spectator[data.match.numplayers] = players[i].spectator; data.match.num[data.match.numplayers] = i; @@ -1662,7 +1662,7 @@ static void Y_CalculateTimeRaceWinners(void) { data.match.scores[data.match.numplayers] = players[i].realtime; data.match.color[data.match.numplayers] = &players[i].skincolor; - data.match.character[data.match.numplayers] = &players[i].skin; + data.match.character[data.match.numplayers] = players[i].skin; data.match.name[data.match.numplayers] = player_names[i]; data.match.num[data.match.numplayers] = i; } @@ -1788,7 +1788,7 @@ static void Y_CalculateCompetitionWinners(void) strncpy(data.competition.name[data.competition.numplayers], tempname, 9); data.competition.color[data.competition.numplayers] = &players[winner].skincolor; - data.competition.character[data.competition.numplayers] = &players[winner].skin; + data.competition.character[data.competition.numplayers] = players[winner].skin; completed[winner] = true; data.competition.numplayers++; @@ -2110,7 +2110,7 @@ static void Y_AwardSpecialStageBonus(void) if (players[i].gotcontinue) data.spec.continues |= 0x80; data.spec.playercolor = &players[i].skincolor; - data.spec.playerchar = &players[i].skin; + data.spec.playerchar = players[i].skin; } } }