From 6225f60eb210fcdf3341b7233854a6715b241ac0 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 31 Jan 2017 11:05:29 +0200 Subject: [PATCH] Added cheat flag for console variables CVAR with this flag can be set in console or from command line when sv_cheats is enabled There is no such restriction for changing its value from ACS, via SetCVar() and related functions 'cheat' modifier can be used in CVARINFO lump to create variable of this kind --- src/c_cvars.cpp | 8 ++++++++ src/c_cvars.h | 1 + src/d_main.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/c_cvars.cpp b/src/c_cvars.cpp index fe859cb49..11ebf5574 100644 --- a/src/c_cvars.cpp +++ b/src/c_cvars.cpp @@ -1617,8 +1617,16 @@ void C_ArchiveCVars (FConfigFile *f, uint32 filter) } } +EXTERN_CVAR(Bool, sv_cheats); + void FBaseCVar::CmdSet (const char *newval) { + if ((GetFlags() & CVAR_CHEAT) && !sv_cheats) + { + Printf("sv_cheats must be true to set this console variable.\n"); + return; + } + UCVarValue val; // Casting away the const is safe in this case. diff --git a/src/c_cvars.h b/src/c_cvars.h index cf6975b86..98dc71915 100644 --- a/src/c_cvars.h +++ b/src/c_cvars.h @@ -63,6 +63,7 @@ enum CVAR_NOSAVE = 4096, // when used with CVAR_SERVERINFO, do not save var to savegame CVAR_MOD = 8192, // cvar was defined by a mod CVAR_IGNORE = 16384,// do not send cvar across the network/inaccesible from ACS (dummy mod cvar) + CVAR_CHEAT = 32768,// can be set only when sv_cheats is enabled }; union UCVarValue diff --git a/src/d_main.cpp b/src/d_main.cpp index aa90d6c46..e0676b751 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1398,6 +1398,10 @@ void ParseCVarInfo() { cvarflags &= ~CVAR_ARCHIVE; } + else if (stricmp(sc.String, "cheat") == 0) + { + cvarflags |= CVAR_CHEAT; + } else { sc.ScriptError("Unknown cvar attribute '%s'", sc.String);