public/mms_sample_ext/sm_ext.cpp

00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourceMod Extension Code for Metamod:Source
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id$
00030  */
00031 
00032 #include <stdio.h>
00033 #include "stub_mm.h"
00034 #include "stub_util.h"
00035 #include "sm_ext.h"
00036 
00037 MyExtension g_SMExt;
00038 
00039 bool SM_LoadExtension(char *error, size_t maxlength)
00040 {
00041           if ((smexts = (IExtensionManager *)g_SMAPI->MetaFactory(
00042                               SOURCEMOD_INTERFACE_EXTENSIONS, 
00043                               NULL, 
00044                               NULL))
00045                     == NULL)
00046           {
00047                     if (error && maxlength)
00048                     {
00049                               UTIL_Format(error, maxlength, SOURCEMOD_INTERFACE_EXTENSIONS " interface not found");
00050                     }
00051                     return false;
00052           }
00053 
00054           /* This could be more dynamic */
00055           char path[256];
00056           g_SMAPI->PathFormat(path, 
00057                     sizeof(path), 
00058                     "addons/myplugin/bin/myplugin%s",
00059 #if defined __linux__
00060                     "_i486.so"
00061 #else
00062                     ".dll"
00063 #endif    
00064                     );
00065 
00066           if ((myself = smexts->LoadExternal(&g_SMExt,
00067                               path,
00068                               "myplugin_mm.ext",
00069                               error,
00070                               maxlength))
00071                     == NULL)
00072           {
00073                     SM_UnsetInterfaces();
00074                     return false;
00075           }
00076 
00077           return true;
00078 }
00079 
00080 void SM_UnloadExtension()
00081 {
00082           smexts->UnloadExtension(myself);        
00083 }
00084 
00085 bool MyExtension::OnExtensionLoad(IExtension *me,
00086                     IShareSys *sys, 
00087                     char *error, 
00088                     size_t maxlength, 
00089                     bool late)
00090 {
00091           sharesys = sys;
00092           myself = me;
00093 
00094           /* Get the default interfaces from our configured SDK header */
00095           if (!SM_AcquireInterfaces(error, maxlength))
00096           {
00097                     return false;
00098           }
00099 
00100           return true;        
00101 }
00102 
00103 void MyExtension::OnExtensionUnload()
00104 {
00105           /* Clean up any resources here, and more importantly, make sure 
00106            * any listeners/hooks into SourceMod are totally removed, as well 
00107            * as data structures like handle types and forwards.
00108            */
00109 
00110           //...
00111 
00112           /* Make sure our pointers get NULL'd just in case */
00113           SM_UnsetInterfaces();
00114 }
00115 
00116 void MyExtension::OnExtensionsAllLoaded()
00117 {
00118           /* Called once all extensions are marked as loaded.
00119            * This always called, and always called only once.
00120            */
00121 }
00122 
00123 void MyExtension::OnExtensionPauseChange(bool pause)
00124 {
00125 }
00126 
00127 bool MyExtension::QueryRunning(char *error, size_t maxlength)
00128 {
00129           /* if something is required that can't be determined during the initial 
00130            * load process, print a message here will show a helpful message to 
00131            * users when they view the extension's info.
00132            */
00133           return true;
00134 }
00135 
00136 bool MyExtension::IsMetamodExtension()
00137 {
00138           /* Must return false! */
00139           return false;
00140 }
00141 
00142 const char *MyExtension::GetExtensionName()
00143 {
00144           return mmsplugin->GetName();
00145 }
00146 
00147 const char *MyExtension::GetExtensionURL()
00148 {
00149           return mmsplugin->GetURL();   
00150 }
00151 
00152 const char *MyExtension::GetExtensionTag()
00153 {
00154           return mmsplugin->GetLogTag();
00155 }
00156 
00157 const char *MyExtension::GetExtensionAuthor()
00158 {
00159           return mmsplugin->GetAuthor();
00160 }
00161 
00162 const char *MyExtension::GetExtensionVerString()
00163 {
00164           return mmsplugin->GetVersion();
00165 }
00166 
00167 const char *MyExtension::GetExtensionDescription()
00168 {
00169           return mmsplugin->GetDescription();
00170 }
00171 
00172 const char *MyExtension::GetExtensionDateString()
00173 {
00174           return mmsplugin->GetDate();
00175 }
00176 

Generated on Sun Dec 28 23:26:25 2008 for SourceMod SDK by  doxygen 1.5.1