stub_plugin/meta_api.cpp
author Scott Ehlert <ds@alliedmods.net>
Thu Sep 26 17:00:32 2013 -0500 (2013-09-26)
changeset 284 ca90ccdb8d49
parent 265 9e61d0d70e9a
permissions -rw-r--r--
Fixed makefile error when issuing 'make clean' or 'make distclean'.
     1 // vi: set ts=4 sw=4 :
     2 // vim: set tw=75 :
     3 
     4 // meta_api.cpp - minimal implementation of metamod's plugin interface
     5 
     6 // This is intended to illustrate the (more or less) bare minimum code
     7 // required for a valid metamod plugin, and is targeted at those who want
     8 // to port existing HL/SDK DLL code to run as a metamod plugin.
     9 
    10 /*
    11  * Copyright (c) 2001-2003 Will Day <[email protected]>
    12  *
    13  *    This file is part of Metamod.
    14  *
    15  *    Metamod is free software; you can redistribute it and/or modify it
    16  *    under the terms of the GNU General Public License as published by the
    17  *    Free Software Foundation; either version 2 of the License, or (at
    18  *    your option) any later version.
    19  *
    20  *    Metamod is distributed in the hope that it will be useful, but
    21  *    WITHOUT ANY WARRANTY; without even the implied warranty of
    22  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    23  *    General Public License for more details.
    24  *
    25  *    You should have received a copy of the GNU General Public License
    26  *    along with Metamod; if not, write to the Free Software Foundation,
    27  *    Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    28  *
    29  *    In addition, as a special exception, the author gives permission to
    30  *    link the code of this program with the Half-Life Game Engine ("HL
    31  *    Engine") and Modified Game Libraries ("MODs") developed by Valve,
    32  *    L.L.C ("Valve").  You must obey the GNU General Public License in all
    33  *    respects for all of the code used other than the HL Engine and MODs
    34  *    from Valve.  If you modify this file, you may extend this exception
    35  *    to your version of the file, but you are not obligated to do so.  If
    36  *    you do not wish to do so, delete this exception statement from your
    37  *    version.
    38  *
    39  */
    40 
    41 #include <extdll.h>			// always
    42 
    43 #include <meta_api.h>		// of course
    44 
    45 #include "sdk_util.h"		// UTIL_LogPrintf, etc
    46 
    47 // Must provide at least one of these..
    48 static META_FUNCTIONS gMetaFunctionTable = {
    49 	NULL,			// pfnGetEntityAPI				HL SDK; called before game DLL
    50 	NULL,			// pfnGetEntityAPI_Post			META; called after game DLL
    51 	GetEntityAPI2,	// pfnGetEntityAPI2				HL SDK2; called before game DLL
    52 	NULL,			// pfnGetEntityAPI2_Post		META; called after game DLL
    53 	NULL,			// pfnGetNewDLLFunctions		HL SDK2; called before game DLL
    54 	NULL,			// pfnGetNewDLLFunctions_Post	META; called after game DLL
    55 	GetEngineFunctions,	// pfnGetEngineFunctions	META; called before HL engine
    56 	NULL,			// pfnGetEngineFunctions_Post	META; called after HL engine
    57 };
    58 
    59 // Description of plugin
    60 plugin_info_t Plugin_info = {
    61 	META_INTERFACE_VERSION,	// ifvers
    62 	"minimal stub",	// name
    63 	"1.17",	// version
    64 	"2003/11/15",	// date
    65 	"Will Day <[email protected]>",	// author
    66 	"http://www.metamod.org/",	// url
    67 	"STUB",	// logtag, all caps please
    68 	PT_ANYTIME,	// (when) loadable
    69 	PT_ANYPAUSE,	// (when) unloadable
    70 };
    71 
    72 // Global vars from metamod:
    73 meta_globals_t *gpMetaGlobals;		// metamod globals
    74 gamedll_funcs_t *gpGamedllFuncs;	// gameDLL function tables
    75 mutil_funcs_t *gpMetaUtilFuncs;		// metamod utility functions
    76 
    77 // Metamod requesting info about this plugin:
    78 //  ifvers			(given) interface_version metamod is using
    79 //  pPlugInfo		(requested) struct with info about plugin
    80 //  pMetaUtilFuncs	(given) table of utility functions provided by metamod
    81 C_DLLEXPORT int Meta_Query(const char * /*ifvers */, plugin_info_t **pPlugInfo,
    82 		mutil_funcs_t *pMetaUtilFuncs) 
    83 {
    84 	// Give metamod our plugin_info struct
    85 	*pPlugInfo=&Plugin_info;
    86 	// Get metamod utility function table.
    87 	gpMetaUtilFuncs=pMetaUtilFuncs;
    88 	return(TRUE);
    89 }
    90 
    91 // Metamod attaching plugin to the server.
    92 //  now				(given) current phase, ie during map, during changelevel, or at startup
    93 //  pFunctionTable	(requested) table of function tables this plugin catches
    94 //  pMGlobals		(given) global vars from metamod
    95 //  pGamedllFuncs	(given) copy of function tables from game dll
    96 C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME /* now */, 
    97 		META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, 
    98 		gamedll_funcs_t *pGamedllFuncs) 
    99 {
   100 	if(!pMGlobals) {
   101 		LOG_ERROR(PLID, "Meta_Attach called with null pMGlobals");
   102 		return(FALSE);
   103 	}
   104 	gpMetaGlobals=pMGlobals;
   105 	if(!pFunctionTable) {
   106 		LOG_ERROR(PLID, "Meta_Attach called with null pFunctionTable");
   107 		return(FALSE);
   108 	}
   109 	memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS));
   110 	gpGamedllFuncs=pGamedllFuncs;
   111 	return(TRUE);
   112 }
   113 
   114 // Metamod detaching plugin from the server.
   115 // now		(given) current phase, ie during map, etc
   116 // reason	(given) why detaching (refresh, console unload, forced unload, etc)
   117 C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME /* now */, 
   118 		PL_UNLOAD_REASON /* reason */) 
   119 {
   120 	return(TRUE);
   121 }