From 3030ab8664e643f9c4d97cfa96804798a6c95c8c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 28 Oct 2009 00:50:48 -0700 Subject: [PATCH] Fixed crash when activating command listeners on EP1 while inside a command callback (bug 4072, r=pred). --- core/ConsoleDetours.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/ConsoleDetours.cpp b/core/ConsoleDetours.cpp index b83d0a93..f7e8c383 100644 --- a/core/ConsoleDetours.cpp +++ b/core/ConsoleDetours.cpp @@ -284,6 +284,23 @@ class GenericCommandHooker Patch cgc; public: + static void DelayedActivation(void *inparam) + { + GenericCommandHooker *cdtrs = reinterpret_cast(inparam); + /* Safe to re-enter because the frame queue is lock+swapped. */ + if ((!cdtrs->ces.applied || !cdtrs->cgc.applied) && + g_HL2.PeekCommandStack() != NULL) + { + g_SourceMod.AddFrameAction(GenericCommandHooker::DelayedActivation, cdtrs); + return; + } + + if (!cdtrs->ces.applied) + cdtrs->ApplyPatch(&cdtrs->ces); + if (!cdtrs->cgc.applied) + cdtrs->ApplyPatch(&cdtrs->cgc); + } + bool Enable() { const char *platform = NULL; @@ -321,6 +338,12 @@ public: if (!PrepPatch("CGameClient::ExecuteString", "CGC", platform, &cgc)) return false; + if (g_HL2.PeekCommandStack() != NULL) + { + g_SourceMod.AddFrameAction(GenericCommandHooker::DelayedActivation, this); + return true; + } + ApplyPatch(&ces); ApplyPatch(&cgc);