sourcemm/sample_mm/SamplePlugin.cpp
author David Anderson <dvander@alliedmods.net>
Mon Apr 18 19:33:44 2005 +0000 (2005-04-18)
changeset 20 7d2ff2c0999b
parent 12 9fd53562f68c
child 22 3fe8e457c5a2
permissions -rw-r--r--
Updated for API 004, also added sourcehook stuff again
     1 #include <oslink.h>
     2 #include "SamplePlugin.h"
     3 
     4 SamplePlugin g_SamplePlugin;
     5 
     6 PLUGIN_EXPOSE(SamplePlugin, g_SamplePlugin);
     7 
     8 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, char const *, char const *, bool, bool);
     9 
    10 bool LevelInit_handler( char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background );
    11 
    12 bool SamplePlugin::Load(PluginId id, ISmmAPI *ismm, factories *list, char *error, size_t maxlen)
    13 {
    14 	PLUGIN_SAVEVARS();
    15 
    16 	IServerGameDLL *isgd = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMEDLL, NULL));
    17 
    18 	if (!isgd)
    19 	{
    20 		snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_SERVERGAMEDLL);
    21 		return false;
    22 	}
    23 
    24 	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelInit, isgd, LevelInit_handler, false);
    25 
    26 	return true;
    27 }
    28 
    29 bool SamplePlugin::Unload(char *error, size_t maxlen)
    30 {
    31 	return true;
    32 }
    33 
    34 void SamplePlugin::AllPluginsLoaded()
    35 {
    36 	//we don't really care
    37 }
    38 
    39 bool LevelInit_handler( char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background )
    40 {
    41 	FILE *fp = fopen("c:\\dump.txt", "at");
    42 	if (!fp)
    43 		RETURN_META_VALUE(MRES_IGNORED, false);
    44 
    45 	fprintf(fp, "Map name: %s (old level: %s)\n", pMapName?pMapName:"", pOldLevel?pOldLevel:"");
    46 
    47 	fclose(fp);
    48 
    49 	RETURN_META_VALUE(MRES_IGNORED, false);
    50 }