1.1 --- a/sourcemm/sample_mm/SamplePlugin.cpp Sun Aug 13 11:55:42 2006 +0000
1.2 +++ b/sourcemm/sample_mm/SamplePlugin.cpp Mon Aug 14 05:37:58 2006 +0000
1.3 @@ -1,40 +1,39 @@
1.4 /* ======== sample_mm ========
1.5 -* Copyright (C) 2004-2006 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 + * Copyright (C) 2004-2006 Metamod:Source Development Team
1.14 + * No warranties of any kind
1.15 + *
1.16 + * License: zlib/libpng
1.17 + *
1.18 + * Author(s): David "BAILOPAN" Anderson
1.19 + * ============================
1.20 + */
1.21
1.22 #include <oslink.h>
1.23 #include "SamplePlugin.h"
1.24 #include "cvars.h"
1.25
1.26 +//Declare the hooks we will be using in this file. Hooking will not compile without these.
1.27 +//The macro naming scheme is SH_DECL_HOOKn[_void].
1.28 +//If you have 5 parameters, it would be HOOK5. If the function is void, add _void.
1.29 +//It stands for "SourceHook, Declare Hook".
1.30 +SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, char const *, char const *, bool, bool);
1.31 +SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
1.32 +SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool);
1.33 +SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0);
1.34 +SH_DECL_HOOK2_void(IServerGameClients, ClientActive, SH_NOATTRIB, 0, edict_t *, bool);
1.35 +SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);
1.36 +SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, char const *);
1.37 +SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, 0, int);
1.38 +SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
1.39 +SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char*, const char *, char *, int);
1.40 +SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
1.41 +SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool);
1.42 +
1.43 SamplePlugin g_SamplePlugin;
1.44 MyListener g_Listener;
1.45
1.46 PLUGIN_EXPOSE(SamplePlugin, g_SamplePlugin);
1.47
1.48 -//This has all of the necessary hook declarations. Read it!
1.49 -#include "meta_hooks.h"
1.50 -
1.51 -#define FIND_IFACE(func, assn_var, num_var, name, type) \
1.52 - do { \
1.53 - if ( (assn_var=(type)((ismm->func())(name, NULL))) != NULL ) { \
1.54 - num_var = 0; \
1.55 - break; \
1.56 - } \
1.57 - if (num_var >= 999) \
1.58 - break; \
1.59 - } while (( num_var=ismm->FormatIface(name, sizeof(name)-1) )); \
1.60 - if (!assn_var) { \
1.61 - if (error) \
1.62 - snprintf(error, maxlen, "Could not find interface %s", name); \
1.63 - return false; \
1.64 - }
1.65 -
1.66 bool SamplePlugin::LevelInit(const char *pMapName, const char *pMapEntities, const char *pOldLevel, const char *pLandmarkName, bool loadGame, bool background)
1.67 {
1.68 META_LOG(g_PLAPI, "LevelInit() called: pMapName=%s", pMapName);
1.69 @@ -112,6 +111,13 @@
1.70 if (!event || !event->GetName())
1.71 RETURN_META_VALUE(MRES_IGNORED, false);
1.72
1.73 + /**
1.74 + * Note that this will only fire on game events that are already being listened to.
1.75 + * For events that are not firing (such as item_pickup), you must actually
1.76 + * register an event listener in the event manager. This hook is provided
1.77 + * as an example for non-eiface hooks only.
1.78 + */
1.79 +
1.80 const char *name = event->GetName();
1.81
1.82 META_LOG(g_PLAPI, "FireGameEvent called: name=%s", name);
1.83 @@ -119,21 +125,28 @@
1.84 RETURN_META_VALUE(MRES_IGNORED, true);
1.85 }
1.86
1.87 +#define GET_V_IFACE(v_factory, v_var, v_type, v_name) \
1.88 + v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name); \
1.89 + if (!v_var) \
1.90 + { \
1.91 + if (error && maxlen) \
1.92 + { \
1.93 + snprintf(error, maxlen, "Could not find interface: %s", v_name); \
1.94 + } \
1.95 + return false; \
1.96 + }
1.97 +
1.98 +
1.99 bool SamplePlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
1.100 {
1.101 PLUGIN_SAVEVARS();
1.102
1.103 - char iface_buffer[255];
1.104 int num = 0;
1.105
1.106 - strcpy(iface_buffer, "ServerGameDLL003");
1.107 - FIND_IFACE(serverFactory, m_ServerDll, num, iface_buffer, IServerGameDLL *);
1.108 - strcpy(iface_buffer, INTERFACEVERSION_VENGINESERVER);
1.109 - FIND_IFACE(engineFactory, m_Engine, num, iface_buffer, IVEngineServer *);
1.110 - strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMECLIENTS);
1.111 - FIND_IFACE(serverFactory, m_ServerClients, num, iface_buffer, IServerGameClients *);
1.112 - strcpy(iface_buffer, INTERFACEVERSION_GAMEEVENTSMANAGER2);
1.113 - FIND_IFACE(engineFactory, m_GameEventManager, num, iface_buffer, IGameEventManager2 *);
1.114 + GET_V_IFACE(serverFactory, m_ServerDll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
1.115 + GET_V_IFACE(engineFactory, m_Engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
1.116 + GET_V_IFACE(serverFactory, m_ServerClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
1.117 + GET_V_IFACE(engineFactory, m_GameEventManager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
1.118
1.119 META_LOG(g_PLAPI, "Starting plugin.\n");
1.120