1.1 --- a/sourcemm/sample_mm/SamplePlugin.cpp Thu May 26 08:06:23 2005 +0000
1.2 +++ b/sourcemm/sample_mm/SamplePlugin.cpp Thu May 26 08:32:34 2005 +0000
1.3 @@ -10,6 +10,7 @@
1.4
1.5 #include <oslink.h>
1.6 #include "SamplePlugin.h"
1.7 +#include "cvars.h"
1.8
1.9 SamplePlugin g_SamplePlugin;
1.10
1.11 @@ -32,7 +33,8 @@
1.12
1.13 void SamplePlugin::GameFrame(bool simulating)
1.14 {
1.15 - META_LOG(g_PLAPI, "GameFrame() called: simulating=%d", simulating);
1.16 + //don't log this, it just pumps stuff to the screen ;]
1.17 + //META_LOG(g_PLAPI, "GameFrame() called: simulating=%d", simulating);
1.18 RETURN_META(MRES_IGNORED);
1.19 }
1.20
1.21 @@ -84,6 +86,18 @@
1.22 RETURN_META(MRES_IGNORED);
1.23 }
1.24
1.25 +bool FireEvent_Handler(IGameEvent *event, bool bDontBroadcast)
1.26 +{
1.27 + if (!event || !event->GetName())
1.28 + RETURN_META_VALUE(MRES_IGNORED, false);
1.29 +
1.30 + const char *name = event->GetName();
1.31 +
1.32 + META_LOG(g_PLAPI, "FireGameEvent called: name=%s", name);
1.33 +
1.34 + RETURN_META_VALUE(MRES_IGNORED, true);
1.35 +}
1.36 +
1.37 bool SamplePlugin::Load(PluginId id, ISmmAPI *ismm, factories *list, char *error, size_t maxlen)
1.38 {
1.39 PLUGIN_SAVEVARS();
1.40 @@ -91,6 +105,7 @@
1.41 m_ServerDll = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMEDLL, NULL));
1.42 m_Engine = (IVEngineServer *)((ismm->engineFactory())(INTERFACEVERSION_VENGINESERVER, NULL));
1.43 m_ServerClients = (IServerGameClients *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMECLIENTS, NULL));
1.44 + m_GameEventManager = (IGameEventManager2 *)((ismm->engineFactory())(INTERFACEVERSION_GAMEEVENTSMANAGER2, NULL));
1.45
1.46 if (!m_ServerDll)
1.47 {
1.48 @@ -107,9 +122,17 @@
1.49 snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_SERVERGAMECLIENTS);
1.50 return false;
1.51 }
1.52 + if (!m_GameEventManager)
1.53 + {
1.54 + snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_GAMEEVENTSMANAGER2);
1.55 + return false;
1.56 + }
1.57
1.58 META_LOG(g_PLAPI, "Starting plugin.\n");
1.59
1.60 + //Init our cvars/concmds
1.61 + ConCommandBaseMgr::OneTimeInit(&g_Accessor);
1.62 +
1.63 //We're hooking the following things as POST, in order to seem like Server Plugins.
1.64 //However, I don't actually know if Valve has done server plugins as POST or not.
1.65 //Change the last parameter to 'false' in order to change this to PRE.
1.66 @@ -141,6 +164,9 @@
1.67 //Hook ClientCommand to our function
1.68 SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, m_ServerClients, &g_SamplePlugin, &SamplePlugin::ClientCommand, false);
1.69
1.70 + //This hook is a static hook, no member function
1.71 + SH_ADD_HOOK_STATICFUNC(IGameEventManager2, FireEvent, m_GameEventManager, FireEvent_Handler, false);
1.72 +
1.73 //Get the call class for IVServerEngine so we can safely call functions without
1.74 // invoking their hooks (when needed).
1.75 m_Engine_CC = SH_GET_CALLCLASS(m_Engine);
1.76 @@ -152,9 +178,14 @@
1.77
1.78 bool SamplePlugin::Unload(char *error, size_t maxlen)
1.79 {
1.80 + //IT IS CRUCIAL THAT YOU REMOVE CVARS.
1.81 + //As of Metamod:Source 1.00-RC2, it will automatically remove them for you.
1.82 + //But this is only if you've registered them correctly!
1.83 +
1.84 //Make sure we remove any hooks we did... this may not be necessary since
1.85 - // SourceHook is capable of unloading plugins' hooks itself, but just to be safe.
1.86 + //SourceHook is capable of unloading plugins' hooks itself, but just to be safe.
1.87
1.88 + SH_REMOVE_HOOK_STATICFUNC(IGameEventManager2, FireEvent, m_GameEventManager, FireEvent_Handler, false);
1.89 SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, m_ServerDll, &g_SamplePlugin, &SamplePlugin::LevelInit, true);
1.90 SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, m_ServerDll, &g_SamplePlugin, &SamplePlugin::ServerActivate, true);
1.91 SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, m_ServerDll, &g_SamplePlugin, &SamplePlugin::GameFrame, true);
1.92 @@ -167,6 +198,7 @@
1.93 SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, m_ServerClients, &g_SamplePlugin, &SamplePlugin::ClientConnect, false);
1.94 SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, m_ServerClients, &g_SamplePlugin, &SamplePlugin::ClientCommand, false);
1.95
1.96 + //this, sourcehook does not keep track of. we must do this.
1.97 SH_RELEASE_CALLCLASS(m_Engine_CC);
1.98
1.99 return true;