metamod/dllapi.cpp
author Scott Ehlert <ds@alliedmods.net>
Thu Sep 26 22:57:05 2013 -0500 (2013-09-26)
changeset 286 202d9c3207a2
parent 265 9e61d0d70e9a
permissions -rw-r--r--
Fixed warning when building stub_mm plugin.
     1 // vi: set ts=4 sw=4 :
     2 // vim: set tw=75 :
     3 
     4 // dllapi.cpp - implementation of Half-Life DLL routines
     5 
     6 /*
     7  * Copyright (c) 2001-2003 Will Day <[email protected]>
     8  *
     9  *    This file is part of Metamod.
    10  *
    11  *    Metamod is free software; you can redistribute it and/or modify it
    12  *    under the terms of the GNU General Public License as published by the
    13  *    Free Software Foundation; either version 2 of the License, or (at
    14  *    your option) any later version.
    15  *
    16  *    Metamod is distributed in the hope that it will be useful, but
    17  *    WITHOUT ANY WARRANTY; without even the implied warranty of
    18  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    19  *    General Public License for more details.
    20  *
    21  *    You should have received a copy of the GNU General Public License
    22  *    along with Metamod; if not, write to the Free Software Foundation,
    23  *    Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24  *
    25  *    In addition, as a special exception, the author gives permission to
    26  *    link the code of this program with the Half-Life Game Engine ("HL
    27  *    Engine") and Modified Game Libraries ("MODs") developed by Valve,
    28  *    L.L.C ("Valve").  You must obey the GNU General Public License in all
    29  *    respects for all of the code used other than the HL Engine and MODs
    30  *    from Valve.  If you modify this file, you may extend this exception
    31  *    to your version of the file, but you are not obligated to do so.  If
    32  *    you do not wish to do so, delete this exception statement from your
    33  *    version.
    34  *
    35  */
    36 
    37 #include <extdll.h>			// always
    38 
    39 #include "dllapi.h"			// me
    40 #include "metamod.h"		// SETUP_API_CALLS, etc
    41 #include "api_info.h"		// dllapi_info, etc
    42 #include "commands_meta.h"	// client_meta, etc
    43 #include "log_meta.h"		// META_ERROR, etc
    44 
    45 
    46 // Original DLL routines, functions returning "void".
    47 #define META_DLLAPI_HANDLE_void(FN_TYPE, pfnName, pfn_args) \
    48 	SETUP_API_CALLS_void(FN_TYPE, pfnName, dllapi_info); \
    49 	CALL_PLUGIN_API_void(P_PRE, pfnName, pfn_args, dllapi_table); \
    50 	CALL_GAME_API_void(pfnName, pfn_args, dllapi_table); \
    51 	CALL_PLUGIN_API_void(P_POST, pfnName, pfn_args, dllapi_post_table);
    52 
    53 // Original DLL routines, functions returning an actual value.
    54 #define META_DLLAPI_HANDLE(ret_t, ret_init, FN_TYPE, pfnName, pfn_args) \
    55 	SETUP_API_CALLS(ret_t, ret_init, FN_TYPE, pfnName, dllapi_info); \
    56 	CALL_PLUGIN_API(P_PRE, ret_init, pfnName, pfn_args, MRES_SUPERCEDE, dllapi_table); \
    57 	CALL_GAME_API(pfnName, pfn_args, dllapi_table); \
    58 	CALL_PLUGIN_API(P_POST, ret_init, pfnName, pfn_args, MRES_OVERRIDE, dllapi_post_table);
    59 
    60 
    61 // The "new" api routines (just 3 right now), functions returning "void".
    62 #define META_NEWAPI_HANDLE_void(FN_TYPE, pfnName, pfn_args) \
    63 	SETUP_API_CALLS_void(FN_TYPE, pfnName, newapi_info); \
    64 	CALL_PLUGIN_API_void(P_PRE, pfnName, pfn_args, newapi_table); \
    65 	CALL_GAME_API_void(pfnName, pfn_args, newapi_table); \
    66 	CALL_PLUGIN_API_void(P_POST, pfnName, pfn_args, newapi_post_table);
    67 
    68 // The "new" api routines (just 3 right now), functions returning an actual value.
    69 #define META_NEWAPI_HANDLE(ret_t, ret_init, FN_TYPE, pfnName, pfn_args) \
    70 	SETUP_API_CALLS(ret_t, ret_init, FN_TYPE, pfnName, newapi_info); \
    71 	CALL_PLUGIN_API(P_PRE, ret_init, pfnName, pfn_args, MRES_SUPERCEDE, newapi_table); \
    72 	CALL_GAME_API(pfnName, pfn_args, newapi_table); \
    73 	CALL_PLUGIN_API(P_POST, ret_init, pfnName, pfn_args, MRES_OVERRIDE, newapi_post_table);
    74 
    75 
    76 // From SDK dlls/game.cpp:
    77 void mm_GameDLLInit(void) {
    78 	META_DLLAPI_HANDLE_void(FN_GAMEINIT, pfnGameInit, ());
    79 	RETURN_API_void();
    80 }
    81 
    82 // From SDK dlls/cbase.cpp:
    83 int mm_DispatchSpawn(edict_t *pent) {
    84 	// 0==Success, -1==Failure ?
    85 	META_DLLAPI_HANDLE(int, 0, FN_DISPATCHSPAWN, pfnSpawn, (pent));
    86 	RETURN_API();
    87 }
    88 void mm_DispatchThink(edict_t *pent) {
    89 	META_DLLAPI_HANDLE_void(FN_DISPATCHTHINK, pfnThink, (pent));
    90 	RETURN_API_void();
    91 }
    92 void mm_DispatchUse(edict_t *pentUsed, edict_t *pentOther) {
    93 	META_DLLAPI_HANDLE_void(FN_DISPATCHUSE, pfnUse, (pentUsed, pentOther));
    94 	RETURN_API_void();
    95 }
    96 void mm_DispatchTouch(edict_t *pentTouched, edict_t *pentOther) {
    97 	META_DLLAPI_HANDLE_void(FN_DISPATCHTOUCH, pfnTouch, (pentTouched, pentOther));
    98 	RETURN_API_void();
    99 }
   100 void mm_DispatchBlocked(edict_t *pentBlocked, edict_t *pentOther) {
   101 	META_DLLAPI_HANDLE_void(FN_DISPATCHBLOCKED, pfnBlocked, (pentBlocked, pentOther));
   102 	RETURN_API_void();
   103 }
   104 void mm_DispatchKeyValue(edict_t *pentKeyvalue, KeyValueData *pkvd) {
   105 	META_DLLAPI_HANDLE_void(FN_DISPATCHKEYVALUE, pfnKeyValue, (pentKeyvalue, pkvd));
   106 	RETURN_API_void();
   107 }
   108 void mm_DispatchSave(edict_t *pent, SAVERESTOREDATA *pSaveData) {
   109 	META_DLLAPI_HANDLE_void(FN_DISPATCHSAVE, pfnSave, (pent, pSaveData));
   110 	RETURN_API_void();
   111 }
   112 int mm_DispatchRestore(edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity) {
   113 	// 0==Success, -1==Failure ?
   114 	META_DLLAPI_HANDLE(int, 0, FN_DISPATCHRESTORE, pfnRestore, (pent, pSaveData, globalEntity));
   115 	RETURN_API();
   116 }
   117 void mm_DispatchObjectCollsionBox(edict_t *pent) {
   118 	META_DLLAPI_HANDLE_void(FN_DISPATCHOBJECTCOLLISIONBOX, pfnSetAbsBox, (pent));
   119 	RETURN_API_void();
   120 }
   121 void mm_SaveWriteFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount) {
   122 	META_DLLAPI_HANDLE_void(FN_SAVEWRITEFIELDS, pfnSaveWriteFields, (pSaveData, pname, pBaseData, pFields, fieldCount));
   123 	RETURN_API_void();
   124 }
   125 void mm_SaveReadFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount) {
   126 	META_DLLAPI_HANDLE_void(FN_SAVEREADFIELDS, pfnSaveReadFields, (pSaveData, pname, pBaseData, pFields, fieldCount));
   127 	RETURN_API_void();
   128 }
   129 
   130 // From SDK dlls/world.cpp:
   131 void mm_SaveGlobalState(SAVERESTOREDATA *pSaveData) {
   132 	META_DLLAPI_HANDLE_void(FN_SAVEGLOBALSTATE, pfnSaveGlobalState, (pSaveData));
   133 	RETURN_API_void();
   134 }
   135 void mm_RestoreGlobalState(SAVERESTOREDATA *pSaveData) {
   136 	META_DLLAPI_HANDLE_void(FN_RESTOREGLOBALSTATE, pfnRestoreGlobalState, (pSaveData));
   137 	RETURN_API_void();
   138 }
   139 void mm_ResetGlobalState(void) {
   140 	META_DLLAPI_HANDLE_void(FN_RESETGLOBALSTATE, pfnResetGlobalState, ());
   141 	RETURN_API_void();
   142 }
   143 
   144 // From SDK dlls/client.cpp:
   145 BOOL mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) {
   146 	g_Players.clear_player_cvar_query(pEntity);
   147 	META_DLLAPI_HANDLE(BOOL, TRUE, FN_CLIENTCONNECT, pfnClientConnect, (pEntity, pszName, pszAddress, szRejectReason));
   148 	RETURN_API();
   149 }
   150 void mm_ClientDisconnect(edict_t *pEntity) {
   151 	g_Players.clear_player_cvar_query(pEntity);
   152 	META_DLLAPI_HANDLE_void(FN_CLIENTDISCONNECT, pfnClientDisconnect, (pEntity));
   153 	RETURN_API_void();
   154 }
   155 void mm_ClientKill(edict_t *pEntity) {
   156 	META_DLLAPI_HANDLE_void(FN_CLIENTKILL, pfnClientKill, (pEntity));
   157 	RETURN_API_void();
   158 }
   159 void mm_ClientPutInServer(edict_t *pEntity) {
   160 	META_DLLAPI_HANDLE_void(FN_CLIENTPUTINSERVER, pfnClientPutInServer, (pEntity));
   161 	RETURN_API_void();
   162 }
   163 void mm_ClientCommand(edict_t *pEntity) {
   164 	if(strmatch(CMD_ARGV(0), "meta")) {
   165 		client_meta(pEntity);
   166 	}
   167 	META_DLLAPI_HANDLE_void(FN_CLIENTCOMMAND, pfnClientCommand, (pEntity));
   168 	RETURN_API_void();
   169 }
   170 void mm_ClientUserInfoChanged(edict_t *pEntity, char *infobuffer) {
   171 	META_DLLAPI_HANDLE_void(FN_CLIENTUSERINFOCHANGED, pfnClientUserInfoChanged, (pEntity, infobuffer));
   172 	RETURN_API_void();
   173 }
   174 void mm_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) {
   175 	META_DLLAPI_HANDLE_void(FN_SERVERACTIVATE, pfnServerActivate, (pEdictList, edictCount, clientMax));
   176 	RETURN_API_void();
   177 }
   178 void mm_ServerDeactivate(void) {
   179 	META_DLLAPI_HANDLE_void(FN_SERVERDEACTIVATE, pfnServerDeactivate, ());
   180 	// Update loaded plugins.  Look for new plugins in inifile, as well as
   181 	// any plugins waiting for a changelevel to load.  
   182 	//
   183 	// This is done in ServerDeactivate rather than Activate, as the latter
   184 	// isn't actually the first routine to be called on a new map.  In
   185 	// particular DispatchKeyValue and DispatchSpawn are called before
   186 	// Activate, and we want any newly loaded plugins to be able to catch
   187 	// these.
   188 	//
   189 	// So, we do this from Deactivate, which is the _last_ routine called
   190 	// from the previous map.  It's also called right before shutdown,
   191 	// which means whenever hlds quits, it'll reload the plugins just
   192 	// before it exits, which is rather silly, but oh well.
   193 	Plugins->refresh(PT_CHANGELEVEL);
   194 	Plugins->unpause_all();
   195 	// Plugins->retry_all(PT_CHANGELEVEL);
   196 	g_Players.clear_all_cvar_queries();
   197 	requestid_counter = 0;
   198 	RETURN_API_void();
   199 }
   200 void mm_PlayerPreThink(edict_t *pEntity) {
   201 	META_DLLAPI_HANDLE_void(FN_PLAYERPRETHINK, pfnPlayerPreThink, (pEntity));
   202 	RETURN_API_void();
   203 }
   204 void mm_PlayerPostThink(edict_t *pEntity) {
   205 	META_DLLAPI_HANDLE_void(FN_PLAYERPOSTTHINK, pfnPlayerPostThink, (pEntity));
   206 	RETURN_API_void();
   207 }
   208 void mm_StartFrame(void) {
   209 	META_DLLAPI_HANDLE_void(FN_STARTFRAME, pfnStartFrame, ());
   210 	RETURN_API_void();
   211 }
   212 void mm_ParmsNewLevel(void) {
   213 	META_DLLAPI_HANDLE_void(FN_PARMSNEWLEVEL, pfnParmsNewLevel, ());
   214 	RETURN_API_void();
   215 }
   216 void mm_ParmsChangeLevel(void) {
   217 	META_DLLAPI_HANDLE_void(FN_PARMSCHANGELEVEL, pfnParmsChangeLevel, ());
   218 	RETURN_API_void();
   219 }
   220 const char *mm_GetGameDescription(void) {
   221 	META_DLLAPI_HANDLE(const char *, NULL, FN_GETGAMEDESCRIPTION, pfnGetGameDescription, ());
   222 	RETURN_API();
   223 }
   224 void mm_PlayerCustomization(edict_t *pEntity, customization_t *pCust) {
   225 	META_DLLAPI_HANDLE_void(FN_PLAYERCUSTOMIZATION, pfnPlayerCustomization, (pEntity, pCust));
   226 	RETURN_API_void();
   227 }
   228 void mm_SpectatorConnect(edict_t *pEntity) {
   229 	META_DLLAPI_HANDLE_void(FN_SPECTATORCONNECT, pfnSpectatorConnect, (pEntity));
   230 	RETURN_API_void();
   231 }
   232 void mm_SpectatorDisconnect(edict_t *pEntity) {
   233 	META_DLLAPI_HANDLE_void(FN_SPECTATORDISCONNECT, pfnSpectatorDisconnect, (pEntity));
   234 	RETURN_API_void();
   235 }
   236 void mm_SpectatorThink(edict_t *pEntity) {
   237 	META_DLLAPI_HANDLE_void(FN_SPECTATORTHINK, pfnSpectatorThink, (pEntity));
   238 	RETURN_API_void();
   239 }
   240 void mm_Sys_Error(const char *error_string) {
   241 	META_DLLAPI_HANDLE_void(FN_SYS_ERROR, pfnSys_Error, (error_string));
   242 	RETURN_API_void();
   243 }
   244 
   245 // From SDK pm_shared/pm_shared.c:
   246 void mm_PM_Move (struct playermove_s *ppmove, int server) {
   247 	META_DLLAPI_HANDLE_void(FN_PM_MOVE, pfnPM_Move, (ppmove, server));
   248 	RETURN_API_void();
   249 }
   250 void mm_PM_Init(struct playermove_s *ppmove) {
   251 	META_DLLAPI_HANDLE_void(FN_PM_INIT, pfnPM_Init, (ppmove));
   252 	RETURN_API_void();
   253 }
   254 char mm_PM_FindTextureType(const char *name) {
   255 	META_DLLAPI_HANDLE(char, '\0', FN_PM_FINDTEXTURETYPE, pfnPM_FindTextureType, (name));
   256 	RETURN_API();
   257 }
   258 
   259 // From SDK dlls/client.cpp:
   260 void mm_SetupVisibility(edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas) {
   261 	META_DLLAPI_HANDLE_void(FN_SETUPVISIBILITY, pfnSetupVisibility, (pViewEntity, pClient, pvs, pas));
   262 	RETURN_API_void();
   263 }
   264 void mm_UpdateClientData (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd) {
   265 	META_DLLAPI_HANDLE_void(FN_UPDATECLIENTDATA, pfnUpdateClientData, (ent, sendweapons, cd));
   266 	RETURN_API_void();
   267 }
   268 int mm_AddToFullPack(struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet) {
   269 	META_DLLAPI_HANDLE(int, 0, FN_ADDTOFULLPACK, pfnAddToFullPack, (state, e, ent, host, hostflags, player, pSet));
   270 	RETURN_API();
   271 }
   272 void mm_CreateBaseline(int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs) {
   273 	META_DLLAPI_HANDLE_void(FN_CREATEBASELINE, pfnCreateBaseline, (player, eindex, baseline, entity, playermodelindex, player_mins, player_maxs));
   274 	RETURN_API_void();
   275 }
   276 void mm_RegisterEncoders(void) {
   277 	META_DLLAPI_HANDLE_void(FN_REGISTERENCODERS, pfnRegisterEncoders, ());
   278 	RETURN_API_void();
   279 }
   280 int mm_GetWeaponData(struct edict_s *player, struct weapon_data_s *info) {
   281 	META_DLLAPI_HANDLE(int, 0, FN_GETWEAPONDATA, pfnGetWeaponData, (player, info));
   282 	RETURN_API();
   283 }
   284 void mm_CmdStart(const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed) {
   285 	META_DLLAPI_HANDLE_void(FN_CMDSTART, pfnCmdStart, (player, cmd, random_seed));
   286 	RETURN_API_void();
   287 }
   288 void mm_CmdEnd (const edict_t *player) {
   289 	META_DLLAPI_HANDLE_void(FN_CMDEND, pfnCmdEnd, (player));
   290 	RETURN_API_void();
   291 }
   292 int mm_ConnectionlessPacket(const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size) {
   293 	META_DLLAPI_HANDLE(int, 0, FN_CONNECTIONLESSPACKET, pfnConnectionlessPacket, (net_from, args, response_buffer, response_buffer_size));
   294 	RETURN_API();
   295 }
   296 int mm_GetHullBounds(int hullnumber, float *mins, float *maxs) {
   297 	META_DLLAPI_HANDLE(int, 0, FN_GETHULLBOUNDS, pfnGetHullBounds, (hullnumber, mins, maxs));
   298 	RETURN_API();
   299 }
   300 void mm_CreateInstancedBaselines (void) {
   301 	META_DLLAPI_HANDLE_void(FN_CREATEINSTANCEDBASELINES, pfnCreateInstancedBaselines, ());
   302 	RETURN_API_void();
   303 }
   304 int mm_InconsistentFile(const edict_t *player, const char *filename, char *disconnect_message) {
   305 	META_DLLAPI_HANDLE(int, 0, FN_INCONSISTENTFILE, pfnInconsistentFile, (player, filename, disconnect_message));
   306 	RETURN_API();
   307 }
   308 int mm_AllowLagCompensation(void) {
   309 	META_DLLAPI_HANDLE(int, 0, FN_ALLOWLAGCOMPENSATION, pfnAllowLagCompensation, ());
   310 	RETURN_API();
   311 }
   312 
   313 
   314 // New API functions
   315 // From SDK ?
   316 void mm_OnFreeEntPrivateData(edict_t *pEnt) {
   317 	META_NEWAPI_HANDLE_void(FN_ONFREEENTPRIVATEDATA, pfnOnFreeEntPrivateData, (pEnt));
   318 	RETURN_API_void();
   319 }
   320 void mm_GameShutdown(void) {
   321 	META_NEWAPI_HANDLE_void(FN_GAMESHUTDOWN, pfnGameShutdown, ());
   322 	RETURN_API_void();
   323 }
   324 int mm_ShouldCollide(edict_t *pentTouched, edict_t *pentOther) {
   325 	META_NEWAPI_HANDLE(int, 1, FN_SHOULDCOLLIDE, pfnShouldCollide, (pentTouched, pentOther));
   326 	RETURN_API();
   327 }
   328 // Added 2005-08-11 (no SDK update)
   329 void mm_CvarValue(const edict_t *pEdict, const char *value) {
   330 	g_Players.clear_player_cvar_query(pEdict);
   331 	META_NEWAPI_HANDLE_void(FN_CVARVALUE, pfnCvarValue, (pEdict, value));
   332 	RETURN_API_void();
   333 }
   334 
   335 //Added 2005-11-22 (no SDK update)
   336 void mm_CvarValue2(const edict_t *pEdict, int requestID, const char *cvarName, const char *value) {
   337 	META_NEWAPI_HANDLE_void(FN_CVARVALUE2, pfnCvarValue2, (pEdict, requestID, cvarName, value));
   338 	RETURN_API_void();
   339 }
   340 
   341 // From SDK dlls/cbase.cpp:
   342 // "(wd)" indicates my comments on the functions
   343 static DLL_FUNCTIONS sFunctionTable = 
   344 {
   345 	mm_GameDLLInit,					//! pfnGameInit()				Initialize the game (one-time call after loading of game .dll)
   346 	mm_DispatchSpawn,				//! pfnSpawn()
   347 	mm_DispatchThink,				//! pfnThink()
   348 	mm_DispatchUse,					//! pfnUse()
   349 	mm_DispatchTouch,				//! pfnTouch()
   350 	mm_DispatchBlocked,				//! pfnBlocked()
   351 	mm_DispatchKeyValue,			//! pfnKeyValue()
   352 	mm_DispatchSave,				//! pfnSave()
   353 	mm_DispatchRestore,				//! pfnRestore()
   354 	mm_DispatchObjectCollsionBox,	//! pfnSetAbsBox()
   355 
   356 	mm_SaveWriteFields,				//! pfnSaveWriteFields()
   357 	mm_SaveReadFields,				//! pfnSaveReadFields()
   358 
   359 	mm_SaveGlobalState,				//! pfnSaveGlobalState()
   360 	mm_RestoreGlobalState,			//! pfnRestoreGlobalState()
   361 	mm_ResetGlobalState,			//! pfnResetGlobalState()
   362 
   363 	mm_ClientConnect,				//! pfnClientConnect()			(wd) Client has connected
   364 	mm_ClientDisconnect,			//! pfnClientDisconnect()		(wd) Player has left the game
   365 	mm_ClientKill,					//! pfnClientKill()				(wd) Player has typed "kill"
   366 	mm_ClientPutInServer,			//! pfnClientPutInServer()		(wd) Client is entering the game
   367 	mm_ClientCommand,				//! pfnClientCommand()			(wd) Player has sent a command (typed, or from a bind)
   368 	mm_ClientUserInfoChanged,		//! pfnClientUserInfoChanged()	(wd) Client has updated their setinfo structure
   369 	mm_ServerActivate,				//! pfnServerActivate()			(wd) Server is starting a new map
   370 	mm_ServerDeactivate,			//! pfnServerDeactivate()		(wd) Server is leaving the map (shutdown, or changelevel); SDK2
   371 
   372 	mm_PlayerPreThink,				//! pfnPlayerPreThink()
   373 	mm_PlayerPostThink,				//! pfnPlayerPostThink()
   374 
   375 	mm_StartFrame,					//! pfnStartFrame()
   376 	mm_ParmsNewLevel,				//! pfnParmsNewLevel()
   377 	mm_ParmsChangeLevel,			//! pfnParmsChangeLevel()
   378 
   379 	mm_GetGameDescription,			//! pfnGetGameDescription()		Returns string describing current .dll.  E.g. "TeamFotrress 2", "Half-Life"
   380 	mm_PlayerCustomization,			//! pfnPlayerCustomization()	Notifies .dll of new customization for player.
   381 
   382 	mm_SpectatorConnect,			//! pfnSpectatorConnect()		Called when spectator joins server
   383 	mm_SpectatorDisconnect,			//! pfnSpectatorDisconnect()	Called when spectator leaves the server
   384 	mm_SpectatorThink,				//! pfnSpectatorThink()			Called when spectator sends a command packet (usercmd_t)
   385 
   386 	mm_Sys_Error,					//! pfnSys_Error()				Notify game .dll that engine is going to shut down.  Allows mod authors to set a breakpoint.  SDK2
   387 
   388 	mm_PM_Move,						//! pfnPM_Move()				(wd) SDK2
   389 	mm_PM_Init,						//! pfnPM_Init()				Server version of player movement initialization; (wd) SDK2
   390 	mm_PM_FindTextureType,			//! pfnPM_FindTextureType()		(wd) SDK2
   391 
   392 	mm_SetupVisibility,				//! pfnSetupVisibility()		Set up PVS and PAS for networking for this client; (wd) SDK2
   393 	mm_UpdateClientData,			//! pfnUpdateClientData()		Set up data sent only to specific client; (wd) SDK2
   394 	mm_AddToFullPack,				//! pfnAddToFullPack()			(wd) SDK2
   395 	mm_CreateBaseline,				//! pfnCreateBaseline()			Tweak entity baseline for network encoding, allows setup of player baselines, too.; (wd) SDK2
   396 	mm_RegisterEncoders,			//! pfnRegisterEncoders()		Callbacks for network encoding; (wd) SDK2
   397 	mm_GetWeaponData,				//! pfnGetWeaponData()			(wd) SDK2
   398 	mm_CmdStart,					//! pfnCmdStart()				(wd) SDK2
   399 	mm_CmdEnd,						//! pfnCmdEnd()					(wd) SDK2
   400 	mm_ConnectionlessPacket,		//! pfnConnectionlessPacket()	(wd) SDK2
   401 	mm_GetHullBounds,				//! pfnGetHullBounds()			(wd) SDK2
   402 	mm_CreateInstancedBaselines,	//! pfnCreateInstancedBaselines()	(wd) SDK2
   403 	mm_InconsistentFile,			//! pfnInconsistentFile()		(wd) SDK2
   404 	mm_AllowLagCompensation,		//! pfnAllowLagCompensation()	(wd) SDK2
   405 };
   406 
   407 DLL_FUNCTIONS *pHookedDllFunctions = &sFunctionTable;
   408 
   409 // It's not clear what the difference is between GetAPI and GetAPI2; they
   410 // both appear to return the exact same function table.  
   411 //
   412 // Only one of them appears to be ever called, though.  If the DLL provides
   413 // GetAPI2, the engine/hlds will call that, and will not call GetAPI.  If
   414 // the engine couldn't find GetAPI2 in the DLL, it appears to fall back to
   415 // GetAPI.
   416 //
   417 // So, GetAPI2 appears to replace GetAPI, and appears to have been added
   418 // with SDK 2.0.  My best guess is that, with the new SDK, interface
   419 // version checking became important, and without the int ptr used in
   420 // GetAPI2, the engine can't find out the version of the DLL via GetAPI.
   421 //
   422 // It's unclear whether a DLL coded under SDK2 needs to provide the older
   423 // GetAPI or not..
   424 
   425 C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion)
   426 {
   427 	META_DEBUG(3, ("called: GetEntityAPI; version=%d", interfaceVersion));
   428 	if(!pFunctionTable) {
   429 		META_ERROR("GetEntityAPI called with null pFunctionTable");
   430 		return(FALSE);
   431 	}
   432 	else if(interfaceVersion != INTERFACE_VERSION) {
   433 		META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION);
   434 		return(FALSE);
   435 	}
   436 
   437 	
   438 	memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
   439 
   440 
   441 	return(TRUE);
   442 }
   443 
   444 C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
   445 {
   446 	META_DEBUG(3, ("called: GetEntityAPI2; version=%d", *interfaceVersion));
   447 
   448 	if(!pFunctionTable) {
   449 		META_ERROR("GetEntityAPI2 called with null pFunctionTable");
   450 		return(FALSE);
   451 	}
   452 	else if(*interfaceVersion != INTERFACE_VERSION) {
   453 		META_ERROR("GetEntityAPI2 version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
   454 		//! Tell engine what version we had, so it can figure out who is out of date.
   455 		*interfaceVersion = INTERFACE_VERSION;
   456 		return(FALSE);
   457 	}
   458 
   459 	
   460 	memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
   461 
   462 
   463 	return(TRUE);
   464 }
   465 
   466 
   467 // I could find _no_ documentation or examples for the intended use of
   468 // NEW_DLL_FUNCTIONS.  I wouldn't have even _known_ about the
   469 // GetNewDLLFunctions() function except for the reference in Adminmod..  It
   470 // appears to be new with SDK 2.0.
   471 //
   472 // Obviously, it seems to provide additional functions to the engine, but
   473 // it's unclear why a new table and interface were added, rather than
   474 // appending new functions to the GetAPI table/interface.
   475 //
   476 // Interestingly, it appears to be called by the engine _before_ GetAPI.
   477 
   478 static meta_new_dll_functions_t sNewFunctionTable (
   479 	&mm_OnFreeEntPrivateData,		//! pfnOnFreeEntPrivateData()	Called right before the object's memory is freed.  Calls its destructor.
   480 	&mm_GameShutdown,				//! pfnGameShutdown()
   481 	&mm_ShouldCollide,				//! pfnShouldCollide()
   482 	// Added 2005-08-11 (no SDK update)
   483 	&mm_CvarValue,					//! pfnCvarValue()      (fz) Obsolete!  Use mm_CvarValue2 instead
   484 	// Added 2005-11-22 (no SDK update)
   485 	&mm_CvarValue2					//! pfnCvarValue2()     (fz) When pfnQueryClientCvarValue2() completes it will call
   486 									//!                     pfnCvarValue2() with the request ID supplied earlier, the name of
   487 									//!                     the cvar requested and the value of that cvar.
   488 );
   489 
   490 
   491 NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable;
   492 
   493 C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) 
   494 {
   495 	META_DEBUG(6, ("called: GetNewDLLFunctions; version=%d", *interfaceVersion));
   496 #if 0 // ~dvander - but then you can't use cvar querying on many mods...
   497 	// Don't provide these functions to engine if gamedll doesn't provide
   498 	// them.  Otherwise, we're in the position of having to provide answers
   499 	// we can't necessarily provide (for instance, ShouldCollide())...
   500 	if(!GameDLL.funcs.newapi_table)
   501 		return(FALSE);
   502 #endif
   503 
   504 	if(!pNewFunctionTable) {
   505 		META_ERROR("GetNewDLLFunctions called with null pNewFunctionTable");
   506 		return(FALSE);
   507 	}
   508 	else if(*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
   509 		META_ERROR("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
   510 		//! Tell engine what version we had, so it can figure out who is out of date.
   511 		*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
   512 		return(FALSE);
   513 	}
   514 
   515 	sNewFunctionTable.copy_to(pNewFunctionTable);
   516 
   517 
   518 	return(TRUE);
   519 }
   520