]> granicus.if.org Git - nethack/commitdiff
Mark some extended commands as no-fuzzer
authorPasi Kallinen <paxed@alt.org>
Thu, 8 Jul 2021 08:35:40 +0000 (11:35 +0300)
committerPasi Kallinen <paxed@alt.org>
Thu, 8 Jul 2021 08:35:43 +0000 (11:35 +0300)
... instead of checking the fuzzer being on in the commands themselves.

include/func_tab.h
src/cmd.c
src/end.c
src/invent.c
src/save.c

index 439de8996917f690394c54eae2a3a05b294bccee..175c4df04f45b81dcd9f735a684a9275c77ff75f 100644 (file)
@@ -12,6 +12,7 @@
 #define WIZMODECMD   0x04 /* wizard-mode command */
 #define GENERALCMD   0x08 /* general command, does not take game time */
 #define CMD_NOT_AVAILABLE 0x10 /* recognized but non-functional (!SHELL,&c) */
+#define NOFUZZERCMD  0x20 /* fuzzer cannot execute this command */
 
 struct ext_func_tab {
     uchar key;
index bc0cdb89e76ff01afb39ee20999a09b1bcbae95b..2735358fc60b28d13f64b602b827e9244873fa7e 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -102,6 +102,7 @@ static int doherecmdmenu(void);
 static int dotherecmdmenu(void);
 static int doprev_message(void);
 static int timed_occupation(void);
+static boolean can_do_extcmd(const struct ext_func_tab *);
 static int doextcmd(void);
 static int dotravel(void);
 static int doterrain(void);
@@ -351,6 +352,23 @@ savech(char ch)
     return;
 }
 
+static boolean
+can_do_extcmd(const struct ext_func_tab *extcmd)
+{
+    int ecflags = extcmd->flags;
+
+    if (!wizard && (ecflags & WIZMODECMD)) {
+        You_cant("do that!");
+        return FALSE;
+    } else if (u.uburied && !(ecflags & IFBURIED)) {
+        You_cant("do that while you are buried!");
+        return FALSE;
+    } else if (iflags.debug_fuzzer && (ecflags & NOFUZZERCMD)) {
+        return FALSE;
+    }
+    return TRUE;
+}
+
 /* here after # - now read a full-word command */
 static int
 doextcmd(void)
@@ -365,10 +383,8 @@ doextcmd(void)
             return 0; /* quit */
 
         func = extcmdlist[idx].ef_funct;
