metamod/dllapi.cpp
author darope
Tue Aug 23 20:31:28 2005 +0000 (2005-08-23)
changeset 248 f72386298cba
parent 0 d15304fcb7a7
child 249 0e54d20d8f28
permissions -rw-r--r--
Merged with working branch (bt-release-1_17_4) for release 1.18
     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 	RETURN_API_void();
   198 }
   199 void mm_PlayerPreThink(edict_t *pEntity) {
   200 	META_DLLAPI_HANDLE_void(FN_PLAYERPRETHINK, pfnPlayerPreThink, (pEntity));
   201 	RETURN_API_void();
   202 }
   203 void mm_PlayerPostThink(edict_t *pEntity) {
   204 	META_DLLAPI_HANDLE_void(FN_PLAYERPOSTTHINK, pfnPlayerPostThink, (pEntity));
   205 	RETURN_API_void();
   206 }
   207 void mm_StartFrame(void) {
   208 	META_DLLAPI_HANDLE_void(FN_STARTFRAME, pfnStartFrame, ());
   209 	RETURN_API_void();
   210 }
   211 void mm_ParmsNewLevel(void) {
   212 	META_DLLAPI_HANDLE_void(FN_PARMSNEWLEVEL, pfnParmsNewLevel, ());
   213 	RETURN_API_void();
   214 }
   215 void mm_ParmsChangeLevel(void) {
   216 	META_DLLAPI_HANDLE_void(FN_PARMSCHANGELEVEL, pfnParmsChangeLevel, ());
   217 	RETURN_API_void();
   218 }
   219 const char *mm_GetGameDescription(void) {
   220 	META_DLLAPI_HANDLE(const char *, NULL, FN_GETGAMEDESCRIPTION, pfnGetGameDescription, ());
   221 	RETURN_API();
   222 }
   223 void mm_PlayerCustomization(edict_t *pEntity, customization_t *pCust) {
   224 	META_DLLAPI_HANDLE_void(FN_PLAYERCUSTOMIZATION, pfnPlayerCustomization, (pEntity, pCust));
   225 	RETURN_API_void();
   226 }
   227 void mm_SpectatorConnect(edict_t *pEntity) {
   228 	META_DLLAPI_HANDLE_void(FN_SPECTATORCONNECT, pfnSpectatorConnect, (pEntity));
   229 	RETURN_API_void();
   230 }
   231 void mm_SpectatorDisconnect(edict_t *pEntity) {
   232 	META_DLLAPI_HANDLE_void(FN_SPECTATORDISCONNECT, pfnSpectatorDisconnect, (pEntity));
   233 	RETURN_API_void();
   234 }
   235 void mm_SpectatorThink(edict_t *pEntity) {
   236 	META_DLLAPI_HANDLE_void(FN_SPECTATORTHINK, pfnSpectatorThink, (pEntity));
   237 	RETURN_API_void();
   238 }
   239 void mm_Sys_Error(const char *error_string) {
   240 	META_DLLAPI_HANDLE_void(FN_SYS_ERROR, pfnSys_Error, (error_string));
   241 	RETURN_API_void();
   242 }
   243 
   244 // From SDK pm_shared/pm_shared.c:
   245 void mm_PM_Move (struct playermove_s *ppmove, int server) {
   246 	META_DLLAPI_HANDLE_void(FN_PM_MOVE, pfnPM_Move, (ppmove, server));
   247 	RETURN_API_void();
   248 }
   249 void mm_PM_Init(struct playermove_s *ppmove) {
   250 	META_DLLAPI_HANDLE_void(FN_PM_INIT, pfnPM_Init, (ppmove));
   251 	RETURN_API_void();
   252 }
   253 char mm_PM_FindTextureType(char *name) {
   254 	META_DLLAPI_HANDLE(char, '\0', FN_PM_FINDTEXTURETYPE, pfnPM_FindTextureType, (name));
   255 	RETURN_API();
   256 }
   257 
   258 // From SDK dlls/client.cpp:
   259 void mm_SetupVisibility(edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas) {
   260 	META_DLLAPI_HANDLE_void(FN_SETUPVISIBILITY, pfnSetupVisibility, (pViewEntity, pClient, pvs, pas));
   261 	RETURN_API_void();
   262 }
   263 void mm_UpdateClientData (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd) {
   264 	META_DLLAPI_HANDLE_void(FN_UPDATECLIENTDATA, pfnUpdateClientData, (ent, sendweapons, cd));
   265 	RETURN_API_void();
   266 }
   267 int mm_AddToFullPack(struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet) {
   268 	META_DLLAPI_HANDLE(int, 0, FN_ADDTOFULLPACK, pfnAddToFullPack, (state, e, ent, host, hostflags, player, pSet));
   269 	RETURN_API();
   270 }
   271 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) {
   272 	META_DLLAPI_HANDLE_void(FN_CREATEBASELINE, pfnCreateBaseline, (player, eindex, baseline, entity, playermodelindex, player_mins, player_maxs));
   273 	RETURN_API_void();
   274 }
   275 void mm_RegisterEncoders(void) {
   276 	META_DLLAPI_HANDLE_void(FN_REGISTERENCODERS, pfnRegisterEncoders, ());
   277 	RETURN_API_void();
   278 }
   279 int mm_GetWeaponData(struct edict_s *player, struct weapon_data_s *info) {
   280 	META_DLLAPI_HANDLE(int, 0, FN_GETWEAPONDATA, pfnGetWeaponData, (player, info));
   281 	RETURN_API();
   282 }
   283 void mm_CmdStart(const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed) {
   284 	META_DLLAPI_HANDLE_void(FN_CMDSTART, pfnCmdStart, (player, cmd, random_seed));
   285 	RETURN_API_void();
   286 }
   287 void mm_CmdEnd (const edict_t *player) {
   288 	META_DLLAPI_HANDLE_void(FN_CMDEND, pfnCmdEnd, (player));
   289 	RETURN_API_void();
   290 }
   291 int mm_ConnectionlessPacket(const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size) {
   292 	META_DLLAPI_HANDLE(int, 0, FN_CONNECTIONLESSPACKET, pfnConnectionlessPacket, (net_from, args, response_buffer, response_buffer_size));
   293 	RETURN_API();
   294 }
   295 int mm_GetHullBounds(int hullnumber, float *mins, float *maxs) {
   296 	META_DLLAPI_HANDLE(int, 0, FN_GETHULLBOUNDS, pfnGetHullBounds, (hullnumber, mins, maxs));
   297 	RETURN_API();
   298 }
   299 void mm_CreateInstancedBaselines (void) {
   300 	META_DLLAPI_HANDLE_void(FN_CREATEINSTANCEDBASELINES, pfnCreateInstancedBaselines, ());
   301 	RETURN_API_void();
   302 }
   303 int mm_InconsistentFile(const edict_t *player, const char *filename, char *disconnect_message) {
   304 	META_DLLAPI_HANDLE(int, 0, FN_INCONSISTENTFILE, pfnInconsistentFile, (player, filename, disconnect_message));
   305 	RETURN_API();
   306 }
   307 int mm_AllowLagCompensation(void) {
   308 	META_DLLAPI_HANDLE(int, 0, FN_ALLOWLAGCOMPENSATION, pfnAllowLagCompensation, ());
   309 	RETURN_API();
   310 }
   311 
   312 
   313 // New API functions
   314 // From SDK ?
   315 void mm_OnFreeEntPrivateData(edict_t *pEnt) {
   316 	META_NEWAPI_HANDLE_void(FN_ONFREEENTPRIVATEDATA, pfnOnFreeEntPrivateData, (pEnt));
   317 	RETURN_API_void();
   318 }
   319 void mm_GameShutdown(void) {
   320 	META_NEWAPI_HANDLE_void(FN_GAMESHUTDOWN, pfnGameShutdown, ());
   321 	RETURN_API_void();
   322 }
   323 int mm_ShouldCollide(edict_t *pentTouched, edict_t *pentOther) {
   324 	META_NEWAPI_HANDLE(int, 1, FN_SHOULDCOLLIDE, pfnShouldCollide, (pentTouched, pentOther));
   325 	RETURN_API();
   326 }
   327 // Added 2005/08/11 (no SDK update)
   328 void mm_CvarValue(const edict_t *pEdict, const char *value) {
   329 	g_Players.clear_player_cvar_query(pEdict);
   330 	META_NEWAPI_HANDLE_void(FN_CVARVALUE, pfnCvarValue, (pEdict, value));
   331 	RETURN_API_void();
   332 }
   333 
   334 // From SDK dlls/cbase.cpp:
   335 // "(wd)" indicates my comments on the functions
   336 static DLL_FUNCTIONS gFunctionTable = 
   337 {
   338 	mm_GameDLLInit,				//! pfnGameInit()				Initialize the game (one-time call after loading of game .dll)
   339 	mm_DispatchSpawn,				//! pfnSpawn()
   340 	mm_DispatchThink,				//! pfnThink()
   341 	mm_DispatchUse,				//! pfnUse()
   342 	mm_DispatchTouch,				//! pfnTouch()
   343 	mm_DispatchBlocked,			//! pfnBlocked()
   344 	mm_DispatchKeyValue,			//! pfnKeyValue()
   345 	mm_DispatchSave,				//! pfnSave()
   346 	mm_DispatchRestore,			//! pfnRestore()
   347 	mm_DispatchObjectCollsionBox,	//! pfnSetAbsBox()
   348 
   349 	mm_SaveWriteFields,			//! pfnSaveWriteFields()
   350 	mm_SaveReadFields,				//! pfnSaveReadFields()
   351 
   352 	mm_SaveGlobalState,			//! pfnSaveGlobalState()
   353 	mm_RestoreGlobalState,			//! pfnRestoreGlobalState()
   354 	mm_ResetGlobalState,			//! pfnResetGlobalState()
   355 
   356 	mm_ClientConnect,				//! pfnClientConnect()			(wd) Client has connected
   357 	mm_ClientDisconnect,			//! pfnClientDisconnect()		(wd) Player has left the game
   358 	mm_ClientKill,					//! pfnClientKill()				(wd) Player has typed "kill"
   359 	mm_ClientPutInServer,			//! pfnClientPutInServer()		(wd) Client is entering the game
   360 	mm_ClientCommand,				//! pfnClientCommand()			(wd) Player has sent a command (typed, or from a bind)
   361 	mm_ClientUserInfoChanged,		//! pfnClientUserInfoChanged()	(wd) Client has updated their setinfo structure
   362 	mm_ServerActivate,				//! pfnServerActivate()			(wd) Server is starting a new map
   363 	mm_ServerDeactivate,			//! pfnServerDeactivate()		(wd) Server is leaving the map (shutdown, or changelevel); SDK2
   364 
   365 	mm_PlayerPreThink,				//! pfnPlayerPreThink()
   366 	mm_PlayerPostThink,			//! pfnPlayerPostThink()
   367 
   368 	mm_StartFrame,					//! pfnStartFrame()
   369 	mm_ParmsNewLevel,				//! pfnParmsNewLevel()
   370 	mm_ParmsChangeLevel,			//! pfnParmsChangeLevel()
   371 
   372 	mm_GetGameDescription,			//! pfnGetGameDescription()		Returns string describing current .dll.  E.g. "TeamFotrress 2", "Half-Life"
   373 	mm_PlayerCustomization,		//! pfnPlayerCustomization()	Notifies .dll of new customization for player.
   374 
   375 	mm_SpectatorConnect,			//! pfnSpectatorConnect()		Called when spectator joins server
   376 	mm_SpectatorDisconnect,		//! pfnSpectatorDisconnect()	Called when spectator leaves the server
   377 	mm_SpectatorThink,				//! pfnSpectatorThink()			Called when spectator sends a command packet (usercmd_t)
   378 
   379 	mm_Sys_Error,					//! pfnSys_Error()				Notify game .dll that engine is going to shut down.  Allows mod authors to set a breakpoint.  SDK2
   380 
   381 	mm_PM_Move,					//! pfnPM_Move()				(wd) SDK2
   382 	mm_PM_Init,					//! pfnPM_Init()				Server version of player movement initialization; (wd) SDK2
   383 	mm_PM_FindTextureType,			//! pfnPM_FindTextureType()		(wd) SDK2
   384 
   385 	mm_SetupVisibility,			//! pfnSetupVisibility()		Set up PVS and PAS for networking for this client; (wd) SDK2
   386 	mm_UpdateClientData,			//! pfnUpdateClientData()		Set up data sent only to specific client; (wd) SDK2
   387 	mm_AddToFullPack,				//! pfnAddToFullPack()			(wd) SDK2
   388 	mm_CreateBaseline,				//! pfnCreateBaseline()			Tweak entity baseline for network encoding, allows setup of player baselines, too.; (wd) SDK2
   389 	mm_RegisterEncoders,			//! pfnRegisterEncoders()		Callbacks for network encoding; (wd) SDK2
   390 	mm_GetWeaponData,				//! pfnGetWeaponData()			(wd) SDK2
   391 	mm_CmdStart,					//! pfnCmdStart()				(wd) SDK2
   392 	mm_CmdEnd,						//! pfnCmdEnd()					(wd) SDK2
   393 	mm_ConnectionlessPacket,		//! pfnConnectionlessPacket()	(wd) SDK2
   394 	mm_GetHullBounds,				//! pfnGetHullBounds()			(wd) SDK2
   395 	mm_CreateInstancedBaselines,	//! pfnCreateInstancedBaselines()	(wd) SDK2
   396 	mm_InconsistentFile,			//! pfnInconsistentFile()		(wd) SDK2
   397 	mm_AllowLagCompensation,		//! pfnAllowLagCompensation()	(wd) SDK2
   398 };
   399 
   400 // It's not clear what the difference is between GetAPI and GetAPI2; they
   401 // both appear to return the exact same function table.  
   402 //
   403 // Only one of them appears to be ever called, though.  If the DLL provides
   404 // GetAPI2, the engine/hlds will call that, and will not call GetAPI.  If
   405 // the engine couldn't find GetAPI2 in the DLL, it appears to fall back to
   406 // GetAPI.
   407 //
   408 // So, GetAPI2 appears to replace GetAPI, and appears to have been added
   409 // with SDK 2.0.  My best guess is that, with the new SDK, interface
   410 // version checking became important, and without the int ptr used in
   411 // GetAPI2, the engine can't find out the version of the DLL via GetAPI.
   412 //
   413 // It's unclear whether a DLL coded under SDK2 needs to provide the older
   414 // GetAPI or not..
   415 
   416 C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion)
   417 {
   418 	META_DEBUG(3, ("called: GetEntityAPI; version=%d", interfaceVersion));
   419 	if(!pFunctionTable) {
   420 		META_ERROR("GetEntityAPI called with null pFunctionTable");
   421 		return(FALSE);
   422 	}
   423 	else if(interfaceVersion != INTERFACE_VERSION) {
   424 		META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION);
   425 		return(FALSE);
   426 	}
   427 	memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
   428 	return(TRUE);
   429 }
   430 
   431 C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
   432 {
   433 	META_DEBUG(3, ("called: GetEntityAPI2; version=%d", *interfaceVersion));
   434 	if(!pFunctionTable) {
   435 		META_ERROR("GetEntityAPI2 called with null pFunctionTable");
   436 		return(FALSE);
   437 	}
   438 	else if(*interfaceVersion != INTERFACE_VERSION) {
   439 		META_ERROR("GetEntityAPI2 version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
   440 		//! Tell engine what version we had, so it can figure out who is out of date.
   441 		*interfaceVersion = INTERFACE_VERSION;
   442 		return(FALSE);
   443 	}
   444 	memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
   445 	return(TRUE);
   446 }
   447 
   448 
   449 // I could find _no_ documentation or examples for the intended use of
   450 // NEW_DLL_FUNCTIONS.  I wouldn't have even _known_ about the
   451 // GetNewDLLFunctions() function except for the reference in Adminmod..  It
   452 // appears to be new with SDK 2.0.
   453 //
   454 // Obviously, it seems to provide additional functions to the engine, but
   455 // it's unclear why a new table and interface were added, rather than
   456 // appending new functions to the GetAPI table/interface.
   457 //
   458 // Interestingly, it appears to be called by the engine _before_ GetAPI.
   459 
   460 static NEW_DLL_FUNCTIONS gNewFunctionTable = 
   461 {
   462 	mm_OnFreeEntPrivateData,		//! pfnOnFreeEntPrivateData()	Called right before the object's memory is freed.  Calls its destructor.
   463 	mm_GameShutdown,				//! pfnGameShutdown()
   464 	mm_ShouldCollide,				//! pfnShouldCollide()
   465 	// Added 2005/08/11 (no SDK update)
   466 	mm_CvarValue,					//! pfnCvarValue()
   467 };
   468 
   469 C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) 
   470 {
   471 	META_DEBUG(6, ("called: GetNewDLLFunctions; version=%d", *interfaceVersion));
   472 	// Don't provide these functions to engine if gamedll doesn't provide
   473 	// them.  Otherwise, we're in the position of having to provide answers
   474 	// we can't necessarily provide (for instance, ShouldCollide())...
   475 	if(!GameDLL.funcs.newapi_table)
   476 		return(FALSE);
   477 
   478 	if(!pNewFunctionTable) {
   479 		META_ERROR("GetNewDLLFunctions called with null pNewFunctionTable");
   480 		return(FALSE);
   481 	}
   482 	else if(*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
   483 		META_ERROR("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
   484 		//! Tell engine what version we had, so it can figure out who is out of date.
   485 		*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
   486 		return(FALSE);
   487 	}
   488 	
   489 	// Detect old engine
   490 	if (!IS_VALID_PTR((void *)g_engfuncs.pfnQueryClientCvarValue))
   491 		memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS) - sizeof(FN_CVARVALUE));
   492 	else
   493         memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));
   494 	return(TRUE);
   495 }