Fixed fresh profiles being able to have duplicate names after deleting other Profiles

This commit is contained in:
SinnamonLat 2022-05-21 18:04:43 +02:00
parent df64ea9ce6
commit c58624bca2
2 changed files with 26 additions and 2 deletions

View file

@ -4579,7 +4579,7 @@ boolean M_ProfileControlsInputs(INT32 ch)
optionsmenu.profile->kickstartaccel = cv_dummyprofilekickstart.value; // Make sure to save kickstart accel.
// Reapply player 1's real profile.
if (cv_currprofile.value)
if (cv_currprofile.value > -1)
PR_ApplyProfile(cv_lastprofile[0].value, 0);
return true;

View file

@ -108,8 +108,32 @@ void PR_InitNewProfile(void)
{
char pname[PROFILENAMELEN+1] = "PRF";
profile_t *dprofile;
UINT8 usenum = numprofiles-1;
UINT8 i;
boolean nameok = false;
strcpy(pname, va("PRF%c", 'A'+numprofiles-1));
// 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.
while (!nameok)
{
strcpy(pname, va("PRF%c", 'A'+usenum-1));
for (i = 0; i < numprofiles; i++)
{
profile_t *pr = PR_GetProfile(i);
if (!strcmp(pr->profilename, pname))
{
usenum++;
if (usenum > 'Z' -1)
usenum = 'A';
break;
}
// if we got here, then it means the name is okay!
if (i == numprofiles-1)
nameok = true;
}
}
dprofile = PR_MakeProfile(pname, PROFILEDEFAULTPNAME, PROFILEDEFAULTSKIN, PROFILEDEFAULTCOLOR, PROFILEDEFAULTFOLLOWER, PROFILEDEFAULTFOLLOWERCOLOR, gamecontroldefault);
PR_AddProfile(dprofile);