]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cmd.c
Fix DP_QC_FINDCHAIN_TOFIELD errors
[xonotic/darkplaces.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index abc512eef3a4e547ba72e24e07e1aaad43cbe961..c9b2cd5d8b0fc8d172d69685c59880122518d1d7 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -86,7 +86,7 @@ static void Cmd_Defer_f (cmd_state_t *cmd)
                        Con_Printf("No commands are pending.\n");
                else
                {
-                       List_For_Each_Entry(current, &cbuf->deferred, list)
+                       List_For_Each_Entry(current, &cbuf->deferred, cmd_input_t, list)
                                Con_Printf("-> In %9.2f: %s\n", current->delay, current->text);
                }
        }
@@ -394,7 +394,7 @@ void Cbuf_InsertText (cmd_state_t *cmd, const char *text)
                Con_Print("Cbuf_InsertText: overflow\n");
        else
        {
-               Cbuf_LinkCreate(cmd, &llist, List_Entry(cbuf->start.next, cmd_input_t, list), text);
+               Cbuf_LinkCreate(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.next, cmd_input_t, list)), text);
                if(!List_Is_Empty(&llist))
                        List_Splice(&llist, &cbuf->start);
        }
@@ -419,7 +419,7 @@ static void Cbuf_Execute_Deferred (cmd_buf_t *cbuf)
                return;
        cbuf->deferred_oldtime = host.realtime;
 
-       List_For_Each_Entry(current, &cbuf->deferred, list)
+       List_For_Each_Entry(current, &cbuf->deferred, cmd_input_t, list)
        {
                current->delay -= eat;
                if(current->delay <= 0)
@@ -1900,7 +1900,6 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const
                                        }
                                }
 
-
                                func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t));
                                func->flags = flags;
                                func->name = cmd_name;
@@ -1909,6 +1908,18 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const
                                func->qcfunc = true; //[515]: csqc
                                func->next = cmd->userdefined->qc_functions;
 
+                               // bones_was_here: if this QC command overrides an engine command, store its pointer
+                               // to avoid doing this search at invocation if QC declines to handle this command.
+                               for (cmd_function_t *f = cmd->engine_functions; f; f = f->next)
+                               {
+                                       if (!strcmp(cmd_name, f->name))
+                                       {
+                                               Con_DPrintf("Adding QC override of engine command %s\n", cmd_name);
+                                               func->overridden = f;
+                                               break;
+                                       }
+                               }
+
                                // insert it at the right alphanumeric position
                                for (prev = NULL, current = cmd->userdefined->qc_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next)
                                        ;
@@ -2192,6 +2203,9 @@ qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text,
                if(((func->flags & CF_CLIENT) && CL_VM_ConsoleCommand(text)) ||
                   ((func->flags & CF_SERVER) && SV_VM_ConsoleCommand(text)))
                        return true;
+
+               if (func->overridden) // If this QC command overrides an engine command,
+                       func = func->overridden; // fall back to that command.
        }
        if (func->flags & CF_SERVER_FROM_CLIENT)
        {