Merge pull request #315 from Arkshine/cstrike-sanity-check

Make sure client is alive before checking buying commands
This commit is contained in:
Vincent Herbet 2015-12-08 01:06:16 +01:00
commit 8ec6136a7c

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) DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity)
{ {
auto command = CMD_ARGV(0); auto command = CMD_ARGV(0);
auto client = TypeConversion.edict_to_id(pEdict);
CurrentItemId = CSI_NONE; CurrentItemId = CSI_NONE;
if (MF_IsPlayerAlive(client))
{
// Purpose is to retrieve an item id based on alias name or selected item from menu, // Purpose is to retrieve an item id based on alias name or selected item from menu,
// to be used in CS_OnBuy* forwards. // to be used in CS_OnBuy* forwards.
if ((HasOnBuyAttemptForward || HasOnBuyForward) && command && *command) if ((HasOnBuyAttemptForward || HasOnBuyForward) && command && *command)
{ {
int itemId = CSI_NONE;
// Handling buy via menu. // Handling buy via menu.
if (!strcmp(command, "menuselect")) if (!strcmp(command, "menuselect"))
{ {
int slot = atoi(CMD_ARGV(1)); auto slot = atoi(CMD_ARGV(1));
if (slot > 0 && slot < 9) 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 } /* 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) if (menuId >= Menu_Buy && menuId <= Menu_BuyItem)
{ {
switch (get_pdata<int>(pEdict, TeamDesc.fieldOffset)) 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_T: CurrentItemId = 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; case TEAM_CT:CurrentItemId = menuItemsCt[menuId - 4][slot]; break;
}
if (itemId)
{
CurrentItemId = itemId;
} }
} }
} }
@ -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) if (HasInternalCommandForward && *UseBotArgs && MF_ExecuteForward(ForwardInternalCommand, client, *BotArgs) > 0)
{ {
return; return;
} }
if (HasOnBuyAttemptForward && CurrentItemId && MF_IsPlayerAlive(client) && MF_ExecuteForward(ForwardOnBuyAttempt, client, CurrentItemId) > 0) if (HasOnBuyAttemptForward && CurrentItemId && MF_ExecuteForward(ForwardOnBuyAttempt, client, CurrentItemId) > 0)
{ {
return; return;
} }
}
TriggeredFromCommand = CurrentItemId != CSI_NONE; TriggeredFromCommand = CurrentItemId != CSI_NONE;