From 25d72e3d9ecc966674cb96ac78f482357e8f8e20 Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Tue, 22 Aug 2023 00:50:49 +0200 Subject: [PATCH] Fix Killstreaks crashing when reconnecting to GameCoordinator --- CastingEssentials/Hooking/GroupGlobalVirtualHook.h | 2 +- CastingEssentials/Modules/Killstreaks.cpp | 11 +++++++++-- CastingEssentials/Modules/Killstreaks.h | 4 +++- CastingEssentials/PluginBase/HookDefinitions.h | 12 +++++++++++- CastingEssentials/PluginBase/HookManager.cpp | 4 ++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CastingEssentials/Hooking/GroupGlobalVirtualHook.h b/CastingEssentials/Hooking/GroupGlobalVirtualHook.h index dee6f6f..4c66ce4 100644 --- a/CastingEssentials/Hooking/GroupGlobalVirtualHook.h +++ b/CastingEssentials/Hooking/GroupGlobalVirtualHook.h @@ -76,7 +76,7 @@ namespace Hooking GroupGlobalVirtualHook() = delete; GroupGlobalVirtualHook(const SelfType& other) = delete; - DetourFnType DefaultDetourFn() override { return Internal::SharedLocalDetourFn(this); } + DetourFnType DefaultDetourFn() override { return SharedLocalDetourFn(); } }; #if 0 diff --git a/CastingEssentials/Modules/Killstreaks.cpp b/CastingEssentials/Modules/Killstreaks.cpp index 03d5c24..96c329b 100644 --- a/CastingEssentials/Modules/Killstreaks.cpp +++ b/CastingEssentials/Modules/Killstreaks.cpp @@ -44,7 +44,8 @@ Killstreaks::Killstreaks() : ce_killstreaks_hide_firstperson_effects("ce_killstreaks_hide_firstperson_effects", "0", FCVAR_NONE, "Don't show professional killstreak eye effects in the middle of the screen for the person we're spectating when in firstperson camera mode."), - m_FireEventClientSideHook(std::bind(&Killstreaks::FireEventClientSideOverride, this, std::placeholders::_1)) + m_FireEventClientSideHook(std::bind(&Killstreaks::FireEventClientSideOverride, this, std::placeholders::_1, std::placeholders::_2)), + m_RequestPriceSheetHook(std::bind(&Killstreaks::RequestPriceSheetOverride, this, std::placeholders::_1)) { } @@ -141,6 +142,7 @@ void Killstreaks::UpdateKillstreaks(bool inGame) VPROF_BUDGET(__FUNCTION__, VPROF_BUDGETGROUP_CE); if (inGame) { + m_RequestPriceSheetHook.Enable(); m_FireEventClientSideHook.Enable(); Assert(TFPlayerResource::GetPlayerResource()); @@ -188,10 +190,11 @@ void Killstreaks::UpdateKillstreaks(bool inGame) { m_CurrentKillstreaks.clear(); m_FireEventClientSideHook.Disable(); + m_RequestPriceSheetHook.Disable(); } } -bool Killstreaks::FireEventClientSideOverride(IGameEvent *event) +bool Killstreaks::FireEventClientSideOverride(IGameEventManager2* pThis, IGameEvent* event) { Assert(event); if (!event) @@ -330,4 +333,8 @@ bool Killstreaks::FireEventClientSideOverride(IGameEvent *event) } return true; +} + +void Killstreaks::RequestPriceSheetOverride(CStorePanel*) { + m_RequestPriceSheetHook.SetState(Hooking::HookAction::SUPERCEDE); } \ No newline at end of file diff --git a/CastingEssentials/Modules/Killstreaks.h b/CastingEssentials/Modules/Killstreaks.h index bcda6d4..2c9a70b 100644 --- a/CastingEssentials/Modules/Killstreaks.h +++ b/CastingEssentials/Modules/Killstreaks.h @@ -31,7 +31,8 @@ class Killstreaks : public Module ConVar ce_killstreaks_hide_firstperson_effects; void HideFirstPersonEffects() const; - bool FireEventClientSideOverride(IGameEvent *event); + bool FireEventClientSideOverride(IGameEventManager2* pThis, IGameEvent *event); + void RequestPriceSheetOverride(CStorePanel*); int m_BluTopKillstreak; int m_BluTopKillstreakPlayer; @@ -40,6 +41,7 @@ class Killstreaks : public Module std::map m_CurrentKillstreaks; Hook m_FireEventClientSideHook; + Hook m_RequestPriceSheetHook; static std::array, 4> s_PlayerStreaks; static EntityOffset s_MedigunHealing; diff --git a/CastingEssentials/PluginBase/HookDefinitions.h b/CastingEssentials/PluginBase/HookDefinitions.h index 12c1d9f..bc39acc 100644 --- a/CastingEssentials/PluginBase/HookDefinitions.h +++ b/CastingEssentials/PluginBase/HookDefinitions.h @@ -62,6 +62,8 @@ class IStudioRender; class IMaterial; class IClientRenderable; class C_TFPlayer; +class CClientState; +class CStorePanel; namespace vgui { @@ -162,6 +164,8 @@ enum class HookFunc vgui_Panel_FindChildByName, vgui_ProgressBar_ApplySettings, + CStorePanel_RequestPricesheet, + Count, }; @@ -219,7 +223,8 @@ class HookDefinitions }; template<> struct HookFuncType { - typedef VirtualHook Hook; + typedef bool(__thiscall* Raw)(IGameEventManager2* pThis, IGameEvent* event); + typedef GlobalVirtualHook Hook; }; template<> struct HookFuncType { @@ -474,4 +479,9 @@ class HookDefinitions typedef void(__cdecl *Raw)(IClientRenderable* pEnt, bool bTwoPass, bool bShadowDepth, bool bIgnoreDepth); typedef GlobalHook Hook; }; + template<> struct HookFuncType + { + typedef void(__thiscall* Raw)(CStorePanel* pThis); + typedef GlobalClassHook Hook; + }; }; \ No newline at end of file diff --git a/CastingEssentials/PluginBase/HookManager.cpp b/CastingEssentials/PluginBase/HookManager.cpp index 02ab65f..fe8cccc 100644 --- a/CastingEssentials/PluginBase/HookManager.cpp +++ b/CastingEssentials/PluginBase/HookManager.cpp @@ -198,6 +198,8 @@ void HookManager::InitRawFunctionsList() FindFunc("\x55\x8B\xEC\x83\xEC\x28\xA1????\x53\x8B\xD9\x33\xC9", "xxxxxxx????xxxxx"); FindFunc("\x55\x8B\xEC\xD9\xEE\x53", "xxxxxx"); + FindFunc("\x57\xE8????\x8B\xC8\x8B\x10\xFF\x52\x2C\x68\x10\x01\x00\x00\xE8????\x8B\xF8\x83\xC4\x04\x85\xFF\x74\x48\x56", "xx????xxxxxxxxxxxxx????xxxxxxxxxx"); + FindFunc_C_BasePlayer_GetLocalPlayer(); } @@ -306,4 +308,6 @@ HookManager::HookManager() InitGlobalHook(); InitGlobalHook(); + + InitGlobalHook(); }