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