Fixed resetting CVARs via internal menu CCMDs

This restores functionality of reset to defaults/saved menu options
This commit is contained in:
alexey.lysiuk 2018-01-30 16:32:16 +02:00
parent d9323b9740
commit 35508bc8fb

View file

@ -157,11 +157,6 @@ void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type)
{ {
return; return;
} }
else if (UnsafeExecutionContext && !(GetFlags() & CVAR_MOD))
{
Printf(TEXTCOLOR_RED "Cannot set console variable" TEXTCOLOR_GOLD " %s " TEXTCOLOR_RED "from unsafe command\n", GetName());
return;
}
else if ((Flags & CVAR_LATCH) && gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP) else if ((Flags & CVAR_LATCH) && gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP)
{ {
FLatchedValue latch; FLatchedValue latch;
@ -1712,6 +1707,16 @@ void C_ArchiveCVars (FConfigFile *f, uint32_t filter)
EXTERN_CVAR(Bool, sv_cheats); EXTERN_CVAR(Bool, sv_cheats);
static bool IsUnsafe(const FBaseCVar *const var)
{
const bool unsafe = UnsafeExecutionContext && !(var->GetFlags() & CVAR_MOD);
if (unsafe)
{
Printf(TEXTCOLOR_RED "Cannot set console variable" TEXTCOLOR_GOLD " %s " TEXTCOLOR_RED "from unsafe command\n", var->GetName());
}
return unsafe;
}
void FBaseCVar::CmdSet (const char *newval) void FBaseCVar::CmdSet (const char *newval)
{ {
if ((GetFlags() & CVAR_CHEAT) && !sv_cheats) if ((GetFlags() & CVAR_CHEAT) && !sv_cheats)
@ -1719,6 +1724,10 @@ void FBaseCVar::CmdSet (const char *newval)
Printf("sv_cheats must be true to set this console variable.\n"); Printf("sv_cheats must be true to set this console variable.\n");
return; return;
} }
else if (IsUnsafe(this))
{
return;
}
UCVarValue val; UCVarValue val;
@ -1805,6 +1814,11 @@ CCMD (toggle)
{ {
if ( (var = FindCVar (argv[1], &prev)) ) if ( (var = FindCVar (argv[1], &prev)) )
{ {
if (IsUnsafe(var))
{
return;
}
val = var->GetGenericRep (CVAR_Bool); val = var->GetGenericRep (CVAR_Bool);
val.Bool = !val.Bool; val.Bool = !val.Bool;
var->SetGenericRep (val, CVAR_Bool); var->SetGenericRep (val, CVAR_Bool);