From a2bf7163dd99f5d3e1bb64db850a2ca22c544dcf Mon Sep 17 00:00:00 2001 From: Brad Harding Date: Mon, 28 Oct 2024 16:54:58 +1100 Subject: [PATCH] Fix crash when setting `health` to negative value --- src/c_cmds.c | 6 +++++- src/st_lib.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/c_cmds.c b/src/c_cmds.c index 4c2d3abff..341b9d67e 100644 --- a/src/c_cmds.c +++ b/src/c_cmds.c @@ -10112,7 +10112,8 @@ static void player_cvars_func2(char *cmd, char *parms) { if (*parms) { - if (sscanf(parms, "%10i", &value) == 1 && value != viewplayer->health) + if (sscanf(parms, "%10i", &value) == 1 + && (!negativehealth && value != viewplayer->health) || (negativehealth && value != viewplayer->negativehealth)) { value = BETWEEN(((viewplayer->cheats & CF_BUDDHA) ? 1 : HUD_NUMBER_MIN), value, maxhealth); @@ -10127,6 +10128,7 @@ static void player_cvars_func2(char *cmd, char *parms) viewplayer->damagecount = viewplayer->health - value; viewplayer->health = value; + viewplayer->negativehealth = value; viewplayer->mo->health = value; } else @@ -10150,6 +10152,7 @@ static void player_cvars_func2(char *cmd, char *parms) { viewplayer->damagecount = viewplayer->health - value; viewplayer->health = value; + viewplayer->negativehealth = value; viewplayer->mo->health = value; healthcvar = true; @@ -10165,6 +10168,7 @@ static void player_cvars_func2(char *cmd, char *parms) { P_UpdateHealthStat(value - viewplayer->health); viewplayer->health = value; + viewplayer->negativehealth = value; viewplayer->mo->health = value; P_AddBonus(); S_StartSound(viewplayer->mo, sfx_itemup); diff --git a/src/st_lib.c b/src/st_lib.c index ef3517e10..8c08f5d4d 100644 --- a/src/st_lib.c +++ b/src/st_lib.c @@ -171,7 +171,7 @@ void STlib_UpdateBigHealthNum(st_number_t *n) const int y = n->y; const int width = SHORT(n->p[0]->width); - if (negativehealth && minuspatch && !viewplayer->health && viewplayer->negativehealth < 0) + if (negativehealth && minuspatch && viewplayer->negativehealth < 0) { int offset = 0;