Files
ClassicAPI/src/turtle/DurationMods.cpp
T
Brues fdbe66b057 fix(aura): let a duration rule edit an aura its own trigger creates
Turtle's Bestial Wrath gives the hunter's pet Scent of Blood for 18s, but
C_UnitAuras reported 8s and then dropped the timer entirely while the buff
was still up.

Server-side (tortoise-wow spell_hunter_bestial_wrath) Bestial Wrath neither
applies the aura nor carries its duration on the wire: effect 0 is
TRIGGER_SPELL(Scent of Blood, 52995), and the script then stretches the
holder that trigger just created via SetAuraMaxDuration/SetAuraDuration.
Both are plain field writes, and 1.12's only duration packet is scoped to an
aura-bearer that is a PLAYER, which a pet is not -- so the client never hears
the 18s and keeps the 8s base it computed when the aura landed. Exactly the
class of edit Aura::Source's duration rules exist to mirror; two things had
to change before one could express it.

The affected-aura selector demanded a SpellFamilyFlags overlap, and every
Turtle custom spell carries flags of 0 (308 in the hunter family alone), so
no mask could ever name this aura. It now takes a family-flag overlap and/or
a SpellIconID, at least one of the two -- an icon is shared across a spell's
whole rank ladder, so it stays as rank-proof as a flag, and icon 2245 picks
out exactly the four Scent of Blood records and nothing else. Registrars
reject the mask-0 + icon-0 rule that would match a whole class family, and
RefreshDurationByFamily takes the same invariant so the two entry points
cannot disagree about what they match.

A trigger can also CREATE the aura it edits, which the immediate-apply model
could not see. The trigger's SMSG_SPELL_GO arrives before the triggered
cast's, so editing at trigger time either matches nothing or is overwritten
moments later when the triggered cast stores its own base duration -- the
edit is lost either way. Idempotent ops now ARM the target as well, and the
next matching store re-applies the edit, from the cast path or the
application path, whichever the aura arrives on. Only refresh and set arm:
re-running those lands on the same value, while reduce would shave twice and
remove would kill an aura that was legitimately re-applied, so Conflagrate
behaves exactly as before.

The rule reads Bestial Wrath's own duration from the client's spell data
instead of hardcoding the server's 18s, so a rebalance that patches the DBC
carries over on its own.

Fixes brues-code/pfUI#50
2026-09-02 19:39:59 -05:00

135 lines
6.2 KiB
C++

// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
// Turtle WoW server-side aura duration mods that the client can't hear.
// These mirror server mechanics that change a DoT's remaining time on another
// unit with no client-visible packet (verified in tortoise-wow: the edit goes
// through SetAuraDuration / RefreshHolder, which notifies only the aura's
// target-if-a-player, never the observing caster). We can't hear the change,
// but we see the triggering cast's SMSG_SPELL_GO, so Aura::Source mirrors the
// edit on the cached entry. A rule is a { exact trigger spellID -> affected
// aura by SpellFamilyName plus a family-flag overlap and/or a SpellIconID }
// pair, applied by Aura::Source::ApplyDurationModifiers.
//
// Conflagrate -> Immolate: shave 3s (Turtle keeps Immolate ticking, -3s;
// stock's full-consume removes it, which
// OnAuraRemoved evicts, so the rule is
// harmless there)
// Molten Blast -> Flame Shock: refresh (RefreshHolder -> reset to full)
// Bestial Wrath -> Scent of Blood: set to Bestial Wrath's own duration
//
// Gated on Turtle::Detected() and registered once (a WorldTick latch, since the
// gate reads a FrameXML global only present in-world). Stock's Conflagrate
// still exists, so keeping the gate preserves the previous Lua behaviour
// exactly; Molten Blast's spell IDs don't exist off Turtle anyway.
#include "Offsets.h"
#include "aura/Source.h"
#include "spell/Lookup.h"
#include "turtle/Detect.h"
#include "tick/WorldTick.h"
#include <cstdint>
namespace Turtle::DurationMods {
namespace {
// SpellFamilyName + family-flag bits of the affected auras (SpellClassMask):
// Immolate is warlock CF_WARLOCK_IMMOLATE (bit 2); Flame Shock is shaman
// CF_SHAMAN_FLAME_SHOCK (bit 28).
constexpr uint32_t kWarlock = 5;
constexpr uint32_t kShaman = 11;
constexpr uint64_t kImmolateFlag = 0x4;
constexpr uint64_t kFlameShockFlag = 0x10000000;
// Bestial Wrath -> Scent of Blood (hunter). The talent's proc puts Scent of
// Blood on the pet for its own 8s; casting Bestial Wrath then stretches that
// SAME holder to Bestial Wrath's length. Server-side (tortoise-wow
// spell_hunter_bestial_wrath) it is a bare
// `holder->SetAuraMaxDuration/SetAuraDuration` on the pet's existing holder —
// both are plain field writes that send nothing, and the one duration packet
// 1.12 has is scoped to an aura-bearer that is a PLAYER, which a pet is not.
// So the client keeps showing the 8s it computed at application and the timer
// simply runs out under a buff that is still up.
//
// The trigger is visible, though, and Bestial Wrath's implicit target is
// TARGET_UNIT_CASTER_PET, so the pet is in its SMSG_SPELL_GO hit list and the
// standard rule machinery reaches the right unit. If the pet has no Scent of
// Blood the server returns without doing anything; we mirror that for free,
// since no cache entry means no match.
//
// Selected by ICON, not by family flags: every Turtle custom spell carries
// SpellFamilyFlags of 0, so no mask can name this aura, while icon 2245 picks
// out exactly the four Scent of Blood records in the hunter family and nothing
// else (client DBC verified) — and it keeps picking them if Turtle adds a rank.
constexpr uint32_t kHunter = 9;
constexpr uint32_t kBestialWrath = 19574;
constexpr uint32_t kScentOfBloodIcon = 2245;
// The server hardcodes 18s; Bestial Wrath's own DBC duration agrees, so we
// read the DBC and keep this only for a record we can't resolve.
constexpr int32_t kBestialWrathFallbackMs = 18000;
// Bestial Wrath's own base duration, straight from the engine's duration
// helper (`skipMod` = base: the server applies no caster mods to the value it
// writes). Reading it instead of hardcoding means a Turtle rebalance that
// patches the client's spell data carries over on its own.
int32_t BestialWrathDurationMs() {
const uint8_t *rec =
Spell::Lookup::RecordForID(static_cast<int>(kBestialWrath));
if (rec == nullptr)
return kBestialWrathFallbackMs;
using GetDuration_t = int(__fastcall *)(const uint8_t *spellRecord,
int unit, char skipMod);
const int ms = reinterpret_cast<GetDuration_t>(
static_cast<uintptr_t>(Offsets::FUN_GET_SPELL_DURATION))(
rec, 0, /*skipMod*/ 1);
return ms > 0 ? ms : kBestialWrathFallbackMs;
}
bool g_registered = false;
void RegisterAll() {
constexpr uint32_t kConflagrate[] = {17962, 18930, 18931, 18932};
for (uint32_t id : kConflagrate)
Aura::Source::AddDurationMod(id, kWarlock, kImmolateFlag, /*icon*/ 0,
Aura::Source::DURATION_MOD_REDUCE,
/*valueMs*/ 3000);
constexpr uint32_t kMoltenBlast[] = {36916, 36917, 36918,
36919, 36920, 36921};
for (uint32_t id : kMoltenBlast)
Aura::Source::AddDurationMod(id, kShaman, kFlameShockFlag, /*icon*/ 0,
Aura::Source::DURATION_MOD_REFRESH,
/*valueMs*/ 0);
Aura::Source::AddDurationMod(kBestialWrath, kHunter, /*mask*/ 0,
kScentOfBloodIcon,
Aura::Source::DURATION_MOD_SET,
BestialWrathDurationMs());
}
void OnTick() {
if (g_registered || !Turtle::Detected())
return;
RegisterAll();
g_registered = true;
}
const Tick::WorldTick::AutoSubscribe _tickSub{&OnTick};
} // namespace
} // namespace Turtle::DurationMods