Skip to content

Commit

Permalink
Clean up GoToIntermission hook
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-000 committed Aug 22, 2024
1 parent 5c9968d commit 09f5fe7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
32 changes: 15 additions & 17 deletions src/cs2fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ SH_DECL_MANUALHOOK2_void(CreateWorkshopMapGroup, 0, 0, 0, const char*, const CUt
SH_DECL_MANUALHOOK1(OnTakeDamage_Alive, 0, 0, 0, bool, CTakeDamageInfoContainer *);
SH_DECL_MANUALHOOK1_void(CheckMovingGround, 0, 0, 0, double);
SH_DECL_HOOK2(IGameEventManager2, LoadEventsFromFile, SH_NOATTRIB, 0, int, const char *, bool);
SH_DECL_MANUALHOOK2(GoToIntermission, 0, 0, 0, int64_t*, int64_t, char);
SH_DECL_MANUALHOOK1_void(GoToIntermission, 0, 0, 0, bool);

CS2Fixes g_CS2Fixes;

Expand Down Expand Up @@ -191,9 +191,6 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
int offset = g_GameConfig->GetOffset("IGameTypes_CreateWorkshopMapGroup");
SH_MANUALHOOK_RECONFIGURE(CreateWorkshopMapGroup, offset, 0, 0);

offset = g_GameConfig->GetOffset("CCSGameRules_GoToIntermission");
SH_MANUALHOOK_RECONFIGURE(GoToIntermission, offset, 0, 0);

SH_ADD_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameFramePost), true);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIActivated), false);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIDeactivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIDeactivated), false);
Expand Down Expand Up @@ -279,6 +276,17 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
return false;
}

auto pCCSGameRulesVTable = modules::server->FindVirtualTable("CCSGameRules");

offset = g_GameConfig->GetOffset("CCSGameRules_GoToIntermission");
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find CCSGameRules::GoToIntermission\n");
bRequiredInitLoaded = false;
}
SH_MANUALHOOK_RECONFIGURE(GoToIntermission, offset, 0, 0);
g_iGoToIntermissionId = SH_ADD_MANUALDVPHOOK(GoToIntermission, pCCSGameRulesVTable, SH_MEMBER(this, &CS2Fixes::Hook_GoToIntermission), false);

Message( "All hooks started!\n" );

UnlockConVars();
Expand Down Expand Up @@ -876,22 +884,12 @@ void CS2Fixes::Hook_CreateWorkshopMapGroup(const char* name, const CUtlStringLis
RETURN_META(MRES_IGNORED);
}

void CS2Fixes::CreateGoToIntermissionHook()
{
g_iGoToIntermissionId = SH_ADD_MANUALVPHOOK(GoToIntermission, g_pGameRules, SH_MEMBER(this, &CS2Fixes::Hook_GoToIntermission), false);
}

void CS2Fixes::RemoveGoToIntermissionHook()
{
SH_REMOVE_HOOK_ID(g_iGoToIntermissionId);
}

int64_t* CS2Fixes::Hook_GoToIntermission(int64_t unk1, char unk2)
void CS2Fixes::Hook_GoToIntermission(bool bAbortedMatch)
{
if (!g_pMapVoteSystem->IsIntermissionAllowed())
RETURN_META_VALUE(MRES_SUPERCEDE, nullptr);
RETURN_META(MRES_SUPERCEDE);

RETURN_META_NOREF(MRES_IGNORED, int64_t*);
RETURN_META(MRES_IGNORED);
}

bool g_bDropMapWeapons = false;
Expand Down
6 changes: 2 additions & 4 deletions src/cs2fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "networksystem/inetworkserializer.h"
#include <iserver.h>

class CTakeDamageInfoContainer;
struct CTakeDamageInfoContainer;
class CCSPlayer_MovementServices;

class CS2Fixes : public ISmmPlugin, public IMetamodListener
Expand Down Expand Up @@ -64,9 +64,7 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener
void Hook_StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*);
void Hook_ApplyGameSettings(KeyValues* pKV);
void Hook_CreateWorkshopMapGroup(const char* name, const CUtlStringList& mapList);
void CreateGoToIntermissionHook();
void RemoveGoToIntermissionHook();
int64_t* Hook_GoToIntermission(int64_t unk1, char unk2);
void Hook_GoToIntermission(bool bAbortedMatch);
bool Hook_OnTakeDamage_Alive(CTakeDamageInfoContainer *pInfoContainer);
void Hook_CheckMovingGround(double frametime);
int Hook_LoadEventsFromFile(const char *filename, bool bSearchAll);
Expand Down
5 changes: 0 additions & 5 deletions src/entitylistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ void CEntityListener::OnEntityCreated(CEntityInstance* pEntity)
ExecuteOnce(Patch_GetHammerUniqueId(pEntity));

if (!V_strcmp("cs_gamerules", pEntity->GetClassname()))
{
g_pGameRules = ((CCSGameRulesProxy*)pEntity)->m_pGameRules;
g_CS2Fixes.CreateGoToIntermissionHook();
}
}

void CEntityListener::OnEntityDeleted(CEntityInstance* pEntity)
{
if (!V_strcmp("cs_gamerules", pEntity->GetClassname()))
g_CS2Fixes.RemoveGoToIntermissionHook();
}

void CEntityListener::OnEntityParentChanged(CEntityInstance* pEntity, CEntityInstance* pNewParent)
Expand Down

0 comments on commit 09f5fe7

Please sign in to comment.