mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
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.
109 lines
3.9 KiB
C++
109 lines
3.9 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/>.
|
|
|
|
// Class metadata accessors backed by `ChrClasses.dbc`.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Classes::Info {
|
|
|
|
namespace {
|
|
|
|
const uint8_t *const *Records() {
|
|
return *reinterpret_cast<const uint8_t *const *const *>(
|
|
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_RECORDS));
|
|
}
|
|
|
|
int Count() {
|
|
return *reinterpret_cast<const int *>(
|
|
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_COUNT));
|
|
}
|
|
|
|
int LocaleIndex() {
|
|
return *reinterpret_cast<const int *>(
|
|
static_cast<uintptr_t>(Offsets::VAR_LOCALE_INDEX));
|
|
}
|
|
|
|
// `FillLocalizedClassList(table [, isFemale]) → table` — fills the
|
|
// passed-in table with `[classToken] = localizedName` pairs for every
|
|
// class in `ChrClasses.dbc`, then returns the same table for chaining.
|
|
//
|
|
// Modern API supports an optional `isFemale` boolean to fetch female-
|
|
// form names. Vanilla 1.12's ChrClasses.dbc has no separate female
|
|
// name array — see `OFF_CHRCLASSES_FILENAME` in Offsets.h for the
|
|
// layout argument. The arg is accepted for signature parity with
|
|
// modern callers but ignored: the same names are returned either way.
|
|
//
|
|
// Iterates 1..count (the records array is 1-based — index 0 is
|
|
// unused, matching the standard DBC convention). Sparse class IDs
|
|
// (e.g. classID 6 was unused in vanilla pre-Death-Knight) have a
|
|
// NULL record pointer; we skip those without writing the table.
|
|
int __fastcall Script_FillLocalizedClassList(void *L) {
|
|
if (Game::Lua::Type(L, 1) != Game::Lua::TYPE_TABLE) {
|
|
Game::Lua::Error(L,
|
|
"Usage: FillLocalizedClassList(table [, isFemale])");
|
|
return 0;
|
|
}
|
|
|
|
auto *records = Records();
|
|
if (records == nullptr) {
|
|
// DBC not loaded yet — return the table unchanged. Matches
|
|
// modern behavior of "fill what's available, don't crash".
|
|
Game::Lua::SetTop(L, 1);
|
|
return 1;
|
|
}
|
|
const int count = Count();
|
|
const int locale = LocaleIndex();
|
|
|
|
// Drop the optional `isFemale` arg (and any further junk) so the
|
|
// table sits alone at idx 1. Each loop iteration pushes key+value
|
|
// and `SetTable(L, 1)` consumes both, returning the stack to
|
|
// [table] before the next iteration.
|
|
Game::Lua::SetTop(L, 1);
|
|
for (int i = 1; i <= count; i++) {
|
|
const uint8_t *record = records[i];
|
|
if (record == nullptr)
|
|
continue;
|
|
|
|
const char *token = *reinterpret_cast<const char *const *>(
|
|
record + Offsets::OFF_CHRCLASSES_FILENAME);
|
|
if (token == nullptr || *token == '\0')
|
|
continue;
|
|
|
|
const char *const *names = reinterpret_cast<const char *const *>(
|
|
record + Offsets::OFF_CHRCLASSES_NAMES);
|
|
const char *name = names[locale];
|
|
if (name == nullptr || *name == '\0')
|
|
continue;
|
|
|
|
Game::Lua::PushString(L, token);
|
|
Game::Lua::PushString(L, name);
|
|
Game::Lua::SetTable(L, 1);
|
|
}
|
|
return 1; // return the same table the caller passed in
|
|
}
|
|
|
|
} // namespace
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterGlobalFunction("FillLocalizedClassList",
|
|
&Script_FillLocalizedClassList);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace Classes::Info
|