From 7cbe6750660a8514ad3093ec032c3fa948c107ab Mon Sep 17 00:00:00 2001 From: drjaska Date: Fri, 8 Dec 2023 00:04:36 +0200 Subject: [PATCH] add game/demo intermission hooks breaking change: gameend hook is no longer fired at the start of an intermission. --- gamemodes-client.cfg | 2 ++ qcsrc/client/main.qc | 3 ++- qcsrc/client/main.qh | 5 +++-- qcsrc/client/view.qc | 34 ++++++++++++++++++++++------------ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/gamemodes-client.cfg b/gamemodes-client.cfg index 431a6cdb5..a1979e511 100644 --- a/gamemodes-client.cfg +++ b/gamemodes-client.cfg @@ -36,8 +36,10 @@ alias cl_hook_gamestart_mayhem alias cl_hook_gamestart_tmayhem alias cl_hook_gamestart_tka alias cl_hook_gamestart_surv +alias cl_hook_intermission alias cl_hook_gameend alias cl_hook_shutdown alias cl_hook_activeweapon alias cl_hook_demostart +alias cl_hook_demointermission alias cl_hook_demoend diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 17f872d0e..f0dd1a88e 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -187,10 +187,11 @@ void Shutdown() // call gameend hook if it hasn't somehow yet fired by intermission starting if (!(calledhooks & HOOK_END)) { - 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 + int gamecount = cvar("cl_matchcount"); localcmd(strcat("cl_matchcount ", itos(gamecount + 1), "\n")); //cvar_set("cl_matchcount", itos(gamecount + 1)); calledhooks |= HOOK_END; diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index 7929a450e..c86329188 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -146,8 +146,9 @@ float damagepush_speedfactor; //hooks int calledhooks; -const int HOOK_START = 1; -const int HOOK_END = 2; +const int HOOK_START = 1; // VM init +const int HOOK_END = 2; // VM shutdown +const int HOOK_INTERMISSION = 4; // intermission start .float ping, ping_packetloss, ping_movementloss; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 17927c78d..86d8bc7ac 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1641,20 +1641,30 @@ 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)) + // fire intermission hooks here once intermission starts + // do not fire game/demo end hooks here as we are + // still running something until the CSQC VM is shutdown + if(intermission && !(calledhooks & HOOK_INTERMISSION)) { - if(calledhooks & HOOK_START) + if(!isdemo()) { - 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; + // 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; + } + } + 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; + } } } -- 2.39.2