mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-27 22:42:57 +00:00
Merge branch 'unsafe_context'
This commit is contained in:
commit
2fddea7bed
10 changed files with 88 additions and 62 deletions
|
@ -558,7 +558,7 @@ void C_UnbindAll ()
|
|||
AutomapBindings.UnbindAll();
|
||||
}
|
||||
|
||||
CCMD (unbindall)
|
||||
UNSAFE_CCMD (unbindall)
|
||||
{
|
||||
C_UnbindAll ();
|
||||
}
|
||||
|
|
|
@ -467,7 +467,7 @@ CCMD (print)
|
|||
}
|
||||
}
|
||||
|
||||
CCMD (exec)
|
||||
UNSAFE_CCMD (exec)
|
||||
{
|
||||
if (argv.argc() < 2)
|
||||
return;
|
||||
|
@ -495,7 +495,7 @@ void execLogfile(const char *fn, bool append)
|
|||
}
|
||||
}
|
||||
|
||||
CCMD (logfile)
|
||||
UNSAFE_CCMD (logfile)
|
||||
{
|
||||
|
||||
if (Logfile)
|
||||
|
@ -651,7 +651,7 @@ CCMD (error)
|
|||
}
|
||||
}
|
||||
|
||||
CCMD (error_fatal)
|
||||
UNSAFE_CCMD (error_fatal)
|
||||
{
|
||||
if (argv.argc() > 1)
|
||||
{
|
||||
|
@ -674,7 +674,7 @@ CCMD (error_fatal)
|
|||
//==========================================================================
|
||||
|
||||
#if !defined(_WIN32) || !defined(_DEBUG)
|
||||
CCMD (crashout)
|
||||
UNSAFE_CCMD (crashout)
|
||||
{
|
||||
*(volatile int *)0 = 0;
|
||||
}
|
||||
|
@ -794,7 +794,7 @@ CCMD (warp)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (load)
|
||||
UNSAFE_CCMD (load)
|
||||
{
|
||||
if (argv.argc() != 2)
|
||||
{
|
||||
|
@ -819,7 +819,7 @@ CCMD (load)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (save)
|
||||
UNSAFE_CCMD (save)
|
||||
{
|
||||
if (argv.argc() < 2 || argv.argc() > 3)
|
||||
{
|
||||
|
|
|
@ -627,7 +627,7 @@ void C_InitConsole (int width, int height, bool ingame)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (atexit)
|
||||
UNSAFE_CCMD (atexit)
|
||||
{
|
||||
if (argv.argc() == 1)
|
||||
{
|
||||
|
|
|
@ -65,7 +65,7 @@ class DWaitingCommand : public DThinker
|
|||
{
|
||||
DECLARE_CLASS (DWaitingCommand, DThinker)
|
||||
public:
|
||||
DWaitingCommand (const char *cmd, int tics);
|
||||
DWaitingCommand (const char *cmd, int tics, bool unsafe);
|
||||
~DWaitingCommand ();
|
||||
void Serialize(FSerializer &arc);
|
||||
void Tick ();
|
||||
|
@ -75,6 +75,7 @@ private:
|
|||
|
||||
char *Command;
|
||||
int TicsLeft;
|
||||
bool IsUnsafe;
|
||||
};
|
||||
|
||||
class DStoredCommand : public DThinker
|
||||
|
@ -126,7 +127,8 @@ FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
|
|||
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
|
||||
Button_AM_ZoomIn, Button_AM_ZoomOut;
|
||||
|
||||
bool ParsingKeyConf, ParsingMenuDef = false;
|
||||
bool ParsingKeyConf;
|
||||
static bool UnsafeExecutionContext;
|
||||
|
||||
// To add new actions, go to the console and type "key <action name>".
|
||||
// This will give you the key value to use in the first column. Then
|
||||
|
@ -187,24 +189,6 @@ static const char *KeyConfCommands[] =
|
|||
"clearplayerclasses"
|
||||
};
|
||||
|
||||
static const char *MenuDefCommands[] =
|
||||
{
|
||||
"snd_reset",
|
||||
"reset2defaults",
|
||||
"reset2saved",
|
||||
"menuconsole",
|
||||
"clearnodecache",
|
||||
"am_restorecolors",
|
||||
"undocolorpic",
|
||||
"special",
|
||||
"puke",
|
||||
"fpuke",
|
||||
"pukename",
|
||||
"event",
|
||||
"netevent",
|
||||
"openmenu"
|
||||
};
|
||||
|
||||
// CODE --------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS(DWaitingCommand, false, false)
|
||||
|
@ -213,19 +197,22 @@ void DWaitingCommand::Serialize(FSerializer &arc)
|
|||
{
|
||||
Super::Serialize (arc);
|
||||
arc("command", Command)
|
||||
("ticsleft", TicsLeft);
|
||||
("ticsleft", TicsLeft)
|
||||
("unsafe", IsUnsafe);
|
||||
}
|
||||
|
||||
DWaitingCommand::DWaitingCommand ()
|
||||
{
|
||||
Command = NULL;
|
||||
TicsLeft = 1;
|
||||
IsUnsafe = false;
|
||||
}
|
||||
|
||||
DWaitingCommand::DWaitingCommand (const char *cmd, int tics)
|
||||
DWaitingCommand::DWaitingCommand (const char *cmd, int tics, bool unsafe)
|
||||
{
|
||||
Command = copystring (cmd);
|
||||
TicsLeft = tics+1;
|
||||
IsUnsafe = unsafe;
|
||||
}
|
||||
|
||||
DWaitingCommand::~DWaitingCommand ()
|
||||
|
@ -240,7 +227,10 @@ void DWaitingCommand::Tick ()
|
|||
{
|
||||
if (--TicsLeft == 0)
|
||||
{
|
||||
const bool wasUnsafe = UnsafeExecutionContext;
|
||||
UnsafeExecutionContext = IsUnsafe;
|
||||
AddCommandString (Command);
|
||||
UnsafeExecutionContext = wasUnsafe;
|
||||
Destroy ();
|
||||
}
|
||||
}
|
||||
|
@ -602,25 +592,6 @@ void C_DoCommand (const char *cmd, int keynum)
|
|||
}
|
||||
}
|
||||
|
||||
if (ParsingMenuDef)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = countof(MenuDefCommands)-1; i >= 0; --i)
|
||||
{
|
||||
if (strnicmp (beg, MenuDefCommands[i], len) == 0 &&
|
||||
MenuDefCommands[i][len] == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < 0)
|
||||
{
|
||||
Printf ("Invalid command for MENUDEF/ZScript: %s\n", beg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this is an action
|
||||
if (*beg == '+' || *beg == '-')
|
||||
{
|
||||
|
@ -687,6 +658,12 @@ void C_DoCommand (const char *cmd, int keynum)
|
|||
|
||||
if (args.argc() >= 2)
|
||||
{ // Set the variable
|
||||
if (UnsafeExecutionContext && !(var->GetFlags() & CVAR_MOD))
|
||||
{
|
||||
Printf(TEXTCOLOR_RED "Cannot set console variable" TEXTCOLOR_GOLD " %s " TEXTCOLOR_RED "from unsafe command\n", var->GetName());
|
||||
return;
|
||||
}
|
||||
|
||||
var->CmdSet (args[1]);
|
||||
}
|
||||
else
|
||||
|
@ -707,9 +684,9 @@ DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand)
|
|||
if (CurrentMenu == nullptr) return 0;
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(cmd);
|
||||
ParsingMenuDef = true;
|
||||
UnsafeExecutionContext = true;
|
||||
C_DoCommand(cmd);
|
||||
ParsingMenuDef = false;
|
||||
UnsafeExecutionContext = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -769,7 +746,7 @@ void AddCommandString (char *cmd, int keynum)
|
|||
// Note that deferred commands lose track of which key
|
||||
// (if any) they were pressed from.
|
||||
*brkpt = ';';
|
||||
Create<DWaitingCommand> (brkpt, tics);
|
||||
Create<DWaitingCommand> (brkpt, tics, UnsafeExecutionContext);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1061,6 +1038,17 @@ void FConsoleCommand::Run (FCommandLine &argv, APlayerPawn *who, int key)
|
|||
m_RunFunc (argv, who, key);
|
||||
}
|
||||
|
||||
void FUnsafeConsoleCommand::Run (FCommandLine &args, APlayerPawn *instigator, int key)
|
||||
{
|
||||
if (UnsafeExecutionContext)
|
||||
{
|
||||
Printf(TEXTCOLOR_RED "Cannot execute unsafe command " TEXTCOLOR_GOLD "%s\n", m_Name);
|
||||
return;
|
||||
}
|
||||
|
||||
FConsoleCommand::Run (args, instigator, key);
|
||||
}
|
||||
|
||||
FConsoleAlias::FConsoleAlias (const char *name, const char *command, bool noSave)
|
||||
: FConsoleCommand (name, NULL),
|
||||
bRunning(false), bKill(false)
|
||||
|
@ -1381,9 +1369,13 @@ CCMD (alias)
|
|||
alias = NULL;
|
||||
}
|
||||
}
|
||||
else if (ParsingKeyConf)
|
||||
{
|
||||
new FUnsafeConsoleAlias (argv[1], argv[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
new FConsoleAlias (argv[1], argv[2], ParsingKeyConf);
|
||||
new FConsoleAlias (argv[1], argv[2], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1521,6 +1513,13 @@ void FConsoleAlias::SafeDelete ()
|
|||
}
|
||||
}
|
||||
|
||||
void FUnsafeConsoleAlias::Run (FCommandLine &args, APlayerPawn *instigator, int key)
|
||||
{
|
||||
UnsafeExecutionContext = true;
|
||||
FConsoleAlias::Run(args, instigator, key);
|
||||
UnsafeExecutionContext = false;
|
||||
}
|
||||
|
||||
void FExecList::AddCommand(const char *cmd, const char *file)
|
||||
{
|
||||
// Pullins are special and need to be separated from general commands.
|
||||
|
|
|
@ -127,6 +127,22 @@ protected:
|
|||
FConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \
|
||||
void Cmd_##n (FCommandLine &argv, APlayerPawn *who, int key)
|
||||
|
||||
class FUnsafeConsoleCommand : public FConsoleCommand
|
||||
{
|
||||
public:
|
||||
FUnsafeConsoleCommand (const char *name, CCmdRun RunFunc)
|
||||
: FConsoleCommand (name, RunFunc)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Run (FCommandLine &args, APlayerPawn *instigator, int key) override;
|
||||
};
|
||||
|
||||
#define UNSAFE_CCMD(n) \
|
||||
static void Cmd_##n (FCommandLine &, APlayerPawn *, int key); \
|
||||
static FUnsafeConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \
|
||||
void Cmd_##n (FCommandLine &argv, APlayerPawn *who, int key)
|
||||
|
||||
const int KEY_DBLCLICKED = 0x8000;
|
||||
|
||||
class FConsoleAlias : public FConsoleCommand
|
||||
|
@ -147,6 +163,17 @@ protected:
|
|||
bool bKill;
|
||||
};
|
||||
|
||||
class FUnsafeConsoleAlias : public FConsoleAlias
|
||||
{
|
||||
public:
|
||||
FUnsafeConsoleAlias (const char *name, const char *command)
|
||||
: FConsoleAlias (name, command, true)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Run (FCommandLine &args, APlayerPawn *instigator, int key) override;
|
||||
};
|
||||
|
||||
// Actions
|
||||
struct FButtonStatus
|
||||
{
|
||||
|
|
|
@ -2821,7 +2821,7 @@ void D_DoomMain (void)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD(restart)
|
||||
UNSAFE_CCMD(restart)
|
||||
{
|
||||
// remove command line args that would get in the way during restart
|
||||
Args->RemoveArgs("-iwad");
|
||||
|
@ -2917,4 +2917,4 @@ CUSTOM_CVAR(Bool, I_FriendlyWindowTitle, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CV
|
|||
I_SetWindowTitle(DoomStartupInfo.Name.GetChars());
|
||||
else
|
||||
I_SetWindowTitle(NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2618,7 +2618,7 @@ CCMD (playdemo)
|
|||
}
|
||||
}
|
||||
|
||||
CCMD (timedemo)
|
||||
UNSAFE_CCMD (timedemo)
|
||||
{
|
||||
if (argv.argc() > 1)
|
||||
{
|
||||
|
|
|
@ -224,7 +224,7 @@ CCMD (map)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD(recordmap)
|
||||
UNSAFE_CCMD(recordmap)
|
||||
{
|
||||
if (netgame)
|
||||
{
|
||||
|
@ -277,7 +277,7 @@ CCMD(recordmap)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (open)
|
||||
UNSAFE_CCMD (open)
|
||||
{
|
||||
if (netgame)
|
||||
{
|
||||
|
|
|
@ -315,7 +315,7 @@ void M_SaveDefaultsFinal ()
|
|||
GameConfig = NULL;
|
||||
}
|
||||
|
||||
CCMD (writeini)
|
||||
UNSAFE_CCMD (writeini)
|
||||
{
|
||||
const char *filename = (argv.argc() == 1) ? NULL : argv[1];
|
||||
if (!M_SaveDefaults (filename))
|
||||
|
|
|
@ -708,7 +708,7 @@ ADD_STAT(music)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (writeopl)
|
||||
UNSAFE_CCMD (writeopl)
|
||||
{
|
||||
if (argv.argc() == 2)
|
||||
{
|
||||
|
@ -746,7 +746,7 @@ CCMD (writeopl)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (writewave)
|
||||
UNSAFE_CCMD (writewave)
|
||||
{
|
||||
if (argv.argc() >= 2 && argv.argc() <= 3)
|
||||
{
|
||||
|
@ -784,7 +784,7 @@ CCMD (writewave)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD (writemidi)
|
||||
UNSAFE_CCMD (writemidi)
|
||||
{
|
||||
if (argv.argc() != 2)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue