diff --git a/src/transmog_scripts.cpp b/src/transmog_scripts.cpp index 451327e0..f622780c 100644 --- a/src/transmog_scripts.cpp +++ b/src/transmog_scripts.cpp @@ -1064,21 +1064,22 @@ class PS_Transmogrification : public PlayerScript AddToDatabase(player, it); } - void OnPlayerLootItem(Player* player, Item* item, uint32 /*count*/, ObjectGuid /*lootguid*/) override + void OnPlayerLootItem(Player* /*player*/, Item* /*item*/, uint32 /*count*/, ObjectGuid /*lootguid*/) override { - if (!sT->GetUseCollectionSystem() || !item || typeid(*item) != typeid(Item)) - return; - if (item->GetTemplate()->Bonding == ItemBondingType::BIND_WHEN_PICKED_UP || item->IsSoulBound()) - { - AddToDatabase(player, item); - } + // Intentionally left no-op. Other modules (e.g., auto-destroy/sell junk) may delete the item + // during earlier OnPlayerLootItem hooks, making this pointer unsafe to touch. + // Collection is handled in OnPlayerCreateItem and OnPlayerAfterStoreOrEquipNewItem. + return; } void OnPlayerCreateItem(Player* player, Item* item, uint32 /*count*/) override { - if (!sT->GetUseCollectionSystem()) + if (!sT->GetUseCollectionSystem() || !item) return; - if (item->GetTemplate()->Bonding == ItemBondingType::BIND_WHEN_PICKED_UP || item->IsSoulBound()) + ItemTemplate const* itemTemplate = item->GetTemplate(); + if (!itemTemplate) + return; + if (itemTemplate->Bonding == ItemBondingType::BIND_WHEN_PICKED_UP || item->IsSoulBound()) { AddToDatabase(player, item); } @@ -1086,9 +1087,12 @@ class PS_Transmogrification : public PlayerScript void OnPlayerAfterStoreOrEquipNewItem(Player* player, uint32 /*vendorslot*/, Item* item, uint8 /*count*/, uint8 /*bag*/, uint8 /*slot*/, ItemTemplate const* /*pProto*/, Creature* /*pVendor*/, VendorItem const* /*crItem*/, bool /*bStore*/) override { - if (!sT->GetUseCollectionSystem()) + if (!sT->GetUseCollectionSystem() || !item) + return; + ItemTemplate const* itemTemplate = item->GetTemplate(); + if (!itemTemplate) return; - if (item->GetTemplate()->Bonding == ItemBondingType::BIND_WHEN_PICKED_UP || item->IsSoulBound()) + if (itemTemplate->Bonding == ItemBondingType::BIND_WHEN_PICKED_UP || item->IsSoulBound()) { AddToDatabase(player, item); }