stub_plugin/meta_api.cpp
changeset 0 d15304fcb7a7
child 265 9e61d0d70e9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/stub_plugin/meta_api.cpp	Tue Apr 06 07:36:14 2004 +0000
     1.3 @@ -0,0 +1,121 @@
     1.4 +// vi: set ts=4 sw=4 :
     1.5 +// vim: set tw=75 :
     1.6 +
     1.7 +// meta_api.cpp - minimal implementation of metamod's plugin interface
     1.8 +
     1.9 +// This is intended to illustrate the (more or less) bare minimum code
    1.10 +// required for a valid metamod plugin, and is targeted at those who want
    1.11 +// to port existing HL/SDK DLL code to run as a metamod plugin.
    1.12 +
    1.13 +/*
    1.14 + * Copyright (c) 2001-2003 Will Day <[email protected]>
    1.15 + *
    1.16 + *    This file is part of Metamod.
    1.17 + *
    1.18 + *    Metamod is free software; you can redistribute it and/or modify it
    1.19 + *    under the terms of the GNU General Public License as published by the
    1.20 + *    Free Software Foundation; either version 2 of the License, or (at
    1.21 + *    your option) any later version.
    1.22 + *
    1.23 + *    Metamod is distributed in the hope that it will be useful, but
    1.24 + *    WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.26 + *    General Public License for more details.
    1.27 + *
    1.28 + *    You should have received a copy of the GNU General Public License
    1.29 + *    along with Metamod; if not, write to the Free Software Foundation,
    1.30 + *    Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.31 + *
    1.32 + *    In addition, as a special exception, the author gives permission to
    1.33 + *    link the code of this program with the Half-Life Game Engine ("HL
    1.34 + *    Engine") and Modified Game Libraries ("MODs") developed by Valve,
    1.35 + *    L.L.C ("Valve").  You must obey the GNU General Public License in all
    1.36 + *    respects for all of the code used other than the HL Engine and MODs
    1.37 + *    from Valve.  If you modify this file, you may extend this exception
    1.38 + *    to your version of the file, but you are not obligated to do so.  If
    1.39 + *    you do not wish to do so, delete this exception statement from your
    1.40 + *    version.
    1.41 + *
    1.42 + */
    1.43 +
    1.44 +#include <extdll.h>			// always
    1.45 +
    1.46 +#include <meta_api.h>		// of course
    1.47 +
    1.48 +#include "sdk_util.h"		// UTIL_LogPrintf, etc
    1.49 +
    1.50 +// Must provide at least one of these..
    1.51 +static META_FUNCTIONS gMetaFunctionTable = {
    1.52 +	NULL,			// pfnGetEntityAPI				HL SDK; called before game DLL
    1.53 +	NULL,			// pfnGetEntityAPI_Post			META; called after game DLL
    1.54 +	GetEntityAPI2,	// pfnGetEntityAPI2				HL SDK2; called before game DLL
    1.55 +	NULL,			// pfnGetEntityAPI2_Post		META; called after game DLL
    1.56 +	NULL,			// pfnGetNewDLLFunctions		HL SDK2; called before game DLL
    1.57 +	NULL,			// pfnGetNewDLLFunctions_Post	META; called after game DLL
    1.58 +	GetEngineFunctions,	// pfnGetEngineFunctions	META; called before HL engine
    1.59 +	NULL,			// pfnGetEngineFunctions_Post	META; called after HL engine
    1.60 +};
    1.61 +
    1.62 +// Description of plugin
    1.63 +plugin_info_t Plugin_info = {
    1.64 +	META_INTERFACE_VERSION,	// ifvers
    1.65 +	"minimal stub",	// name
    1.66 +	"1.17",	// version
    1.67 +	"2003/11/15",	// date
    1.68 +	"Will Day <[email protected]>",	// author
    1.69 +	"http://www.metamod.org/",	// url
    1.70 +	"STUB",	// logtag, all caps please
    1.71 +	PT_ANYTIME,	// (when) loadable
    1.72 +	PT_ANYPAUSE,	// (when) unloadable
    1.73 +};
    1.74 +
    1.75 +// Global vars from metamod:
    1.76 +meta_globals_t *gpMetaGlobals;		// metamod globals
    1.77 +gamedll_funcs_t *gpGamedllFuncs;	// gameDLL function tables
    1.78 +mutil_funcs_t *gpMetaUtilFuncs;		// metamod utility functions
    1.79 +
    1.80 +// Metamod requesting info about this plugin:
    1.81 +//  ifvers			(given) interface_version metamod is using
    1.82 +//  pPlugInfo		(requested) struct with info about plugin
    1.83 +//  pMetaUtilFuncs	(given) table of utility functions provided by metamod
    1.84 +C_DLLEXPORT int Meta_Query(char * /*ifvers */, plugin_info_t **pPlugInfo,
    1.85 +		mutil_funcs_t *pMetaUtilFuncs) 
    1.86 +{
    1.87 +	// Give metamod our plugin_info struct
    1.88 +	*pPlugInfo=&Plugin_info;
    1.89 +	// Get metamod utility function table.
    1.90 +	gpMetaUtilFuncs=pMetaUtilFuncs;
    1.91 +	return(TRUE);
    1.92 +}
    1.93 +
    1.94 +// Metamod attaching plugin to the server.
    1.95 +//  now				(given) current phase, ie during map, during changelevel, or at startup
    1.96 +//  pFunctionTable	(requested) table of function tables this plugin catches
    1.97 +//  pMGlobals		(given) global vars from metamod
    1.98 +//  pGamedllFuncs	(given) copy of function tables from game dll
    1.99 +C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME /* now */, 
   1.100 +		META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, 
   1.101 +		gamedll_funcs_t *pGamedllFuncs) 
   1.102 +{
   1.103 +	if(!pMGlobals) {
   1.104 +		LOG_ERROR(PLID, "Meta_Attach called with null pMGlobals");
   1.105 +		return(FALSE);
   1.106 +	}
   1.107 +	gpMetaGlobals=pMGlobals;
   1.108 +	if(!pFunctionTable) {
   1.109 +		LOG_ERROR(PLID, "Meta_Attach called with null pFunctionTable");
   1.110 +		return(FALSE);
   1.111 +	}
   1.112 +	memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS));
   1.113 +	gpGamedllFuncs=pGamedllFuncs;
   1.114 +	return(TRUE);
   1.115 +}
   1.116 +
   1.117 +// Metamod detaching plugin from the server.
   1.118 +// now		(given) current phase, ie during map, etc
   1.119 +// reason	(given) why detaching (refresh, console unload, forced unload, etc)
   1.120 +C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME /* now */, 
   1.121 +		PL_UNLOAD_REASON /* reason */) 
   1.122 +{
   1.123 +	return(TRUE);
   1.124 +}