Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Fix Killstreaks crashing when reconnecting to GameCoordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
dalegaard committed Aug 21, 2023
1 parent 4a90b37 commit 25d72e3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CastingEssentials/Hooking/GroupGlobalVirtualHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace Hooking
GroupGlobalVirtualHook() = delete;
GroupGlobalVirtualHook(const SelfType& other) = delete;

DetourFnType DefaultDetourFn() override { return Internal::SharedLocalDetourFn<SelfType, Type, RetVal, Args...>(this); }
DetourFnType DefaultDetourFn() override { return SharedLocalDetourFn(); }
};

#if 0
Expand Down
11 changes: 9 additions & 2 deletions CastingEssentials/Modules/Killstreaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -330,4 +333,8 @@ bool Killstreaks::FireEventClientSideOverride(IGameEvent *event)
}

return true;
}

void Killstreaks::RequestPriceSheetOverride(CStorePanel*) {
m_RequestPriceSheetHook.SetState(Hooking::HookAction::SUPERCEDE);
}
4 changes: 3 additions & 1 deletion CastingEssentials/Modules/Killstreaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Killstreaks : public Module<Killstreaks>
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;
Expand All @@ -40,6 +41,7 @@ class Killstreaks : public Module<Killstreaks>

std::map<int, int> m_CurrentKillstreaks;
Hook<HookFunc::IGameEventManager2_FireEventClientSide> m_FireEventClientSideHook;
Hook<HookFunc::CStorePanel_RequestPricesheet> m_RequestPriceSheetHook;

static std::array<EntityOffset<int>, 4> s_PlayerStreaks;
static EntityOffset<bool> s_MedigunHealing;
Expand Down
12 changes: 11 additions & 1 deletion CastingEssentials/PluginBase/HookDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class IStudioRender;
class IMaterial;
class IClientRenderable;
class C_TFPlayer;
class CClientState;
class CStorePanel;

namespace vgui
{
Expand Down Expand Up @@ -162,6 +164,8 @@ enum class HookFunc
vgui_Panel_FindChildByName,
vgui_ProgressBar_ApplySettings,

CStorePanel_RequestPricesheet,

Count,
};

Expand Down Expand Up @@ -219,7 +223,8 @@ class HookDefinitions
};
template<> struct HookFuncType<HookFunc::IGameEventManager2_FireEventClientSide>
{
typedef VirtualHook<HookFunc::IGameEventManager2_FireEventClientSide, false, IGameEventManager2, bool, IGameEvent*> Hook;
typedef bool(__thiscall* Raw)(IGameEventManager2* pThis, IGameEvent* event);
typedef GlobalVirtualHook<HookFunc::IGameEventManager2_FireEventClientSide, false, IGameEventManager2, bool, IGameEvent*> Hook;
};
template<> struct HookFuncType<HookFunc::IGameSystem_Add>
{
Expand Down Expand Up @@ -474,4 +479,9 @@ class HookDefinitions
typedef void(__cdecl *Raw)(IClientRenderable* pEnt, bool bTwoPass, bool bShadowDepth, bool bIgnoreDepth);
typedef GlobalHook<HookFunc::Global_DrawTranslucentRenderable, false, void, IClientRenderable*, bool, bool, bool> Hook;
};
template<> struct HookFuncType<HookFunc::CStorePanel_RequestPricesheet>
{
typedef void(__thiscall* Raw)(CStorePanel* pThis);
typedef GlobalClassHook<HookFunc::CStorePanel_RequestPricesheet, false, CStorePanel, void> Hook;
};
};
4 changes: 4 additions & 0 deletions CastingEssentials/PluginBase/HookManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ void HookManager::InitRawFunctionsList()
FindFunc<HookFunc::vgui_Panel_FindChildByName>("\x55\x8B\xEC\x83\xEC\x28\xA1????\x53\x8B\xD9\x33\xC9", "xxxxxxx????xxxxx");
FindFunc<HookFunc::vgui_ProgressBar_ApplySettings>("\x55\x8B\xEC\xD9\xEE\x53", "xxxxxx");

FindFunc<HookFunc::CStorePanel_RequestPricesheet>("\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();
}

Expand Down Expand Up @@ -306,4 +308,6 @@ HookManager::HookManager()

InitGlobalHook<HookFunc::vgui_Panel_FindChildByName>();
InitGlobalHook<HookFunc::vgui_ProgressBar_ApplySettings>();

InitGlobalHook<HookFunc::CStorePanel_RequestPricesheet>();
}

0 comments on commit 25d72e3

Please sign in to comment.