Files
ClassicAPI/src/spell/Reagents.cpp
T
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

73 lines
2.6 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.
// `C_Spell.GetSpellReagents(spellIdentifier)` — modern accessor for
// a spell's reagent list. Returns an array of `{itemID, count}`
// tables, one per non-empty reagent slot. Reagents apply mostly to
// crafting recipes and a few class spells (Soulshatter / Soulstone
// items, paladin Symbol of Kings, etc.).
//
// Reads directly out of `Spell.dbc` at the documented offsets:
// - `+0x110`: int32 itemID[8]
// - `+0x130`: int32 count[8]
// Empty slots have itemID == 0; iteration stops at the first empty
// slot, matching how the engine itself walks the reagent table
// (`Script_GetTradeSkillReagentInfo` etc.).
#include "Arg.h"
#include "Lookup.h"
#include "Game.h"
#include "Offsets.h"
#include <cstdint>
namespace Spell::Reagents {
namespace {
int __fastcall Script_C_Spell_GetSpellReagents(void *L) {
const int spellID = Spell::Arg::ResolveSpellID(L, 1);
if (spellID <= 0)
return 0;
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return 0;
auto *ids = reinterpret_cast<const int32_t *>(
record + Offsets::OFF_SPELL_REAGENT_ID);
auto *counts = reinterpret_cast<const int32_t *>(
record + Offsets::OFF_SPELL_REAGENT_COUNT);
Game::Lua::NewTable(L); // outer array
int nextKey = 1;
for (int i = 0; i < Offsets::SPELL_RECIPE_MAX_REAGENTS; ++i) {
if (ids[i] == 0)
break; // engine convention: stop at first empty slot
Game::Lua::PushNumber(L, static_cast<double>(nextKey++));
Game::Lua::NewTable(L); // {itemID = ?, count = ?}
Game::Lua::SetFieldNumber(L, "itemID", static_cast<double>(ids[i]));
Game::Lua::SetFieldNumber(L, "count", static_cast<double>(counts[i]));
Game::Lua::SetTable(L, -3);
}
return 1;
}
} // namespace
static void RegisterLuaFunctions() {
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellReagents",
&Script_C_Spell_GetSpellReagents);
}
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
} // namespace Spell::Reagents