Make sure client is alive before checking buying commands

This commit is contained in:
Arkshine 2015-12-05 14:24:35 +01:00
parent 4cea082303
commit 5b0191f691

View File

@ -102,19 +102,20 @@ const char *CMD_ARGV(int i)
DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity)
{
auto command = CMD_ARGV(0);
auto client = TypeConversion.edict_to_id(pEdict);
CurrentItemId = CSI_NONE;
if (MF_IsPlayerAlive(client))
{
// Purpose is to retrieve an item id based on alias name or selected item from menu,
// to be used in CS_OnBuy* forwards.
if ((HasOnBuyAttemptForward || HasOnBuyForward) && command && *command)
{
int itemId = CSI_NONE;
// Handling buy via menu.
if (!strcmp(command, "menuselect"))
{
int slot = atoi(CMD_ARGV(1));
auto slot = atoi(CMD_ARGV(1));
if (slot > 0 && slot < 9)
{
@ -140,19 +141,14 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
/* Menu_BuyItem */ { 0, CSI_VEST, CSI_VESTHELM, CSI_FLASHBANG, CSI_HEGRENADE, CSI_SMOKEGRENADE, CSI_NVGS, CSI_DEFUSER, CSI_SHIELD }
};
int menuId = get_pdata<int>(pEdict, MenuDesc.fieldOffset);
auto menuId = get_pdata<int>(pEdict, MenuDesc.fieldOffset);
if (menuId >= Menu_Buy && menuId <= Menu_BuyItem)
{
switch (get_pdata<int>(pEdict, TeamDesc.fieldOffset))
{
case TEAM_T: itemId = menuItemsTe[menuId - 4][slot]; break; // -4 because array is zero-based and Menu_Buy* constants starts from 4.
case TEAM_CT:itemId = menuItemsCt[menuId - 4][slot]; break;
}
if (itemId)
{
CurrentItemId = itemId;
case TEAM_T: CurrentItemId = menuItemsTe[menuId - 4][slot]; break; // -4 because array is zero-based and Menu_Buy* constants starts from 4.
case TEAM_CT:CurrentItemId = menuItemsCt[menuId - 4][slot]; break;
}
}
}
@ -171,17 +167,16 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
}
}
auto client = TypeConversion.edict_to_id(pEdict);
if (HasInternalCommandForward && *UseBotArgs && MF_ExecuteForward(ForwardInternalCommand, client, *BotArgs) > 0)
{
return;
}
if (HasOnBuyAttemptForward && CurrentItemId && MF_IsPlayerAlive(client) && MF_ExecuteForward(ForwardOnBuyAttempt, client, CurrentItemId) > 0)
if (HasOnBuyAttemptForward && CurrentItemId && MF_ExecuteForward(ForwardOnBuyAttempt, client, CurrentItemId) > 0)
{
return;
}
}
TriggeredFromCommand = CurrentItemId != CSI_NONE;