2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2024-12-31 00:55:47 +03:00
metamod-r/metamod/src/meta_api.h

185 lines
8.5 KiB
C
Raw Normal View History

2016-07-26 19:31:47 +03:00
#pragma once
2016-07-04 09:07:29 +03:00
#include "dllapi.h" // GETENTITYAPI_FN, etc
2016-07-26 19:31:47 +03:00
#include "engine_api.h" // GET_ENGINE_FUNCTIONS_FN, etc
2016-07-04 09:07:29 +03:00
#include "plinfo.h" // plugin_info_t, etc
#include "osdep.h" // DLLEXPORT, etc
2016-07-26 19:31:47 +03:00
#include "mutil.h"
2016-07-04 09:07:29 +03:00
// Version consists of "major:minor", two separate integer numbers.
// Version 1 original
// Version 2 added plugin_info_t **pinfo
// Version 3 init split into query and attach, added detach
// Version 4 added (PLUG_LOADTIME now) to attach
// Version 5 changed mm ifvers int* to string, moved pl ifvers to info
// Version 5:1 added link support for entity "adminmod_timer" (adminmod)
// Version 5:2 added gamedll_funcs to meta_attach() [v1.0-rc2]
// Version 5:3 added mutil_funcs to meta_query() [v1.05]
// Version 5:4 added centersay utility functions [v1.06]
// Version 5:5 added Meta_Init to plugin API [v1.08]
// Version 5:6 added CallGameEntity utility function [v1.09]
// Version 5:7 added GetUserMsgID, GetUserMsgName util funcs [v1.11]
// Version 5:8 added GetPluginPath [v1.11]
// Version 5:9 added GetGameInfo [v1.14]
// Version 5:10 added GINFO_REALDLL_FULLPATH for GetGameInfo [v1.17]
// Version 5:11 added plugin loading and unloading API [v1.18]
2016-07-26 19:31:47 +03:00
// Version 5:12 added IS_QUERYING_CLIENT_CVAR to mutils [v1.18]
// Version 5:13 added MAKE_REQUESTID and GET_HOOK_TABLES to mutils [v1.19]
2016-07-04 09:07:29 +03:00
#define META_INTERFACE_VERSION "5:13"
// Flags returned by a plugin's api function.
// NOTE: order is crucial, as greater/less comparisons are made.
2016-07-26 19:31:47 +03:00
enum META_RES
{
2016-07-04 09:07:29 +03:00
MRES_UNSET = 0,
MRES_IGNORED, // plugin didn't take any action
MRES_HANDLED, // plugin did something, but real function should still be called
MRES_OVERRIDE, // call real function, but use my return value
MRES_SUPERCEDE, // skip real function; use my return value
2016-07-26 19:31:47 +03:00
};
2016-07-04 09:07:29 +03:00
// Variables provided to plugins.
2016-07-26 19:31:47 +03:00
struct meta_globals_t
{
2016-07-04 09:07:29 +03:00
META_RES mres; // writable; plugin's return flag
META_RES prev_mres; // readable; return flag of the previous plugin called
META_RES status; // readable; "highest" return flag so far
void *orig_ret; // readable; return value from "real" function
void *override_ret; // readable; return value from overriding/superceding plugin
2016-07-26 19:31:47 +03:00
};
2016-07-04 09:07:29 +03:00
2016-07-26 03:22:47 +03:00
extern meta_globals_t *gpMetaGlobals;
2016-07-26 19:31:47 +03:00
#define SET_META_RESULT(result) gpMetaGlobals->mres = result
2016-07-04 09:07:29 +03:00
#define RETURN_META(result) \
2016-07-26 19:31:47 +03:00
do { gpMetaGlobals->mres = result; return; } while (0)
2016-07-04 09:07:29 +03:00
#define RETURN_META_VALUE(result, value) \
2016-07-26 19:31:47 +03:00
do { gpMetaGlobals->mres = result; return value; } while (0)
#define META_RESULT_STATUS gpMetaGlobals->status
2016-07-04 09:07:29 +03:00
#define META_RESULT_PREVIOUS gpMetaGlobals->prev_mres
#define META_RESULT_ORIG_RET(type) *(type *)gpMetaGlobals->orig_ret
2016-07-26 19:31:47 +03:00
#define META_RESULT_OVERRIDE_RET(type) *(type *)gpMetaGlobals->override_ret
2016-07-04 09:07:29 +03:00
// Table of getapi functions, retrieved from each plugin.
2016-07-26 19:31:47 +03:00
struct META_FUNCTIONS
{
2016-07-04 09:07:29 +03:00
GETENTITYAPI_FN pfnGetEntityAPI;
GETENTITYAPI_FN pfnGetEntityAPI_Post;
GETENTITYAPI2_FN pfnGetEntityAPI2;
GETENTITYAPI2_FN pfnGetEntityAPI2_Post;
GETNEWDLLFUNCTIONS_FN pfnGetNewDLLFunctions;
GETNEWDLLFUNCTIONS_FN pfnGetNewDLLFunctions_Post;
GET_ENGINE_FUNCTIONS_FN pfnGetEngineFunctions;
GET_ENGINE_FUNCTIONS_FN pfnGetEngineFunctions_Post;
2016-07-26 19:31:47 +03:00
};
2016-07-04 09:07:29 +03:00
// Pair of function tables provided by game DLL.
2016-07-26 19:31:47 +03:00
struct gamedll_funcs_t
{
2016-07-04 09:07:29 +03:00
DLL_FUNCTIONS *dllapi_table;
NEW_DLL_FUNCTIONS *newapi_table;
2016-07-26 19:31:47 +03:00
};
2016-07-04 09:07:29 +03:00
// Declared in plugin; referenced in macros.
2016-07-26 03:22:47 +03:00
extern gamedll_funcs_t *gpGamedllFuncs;
extern mutil_funcs_t *gpMetaUtilFuncs;
2016-07-04 09:07:29 +03:00
// Tell the dll that we'll be loading it as a metamod plugin, in case it
// needs to do something special prior to the standard query/attach
// procedure. In particular, this will allow for DLL's that can be used as
// both standalone DLL's and metamod plugins. (optional; not required in
// plugin)
2016-07-26 19:31:47 +03:00
C_DLLEXPORT void Meta_Init();
typedef void (*META_INIT_FN)();
2016-07-04 09:07:29 +03:00
// Get info about plugin, compare meta_interface versions, provide meta
// utility callback functions.
2016-07-26 19:31:47 +03:00
C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs);
typedef int (*META_QUERY_FN) (char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs);
// Attach the plugin to the API; get the table of getapi functions; give
2016-07-04 09:07:29 +03:00
// meta_globals and gamedll_funcs.
2016-07-26 19:31:47 +03:00
C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs);
typedef int (*META_ATTACH_FN) (PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs);
2016-07-04 09:07:29 +03:00
// Detach the plugin; tell why and when.
C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
typedef int (*META_DETACH_FN) (PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
// Standard HL SDK interface function prototypes.
2016-07-26 19:31:47 +03:00
C_DLLEXPORT int GetEntityAPI_Post(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion );
C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion );
2016-07-04 09:07:29 +03:00
// Additional SDK-like interface function prototypes.
2016-07-26 19:31:47 +03:00
C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion );
C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
2016-07-04 09:07:29 +03:00
// Convenience macros for accessing GameDLL functions. Note: these talk
// _directly_ to the gamedll, and are not multiplexed through Metamod to
// the other plugins.
// DLL API functions:
2016-07-26 19:31:47 +03:00
#define MDLL_FUNC gpGamedllFuncs->dllapi_table
#define MDLL_GameDLLInit MDLL_FUNC->pfnGameInit
#define MDLL_Spawn MDLL_FUNC->pfnSpawn
#define MDLL_Think MDLL_FUNC->pfnThink
#define MDLL_Use MDLL_FUNC->pfnUse
#define MDLL_Touch MDLL_FUNC->pfnTouch
#define MDLL_Blocked MDLL_FUNC->pfnBlocked
#define MDLL_KeyValue MDLL_FUNC->pfnKeyValue
#define MDLL_Save MDLL_FUNC->pfnSave
#define MDLL_Restore MDLL_FUNC->pfnRestore
2016-07-04 09:07:29 +03:00
#define MDLL_ObjectCollsionBox MDLL_FUNC->pfnAbsBox
#define MDLL_SaveWriteFields MDLL_FUNC->pfnSaveWriteFields
2016-07-26 19:31:47 +03:00
#define MDLL_SaveReadFields MDLL_FUNC->pfnSaveReadFields
2016-07-04 09:07:29 +03:00
#define MDLL_SaveGlobalState MDLL_FUNC->pfnSaveGlobalState
#define MDLL_RestoreGlobalState MDLL_FUNC->pfnRestoreGlobalState
#define MDLL_ResetGlobalState MDLL_FUNC->pfnResetGlobalState
2016-07-26 19:31:47 +03:00
#define MDLL_ClientConnect MDLL_FUNC->pfnClientConnect
2016-07-04 09:07:29 +03:00
#define MDLL_ClientDisconnect MDLL_FUNC->pfnClientDisconnect
2016-07-26 19:31:47 +03:00
#define MDLL_ClientKill MDLL_FUNC->pfnClientKill
2016-07-04 09:07:29 +03:00
#define MDLL_ClientPutInServer MDLL_FUNC->pfnClientPutInServer
2016-07-26 19:31:47 +03:00
#define MDLL_ClientCommand MDLL_FUNC->pfnClientCommand
2016-07-04 09:07:29 +03:00
#define MDLL_ClientUserInfoChanged MDLL_FUNC->pfnClientUserInfoChanged
2016-07-26 19:31:47 +03:00
#define MDLL_ServerActivate MDLL_FUNC->pfnServerActivate
2016-07-04 09:07:29 +03:00
#define MDLL_ServerDeactivate MDLL_FUNC->pfnServerDeactivate
2016-07-26 19:31:47 +03:00
#define MDLL_PlayerPreThink MDLL_FUNC->pfnPlayerPreThink
2016-07-04 09:07:29 +03:00
#define MDLL_PlayerPostThink MDLL_FUNC->pfnPlayerPostThink
2016-07-26 19:31:47 +03:00
#define MDLL_StartFrame MDLL_FUNC->pfnStartFrame
#define MDLL_ParmsNewLevel MDLL_FUNC->pfnParmsNewLevel
2016-07-04 09:07:29 +03:00
#define MDLL_ParmsChangeLevel MDLL_FUNC->pfnParmsChangeLevel
#define MDLL_GetGameDescription MDLL_FUNC->pfnGetGameDescription
#define MDLL_PlayerCustomization MDLL_FUNC->pfnPlayerCustomization
#define MDLL_SpectatorConnect MDLL_FUNC->pfnSpectatorConnect
#define MDLL_SpectatorDisconnect MDLL_FUNC->pfnSpectatorDisconnect
2016-07-26 19:31:47 +03:00
#define MDLL_SpectatorThink MDLL_FUNC->pfnSpectatorThink
#define MDLL_Sys_Error MDLL_FUNC->pfnSys_Error
#define MDLL_PM_Move MDLL_FUNC->pfnPM_Move
#define MDLL_PM_Init MDLL_FUNC->pfnPM_Init
2016-07-04 09:07:29 +03:00
#define MDLL_PM_FindTextureType MDLL_FUNC->pfnPM_FindTextureType
#define MDLL_SetupVisibility MDLL_FUNC->pfnSetupVisibility
#define MDLL_UpdateClientData MDLL_FUNC->pfnUpdateClientData
2016-07-26 19:31:47 +03:00
#define MDLL_AddToFullPack MDLL_FUNC->pfnAddToFullPack
#define MDLL_CreateBaseline MDLL_FUNC->pfnCreateBaseline
2016-07-04 09:07:29 +03:00
#define MDLL_RegisterEncoders MDLL_FUNC->pfnRegisterEncoders
2016-07-26 19:31:47 +03:00
#define MDLL_GetWeaponData MDLL_FUNC->pfnGetWeaponData
#define MDLL_CmdStart MDLL_FUNC->pfnCmdStart
#define MDLL_CmdEnd MDLL_FUNC->pfnCmdEnd
2016-07-04 09:07:29 +03:00
#define MDLL_ConnectionlessPacket MDLL_FUNC->pfnConnectionlessPacket
2016-07-26 19:31:47 +03:00
#define MDLL_GetHullBounds MDLL_FUNC->pfnGetHullBounds
#define MDLL_CreateInstancedBaselines MDLL_FUNC->pfnCreateInstancedBaselines
2016-07-04 09:07:29 +03:00
#define MDLL_InconsistentFile MDLL_FUNC->pfnInconsistentFile
#define MDLL_AllowLagCompensation MDLL_FUNC->pfnAllowLagCompensation
// NEW API functions:
2016-07-26 19:31:47 +03:00
#define MNEW_FUNC gpGamedllFuncs->newapi_table
2016-07-04 09:07:29 +03:00
#define MNEW_OnFreeEntPrivateData MNEW_FUNC->pfnOnFreeEntPrivateData
2016-07-26 19:31:47 +03:00
#define MNEW_GameShutdown MNEW_FUNC->pfnGameShutdown
#define MNEW_ShouldCollide MNEW_FUNC->pfnShouldCollide
#define MNEW_CvarValue MNEW_FUNC->pfnCvarValue