4 // dllapi_post.cpp - implementation of "post" versions 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
41 #include "dllapi_post.h"
42 #include "trace_api.h"
43 #include "log_plugin.h"
45 // from SDK dlls/game.cpp:
46 void GameDLLInit_Post( void ) {
47 DLL_TRACE(pfnGameInit, P_POST, (""));
48 RETURN_META(MRES_IGNORED);
51 // from SDK dlls/cbase.cpp:
52 int DispatchSpawn_Post( edict_t *pent ) {
54 DLL_TRACE(pfnSpawn, P_POST, ("classname=%s, returning %d",
55 ed ? STRING(ed->v.classname) : "nil",
56 META_RESULT_ORIG_RET(int)));
57 // 0==Success, -1==Failure ?
58 RETURN_META_VALUE(MRES_IGNORED, 0);
60 void DispatchThink_Post( edict_t *pent ) {
61 DLL_TRACE(pfnThink, P_POST, (""));
62 RETURN_META(MRES_IGNORED);
64 void DispatchUse_Post( edict_t *pentUsed, edict_t *pentOther ) {
65 DLL_TRACE(pfnUse, P_POST, (""));
66 RETURN_META(MRES_IGNORED);
68 void DispatchTouch_Post( edict_t *pentTouched, edict_t *pentOther ) {
69 DLL_TRACE(pfnTouch, P_POST, (""));
70 RETURN_META(MRES_IGNORED);
72 void DispatchBlocked_Post( edict_t *pentBlocked, edict_t *pentOther ) {
73 DLL_TRACE(pfnBlocked, P_POST, (""));
74 RETURN_META(MRES_IGNORED);
76 void DispatchKeyValue_Post( edict_t *pentKeyvalue, KeyValueData *pkvd ) {
77 DLL_TRACE(pfnKeyValue, P_POST, ("classname=%s keyname=%s value=%s",
78 pkvd->szClassName, pkvd->szKeyName, pkvd->szValue));
79 RETURN_META(MRES_IGNORED);
81 void DispatchSave_Post( edict_t *pent, SAVERESTOREDATA *pSaveData ) {
82 DLL_TRACE(pfnSave, P_POST, (""));
83 RETURN_META(MRES_IGNORED);
85 int DispatchRestore_Post( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity ) {
86 DLL_TRACE(pfnRestore, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
87 // 0==Success, -1==Failure ?
88 RETURN_META_VALUE(MRES_IGNORED, 0);
90 void DispatchObjectCollsionBox_Post( edict_t *pent ) {
91 DLL_TRACE(pfnSetAbsBox, P_POST, (""));
92 RETURN_META(MRES_IGNORED);
94 void SaveWriteFields_Post( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ) {
95 DLL_TRACE(pfnSaveWriteFields, P_POST, (""));
96 RETURN_META(MRES_IGNORED);
98 void SaveReadFields_Post( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ) {
99 DLL_TRACE(pfnSaveReadFields, P_POST, (""));
100 RETURN_META(MRES_IGNORED);
103 // from SDK dlls/world.cpp:
104 void SaveGlobalState_Post( SAVERESTOREDATA *pSaveData ) {
105 DLL_TRACE(pfnSaveGlobalState, P_POST, (""));
106 RETURN_META(MRES_IGNORED);
108 void RestoreGlobalState_Post( SAVERESTOREDATA *pSaveData ) {
109 DLL_TRACE(pfnRestoreGlobalState, P_POST, (""));
110 RETURN_META(MRES_IGNORED);
112 void ResetGlobalState_Post( void ) {
113 DLL_TRACE(pfnResetGlobalState, P_POST, (""));
114 RETURN_META(MRES_IGNORED);
117 //! from SDK dlls/client.cpp:
118 BOOL ClientConnect_Post( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) {
119 BOOL ret=META_RESULT_ORIG_RET(BOOL);
120 if(ret) DLL_TRACE(pfnClientConnect, P_POST, ("returning %d", ret));
121 else DLL_TRACE(pfnClientConnect, P_POST, ("returning %d, reason=%s", ret, szRejectReason));
122 RETURN_META_VALUE(MRES_IGNORED, TRUE);
124 void ClientDisconnect_Post( edict_t *pEntity ) {
125 DLL_TRACE(pfnClientDisconnect, P_POST, (""));
126 RETURN_META(MRES_IGNORED);
128 void ClientKill_Post( edict_t *pEntity ) {
129 DLL_TRACE(pfnClientKill, P_POST, (""));
130 RETURN_META(MRES_IGNORED);
132 void ClientPutInServer_Post( edict_t *pEntity ) {
133 DLL_TRACE(pfnClientPutInServer, P_POST, (""));
134 RETURN_META(MRES_IGNORED);
136 void ClientCommand_Post( edict_t *pEntity ) {
137 DLL_TRACE(pfnClientCommand, P_POST, (""));
138 RETURN_META(MRES_IGNORED);
140 void ClientUserInfoChanged_Post( edict_t *pEntity, char *infobuffer ) {
141 DLL_TRACE(pfnClientUserInfoChanged, P_POST, (""));
142 RETURN_META(MRES_IGNORED);
144 void ServerActivate_Post( edict_t *pEdictList, int edictCount, int clientMax ) {
145 DLL_TRACE(pfnServerActivate, P_POST, (""));
146 RETURN_META(MRES_IGNORED);
148 void ServerDeactivate_Post( void ) {
149 DLL_TRACE(pfnServerDeactivate, P_POST, (""));
150 RETURN_META(MRES_IGNORED);
152 void PlayerPreThink_Post( edict_t *pEntity ) {
153 DLL_TRACE(pfnPlayerPreThink, P_POST, (""));
154 RETURN_META(MRES_IGNORED);
156 void PlayerPostThink_Post( edict_t *pEntity ) {
157 DLL_TRACE(pfnPlayerPostThink, P_POST, (""));
158 RETURN_META(MRES_IGNORED);
160 void StartFrame_Post( void ) {
161 DLL_TRACE(pfnStartFrame, P_POST, (""));
162 RETURN_META(MRES_IGNORED);
164 void ParmsNewLevel_Post( void ) {
165 DLL_TRACE(pfnParmsNewLevel, P_POST, (""));
166 RETURN_META(MRES_IGNORED);
168 void ParmsChangeLevel_Post( void ) {
169 DLL_TRACE(pfnParmsChangeLevel, P_POST, (""));
170 RETURN_META(MRES_IGNORED);
172 const char *GetGameDescription_Post( void ) {
173 DLL_TRACE(pfnGetGameDescription, P_POST, ("returning %s", META_RESULT_ORIG_RET(char *)));
174 RETURN_META_VALUE(MRES_IGNORED, "");
176 void PlayerCustomization_Post( edict_t *pEntity, customization_t *pCust ) {
177 DLL_TRACE(pfnPlayerCustomization, P_POST, (""));
178 RETURN_META(MRES_IGNORED);
180 void SpectatorConnect_Post( edict_t *pEntity ) {
181 DLL_TRACE(pfnSpectatorConnect, P_POST, (""));
182 RETURN_META(MRES_IGNORED);
184 void SpectatorDisconnect_Post( edict_t *pEntity ) {
185 DLL_TRACE(pfnSpectatorDisconnect, P_POST, (""));
186 RETURN_META(MRES_IGNORED);
188 void SpectatorThink_Post( edict_t *pEntity ) {
189 DLL_TRACE(pfnSpectatorThink, P_POST, (""));
190 RETURN_META(MRES_IGNORED);
192 void Sys_Error_Post( const char *error_string ) {
193 DLL_TRACE(pfnSys_Error, P_POST, (""));
194 RETURN_META(MRES_IGNORED);
197 // from SDK pm_shared/pm_shared.c:
198 void PM_Move_Post( struct playermove_s *ppmove, int server ) {
199 DLL_TRACE(pfnPM_Move, P_POST, (""));
200 RETURN_META(MRES_IGNORED);
202 void PM_Init_Post( struct playermove_s *ppmove ) {
203 DLL_TRACE(pfnPM_Init, P_POST, (""));
204 RETURN_META(MRES_IGNORED);
206 char PM_FindTextureType_Post( char *name ) {
207 DLL_TRACE(pfnPM_FindTextureType, P_POST, (""));
208 RETURN_META_VALUE(MRES_IGNORED, '\0');
211 // from SDK dlls/client.cpp:
212 void SetupVisibility_Post( edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas ) {
213 DLL_TRACE(pfnSetupVisibility, P_POST, (""));
214 RETURN_META(MRES_IGNORED);
216 void UpdateClientData_Post ( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd ) {
217 DLL_TRACE(pfnUpdateClientData, P_POST, (""));
218 RETURN_META(MRES_IGNORED);
220 int AddToFullPack_Post( struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet ) {
221 DLL_TRACE(pfnAddToFullPack, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
222 RETURN_META_VALUE(MRES_IGNORED, 0);
224 void CreateBaseline_Post( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs ) {
225 DLL_TRACE(pfnCreateBaseline, P_POST, (""));
226 RETURN_META(MRES_IGNORED);
228 void RegisterEncoders_Post( void ) {
229 DLL_TRACE(pfnRegisterEncoders, P_POST, (""));
230 RETURN_META(MRES_IGNORED);
232 int GetWeaponData_Post( struct edict_s *player, struct weapon_data_s *info ) {
233 DLL_TRACE(pfnGetWeaponData, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
234 RETURN_META_VALUE(MRES_IGNORED, 1);
236 void CmdStart_Post( const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed ) {
237 DLL_TRACE(pfnCmdStart, P_POST, (""));
238 RETURN_META(MRES_IGNORED);
240 void CmdEnd_Post ( const edict_t *player ) {
241 DLL_TRACE(pfnCmdEnd, P_POST, (""));
242 RETURN_META(MRES_IGNORED);
244 int ConnectionlessPacket_Post( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size ) {
245 DLL_TRACE(pfnConnectionlessPacket, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
246 RETURN_META_VALUE(MRES_IGNORED, 0);
248 int GetHullBounds_Post( int hullnumber, float *mins, float *maxs ) {
249 DLL_TRACE(pfnGetHullBounds, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
250 RETURN_META_VALUE(MRES_IGNORED, 0);
252 void CreateInstancedBaselines_Post ( void ) {
253 DLL_TRACE(pfnCreateInstancedBaselines, P_POST, (""));
254 RETURN_META(MRES_IGNORED);
256 int InconsistentFile_Post( const edict_t *player, const char *filename, char *disconnect_message ) {
257 DLL_TRACE(pfnInconsistentFile, P_POST, ("returning %d, message=%s", META_RESULT_ORIG_RET(int), disconnect_message));
258 RETURN_META_VALUE(MRES_IGNORED, 0);
260 int AllowLagCompensation_Post( void ) {
261 DLL_TRACE(pfnAllowLagCompensation, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
262 RETURN_META_VALUE(MRES_IGNORED, 1);
267 void OnFreeEntPrivateData_Post(edict_t *pEnt) {
268 NEWDLL_TRACE(pfnOnFreeEntPrivateData, P_POST, (""));
269 RETURN_META(MRES_IGNORED);
271 void GameShutdown_Post(void) {
272 NEWDLL_TRACE(pfnGameShutdown, P_POST, (""));
273 RETURN_META(MRES_IGNORED);
275 int ShouldCollide_Post(edict_t *pentTouched, edict_t *pentOther) {
276 NEWDLL_TRACE(pfnShouldCollide, P_POST, ("returning %d", META_RESULT_ORIG_RET(int)));
277 RETURN_META_VALUE(MRES_IGNORED, 1);
280 void CvarValue_Post(const edict_t *pEdict, const char *szValue)
282 NEWDLL_TRACE(pfnCvarValue, P_POST, (""));
283 RETURN_META(MRES_IGNORED);
287 // from SDK dlls/cbase.cpp:
288 // (wd) indicates my comments on the functions
289 static DLL_FUNCTIONS gFunctionTable_Post =
291 GameDLLInit_Post, //! pfnGameInit() Initialize the game (one-time call after loading of game .dll)
292 DispatchSpawn_Post, //! pfnSpawn()
293 DispatchThink_Post, //! pfnThink()
294 DispatchUse_Post, //! pfnUse()
295 DispatchTouch_Post, //! pfnTouch()
296 DispatchBlocked_Post, //! pfnBlocked()
297 DispatchKeyValue_Post, //! pfnKeyValue()
298 DispatchSave_Post, //! pfnSave()
299 DispatchRestore_Post, //! pfnRestore()
300 DispatchObjectCollsionBox_Post, //! pfnSetAbsBox()
302 SaveWriteFields_Post, //! pfnSaveWriteFields()
303 SaveReadFields_Post, //! pfnSaveReadFields()
305 SaveGlobalState_Post, //! pfnSaveGlobalState()
306 RestoreGlobalState_Post, //! pfnRestoreGlobalState()
307 ResetGlobalState_Post, //! pfnResetGlobalState()
309 ClientConnect_Post, //! pfnClientConnect() (wd) Client has connected
310 ClientDisconnect_Post, //! pfnClientDisconnect() (wd) Player has left the game
311 ClientKill_Post, //! pfnClientKill() (wd) Player has typed "kill"
312 ClientPutInServer_Post, //! pfnClientPutInServer() (wd) Client is entering the game
313 ClientCommand_Post, //! pfnClientCommand() (wd) Player has sent a command (typed, or from a bind)
314 ClientUserInfoChanged_Post, //! pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure
315 ServerActivate_Post, //! pfnServerActivate() (wd) Server is starting a new map
316 ServerDeactivate_Post, //! pfnServerDeactivate() (wd) Server is leaving the map (shutdown, or changelevel); SDK2
318 PlayerPreThink_Post, //! pfnPlayerPreThink()
319 PlayerPostThink_Post, //! pfnPlayerPostThink()
321 StartFrame_Post, //! pfnStartFrame()
322 ParmsNewLevel_Post, //! pfnParmsNewLevel()
323 ParmsChangeLevel_Post, //! pfnParmsChangeLevel()
325 GetGameDescription_Post, //! pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2", "Half-Life"
326 PlayerCustomization_Post, //! pfnPlayerCustomization() Notifies .dll of new customization for player.
328 SpectatorConnect_Post, //! pfnSpectatorConnect() Called when spectator joins server
329 SpectatorDisconnect_Post, //! pfnSpectatorDisconnect() Called when spectator leaves the server
330 SpectatorThink_Post, //! pfnSpectatorThink() Called when spectator sends a command packet (usercmd_t)
332 Sys_Error_Post, //! pfnSys_Error() Notify game .dll that engine is going to shut down. Allows mod authors to set a breakpoint. SDK2
334 PM_Move_Post, //! pfnPM_Move() (wd) SDK2
335 PM_Init_Post, //! pfnPM_Init() Server version of player movement initialization; (wd) SDK2
336 PM_FindTextureType_Post, //! pfnPM_FindTextureType() (wd) SDK2
338 SetupVisibility_Post, //! pfnSetupVisibility() Set up PVS and PAS for networking for this client; (wd) SDK2
339 UpdateClientData_Post, //! pfnUpdateClientData() Set up data sent only to specific client; (wd) SDK2
340 AddToFullPack_Post, //! pfnAddToFullPack() (wd) SDK2
341 CreateBaseline_Post, //! pfnCreateBaseline() Tweak entity baseline for network encoding, allows setup of player baselines, too.; (wd) SDK2
342 RegisterEncoders_Post, //! pfnRegisterEncoders() Callbacks for network encoding; (wd) SDK2
343 GetWeaponData_Post, //! pfnGetWeaponData() (wd) SDK2
344 CmdStart_Post, //! pfnCmdStart() (wd) SDK2
345 CmdEnd_Post, //! pfnCmdEnd() (wd) SDK2
346 ConnectionlessPacket_Post, //! pfnConnectionlessPacket() (wd) SDK2
347 GetHullBounds_Post, //! pfnGetHullBounds() (wd) SDK2
348 CreateInstancedBaselines_Post, //! pfnCreateInstancedBaselines() (wd) SDK2
349 InconsistentFile_Post, //! pfnInconsistentFile() (wd) SDK2
350 AllowLagCompensation_Post, //! pfnAllowLagCompensation() (wd) SDK2
353 C_DLLEXPORT int GetEntityAPI_Post( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion )
355 LOG_DEVELOPER(PLID, "called: GetEntityAPI_Post; version=%d", interfaceVersion);
356 if(!pFunctionTable) {
357 LOG_ERROR(PLID, "GetEntityAPI_Post called with null pFunctionTable");
360 else if(interfaceVersion != INTERFACE_VERSION) {
361 LOG_ERROR(PLID, "GetEntityAPI_Post version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION);
364 memcpy(pFunctionTable, &gFunctionTable_Post, sizeof( DLL_FUNCTIONS ) );
368 C_DLLEXPORT int GetEntityAPI2_Post( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion )
370 LOG_DEVELOPER(PLID, "called: GetEntityAPI2_Post; version=%d", *interfaceVersion);
371 if(!pFunctionTable) {
372 LOG_ERROR(PLID, "GetEntityAPI2_Post called with null pFunctionTable");
375 else if(*interfaceVersion != INTERFACE_VERSION) {
376 LOG_ERROR(PLID, "GetEntityAPI2_Post version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
377 //! Tell engine what version we had, so it can figure out who is out of date.
378 *interfaceVersion = INTERFACE_VERSION;
381 memcpy( pFunctionTable, &gFunctionTable_Post, sizeof( DLL_FUNCTIONS ) );
386 static NEW_DLL_FUNCTIONS gNewFunctionTable_Post =
388 OnFreeEntPrivateData_Post, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor.
389 GameShutdown_Post, //! pfnGameShutdown()
390 ShouldCollide_Post, //! pfnShouldCollide()
391 CvarValue_Post, //! pfnCvarValue()
394 C_DLLEXPORT int GetNewDLLFunctions_Post( NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion )
396 LOG_DEVELOPER(PLID, "called: GetNewDLLFunctions_Post; version=%d", *interfaceVersion);
397 if(!pNewFunctionTable) {
398 LOG_ERROR(PLID, "GetNewDLLFunctions_Post called with null pNewFunctionTable");
401 else if(*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
402 LOG_ERROR(PLID, "GetNewDLLFunctions_Post version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
403 //! Tell engine what version we had, so it can figure out who is out of date.
404 *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
407 memcpy(pNewFunctionTable, &gNewFunctionTable_Post, sizeof(NEW_DLL_FUNCTIONS));