]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
rework what hooks fire and when
authordrjaska <drjaska83@gmail.com>
Sun, 7 Jan 2024 21:03:31 +0000 (23:03 +0200)
committerdrjaska <drjaska83@gmail.com>
Sun, 7 Jan 2024 21:52:59 +0000 (23:52 +0200)
qcsrc/client/main.qc
qcsrc/client/view.qc

index f0dd1a88e51fd4332f9147145bf617a059d80671..6c54cb26a62fe2ee2e46291fdfbaf9df1c103ae4 100644 (file)
@@ -176,16 +176,16 @@ void Shutdown()
 
        cvar_set("slowmo", cvar_defstring("slowmo")); // reset it back to 'default'
 
+       // if _cl_hook_gamestart wasn't called with an actual gamemode
+       // before CSQC VM shutdown then call it with nop fallback here
+       if (!(calledhooks & HOOK_START) && !isdemo())
+               localcmd("\n_cl_hook_gamestart nop\n");
+
        // fire game or demo end hooks when CSQC VM shuts down
-       if (!isdemo())
+       if (!(calledhooks & HOOK_END))
        {
-               // if _cl_hook_gamestart wasn't called with an actual gamemode
-               // before CSQC VM shutdown then call it with nop fallback here
-               if (!(calledhooks & HOOK_START))
-                       localcmd("\n_cl_hook_gamestart nop\n");
-
                // call gameend hook if it hasn't somehow yet fired by intermission starting
-               if (!(calledhooks & HOOK_END))
+               if (!isdemo())
                {
                        localcmd("\ncl_hook_gameend\n");
 
@@ -194,17 +194,11 @@ void Shutdown()
                        int gamecount = cvar("cl_matchcount");
                        localcmd(strcat("cl_matchcount ", itos(gamecount + 1), "\n"));
                        //cvar_set("cl_matchcount", itos(gamecount + 1));
-                       calledhooks |= HOOK_END;
                }
-       }
-       else
-       {
-               // call demo end hook
-               if (!(calledhooks & HOOK_END))
-               {
+               else
                        localcmd("\ncl_hook_demoend\n");
-                       calledhooks |= HOOK_END; // mark the hook as having fired
-               }
+
+               calledhooks |= HOOK_END; // mark the hook as having fired
        }
 
        localcmd("\ncl_hook_shutdown\n");
@@ -1029,29 +1023,24 @@ void CSQC_Ent_Remove(entity this)
 void Gamemode_Init()
 {
        // fire game or demo start hooks here
-       if (!isdemo())
+       if (!(calledhooks & HOOK_START))
        {
-               if(!(calledhooks & HOOK_START))
-               {
+               if (!isdemo())
                        localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
-                       calledhooks |= HOOK_START; // mark start hook as fired
-               }
-       }
-       else
-       {
-               if (!(calledhooks & HOOK_START))
-               {
+               else
                        localcmd("\ncl_hook_demostart\n");
-                       calledhooks |= HOOK_START; // mark start hook as fired
-               }
+
+               calledhooks |= HOOK_START; // mark start hook as fired
        }
 }
+
 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided.  To execute standard behavior, simply execute localcmd with the string.
 void CSQC_Parse_StuffCmd(string strMessage)
 {
        if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")", strMessage);
        localcmd(strMessage);
 }
+
 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided.  To execute standard behavior, simply execute print with the string.
 void CSQC_Parse_Print(string strMessage)
 {
index 790b5406ee40be4b17ec543d43bd32c95ff0d5c3..fdc1e537df57076eea19fdf32d3b5bce0978a5a7 100644 (file)
@@ -1641,29 +1641,31 @@ void CSQC_UpdateView(entity this, float w, float h)
        else if(game_stopped_time && !STAT(GAME_STOPPED))
                game_stopped_time = 0;
 
-       // fire intermission hooks here
-       // game/demo end hooks are executed on CSQC VM shutdown
-       if(intermission && !(calledhooks & HOOK_INTERMISSION))
+       // fire intermission hooks and gameend hook here
+       // gameend hook is executed on CSQC VM shutdown if
+       // the shutdown happens before intermission start
+       if(intermission
+       && (calledhooks & HOOK_START) // ensure that we have initiated a gamemode
+       && !(calledhooks & HOOK_END)) // fire only once
+       && !(calledhooks & HOOK_INTERMISSION)
        {
                if(!isdemo())
                {
-                       // ensure that we have properly initiated a gamemode
-                       // before firing this hook. gamestart -> intermission
-                       if(calledhooks & HOOK_START)
-                       {
-                               localcmd("\ncl_hook_intermission\n");
-                               calledhooks |= HOOK_INTERMISSION;
-                       }
+                       int gamecount = cvar("cl_matchcount");
+                       localcmd("\ncl_hook_gameend\n");
+                       // NOTE: using localcmd here to ensure it's executed AFTER cl_hook_gameend
+                       // earlier versions of the game abuse the hook to set this cvar
+                       localcmd(strcat("cl_matchcount ", itos(gamecount + 1), "\n"));
+                       //cvar_set("cl_matchcount", itos(gamecount + 1));
+                       calledhooks |= HOOK_END;
+
+                       localcmd("\ncl_hook_intermission\n");
+                       calledhooks |= HOOK_INTERMISSION;
                }
                else
                {
-                       // ensure that we have properly initiated a gamemode
-                       // before firing this hook. demostart -> intermission
-                       if(calledhooks & HOOK_START)
-                       {
-                               localcmd("\ncl_hook_demointermission\n");
-                               calledhooks |= HOOK_INTERMISSION;
-                       }
+                       localcmd("\ncl_hook_demointermission\n");
+                       calledhooks |= HOOK_INTERMISSION;
                }
        }