Skip to content

Commit

Permalink
add validation for some arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rfomin committed Jul 10, 2022
1 parent e2c901e commit 67f1f14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2137,10 +2137,19 @@ void D_DoomMain(void)
//

if ((p = M_CheckParm ("-skill")) && p < myargc-1)
{
startskill = myargv[p+1][0]-'1';
autostart = true;
}
{
if (M_ParmStrToInt(myargv[p+1], (int *)&startskill) &&
startskill > sk_none && startskill <= sk_nightmare)
{
autostart = true;
}
else
{

This comment has been minimized.

Copy link
@fabiangreffrath

fabiangreffrath Jul 10, 2022

Owner

But -skill 0 is still possible, right?

This comment has been minimized.

Copy link
@rfomin

rfomin Jul 10, 2022

Author Collaborator

I fixed it. But -skill 0 doesn't work in Woof/PrBoom+, only in Choco/Crispy.

This comment has been minimized.

Copy link
@fabiangreffrath

fabiangreffrath Jul 10, 2022

Owner

Should be similar to -nomonsters, but doesn't spawn any items, right?

This comment has been minimized.

Copy link
@rfomin

rfomin Jul 10, 2022

Author Collaborator

From my testing -skill 0 doesn't work at all, all monsters and items still spawn.

I_Error("Wrong -skill parameter '%s', valid values are 1-5 "
"(1: easiest, 5: hardest). "
"A skill of 0 disables all monsters.", myargv[p+1]);
}
}

//!
// @category game
Expand All @@ -2152,9 +2161,16 @@ void D_DoomMain(void)

if ((p = M_CheckParm ("-episode")) && p < myargc-1)
{
startepisode = myargv[p+1][0]-'0';
startmap = 1;
autostart = true;
if (M_ParmStrToInt(myargv[p+1], &startepisode) &&
startepisode >= 1 && startepisode <= 4)
{
startmap = 1;
autostart = true;
}
else
{
I_Error("Wrong -episode parameter '%s', should be 1-4", myargv[p+1]);
}
}

//!
Expand All @@ -2167,9 +2183,9 @@ void D_DoomMain(void)

if ((p = M_CheckParm ("-timer")) && p < myargc-1 && deathmatch)
{
int time = atoi(myargv[p+1]);
timelimit = time;
printf("Levels will end after %d minute%s.\n", time, time>1 ? "s" : "");
if (!M_ParmStrToInt(myargv[p+1], &timelimit))
I_Error("Wrong -timer parameter '%s', valid value n minutes", myargv[p+1]);
printf("Levels will end after %d minute%s.\n", timelimit, timelimit>1 ? "s" : "");
}

//!
Expand Down
3 changes: 3 additions & 0 deletions src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,9 @@ void G_ReloadDefaults(void)
int l = G_GetNamedComplevel(myargv[i+1]);
if (l > -1)
demo_version = l;
else
I_Error("Wrong -complevel parameter '%s', "
"valid values are 'vanilla', 'boom', 'mbf', 'mbf21'", myargv[i+1]);
}
}

Expand Down

0 comments on commit 67f1f14

Please sign in to comment.