diff --git a/src/game/iw3/mp/components/events.cpp b/src/game/iw3/mp/components/events.cpp index 4b1259a6..d0022b54 100644 --- a/src/game/iw3/mp/components/events.cpp +++ b/src/game/iw3/mp/components/events.cpp @@ -106,15 +106,18 @@ void Events::Load_DelayStream_Hook() Detour Events::Load_DelayStream_Detour; -void Events::Scr_ShutdownSystem_Hook(unsigned __int8 sys) +void Events::Scr_ShutdownSystem_Hook(int bComplete) { - for (size_t i = 0; i < ARRAYSIZE(vmShutdownHandlers); ++i) + if (bComplete) { - vmShutdownHandlers[i](); + for (size_t i = 0; i < ARRAYSIZE(vmShutdownHandlers); ++i) + { + vmShutdownHandlers[i](); + } } // Call original function after callbacks - Scr_ShutdownSystem_Detour.GetOriginal()(sys); + Scr_ShutdownSystem_Detour.GetOriginal()(bComplete); } Detour Events::Scr_ShutdownSystem_Detour; diff --git a/src/game/iw3/mp/components/events.h b/src/game/iw3/mp/components/events.h index 5c447f63..ee7ef1e3 100644 --- a/src/game/iw3/mp/components/events.h +++ b/src/game/iw3/mp/components/events.h @@ -24,7 +24,7 @@ class Events : public Module static void Load_DelayStream_Hook(); static Detour Scr_ShutdownSystem_Detour; - static void Scr_ShutdownSystem_Hook(unsigned __int8 sys); + static void Scr_ShutdownSystem_Hook(int bComplete); static Detour Com_InitDvars_Detour; static void Com_InitDvars_Hook(); diff --git a/src/game/iw3/mp/symbols.h b/src/game/iw3/mp/symbols.h index 28760762..56ccdbf8 100644 --- a/src/game/iw3/mp/symbols.h +++ b/src/game/iw3/mp/symbols.h @@ -486,7 +486,8 @@ typedef int (*CL_ConsolePrint_AddLine_t)(int localClientNum, int channel, const unsigned int pixelWidth, char color, int flags); static CL_ConsolePrint_AddLine_t CL_ConsolePrint_AddLine = reinterpret_cast(0x822E1EB8); -typedef void (*Scr_ShutdownSystem_t)(unsigned __int8 sys); +// TU4 omits the sys argument; only bComplete remains. +typedef void (*Scr_ShutdownSystem_t)(int bComplete); static Scr_ShutdownSystem_t Scr_ShutdownSystem = reinterpret_cast(0x82211FD0); typedef void (*Com_InitDvars_t)(); diff --git a/src/game/t4/mp/components/events.cpp b/src/game/t4/mp/components/events.cpp index 5ae4a602..59774f3d 100644 --- a/src/game/t4/mp/components/events.cpp +++ b/src/game/t4/mp/components/events.cpp @@ -57,10 +57,10 @@ void Events::Cmd_Init_Hook() Detour Events::Cmd_Init_Detour; -void *Events::Scr_ShutdownSystem_Hook(scriptInstance_t inst, int sys, int bComplete) +void *Events::Scr_ShutdownSystem_Hook(scriptInstance_t inst, scrSystem_t sys, int bComplete) { - // These handlers own server script state. - if (inst == SCRIPTINSTANCE_SERVER) + // These handlers own server script state and run only on complete shutdowns. + if (inst == SCRIPTINSTANCE_SERVER && bComplete) { for (size_t i = 0; i < ARRAYSIZE(vmShutdownHandlers); ++i) { diff --git a/src/game/t4/mp/components/events.h b/src/game/t4/mp/components/events.h index 152a93e5..26b5d637 100644 --- a/src/game/t4/mp/components/events.h +++ b/src/game/t4/mp/components/events.h @@ -20,7 +20,7 @@ class Events : public Module static void Cmd_Init_Hook(); static Detour Scr_ShutdownSystem_Detour; - static void *Scr_ShutdownSystem_Hook(scriptInstance_t inst, int sys, int bComplete); + static void *Scr_ShutdownSystem_Hook(scriptInstance_t inst, scrSystem_t sys, int bComplete); static Detour UI_Refresh_Detour; static int UI_Refresh_Hook(int localClientNum); diff --git a/src/game/t4/mp/structs.h b/src/game/t4/mp/structs.h index c1f60e25..4bc848ea 100644 --- a/src/game/t4/mp/structs.h +++ b/src/game/t4/mp/structs.h @@ -767,6 +767,11 @@ enum svscmd_type SV_CMD_RELIABLE = 0x1, }; +enum scrSystem_t : __int32 +{ + SCR_SYS_GAME = 0x1, +}; + enum scriptInstance_t : __int32 { SCRIPTINSTANCE_SERVER = 0x0, diff --git a/src/game/t4/mp/symbols.h b/src/game/t4/mp/symbols.h index 91c16f38..c0d93a79 100644 --- a/src/game/t4/mp/symbols.h +++ b/src/game/t4/mp/symbols.h @@ -189,7 +189,7 @@ static auto Scr_SetClientField = reinterpret_cast(0x8220A2D0); static auto Scr_SetGenericField = reinterpret_cast(0x82254E90); -typedef void *(*Scr_ShutdownSystem_t)(scriptInstance_t inst, int sys, int bComplete); +typedef void *(*Scr_ShutdownSystem_t)(scriptInstance_t inst, scrSystem_t sys, int bComplete); static Scr_ShutdownSystem_t Scr_ShutdownSystem = reinterpret_cast(0x82345388); static auto String_Parse = reinterpret_cast(0x822A8680);