mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-10 20:07:37 +00:00
docs/API.md is 18.7k lines and its anchors are signature slugs, so editing a signature breaks the 281 internal and 88 README links into it. Blizzard solved the same problem by shipping the API as data plus a browser addon, and warcraft.wiki.gg renders those same tables. One set of descriptors can feed all three. Each registration now carries one next to it: typed arguments and returns, nilability, defaults, and a sentence. Events, enumerations and returned table shapes are described the same way. No Script_* body changed. Game.h gains namespace Game::Doc (Field with Req/Opt/Vararg, FieldList, Function, Method, Structure, Event) and a trailing descriptor argument on all six Game::Lua::Register* plus Event::Custom::AutoReserve. api/Documentation.cpp records every registration on the first pass of each Lua state and seals it, so /reload re-registers but records nothing and the environment comes from which pass saw the name. Export is lazy: nothing is materialized until C_APIDocumentation.GetSystem asks for one system, because eager export would build thousands of tables per reload for a slash command. _classicapi_UndocumentedAPI lists what still has no descriptor. AddOns/!!!ClassicAPI/APIDocumentation/ ports Blizzard_APIDocumentation's eight files. Named /classicapi, not /api: the browser holds only what ClassicAPI adds, so /api would have implied the whole 1.12 surface. Two deliberate differences from the retail source, both noted in the file headers: a system search also matches its namespace, since that is the name people type; and an undocumented function says so, because an empty signature otherwise reads as a real one. LinkUtil gains the SetItemRef to LinkUtil.ProcessLink dispatch. That handler registry was dead code; a new link type now registers a handler instead of stacking another SetItemRef override. Also defines assertsafe there, which was undefined and only mattered once the function went live. Documented: the C_Spell and C_SpellBook surface, the spell globals, both spellbook enumerations, the 13 UNIT_SPELLCAST_* events, GameTooltip as the widget-method example and C_Glue as the glue and mixed-environment example. 66 of 692 function registrations. tools/New-ApiDocSkeletons.ps1 emits paste-ready skeletons to make the rest of the sweep tractable. Verified in game: the browser lists, searches, and prints detail; links render and click through; right-click copies and shift-click dumps.
135 lines
5.5 KiB
C++
135 lines
5.5 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/>.
|
|
|
|
// `C_Spell.GetSpellDispelType` / `IsNextMeleeSpell` / `ResetsMeleeSwing` —
|
|
// read raw Spell.dbc fields straight off the record so pfUI can drop its
|
|
// nampower `GetSpellRecField` dependency.
|
|
//
|
|
// The Spell.dbc record fields we read live in `Offsets.h` (the single source
|
|
// of truth for the record layout): `OFF_SPELL_DISPEL_TYPE` (+0x10),
|
|
// `OFF_SPELL_RECORD_ATTRIBUTES` (+0x18), `OFF_SPELL_RECORD_ATTRIBUTES_EX2`
|
|
// (+0x20), `OFF_SPELL_RECORD_INTERRUPT_FLAGS` (+0x54).
|
|
//
|
|
// Melee rules (server core, Spell.h / Spell.cpp):
|
|
// on-next-swing = Attributes & (0x04 | 0x400) — two bits (Spell.h:434)
|
|
// resets swing = (InterruptFlags & 0x08) && !(AttributesEx2 & 0x20000)
|
|
// (Spell.cpp:3964 + Spell.h:441)
|
|
|
|
#include "Arg.h"
|
|
#include "Lookup.h"
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Spell::RecordFields {
|
|
|
|
namespace {
|
|
|
|
// Attributes bits 0x04 (SPELL_ATTR_ON_NEXT_SWING) and 0x400
|
|
// (SPELL_ATTR_ON_NEXT_SWING_2) both mark an on-next-melee-swing ability
|
|
// (server Spell.h:434 tests the pair).
|
|
constexpr uint32_t SPELL_ATTR_ON_NEXT_SWING = 0x04 | 0x400;
|
|
// InterruptFlags bit 0x08 = SPELL_INTERRUPT_FLAG_AUTOATTACK.
|
|
constexpr uint32_t SPELL_INTERRUPT_AUTOATTACK = 0x08;
|
|
// AttributesEx2 bit 0x20000 = NOT_RESET_AUTO_ACTIONS — exempts the spell
|
|
// from the swing reset the AUTOATTACK interrupt flag would otherwise cause.
|
|
constexpr uint32_t SPELL_ATTR_EX2_NOT_RESET_AUTO_ACTIONS = 0x20000;
|
|
|
|
uint32_t ReadField(const uint8_t *rec, int offset) {
|
|
return *reinterpret_cast<const uint32_t *>(rec + offset);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// C_Spell.GetSpellDispelType(spellId) -> number. 0 for a non-dispellable
|
|
// spell or an unknown ID.
|
|
static int __fastcall Script_GetSpellDispelType(void *L) {
|
|
const uint8_t *rec = Spell::Lookup::RecordForID(Spell::Arg::ResolveSpellID(L, 1));
|
|
Game::Lua::PushNumber(
|
|
L, rec != nullptr
|
|
? static_cast<double>(ReadField(rec, Offsets::OFF_SPELL_DISPEL_TYPE))
|
|
: 0.0);
|
|
return 1;
|
|
}
|
|
|
|
// C_Spell.IsNextMeleeSpell(spellId) -> bool. True for on-next-swing abilities
|
|
// (Heroic Strike, Maul, Cleave, Raptor Strike, Slam).
|
|
static int __fastcall Script_IsNextMeleeSpell(void *L) {
|
|
const uint8_t *rec = Spell::Lookup::RecordForID(Spell::Arg::ResolveSpellID(L, 1));
|
|
const bool onNextSwing =
|
|
rec != nullptr &&
|
|
(ReadField(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) & SPELL_ATTR_ON_NEXT_SWING) != 0;
|
|
Game::Lua::PushBool(L, onNextSwing);
|
|
return 1;
|
|
}
|
|
|
|
// C_Spell.ResetsMeleeSwing(spellId) -> bool. True when casting the spell
|
|
// resets the melee swing timer (AUTOATTACK interrupt flag set and the
|
|
// NOT_RESET_AUTO_ACTIONS exemption clear).
|
|
static int __fastcall Script_ResetsMeleeSwing(void *L) {
|
|
const uint8_t *rec = Spell::Lookup::RecordForID(Spell::Arg::ResolveSpellID(L, 1));
|
|
const bool resets =
|
|
rec != nullptr &&
|
|
(ReadField(rec, Offsets::OFF_SPELL_RECORD_INTERRUPT_FLAGS) &
|
|
SPELL_INTERRUPT_AUTOATTACK) != 0 &&
|
|
(ReadField(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2) &
|
|
SPELL_ATTR_EX2_NOT_RESET_AUTO_ACTIONS) == 0;
|
|
Game::Lua::PushBool(L, resets);
|
|
return 1;
|
|
}
|
|
|
|
// --- Documentation ----------------------------------------------------------
|
|
|
|
const Game::Doc::Field kSpellArgs[] = {
|
|
Game::Doc::Req("spellID", "SpellIdentifier",
|
|
"A spell ID, spell link, or spell name."),
|
|
};
|
|
|
|
const Game::Doc::Field kDispelTypeRets[] = {
|
|
Game::Doc::Req("dispelType", "number",
|
|
"1 magic, 2 curse, 3 disease, 4 poison; 0 when nothing removes it."),
|
|
};
|
|
const Game::Doc::Function kGetSpellDispelType{
|
|
"Which kind of dispel removes the effects of a spell.", kSpellArgs, kDispelTypeRets};
|
|
|
|
const Game::Doc::Field kNextMeleeRets[] = {
|
|
Game::Doc::Req("isNextMelee", "bool",
|
|
"True when the ability lands on your next weapon swing."),
|
|
};
|
|
const Game::Doc::Function kIsNextMeleeSpell{
|
|
"Whether the ability waits for your next weapon swing instead of casting.",
|
|
kSpellArgs, kNextMeleeRets};
|
|
|
|
const Game::Doc::Field kResetsSwingRets[] = {
|
|
Game::Doc::Req("resetsSwing", "bool",
|
|
"True when casting the spell starts the swing timer again."),
|
|
};
|
|
const Game::Doc::Function kResetsMeleeSwing{
|
|
"Whether casting the spell starts your melee swing timer again.",
|
|
kSpellArgs, kResetsSwingRets};
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellDispelType",
|
|
&Script_GetSpellDispelType, &kGetSpellDispelType);
|
|
Game::Lua::RegisterTableFunction("C_Spell", "IsNextMeleeSpell",
|
|
&Script_IsNextMeleeSpell, &kIsNextMeleeSpell);
|
|
Game::Lua::RegisterTableFunction("C_Spell", "ResetsMeleeSwing",
|
|
&Script_ResetsMeleeSwing, &kResetsMeleeSwing);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace Spell::RecordFields
|