amxmodx/amxmodx/amxmodx.h

370 lines
11 KiB
C
Raw Normal View History

2014-08-04 03:36:20 -05:00
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
2004-03-24 01:35:44 +00:00
#ifndef AMXMODX_H
#define AMXMODX_H
#if defined PLATFORM_POSIX
2004-10-29 20:35:44 +00:00
#include <unistd.h>
#include <stdlib.h>
2005-07-27 16:24:14 +00:00
#include "sclinux.h"
2004-10-29 20:35:44 +00:00
#endif
2005-09-16 23:48:51 +00:00
#include <ctype.h> //tolower, etc
#include "string.h"
#include <extdll.h>
#include <meta_api.h>
#ifdef _MSC_VER
// MSVC8 - replace POSIX functions with ISO C++ conformant ones as they are deprecated
#if _MSC_VER >= 1400
#define unlink _unlink
#define mkdir _mkdir
#define strdup _strdup
#endif
#endif
#include "hashing.h"
2004-03-24 01:35:44 +00:00
#include "modules.h"
#include "CPlugin.h"
#include "CLibrarySys.h"
#include <auto-string.h>
2015-09-30 19:08:39 +02:00
#include <amtl/am-string.h>
#include <amtl/am-vector.h>
#include <amtl/am-inlinelist.h>
2004-03-24 01:35:44 +00:00
#include "CMisc.h"
#include "CVault.h"
#include "CModule.h"
#include "CTask.h"
#include "CLogEvent.h"
#include "CForward.h"
#include "CCmd.h"
#include "CEvent.h"
2004-07-28 18:33:20 +00:00
#include "CLang.h"
2004-04-24 20:05:08 +00:00
#include "fakemeta.h"
2004-07-08 16:02:01 +00:00
#include "amxxlog.h"
#include "CvarManager.h"
2015-07-19 21:11:34 +02:00
#include "CoreConfig.h"
#include "CFrameAction.h"
2015-07-19 21:11:34 +02:00
#include <amxmodx_version.h>
#include <HLTypeConversion.h>
2004-03-24 01:35:44 +00:00
2004-07-08 16:02:01 +00:00
#define AMXXLOG_Log g_log.Log
#define AMXXLOG_Error g_log.LogError
2004-03-24 01:35:44 +00:00
2005-09-16 23:48:51 +00:00
extern AMX_NATIVE_INFO core_Natives[];
extern AMX_NATIVE_INFO time_Natives[];
extern AMX_NATIVE_INFO power_Natives[];
2005-09-11 03:58:38 +00:00
extern AMX_NATIVE_INFO amxmodx_Natives[];
extern AMX_NATIVE_INFO file_Natives[];
extern AMX_NATIVE_INFO float_Natives[];
extern AMX_NATIVE_INFO string_Natives[];
extern AMX_NATIVE_INFO vault_Natives[];
2006-05-17 20:23:36 +00:00
extern AMX_NATIVE_INFO msg_Natives[];
extern AMX_NATIVE_INFO vector_Natives[];
extern AMX_NATIVE_INFO g_SortNatives[];
extern AMX_NATIVE_INFO g_DataStructNatives[];
extern AMX_NATIVE_INFO g_StackNatives[];
2014-07-21 21:12:35 +02:00
extern AMX_NATIVE_INFO g_TextParserNatives[];
extern AMX_NATIVE_INFO g_CvarNatives[];
2015-06-24 17:45:12 +02:00
extern AMX_NATIVE_INFO g_GameConfigNatives[];
2004-03-24 01:35:44 +00:00
#if defined PLATFORM_WINDOWS
2004-03-31 18:04:22 +00:00
#define DLLOAD(path) (DLHANDLE)LoadLibrary(path)
2005-09-16 23:48:51 +00:00
#define DLPROC(m, func) GetProcAddress(m, func)
2004-03-31 18:04:22 +00:00
#define DLFREE(m) FreeLibrary(m)
2004-03-24 01:35:44 +00:00
#else
2004-03-31 18:04:22 +00:00
#define DLLOAD(path) (DLHANDLE)dlopen(path, RTLD_NOW)
2005-09-16 23:48:51 +00:00
#define DLPROC(m, func) dlsym(m, func)
2004-03-31 18:04:22 +00:00
#define DLFREE(m) dlclose(m)
2004-03-24 01:35:44 +00:00
#endif
#if defined __GNUC__
#include <stdint.h>
typedef intptr_t _INT_PTR;
#else
#if defined AMD64
typedef __int64 _INT_PTR;
#else
typedef __int32 _INT_PTR;
#endif
#endif
#if defined PLATFORM_WINDOWS
2005-09-16 23:48:51 +00:00
typedef HINSTANCE DLHANDLE;
2004-03-24 01:35:44 +00:00
#else
2005-09-16 23:48:51 +00:00
typedef void* DLHANDLE;
2005-11-13 22:34:32 +00:00
#define INFINITE 0xFFFFFFFF
2004-03-24 01:35:44 +00:00
#endif
#ifndef GETPLAYERAUTHID
#define GETPLAYERAUTHID (*g_engfuncs.pfnGetPlayerAuthId)
#endif
#define ANGLEVECTORS (*g_engfuncs.pfnAngleVectors)
#define CLIENT_PRINT (*g_engfuncs.pfnClientPrintf)
#define CVAR_DIRECTSET (*g_engfuncs.pfnCvar_DirectSet)
#define GETCLIENTLISTENING (*g_engfuncs.pfnVoice_GetClientListening)
#define RUNPLAYERMOVE (*g_engfuncs.pfnRunPlayerMove)
#define SETCLIENTLISTENING (*g_engfuncs.pfnVoice_SetClientListening)
#define SETCLIENTMAXSPEED (*g_engfuncs.pfnSetClientMaxspeed)
Improve UTF-8 support in some natives (bug 6475) (#407) * Compile as static library, update AMBuildScript and link to core * Update VS project files to include the library * Add UTF-8 Rewind library (v1.5.1) to third_party directory * Update ACKNOWLEDGEMENTS.txt * Move AMXX buffer in its own function * Move constants from string.inc to string_const.inc and update project files * Move stocks from string.inc to string_stocks.inc and update project files * Improve UTF-8 support in containi() and update documentation * Improve UTF-8 support in strcmp() and update documentation * Improve UTF-8 support in strfind() and update documentation Worth to be noted that this native with ignorecase set was not working properly. So broken that no one reported the issue. This adds also a safety check for "pos" parameter to not go < 0. * Improve UTF-8 support in strncmp() and update documentation * Improve UTF-8 support in equali() and update documentation * Add an option to some UTF-8 Rewind functions for avoiding invalid data to be replaced By default it replaces any invalid byte or sequence of bytes by 0xFFFD (3 bytes). It can be problematic when the input buffer is not changed (from a plugin) and that some natives need to calculate a position from the converted string. With such replacement, the position is displaced due the final string length being larger. This compiles the library as C++, because I added some silly param with a default default value which is not supported by C. * Improve UTF-8 support in replace_string/ex() and update documentation * Add is_string_category() and update documentation * Update a little testsuite plugin (and fix linux compilation) * Add mb_strotolower/upper() and update documentation * Add mb_ucfirst() and update documentation * Add mb_strtotile() and update documentation * Improve UTF-8 support in get_players() and find_player() with name/case insenstive flags set * Fix KliPPy's complain
2017-08-05 10:32:16 +02:00
#define MAX_BUFFER_LENGTH 16384
2004-03-24 01:35:44 +00:00
char* UTIL_SplitHudMessage(register const char *src);
int UTIL_ReadFlags(const char* c);
2005-09-16 23:48:51 +00:00
void UTIL_ClientPrint(edict_t *pEntity, int msg_dest, char *msg);
void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1 = NULL, const char *arg2 = NULL, bool fwd = false);
2005-09-16 23:48:51 +00:00
void UTIL_GetFlags(char* flags, int flag);
void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage);
void UTIL_DHudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage, unsigned int length);
2004-03-24 01:35:44 +00:00
void UTIL_IntToString(int value, char *output);
2005-09-16 23:48:51 +00:00
void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name);
void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen);
void UTIL_ClientSayText(edict_t *pEntity, int sender, char *msg);
void UTIL_TeamInfo(edict_t *pEntity, int playerIndex, const char *pszTeamName);
2005-09-16 23:48:51 +00:00
template <typename D> int UTIL_CheckValidChar(D *c);
template <typename D, typename S> unsigned int strncopy(D *dest, const S *src, size_t count);
unsigned int UTIL_GetUTF8CharBytes(const char *stream);
Improve UTF-8 support in some natives (bug 6475) (#407) * Compile as static library, update AMBuildScript and link to core * Update VS project files to include the library * Add UTF-8 Rewind library (v1.5.1) to third_party directory * Update ACKNOWLEDGEMENTS.txt * Move AMXX buffer in its own function * Move constants from string.inc to string_const.inc and update project files * Move stocks from string.inc to string_stocks.inc and update project files * Improve UTF-8 support in containi() and update documentation * Improve UTF-8 support in strcmp() and update documentation * Improve UTF-8 support in strfind() and update documentation Worth to be noted that this native with ignorecase set was not working properly. So broken that no one reported the issue. This adds also a safety check for "pos" parameter to not go < 0. * Improve UTF-8 support in strncmp() and update documentation * Improve UTF-8 support in equali() and update documentation * Add an option to some UTF-8 Rewind functions for avoiding invalid data to be replaced By default it replaces any invalid byte or sequence of bytes by 0xFFFD (3 bytes). It can be problematic when the input buffer is not changed (from a plugin) and that some natives need to calculate a position from the converted string. With such replacement, the position is displaced due the final string length being larger. This compiles the library as C++, because I added some silly param with a default default value which is not supported by C. * Improve UTF-8 support in replace_string/ex() and update documentation * Add is_string_category() and update documentation * Update a little testsuite plugin (and fix linux compilation) * Add mb_strotolower/upper() and update documentation * Add mb_ucfirst() and update documentation * Add mb_strtotile() and update documentation * Improve UTF-8 support in get_players() and find_player() with name/case insenstive flags set * Fix KliPPy's complain
2017-08-05 10:32:16 +02:00
size_t UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive);
size_t UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive);
char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive);
void UTIL_TrimLeft(char *buffer);
void UTIL_TrimRight(char *buffer);
2004-03-24 18:33:41 +00:00
Improve UTF-8 support in some natives (bug 6475) (#407) * Compile as static library, update AMBuildScript and link to core * Update VS project files to include the library * Add UTF-8 Rewind library (v1.5.1) to third_party directory * Update ACKNOWLEDGEMENTS.txt * Move AMXX buffer in its own function * Move constants from string.inc to string_const.inc and update project files * Move stocks from string.inc to string_stocks.inc and update project files * Improve UTF-8 support in containi() and update documentation * Improve UTF-8 support in strcmp() and update documentation * Improve UTF-8 support in strfind() and update documentation Worth to be noted that this native with ignorecase set was not working properly. So broken that no one reported the issue. This adds also a safety check for "pos" parameter to not go < 0. * Improve UTF-8 support in strncmp() and update documentation * Improve UTF-8 support in equali() and update documentation * Add an option to some UTF-8 Rewind functions for avoiding invalid data to be replaced By default it replaces any invalid byte or sequence of bytes by 0xFFFD (3 bytes). It can be problematic when the input buffer is not changed (from a plugin) and that some natives need to calculate a position from the converted string. With such replacement, the position is displaced due the final string length being larger. This compiles the library as C++, because I added some silly param with a default default value which is not supported by C. * Improve UTF-8 support in replace_string/ex() and update documentation * Add is_string_category() and update documentation * Update a little testsuite plugin (and fix linux compilation) * Add mb_strotolower/upper() and update documentation * Add mb_ucfirst() and update documentation * Add mb_strtotile() and update documentation * Improve UTF-8 support in get_players() and find_player() with name/case insenstive flags set * Fix KliPPy's complain
2017-08-05 10:32:16 +02:00
char* utf8stristr(const char *string1, const char *string2);
int utf8strncasecmp(const char *string1, const char *string2, size_t n);
int utf8strcasecmp(const char *string1, const char *string2);
2004-03-24 01:35:44 +00:00
#define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)])
2005-09-16 23:48:51 +00:00
//#define GET_PLAYER_POINTER(e) (&g_players[(((int)e-g_edict_point)/sizeof(edict_t))])
2004-03-24 01:35:44 +00:00
#define GET_PLAYER_POINTER_I(i) (&g_players[i])
2005-09-16 23:48:51 +00:00
struct WeaponsVault
{
ke::AString fullName;
2005-09-16 23:48:51 +00:00
short int iId;
short int ammoSlot;
2004-03-24 01:35:44 +00:00
};
2005-09-16 23:48:51 +00:00
struct fakecmd_t
{
char args[256];
const char *argv[3];
int argc;
bool fake;
bool notify; // notify to plugins.
2004-03-24 01:35:44 +00:00
};
2004-07-08 16:02:01 +00:00
extern CLog g_log;
2004-03-24 01:35:44 +00:00
extern CPluginMngr g_plugins;
extern CTaskMngr g_tasksMngr;
extern CFrameActionMngr g_frameActionMngr;
2004-03-24 01:35:44 +00:00
extern CPlayer g_players[33];
extern CPlayer* mPlayer;
extern CmdMngr g_commands;
extern ke::Vector<ke::AutoPtr<ForceObject>> g_forcemodels;
extern ke::Vector<ke::AutoPtr<ForceObject>> g_forcesounds;
extern ke::Vector<ke::AutoPtr<ForceObject>> g_forcegeneric;
extern ke::Vector<ke::AutoPtr<CPlayer *>> g_auth;
extern ke::InlineList<CModule> g_modules;
extern ke::InlineList<CScript> g_loadedscripts;
2004-03-24 01:35:44 +00:00
extern EventsMngr g_events;
extern Grenades g_grenades;
extern LogEventsMngr g_logevents;
2004-07-28 18:33:20 +00:00
extern CLangMngr g_langMngr;
extern ke::AString g_log_dir;
extern ke::AString g_mod_name;
2004-03-24 01:35:44 +00:00
extern TeamIds g_teamsIds;
extern Vault g_vault;
2005-09-16 23:48:51 +00:00
extern CForwardMngr g_forwards;
2004-03-24 01:35:44 +00:00
extern WeaponsVault g_weaponsData[MAX_WEAPONS];
extern XVars g_xvars;
extern bool g_bmod_cstrike;
extern bool g_bmod_dod;
extern bool g_dontprecache;
extern int g_srvindex;
extern cvar_t* amxmodx_version;
2014-07-27 11:52:30 +03:00
extern cvar_t* amxmodx_language;
2004-03-24 01:35:44 +00:00
extern cvar_t* hostname;
extern cvar_t* mp_timelimit;
extern fakecmd_t g_fakecmd;
extern float g_game_restarting;
extern float g_game_timeleft;
extern float g_task_time;
extern float g_auth_time;
2005-08-27 23:00:44 +00:00
extern bool g_NewDLL_Available;
2004-03-24 01:35:44 +00:00
extern hudtextparms_t g_hudset;
//extern int g_edict_point;
extern int g_players_num;
extern int mPlayerIndex;
extern int mState;
extern void (*endfunction)(void*);
extern void (*function)(void*);
typedef void (*funEventCall)(void*);
extern funEventCall modMsgsEnd[MAX_REG_MSGS];
extern funEventCall modMsgs[MAX_REG_MSGS];
extern int gmsgAmmoPickup;
extern int gmsgAmmoX;
extern int gmsgBattery;
extern int gmsgCurWeapon;
extern int gmsgDamage;
extern int gmsgDeathMsg;
extern int gmsgHealth;
extern int gmsgMOTD;
extern int gmsgScoreInfo;
extern int gmsgSendAudio;
extern int gmsgServerName;
extern int gmsgShowMenu;
extern int gmsgTeamInfo;
extern int gmsgTextMsg;
extern int gmsgVGUIMenu;
extern int gmsgWeapPickup;
extern int gmsgWeaponList;
extern int gmsgintermission;
extern int gmsgResetHUD;
extern int gmsgRoundTime;
extern int gmsgSayText;
extern int gmsgInitHUD;
2004-03-24 01:35:44 +00:00
void Client_AmmoPickup(void*);
void Client_AmmoX(void*);
void Client_CurWeapon(void*);
void Client_ScoreInfo(void*);
void Client_ShowMenu(void*);
void Client_TeamInfo(void*);
void Client_TextMsg(void*);
void Client_VGUIMenu(void*);
void Client_WeaponList(void*);
void Client_DamageEnd(void*);
void Client_DeathMsg(void*);
void Client_InitHUDEnd(void*);
2004-03-24 01:35:44 +00:00
void amx_command();
void plugin_srvcmd();
2005-09-16 23:48:51 +00:00
const char* stristr(const char* a, const char* b);
2004-03-24 01:35:44 +00:00
char *strptime(const char *buf, const char *fmt, struct tm *tm, short addthem);
int loadModules(const char* filename, PLUG_LOADTIME now);
void detachModules();
void detachReloadModules();
2005-09-16 23:48:51 +00:00
// Count modules
enum CountModulesMode
{
CountModules_Running = 0,
CountModules_All,
CountModules_Stopped
};
int countModules(CountModulesMode mode);
2004-04-03 19:21:07 +00:00
void modules_callPluginsLoaded();
void modules_callPluginsUnloaded();
void modules_callPluginsUnloading();
2005-09-16 23:48:51 +00:00
cell* get_amxaddr(AMX *amx, cell amx_addr);
char* build_pathname(const char *fmt, ...);
char* build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...);
2005-09-16 23:48:51 +00:00
char* format_amxstring(AMX *amx, cell *params, int parm, int& len);
AMX* get_amxscript(int, void**, const char**);
2004-03-24 01:35:44 +00:00
const char* get_amxscriptname(AMX* amx);
2005-09-16 23:48:51 +00:00
char* get_amxstring(AMX *amx, cell amx_addr, int id, int& len);
2015-05-06 11:28:54 +02:00
char* get_amxstring_null(AMX *amx, cell amx_addr, int id, int& len);
cell* get_amxvector_null(AMX *amx, cell amx_addr);
2006-02-14 12:01:22 +00:00
extern "C" size_t get_amxstring_r(AMX *amx, cell amx_addr, char *destination, int maxlen);
2005-09-16 23:48:51 +00:00
2004-03-24 01:35:44 +00:00
int amxstring_len(cell* cstr);
2004-09-08 07:05:16 +00:00
int load_amxscript(AMX* amx, void** program, const char* path, char error[64], int debug);
int load_amxscript_ex(AMX* amx, void** program, const char* path, char *error, size_t maxLength, int debug);
2005-09-16 23:48:51 +00:00
int set_amxnatives(AMX* amx, char error[64]);
int set_amxstring(AMX *amx, cell amx_addr, const char *source, int max);
2015-01-24 21:28:43 +01:00
int set_amxstring_simple(cell *dest, const char *source, int max);
2014-07-25 00:25:31 +02:00
template <typename T> int set_amxstring_utf8(AMX *amx, cell amx_addr, const T *source, size_t sourcelen, size_t maxlen);
int set_amxstring_utf8_char(AMX *amx, cell amx_addr, const char *source, size_t sourcelen, size_t maxlen);
int set_amxstring_utf8_cell(AMX *amx, cell amx_addr, const cell *source, size_t sourcelen, size_t maxlen);
2005-09-16 23:48:51 +00:00
int unload_amxscript(AMX* amx, void** program);
void copy_amxmemory(cell* dest, cell* src, int len);
2004-03-24 01:35:44 +00:00
void get_modname(char*);
void print_srvconsole(const char *fmt, ...);
void report_error(int code, const char* fmt, ...);
2004-03-24 18:59:37 +00:00
// get_localinfo
2005-09-16 23:48:51 +00:00
const char* get_localinfo(const char* name, const char* def);
2006-02-14 12:01:22 +00:00
extern "C" void LogError(AMX *amx, int err, const char *fmt, ...);
2004-03-24 01:35:44 +00:00
2004-04-03 19:21:07 +00:00
enum ModuleCallReason
{
2005-09-16 23:48:51 +00:00
ModuleCall_NotCalled = 0, // nothing
ModuleCall_Query, // in Query func
ModuleCall_Attach, // in Attach func
ModuleCall_Detach, // in Detach func
2004-04-03 19:21:07 +00:00
};
extern ModuleCallReason g_ModuleCallReason; // modules.cpp
extern CModule *g_CurrentlyCalledModule; // modules.cpp
2004-03-31 18:04:22 +00:00
extern const char *g_LastRequestedFunc; // modules.cpp
2005-09-16 23:48:51 +00:00
void Module_CacheFunctions();
void Module_UncacheFunctions();
2004-03-31 18:04:22 +00:00
void *Module_ReqFnptr(const char *funcName); // modules.cpp
2004-04-03 19:21:07 +00:00
// standard forwards
// defined in meta_api.cpp
extern int FF_ClientCommand;
extern int FF_ClientConnect;
extern int FF_ClientDisconnect;
extern int FF_ClientInfoChanged;
extern int FF_ClientPutInServer;
extern int FF_PluginInit;
extern int FF_PluginCfg;
extern int FF_PluginPrecache;
extern int FF_PluginLog;
extern int FF_PluginEnd;
extern int FF_InconsistentFile;
2004-04-24 20:05:08 +00:00
extern int FF_ClientAuthorized;
extern int FF_ChangeLevel;
extern int FF_ClientConnectEx;
extern bool g_coloredmenus;
2004-04-03 19:21:07 +00:00
typedef void (*AUTHORIZEFUNC)(int player, const char *authstring);
#define MM_CVAR2_VERS 13
struct func_s
{
void *pfn;
const char *desc;
};
enum AdminProperty
{
Admin_Auth = 0,
Admin_Password,
Admin_Access,
Admin_Flags
};
enum PrintColor
{
print_team_default = 0,
print_team_grey =-1,
print_team_red = -2,
print_team_blue = -3,
};
extern enginefuncs_t *g_pEngTable;
extern HLTypeConversion TypeConversion;
2004-03-24 01:35:44 +00:00
#endif // AMXMODX_H