From 9dcdba439a276048c418ccee49885d080152ec09 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 28 Jun 2006 10:07:20 +0000 Subject: [PATCH] added fix for binlog bug with failed plugins added experimental emsg natives fixed target's velbyaim bug find added native for setting player curweapon --- amxmodx/amxmodx.cpp | 27 ++++++++++ amxmodx/amxmodx.h | 2 + amxmodx/binlog.cpp | 55 ++++++++++++-------- amxmodx/messages.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++ amxmodx/meta_api.cpp | 2 + amxmodx/vector.cpp | 29 ++++++----- 6 files changed, 200 insertions(+), 36 deletions(-) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 4405a6f8..8728dc90 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -3932,6 +3932,11 @@ static cell AMX_NATIVE_CALL ShowSyncHudMsg(AMX *amx, cell *params) return len; } +static cell AMX_NATIVE_CALL is_user_hacking(AMX *amx, cell *params) +{ + return g_bmod_cstrike ? 1 : 0; +} + static cell AMX_NATIVE_CALL arrayset(AMX *amx, cell *params) { memset(get_amxaddr(amx, params[1]), params[2], params[3] * sizeof(cell)); @@ -3939,6 +3944,27 @@ static cell AMX_NATIVE_CALL arrayset(AMX *amx, cell *params) return 1; } +static cell AMX_NATIVE_CALL amxx_setpl_curweap(AMX *amx, cell *params) +{ + if (params[1] < 1 || params[1] > gpGlobals->maxClients) + { + LogError(amx, AMX_ERR_NATIVE, "Invalid client %d", params[1]); + return 0; + } + + CPlayer *p = GET_PLAYER_POINTER_I(params[1]); + + if (!p->ingame) + { + LogError(amx, AMX_ERR_NATIVE, "Player %d not ingame", params[1]); + return 0; + } + + p->current = params[2]; + + return 1; +} + AMX_NATIVE_INFO amxmodx_Natives[] = { {"abort", amx_abort}, @@ -4043,6 +4069,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"is_user_bot", is_user_bot}, {"is_user_connected", is_user_connected}, {"is_user_connecting", is_user_connecting}, + {"is_user_hacking", is_user_hacking}, {"is_user_hltv", is_user_hltv}, {"lang_exists", lang_exists}, {"log_amx", log_amx}, diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 62d26a4d..2b5fa857 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -338,4 +338,6 @@ struct func_s const char *desc; }; +extern enginefuncs_t *g_pEngTable; + #endif // AMXMODX_H diff --git a/amxmodx/binlog.cpp b/amxmodx/binlog.cpp index ba826e8f..b7bf1928 100644 --- a/amxmodx/binlog.cpp +++ b/amxmodx/binlog.cpp @@ -227,32 +227,43 @@ void BinLog::WritePluginDB(FILE *fp) if (c && pl->isDebug()) c = 2; fwrite(&c, sizeof(char), 1, fp); - len = (char)strlen(pl->getName()); - fwrite(&len, sizeof(char), 1, fp); - len++; - fwrite(pl->getName(), sizeof(char), len, fp); - int natives, publics; - AMX *amx = pl->getAMX(); - amx_NumNatives(amx, &natives); - amx_NumPublics(amx, &publics); - fwrite(&natives, sizeof(int), 1, fp); - fwrite(&publics, sizeof(int), 1, fp); - char name[34]; - for (int i=0; igetName()); fwrite(&len, sizeof(char), 1, fp); len++; - fwrite(name, sizeof(char), len, fp); - } - for (int i=0; igetName(), sizeof(char), len, fp); + int natives, publics; + AMX *amx = pl->getAMX(); + amx_NumNatives(amx, &natives); + amx_NumPublics(amx, &publics); + fwrite(&natives, sizeof(int), 1, fp); + fwrite(&publics, sizeof(int), 1, fp); + char name[34]; + for (int i=0; i 63) // maximal number of engine messages + && !GET_USER_MSG_NAME(PLID, params[2], NULL))) + { + LogError(amx, AMX_ERR_NATIVE, "Plugin called message_begin with an invalid message id (%d).", params[2]); + return 0; + } + + switch (params[1]) + { + case MSG_BROADCAST: + case MSG_ALL: + case MSG_SPEC: + g_pEngTable->pfnMessageBegin(params[1], params[2], NULL, NULL); + break; + case MSG_PVS: case MSG_PAS: + case MSG_PVS_R: case MSG_PAS_R: + if (numparam < 3) + { + LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed"); + return 0; + } + + cpOrigin = get_amxaddr(amx, params[3]); + + vecOrigin[0] = static_cast(*cpOrigin); + vecOrigin[1] = static_cast(*(cpOrigin + 1)); + vecOrigin[2] = static_cast(*(cpOrigin + 2)); + + g_pEngTable->pfnMessageBegin(params[1], params[2], vecOrigin, NULL); + + break; + case MSG_ONE_UNRELIABLE: + case MSG_ONE: + if (numparam < 4) + { + LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed"); + return 0; + } + + g_pEngTable->pfnMessageBegin(params[1], params[2], NULL, INDEXENT(params[4])); + break; + } + + return 1; +} + +static cell AMX_NATIVE_CALL emessage_end(AMX *amx, cell *params) +{ + g_pEngTable->pfnMessageEnd(); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_byte(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteByte(params[1]); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_char(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteChar(params[1]); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_short(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteShort(params[1]); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_long(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteLong(params[1]); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_entity(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteEntity(params[1]); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_angle(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteAngle(static_cast(params[1])); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_coord(AMX *amx, cell *params) /* 1 param */ +{ + g_pEngTable->pfnWriteCoord(static_cast(params[1])); + return 1; +} + +static cell AMX_NATIVE_CALL ewrite_string(AMX *amx, cell *params) /* 1 param */ +{ + int a; + g_pEngTable->pfnWriteString(get_amxstring(amx, params[1], 3, a)); + + return 1; +} + AMX_NATIVE_INFO msg_Natives[] = { {"message_begin", message_begin}, @@ -680,5 +789,17 @@ AMX_NATIVE_INFO msg_Natives[] = {"set_msg_arg_string", set_msg_arg_string}, {"get_msg_origin", get_msg_origin}, + {"emessage_begin", emessage_begin}, + {"emessage_end", emessage_end}, + + {"ewrite_angle", ewrite_angle}, + {"ewrite_byte", ewrite_byte}, + {"ewrite_char", ewrite_char}, + {"ewrite_coord", ewrite_coord}, + {"ewrite_entity", ewrite_entity}, + {"ewrite_long", ewrite_long}, + {"ewrite_short", ewrite_short}, + {"ewrite_string", ewrite_string}, + {NULL, NULL}, }; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 7002bab6..23510495 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -1351,6 +1351,8 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m // This will also call modules Meta_Query and Meta_Attach functions loadModules(get_localinfo("amxx_modules", "addons/amxmodx/configs/modules.ini"), now); + GET_HOOK_TABLES(PLID, &g_pEngTable, NULL, NULL); + return (TRUE); } diff --git a/amxmodx/vector.cpp b/amxmodx/vector.cpp index 6ba465d0..43633e29 100644 --- a/amxmodx/vector.cpp +++ b/amxmodx/vector.cpp @@ -67,6 +67,7 @@ static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params) int iVelocity = params[2]; cell *vRet = get_amxaddr(amx, params[3]); Vector vVector = Vector(0, 0, 0); + edict_t *pEnt = NULL; if (iEnt < 0 || iEnt > gpGlobals->maxEntities) { @@ -75,24 +76,24 @@ static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params) } else { - if (iEnt <= gpGlobals->maxClients && !GET_PLAYER_POINTER_I(iEnt)->ingame) + if (iEnt > 0 && iEnt <= gpGlobals->maxClients) { - LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", iEnt); - return 0; - } - else if (iEnt != 0 && FNullEnt(INDEXENT(iEnt))) - { - LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", iEnt); - return 0; + if (!GET_PLAYER_POINTER_I(iEnt)->ingame) + { + LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not ingame)", iEnt); + return 0; + } + pEnt = GET_PLAYER_POINTER_I(iEnt)->pEdict; + } else { + pEnt = INDEXENT(iEnt); } } - edict_t *pEnt; - - if (iEnt >= 1 || iEnt <= gpGlobals->maxClients) - pEnt = GET_PLAYER_POINTER_I(iEnt)->pEdict; - else - pEnt = INDEXENT(iEnt); + if (!pEnt) + { + LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d (nullent)", iEnt); + return 0; + } MAKE_VECTORS(pEnt->v.v_angle); vVector = gpGlobals->v_forward * iVelocity;