Commit Graph
5 Commits
Author SHA1 Message Date
Brues 14fa610bc8 feat(spellbook): add the skill-line, cast-count, and loss-of-control surface
Nine C_SpellBook functions, two C_Spell functions, and one event, all
backed by engine data the stock Lua surface never exposed:

- LEARNED_SPELL_IN_SKILL_LINE(spellID, skillLineIndex, isGuildPerkSpell),
  fired from the learn-spell hook under the engine's own
  LEARNED_SPELL_IN_TAB gate (notified AND appended to the book). The
  learn/unlearn co-hooks move from spell/Info.cpp to spell/Learn.cpp.
- GetNumSpellBookSkillLines / GetSpellBookSkillLineInfo /
  GetSpellBookItemSkillLineIndex / GetSkillLineIndexByID, reading the
  engine's tab array ({skillLineID, numSpells} entries at 0x00B71160).
  The info table calls the engine's own Script_GetSpellTabInfo for the
  name and icon.
- C_Spell.GetSpellCastCount / GetSpellBookItemCastCount: the minimum
  over reagent slots of floor(carried / required), where carried is
  equipped + bags 0..4. GetActionCount / IsConsumableAction are
  item-only in this client, so the count is computed, not mirrored.
- C_Spell.GetSpellLossOfControlCooldown /
  GetSpellBookItemLossOfControlCooldownInfo / ...Duration: the
  C_LossOfControl effect that blocks a given spell, shaped as a
  cooldown. Silence and pacify gate on Spell.dbc PreventionType
  (+0x294, verified against six known spells).
- IsClassTalentSpellBookItem: Talent.dbc rank spells plus trained
  higher ranks via SkillLineAbility's next-rank link (+0x20, verified
  on Mortal Strike). Talent::SpellSet now owns the talent spell set
  that GetCurrentLevelSpells already used.
- ContainsAnyDisenchantSpell: any known spell with effect 99.

Shared helpers added along the way: Spell::Lookup::SpellBankArgToBookType
and SpellbookItemArgsToID, Spell::Cooldown::Query, and
LossOfControl::LockoutForSpell.
2026-09-09 00:10:52 -05:00
Brues 39d22ac124 fix(time): centralize engine ms-tick reads in Time::Clock
The engine's OS millisecond counter (FUN_OS_TICKCOUNT_MS, same epoch
GetTime() scales by 0.001) is unsigned and wraps at 2^32 ms. Nine files
each re-derived the reader; several stored the tick into a signed int,
so past 2^31 ms (~24.9 days uptime) every timestamp went negative and
`startTime + duration` landed in the past -- callers saw every cooldown,
aura, and lockout as already elapsed. The same bug shipped three times
(the cooldown by-ID getters and C_LossOfControl).

Add one source of truth -- Time::Clock (src/time/Clock.h) -- with a
uint32 NowMs() and wrap-safe Reached/Remaining/Elapsed helpers, and route
every tick reader through it. No module re-derives the reader or hand-
rolls a `now < deadline` compare (which inverts across the wrap) anymore.

Also fixes the reported cooldown/LoC getters (unsigned out-params,
wrap-safe compares) and three latent instances of the same `now < end`
inversion found while sweeping: totem/Tracker's two timer getters and
aura/Source's cache-eviction pass.

Named Time::Clock, not Time::Tick, because a Time::Tick inner name
shadows the global Tick namespace (the WorldTick hook) from inside any
Time::* file.

Discovered by fuffc in #17.
2026-08-12 01:58:54 -05:00
Brues d9102bae3b Relicense source headers from LGPL to GPL v3
The repo was internally inconsistent: the LICENSE file is GPL v3 but every
src/ header carried the LGPL v3 notice and the README said "LGPL v3 or
later". LGPL was also the wrong fit — this is an injected mod plus a
bundled addon, not a library other code links against, so LGPL's linking
exception buys nothing.

It's also required: src/voicechat/Tts.cpp is ported from awesome_wotlk's
VoiceChat.cpp, which is GPL v3, and a derivative of GPL code cannot be
relicensed under more permissive terms. Dependencies stay compatible —
MinHook (BSD-2) and the nampower-mirrored packet shapes (BSD) are
GPL-compatible, and SAPI is covered by the system-library exception.

Swept "GNU Lesser General Public License" -> "GNU General Public License"
across all 257 src/ headers and changed the README license line to match
the GPL v3 LICENSE file. Comment-only; no build impact.
2026-06-29 16:38:16 -05:00
Brues 8e790e9221 Extract Spell::Arg, mirroring Item::Arg
Two callers were duplicating the spellIdentifier-resolution pattern
(number / hyperlink / name) and the NameToSpellID_t typedef:

  src/spell/Cooldown.cpp      → full pipeline via SpellIDFromLink +
                                 ResolveSpellID + NameToSpellID_t
  src/spell/CastNoToggle.cpp  → NameToSpellID_t + ResolveNameViaEngine
                                 helper for the macro-parser hook

Consolidated into Spell::Arg (new spell/Arg.h + Arg.cpp), parallel
to Item::Arg. Same `Resolved { spellID, name }` shape, same
strstr("spell:") link-parse approach. Three exports:

  Spell::Arg::Resolve(L, idx)         → Resolved
  Spell::Arg::ResolveSpellID(L, idx)  → int (auto-name-lookup)
  Spell::Arg::NameToSpellID(name)     → int (standalone)

C_Spell.GetSpellCooldown sheds the local SpellIDFromLink /
ResolveSpellID helpers; CastNoToggle sheds the duplicate typedef
plus its ResolveNameViaEngine wrapper. Net -50 lines, single place
to extend when we want to add link/name parsing to other C_Spell.*
endpoints later.

Verified: GetSpellCooldown still works for number, link, and name
inputs; CastSpellNoToggle macro-tag path still works.
2026-05-21 14:06:34 -05:00
Brues d2591b7f59 C_Spell.GetSpellCooldown
Modern table-shape cooldown query. Accepts spellID (number),
spell name (with optional (Rank N) suffix), or |Hspell:N|h
hyperlink. Returns a SpellCooldownInfo table:

  { startTime, duration, isEnabled, modRate }

or nil for spellIDs without a Spell.dbc row. modRate is hard-coded
to 1.0 (vanilla has no haste-on-cooldown mechanic); the
post-vanilla fields (activeCategory, timeUntilEndOfStartRecovery,
isOnGCD) are left unset.

Reads the engine's per-spell cooldown manager via
FUN_SPELL_QUERY_COOLDOWN (0x006E2EA0). Fixed the
(*outDuration, *outStart) argument order while doing this — the
typedef in Spell::Usable had it as (*outStart, *outDuration), which
worked accidentally because both fields are 0 when no cooldown is
active, but produced swapped values when a cooldown was running.
Round-tripped against Blink (1953) to verify the corrected order.
2026-05-21 13:59:13 -05:00