From 601bb30b7ecd29a005dfb5ce3e430614284a53ad Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 3 Oct 2004 21:54:27 +0000 Subject: [PATCH] Added debugging engine --- dlls/tfc/tfcx/NBase.cpp | 56 +++++++++------------------- dlls/tfc/tfcx/NRank.cpp | 72 +++++++++--------------------------- dlls/tfc/tfcx/amxxmodule.cpp | 30 ++++++++++++++- dlls/tfc/tfcx/amxxmodule.h | 24 ++++++++++-- dlls/tfc/tfcx/tfcx.h | 36 ++++++++++++++++++ 5 files changed, 120 insertions(+), 98 deletions(-) diff --git a/dlls/tfc/tfcx/NBase.cpp b/dlls/tfc/tfcx/NBase.cpp index e10995c4..a67c01b5 100755 --- a/dlls/tfc/tfcx/NBase.cpp +++ b/dlls/tfc/tfcx/NBase.cpp @@ -38,10 +38,7 @@ static cell AMX_NATIVE_CALL TFC_SetModel(AMX *amx, cell *params) { int iIndex = params[1]; // Make sure its a player. - if (iIndex < 1 || iIndex > gpGlobals->maxClients) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(iIndex); int iLen; @@ -78,10 +75,7 @@ static cell AMX_NATIVE_CALL TFC_SetModel(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_ClearModel(AMX *amx, cell *params) { int iIndex = params[1]; - if (iIndex < 1 || iIndex > gpGlobals->maxClients) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(iIndex) edict_t* pPlayer = INDEXENT(iIndex); @@ -148,14 +142,11 @@ static cell AMX_NATIVE_CALL TFC_ClearModel(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_SetBAmmo(AMX *amx, cell *params) { int iIndex = params[1]; - if (iIndex < 1 || iIndex > gpGlobals->maxClients) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(iIndex); int iValue = params[3]; if (iValue < 0 ) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid ammo amount %d", iValue); return 0; } @@ -190,10 +181,7 @@ static cell AMX_NATIVE_CALL TFC_SetBAmmo(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_GetBAmmo(AMX *amx, cell *params) { int iIndex = params[1]; - if (iIndex < 1 || iIndex > gpGlobals->maxClients) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(iIndex); CPlayer* pPlayer = GET_PLAYER_POINTER_I(iIndex); @@ -226,10 +214,7 @@ static cell AMX_NATIVE_CALL TFC_GetBAmmo(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_GetWeaponBAmmo(AMX *amx, cell *params) { int iIndex = params[1]; - if (iIndex < 1 || iIndex > gpGlobals->maxClients) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(iIndex); CPlayer* pPlayer = GET_PLAYER_POINTER_I(iIndex); @@ -281,15 +266,12 @@ static cell AMX_NATIVE_CALL TFC_GetWeaponBAmmo(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_SetWeaponBAmmo(AMX *amx, cell *params) { int iIndex = params[1]; - if (iIndex < 1 || iIndex > gpGlobals->maxClients) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(iIndex); int iValue = params[3]; if (iValue < 0 ) { - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid ammo amount %d", iValue); return 0; } @@ -341,7 +323,7 @@ static cell AMX_NATIVE_CALL TFC_SetWeaponBAmmo(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_GetWpnName(AMX *amx, cell *params) { int iIndex = params[1]; if ( iIndex < 1 || iIndex > TFCMAX_WEAPONS ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", iIndex); return 0; } return MF_SetAmxString(amx,params[2],weaponData[iIndex].name,params[3]); @@ -350,7 +332,7 @@ static cell AMX_NATIVE_CALL TFC_GetWpnName(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_GetWpnLogName(AMX *amx, cell *params) { int iIndex = params[1]; if ( iIndex < 1 || iIndex > TFCMAX_WEAPONS ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", iIndex); return 0; } return MF_SetAmxString(amx,params[2],weaponData[iIndex].logName,params[3]); @@ -375,7 +357,7 @@ static cell AMX_NATIVE_CALL TFC_SetPDdata(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL TFC_IsMelee(AMX *amx, cell *params){ // player,wid int weapon = params[1]; if ( weapon < 1 || weapon >= TFCMAX_WEAPONS ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", weapon); return 0; } return weaponData[weapon].melee; @@ -383,10 +365,7 @@ static cell AMX_NATIVE_CALL TFC_IsMelee(AMX *amx, cell *params){ // player,wid static cell AMX_NATIVE_CALL TFC_UserKill(AMX *amx, cell *params){ // player,wid int index = params[1]; - if ( index < 1 || index >gpGlobals->maxClients ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); pPlayer->killPlayer(); @@ -395,23 +374,24 @@ static cell AMX_NATIVE_CALL TFC_UserKill(AMX *amx, cell *params){ // player,wid static cell AMX_NATIVE_CALL register_forward(AMX *amx, cell *params){ // forward int iFunctionIndex; + int err; switch( params[1] ){ case 0: - if( MF_AmxFindPublic(amx, "client_damage", &iFunctionIndex) == AMX_ERR_NONE ) + if( (err=MF_AmxFindPublic(amx, "client_damage", &iFunctionIndex)) == AMX_ERR_NONE ) g_damage_info.put( amx , iFunctionIndex ); else - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, err, "Error finding function \"client_damage\""); return 0; break; case 1: - if( MF_AmxFindPublic(amx, "client_death", &iFunctionIndex) == AMX_ERR_NONE ) + if( (err=MF_AmxFindPublic(amx, "client_death", &iFunctionIndex)) == AMX_ERR_NONE ) g_death_info.put( amx , iFunctionIndex ); else - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, err, "Error finding function \"client_death\""); return 0; break; default: - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid forward id %d", params[1]); return 0; } return 1; diff --git a/dlls/tfc/tfcx/NRank.cpp b/dlls/tfc/tfcx/NRank.cpp index 7982b558..9f070696 100755 --- a/dlls/tfc/tfcx/NRank.cpp +++ b/dlls/tfc/tfcx/NRank.cpp @@ -36,15 +36,9 @@ static cell AMX_NATIVE_CALL get_user_astats(AMX *amx, cell *params) /* 6 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); int attacker = params[2]; - if (attacker<0||attacker>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(attacker); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->attackers[attacker].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); @@ -69,15 +63,9 @@ static cell AMX_NATIVE_CALL get_user_astats(AMX *amx, cell *params) /* 6 param * static cell AMX_NATIVE_CALL get_user_vstats(AMX *amx, cell *params) /* 6 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); int victim = params[2]; - if (victim<0||victim>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(victim); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->victims[victim].hits){ cell *cpStats = MF_GetAmxAddr(amx,params[3]); @@ -102,13 +90,10 @@ static cell AMX_NATIVE_CALL get_user_vstats(AMX *amx, cell *params) /* 6 param * static cell AMX_NATIVE_CALL get_user_wrstats(AMX *amx, cell *params) /* 4 param */ // DEC-Weapon (round) stats (end) { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); int weapon = params[2]; if (weapon<0||weapon>=TFCMAX_WEAPONS){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", weapon); return 0; } CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); @@ -133,13 +118,10 @@ static cell AMX_NATIVE_CALL get_user_wrstats(AMX *amx, cell *params) /* 4 param static cell AMX_NATIVE_CALL get_user_wstats(AMX *amx, cell *params) /* 4 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); int weapon = params[2]; if (weapon<0||weapon>=TFCMAX_WEAPONS){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", weapon); return 0; } CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); @@ -164,10 +146,7 @@ static cell AMX_NATIVE_CALL get_user_wstats(AMX *amx, cell *params) /* 4 param * static cell AMX_NATIVE_CALL reset_user_wstats(AMX *amx, cell *params) /* 6 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); GET_PLAYER_POINTER_I(index)->restartStats(); return 1; } @@ -175,10 +154,7 @@ static cell AMX_NATIVE_CALL reset_user_wstats(AMX *amx, cell *params) /* 6 param static cell AMX_NATIVE_CALL get_user_stats(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if ( pPlayer->rank ){ cell *cpStats = MF_GetAmxAddr(amx,params[2]); @@ -202,10 +178,7 @@ static cell AMX_NATIVE_CALL get_user_stats(AMX *amx, cell *params) /* 3 param */ static cell AMX_NATIVE_CALL get_user_rstats(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->rank){ cell *cpStats = MF_GetAmxAddr(amx,params[2]); @@ -282,31 +255,25 @@ static cell AMX_NATIVE_CALL register_cwpn(AMX *amx, cell *params){ // name,logna static cell AMX_NATIVE_CALL cwpn_dmg(AMX *amx, cell *params){ // wid,att,vic,dmg,hp=0 int weapon = params[1]; if ( weapon < TFCMAX_WEAPONS-TFCMAX_CUSTOMWPNS ){ // only for custom weapons - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid custom weapon id %d", weapon); return 0; } int att = params[2]; - if (att<1||att>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(att); int vic = params[3]; - if (vic<1||vic>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(vic); int dmg = params[4]; if ( dmg<1 ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid damage amount %d", dmg); return 0; } int aim = params[5]; if ( aim < 0 || aim > 7 ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid aim %d", aim); return 0; } @@ -333,14 +300,11 @@ static cell AMX_NATIVE_CALL cwpn_dmg(AMX *amx, cell *params){ // wid,att,vic,dmg static cell AMX_NATIVE_CALL cwpn_shot(AMX *amx, cell *params){ // player,wid int index = params[2]; - if (index<1||index>gpGlobals->maxClients){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); - return 0; - } + CHECK_PLAYER(index); int weapon = params[1]; if ( weapon < TFCMAX_WEAPONS-TFCMAX_CUSTOMWPNS ){ - MF_RaiseAmxError(amx,AMX_ERR_NATIVE); + MF_LogError(amx,AMX_ERR_NATIVE, "Invalid custom weapon id %d", weapon); return 0; } diff --git a/dlls/tfc/tfcx/amxxmodule.cpp b/dlls/tfc/tfcx/amxxmodule.cpp index 88a48c5a..e22a1187 100755 --- a/dlls/tfc/tfcx/amxxmodule.cpp +++ b/dlls/tfc/tfcx/amxxmodule.cpp @@ -45,6 +45,16 @@ enginefuncs_t g_engfuncs; globalvars_t *gpGlobals; + + +DLL_FUNCTIONS *g_pFunctionTable; +DLL_FUNCTIONS *g_pFunctionTable_Post; +enginefuncs_t *g_pengfuncsTable; +enginefuncs_t *g_pengfuncsTable_Post; +NEW_DLL_FUNCTIONS *g_pNewFunctionsTable; +NEW_DLL_FUNCTIONS *g_pNewFunctionsTable_Post; + + // GetEntityAPI2 functions static DLL_FUNCTIONS g_EntityAPI_Table = { @@ -2114,6 +2124,7 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi return(FALSE); } memcpy(pFunctionTable, &g_EntityAPI_Table, sizeof(DLL_FUNCTIONS)); + g_pFunctionTable=pFunctionTable; return(TRUE); } @@ -2131,7 +2142,7 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interface return(FALSE); } memcpy( pFunctionTable, &g_EntityAPI_Post_Table, sizeof( DLL_FUNCTIONS ) ); - + g_pFunctionTable_Post=pFunctionTable; return(TRUE); } @@ -2154,6 +2165,7 @@ C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *inte return(FALSE); } memcpy(pengfuncsFromEngine, &g_EngineFuncs_Table, sizeof(enginefuncs_t)); + g_pengfuncsTable=pengfuncsFromEngine; return TRUE; } @@ -2171,6 +2183,7 @@ C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int return(FALSE); } memcpy(pengfuncsFromEngine, &g_EngineFuncs_Post_Table, sizeof(enginefuncs_t)); + g_pengfuncsTable_Post=pengfuncsFromEngine; return TRUE; } @@ -2195,6 +2208,7 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, return(FALSE); } memcpy(pNewFunctionTable, &g_NewFuncs_Table, sizeof(NEW_DLL_FUNCTIONS)); + g_pNewFunctionsTable=pNewFunctionTable; return TRUE; } @@ -2212,6 +2226,7 @@ C_DLLEXPORT int GetNewDLLFunctions_Post( NEW_DLL_FUNCTIONS *pNewFunctionTable, i return(FALSE); } memcpy(pNewFunctionTable, &g_NewFuncs_Post_Table, sizeof(NEW_DLL_FUNCTIONS)); + g_pNewFunctionsTable_Post=pNewFunctionTable; return TRUE; } @@ -2439,11 +2454,14 @@ PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; PFN_LOG g_fn_Log; +PFN_LOG_ERROR g_fn_LogError; PFN_RAISE_AMXERROR g_fn_RaiseAmxError; PFN_REGISTER_FORWARD g_fn_RegisterForward; PFN_EXECUTE_FORWARD g_fn_ExecuteForward; PFN_PREPARE_CELLARRAY g_fn_PrepareCellArray; PFN_PREPARE_CHARARRAY g_fn_PrepareCharArray; +PFN_PREPARE_CELLARRAY_A g_fn_PrepareCellArrayA; +PFN_PREPARE_CHARARRAY_A g_fn_PrepareCharArrayA; PFN_IS_PLAYER_VALID g_fn_IsPlayerValid; PFN_GET_PLAYER_NAME g_fn_GetPlayerName; PFN_GET_PLAYER_IP g_fn_GetPlayerIP; @@ -2453,6 +2471,7 @@ PFN_IS_PLAYER_AUTHORIZED g_fn_IsPlayerAuthorized; PFN_GET_PLAYER_TIME g_fn_GetPlayerTime; PFN_GET_PLAYER_PLAYTIME g_fn_GetPlayerPlayTime; PFN_GET_PLAYER_CURWEAPON g_fn_GetPlayerCurweapon; +PFN_GET_PLAYER_TEAM g_fn_GetPlayerTeam; PFN_GET_PLAYER_TEAMID g_fn_GetPlayerTeamID; PFN_GET_PLAYER_DEATHS g_fn_GetPlayerDeaths; PFN_GET_PLAYER_MENU g_fn_GetPlayerMenu; @@ -2525,6 +2544,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("PrintSrvConsole", g_fn_PrintSrvConsole, PFN_PRINT_SRVCONSOLE); REQFUNC("GetModname", g_fn_GetModname, PFN_GET_MODNAME); REQFUNC("Log", g_fn_Log, PFN_LOG); + REQFUNC("LogError", g_fn_LogError, PFN_LOG_ERROR); REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); @@ -2560,7 +2580,8 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("ExecuteForward", g_fn_ExecuteForward, PFN_EXECUTE_FORWARD); REQFUNC("PrepareCellArray", g_fn_PrepareCellArray, PFN_PREPARE_CELLARRAY); REQFUNC("PrepareCharArray", g_fn_PrepareCharArray, PFN_PREPARE_CHARARRAY); - + REQFUNC("PrepareCellArrayA", g_fn_PrepareCellArrayA, PFN_PREPARE_CELLARRAY_A); + REQFUNC("PrepareCharArrayA", g_fn_PrepareCharArrayA, PFN_PREPARE_CHARARRAY_A); // Player REQFUNC("IsPlayerValid", g_fn_IsPlayerValid, PFN_IS_PLAYER_VALID); REQFUNC("GetPlayerName", g_fn_GetPlayerName, PFN_GET_PLAYER_NAME); @@ -2572,6 +2593,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("GetPlayerPlayTime", g_fn_GetPlayerPlayTime, PFN_GET_PLAYER_PLAYTIME); REQFUNC("GetPlayerCurweapon", g_fn_GetPlayerCurweapon, PFN_GET_PLAYER_CURWEAPON); REQFUNC("GetPlayerTeamID", g_fn_GetPlayerTeamID, PFN_GET_PLAYER_TEAMID); + REQFUNC("GetPlayerTeam",g_fn_GetPlayerTeam, PFN_GET_PLAYER_TEAM); REQFUNC("GetPlayerDeaths", g_fn_GetPlayerDeaths, PFN_GET_PLAYER_DEATHS); REQFUNC("GetPlayerMenu", g_fn_GetPlayerMenu, PFN_GET_PLAYER_MENU); REQFUNC("GetPlayerKeys", g_fn_GetPlayerKeys, PFN_GET_PLAYER_KEYS); @@ -2649,11 +2671,14 @@ void ValidateMacros_DontCallThis_Smiley() MF_GetAmxStringLen(NULL); MF_CopyAmxMemory(NULL, NULL, 0); MF_Log("str", "str", 0); + MF_LogError(NULL, 0, NULL); MF_RaiseAmxError(NULL, 0); MF_RegisterForward("str", (ForwardExecType)0, 0, 0, 0); MF_ExecuteForward(0, 0, 0); MF_PrepareCellArray(NULL, 0); MF_PrepareCharArray(NULL, 0); + MF_PrepareCellArrayA(NULL, 0, true); + MF_PrepareCharArrayA(NULL, 0, true); MF_IsPlayerValid(0); MF_GetPlayerName(0); MF_GetPlayerIP(0); @@ -2664,6 +2689,7 @@ void ValidateMacros_DontCallThis_Smiley() MF_GetPlayerPlayTime(0); MF_GetPlayerCurweapon(0); MF_GetPlayerTeamID(0); + MF_GetPlayerTeam(0); MF_GetPlayerDeaths(0); MF_GetPlayerMenu(0); MF_GetPlayerKeys(0); diff --git a/dlls/tfc/tfcx/amxxmodule.h b/dlls/tfc/tfcx/amxxmodule.h index 0d44ad13..1863c829 100755 --- a/dlls/tfc/tfcx/amxxmodule.h +++ b/dlls/tfc/tfcx/amxxmodule.h @@ -55,7 +55,7 @@ struct amxx_module_info_s // The next section is copied from the amx.h file // Copyright (c) ITB CompuPhase, 1997-2004 -#if defined __LCC__ || defined __DMC__ || defined __linux__ +#if defined __LCC__ || defined __DMC__ || defined __linux__ || defined __GNUC__ #include #elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L /* The ISO C99 defines the int16_t and int_32t types. If the compiler got @@ -929,7 +929,7 @@ void FN_EngineFprintf(FILE *pfile, char *szFmt, ...); #endif // FN_EngineFprintf #ifdef FN_PvAllocEntPrivateData -void *FN_PvAllocEntPrivateData(edict_t *pEdict, long cb); +void *FN_PvAllocEntPrivateData(edict_t *pEdict, int32 cb); #endif // FN_PvAllocEntPrivateData #ifdef FN_PvEntPrivateData @@ -1919,11 +1919,14 @@ typedef int (*PFN_GET_AMXSTRINGLEN) (const cell *ptr); typedef char * (*PFN_FORMAT_AMXSTRING) (AMX * /*amx*/, cell * /*params*/, int /*startParam*/, int * /*pLen*/); typedef void (*PFN_COPY_AMXMEMORY) (cell * /*dest*/, const cell * /*src*/, int /*len*/); typedef void (*PFN_LOG) (const char * /*fmt*/, ...); +typedef void (*PFN_LOG_ERROR) (AMX * /*amx*/, int /*err*/, const char * /*fmt*/, ...); typedef int (*PFN_RAISE_AMXERROR) (AMX * /*amx*/, int /*error*/); typedef int (*PFN_REGISTER_FORWARD) (const char * /*funcname*/, ForwardExecType /*exectype*/, ... /*paramtypes terminated by PF_DONE*/); typedef int (*PFN_EXECUTE_FORWARD) (int /*id*/, ... /*params*/); typedef cell (*PFN_PREPARE_CELLARRAY) (cell * /*ptr*/, unsigned int /*size*/); typedef cell (*PFN_PREPARE_CHARARRAY) (char * /*ptr*/, unsigned int /*size*/); +typedef cell (*PFN_PREPARE_CELLARRAY_A) (cell * /*ptr*/, unsigned int /*size*/, bool /*copyBack*/); +typedef cell (*PFN_PREPARE_CHARARRAY_A) (char * /*ptr*/, unsigned int /*size*/, bool /*copyBack*/); typedef int (*PFN_IS_PLAYER_VALID) (int /*id*/); typedef const char * (*PFN_GET_PLAYER_NAME) (int /*id*/); typedef const char * (*PFN_GET_PLAYER_IP) (int /*id*/); @@ -1932,8 +1935,9 @@ typedef int (*PFN_IS_PLAYER_BOT) (int /*id*/); typedef int (*PFN_IS_PLAYER_AUTHORIZED) (int /*id*/); typedef float (*PFN_GET_PLAYER_TIME) (int /*id*/); typedef float (*PFN_GET_PLAYER_PLAYTIME) (int /*id*/); -typedef int (*PFN_GETPLAYERFLAGS) (int /* id*/); +typedef int (*PFN_GETPLAYERFLAGS) (int /* id*/); typedef int (*PFN_GET_PLAYER_CURWEAPON) (int /*id*/); +typedef const char * (*PFN_GET_PLAYER_TEAM) (int /*id*/); typedef int (*PFN_GET_PLAYER_TEAMID) (int /*id*/); typedef int (*PFN_GET_PLAYER_DEATHS) (int /*id*/); typedef int (*PFN_GET_PLAYER_MENU) (int /*id*/); @@ -1986,11 +1990,14 @@ extern PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; extern PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; extern PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; extern PFN_LOG g_fn_Log; +extern PFN_LOG_ERROR g_fn_LogError; extern PFN_RAISE_AMXERROR g_fn_RaiseAmxError; extern PFN_REGISTER_FORWARD g_fn_RegisterForward; extern PFN_EXECUTE_FORWARD g_fn_ExecuteForward; extern PFN_PREPARE_CELLARRAY g_fn_PrepareCellArray; extern PFN_PREPARE_CHARARRAY g_fn_PrepareCharArray; +extern PFN_PREPARE_CELLARRAY_A g_fn_PrepareCellArrayA; +extern PFN_PREPARE_CHARARRAY_A g_fn_PrepareCharArrayA; extern PFN_IS_PLAYER_VALID g_fn_IsPlayerValid; extern PFN_GET_PLAYER_NAME g_fn_GetPlayerName; extern PFN_GET_PLAYER_IP g_fn_GetPlayerIP; @@ -2026,6 +2033,7 @@ extern PFN_AMX_FINDNATIVE g_fn_AmxFindNative; extern PFN_GETPLAYERFLAGS g_fn_GetPlayerFlags; extern PFN_GET_PLAYER_EDICT g_fn_GetPlayerEdict; extern PFN_FORMAT g_fn_Format; +extern PFN_GET_PLAYER_TEAM g_fn_GetPlayerTeam; #ifdef MAY_NEVER_BE_DEFINED // Function prototypes for intellisense and similar systems @@ -2045,11 +2053,14 @@ int MF_GetAmxStringLen (const cell *ptr) { } char * MF_FormatAmxString (AMX * amx, cell * params, int startParam, int * pLen) { } void MF_CopyAmxMemory (cell * dest, const cell * src, int len) { } void MF_Log (const char * fmt, ...) { } +void MF_LogError (AMX * amx, int err, const char *fmt, ...) { } int MF_RaiseAmxError (AMX * amx, int error) { } int MF_RegisterForward (const char * funcname, ForwardExecType exectype, ...) { } int MF_ExecuteForward (int id, ...) { } cell MF_PrepareCellArray (cell * ptr, unsigned int size) { } cell MF_PrepareCharArray (char * ptr, unsigned int size) { } +cell MF_PrepareCellArrayA (cell * ptr, unsigned int size, bool copyBack) { } +cell MF_PrepareCharArrayA (char * ptr, unsigned int size, bool copyBack) { } int MF_IsPlayerValid (int id) { } const char * MF_GetPlayerName (int id) { } const char * MF_GetPlayerIP (int id) { } @@ -2059,6 +2070,7 @@ int MF_IsPlayerAuthorized (int id) { } float MF_GetPlayerTime (int id) { } float MF_GetPlayerPlayTime (int id) { } int MF_GetPlayerCurweapon (int id) { } +const char * MF_GetPlayerTeam (int id) { } int MF_GetPlayerTeamID (int id) { } int MF_GetPlayerDeaths (int id) { } int MF_GetPlayerMenu (int id) { } @@ -2094,11 +2106,14 @@ const char * MF_Format (const char *fmt, ...) { } #define MF_GetAmxStringLen g_fn_GetAmxStringLen #define MF_CopyAmxMemory g_fn_CopyAmxMemory void MF_Log(const char *fmt, ...); +#define MF_LogError g_fn_LogError #define MF_RaiseAmxError g_fn_RaiseAmxError #define MF_RegisterForward g_fn_RegisterForward #define MF_ExecuteForward g_fn_ExecuteForward #define MF_PrepareCellArray g_fn_PrepareCellArray #define MF_PrepareCharArray g_fn_PrepareCharArray +#define MF_PrepareCellArrayA g_fn_PrepareCellArrayA +#define MF_PrepareCharArrayA g_fn_PrepareCharArrayA #define MF_IsPlayerValid g_fn_IsPlayerValid #define MF_GetPlayerName g_fn_GetPlayerName #define MF_GetPlayerIP g_fn_GetPlayerIP @@ -2108,6 +2123,7 @@ void MF_Log(const char *fmt, ...); #define MF_GetPlayerTime g_fn_GetPlayerTime #define MF_GetPlayerPlayTime g_fn_GetPlayerPlayTime #define MF_GetPlayerCurweapon g_fn_GetPlayerCurweapon +#define MF_GetPlayerTeam g_fn_GetPlayerTeam #define MF_GetPlayerTeamID g_fn_GetPlayerTeamID #define MF_GetPlayerDeaths g_fn_GetPlayerDeaths #define MF_GetPlayerMenu g_fn_GetPlayerMenu @@ -2133,7 +2149,7 @@ void MF_Log(const char *fmt, ...); #define MF_UnregisterSPForward g_fn_UnregisterSPForward #define MF_GetPlayerFlags g_fn_GetPlayerFlags #define MF_GetPlayerEdict g_fn_GetPlayerEdict -#define MF_Format g_fn_Format; +#define MF_Format g_fn_Format /*** Memory ***/ void *operator new(size_t reportedSize); diff --git a/dlls/tfc/tfcx/tfcx.h b/dlls/tfc/tfcx/tfcx.h index 5fdde031..bf38f26c 100755 --- a/dlls/tfc/tfcx/tfcx.h +++ b/dlls/tfc/tfcx/tfcx.h @@ -105,5 +105,41 @@ bool ignoreBots (edict_t *pEnt, edict_t *pOther = NULL ); bool isModuleActive(); bool util_strncmp( const char *sz1, const char *sz2, int size); +#define CHECK_ENTITY(x) \ + if (x <= 0 || x > gpGlobals->maxEntities) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + } else { \ + if (x <= gpGlobals->maxClients) { \ + if (!MF_IsPlayerIngame(x)) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + } \ + } else { \ + if (FNullEnt(INDEXENT(x))) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + } \ + } \ + } + +#define CHECK_PLAYER(x) \ + if (x < 1 || x > gpGlobals->maxClients) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + } else { \ + if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ + } \ + } + +#define CHECK_NONPLAYER(x) \ + if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ + } else { \ + if (FNullEnt(INDEXENT(x))) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \ + } \ + } + +#define GETEDICT(n) \ + ((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n)) + #endif // TFCX_H