mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
fix: use CMSG_OPEN_ITEM for locked containers (lockboxes)
Right-clicking a locked container (e.g. Dead-Tooth's Strong Box) was sending CMSG_USE_ITEM with spellId=0, which the server rejects. Locked containers (itemClass==1, inventoryType==0) now send CMSG_OPEN_ITEM instead, letting the server auto-check the keyring for the required key.
This commit is contained in:
parent
2fb7901cca
commit
25138b5648
5 changed files with 50 additions and 2 deletions
|
|
@ -2007,6 +2007,9 @@ public:
|
||||||
void autoEquipItemInBag(int bagIndex, int slotIndex);
|
void autoEquipItemInBag(int bagIndex, int slotIndex);
|
||||||
void useItemBySlot(int backpackIndex);
|
void useItemBySlot(int backpackIndex);
|
||||||
void useItemInBag(int bagIndex, int slotIndex);
|
void useItemInBag(int bagIndex, int slotIndex);
|
||||||
|
// CMSG_OPEN_ITEM — for locked containers (lockboxes); server checks keyring automatically
|
||||||
|
void openItemBySlot(int backpackIndex);
|
||||||
|
void openItemInBag(int bagIndex, int slotIndex);
|
||||||
void destroyItem(uint8_t bag, uint8_t slot, uint8_t count = 1);
|
void destroyItem(uint8_t bag, uint8_t slot, uint8_t count = 1);
|
||||||
void swapContainerItems(uint8_t srcBag, uint8_t srcSlot, uint8_t dstBag, uint8_t dstSlot);
|
void swapContainerItems(uint8_t srcBag, uint8_t srcSlot, uint8_t dstBag, uint8_t dstSlot);
|
||||||
void swapBagSlots(int srcBagIndex, int dstBagIndex);
|
void swapBagSlots(int srcBagIndex, int dstBagIndex);
|
||||||
|
|
|
||||||
|
|
@ -2027,6 +2027,12 @@ public:
|
||||||
static network::Packet build(uint8_t bagIndex, uint8_t slotIndex, uint64_t itemGuid, uint32_t spellId = 0);
|
static network::Packet build(uint8_t bagIndex, uint8_t slotIndex, uint64_t itemGuid, uint32_t spellId = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** CMSG_OPEN_ITEM packet builder (for locked containers / lockboxes) */
|
||||||
|
class OpenItemPacket {
|
||||||
|
public:
|
||||||
|
static network::Packet build(uint8_t bagIndex, uint8_t slotIndex);
|
||||||
|
};
|
||||||
|
|
||||||
/** CMSG_AUTOEQUIP_ITEM packet builder */
|
/** CMSG_AUTOEQUIP_ITEM packet builder */
|
||||||
class AutoEquipItemPacket {
|
class AutoEquipItemPacket {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -21165,6 +21165,26 @@ void GameHandler::useItemInBag(int bagIndex, int slotIndex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameHandler::openItemBySlot(int backpackIndex) {
|
||||||
|
if (backpackIndex < 0 || backpackIndex >= inventory.getBackpackSize()) return;
|
||||||
|
if (inventory.getBackpackSlot(backpackIndex).empty()) return;
|
||||||
|
if (state != WorldState::IN_WORLD || !socket) return;
|
||||||
|
auto packet = OpenItemPacket::build(0xFF, static_cast<uint8_t>(23 + backpackIndex));
|
||||||
|
LOG_INFO("openItemBySlot: CMSG_OPEN_ITEM bag=0xFF slot=", (23 + backpackIndex));
|
||||||
|
socket->send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameHandler::openItemInBag(int bagIndex, int slotIndex) {
|
||||||
|
if (bagIndex < 0 || bagIndex >= inventory.NUM_BAG_SLOTS) return;
|
||||||
|
if (slotIndex < 0 || slotIndex >= inventory.getBagSize(bagIndex)) return;
|
||||||
|
if (inventory.getBagSlot(bagIndex, slotIndex).empty()) return;
|
||||||
|
if (state != WorldState::IN_WORLD || !socket) return;
|
||||||
|
uint8_t wowBag = static_cast<uint8_t>(19 + bagIndex);
|
||||||
|
auto packet = OpenItemPacket::build(wowBag, static_cast<uint8_t>(slotIndex));
|
||||||
|
LOG_INFO("openItemInBag: CMSG_OPEN_ITEM bag=", (int)wowBag, " slot=", slotIndex);
|
||||||
|
socket->send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
void GameHandler::useItemById(uint32_t itemId) {
|
void GameHandler::useItemById(uint32_t itemId) {
|
||||||
if (itemId == 0) return;
|
if (itemId == 0) return;
|
||||||
LOG_DEBUG("useItemById: searching for itemId=", itemId);
|
LOG_DEBUG("useItemById: searching for itemId=", itemId);
|
||||||
|
|
|
||||||
|
|
@ -4271,6 +4271,13 @@ network::Packet UseItemPacket::build(uint8_t bagIndex, uint8_t slotIndex, uint64
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network::Packet OpenItemPacket::build(uint8_t bagIndex, uint8_t slotIndex) {
|
||||||
|
network::Packet packet(wireOpcode(Opcode::CMSG_OPEN_ITEM));
|
||||||
|
packet.writeUInt8(bagIndex);
|
||||||
|
packet.writeUInt8(slotIndex);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
network::Packet AutoEquipItemPacket::build(uint8_t srcBag, uint8_t srcSlot) {
|
network::Packet AutoEquipItemPacket::build(uint8_t srcBag, uint8_t srcSlot) {
|
||||||
network::Packet packet(wireOpcode(Opcode::CMSG_AUTOEQUIP_ITEM));
|
network::Packet packet(wireOpcode(Opcode::CMSG_AUTOEQUIP_ITEM));
|
||||||
packet.writeUInt8(srcBag);
|
packet.writeUInt8(srcBag);
|
||||||
|
|
|
||||||
|
|
@ -2356,7 +2356,14 @@ void InventoryScreen::renderItemSlot(game::Inventory& inventory, const game::Ite
|
||||||
} else if (item.inventoryType > 0) {
|
} else if (item.inventoryType > 0) {
|
||||||
gameHandler_->autoEquipItemBySlot(backpackIndex);
|
gameHandler_->autoEquipItemBySlot(backpackIndex);
|
||||||
} else {
|
} else {
|
||||||
gameHandler_->useItemBySlot(backpackIndex);
|
// itemClass==1 (Container) with inventoryType==0 means a lockbox;
|
||||||
|
// use CMSG_OPEN_ITEM so the server checks keyring automatically.
|
||||||
|
auto* info = gameHandler_->getItemInfo(item.itemId);
|
||||||
|
if (info && info->valid && info->itemClass == 1) {
|
||||||
|
gameHandler_->openItemBySlot(backpackIndex);
|
||||||
|
} else {
|
||||||
|
gameHandler_->useItemBySlot(backpackIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (kind == SlotKind::BACKPACK && isBagSlot) {
|
} else if (kind == SlotKind::BACKPACK && isBagSlot) {
|
||||||
LOG_INFO("Right-click bag item: name='", item.name,
|
LOG_INFO("Right-click bag item: name='", item.name,
|
||||||
|
|
@ -2369,7 +2376,12 @@ void InventoryScreen::renderItemSlot(game::Inventory& inventory, const game::Ite
|
||||||
} else if (item.inventoryType > 0) {
|
} else if (item.inventoryType > 0) {
|
||||||
gameHandler_->autoEquipItemInBag(bagIndex, bagSlotIndex);
|
gameHandler_->autoEquipItemInBag(bagIndex, bagSlotIndex);
|
||||||
} else {
|
} else {
|
||||||
gameHandler_->useItemInBag(bagIndex, bagSlotIndex);
|
auto* info = gameHandler_->getItemInfo(item.itemId);
|
||||||
|
if (info && info->valid && info->itemClass == 1) {
|
||||||
|
gameHandler_->openItemInBag(bagIndex, bagSlotIndex);
|
||||||
|
} else {
|
||||||
|
gameHandler_->useItemInBag(bagIndex, bagSlotIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue