Fixed warning when building stub_mm plugin.
4 // dllapi.cpp - implementation of Half-Life DLL routines
9 * This file is part of Metamod.
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.
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.
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
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
46 #include "trace_api.h"
47 #include "log_plugin.h"
49 // from SDK dlls/game.cpp:
50 void GameDLLInit( void ) {
51 DLL_TRACE(pfnGameInit, P_PRE, (""));
52 RETURN_META(MRES_IGNORED);
55 // from SDK dlls/cbase.cpp:
56 int DispatchSpawn( edict_t *pent ) {
58 DLL_TRACE(pfnSpawn, P_PRE, ("classname=%s",
59 ed ? STRING(ed->v.classname) : "nil"));
60 // 0==Success, -1==Failure ?
61 RETURN_META_VALUE(MRES_IGNORED, 0);
63 void DispatchThink( edict_t *pent ) {
64 DLL_TRACE(pfnThink, P_PRE, (""));
65 RETURN_META(MRES_IGNORED);
67 void DispatchUse( edict_t *pentUsed, edict_t *pentOther ) {
68 DLL_TRACE(pfnUse, P_PRE, (""));
69 RETURN_META(MRES_IGNORED);
71 void DispatchTouch( edict_t *pentTouched, edict_t *pentOther ) {
72 DLL_TRACE(pfnTouch, P_PRE, (""));
73 RETURN_META(MRES_IGNORED);
75 void DispatchBlocked( edict_t *pentBlocked, edict_t *pentOther ) {
76 DLL_TRACE(pfnBlocked, P_PRE, (""));
77 RETURN_META(MRES_IGNORED);
79 void DispatchKeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd ) {
80 DLL_TRACE(pfnKeyValue, P_PRE, ("classname=%s keyname=%s value=%s", P_PRE,
81 pkvd->szClassName, pkvd->szKeyName, pkvd->szValue));
82 RETURN_META(MRES_IGNORED);
84 void DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData ) {
85 DLL_TRACE(pfnSave, P_PRE, (""));
86 RETURN_META(MRES_IGNORED);
88 int DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity ) {
89 DLL_TRACE(pfnRestore, P_PRE, (""));
90 // 0==Success, -1==Failure ?
91 RETURN_META_VALUE(MRES_IGNORED, 0);
93 void DispatchObjectCollsionBox( edict_t *pent ) {
95 DLL_TRACE(pfnSetAbsBox, P_PRE, ("classname=%s netname=%s",
96 ed ? STRING(ed->v.classname) : "nil",
97 ed ? STRING(ed->v.netname) : "nil"));
98 RETURN_META(MRES_IGNORED);
100 void SaveWriteFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ) {
101 DLL_TRACE(pfnSaveWriteFields, P_PRE, (""));
102 RETURN_META(MRES_IGNORED);
104 void SaveReadFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ) {
105 DLL_TRACE(pfnSaveReadFields, P_PRE, (""));
106 RETURN_META(MRES_IGNORED);
109 // from SDK dlls/world.cpp:
110 void SaveGlobalState( SAVERESTOREDATA *pSaveData ) {
111 DLL_TRACE(pfnSaveGlobalState, P_PRE, (""));
112 RETURN_META(MRES_IGNORED);
114 void RestoreGlobalState( SAVERESTOREDATA *pSaveData ) {
115 DLL_TRACE(pfnRestoreGlobalState, P_PRE, (""));
116 RETURN_META(MRES_IGNORED);
118 void ResetGlobalState( void ) {
119 DLL_TRACE(pfnResetGlobalState, P_PRE, (""));
120 RETURN_META(MRES_IGNORED);
123 //! from SDK dlls/client.cpp:
124 BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) {
125 DLL_TRACE(pfnClientConnect, P_PRE, ("name=%s, addr=%s", pszName, pszAddress));
126 RETURN_META_VALUE(MRES_IGNORED, FALSE);
128 void ClientDisconnect( edict_t *pEntity ) {
129 // DLL_TRACE(pfnClientDisconnect, P_PRE, ("name=%s", ENTITY_KEYVALUE(pEntity, "name")));
130 DLL_TRACE(pfnClientDisconnect, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
131 RETURN_META(MRES_IGNORED);
133 void ClientKill( edict_t *pEntity ) {
134 DLL_TRACE(pfnClientKill, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
135 RETURN_META(MRES_IGNORED);
137 void ClientPutInServer( edict_t *pEntity ) {
138 CBaseEntity *pPlayer=NULL;
139 pPlayer=(CBasePlayer*)GET_PRIVATE(pEntity);
140 DLL_TRACE(pfnClientPutInServer, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
141 RETURN_META(MRES_IGNORED);
143 void ClientCommand( edict_t *pEntity ) {
144 DLL_TRACE(pfnClientCommand, P_PRE, ("name=%s, cmd='%s %s'", STRING(pEntity->v.netname), CMD_ARGV(0),
145 CMD_ARGC() >= 1 ? CMD_ARGS() : ""));
146 RETURN_META(MRES_IGNORED);
148 void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer ) {
149 DLL_TRACE(pfnClientUserInfoChanged, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
150 RETURN_META(MRES_IGNORED);
152 void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) {
153 DLL_TRACE(pfnServerActivate, P_PRE, ("count=%d, max=%d", edictCount, clientMax));
154 RETURN_META(MRES_IGNORED);
156 void ServerDeactivate( void ) {
157 DLL_TRACE(pfnServerDeactivate, P_PRE, (""));
158 RETURN_META(MRES_IGNORED);
160 void PlayerPreThink( edict_t *pEntity ) {
161 DLL_TRACE(pfnPlayerPreThink, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
162 RETURN_META(MRES_IGNORED);
164 void PlayerPostThink( edict_t *pEntity ) {
165 DLL_TRACE(pfnPlayerPostThink, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
166 RETURN_META(MRES_IGNORED);
168 void StartFrame( void ) {
169 DLL_TRACE(pfnStartFrame, P_PRE, (""));
170 RETURN_META(MRES_IGNORED);
172 void ParmsNewLevel( void ) {
173 DLL_TRACE(pfnParmsNewLevel, P_PRE, (""));
174 RETURN_META(MRES_IGNORED);
176 void ParmsChangeLevel( void ) {
177 DLL_TRACE(pfnParmsChangeLevel, P_PRE, (""));
178 RETURN_META(MRES_IGNORED);
180 const char *GetGameDescription( void ) {
181 DLL_TRACE(pfnGetGameDescription, P_PRE, (""));
182 RETURN_META_VALUE(MRES_IGNORED, "");
184 void PlayerCustomization( edict_t *pEntity, customization_t *pCust ) {
185 DLL_TRACE(pfnPlayerCustomization, P_PRE, ("name=%s", STRING(pEntity->v.netname)));
186 RETURN_META(MRES_IGNORED);
188 void SpectatorConnect( edict_t *pEntity ) {
189 DLL_TRACE(pfnSpectatorConnect, P_PRE, (""));
190 RETURN_META(MRES_IGNORED);
192 void SpectatorDisconnect( edict_t *pEntity ) {
193 DLL_TRACE(pfnSpectatorDisconnect, P_PRE, (""));
194 RETURN_META(MRES_IGNORED);
196 void SpectatorThink( edict_t *pEntity ) {
197 DLL_TRACE(pfnSpectatorThink, P_PRE, (""));
198 RETURN_META(MRES_IGNORED);
200 void Sys_Error( const char *error_string ) {
201 DLL_TRACE(pfnSys_Error, P_PRE, ("string=%s", error_string));
202 RETURN_META(MRES_IGNORED);
205 // from SDK pm_shared/pm_shared.c:
206 void PM_Move ( struct playermove_s *ppmove, int server ) {
207 DLL_TRACE(pfnPM_Move, P_PRE, (""));
208 RETURN_META(MRES_IGNORED);
210 void PM_Init( struct playermove_s *ppmove ) {
211 DLL_TRACE(pfnPM_Init, P_PRE, (""));
212 RETURN_META(MRES_IGNORED);
214 char PM_FindTextureType( const char *name ) {
215 DLL_TRACE(pfnPM_FindTextureType, P_PRE, ("name=%s", name));
216 RETURN_META_VALUE(MRES_IGNORED, '\0');
219 // from SDK dlls/client.cpp:
220 void SetupVisibility( edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas ) {
221 DLL_TRACE(pfnSetupVisibility, P_PRE, (""));
222 RETURN_META(MRES_IGNORED);
224 void UpdateClientData ( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd ) {
225 DLL_TRACE(pfnUpdateClientData, P_PRE, (""));
226 RETURN_META(MRES_IGNORED);
228 int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet ) {
229 DLL_TRACE(pfnAddToFullPack, P_PRE, (""));
230 RETURN_META_VALUE(MRES_IGNORED, 0);
232 void CreateBaseline( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs ) {
233 DLL_TRACE(pfnCreateBaseline, P_PRE, (""));
234 RETURN_META(MRES_IGNORED);
236 void RegisterEncoders( void ) {
237 DLL_TRACE(pfnRegisterEncoders, P_PRE, (""));
238 RETURN_META(MRES_IGNORED);
240 int GetWeaponData( struct edict_s *player, struct weapon_data_s *info ) {
241 DLL_TRACE(pfnGetWeaponData, P_PRE, (""));
242 RETURN_META_VALUE(MRES_IGNORED, 1);
244 void CmdStart( const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed ) {
245 DLL_TRACE(pfnCmdStart, P_PRE, ("name=%s, rand=%d", STRING(player->v.netname), random_seed));
246 RETURN_META(MRES_IGNORED);
248 void CmdEnd ( const edict_t *player ) {
249 DLL_TRACE(pfnCmdEnd, P_PRE, ("name=%s", STRING(player->v.netname)));
250 RETURN_META(MRES_IGNORED);
252 int ConnectionlessPacket( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size ) {
253 DLL_TRACE(pfnConnectionlessPacket, P_PRE, (""));
254 RETURN_META_VALUE(MRES_IGNORED, 0);
256 int GetHullBounds( int hullnumber, float *mins, float *maxs ) {
257 DLL_TRACE(pfnGetHullBounds, P_PRE, (""));
258 RETURN_META_VALUE(MRES_IGNORED, 0);
260 void CreateInstancedBaselines ( void ) {
261 DLL_TRACE(pfnCreateInstancedBaselines, P_PRE, (""));
262 RETURN_META(MRES_IGNORED);
264 int InconsistentFile( const edict_t *player, const char *filename, char *disconnect_message ) {
265 DLL_TRACE(pfnInconsistentFile, P_PRE, ("name=%s, file=%s", STRING(player->v.netname), filename));
266 RETURN_META_VALUE(MRES_IGNORED, 0);
268 int AllowLagCompensation( void ) {
269 DLL_TRACE(pfnAllowLagCompensation, P_PRE, (""));
270 RETURN_META_VALUE(MRES_IGNORED, 1);
275 void OnFreeEntPrivateData(edict_t *pEnt) {
276 NEWDLL_TRACE(pfnOnFreeEntPrivateData, P_PRE, (""));
277 RETURN_META(MRES_IGNORED);
279 void GameShutdown(void) {
280 NEWDLL_TRACE(pfnGameShutdown, P_PRE, (""));
281 RETURN_META(MRES_IGNORED);
283 int ShouldCollide(edict_t *pentTouched, edict_t *pentOther) {
284 NEWDLL_TRACE(pfnShouldCollide, P_PRE, (""));
285 RETURN_META_VALUE(MRES_IGNORED, 1);
288 // Added 2005-08-11 (no SDK update)
289 void CvarValue(const edict_t *pEdict, const char *szValue) {
290 NEWDLL_TRACE(pfnCvarValue, P_PRE, ("player=%s, value=%s", STRING(pEdict->v.netname), szValue?szValue:"nil"));
291 RETURN_META(MRES_IGNORED);
294 // Added 2005-11-22 (no SDK update)
295 void CvarValue2(const edict_t *pEdict, int requestID, const char *cvarName, const char *value) {
296 NEWDLL_TRACE(pfnCvarValue2, P_PRE, ("player=%s, requestID=%d, cvar=%s, value=%s",
297 STRING(pEdict->v.netname), requestID, cvarName?cvarName:"nil", value?value:"nil"));
298 RETURN_META(MRES_IGNORED);
302 // from SDK dlls/cbase.cpp:
303 // (wd) indicates my comments on the functions
304 static DLL_FUNCTIONS gFunctionTable =
306 GameDLLInit, //! pfnGameInit() Initialize the game (one-time call after loading of game .dll)
307 DispatchSpawn, //! pfnSpawn()
308 DispatchThink, //! pfnThink()
309 DispatchUse, //! pfnUse()
310 DispatchTouch, //! pfnTouch()
311 DispatchBlocked, //! pfnBlocked()
312 DispatchKeyValue, //! pfnKeyValue()
313 DispatchSave, //! pfnSave()
314 DispatchRestore, //! pfnRestore()
315 DispatchObjectCollsionBox, //! pfnSetAbsBox()
317 SaveWriteFields, //! pfnSaveWriteFields()
318 SaveReadFields, //! pfnSaveReadFields()
320 SaveGlobalState, //! pfnSaveGlobalState()
321 RestoreGlobalState, //! pfnRestoreGlobalState()
322 ResetGlobalState, //! pfnResetGlobalState()
324 ClientConnect, //! pfnClientConnect() (wd) Client has connected
325 ClientDisconnect, //! pfnClientDisconnect() (wd) Player has left the game
326 ClientKill, //! pfnClientKill() (wd) Player has typed "kill"
327 ClientPutInServer, //! pfnClientPutInServer() (wd) Client is entering the game
328 ClientCommand, //! pfnClientCommand() (wd) Player has sent a command (typed, or from a bind)
329 ClientUserInfoChanged, //! pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure
330 ServerActivate, //! pfnServerActivate() (wd) Server is starting a new map
331 ServerDeactivate, //! pfnServerDeactivate() (wd) Server is leaving the map (shutdown, or changelevel); SDK2
333 PlayerPreThink, //! pfnPlayerPreThink()
334 PlayerPostThink, //! pfnPlayerPostThink()
336 StartFrame, //! pfnStartFrame()
337 ParmsNewLevel, //! pfnParmsNewLevel()
338 ParmsChangeLevel, //! pfnParmsChangeLevel()
340 GetGameDescription, //! pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2", "Half-Life"
341 PlayerCustomization, //! pfnPlayerCustomization() Notifies .dll of new customization for player.
343 SpectatorConnect, //! pfnSpectatorConnect() Called when spectator joins server
344 SpectatorDisconnect, //! pfnSpectatorDisconnect() Called when spectator leaves the server
345 SpectatorThink, //! pfnSpectatorThink() Called when spectator sends a command packet (usercmd_t)
347 Sys_Error, //! pfnSys_Error() Notify game .dll that engine is going to shut down. Allows mod authors to set a breakpoint. SDK2
349 PM_Move, //! pfnPM_Move() (wd) SDK2
350 PM_Init, //! pfnPM_Init() Server version of player movement initialization; (wd) SDK2
351 PM_FindTextureType, //! pfnPM_FindTextureType() (wd) SDK2
353 SetupVisibility, //! pfnSetupVisibility() Set up PVS and PAS for networking for this client; (wd) SDK2
354 UpdateClientData, //! pfnUpdateClientData() Set up data sent only to specific client; (wd) SDK2
355 AddToFullPack, //! pfnAddToFullPack() (wd) SDK2
356 CreateBaseline, //! pfnCreateBaseline() Tweak entity baseline for network encoding, allows setup of player baselines, too.; (wd) SDK2
357 RegisterEncoders, //! pfnRegisterEncoders() Callbacks for network encoding; (wd) SDK2
358 GetWeaponData, //! pfnGetWeaponData() (wd) SDK2
359 CmdStart, //! pfnCmdStart() (wd) SDK2
360 CmdEnd, //! pfnCmdEnd() (wd) SDK2
361 ConnectionlessPacket, //! pfnConnectionlessPacket() (wd) SDK2
362 GetHullBounds, //! pfnGetHullBounds() (wd) SDK2
363 CreateInstancedBaselines, //! pfnCreateInstancedBaselines() (wd) SDK2
364 InconsistentFile, //! pfnInconsistentFile() (wd) SDK2
365 AllowLagCompensation, //! pfnAllowLagCompensation() (wd) SDK2
368 // It's not clear what the difference is between GetAPI and GetAPI2; they
369 // both appear to return the exact same function table.
371 // Only one of them appears to be ever called, though. If the DLL provides
372 // GetAPI2, the engine/hlds will call that, and will not call GetAPI. If
373 // the engine couldn't find GetAPI2 in the DLL, it appears to fall back to
376 // So, GetAPI2 appears to replace GetAPI, and appears to have been added
377 // with SDK 2.0. My best guess is that, with the new SDK, interface
378 // version checking became important, and without the int ptr used in
379 // GetAPI2, the engine can't find out the version of the DLL via GetAPI.
381 // It's unclear whether a DLL coded under SDK2 needs to provide the older
384 C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable,
385 int *interfaceVersion )
387 LOG_DEVELOPER(PLID, "called: GetEntityAPI2; version=%d", *interfaceVersion);
388 if(!pFunctionTable) {
389 LOG_ERROR(PLID, "GetEntityAPI2 called with null pFunctionTable");
392 else if(*interfaceVersion != INTERFACE_VERSION) {
394 "GetEntityAPI2 version mismatch; requested=%d ours=%d",
395 *interfaceVersion, INTERFACE_VERSION);
396 //! Tell engine what version we had, so it can figure out who is
398 *interfaceVersion = INTERFACE_VERSION;
401 memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
406 // I could find _no_ documentation or examples for the intended use of
407 // NEW_DLL_FUNCTIONS. I wouldn't have even _known_ about the
408 // GetNewDLLFunctions() function except for the reference in Adminmod.. It
409 // appears to be new with SDK 2.0.
411 // Obviously, it seems to provide additional functions to the engine, but
412 // it's unclear why a new table and interface were added, rather than
413 // appending new functions to the GetAPI table/interface.
415 // Interestingly, it appears to be called by the engine _before_ GetAPI.
417 static NEW_DLL_FUNCTIONS gNewFunctionTable =
419 OnFreeEntPrivateData, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor.
420 GameShutdown, //! pfnGameShutdown()
421 ShouldCollide, //! pfnShouldCollide()
422 // Added 2005-08-11 (no SDK update)
423 CvarValue, //! pfnCvarValue()
424 // Added 2005-11-22 (no SDK update)
425 CvarValue2, //! pfnCvarValue2()
428 C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable,
429 int *interfaceVersion)
431 LOG_DEVELOPER(PLID, "called: GetNewDLLFunctions; version=%d",
433 if(!pNewFunctionTable) {
435 "GetNewDLLFunctions called with null pNewFunctionTable");
438 else if(*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
440 "GetNewDLLFunctions version mismatch; requested=%d ours=%d",
441 *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
442 //! Tell engine what version we had, so it can figure out who is
444 *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
447 memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));