-        if (!wizard && (extcmdlist[idx].flags & WIZMODECMD)) {
-            You("can't do that.");
+        if (!can_do_extcmd(&extcmdlist[idx]))
             return 0;
-        }
         if (iflags.menu_requested && !accept_menu_prefix(func)) {
             pline("'%s' prefix has no effect for the %s command.",
                   visctrl(g.Cmd.spkeys[NHKF_REQMENU]),
@@ -795,9 +811,6 @@ domonability(void)
 int
 enter_explore_mode(void)
 {
-    if (iflags.debug_fuzzer)
-        return 0;
-
     if (discover) {
         You("are already in explore mode.");
     } else {
@@ -1047,7 +1060,7 @@ wiz_detect(void)
 static int
 wiz_load_lua(void)
 {
-    if (wizard && !iflags.debug_fuzzer) {
+    if (wizard) {
         char buf[BUFSZ];
 
         buf[0] = '\0';
@@ -1065,7 +1078,7 @@ wiz_load_lua(void)
 static int
 wiz_load_splua(void)
 {
-    if (wizard && !iflags.debug_fuzzer) {
+    if (wizard) {
         boolean was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz);
         char buf[BUFSZ];
         int ridx;
@@ -1903,7 +1916,7 @@ struct ext_func_tab extcmdlist[] = {
     /* #exploremode should be flagged AUTOCOMPETE but that would negatively
        impact frequently used #enhance by making #e become ambiguous */
     { M('X'), "exploremode", "enter explore (discovery) mode",
-              enter_explore_mode, IFBURIED | GENERALCMD, NULL },
+              enter_explore_mode, IFBURIED | GENERALCMD | NOFUZZERCMD, NULL },
     { 'f',    "fire", "fire ammunition from quiver",
               dofire, 0, NULL },
     { M('f'), "force", "force a lock",
@@ -1962,7 +1975,7 @@ struct ext_func_tab extcmdlist[] = {
     { 'p',    "pay", "pay your shopping bill",
               dopay, 0, NULL },
     { '|',    "perminv", "scroll persistent inventory display",
-              doperminv, IFBURIED | GENERALCMD, NULL },
+              doperminv, IFBURIED | GENERALCMD | NOFUZZERCMD, NULL },
     { ',',    "pickup", "pick up things at the current location",
               dopickup, 0, NULL },
     { '\0',   "polyself", "polymorph self",
@@ -1976,7 +1989,7 @@ struct ext_func_tab extcmdlist[] = {
     { 'q',    "quaff", "quaff (drink) something",
               dodrink, 0, NULL },
     { '\0', "quit", "exit without saving current game",
-              done2, IFBURIED | AUTOCOMPLETE | GENERALCMD, NULL },
+              done2, IFBURIED | AUTOCOMPLETE | GENERALCMD | NOFUZZERCMD, NULL },
     { 'Q',    "quiver", "select ammunition for quiver",
               dowieldquiver, 0, NULL },
     { 'r',    "read", "read a scroll or spellbook",
@@ -1990,7 +2003,7 @@ struct ext_func_tab extcmdlist[] = {
     { M('r'), "rub", "rub a lamp or a stone",
               dorub, AUTOCOMPLETE, NULL },
     { 'S',    "save", "save the game and exit",
-              dosave, IFBURIED | GENERALCMD, NULL },
+              dosave, IFBURIED | GENERALCMD | NOFUZZERCMD, NULL },
     { 's',    "search", "search for traps and secret doors",
               dosearch, IFBURIED, "searching" },
     { '*',    "seeall", "show all equipment in use",
@@ -2006,7 +2019,7 @@ struct ext_func_tab extcmdlist[] = {
     { WEAPON_SYM, "seeweapon", "show the weapon currently wielded",
               doprwep, IFBURIED, NULL },
     { '!', "shell", "leave game to enter a sub-shell ('exit' to come back)",
-              dosh_core, (IFBURIED | GENERALCMD
+              dosh_core, (IFBURIED | GENERALCMD | NOFUZZERCMD
 #ifndef SHELL
                         | CMD_NOT_AVAILABLE
 #endif /* SHELL */
@@ -2023,7 +2036,7 @@ struct ext_func_tab extcmdlist[] = {
     { '\0',   "stats", "show memory statistics",
               wiz_show_stats, IFBURIED | AUTOCOMPLETE | WIZMODECMD, NULL },
     { C('z'), "suspend", "push game to background ('fg' to come back)",
-              dosuspend_core, (IFBURIED | GENERALCMD
+              dosuspend_core, (IFBURIED | GENERALCMD | NOFUZZERCMD
 #ifndef SUSPEND
                                | CMD_NOT_AVAILABLE
 #endif /* SUSPEND */
@@ -2102,9 +2115,9 @@ struct ext_func_tab extcmdlist[] = {
     { C('v'), "wizlevelport", "teleport to another level",
               wiz_level_tele, IFBURIED | WIZMODECMD, NULL },
     { '\0',   "wizloaddes", "load and execute a des-file lua script",
-              wiz_load_splua, IFBURIED | WIZMODECMD, NULL },
+              wiz_load_splua, IFBURIED | WIZMODECMD | NOFUZZERCMD, NULL },
     { '\0',   "wizloadlua", "load and execute a lua script",
-              wiz_load_lua, IFBURIED | WIZMODECMD, NULL },
+              wiz_load_lua, IFBURIED | WIZMODECMD | NOFUZZERCMD, NULL },
     { '\0',   "wizmakemap", "recreate the current level",
               wiz_makemap, IFBURIED | WIZMODECMD, NULL },
     { C('f'), "wizmap", "map the level",
@@ -3625,12 +3638,7 @@ do_cmdq_extcmd:
 
         /* current - use *cmd to directly index cmdlist array */
         if (tlist != 0) {
-            if (!wizard && (tlist->flags & WIZMODECMD)) {
-                You_cant("do that!");
-                res = 0;
-                cmdq_clear();
-            } else if (u.uburied && !(tlist->flags & IFBURIED)) {
-                You_cant("do that while you are buried!");
+            if (!can_do_extcmd(tlist)) {
                 res = 0;
                 cmdq_clear();
             } else {
@@ -4517,12 +4525,6 @@ parse(void)
         g.last_command_count = g.command_count;
     }
 
-    if (iflags.debug_fuzzer /* if fuzzing, override '!' and ^Z */
-        && (g.Cmd.commands[foo & 0x0ff]
-            && (g.Cmd.commands[foo & 0x0ff]->ef_funct == dosuspend_core
-                || g.Cmd.commands[foo & 0x0ff]->ef_funct == dosh_core)))
-        foo = g.Cmd.spkeys[NHKF_ESC];
-
     if (foo == g.Cmd.spkeys[NHKF_ESC]) { /* esc cancels count (TH) */
         clear_nhwindow(WIN_MESSAGE);
         g.command_count = 0;
index ce17c903640747d06c2854a1386d20edd2bc4fbe..f2ee39bee428c7181b60007534d25c3dceef24a0 100644 (file)
--- a/src/end.c
+++ b/src/end.c
@@ -327,8 +327,6 @@ done1(int sig_unused UNUSED)
 int
 done2(void)
 {
-    if (iflags.debug_fuzzer)
-        return 0;
     if (!paranoid_query(ParanoidQuit, "Really quit?")) {
 #ifndef NO_SIGNAL
         (void) signal(SIGINT, (SIG_RET_TYPE) done1);
index 5e6bcaece59e1815d92559523979562b3e7dfcfa..a3fb3f3f10fcbc4d9e5dbb8bb5621b19970f9d83 100644 (file)
@@ -2357,8 +2357,6 @@ doperminv(void)
      * (typically by typing <return> or <esc> but that's up to interface).
      */
 
-    if (iflags.debug_fuzzer)
-        return 0;
 #if 0
     /* [currently this would redraw the persistent inventory window
        whether that's needed or not, so also reset any previous
index 735a0d4191b2b4fe1a5b3ab79925fe29a3cb59cd..21a46cbb10c2529c2f027b56bb0127f3fef614ed 100644 (file)
@@ -49,8 +49,6 @@ static void zerocomp_bputc(int);
 int
 dosave(void)
 {
-    if (iflags.debug_fuzzer)
-        return 0;
     clear_nhwindow(WIN_MESSAGE);
     if (yn("Really save?") == 'n') {
         clear_nhwindow(WIN_MESSAGE);