From dee5d064e977acb236f61582b945aa806b89e8c3 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Thu, 14 Dec 2017 16:39:33 -0500 Subject: [PATCH] - revise last script a bit: allow certain cheats/scripts/events to be called from the menu. --- src/c_dispatch.cpp | 56 +++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index 4e3f027f0..1bca9051b 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -126,7 +126,7 @@ 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; +bool ParsingKeyConf, ParsingMenuDef = false; // To add new actions, go to the console and type "key ". // This will give you the key value to use in the first column. Then @@ -187,6 +187,21 @@ static const char *KeyConfCommands[] = "clearplayerclasses" }; +static const char *MenuDefCommands[] = +{ + "snd_reset", + "reset2defaults", + "menuconsole", + "clearnodecache", + "am_restorecolors", + "special", + "puke", + "fpuke", + "pukename", + "event", + "netevent" +}; + // CODE -------------------------------------------------------------------- IMPLEMENT_CLASS(DWaitingCommand, false, false) @@ -584,6 +599,25 @@ 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 == '-') { @@ -664,29 +698,15 @@ void C_DoCommand (const char *cmd, int keynum) } } -#define ZS_SAFE_COMMAND(ccmd) if (stricmp(cmd, #ccmd) == 0) return true; - -bool C_ZSIsSafe(FString cmd) -{ - ZS_SAFE_COMMAND(snd_reset) - ZS_SAFE_COMMAND(reset2defaults) - ZS_SAFE_COMMAND(menuconsole) - ZS_SAFE_COMMAND(clearnodecache) - ZS_SAFE_COMMAND(am_restorecolors) - - return false; -} - // This is only accessible to the special menu item to run CCMDs. DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand) { if (CurrentMenu == nullptr) return 0; PARAM_PROLOGUE; PARAM_STRING(cmd); - if (C_ZSIsSafe(cmd)) - C_DoCommand(cmd); - else - Printf("Script attempted to call unsafe command '%s'\n", cmd); + ParsingMenuDef = true; + C_DoCommand(cmd); + ParsingMenuDef = false; return 0; }