diff -r 63d54a87df53 -r e6abd02a6a95 sample_mm/sample_mm.cpp --- a/sample_mm/sample_mm.cpp Sun Feb 17 22:03:10 2008 +0000 +++ b/sample_mm/sample_mm.cpp Sun Feb 17 22:56:20 2008 +0000 @@ -29,10 +29,10 @@ SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char*, const char *, char *, int); SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool); -#if defined ORANGEBOX_BUILD +#if defined ENGINE_ORANGEBOX SH_DECL_HOOK2_void(IServerGameClients, NetworkIDValidated, SH_NOATTRIB, 0, const char *, const char *); SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &); -#else +#elif defined ENGINE_ORIGINAL SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *); #endif @@ -45,6 +45,21 @@ IServerPluginCallbacks *vsp_callbacks = NULL; IPlayerInfoManager *playerinfomanager = NULL; +ConVar sample_cvar("sample_cvar", "42", 0); + +/** + * Something like this is needed to register cvars/CON_COMMANDs. + */ +class BaseAccessor : public IConCommandBaseAccessor +{ +public: + bool RegisterConCommandBase(ConCommandBase *pCommandBase) + { + /* Always call META_REGCVAR instead of going through the engine. */ + return META_REGCVAR(pCommandBase); + } +} s_BaseAccessor; + PLUGIN_EXPOSE(StubPlugin, g_StubPlugin); bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) { @@ -59,40 +74,60 @@ META_LOG(g_PLAPI, "Starting plugin."); - /* Load the VSP listener. Most people won't need this. */ + /* Load the VSP listener. This is usually needed for IServerPluginHelpers. */ +#if defined METAMOD_PLAPI_VERSION if ((vsp_callbacks = ismm->GetVSPInfo(NULL)) == NULL) +#endif { ismm->AddListener(this, this); ismm->EnableVSPListener(); } - m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, LevelInit, server, SH_MEMBER(this, &StubPlugin::Hook_LevelInit), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, ServerActivate, server, SH_MEMBER(this, &StubPlugin::Hook_ServerActivate), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, GameFrame, server, SH_MEMBER(this, &StubPlugin::Hook_GameFrame), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, LevelShutdown, server, SH_MEMBER(this, &StubPlugin::Hook_LevelShutdown), false)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientActive, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientActive), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientDisconnect, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientDisconnect), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientPutInServer, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientPutInServer), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, SetCommandClient, gameclients, SH_MEMBER(this, &StubPlugin::Hook_SetCommandClient), true)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientSettingsChanged, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientSettingsChanged), false)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientConnect, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientConnect), false)); - m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientCommand, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientCommand), false)); + SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &StubPlugin::Hook_LevelInit, true); + SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, server, this, &StubPlugin::Hook_ServerActivate, true); + SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &StubPlugin::Hook_GameFrame, true); + SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, server, this, &StubPlugin::Hook_LevelShutdown, false); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientActive, gameclients, this, &StubPlugin::Hook_ClientActive, true); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &StubPlugin::Hook_ClientDisconnect, true); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &StubPlugin::Hook_ClientPutInServer, true); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, gameclients, this, &StubPlugin::Hook_SetCommandClient, true); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, gameclients, this, &StubPlugin::Hook_ClientSettingsChanged, false); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, gameclients, this, &StubPlugin::Hook_ClientConnect, false); + SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &StubPlugin::Hook_ClientCommand, false); - SH_CALL(engine, &IVEngineServer::LogPrint)("All hooks started!\n"); +#if defined ENGINE_ORIGINAL + m_EngineCC = SH_GET_CALLCLASS(engine); +#endif + + ENGINE_CALL(&IVEngineServer::LogPrint)("All hooks started!\n"); + +#if defined ENGINE_ORANGEBOX + g_pCVar = ICvar; + ConVar_Register(0, &s_BaseAccessor); +#elif defined ENGINE_ORIGINAL + ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor); +#endif return true; } bool StubPlugin::Unload(char *error, size_t maxlen) { - for (size_t i = 0; i < m_hooks.size(); i++) - { - if (m_hooks[i] != 0) - { - SH_REMOVE_HOOK_ID(m_hooks[i]); - } - } - m_hooks.clear(); + SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &StubPlugin::Hook_LevelInit, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, server, this, &StubPlugin::Hook_ServerActivate, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &StubPlugin::Hook_GameFrame, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, server, this, &StubPlugin::Hook_LevelShutdown, false); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientActive, gameclients, this, &StubPlugin::Hook_ClientActive, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &StubPlugin::Hook_ClientDisconnect, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &StubPlugin::Hook_ClientPutInServer, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, gameclients, this, &StubPlugin::Hook_SetCommandClient, true); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, gameclients, this, &StubPlugin::Hook_ClientSettingsChanged, false); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, gameclients, this, &StubPlugin::Hook_ClientConnect, false); + SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &StubPlugin::Hook_ClientCommand, false); + +#if defined ENGINE_ORIGINAL + SH_RELEASE_CALLCLASS(m_EngineCC); +#endif return true; } @@ -119,13 +154,13 @@ META_LOG(g_PLAPI, "Hook_ClientActive(%d, %d)", engine->IndexOfEdict(pEntity), bLoadGame); } -#if defined ORANGEBOX_BUILD +#if defined ENGINE_ORANGEBOX void StubPlugin::Hook_ClientCommand(edict_t *pEntity, const CCommand &args) -#else +#elif defined ENGINE_ORIGINAL void StubPlugin::Hook_ClientCommand(edict_t *pEntity) #endif { -#if !defined ORANGEBOX_BUILD +#if defined ENGINE_ORIGINAL CCommand args; #endif @@ -147,9 +182,9 @@ for (int i = 1; i < 9; i++) { char num[10], msg[10], cmd[10]; - g_SMAPI->Format( num, sizeof(num), "%i", i ); - g_SMAPI->Format( msg, sizeof(msg), "Option %i", i ); - g_SMAPI->Format( cmd, sizeof(cmd), "option %i", i ); + MM_Format( num, sizeof(num), "%i", i ); + MM_Format( msg, sizeof(msg), "Option %i", i ); + MM_Format( cmd, sizeof(cmd), "option %i", i ); KeyValues *item1 = kv->FindKey(num, true); item1->SetString("msg", msg); @@ -208,11 +243,12 @@ if (playerinfo != NULL && name != NULL + && strcmp(engine->GetPlayerNetworkIDString(pEdict), "BOT") != 0 && playerinfo->GetName() != NULL && strcmp(name, playerinfo->GetName()) == 0) { char msg[128]; - g_SMAPI->Format(msg, sizeof(msg), "Your name changed to \"%s\" (from \"%s\")\n", name, playerinfo->GetName()); + MM_Format(msg, sizeof(msg), "Your name changed to \"%s\" (from \"%s\")\n", name, playerinfo->GetName()); engine->ClientPrintf(pEdict, msg); } }