// 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 . // Class metadata accessors backed by `ChrClasses.dbc`. #include "Game.h" #include "Offsets.h" #include namespace Classes::Info { namespace { const uint8_t *const *Records() { return *reinterpret_cast( static_cast(Offsets::VAR_CHRCLASSES_RECORDS)); } int Count() { return *reinterpret_cast( static_cast(Offsets::VAR_CHRCLASSES_COUNT)); } int LocaleIndex() { return *reinterpret_cast( static_cast(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( record + Offsets::OFF_CHRCLASSES_FILENAME); if (token == nullptr || *token == '\0') continue; const char *const *names = reinterpret_cast( 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