diff --git a/docs/API.md b/docs/API.md index 91cde4fa..ee441d9c 100644 --- a/docs/API.md +++ b/docs/API.md @@ -18563,12 +18563,10 @@ tokens (`"HELPFUL"`, `"HARMFUL"`, - **`HELPFUL`** (default) / **`HARMFUL`** — pick buffs or debuffs by each aura's polarity flag. In `GetUnitAuras`, supplying neither returns both. -- **`PLAYER`** — restrict to auras the local player cast, via the - `Aura::Source` caster cache (`sourceGUID == ` player GUID). Combines with - the range tokens (`"HARMFUL|PLAYER"` = your debuffs only). Because the - caster is best-effort, an aura whose cast we didn't observe is treated as - not-player-cast and excluded — so `PLAYER` can under-report auras that - predate login. +- **`PLAYER`** — restrict to auras that the player or the player's pet + cast. Combines with the range tokens (`"HARMFUL|PLAYER"` = your debuffs + only). The caster is known only for casts seen this session, so an aura + that predates login counts as not-player-cast and is excluded. Other tokens (`RAID` / `CANCELABLE` / `INCLUDE_NAME_PLATE_ONLY`) are accepted but no-op — they need engine systems (raid-dispel relevance, @@ -18671,10 +18669,10 @@ leading `!`. This build honors: - `HELPFUL` / `HARMFUL` — buffs / debuffs, by each aura's polarity flag rather than its slot number. With neither token the query returns both (the indexed getter defaults to helpful). -- `PLAYER` / `!PLAYER` — only auras the local player cast, or only - auras the player did not cast. Caster data comes from casts this - session, so an aura present before you saw it cast has no caster and - counts as not-player. +- `PLAYER` / `!PLAYER` — only auras the player or the player's pet cast, + or only the auras neither of them cast. Caster data comes from casts + this session, so an aura present before you saw it cast has no caster + and counts as not-player. - `DISPELLABLE` / `!DISPELLABLE` — only auras that can be dispelled, purged, or stolen (dispel type Magic, Curse, Disease, or Poison), or only auras that cannot. This is "can it be removed at all", not "can diff --git a/src/aura/Api.cpp b/src/aura/Api.cpp index 14672e43..5434328b 100644 --- a/src/aura/Api.cpp +++ b/src/aura/Api.cpp @@ -23,7 +23,8 @@ // mistaken for `PLAYER` and `!PLAYER` is a negation rather than a match. // Honored: `HELPFUL` / `HARMFUL` (the aura's real polarity, read however this // server encodes it — see `Aura::Data::IsSlotHarmful`), `PLAYER` / -// `!PLAYER` (caster == / != the local player, from the Aura::Source cache), +// `!PLAYER` (caster is / isn't the local player or their pet, from the +// Aura::Source cache), // `DISPELLABLE` / `!DISPELLABLE` (dispel type is / isn't one a // dispel/purge/steal can remove — Spell.dbc Dispel ∈ Magic/Curse/Disease/ // Poison, matching the server's DISPEL_ALL_MASK), and `CROWD_CONTROL` / diff --git a/src/aura/Data.cpp b/src/aura/Data.cpp index 3c6988e3..7dbe3647 100644 --- a/src/aura/Data.cpp +++ b/src/aura/Data.cpp @@ -361,16 +361,36 @@ int SlotInFilterOrder(Filter filter, int i) { return i; } +// The caster set the `PLAYER` filter selects: the player AND the player's +// pet. Modern defines the token as "auras that were cast by the player, or +// by the player's pet or vehicle" (`AuraUtil.AuraFilters.Player`) — there +// are no vehicles here, so the pair is player + pet. A pet's cast carries +// the PET's guid in the Aura::Source cache (that is who SMSG_SPELL_GO +// names), so a plain player compare drops e.g. a Hunter's own Serpent +// Sting off a `HARMFUL|PLAYER` query. The pet guid is a live engine global, +// so this stays two compares with no object resolve — it runs per slot. +// A caster of 0 is a cache miss, never a match (see CasterMode). +bool IsPlayerOrPetCaster(uint64_t casterGuid) { + if (casterGuid == 0) + return false; + if (casterGuid == Unit::Identity::PlayerGuid()) + return true; + const uint64_t pet = + Game::Read(static_cast(Offsets::VAR_PET_GUID)); + return pet != 0 && casterGuid == pet; +} + bool IsPlayerCast(const uint8_t *unit, int slot) { const uint32_t spellID = ReadSpellID(unit, slot); if (spellID == 0) return false; - const uint64_t player = Unit::Identity::PlayerGuid(); - return player != 0 && Attribute(UnitGuid(unit), spellID, slot).caster == player; + return IsPlayerOrPetCaster( + Attribute(UnitGuid(unit), spellID, slot).caster); } // Applies the PLAYER / !PLAYER caster restriction. `isPlayerCast` is the -// per-aura "was this cast by the local player" answer (false on a cache miss). +// per-aura "was this cast by the player or their pet" answer (false on a +// cache miss). bool CasterMatches(CasterMode caster, bool isPlayerCast) { switch (caster) { case CasterMode::PlayerOnly: return isPlayerCast; @@ -444,9 +464,8 @@ bool SlotMatchesFilter(const uint8_t *unit, int slot, Filter filter, // no slot to attribute by and the cache is consulted by (guid, spellID) alone. // A miss counts as "not the player" (same as IsPlayerCast). bool GroupIsPlayerCast(uint64_t guid, uint32_t spellID) { - const uint64_t player = Unit::Identity::PlayerGuid(); - return player != 0 && - Attribute(guid, spellID, Aura::Source::SLOT_UNBOUND).caster == player; + return IsPlayerOrPetCaster( + Attribute(guid, spellID, Aura::Source::SLOT_UNBOUND).caster); } int FindNthSlot(const uint8_t *unit, int oneBasedIndex, Filter filter, @@ -847,8 +866,7 @@ bool FallbackEligible(const uint8_t *unit, const Aura::Source::CachedAura &c, // Applies `match` to a cache entry. The entry carries its caster, so the caster // test is a plain GUID compare — no scan, nothing to defer. bool CachedMatches(const Aura::Source::CachedAura &c, const Match &match) { - return MatchesAura(match, c.casterGuid == Unit::Identity::PlayerGuid(), - c.spellId); + return MatchesAura(match, IsPlayerOrPetCaster(c.casterGuid), c.spellId); } // The eligible cache-fallback entries for `unit` under `filter`, in `Enumerate` diff --git a/src/aura/Data.h b/src/aura/Data.h index 303ee276..cdf6b5ef 100644 --- a/src/aura/Data.h +++ b/src/aura/Data.h @@ -63,11 +63,13 @@ enum class Filter { Helpful, Harmful }; enum class Emit { Table, Positional }; // Caster restriction from the `PLAYER` / `!PLAYER` aura filter tokens. -// `Any` = no restriction; `PlayerOnly` = only auras the local player cast -// (`PLAYER`); `NotPlayer` = only auras NOT cast by the local player -// (`!PLAYER`). Caster attribution comes from the `Aura::Source` cache; a -// cache miss counts as "not the player" (so `PlayerOnly` excludes it and -// `NotPlayer` includes it — matching `IsPlayerCast`'s miss semantics). +// `Any` = no restriction; `PlayerOnly` = only auras the local player OR the +// player's pet cast (`PLAYER`); `NotPlayer` = the complement (`!PLAYER`). +// The pet is part of the set by definition — modern documents the token as +// "cast by the player, or by the player's pet or vehicle". Caster +// attribution comes from the `Aura::Source` cache; a cache miss counts as +// "not the player" (so `PlayerOnly` excludes it and `NotPlayer` includes +// it — matching `IsPlayerCast`'s miss semantics). enum class CasterMode { Any, PlayerOnly, NotPlayer }; // Restriction from the `DISPELLABLE` / `!DISPELLABLE` aura filter tokens. @@ -148,13 +150,15 @@ int FindSlotBySpellID(const uint8_t *unit, uint32_t spellID, int FindSlotBySpellName(const uint8_t *unit, const char *spellName, const Filter *filter, Match match = {}); -// True iff the aura at `slot` was cast by the local player, per the -// `Aura::Source` cache. False on a cache miss (caster unknown) — so a -// PLAYER-filtered query excludes auras whose cast we didn't observe. +// True iff the aura at `slot` was cast by the local player or by the +// player's pet, per the `Aura::Source` cache. False on a cache miss (caster +// unknown) — so a PLAYER-filtered query excludes auras whose cast we didn't +// observe. bool IsPlayerCast(const uint8_t *unit, int slot); -// Applies a `CasterMode` to a per-aura "was cast by the local player" answer. -// `Any` → always true; `PlayerOnly` → the answer; `NotPlayer` → its negation. +// Applies a `CasterMode` to a per-aura "was cast by the player or their pet" +// answer. `Any` → always true; `PlayerOnly` → the answer; `NotPlayer` → its +// negation. bool CasterMatches(CasterMode caster, bool isPlayerCast); // True iff the spell's dispel type is one a dispel/purge/steal can remove —