From 492c70d15690a91da0a66ca6d27cb0652fcc4fef Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Wed, 24 Jun 2026 16:57:28 -0500 Subject: [PATCH] Use applied (caster-modified) duration for AuraData.duration duration came from a base Spell.dbc/SpellDuration.dbc lookup while expirationTime came from the Aura::Source cache computed with the caster's duration modifiers. For a talented DoT (e.g. 2/2 Improved Shadow Word: Pain, 18s -> 24s) the two disagreed, so remaining (expirationTime - GetTime()) exceeded duration -- impossible for a single aura. Cache the applied durationMs alongside expirationMs in Aura::Source and have Push prefer it for the duration field, keeping the two consistent (remaining <= duration). Falls back to the base DBC value on a cache miss. --- docs/API.md | 2 +- src/aura/Data.cpp | 13 +++++++++++-- src/aura/Source.cpp | 15 +++++++++------ src/aura/Source.h | 16 +++++++++------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/docs/API.md b/docs/API.md index b0bfede1..9d176bb5 100644 --- a/docs/API.md +++ b/docs/API.md @@ -9270,7 +9270,7 @@ selects. | `dispelName` | string | `"Magic"` / `"Curse"` / `"Disease"` / `"Poison"` (from `SpellDispelType.dbc`), or `""` if non-dispellable | | `isHelpful` | boolean | true for slot < 32 | | `isHarmful` | boolean | true for slot >= 32 | -| `duration` | number | base applied duration in seconds, looked up via `Spell.dbc → SpellDuration.dbc` with level scaling. Talent / glyph duration extensions (Improved PW:F, etc.) aren't reflected here — those are baked into `expirationTime` on the caster's side. Returns 0 for spells flagged "no duration" (passives, paladin auras, infinite buffs) | +| `duration` | number | applied duration in seconds. When the aura's cast was observed (in the `Aura::Source` cache), this is the caster-modified duration — talent/glyph extensions like Improved Shadow Word: Pain included — so it stays consistent with `expirationTime` (`remaining ≤ duration`). On a cache miss it falls back to the base `Spell.dbc → SpellDuration.dbc` value with level scaling. Returns 0 for spells flagged "no duration" (passives, paladin auras, infinite buffs) | | `expirationTime` | number | for `unit == "player"`, read from the engine's player-buff table at `0x00BC6040` (same data `GetPlayerBuffTimeLeft` returns). For any other unit, taken from the `Aura::Source` cache (cast time + duration captured from `SMSG_SPELL_GO`; see below). `0` when neither source has it. `expirationTime - GetTime()` gives the true remaining time | | `sourceUnit` | string | unit token of the caster (`"player"`, `"raid7"`, `"nameplate1"`, …), resolved from the `Aura::Source` cache. `nil` if the cast wasn't observed or the caster maps to no current token | | `sourceGUID` | string | caster's `"0x…"` GUID string from the same cache. **ClassicAPI extension — not a retail `AuraData` field.** Set whenever a caster is known, including when `sourceUnit` is `nil` (caster left token range). Stable for the session, unlike the volatile nameplate token; doubles as a unit token under SuperWoW. `nil` on a cache miss | diff --git a/src/aura/Data.cpp b/src/aura/Data.cpp index bd49cf31..ca988d70 100644 --- a/src/aura/Data.cpp +++ b/src/aura/Data.cpp @@ -242,7 +242,8 @@ bool IsPlayerCast(const uint8_t *unit, int slot) { return false; uint64_t casterGuid = 0; uint32_t expMs = 0; - if (!Aura::Source::Get(UnitGuid(unit), spellID, &casterGuid, &expMs)) + uint32_t durMs = 0; + if (!Aura::Source::Get(UnitGuid(unit), spellID, &casterGuid, &expMs, &durMs)) return false; return casterGuid != 0 && casterGuid == Unit::Identity::PlayerGuid(); } @@ -426,9 +427,17 @@ void Push(void *L, const uint8_t *unit, int slot) { if (spellID != 0) { uint64_t casterGuid = 0; uint32_t expMs = 0; - if (Aura::Source::Get(UnitGuid(unit), spellID, &casterGuid, &expMs)) { + uint32_t durMs = 0; + if (Aura::Source::Get(UnitGuid(unit), spellID, &casterGuid, &expMs, + &durMs)) { if (expirationTime == 0.0 && expMs != 0) expirationTime = static_cast(expMs) * 0.001; + // Prefer the applied (caster-modified) duration so `duration` + // stays consistent with `expirationTime` — otherwise a talented + // DoT (e.g. Improved Shadow Word: Pain) shows remaining time + // exceeding the base `duration`. + if (durMs != 0) + duration = static_cast(durMs) * 0.001; if (casterGuid != 0) { // `sourceUnit` is a token (nil when the caster maps to no // current token); `sourceGUID` is the raw "0x..." GUID and diff --git a/src/aura/Source.cpp b/src/aura/Source.cpp index 5f2fc62f..7018bafc 100644 --- a/src/aura/Source.cpp +++ b/src/aura/Source.cpp @@ -104,6 +104,7 @@ struct Entry { uint64_t casterGuid; uint32_t spellId; uint32_t expirationMs; // 0 = infinite / unknown duration + uint32_t durationMs; // applied duration (incl. caster mods); 0 = none bool used; }; @@ -112,7 +113,7 @@ Entry g_cache[kCacheSize]; int g_writeCursor = 0; void Store(uint64_t targetGuid, uint32_t spellId, uint64_t casterGuid, - uint32_t expirationMs) { + uint32_t expirationMs, uint32_t durationMs) { if (targetGuid == 0 || spellId == 0 || casterGuid == 0) return; @@ -121,6 +122,7 @@ void Store(uint64_t targetGuid, uint32_t spellId, uint64_t casterGuid, if (e.used && e.targetGuid == targetGuid && e.spellId == spellId) { e.casterGuid = casterGuid; e.expirationMs = expirationMs; + e.durationMs = durationMs; return; } } @@ -128,13 +130,13 @@ void Store(uint64_t targetGuid, uint32_t spellId, uint64_t casterGuid, const uint32_t now = NowMs(); for (auto &e : g_cache) { if (!e.used || (e.expirationMs != 0 && now >= e.expirationMs)) { - e = {targetGuid, casterGuid, spellId, expirationMs, true}; + e = {targetGuid, casterGuid, spellId, expirationMs, durationMs, true}; return; } } Entry &slot = g_cache[g_writeCursor]; g_writeCursor = (g_writeCursor + 1) % kCacheSize; - slot = {targetGuid, casterGuid, spellId, expirationMs, true}; + slot = {targetGuid, casterGuid, spellId, expirationMs, durationMs, true}; } // Drop entries whose timed aura has elapsed so the table doesn't fill with @@ -196,11 +198,11 @@ void __fastcall SpellGo_h(uint64_t *itemGUID, uint64_t *casterGUID, if (numTargets == 0) { // No explicit hit list (self-cast with caster-implicit target). - Store(caster, spellId, caster, expirationMs); + Store(caster, spellId, caster, expirationMs, durationMs); return; } for (int i = 0; i < numTargets; ++i) - Store(targets[i], spellId, caster, expirationMs); + Store(targets[i], spellId, caster, expirationMs, durationMs); } const Game::HookAutoRegister _hook{Offsets::FUN_SPELL_GO, @@ -210,13 +212,14 @@ const Game::HookAutoRegister _hook{Offsets::FUN_SPELL_GO, } // namespace bool Get(uint64_t unitGuid, uint32_t spellId, uint64_t *outCaster, - uint32_t *outExpirationMs) { + uint32_t *outExpirationMs, uint32_t *outDurationMs) { if (unitGuid == 0 || spellId == 0) return false; for (const auto &e : g_cache) { if (e.used && e.targetGuid == unitGuid && e.spellId == spellId) { *outCaster = e.casterGuid; *outExpirationMs = e.expirationMs; + *outDurationMs = e.durationMs; return true; } } diff --git a/src/aura/Source.h b/src/aura/Source.h index f5245a11..67c711a1 100644 --- a/src/aura/Source.h +++ b/src/aura/Source.h @@ -31,13 +31,15 @@ namespace Aura::Source { -// Looks up the cached caster + expiration for the aura `spellId` currently -// on the unit identified by `unitGuid`. Returns true and fills the out -// params on a hit. `*outExpirationMs` is an absolute `GetTickCount`-epoch -// timestamp (0 = unknown / infinite-duration aura); `*outCaster` is the -// caster's 64-bit GUID (never 0 on a hit). Returns false on a miss or for -// zero inputs. +// Looks up the cached caster + timing for the aura `spellId` currently on +// the unit identified by `unitGuid`. Returns true and fills the out params +// on a hit. `*outExpirationMs` is an absolute `GetTickCount`-epoch timestamp +// (0 = unknown / infinite-duration aura); `*outDurationMs` is the applied +// duration including the caster's modifiers (talents etc.; 0 = none) — use +// it for the `duration` field so it stays consistent with `expirationTime`; +// `*outCaster` is the caster's 64-bit GUID (never 0 on a hit). Returns false +// on a miss or for zero inputs. bool Get(uint64_t unitGuid, uint32_t spellId, uint64_t *outCaster, - uint32_t *outExpirationMs); + uint32_t *outExpirationMs, uint32_t *outDurationMs); } // namespace Aura::Source