[Crash] Fix crash with EVENT_UNEQUIP_ITEM_BOT (#2973)

This commit is contained in:
Aeadoin 2023-02-20 17:31:15 -05:00 committed by GitHub
parent df499b22ab
commit 6a668f8aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 11 deletions

View File

@ -4612,17 +4612,17 @@ void Bot::PerformTradeWithClient(int16 begin_slot_id, int16 end_slot_id, Client*
struct ClientTrade { struct ClientTrade {
ItemInstance* trade_item_instance; ItemInstance* trade_item_instance;
int16 from_client_slot; int16 from_client_slot;
int16 to_bot_slot; int16 to_bot_slot = invslot::SLOT_INVALID;
ClientTrade(ItemInstance* item, int16 from) : trade_item_instance(item), from_client_slot(from), to_bot_slot(invslot::SLOT_INVALID) { } ClientTrade(ItemInstance* item, int16 from) : trade_item_instance(item), from_client_slot(from) { }
}; };
struct ClientReturn { struct ClientReturn {
const ItemInstance* return_item_instance; ItemInstance* return_item_instance;
int16 from_bot_slot; int16 from_bot_slot;
int16 to_client_slot; int16 to_client_slot = invslot::SLOT_INVALID;
ClientReturn(const ItemInstance* item, int16 from) : return_item_instance(item), from_bot_slot(from), to_client_slot(invslot::SLOT_INVALID) { } ClientReturn(ItemInstance* item, int16 from) : return_item_instance(item), from_bot_slot(from) { }
}; };
static const int16 bot_equip_order[invslot::EQUIPMENT_COUNT] = { static const int16 bot_equip_order[invslot::EQUIPMENT_COUNT] = {
@ -4902,7 +4902,7 @@ void Bot::PerformTradeWithClient(int16 begin_slot_id, int16 end_slot_id, Client*
if (trade_instance->GetItem()->IsType2HWeapon()) { if (trade_instance->GetItem()->IsType2HWeapon()) {
if (!melee_secondary) { if (!melee_secondary) {
melee_2h_weapon = true; melee_2h_weapon = true;
auto equipped_secondary_weapon = m_inv[invslot::slotSecondary]; auto equipped_secondary_weapon = GetBotItem(invslot::slotSecondary);
if (equipped_secondary_weapon) { if (equipped_secondary_weapon) {
client_return.push_back(ClientReturn(equipped_secondary_weapon, invslot::slotSecondary)); client_return.push_back(ClientReturn(equipped_secondary_weapon, invslot::slotSecondary));
} }
@ -4918,7 +4918,7 @@ void Bot::PerformTradeWithClient(int16 begin_slot_id, int16 end_slot_id, Client*
!trade_instance->IsWeapon() !trade_instance->IsWeapon()
) { ) {
melee_secondary = true; melee_secondary = true;
auto equipped_primary_weapon = m_inv[invslot::slotPrimary]; auto equipped_primary_weapon = GetBotItem(invslot::slotPrimary);
if (equipped_primary_weapon && equipped_primary_weapon->GetItem()->IsType2HWeapon()) { if (equipped_primary_weapon && equipped_primary_weapon->GetItem()->IsType2HWeapon()) {
client_return.push_back(ClientReturn(equipped_primary_weapon, invslot::slotPrimary)); client_return.push_back(ClientReturn(equipped_primary_weapon, invslot::slotPrimary));
} }
@ -4933,7 +4933,7 @@ void Bot::PerformTradeWithClient(int16 begin_slot_id, int16 end_slot_id, Client*
trade_iterator.to_bot_slot = index; trade_iterator.to_bot_slot = index;
if (m_inv[index]) { if (m_inv[index]) {
client_return.push_back(ClientReturn(m_inv[index], index)); client_return.push_back(ClientReturn(GetBotItem(index), index));
} }
break; break;
@ -5067,9 +5067,8 @@ void Bot::PerformTradeWithClient(int16 begin_slot_id, int16 end_slot_id, Client*
client->DeleteItemInInventory(return_iterator.from_bot_slot); client->DeleteItemInInventory(return_iterator.from_bot_slot);
} else { // successful trade returns } else { // successful trade returns
auto return_instance = m_inv.PopItem(return_iterator.from_bot_slot); auto return_instance = m_inv.PopItem(return_iterator.from_bot_slot);
//if (*return_instance != *return_iterator.return_item_instance) {
// // TODO: add logging // // TODO: add logging
//}
if (!database.botdb.DeleteItemBySlot(GetBotID(), return_iterator.from_bot_slot)) { if (!database.botdb.DeleteItemBySlot(GetBotID(), return_iterator.from_bot_slot)) {
OwnerMessage( OwnerMessage(

View File

@ -9320,7 +9320,7 @@ void bot_subcommand_inventory_remove(Client *c, const Seperator *sep)
return; return;
} }
const auto* inst = my_bot->GetBotItem(slot_id); auto* inst = my_bot->GetBotItem(slot_id);
if (!inst) { if (!inst) {
std::string slot_message = "is"; std::string slot_message = "is";
switch (slot_id) { switch (slot_id) {