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