Fix handleInstanceDifficulty to handle variable-length packet formats

MSG_SET_DUNGEON_DIFFICULTY sends 4 or 12 bytes (difficulty + optional
isInGroup + savedBool) while SMSG_INSTANCE_DIFFICULTY sends 8 bytes
(difficulty + heroic).  The previous guard of < 8 caused the handler
to silently return for 4-byte variants, leaving instanceDifficulty_
unchanged.  Now reads as much as available and infers heroic flag from
the field count.
This commit is contained in:
Kelsi 2026-03-11 02:08:38 -07:00
parent 7c77c4a81e
commit a67feb6d93

View file

@ -12266,10 +12266,27 @@ void GameHandler::handleRaidInstanceInfo(network::Packet& packet) {
}
void GameHandler::handleInstanceDifficulty(network::Packet& packet) {
if (packet.getSize() - packet.getReadPos() < 8) return;
// SMSG_INSTANCE_DIFFICULTY: uint32 difficulty, uint32 heroic (8 bytes)
// MSG_SET_DUNGEON_DIFFICULTY: uint32 difficulty[, uint32 isInGroup, uint32 savedBool] (4 or 12 bytes)
auto rem = [&]() { return packet.getSize() - packet.getReadPos(); };
if (rem() < 4) return;
instanceDifficulty_ = packet.readUInt32();
uint32_t isHeroic = packet.readUInt32();
instanceIsHeroic_ = (isHeroic != 0);
if (rem() >= 4) {
uint32_t secondField = packet.readUInt32();
// SMSG_INSTANCE_DIFFICULTY: second field is heroic flag (0 or 1)
// MSG_SET_DUNGEON_DIFFICULTY: second field is isInGroup (not heroic)
// Heroic = difficulty value 1 for 5-man, so use the field value for SMSG and
// infer from difficulty for MSG variant (which has larger payloads).
if (rem() >= 4) {
// Three+ fields: this is MSG_SET_DUNGEON_DIFFICULTY; heroic = (difficulty == 1)
instanceIsHeroic_ = (instanceDifficulty_ == 1);
} else {
// Two fields: SMSG_INSTANCE_DIFFICULTY format
instanceIsHeroic_ = (secondField != 0);
}
} else {
instanceIsHeroic_ = (instanceDifficulty_ == 1);
}
LOG_INFO("Instance difficulty: ", instanceDifficulty_, " heroic=", instanceIsHeroic_);
}