From a24679bd2ac73cc99c9168cc5e30812fa917d2e0 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Thu, 16 Jan 2025 12:31:45 +0700 Subject: [PATCH 1/2] id24: implement DEHACKED "Carousel icon" weapon block field --- src/d_deh.c | 11 ++++++++++- src/d_items.h | 1 + src/st_carousel.c | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/d_deh.c b/src/d_deh.c index c3334e6dd..150d8f0a9 100644 --- a/src/d_deh.c +++ b/src/d_deh.c @@ -1503,6 +1503,8 @@ char *deh_weapon[] = // mbf21 "Ammo per shot", // .ammopershot "MBF21 Bits", // .flags + // id24 + "Carousel icon", // .carouselicon }; // CHEATS - Dehacked block name = "Cheat" @@ -2566,7 +2568,14 @@ void deh_procWeapon(DEHFILE *fpin, FILE* fpout, char *line) weaponinfo[indexnum].flags = value; } - else + else + if (!strcasecmp(key, deh_weapon[8])) // Carousel icon + { + char *lump = calloc(1, 9); + M_CopyLumpName(lump, ptr_lstrip(strval)); + weaponinfo[indexnum].carouselicon = lump; + } + else if (fpout) fprintf(fpout,"Invalid weapon string index for '%s'\n",key); } return; diff --git a/src/d_items.h b/src/d_items.h index a120a69b9..b53624806 100644 --- a/src/d_items.h +++ b/src/d_items.h @@ -59,6 +59,7 @@ typedef struct int flags; // id24 int slot; + const char *carouselicon; } weaponinfo_t; extern weaponinfo_t weaponinfo[NUMWEAPONS+2]; diff --git a/src/st_carousel.c b/src/st_carousel.c index a0fabd5c4..e01522137 100644 --- a/src/st_carousel.c +++ b/src/st_carousel.c @@ -13,6 +13,7 @@ #include +#include "d_items.h" #include "d_player.h" #include "doomdef.h" #include "doomtype.h" @@ -164,8 +165,17 @@ void ST_UpdateCarousel(player_t *player) static void DrawIcon(int x, int y, sbarelem_t *elem, weapon_icon_t icon) { char lump[9] = {0}; - M_snprintf(lump, sizeof(lump), "%s%d", names[icon.weapon], - icon.state == wpi_selected); + const char *name; + if (weaponinfo[icon.weapon].carouselicon) + { + name = weaponinfo[icon.weapon].carouselicon; + } + else + { + name = names[icon.weapon]; + } + + M_snprintf(lump, sizeof(lump), "%s%d", name, icon.state == wpi_selected); patch_t *patch = V_CachePatchName(lump, PU_CACHE); From 6ddcd9d6d11b1350fe837edf7fb8eedbaa04b65b Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Thu, 16 Jan 2025 12:53:07 +0700 Subject: [PATCH 2/2] check name length --- src/d_deh.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/d_deh.c b/src/d_deh.c index 150d8f0a9..8568257ec 100644 --- a/src/d_deh.c +++ b/src/d_deh.c @@ -2571,9 +2571,15 @@ void deh_procWeapon(DEHFILE *fpin, FILE* fpout, char *line) else if (!strcasecmp(key, deh_weapon[8])) // Carousel icon { - char *lump = calloc(1, 9); - M_CopyLumpName(lump, ptr_lstrip(strval)); - weaponinfo[indexnum].carouselicon = lump; + char candidate[9] = {0}; + M_CopyLumpName(candidate, ptr_lstrip(strval)); + int len = strlen(candidate); + if (len < 1 || len > 7) + { + if (fpout) fprintf(fpout,"Bad length for carousel icon name '%s'\n",candidate); + continue; + } + weaponinfo[indexnum].carouselicon = M_StringDuplicate(candidate); } else if (fpout) fprintf(fpout,"Invalid weapon string index for '%s'\n",key); @@ -3406,7 +3412,7 @@ void rstrip(char *s) // strip trailing whitespace // char *ptr_lstrip(char *p) // point past leading whitespace { - while (*p >= 0 && isspace(*p)) + while (*p && isspace(*p)) p++; return p; }