void SDKTools::SDK_OnUnload() { SourceHook::List<ValveCall *>::iterator iter; for (iter = g_RegCalls.begin(); iter != g_RegCalls.end(); iter++) { delete (*iter); } g_RegCalls.clear(); ShutdownHelpers(); if (g_pAcceptInput) { g_pAcceptInput->Destroy(); g_pAcceptInput = NULL; } g_TEManager.Shutdown(); s_TempEntHooks.Shutdown(); s_SoundHooks.Shutdown(); g_Hooks.Shutdown(); g_OutputManager.Shutdown(); gameconfs->CloseGameConfigFile(g_pGameConf); playerhelpers->RemoveClientListener(&g_SdkTools); playerhelpers->UnregisterCommandTargetProcessor(this); plsys->RemovePluginsListener(&g_OutputManager); SH_REMOVE_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SDKTools::LevelInit), true); if (enginePatch) { SH_RELEASE_CALLCLASS(enginePatch); enginePatch = NULL; } if (enginesoundPatch) { SH_RELEASE_CALLCLASS(enginesoundPatch); enginesoundPatch = NULL; } bool err; if (g_CallHandle != 0) { if ((err = handlesys->RemoveType(g_CallHandle, myself->GetIdentity())) != true) { g_pSM->LogError(myself, "Could not remove call handle (type=%x, err=%d)", g_CallHandle, err); } } if (g_TraceHandle != 0) { if ((err = handlesys->RemoveType(g_TraceHandle, myself->GetIdentity())) != true) { g_pSM->LogError(myself, "Could not remove trace handle (type=%x, err=%d)", g_TraceHandle, err); } } }
void SourceModBase::ShutdownServices() { /* Unload plugins */ scripts->Shutdown(); /* Unload extensions */ extsys->Shutdown(); if (g_pOnMapEnd) forwardsys->ReleaseForward(g_pOnMapEnd); /* Notify! */ SMGlobalClass *pBase = SMGlobalClass::head; while (pBase) { pBase->OnSourceModShutdown(); pBase = pBase->m_pGlobalClassNext; } /* Delete all data packs */ CStack<CDataPack *>::iterator iter; CDataPack *pd; for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++) { pd = (*iter); delete pd; } m_freepacks.popall(); /* Notify! */ pBase = SMGlobalClass::head; while (pBase) { pBase->OnSourceModAllShutdown(); pBase = pBase->m_pGlobalClassNext; } if (enginePatch) { SH_RELEASE_CALLCLASS(enginePatch); enginePatch = NULL; } if (gamedllPatch) { SH_RELEASE_CALLCLASS(gamedllPatch); gamedllPatch = NULL; } SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SourceModBase::LevelShutdown), false); SH_REMOVE_HOOK(IServerGameDLL, GameFrame, gamedll, SH_MEMBER(&g_Timers, &TimerSystem::GameFrame), false); }
bool l4dtoolz::Unload(char *error, size_t maxlen) { #if !defined METAMOD_PLAPI_VERSION SH_RELEASE_CALLCLASS(m_EngineCC); #endif #ifdef L4D1 write_signature(max_players_friend_lobby, friends_lobby_org); write_signature(chuman_limit, human_limit_org); free(friends_lobby_org); free(human_limit_org); #endif write_signature(max_players_connect, max_players_org); write_signature(lobby_sux_ptr, lobby_sux_org); write_signature(max_players_server_browser, server_bplayers_org); write_signature(unreserved_ptr, unreserved_org); write_signature(lobby_match_ptr, lobby_match_org); free(max_players_org); free(lobby_sux_org); free(server_bplayers_org); free(unreserved_org); free(lobby_match_org); return true; }
void SourceModBase::ShutdownServices() { /* Unload plugins */ scripts->Shutdown(); /* Unload extensions */ extsys->Shutdown(); if (g_pOnMapEnd) forwardsys->ReleaseForward(g_pOnMapEnd); /* Notify! */ SMGlobalClass *pBase = SMGlobalClass::head; while (pBase) { pBase->OnSourceModShutdown(); pBase = pBase->m_pGlobalClassNext; } sCoreProviderImpl.ShutdownHooks(); /* Notify! */ pBase = SMGlobalClass::head; while (pBase) { pBase->OnSourceModAllShutdown(); pBase = pBase->m_pGlobalClassNext; } if (enginePatch) { SH_RELEASE_CALLCLASS(enginePatch); enginePatch = NULL; } if (gamedllPatch) { SH_RELEASE_CALLCLASS(gamedllPatch); gamedllPatch = NULL; } SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SourceModBase::LevelShutdown), false); SH_REMOVE_HOOK(IServerGameDLL, GameFrame, gamedll, SH_MEMBER(&g_Timers, &TimerSystem::GameFrame), false); SH_REMOVE_HOOK(IServerGameDLL, Think, gamedll, SH_MEMBER(logicore.callbacks, &IProviderCallbacks::OnThink), false); }
bool l4dtoolz::Unload(char *error, size_t maxlen) { #if !defined METAMOD_PLAPI_VERSION SH_RELEASE_CALLCLASS(m_EngineCC); #endif if(max_players_friend_lobby != NULL) WriteSignature(max_players_friend_lobby, friends_lobby_org); if(max_players_connect != NULL) WriteSignature(max_players_connect, max_players_org); if(lobby_sux_ptr != NULL) WriteSignature(lobby_sux_ptr, lobby_sux_org); if(max_players_server_browser != NULL) WriteSignature(max_players_server_browser, server_bplayers_org); if(chuman_limit != NULL) WriteSignature(chuman_limit, human_limit_org); if(tmp_player != NULL) WriteSignature(tmp_player, players_org); if(tmp_player2 != NULL) WriteSignature(tmp_player2, players_org2); if(unreserved_ptr != NULL) WriteSignature(unreserved_ptr, unreserved_org); if(lobby_match_ptr != NULL) WriteSignature(lobby_match_ptr, lobby_match_org); #ifdef WIN32 CloseHandle(hProcess); #endif delete[] friends_lobby_org; delete[] max_players_org; delete[] lobby_sux_org; delete[] server_bplayers_org; delete[] human_limit_org; delete[] players_org; delete[] players_org2; delete[] unreserved_org; return true; }
bool TestThisPtrOffs(std::string &error) { GET_SHPTR(g_SHPtr); g_PLID = 1337; Derived *pD = MyInstanceFactory(); Base1 *pB1 = pD; Base2 *pB2 = pD; CAutoPtrDestruction<Derived> apd(pD); // It should be: // pB1 = pD // pB2 > pB1 // 1) // Get a callclass for pD // Verify whether the this pointers are correct // Also call them normally to make sure that we aren't messing it up ;) SourceHook::CallClass<Derived> *pD_CC = SH_GET_CALLCLASS(pD); SH_CALL(pD_CC, &Derived::Func1)(); SH_CALL(pD_CC, &Derived::Func2)(); SH_CALL(pD_CC, &Derived::Func3)(); pD->Func1(); pD->Func2(); pD->Func3(); CHECK_STATES((&g_States, new State_Func1_Called(pB1), new State_Func2_Called(pB2), new State_Func3_Called(pD), new State_Func1_Called(pB1), new State_Func2_Called(pB2), new State_Func3_Called(pD), NULL), "Part 1"); SH_CALL(pD_CC, &Base1::Func1)(); SH_CALL(pD_CC, &Base2::Func2)(); CHECK_STATES((&g_States, new State_Func1_Called(pB1), new State_Func2_Called(pB2), NULL), "Part 1.1"); // 2) // Get callclasses for the other ones and verify it as well SourceHook::CallClass<Base1> *pB1_CC = SH_GET_CALLCLASS(pB1); SourceHook::CallClass<Base2> *pB2_CC = SH_GET_CALLCLASS(pB2); SH_CALL(pB1_CC, &Base1::Func1)(); SH_CALL(pB2_CC, &Base2::Func2)(); CHECK_STATES((&g_States, new State_Func1_Called(pB1), new State_Func2_Called(pB2), NULL), "Part 2"); // 3) Add hooks on them (referring to them through pD1 / Derived) // Check whether the hooks are called with the correct this pointer SH_ADD_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false); SH_ADD_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false); SH_ADD_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false); pD->Func1(); pD->Func2(); pD->Func3(); pB1->Func1(); pB2->Func2(); // The handlers should always be called with the pointer to Derived CHECK_STATES((&g_States, new State_Func1H_Called(pD), new State_Func1_Called(pB1), new State_Func2H_Called(pD), new State_Func2_Called(pB2), new State_Func3H_Called(pD), new State_Func3_Called(pD), new State_Func1H_Called(pD), new State_Func1_Called(pB1), new State_Func2H_Called(pD), new State_Func2_Called(pB2), NULL), "Part 3"); SH_REMOVE_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false); SH_REMOVE_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false); SH_REMOVE_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false); // 4) // Now add the hooks on Base1 and Base2 and check again // Note that the new implicit_cast should convert the pD to Base1*/Base2* :) SH_ADD_HOOK(Base1, Func1, pD, SH_STATIC(Handler_Func1), false); SH_ADD_HOOK(Base2, Func2, pD, SH_STATIC(Handler_Func2), false); SH_ADD_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false); pD->Func1(); pD->Func2(); pD->Func3(); pB1->Func1(); pB2->Func2(); // This time, the handlers for Func1 should be called with pB1 and the handlers // for Func2 should be called with pB2 CHECK_STATES((&g_States, new State_Func1H_Called(pB1), new State_Func1_Called(pB1), new State_Func2H_Called(pB2), new State_Func2_Called(pB2), new State_Func3H_Called(pD), new State_Func3_Called(pD), new State_Func1H_Called(pB1), new State_Func1_Called(pB1), new State_Func2H_Called(pB2), new State_Func2_Called(pB2), NULL), "Part 4"); SH_REMOVE_HOOK(Base1, Func1, pD, SH_STATIC(Handler_Func1), false); SH_REMOVE_HOOK(Base2, Func2, pD, SH_STATIC(Handler_Func2), false); SH_REMOVE_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false); // 5) // Add some hooks, and use callclasses // 5.1) First off, add all of them on pD SH_ADD_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false); SH_ADD_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false); SH_ADD_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false); pD->Func1(); pD->Func2(); pD->Func3(); CHECK_STATES((&g_States, new State_Func1H_Called(pD), new State_Func1_Called(pB1), new State_Func2H_Called(pD), new State_Func2_Called(pB2), new State_Func3H_Called(pD), new State_Func3_Called(pD), NULL), "Part 5.1"); SH_CALL(pD_CC, &Derived::Func1)(); SH_CALL(pD_CC, &Derived::Func2)(); SH_CALL(pD_CC, &Derived::Func3)(); SH_CALL(pB1_CC, &Base1::Func1)(); SH_CALL(pB2_CC, &Base2::Func2)(); CHECK_STATES((&g_States, new State_Func1_Called(pB1), new State_Func2_Called(pB2), new State_Func3_Called(pD), new State_Func1_Called(pB1), new State_Func2_Called(pB2), NULL), "Part 5.2"); SH_REMOVE_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false); SH_REMOVE_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false); SH_REMOVE_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false); SH_RELEASE_CALLCLASS(pB1_CC); SH_RELEASE_CALLCLASS(pB2_CC); SH_RELEASE_CALLCLASS(pD_CC); return true; }
void ValveMenuStyle::OnSourceModShutdown() { SH_RELEASE_CALLCLASS(g_pSPHCC); SH_REMOVE_HOOK_MEMFUNC(IServerPluginHelpers, CreateMessage, serverpluginhelpers, this, &ValveMenuStyle::HookCreateMessage, false); g_Players.RemoveClientListener(this); }
bool CSourceMMMAP::Unload(char *error, size_t maxlen) { #if defined ( GAME_CSGO ) ConCommand *remove_cheat_on_bot_kill = static_cast<ConCommand *>(g_pCVar->FindCommand("bot_kill")); if (remove_cheat_on_bot_kill) { if (!(remove_cheat_on_bot_kill->GetFlags() & FCVAR_CHEAT)) remove_cheat_on_bot_kill->AddFlags(FCVAR_CHEAT); } #endif if(g_CallBackCount > 0) { for(unsigned int i=0;i<g_CallBackCount;i++) { AdminInterfaceListner *ptr = (AdminInterfaceListner *)g_CallBackList[i]->ptr; if(!ptr) continue; ptr->OnAdminInterfaceUnload(); } } gpManiAdminPlugin->Unload(); //IT IS CRUCIAL THAT YOU REMOVE CVARS. //As of Metamod:Source 1.00-RC2, it will automatically remove them for you. //But this is only if you've registered them correctly! //Make sure we remove any hooks we did... this may not be necessary since //SourceHook is capable of unloading plugins' hooks itself, but just to be safe. // SH_REMOVE_HOOK_STATICFUNC(IGameEventManager2, FireEvent, gameeventmanager, FireEvent_Handler, false); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, serverdll, &g_ManiCallback, &CSourceMMMAP::LevelInit, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, serverdll, &g_ManiCallback, &CSourceMMMAP::ServerActivate, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, serverdll, &g_ManiCallback, &CSourceMMMAP::GameFrame, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, serverdll, &g_ManiCallback, &CSourceMMMAP::LevelShutdown, false); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientActive, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientActive, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientDisconnect, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientPutInServer, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverclients, &g_ManiCallback, &CSourceMMMAP::SetCommandClient, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientSettingsChanged, true); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientConnect, false); SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientCommand, false); if (voiceserver && gpManiGameType->IsVoiceAllowed()) { SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_ManiSMMHooks, &ManiSMMHooks::SetClientListening, false); } if (effects && gpManiGameType->GetAdvancedEffectsAllowed()) { SH_REMOVE_HOOK_MEMFUNC(ITempEntsSystem, PlayerDecal, temp_ents, &g_ManiSMMHooks, &ManiSMMHooks::PlayerDecal, false); } if (pSayCmd) SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pSayCmd, Say_handler, false); if (pRespawnEntities) SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pRespawnEntities, RespawnEntities_handler, false); if (pTeamSayCmd) SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pTeamSayCmd, TeamSay_handler, false); if (pChangeLevelCmd) SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pChangeLevelCmd, ChangeLevel_handler, false); if (pAutoBuyCmd) { SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pAutoBuyCmd, AutoBuy_handler, false); #if !defined GAME_ORANGE && defined SOURCEMM SH_RELEASE_CALLCLASS(autobuy_cc); #endif } if (pReBuyCmd) { SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, pReBuyCmd, ReBuy_handler, false); #if !defined GAME_ORANGE && defined SOURCEMM SH_RELEASE_CALLCLASS(rebuy_cc); #endif } #if !defined GAME_ORANGE && defined SOURCEMM if (gpManiGameType->GetAdvancedEffectsAllowed()) { SH_RELEASE_CALLCLASS(temp_ents_cc); } //this, sourcehook does not keep track of. we must do this. SH_RELEASE_CALLCLASS(engine_cc); SH_RELEASE_CALLCLASS(voiceserver_cc); SH_RELEASE_CALLCLASS(serverdll_cc); #endif //this, sourcehook does not keep track of. we must do this. #if defined ( GAME_ORANGE ) ConVar_Unregister(); // probably not needed, but do it just in case. #endif return true; }