From cd2bb2b30032d302a5718eadd14aa1b05270767d Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 1 Sep 2022 18:44:29 +0100 Subject: [PATCH] Extra profile menu improvements * Don't allow creation/loading of more profiles than the game supports. * Add a few missing M_SetMenuDelay()'s * Fix PRF%c default name generation issues * There could still be an infinite loop if MAXPROFILES is ever increased >= 26... but we can handle that one later. --- src/k_menufunc.c | 16 +++++++++++++--- src/k_profiles.c | 12 +++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/k_menufunc.c b/src/k_menufunc.c index a09ddadda..99a1d0d4e 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -4702,9 +4702,15 @@ static void M_StartEditProfile(INT32 c) void M_HandleProfileSelect(INT32 ch) { const UINT8 pid = 0; - const INT32 maxp = PR_GetNumProfiles(); + INT32 maxp = PR_GetNumProfiles(); + boolean creatable = (maxp < MAXPROFILES); (void) ch; + if (!creatable) + { + maxp = MAXPROFILES; + } + if (menucmd[pid].dpad_lr > 0) { optionsmenu.profilen++; @@ -4749,7 +4755,7 @@ void M_HandleProfileSelect(INT32 ch) M_SetMenuDelay(pid); return; } - else if (optionsmenu.profilen == maxp && gamestate != GS_MENU) + else if (creatable && optionsmenu.profilen == maxp && gamestate != GS_MENU) { S_StartSound(NULL, sfx_s3k7b); M_StartMessage(M_GetText("Cannot create a new profile\nmid-game. Return to the\ntitle screen first."), NULL, MM_NOTHING); @@ -4763,7 +4769,7 @@ void M_HandleProfileSelect(INT32 ch) else { // We're on the profile selection screen. - if (optionsmenu.profilen == maxp) + if (creatable && optionsmenu.profilen == maxp) { M_StartEditProfile(MA_YES); M_SetMenuDelay(pid); @@ -4790,6 +4796,7 @@ void M_HandleProfileSelect(INT32 ch) { optionsmenu.resetprofilemenu = true; M_GoBack(0); + M_SetMenuDelay(pid); } if (menutransition.tics == 0 && optionsmenu.resetprofile) @@ -4859,6 +4866,7 @@ boolean M_ProfileEditInputs(INT32 ch) M_SetupNextMenu(&MAIN_ProfilesDef, false); else M_GoBack(0); + M_SetMenuDelay(pid); } return true; } @@ -4910,6 +4918,7 @@ void M_ConfirmProfile(INT32 choice) { M_ProfileEditExit(); M_GoBack(0); + M_SetMenuDelay(pid); } else { @@ -5186,6 +5195,7 @@ boolean M_ProfileControlsInputs(INT32 ch) else if (M_MenuBackPressed(pid)) { M_ProfileControlsConfirm(0); + M_SetMenuDelay(pid); return true; } diff --git a/src/k_profiles.c b/src/k_profiles.c index 34648268a..e88ce6b9c 100644 --- a/src/k_profiles.c +++ b/src/k_profiles.c @@ -161,10 +161,13 @@ void PR_InitNewProfile(void) UINT8 i; boolean nameok = false; + pname[4] = '\0'; + // When deleting profile, it's possible to do some pretty wacko stuff that would lead a new fresh profile to share the same name as another profile we have never changed the name of. + // This could become an infinite loop if MAXPROFILES >= 26. while (!nameok) { - strcpy(pname, va("PRF%c", 'A'+usenum-1)); + pname[3] = 'A'+usenum; for (i = 0; i < numprofiles; i++) { @@ -172,8 +175,8 @@ void PR_InitNewProfile(void) if (!strcmp(pr->profilename, pname)) { usenum++; - if (usenum > 'Z' -1) - usenum = 'A'; + if (pname[3] == 'Z') + usenum = 0; break; } @@ -237,6 +240,9 @@ void PR_LoadProfiles(void) fread(&numprofiles, sizeof numprofiles, 1, f); + if (numprofiles > MAXPROFILES) + numprofiles = MAXPROFILES; + for (i = PROFILE_GUEST+1; i < numprofiles; ++i) { profilesList[i] = Z_Malloc(sizeof(profile_t), PU_STATIC, NULL);