mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-14 15:10:39 +00:00
66 lines
2.3 KiB
C++
66 lines
2.3 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 Lesser 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 Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// `C_Spell.GetSpellSubtext(spellIdentifier)` — the localized "Rank N"
|
|
// / "Passive" / "Racial Passive" string from `Spell.dbc.Rank[9]`.
|
|
// String-keyed input resolves by name through the spellbook (modern
|
|
// `SpellIdentifier` semantics); numeric input is a direct spellID
|
|
// lookup.
|
|
|
|
#include "Arg.h"
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "dbc/Lookup.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Spell::Subtext {
|
|
|
|
namespace {
|
|
|
|
// `Spell.dbc.Rank[9]` — same 9-slot locale-string array shape as the
|
|
// adjacent `Name[9]` field. Defined locally; sibling modules
|
|
// (`Info.cpp`, `Tooltip.cpp`, `macro/Spell.cpp`) carry the same
|
|
// constant — promoting to `Offsets.h` is a future refactor.
|
|
constexpr int OFF_SPELL_RANK = 0x204;
|
|
|
|
} // namespace
|
|
|
|
static int __fastcall Script_GetSpellSubtext(void *L) {
|
|
const int spellID = Spell::Arg::ResolveSpellID(L, 1);
|
|
if (spellID <= 0) {
|
|
Game::Lua::PushNil(L);
|
|
return 1;
|
|
}
|
|
const char *subtext = DBC::LocalizedField(Offsets::VAR_SPELL_RECORDS,
|
|
Offsets::VAR_SPELL_RECORD_COUNT,
|
|
static_cast<uint32_t>(spellID),
|
|
OFF_SPELL_RANK);
|
|
if (subtext == nullptr) {
|
|
Game::Lua::PushNil(L);
|
|
return 1;
|
|
}
|
|
Game::Lua::PushString(L, subtext);
|
|
return 1;
|
|
}
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellSubtext",
|
|
&Script_GetSpellSubtext);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace Spell::Subtext
|