From 2aa36b5d326537a62138fba59a3fb8b0dbc4a24b Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 6 Jun 2023 16:40:09 +0100 Subject: [PATCH 1/2] M_CharacterSelectInit: Fix a heaping of bugs - Fix a softlock caused by commit 8d9b42e4 (!!) - If your profile's skin was locked, fix a softlock where control was never restored - If your profile's skin didn't exist, fix an invalid skin id set - Just straight up flatten out the nested complexity of this function --- src/menus/play-char-select.c | 90 +++++++++++++----------------------- 1 file changed, 32 insertions(+), 58 deletions(-) diff --git a/src/menus/play-char-select.c b/src/menus/play-char-select.c index 0110870d9..5edd47f76 100644 --- a/src/menus/play-char-select.c +++ b/src/menus/play-char-select.c @@ -317,6 +317,9 @@ static void M_SetupProfileGridPos(setup_player_t *p) INT32 i = R_SkinAvailable(pr->skinname); INT32 alt = 0; // Hey it's my character's name! + if (i == -1) + i = 0; + // While we're here, read follower values. p->followern = K_FollowerAvailable(pr->follower); @@ -349,6 +352,9 @@ static void M_SetupMidGameGridPos(setup_player_t *p, UINT8 num) INT32 i = R_SkinAvailable(cv_skin[num].zstring); INT32 alt = 0; // Hey it's my character's name! + if (i == -1) + i = 0; + // While we're here, read follower values. p->followern = cv_follower[num].value; p->followercolor = cv_followercolor[num].value; @@ -377,20 +383,6 @@ void M_CharacterSelectInit(void) UINT8 i, j; setup_maxpage = 0; - // While we're editing profiles, don't unset the devices for p1 - if (gamestate == GS_MENU) - { - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - // Un-set devices for all players if not editing profile - if (!optionsmenu.profile) - { - G_SetDeviceForPlayer(i, -1); - CONS_Printf("M_CharacterSelectInit: Device for %d set to %d\n", i, -1); - } - } - } - memset(setup_chargrid, -1, sizeof(setup_chargrid)); for (i = 0; i < 9; i++) { @@ -404,8 +396,6 @@ void M_CharacterSelectInit(void) memset(setup_explosions, 0, sizeof(setup_explosions)); setup_animcounter = 0; - UINT32 localskinhash[MAXSPLITSCREENPLAYERS]; - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { // Default to no follower / match colour. @@ -413,12 +403,33 @@ void M_CharacterSelectInit(void) setup_player[i].followercategory = -1; setup_player[i].followercolor = FOLLOWERCOLOR_MATCH; - // Set default selected profile to the last used profile for each player: - // (Make sure we don't overshoot it somehow if we deleted profiles or whatnot) - setup_player[i].profilen = min(cv_lastprofile[i].value, PR_GetNumProfiles()); + // If we're on prpfile select, skip straight to CSSTEP_CHARS + // do the same if we're midgame, but make sure to consider splitscreen properly. + if (optionsmenu.profile && i == 0) + { + setup_player[i].profilen = optionsmenu.profilen; + //PR_ApplyProfileLight(setup_player[i].profilen, 0); + M_SetupProfileGridPos(&setup_player[i]); + setup_player[i].mdepth = CSSTEP_CHARS; + } + else + { + // Set default selected profile to the last used profile for each player: + // (Make sure we don't overshoot it somehow if we deleted profiles or whatnot) + setup_player[i].profilen = min(cv_lastprofile[i].value, PR_GetNumProfiles()); - // Assistant for comparisons. - localskinhash[i] = quickncasehash(cv_skin[i].string, SKINNAMESIZE); + if (gamestate != GS_MENU && i <= splitscreen) + { + M_SetupMidGameGridPos(&setup_player[i], i); + setup_player[i].mdepth = CSSTEP_CHARS; + } + else + { + // Un-set devices + G_SetDeviceForPlayer(i, -1); + CONS_Printf("M_CharacterSelectInit: Device for %d set to %d\n", i, -1); + } + } } for (i = 0; i < numskins; i++) @@ -438,43 +449,6 @@ void M_CharacterSelectInit(void) setup_maxpage = max(setup_maxpage, setup_chargrid[x][y].numskins-1); } - - for (j = 0; j < MAXSPLITSCREENPLAYERS; j++) - { - // See also R_SkinAvailable - - if (localskinhash[j] != skins[i].namehash) - continue; - - if (!stricmp(cv_skin[j].string, skins[i].name)) - continue; - - { - setup_player[j].gridx = x; - setup_player[j].gridy = y; - setup_player[j].color = skins[i].prefcolor; - - // If we're on prpfile select, skip straight to CSSTEP_CHARS - // do the same if we're midgame, but make sure to consider splitscreen properly. - if ((optionsmenu.profile && j == 0) || (gamestate != GS_MENU && j <= splitscreen)) - { - if (optionsmenu.profile) // In menu, setting up profile character/follower - { - setup_player[j].profilen = optionsmenu.profilen; - PR_ApplyProfileLight(setup_player[j].profilen, 0); - M_SetupProfileGridPos(&setup_player[j]); - } - 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; - M_SetupMidGameGridPos(&setup_player[j], j); - } - - // Don't reapply the profile here, it was already applied. - setup_player[j].mdepth = CSSTEP_CHARS; - } - } - } } setup_numfollowercategories = 0; From 533433d41fe8878ec4aff5f932f2a34ac979819f Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 6 Jun 2023 16:45:45 +0100 Subject: [PATCH 2/2] play-char-select.c: We haven't had problems with devices for a while, so #define away all the device handling messages to reduce the spurious console noise. --- src/menus/play-char-select.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/menus/play-char-select.c b/src/menus/play-char-select.c index 5edd47f76..9e7d4ca60 100644 --- a/src/menus/play-char-select.c +++ b/src/menus/play-char-select.c @@ -7,6 +7,8 @@ #include "../k_grandprix.h" // K_CanChangeRules #include "../m_cond.h" // Condition Sets +//#define CHARSELECT_DEVICEDEBUG + menuitem_t PLAY_CharSelect[] = { {IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, @@ -427,7 +429,9 @@ void M_CharacterSelectInit(void) { // Un-set devices G_SetDeviceForPlayer(i, -1); +#ifdef CHARSELECT_DEVICEDEBUG CONS_Printf("M_CharacterSelectInit: Device for %d set to %d\n", i, -1); +#endif } } } @@ -603,13 +607,17 @@ static boolean M_HandlePressStart(setup_player_t *p, UINT8 num) } G_SetDeviceForPlayer(num, device); +#ifdef CHARSELECT_DEVICEDEBUG CONS_Printf("M_HandlePressStart: Device for %d set to %d\n", num, device); +#endif for (j = num + 1; j < MAXSPLITSCREENPLAYERS; j++) { // Un-set devices for other players. G_SetDeviceForPlayer(j, -1); +#ifdef CHARSELECT_DEVICEDEBUG CONS_Printf("M_HandlePressStart: Device for %d set to %d\n", j, -1); +#endif } //setup_numplayers++; @@ -677,7 +685,9 @@ static boolean M_HandleCSelectProfile(setup_player_t *p, UINT8 num) } G_SetDeviceForPlayer(num, -1); +#ifdef CHARSELECT_DEVICEDEBUG CONS_Printf("M_HandleCSelectProfile: Device for %d set to %d\n", num, -1); +#endif return true; }