sample_mm/sample_mm.cpp
changeset 605 131878209276
parent 509 811679ebed9e
child 637 b66489d8aedc
     1.1 --- a/sample_mm/sample_mm.cpp	Mon Nov 24 07:50:01 2008 -0600
     1.2 +++ b/sample_mm/sample_mm.cpp	Mon Nov 24 12:03:02 2008 -0600
     1.3 @@ -29,14 +29,14 @@
     1.4  SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char*, const char *, char *, int);
     1.5  SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool);
     1.6  
     1.7 -#if defined ENGINE_ORANGEBOX
     1.8 +#if SOURCE_ENGINE >= SE_ORANGEBOX
     1.9  SH_DECL_HOOK2_void(IServerGameClients, NetworkIDValidated, SH_NOATTRIB, 0, const char *, const char *);
    1.10  SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
    1.11 -#elif defined ENGINE_ORIGINAL
    1.12 +#else
    1.13  SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
    1.14  #endif
    1.15  
    1.16 -StubPlugin g_StubPlugin;
    1.17 +SamplePlugin g_SamplePlugin;
    1.18  IServerGameDLL *server = NULL;
    1.19  IServerGameClients *gameclients = NULL;
    1.20  IVEngineServer *engine = NULL;
    1.21 @@ -45,6 +45,7 @@
    1.22  IServerPluginCallbacks *vsp_callbacks = NULL;
    1.23  IPlayerInfoManager *playerinfomanager = NULL;
    1.24  ICvar *icvar = NULL;
    1.25 +CGlobalVars *gpGlobals = NULL;
    1.26  
    1.27  ConVar sample_cvar("sample_cvar", "42", 0);
    1.28  
    1.29 @@ -61,8 +62,8 @@
    1.30  	}
    1.31  } s_BaseAccessor;
    1.32  
    1.33 -PLUGIN_EXPOSE(StubPlugin, g_StubPlugin);
    1.34 -bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    1.35 +PLUGIN_EXPOSE(SamplePlugin, g_SamplePlugin);
    1.36 +bool SamplePlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    1.37  {
    1.38  	PLUGIN_SAVEVARS();
    1.39  
    1.40 @@ -74,6 +75,8 @@
    1.41  	GET_V_IFACE_ANY(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    1.42  	GET_V_IFACE_ANY(GetServerFactory, playerinfomanager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    1.43  
    1.44 +	gpGlobals = ismm->GetCGlobals();
    1.45 +
    1.46  	META_LOG(g_PLAPI, "Starting plugin.");
    1.47  
    1.48  	/* Load the VSP listener.  This is usually needed for IServerPluginHelpers. */
    1.49 @@ -85,84 +88,84 @@
    1.50  		ismm->EnableVSPListener();
    1.51  	}
    1.52  
    1.53 -	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &StubPlugin::Hook_LevelInit, true);
    1.54 -	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, server, this, &StubPlugin::Hook_ServerActivate, true);
    1.55 -	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &StubPlugin::Hook_GameFrame, true);
    1.56 -	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, server, this, &StubPlugin::Hook_LevelShutdown, false);
    1.57 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientActive, gameclients, this, &StubPlugin::Hook_ClientActive, true);
    1.58 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &StubPlugin::Hook_ClientDisconnect, true);
    1.59 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &StubPlugin::Hook_ClientPutInServer, true);
    1.60 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, gameclients, this, &StubPlugin::Hook_SetCommandClient, true);
    1.61 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, gameclients, this, &StubPlugin::Hook_ClientSettingsChanged, false);
    1.62 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, gameclients, this, &StubPlugin::Hook_ClientConnect, false);
    1.63 -	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &StubPlugin::Hook_ClientCommand, false);
    1.64 +	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &SamplePlugin::Hook_LevelInit, true);
    1.65 +	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, server, this, &SamplePlugin::Hook_ServerActivate, true);
    1.66 +	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &SamplePlugin::Hook_GameFrame, true);
    1.67 +	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, server, this, &SamplePlugin::Hook_LevelShutdown, false);
    1.68 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientActive, gameclients, this, &SamplePlugin::Hook_ClientActive, true);
    1.69 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &SamplePlugin::Hook_ClientDisconnect, true);
    1.70 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &SamplePlugin::Hook_ClientPutInServer, true);
    1.71 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, gameclients, this, &SamplePlugin::Hook_SetCommandClient, true);
    1.72 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, gameclients, this, &SamplePlugin::Hook_ClientSettingsChanged, false);
    1.73 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, gameclients, this, &SamplePlugin::Hook_ClientConnect, false);
    1.74 +	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &SamplePlugin::Hook_ClientCommand, false);
    1.75  
    1.76 -#if defined ENGINE_ORIGINAL
    1.77 +#if SOURCE_ENGINE == SE_EPISODEONE
    1.78  	m_EngineCC = SH_GET_CALLCLASS(engine);
    1.79  #endif
    1.80  
    1.81  	ENGINE_CALL(&IVEngineServer::LogPrint)("All hooks started!\n");
    1.82  
    1.83 -#if defined ENGINE_ORANGEBOX
    1.84 +#if SOURCE_ENGINE >= SE_ORANGEBOX
    1.85  	g_pCVar = icvar;
    1.86  	ConVar_Register(0, &s_BaseAccessor);
    1.87 -#elif defined ENGINE_ORIGINAL
    1.88 +#else
    1.89  	ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor);
    1.90  #endif
    1.91  
    1.92  	return true;
    1.93  }
    1.94  
    1.95 -bool StubPlugin::Unload(char *error, size_t maxlen)
    1.96 +bool SamplePlugin::Unload(char *error, size_t maxlen)
    1.97  {
    1.98 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &StubPlugin::Hook_LevelInit, true);
    1.99 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, server, this, &StubPlugin::Hook_ServerActivate, true);
   1.100 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &StubPlugin::Hook_GameFrame, true);
   1.101 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, server, this, &StubPlugin::Hook_LevelShutdown, false);
   1.102 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientActive, gameclients, this, &StubPlugin::Hook_ClientActive, true);
   1.103 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &StubPlugin::Hook_ClientDisconnect, true);
   1.104 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &StubPlugin::Hook_ClientPutInServer, true);
   1.105 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, gameclients, this, &StubPlugin::Hook_SetCommandClient, true);
   1.106 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, gameclients, this, &StubPlugin::Hook_ClientSettingsChanged, false);
   1.107 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, gameclients, this, &StubPlugin::Hook_ClientConnect, false);
   1.108 -	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &StubPlugin::Hook_ClientCommand, false);
   1.109 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &SamplePlugin::Hook_LevelInit, true);
   1.110 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, server, this, &SamplePlugin::Hook_ServerActivate, true);
   1.111 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &SamplePlugin::Hook_GameFrame, true);
   1.112 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, server, this, &SamplePlugin::Hook_LevelShutdown, false);
   1.113 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientActive, gameclients, this, &SamplePlugin::Hook_ClientActive, true);
   1.114 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &SamplePlugin::Hook_ClientDisconnect, true);
   1.115 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, gameclients, this, &SamplePlugin::Hook_ClientPutInServer, true);
   1.116 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, gameclients, this, &SamplePlugin::Hook_SetCommandClient, true);
   1.117 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, gameclients, this, &SamplePlugin::Hook_ClientSettingsChanged, false);
   1.118 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, gameclients, this, &SamplePlugin::Hook_ClientConnect, false);
   1.119 +	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, gameclients, this, &SamplePlugin::Hook_ClientCommand, false);
   1.120  
   1.121 -#if defined ENGINE_ORIGINAL
   1.122 +#if SOURCE_ENGINE == SE_EPISODEONE
   1.123  	SH_RELEASE_CALLCLASS(m_EngineCC);
   1.124  #endif
   1.125  
   1.126  	return true;
   1.127  }
   1.128  
   1.129 -void StubPlugin::OnVSPListening(IServerPluginCallbacks *iface)
   1.130 +void SamplePlugin::OnVSPListening(IServerPluginCallbacks *iface)
   1.131  {
   1.132  	vsp_callbacks = iface;
   1.133  }
   1.134  
   1.135 -void StubPlugin::Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
   1.136 +void SamplePlugin::Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
   1.137  {
   1.138  	META_LOG(g_PLAPI, "ServerActivate() called: edictCount = %d, clientMax = %d", edictCount, clientMax);
   1.139  }
   1.140  
   1.141 -void StubPlugin::AllPluginsLoaded()
   1.142 +void SamplePlugin::AllPluginsLoaded()
   1.143  {
   1.144  	/* This is where we'd do stuff that relies on the mod or other plugins 
   1.145  	 * being initialized (for example, cvars added and events registered).
   1.146  	 */
   1.147  }
   1.148  
   1.149 -void StubPlugin::Hook_ClientActive(edict_t *pEntity, bool bLoadGame)
   1.150 +void SamplePlugin::Hook_ClientActive(edict_t *pEntity, bool bLoadGame)
   1.151  {
   1.152 -	META_LOG(g_PLAPI, "Hook_ClientActive(%d, %d)", engine->IndexOfEdict(pEntity), bLoadGame);
   1.153 +	META_LOG(g_PLAPI, "Hook_ClientActive(%d, %d)", IndexOfEdict(pEntity), bLoadGame);
   1.154  }
   1.155  
   1.156 -#if defined ENGINE_ORANGEBOX
   1.157 -void StubPlugin::Hook_ClientCommand(edict_t *pEntity, const CCommand &args)
   1.158 -#elif defined ENGINE_ORIGINAL
   1.159 -void StubPlugin::Hook_ClientCommand(edict_t *pEntity)
   1.160 +#if SOURCE_ENGINE >= SE_ORANGEBOX
   1.161 +void SamplePlugin::Hook_ClientCommand(edict_t *pEntity, const CCommand &args)
   1.162 +#else
   1.163 +void SamplePlugin::Hook_ClientCommand(edict_t *pEntity)
   1.164  #endif
   1.165  {
   1.166 -#if defined ENGINE_ORIGINAL
   1.167 +#if SOURCE_ENGINE == SE_EPISODEONE
   1.168  	CCommand args;
   1.169  #endif
   1.170  
   1.171 @@ -235,13 +238,13 @@
   1.172  	}
   1.173  }
   1.174  
   1.175 -void StubPlugin::Hook_ClientSettingsChanged(edict_t *pEdict)
   1.176 +void SamplePlugin::Hook_ClientSettingsChanged(edict_t *pEdict)
   1.177  {
   1.178  	if (playerinfomanager)
   1.179  	{
   1.180  		IPlayerInfo *playerinfo = playerinfomanager->GetPlayerInfo(pEdict);
   1.181  
   1.182 -		const char *name = engine->GetClientConVarValue(engine->IndexOfEdict(pEdict), "name");
   1.183 +		const char *name = engine->GetClientConVarValue(IndexOfEdict(pEdict), "name");
   1.184  
   1.185  		if (playerinfo != NULL
   1.186  			&& name != NULL
   1.187 @@ -256,18 +259,18 @@
   1.188  	}
   1.189  }
   1.190  
   1.191 -bool StubPlugin::Hook_ClientConnect(edict_t *pEntity,
   1.192 +bool SamplePlugin::Hook_ClientConnect(edict_t *pEntity,
   1.193  									const char *pszName,
   1.194  									const char *pszAddress,
   1.195  									char *reject,
   1.196  									int maxrejectlen)
   1.197  {
   1.198 -	META_LOG(g_PLAPI, "Hook_ClientConnect(%d, \"%s\", \"%s\")", engine->IndexOfEdict(pEntity), pszName, pszAddress);
   1.199 +	META_LOG(g_PLAPI, "Hook_ClientConnect(%d, \"%s\", \"%s\")", IndexOfEdict(pEntity), pszName, pszAddress);
   1.200  
   1.201  	return true;
   1.202  }
   1.203  
   1.204 -void StubPlugin::Hook_ClientPutInServer(edict_t *pEntity, char const *playername)
   1.205 +void SamplePlugin::Hook_ClientPutInServer(edict_t *pEntity, char const *playername)
   1.206  {
   1.207  	KeyValues *kv = new KeyValues( "msg" );
   1.208  	kv->SetString( "title", "Hello" );
   1.209 @@ -279,12 +282,12 @@
   1.210  	kv->deleteThis();
   1.211  }
   1.212  
   1.213 -void StubPlugin::Hook_ClientDisconnect(edict_t *pEntity)
   1.214 +void SamplePlugin::Hook_ClientDisconnect(edict_t *pEntity)
   1.215  {
   1.216 -	META_LOG(g_PLAPI, "Hook_ClientDisconnect(%d)", engine->IndexOfEdict(pEntity));
   1.217 +	META_LOG(g_PLAPI, "Hook_ClientDisconnect(%d)", IndexOfEdict(pEntity));
   1.218  }
   1.219  
   1.220 -void StubPlugin::Hook_GameFrame(bool simulating)
   1.221 +void SamplePlugin::Hook_GameFrame(bool simulating)
   1.222  {
   1.223  	/**
   1.224  	 * simulating:
   1.225 @@ -294,7 +297,7 @@
   1.226  	 */
   1.227  }
   1.228  
   1.229 -bool StubPlugin::Hook_LevelInit(const char *pMapName,
   1.230 +bool SamplePlugin::Hook_LevelInit(const char *pMapName,
   1.231  								char const *pMapEntities,
   1.232  								char const *pOldLevel,
   1.233  								char const *pLandmarkName,
   1.234 @@ -306,62 +309,62 @@
   1.235  	return true;
   1.236  }
   1.237  
   1.238 -void StubPlugin::Hook_LevelShutdown()
   1.239 +void SamplePlugin::Hook_LevelShutdown()
   1.240  {
   1.241  	META_LOG(g_PLAPI, "Hook_LevelShutdown()");
   1.242  }
   1.243  
   1.244 -void StubPlugin::Hook_SetCommandClient(int index)
   1.245 +void SamplePlugin::Hook_SetCommandClient(int index)
   1.246  {
   1.247  	META_LOG(g_PLAPI, "Hook_SetCommandClient(%d)", index);
   1.248  }
   1.249  
   1.250 -bool StubPlugin::Pause(char *error, size_t maxlen)
   1.251 +bool SamplePlugin::Pause(char *error, size_t maxlen)
   1.252  {
   1.253  	return true;
   1.254  }
   1.255  
   1.256 -bool StubPlugin::Unpause(char *error, size_t maxlen)
   1.257 +bool SamplePlugin::Unpause(char *error, size_t maxlen)
   1.258  {
   1.259  	return true;
   1.260  }
   1.261  
   1.262 -const char *StubPlugin::GetLicense()
   1.263 +const char *SamplePlugin::GetLicense()
   1.264  {
   1.265  	return "Public Domain";
   1.266  }
   1.267  
   1.268 -const char *StubPlugin::GetVersion()
   1.269 +const char *SamplePlugin::GetVersion()
   1.270  {
   1.271  	return "1.0.0.0";
   1.272  }
   1.273  
   1.274 -const char *StubPlugin::GetDate()
   1.275 +const char *SamplePlugin::GetDate()
   1.276  {
   1.277  	return __DATE__;
   1.278  }
   1.279  
   1.280 -const char *StubPlugin::GetLogTag()
   1.281 +const char *SamplePlugin::GetLogTag()
   1.282  {
   1.283  	return "SAMPLE";
   1.284  }
   1.285  
   1.286 -const char *StubPlugin::GetAuthor()
   1.287 +const char *SamplePlugin::GetAuthor()
   1.288  {
   1.289  	return "AlliedModders LLC";
   1.290  }
   1.291  
   1.292 -const char *StubPlugin::GetDescription()
   1.293 +const char *SamplePlugin::GetDescription()
   1.294  {
   1.295  	return "Sample basic plugin";
   1.296  }
   1.297  
   1.298 -const char *StubPlugin::GetName()
   1.299 +const char *SamplePlugin::GetName()
   1.300  {
   1.301  	return "Sample Plugin";
   1.302  }
   1.303  
   1.304 -const char *StubPlugin::GetURL()
   1.305 +const char *SamplePlugin::GetURL()
   1.306  {
   1.307  	return "http://www.sourcemm.net/";
   1.308  }