]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
add comments and demo start and end hooks
authordrjaska <drjaska83@gmail.com>
Thu, 7 Dec 2023 11:44:44 +0000 (13:44 +0200)
committerdrjaska <drjaska83@gmail.com>
Thu, 7 Dec 2023 12:12:05 +0000 (14:12 +0200)
gamemodes-client.cfg
qcsrc/client/main.qc
qcsrc/client/view.qc

index c63bba5a76efb86a6ca15ae8ba4405dd4598828d..431a6cdb51ceb24296aa4db579ea5cfc308798c3 100644 (file)
@@ -39,3 +39,5 @@ alias cl_hook_gamestart_surv
 alias cl_hook_gameend
 alias cl_hook_shutdown
 alias cl_hook_activeweapon
+alias cl_hook_demostart
+alias cl_hook_demoend
index 58d497aab77b176a9ef60b951762e60d7eecac95..17f872d0e2914030323bc3617e20e7b1c9b121d7 100644 (file)
@@ -176,10 +176,15 @@ void Shutdown()
 
        cvar_set("slowmo", cvar_defstring("slowmo")); // reset it back to 'default'
 
+       // fire game or demo end hooks when CSQC VM shuts down
        if (!isdemo())
        {
+               // 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))
                {
                        int gamecount = cvar("cl_matchcount");
@@ -188,6 +193,16 @@ void Shutdown()
                        // 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;
+               }
+       }
+       else
+       {
+               // call demo end hook
+               if (!(calledhooks & HOOK_END))
+               {
+                       localcmd("\ncl_hook_demoend\n");
+                       calledhooks |= HOOK_END; // mark the hook as having fired
                }
        }
 
@@ -1012,11 +1027,22 @@ void CSQC_Ent_Remove(entity this)
 
 void Gamemode_Init()
 {
+       // fire game or demo start hooks here
        if (!isdemo())
        {
                if(!(calledhooks & HOOK_START))
+               {
                        localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
-               calledhooks |= HOOK_START;
+                       calledhooks |= HOOK_START; // mark start hook as fired
+               }
+       }
+       else
+       {
+               if (!(calledhooks & HOOK_START))
+               {
+                       localcmd("\ncl_hook_demostart\n");
+                       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.
index a9496ea15310ba50332e9480692c4e30bacc2502..17927c78d13154bc3244a9279d12ada2fe617543 100644 (file)
@@ -1641,6 +1641,9 @@ void CSQC_UpdateView(entity this, float w, float h)
        else if(game_stopped_time && !STAT(GAME_STOPPED))
                game_stopped_time = 0;
 
+       // fire game end hooks here once intermission starts
+       // do not fire demo end hooks here as we are
+       // still running a demo until the CSQC VM is shutdown
        if(intermission && !isdemo() && !(calledhooks & HOOK_END))
        {
                if(calledhooks & HOOK_START)