Fixed some small things

This commit is contained in:
David Anderson 2004-05-26 05:18:34 +00:00
parent 86fb009e43
commit e45e0c9634
3 changed files with 77 additions and 91 deletions

View File

@ -34,6 +34,9 @@
#include <string.h>
#include <new>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "amxxmodule.h"
/************* METAMOD SUPPORT *************/
@ -2469,6 +2472,12 @@ PFN_AMX_ALLOT g_fn_AmxAllot;
PFN_AMX_FINDPUBLIC g_fn_AmxFindPublic;
PFN_LOAD_AMXSCRIPT g_fn_LoadAmxScript;
PFN_UNLOAD_AMXSCRIPT g_fn_UnloadAmxScript;
PFN_REAL_TO_CELL g_fn_RealToCell;
PFN_CELL_TO_REAL g_fn_CellToReal;
PFN_REGISTER_SPFORWARD g_fn_RegisterSPForward;
PFN_REGISTER_SPFORWARD_BYNAME g_fn_RegisterSPForwardByName;
PFN_UNREGISTER_SPFORWARD g_fn_UnregisterSPForward;
// *** Exports ***
C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo)
{
@ -2536,6 +2545,9 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
REQFUNC("AddNatives", g_fn_AddNatives, PFN_ADD_NATIVES);
REQFUNC("RaiseAmxError", g_fn_RaiseAmxError, PFN_RAISE_AMXERROR);
REQFUNC("RegisterForward", g_fn_RegisterForward, PFN_REGISTER_FORWARD);
REQFUNC("RegisterSPForward", g_fn_RegisterSPForward, PFN_REGISTER_SPFORWARD);
REQFUNC("RegisterSPForwardByName", g_fn_RegisterSPForwardByName, PFN_REGISTER_SPFORWARD_BYNAME);
REQFUNC("UnregisterSPForward", g_fn_UnregisterSPForward, PFN_UNREGISTER_SPFORWARD);
REQFUNC("ExecuteForward", g_fn_ExecuteForward, PFN_EXECUTE_FORWARD);
REQFUNC("PrepareCellArray", g_fn_PrepareCellArray, PFN_PREPARE_CELLARRAY);
REQFUNC("PrepareCharArray", g_fn_PrepareCharArray, PFN_PREPARE_CHARARRAY);
@ -2566,6 +2578,9 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
REQFUNC_OPT("Reallocator", g_fn_Reallocator, PFN_REALLOCATOR);
REQFUNC_OPT("Deallocator", g_fn_Deallocator, PFN_DEALLOCATOR);
REQFUNC("CellToReal", g_fn_CellToReal, PFN_CELL_TO_REAL);
REQFUNC("RealToCell", g_fn_RealToCell, PFN_REAL_TO_CELL);
#ifdef FN_AMXX_ATTACH
FN_AMXX_ATTACH();
#endif // FN_AMXX_ATACH
@ -2593,8 +2608,6 @@ C_DLLEXPORT int AMXX_PluginsLoaded()
// Advanced MF functions
void MF_Log(const char *fmt, ...)
{
ASSERT(g_fn_Log);
// :TODO: Overflow possible here
char msg[3072];
va_list arglst;
@ -2609,7 +2622,7 @@ void MF_Log(const char *fmt, ...)
#ifdef _DEBUG
// validate macros
// Makes sure compiler reports errors when macros are invalid
void ValidateMacros()
void ValidateMacros_DontCallThis_Smiley()
{
MF_BuildPathname("str", "str", 0);
MF_FormatAmxString(NULL, 0, 0, NULL);
@ -2655,6 +2668,9 @@ void ValidateMacros()
MF_AmxAllot(0, 0, 0, 0);
MF_LoadAmxScript(0, 0, 0, 0);
MF_UnloadAmxScript(0, 0);
MF_RegisterSPForward(0, 0, 0, 0, 0, 0);
MF_RegisterSPForwardByName(0, 0, 0, 0, 0, 0);
MF_UnregisterSPForward(0);
}
#endif

View File

@ -106,21 +106,17 @@ struct amxx_module_info_s
#if defined BIT16
#define SMALL_CELL_SIZE 16 /* for backward compatibility */
#endif
#if !defined SMALL_CELL_SIZE
#define SMALL_CELL_SIZE 32 /* by default, use 32-bit cells */
#endif
#if SMALL_CELL_SIZE==16
typedef uint16_t ucell;
typedef int16_t cell;
#elif SMALL_CELL_SIZE==32
#if SMALL_CELL_SIZE==32
typedef uint32_t ucell;
typedef int32_t cell;
typedef float REAL;
#elif SMALL_CELL_SIZE==64
typedef uint64_t ucell;
typedef int64_t cell;
typedef double REAL;
#else
#error Unsupported cell size (SMALL_CELL_SIZE)
#endif
@ -244,32 +240,6 @@ enum {
AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
};
/* for native functions that use floating point parameters, the following
* two macros are convenient for casting a "cell" into a "float" type _without_
* changing the bit pattern
*/
#if SMALL_CELL_SIZE==32
inline cell amx_ftoc(float f)
{
return *(cell*)&f;
}
inline float amx_ctof(cell c)
{
return *(float*)&c;
}
#elif SMALL_CELL_SIZE==64
inline cell amx_ftoc(double f)
{
return *(cell*)&f;
}
inline double amx_ctof(cell c)
{
return *(double*)&c;
}
#else
#error Unsupported cell size
#endif
// ***** declare functions *****
@ -1979,6 +1949,11 @@ typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_ad
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/);
typedef int (*PFN_LOAD_AMXSCRIPT) (AMX* /*amx*/, void** /*code*/, const char* /*path*/, char[64] /*error info*/);
typedef int (*PFN_UNLOAD_AMXSCRIPT) (AMX* /*amx*/,void** /*code*/);
typedef cell (*PFN_REAL_TO_CELL) (REAL /*x*/);
typedef REAL (*PFN_CELL_TO_REAL) (cell /*x*/);
typedef int (*PFN_REGISTER_SPFORWARD) (AMX * /*amx*/, int /*func*/, ... /*params*/);
typedef int (*PFN_REGISTER_SPFORWARD_BYNAME) (AMX * /*amx*/, const char * /*funcName*/, ... /*params*/);
typedef void (*PFN_UNREGISTER_SPFORWARD) (int /*id*/);
extern PFN_ADD_NATIVES g_fn_AddNatives;
extern PFN_BUILD_PATHNAME g_fn_BuildPathname;
@ -2019,6 +1994,17 @@ extern PFN_IS_PLAYER_CONNECTING g_fn_IsPlayerConnecting;
extern PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
extern PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
extern PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
extern PFN_AMX_EXEC g_fn_AmxExec;
extern PFN_AMX_EXECV g_fn_AmxExecv;
extern PFN_AMX_ALLOT g_fn_AmxAllot;
extern PFN_AMX_FINDPUBLIC g_fn_AmxFindPublic;
extern PFN_LOAD_AMXSCRIPT g_fn_LoadAmxScript;
extern PFN_UNLOAD_AMXSCRIPT g_fn_UnloadAmxScript;
extern PFN_REAL_TO_CELL g_fn_RealToCell;
extern PFN_CELL_TO_REAL g_fn_CellToReal;
extern PFN_REGISTER_SPFORWARD g_fn_RegisterSPForward;
extern PFN_REGISTER_SPFORWARD_BYNAME g_fn_RegisterSPForwardByName;
extern PFN_UNREGISTER_SPFORWARD g_fn_UnregisterSPForward;
#ifdef MAY_NEVER_BE_DEFINED
// Function prototypes for intellisense and similar systems
@ -2062,6 +2048,11 @@ int MF_IsPlayerConnecting (int id) { }
int MF_IsPlayerHLTV (int id) { }
int MF_GetPlayerArmor (int id) { }
int MF_GetPlayerHealth (int id) { }
REAL amx_ctof (cell x) { }
cell amx_ftoc (float x) { }
int MF_RegisterSPForwardByName (AMX * amx, const char *str, ...) { }
int MF_RegisterSPForward (AMX * amx, int func, ...) { }
void MF_UnregisterSPForward (int id) { }
#endif // MAY_NEVER_BE_DEFINED
#define MF_AddNatives g_fn_AddNatives
@ -2109,6 +2100,11 @@ void MF_Log(const char *fmt, ...);
#define MF_AmxAllot g_fn_AmxAllot
#define MF_LoadAmxScript g_fn_LoadAmxScript
#define MF_UnloadAmxScript g_fn_UnloadAmxScript
#define amx_ctof g_fn_CellToReal
#define amx_ftoc g_fn_RealToCell
#define MF_RegisterSPForwardByName g_fn_RegisterSPForwardByName
#define MF_RegisterSPForward g_fn_RegisterSPForward
#define MF_UnregisterSPForward g_fn_UnregisterSPForward
/*** Memory ***/
void *operator new(size_t reportedSize);

View File

@ -74,7 +74,7 @@ static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) // cs_set_
// params[3] = flash money?
// Check index
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -107,7 +107,7 @@ static cell AMX_NATIVE_CALL cs_get_user_money(AMX *amx, cell *params) // cs_get_
// params[1] = user
// Check index
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -132,7 +132,7 @@ static cell AMX_NATIVE_CALL cs_get_user_deaths(AMX *amx, cell *params) // cs_get
// params[1] = user
// Check index
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -157,7 +157,7 @@ static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params) // cs_set
// params[2] = new deaths
// Check index
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -193,7 +193,7 @@ static cell AMX_NATIVE_CALL cs_get_hostage_id(AMX *amx, cell *params) // cs_get_
// params[1] = hostage entity index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -224,7 +224,7 @@ static cell AMX_NATIVE_CALL cs_get_weapon_silenced(AMX *amx, cell *params) // cs
// params[1] = weapon index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -261,7 +261,7 @@ static cell AMX_NATIVE_CALL cs_set_weapon_silenced(AMX *amx, cell *params) // cs
// params[2] = 1, and we silence the gun, 0 and we unsilence gun.
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -325,7 +325,7 @@ static cell AMX_NATIVE_CALL cs_get_weapon_burstmode(AMX *amx, cell *params) // c
// params[1] = weapon index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -362,7 +362,7 @@ static cell AMX_NATIVE_CALL cs_set_weapon_burstmode(AMX *amx, cell *params) // c
// params[2] = 1, and we set burstmode, 0 and we unset it.
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -432,7 +432,7 @@ static cell AMX_NATIVE_CALL cs_get_user_vip(AMX *amx, cell *params) // cs_get_us
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -460,7 +460,7 @@ static cell AMX_NATIVE_CALL cs_set_user_vip(AMX *amx, cell *params) // cs_set_us
// params[2] = if 1, activate vip, else deactivate vip.
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -522,7 +522,7 @@ static cell AMX_NATIVE_CALL cs_get_user_team(AMX *amx, cell *params) // cs_get_u
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -548,7 +548,7 @@ static cell AMX_NATIVE_CALL cs_set_user_team(AMX *amx, cell *params) // cs_set_u
// params[3] = model = 0
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -605,7 +605,7 @@ static cell AMX_NATIVE_CALL cs_get_user_inside_buyzone(AMX *amx, cell *params) /
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -629,7 +629,7 @@ static cell AMX_NATIVE_CALL cs_get_user_plant(AMX *amx, cell *params) // cs_get_
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -658,7 +658,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params) // cs_set_
// params[3] = show bomb icon?
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -714,7 +714,7 @@ static cell AMX_NATIVE_CALL cs_get_user_defusekit(AMX *amx, cell *params) // cs_
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -747,7 +747,7 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) // cs_
// params[7] = flash = 0
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -822,7 +822,7 @@ static cell AMX_NATIVE_CALL cs_get_user_backpackammo(AMX *amx, cell *params) //
// params[2] = weapon, as in CSW_*
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -914,7 +914,7 @@ static cell AMX_NATIVE_CALL cs_set_user_backpackammo(AMX *amx, cell *params) //
// params[3] = new amount
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1004,7 +1004,7 @@ static cell AMX_NATIVE_CALL cs_get_user_nvg(AMX *amx, cell *params) // cs_get_us
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1032,7 +1032,7 @@ static cell AMX_NATIVE_CALL cs_set_user_nvg(AMX *amx, cell *params) // cs_set_us
// params[2] = 1 = give, 0 = remove
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1073,7 +1073,7 @@ static cell AMX_NATIVE_CALL cs_get_user_model(AMX *amx, cell *params) // cs_get_
// params[3] = max length to set
// Valid player index should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1098,7 +1098,7 @@ static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params) // cs_set_
// params[2] = model
// Valid player index should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1137,7 +1137,7 @@ static cell AMX_NATIVE_CALL cs_reset_user_model(AMX *amx, cell *params) // cs_re
// params[1] = user index
// Valid player index should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients || !g_players[params[1]].GetOnline())
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1165,7 +1165,7 @@ static cell AMX_NATIVE_CALL cs_get_hostage_follow(AMX *amx, cell *params) // cs_
// params[1] = hostage index
// Valid index should be within range
if (params[1] < gpGlobals->maxClients + 1 || params[1] > gpGlobals->maxEntities) // highest player index on a 10 player server is 10 :-)!
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1209,7 +1209,7 @@ static cell AMX_NATIVE_CALL cs_set_hostage_follow(AMX *amx, cell *params) // cs_
// params[2] = index to follow, if -1 then set hostage to not follow anything
// Valid index should be within range
if (params[1] < gpGlobals->maxClients + 1 || params[1] > gpGlobals->maxEntities) // highest player index on a 10 player server is 10 :-)!
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1262,7 +1262,7 @@ static cell AMX_NATIVE_CALL cs_get_weapon_ammo(AMX *amx, cell *params) // cs_get
// params[1] = weapon index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1287,7 +1287,7 @@ static cell AMX_NATIVE_CALL cs_set_weapon_ammo(AMX *amx, cell *params) // cs_set
// params[2] = newammo
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxEntities)
if (!MF_IsPlayerIngame(params[1]))
{
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
@ -1359,7 +1359,6 @@ void MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
void ClientDisconnect(edict_t *pEntity) {
int index = ENTINDEX(pEntity);
g_players[index].SetModelled(false);
g_players[index].SetOnline(false);
RETURN_META(MRES_IGNORED);
}
@ -1387,31 +1386,6 @@ void PlayerPostThink(edict_t* pPlayer) {
RETURN_META(MRES_IGNORED);
}
/****GetEntityAPI2_Post**********************************************************/
void ClientUserInfoChanged_Post( edict_t *pEntity, char *infobuffer ) {
int index = ENTINDEX(pEntity);
// Only BOTs are set online here! Players must not, because then cs_user_* natives will crash in client_connect, possibly also other early forwards.
if (!g_players[index].GetOnline() && strcmp(GETPLAYERAUTHID(pEntity), "BOT") == 0) {
g_players[index].SetOnline(true);
//LOG_CONSOLE(PLID, "CSTRIKE MODULE: ClientUserInfoChanged_Post: %d was set to be online! (Auth: %s)", index, GETPLAYERAUTHID(pEntity));
}
RETURN_META(MRES_IGNORED);
}
void ClientPutInServer_Post( edict_t *pEntity ) {
int index = ENTINDEX(pEntity);
// At this place normal players will be set online. Bots (at least MM bots) don't normally ever get caught here so they can't be set online here.
// There might be other implementations of bots though that are caught by MM, so they will be set online here if they didn't already
// in ClientUserInfoChanged_Post above...
if (!g_players[index].GetOnline()) {
g_players[index].SetOnline(true);
//LOG_CONSOLE(PLID, "CSTRIKE MODULE: ClientPutInServer_Post: %d was set to be online! (Auth: %s)", index, GETPLAYERAUTHID(pEntity));
}
RETURN_META(MRES_IGNORED);
}
void OnAmxxAttach()
{
MF_AddNatives(cstrike_Exports);