void HLTVServerWrapper::Unhook() { if (!m_Connected) return; g_pSTVForwards.UnhookServer(this); if (m_DemoRecorder) g_pSTVForwards.UnhookRecorder(m_DemoRecorder); if (g_HLTVServers.HasShutdownOffset()) SH_REMOVE_MANUALHOOK(CHLTVServer_Shutdown, m_HLTVServer->GetBaseServer(), SH_MEMBER(this, &HLTVServerWrapper::OnHLTVServerShutdown), false); if (iserver) { IClient *pClient = iserver->GetClient(m_HLTVServer->GetHLTVSlot()); if (pClient) { SH_REMOVE_HOOK(IClient, ExecuteStringCommand, pClient, SH_MEMBER(this, &HLTVServerWrapper::OnHLTVBotExecuteStringCommand), false); SH_REMOVE_HOOK(IClient, ExecuteStringCommand, pClient, SH_MEMBER(this, &HLTVServerWrapper::OnHLTVBotExecuteStringCommand_Post), true); #if SOURCE_ENGINE != SE_CSGO SH_REMOVE_HOOK(IClient, ClientPrintf, pClient, SH_MEMBER(this, &HLTVServerWrapper::OnIClient_ClientPrintf_Post), false); #ifndef WIN32 // The IClient vtable is +4 from the CBaseClient vtable due to multiple inheritance. void *pGameClient = (void *)((intptr_t)pClient - 4); if (g_HLTVServers.HasClientPrintfOffset()) SH_REMOVE_MANUALHOOK(CGameClient_ClientPrintf, pGameClient, SH_MEMBER(this, &HLTVServerWrapper::OnCGameClient_ClientPrintf_Post), false); #endif // !WIN32 #endif // SOURCE_ENGINE != SE_CSGO } } }
void CForwardManager::UnhookClient(IClient *client) { // Remove ExecuteStringCommand hook g_pSTVCommonHooks.RemoveSpectatorHook(this, client); void *pGameClient = (void *)((intptr_t)client - 4); if (m_bHasActivatePlayerOffset) SH_REMOVE_MANUALHOOK(CBaseClient_ActivatePlayer, pGameClient, SH_MEMBER(this, &CForwardManager::OnSpectatorPutInServer), true); SH_REMOVE_HOOK(IClient, Disconnect, client, SH_MEMBER(this, &CForwardManager::IClient_OnSpectatorDisconnect), false); #ifndef WIN32 if (m_bHasDisconnectOffset) SH_REMOVE_MANUALHOOK(CBaseClient_Disconnect, pGameClient, SH_MEMBER(this, &CForwardManager::BaseClient_OnSpectatorDisconnect), false); #endif }
void CHookManager::OnClientDisconnecting(int client) { if (!PRCH_enabled) return; if (!PRCH_used) return; edict_t *pEdict = PEntityOfEntIndex(client); if (!pEdict) { return; } IServerUnknown *pUnknown = pEdict->GetUnknown(); if (!pUnknown) { return; } CBaseEntity *pEntity = pUnknown->GetBaseEntity(); if (!pEntity) { return; } SH_REMOVE_MANUALHOOK(PlayerRunCmdHook, pEntity, SH_MEMBER(this, &CHookManager::PlayerRunCmd), false); }
void CForwardManager::UnhookServer(HLTVServerWrapper *wrapper) { IServer *server = wrapper->GetBaseServer(); if (m_bHasClientConnectOffset) SH_REMOVE_MANUALHOOK(CHLTVServer_ConnectClient, server, SH_MEMBER(this, &CForwardManager::OnSpectatorConnect), false); if (m_bHasGetChallengeTypeOffset) SH_REMOVE_MANUALHOOK(CHLTVServer_GetChallengeType, server, SH_MEMBER(this, &CForwardManager::OnGetChallengeType), false); // Unhook all connected clients as well. for (int i = 0; i < server->GetClientCount(); i++) { IClient *client = server->GetClient(i); if (client->IsConnected()) UnhookClient(client); } }
void HLTVServerWrapperManager::ShutdownHooks() { #ifndef WIN32 g_pSTVForwards.RemoveStartRecordingDetour(); g_pSTVForwards.RemoveStopRecordingDetour(); #endif #if SOURCE_ENGINE != SE_CSGO if (m_bSendNetMsgHooked) { SH_REMOVE_MANUALHOOK(NetChan_SendNetMsg, &FakeNetChan, SH_MEMBER(this, &HLTVServerWrapperManager::OnHLTVBotNetChanSendNetMsg), false); m_bSendNetMsgHooked = false; } #endif }