public/mms_sample_ext/sm_ext.cpp
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 1990 de135d1f05b1
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
     1 #include <stdio.h>
     2 #include "stub_mm.h"
     3 #include "stub_util.h"
     4 #include "sm_ext.h"
     5 
     6 MyExtension g_SMExt;
     7 
     8 bool SM_LoadExtension(char *error, size_t maxlength)
     9 {
    10 	if ((smexts = (IExtensionManager *)g_SMAPI->MetaFactory(
    11 			SOURCEMOD_INTERFACE_EXTENSIONS, 
    12 			NULL, 
    13 			NULL))
    14 		== NULL)
    15 	{
    16 		if (error && maxlength)
    17 		{
    18 			UTIL_Format(error, maxlength, SOURCEMOD_INTERFACE_EXTENSIONS " interface not found");
    19 		}
    20 		return false;
    21 	}
    22 
    23 	/* This could be more dynamic */
    24 	char path[256];
    25 	g_SMAPI->PathFormat(path, 
    26 		sizeof(path), 
    27 		"addons/myplugin/bin/myplugin%s",
    28 #if defined __linux__
    29 		"_i486.so"
    30 #else
    31 		".dll"
    32 #endif	
    33 		);
    34 
    35 	if ((myself = smexts->LoadExternal(&g_SMExt,
    36 			path,
    37 			"myplugin_mm.ext",
    38 			error,
    39 			maxlength))
    40 		== NULL)
    41 	{
    42 		SM_UnsetInterfaces();
    43 		return false;
    44 	}
    45 
    46 	return true;
    47 }
    48 
    49 void SM_UnloadExtension()
    50 {
    51 	smexts->UnloadExtension(myself);	
    52 }
    53 
    54 bool MyExtension::OnExtensionLoad(IExtension *me,
    55 		IShareSys *sys, 
    56 		char *error, 
    57 		size_t maxlength, 
    58 		bool late)
    59 {
    60 	sharesys = sys;
    61 	myself = me;
    62 
    63 	/* Get the default interfaces from our configured SDK header */
    64 	if (!SM_AcquireInterfaces(error, maxlength))
    65 	{
    66 		return false;
    67 	}
    68 
    69 	return true;	
    70 }
    71 
    72 void MyExtension::OnExtensionUnload()
    73 {
    74 	/* Clean up any resources here, and more importantly, make sure 
    75 	 * any listeners/hooks into SourceMod are totally removed, as well 
    76 	 * as data structures like handle types and forwards.
    77 	 */
    78 
    79 	//...
    80 
    81 	/* Make sure our pointers get NULL'd just in case */
    82 	SM_UnsetInterfaces();
    83 }
    84 
    85 void MyExtension::OnExtensionsAllLoaded()
    86 {
    87 	/* Called once all extensions are marked as loaded.
    88 	 * This always called, and always called only once.
    89 	 */
    90 }
    91 
    92 void MyExtension::OnExtensionPauseChange(bool pause)
    93 {
    94 }
    95 
    96 bool MyExtension::QueryRunning(char *error, size_t maxlength)
    97 {
    98 	/* if something is required that can't be determined during the initial 
    99 	 * load process, print a message here will show a helpful message to 
   100 	 * users when they view the extension's info.
   101 	 */
   102 	return true;
   103 }
   104 
   105 bool MyExtension::IsMetamodExtension()
   106 {
   107 	/* Must return false! */
   108 	return false;
   109 }
   110 
   111 const char *MyExtension::GetExtensionName()
   112 {
   113 	return mmsplugin->GetName();
   114 }
   115 
   116 const char *MyExtension::GetExtensionURL()
   117 {
   118 	return mmsplugin->GetURL();	
   119 }
   120 
   121 const char *MyExtension::GetExtensionTag()
   122 {
   123 	return mmsplugin->GetLogTag();
   124 }
   125 
   126 const char *MyExtension::GetExtensionAuthor()
   127 {
   128 	return mmsplugin->GetAuthor();
   129 }
   130 
   131 const char *MyExtension::GetExtensionVerString()
   132 {
   133 	return mmsplugin->GetVersion();
   134 }
   135 
   136 const char *MyExtension::GetExtensionDescription()
   137 {
   138 	return mmsplugin->GetDescription();
   139 }
   140 
   141 const char *MyExtension::GetExtensionDateString()
   142 {
   143 	return mmsplugin->GetDate();
   144 }
   145