public/mms_sample_ext/sm_ext.cpp
author Nicholas Hastings <skamonkey@gmail.com>
Thu Jul 04 11:28:32 2013 -0400 (2013-07-04)
changeset 3931 576fa42454dc
parent 1990 de135d1f05b1
permissions -rw-r--r--
Fixed build for real.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Extension Code for Metamod:Source
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include <stdio.h>
    33 #include "stub_mm.h"
    34 #include "stub_util.h"
    35 #include "sm_ext.h"
    36 
    37 MyExtension g_SMExt;
    38 
    39 bool SM_LoadExtension(char *error, size_t maxlength)
    40 {
    41 	if ((smexts = (IExtensionManager *)g_SMAPI->MetaFactory(
    42 			SOURCEMOD_INTERFACE_EXTENSIONS, 
    43 			NULL, 
    44 			NULL))
    45 		== NULL)
    46 	{
    47 		if (error && maxlength)
    48 		{
    49 			UTIL_Format(error, maxlength, SOURCEMOD_INTERFACE_EXTENSIONS " interface not found");
    50 		}
    51 		return false;
    52 	}
    53 
    54 	/* This could be more dynamic */
    55 	char path[256];
    56 	g_SMAPI->PathFormat(path, 
    57 		sizeof(path), 
    58 		"addons/myplugin/bin/myplugin%s",
    59 #if defined __linux__
    60 		"_i486.so"
    61 #else
    62 		".dll"
    63 #endif	
    64 		);
    65 
    66 	if ((myself = smexts->LoadExternal(&g_SMExt,
    67 			path,
    68 			"myplugin_mm.ext",
    69 			error,
    70 			maxlength))
    71 		== NULL)
    72 	{
    73 		SM_UnsetInterfaces();
    74 		return false;
    75 	}
    76 
    77 	return true;
    78 }
    79 
    80 void SM_UnloadExtension()
    81 {
    82 	smexts->UnloadExtension(myself);	
    83 }
    84 
    85 bool MyExtension::OnExtensionLoad(IExtension *me,
    86 		IShareSys *sys, 
    87 		char *error, 
    88 		size_t maxlength, 
    89 		bool late)
    90 {
    91 	sharesys = sys;
    92 	myself = me;
    93 
    94 	/* Get the default interfaces from our configured SDK header */
    95 	if (!SM_AcquireInterfaces(error, maxlength))
    96 	{
    97 		return false;
    98 	}
    99 
   100 	return true;	
   101 }
   102 
   103 void MyExtension::OnExtensionUnload()
   104 {
   105 	/* Clean up any resources here, and more importantly, make sure 
   106 	 * any listeners/hooks into SourceMod are totally removed, as well 
   107 	 * as data structures like handle types and forwards.
   108 	 */
   109 
   110 	//...
   111 
   112 	/* Make sure our pointers get NULL'd just in case */
   113 	SM_UnsetInterfaces();
   114 }
   115 
   116 void MyExtension::OnExtensionsAllLoaded()
   117 {
   118 	/* Called once all extensions are marked as loaded.
   119 	 * This always called, and always called only once.
   120 	 */
   121 }
   122 
   123 void MyExtension::OnExtensionPauseChange(bool pause)
   124 {
   125 }
   126 
   127 bool MyExtension::QueryRunning(char *error, size_t maxlength)
   128 {
   129 	/* if something is required that can't be determined during the initial 
   130 	 * load process, print a message here will show a helpful message to 
   131 	 * users when they view the extension's info.
   132 	 */
   133 	return true;
   134 }
   135 
   136 bool MyExtension::IsMetamodExtension()
   137 {
   138 	/* Must return false! */
   139 	return false;
   140 }
   141 
   142 const char *MyExtension::GetExtensionName()
   143 {
   144 	return mmsplugin->GetName();
   145 }
   146 
   147 const char *MyExtension::GetExtensionURL()
   148 {
   149 	return mmsplugin->GetURL();	
   150 }
   151 
   152 const char *MyExtension::GetExtensionTag()
   153 {
   154 	return mmsplugin->GetLogTag();
   155 }
   156 
   157 const char *MyExtension::GetExtensionAuthor()
   158 {
   159 	return mmsplugin->GetAuthor();
   160 }
   161 
   162 const char *MyExtension::GetExtensionVerString()
   163 {
   164 	return mmsplugin->GetVersion();
   165 }
   166 
   167 const char *MyExtension::GetExtensionDescription()
   168 {
   169 	return mmsplugin->GetDescription();
   170 }
   171 
   172 const char *MyExtension::GetExtensionDateString()
   173 {
   174 	return mmsplugin->GetDate();
   175 }
   176