From: drjaska Date: Sun, 7 Jan 2024 21:03:31 +0000 (+0200) Subject: rework what hooks fire and when X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3f624a3ae885ab957cebfaee51315e4ee0a819a6;p=xonotic%2Fxonotic-data.pk3dir.git rework what hooks fire and when --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index f0dd1a88e..6c54cb26a 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -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) { diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 790b5406e..fdc1e537d 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -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; } }