1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcemm/sample_mm/SamplePlugin.h Tue Sep 18 20:03:47 2007 +0000
1.3 @@ -0,0 +1,132 @@
1.4 +/* ======== sample_mm ========
1.5 + * Copyright (C) 2004-2007 Metamod:Source Development Team
1.6 + * No warranties of any kind
1.7 + *
1.8 + * License: zlib/libpng
1.9 + *
1.10 + * Author(s): David "BAILOPAN" Anderson
1.11 + * ============================
1.12 + */
1.13 +
1.14 +#ifndef _INCLUDE_SAMPLEPLUGIN_H
1.15 +#define _INCLUDE_SAMPLEPLUGIN_H
1.16 +
1.17 +#include <ISmmPlugin.h>
1.18 +#include <sourcehook/sourcehook.h>
1.19 +#include <igameevents.h>
1.20 +
1.21 +#define SAMPLE_VERSION "1.10"
1.22 +
1.23 +class SamplePlugin : public ISmmPlugin, public IMetamodListener
1.24 +{
1.25 +public:
1.26 + bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
1.27 + bool Unload(char *error, size_t maxlen);
1.28 + void AllPluginsLoaded();
1.29 + bool Pause(char *error, size_t maxlen)
1.30 + {
1.31 + return true;
1.32 + }
1.33 + bool Unpause(char *error, size_t maxlen)
1.34 + {
1.35 + return true;
1.36 + }
1.37 +public:
1.38 + int GetApiVersion() { return PLAPI_VERSION; }
1.39 +public:
1.40 + const char *GetAuthor()
1.41 + {
1.42 + return "BAILOPAN";
1.43 + }
1.44 + const char *GetName()
1.45 + {
1.46 + return "Sample Plugin";
1.47 + }
1.48 + const char *GetDescription()
1.49 + {
1.50 + return "Sample plugin that hooks basic things";
1.51 + }
1.52 + const char *GetURL()
1.53 + {
1.54 + return "http://www.sourcemm.net/";
1.55 + }
1.56 + const char *GetLicense()
1.57 + {
1.58 + return "zlib/libpng";
1.59 + }
1.60 + const char *GetVersion()
1.61 + {
1.62 + return SAMPLE_VERSION;
1.63 + }
1.64 + const char *GetDate()
1.65 + {
1.66 + return __DATE__;
1.67 + }
1.68 + const char *GetLogTag()
1.69 + {
1.70 + return "SAMPLE";
1.71 + }
1.72 +public:
1.73 + //These functions are from IServerPluginCallbacks
1.74 + //Note, the parameters might be a little different to match the actual calls!
1.75 +
1.76 + //Called on LevelInit. Server plugins only have pMapName
1.77 + bool LevelInit(const char *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
1.78 +
1.79 + //Called on ServerActivate. Same definition as server plugins
1.80 + void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
1.81 +
1.82 + //Called on a game tick. Same definition as server plugins
1.83 + void GameFrame(bool simulating);
1.84 +
1.85 + //Called on level shutdown. Same definition as server plugins
1.86 + void LevelShutdown(void);
1.87 +
1.88 + //Client is activate (whatever that means). We get an extra parameter...
1.89 + // "If bLoadGame is true, don't spawn the player because its state is already setup."
1.90 + void ClientActive(edict_t *pEntity, bool bLoadGame);
1.91 +
1.92 + //Client disconnects - same as server plugins
1.93 + void ClientDisconnect(edict_t *pEntity);
1.94 +
1.95 + //Client is put in server - same as server plugins
1.96 + void ClientPutInServer(edict_t *pEntity, char const *playername);
1.97 +
1.98 + //Sets the client index - same as server plugins
1.99 + void SetCommandClient(int index);
1.100 +
1.101 + //Called on client settings changed (duh) - same as server plugins
1.102 + void ClientSettingsChanged(edict_t *pEdict);
1.103 +
1.104 + //Called on client connect. Unlike server plugins, we return whether the
1.105 + // connection is allowed rather than set it through a pointer in the first parameter.
1.106 + // You can still supercede the GameDLL through RETURN_META_VALUE(MRES_SUPERCEDE, true/false)
1.107 + bool ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
1.108 +
1.109 + //Called when a client uses a command. Unlike server plugins, it's void.
1.110 + // You can still supercede the gamedll through RETURN_META(MRES_SUPERCEDE).
1.111 + void ClientCommand(edict_t *pEntity);
1.112 +
1.113 + //From IMetamodListener
1.114 + virtual void OnLevelShutdown();
1.115 +
1.116 +private:
1.117 + IGameEventManager2 *m_GameEventManager;
1.118 + IVEngineServer *m_Engine;
1.119 + IServerGameDLL *m_ServerDll;
1.120 + IServerGameClients *m_ServerClients;
1.121 + SourceHook::CallClass<IVEngineServer> *m_Engine_CC;
1.122 +};
1.123 +
1.124 +class MyListener : public IMetamodListener
1.125 +{
1.126 +public:
1.127 + virtual void *OnMetamodQuery(const char *iface, int *ret);
1.128 +};
1.129 +
1.130 +extern SamplePlugin g_SamplePlugin;
1.131 +PLUGIN_GLOBALVARS();
1.132 +
1.133 +bool FireEvent_Handler(IGameEvent *event, bool bDontBroadcast);
1.134 +
1.135 +#endif //_INCLUDE_SAMPLEPLUGIN_H