From afae44b7415ac726e452c4110a4c05bb7d84dc36 Mon Sep 17 00:00:00 2001 From: drjaska Date: Thu, 7 Dec 2023 13:44:44 +0200 Subject: [PATCH] add comments and demo start and end hooks --- gamemodes-client.cfg | 2 ++ qcsrc/client/main.qc | 28 +++++++++++++++++++++++++++- qcsrc/client/view.qc | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gamemodes-client.cfg b/gamemodes-client.cfg index c63bba5a7..431a6cdb5 100644 --- a/gamemodes-client.cfg +++ b/gamemodes-client.cfg @@ -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 diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 58d497aab..17f872d0e 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -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. diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index a9496ea15..17927c78d 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -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) -- 2.39.2