From 60449b8a26ac0e595374e3288176852edfe7e99e Mon Sep 17 00:00:00 2001 From: SinnamonLat Date: Fri, 20 May 2022 16:47:03 +0200 Subject: [PATCH] Fix crash when editing profile character with existing follower --- src/k_menudraw.c | 33 ++++++++++++++++++--------------- src/k_menufunc.c | 2 +- src/k_profiles.c | 13 +++++++++++++ src/k_profiles.h | 5 +++++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 6d6f6f8f7..8b63f9ff0 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -1399,24 +1399,27 @@ static void M_DrawProfileCard(INT32 x, INT32 y, boolean greyedout, profile_t *p) if (M_DrawCharacterSprite(x-22, y+119, skinnum, V_FLIP, colormap)) V_DrawMappedPatch(x+14, y+66, 0, faceprefix[skinnum][FACE_RANK], colormap); - if (M_DrawFollowerSprite(x-44 +12, y+119, 0, V_FLIP, 0, sp)) + if (sp->mdepth >= CSSTEP_FOLLOWER) { - UINT16 col = (unsigned)p->followercolor; - patch_t *ico = W_CachePatchName(followers[sp->followern].icon, PU_CACHE); - UINT8 *fcolormap; - - switch (col) + if (M_DrawFollowerSprite(x-44 +12, y+119, 0, V_FLIP, 0, sp)) { - case FOLLOWERCOLOR_MATCH: // "Match" - col = sp->color; - break; - case FOLLOWERCOLOR_OPPOSITE: // "Opposite" - col = skincolors[sp->color].invcolor; - break; - } + UINT16 col = (unsigned)p->followercolor; + patch_t *ico = W_CachePatchName(followers[sp->followern].icon, PU_CACHE); + UINT8 *fcolormap; - fcolormap = R_GetTranslationColormap(TC_DEFAULT, col, GTC_MENUCACHE); - V_DrawMappedPatch(x+14+18, y+66, 0, ico, fcolormap); + switch (col) + { + case FOLLOWERCOLOR_MATCH: // "Match" + col = sp->color; + break; + case FOLLOWERCOLOR_OPPOSITE: // "Opposite" + col = skincolors[sp->color].invcolor; + break; + } + + fcolormap = R_GetTranslationColormap(TC_DEFAULT, col, GTC_MENUCACHE); + V_DrawMappedPatch(x+14+18, y+66, 0, ico, fcolormap); + } } if (sp->mdepth == CSSTEP_ALTS || sp->mdepth == CSSTEP_COLORS || sp->mdepth == CSSTEP_FOLLOWERCOLORS) diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 832bd6c0a..ec47dc549 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -2153,7 +2153,7 @@ void M_CharacterSelectInit(void) if (optionsmenu.profile) // In menu, setting up profile character/follower { setup_player[j].profilen = optionsmenu.profilen; - PR_ApplyProfile(setup_player[j].profilen, 0); + PR_ApplyProfileLight(setup_player[j].profilen, 0); } else // gamestate != GS_MENU, in that case, assume this is whatever profile we chose to play with. setup_player[j].profilen = cv_lastprofile[j].value; diff --git a/src/k_profiles.c b/src/k_profiles.c index af7801c2e..9ee9fcf36 100644 --- a/src/k_profiles.c +++ b/src/k_profiles.c @@ -188,6 +188,19 @@ void PR_ApplyProfile(UINT8 profilenum, UINT8 playernum) CV_StealthSetValue(&cv_currprofile, profilenum); } +void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum) +{ + profile_t *p = PR_GetProfile(profilenum); + + CV_StealthSet(&cv_skin[playernum], p->skinname); + CV_StealthSetValue(&cv_playercolor[playernum], p->color); + CV_StealthSet(&cv_playername[playernum], p->playername); + + // Followers + CV_StealthSet(&cv_follower[playernum], p->follower); + CV_StealthSetValue(&cv_followercolor[playernum], p->followercolor); +} + UINT8 PR_GetProfileNum(profile_t *p) { UINT8 i; diff --git a/src/k_profiles.h b/src/k_profiles.h index d50d73bb2..fd05ff1f6 100644 --- a/src/k_profiles.h +++ b/src/k_profiles.h @@ -113,6 +113,11 @@ void PR_LoadProfiles(void); // Applies the given profile's settings to the given player. void PR_ApplyProfile(UINT8 profilenum, UINT8 playernum); +// PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum) +// Similar to PR_ApplyProfile but only applies skin and follower values. +// Controls, kickstartaccel and "current profile" data is *not* modified. +void PR_ApplyProfileLight(UINT8 profilenum, UINT8 playernum); + // PR_GetProfileNum(profile_t *p) // Gets the profile's index # in profilesList UINT8 PR_GetProfileNum(profile_t *p);