mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Add C_QuestLog.GetNumQuestObjectives(questID)
The quest's objective count — the length GetQuestDetails(questID) .requirements would have — read straight from the cache block with no Lua tables or strings materialized. nil when the quest isn't cached (same contract as GetQuestDetails). Exists because materializing full detail tables in a login-path loop is expensive at warm cache: GetQuestDetails copies description / objectives / completion text into Lua strings (~5 KB per quest). TurtleGuide's guide-load OIDX validation did exactly that for every tagged step — fine on the first (cold-cache) session, but once the quest cache was warm from questcache.wdb every subsequent login exhausted vanilla's fixed Lua memory pool and crashed the client in lmemPool.cpp:53. With this accessor the same validation costs a few dozen byte reads regardless of cache temperature.
This commit is contained in:
@@ -48,7 +48,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [MerchantFrame](docs/API.md#merchantframe) | `C_MerchantFrame.GetBuybackItemID`, `C_MerchantFrame.GetItemInfo`, `C_MerchantFrame.GetNumJunkItems`, `C_MerchantFrame.IsMerchantItemRefundable`, `C_MerchantFrame.IsSellAllJunkEnabled`, `C_MerchantFrame.SellAllJunkItems` |
|
||||
| [NamePlate](docs/API.md#nameplate) | `C_NamePlate.GetNamePlateForGUID`, `C_NamePlate.GetNamePlateForUnit`, `C_NamePlate.GetNamePlateGUIDs`, `C_NamePlate.GetNamePlates` |
|
||||
| [NameCache](docs/API.md#namecache) | `C_PlayerCache.GetPlayerInfoByName`, `C_PlayerCache.IsEnabled`, `C_PlayerCache.IsScanEnabled`, `C_PlayerCache.RememberPlayer`, `C_PlayerCache.SetEnabled`, `C_PlayerCache.SetScanEnabled`, `C_PlayerInfo.GUIDIsCreature`, `C_PlayerInfo.GUIDIsGameObject`, `C_PlayerInfo.GUIDIsPet`, `C_PlayerInfo.GUIDIsPlayer`, `GetPlayerInfoByGUID`, `UnitNameFromGUID` |
|
||||
| [Quest](docs/API.md#quest) | `C_QuestLog.GetQuestDetails`, `C_QuestLog.GetQuestIDForLogIndex`, `C_QuestLog.GetTitleForQuestID`, `C_QuestLog.IsOnQuest`, `C_QuestLog.IsQuestDataCachedByID`, `C_QuestLog.IsUnitOnQuest`, `C_QuestLog.RequestLoadQuestByID`, `GetQuestLogLeaderBoardID` |
|
||||
| [Quest](docs/API.md#quest) | `C_QuestLog.GetNumQuestObjectives`, `C_QuestLog.GetQuestDetails`, `C_QuestLog.GetQuestIDForLogIndex`, `C_QuestLog.GetTitleForQuestID`, `C_QuestLog.IsOnQuest`, `C_QuestLog.IsQuestDataCachedByID`, `C_QuestLog.IsUnitOnQuest`, `C_QuestLog.RequestLoadQuestByID`, `GetQuestLogLeaderBoardID` |
|
||||
| [Screen](docs/API.md#screen) | `GetPhysicalScreenSize` |
|
||||
| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.CastAtCursor`, `C_Spell.CastAtUnit`, `C_Spell.CastingInfo`, `C_Spell.ChannelInfo`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellMechanicByID`, `C_Spell.GetSpellName`, `C_Spell.GetSpellPowerCost`, `C_Spell.GetSpellRadius`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsAutoAttackSpell`, `C_Spell.IsCurrentSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.SpellHasRange`, `C_Spell.UnitCastingInfo`, `C_Spell.UnitChannelInfo`, `CancelSpellByName`, `CastSpellNoToggle`, `GetCraftSpellID`, `GetSpellInfo`, `GetSpellLink`, `GetSpellRadius`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell`, `SpellHasRange` |
|
||||
| [SpellBook](docs/API.md#spellbook) | `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSpellLevelLearned`, `C_SpellBook.GetSpellSkillLine`, `C_SpellBook.IsAutoAttackSpellBookItem`, `C_SpellBook.IsRangedAutoAttackSpellBookItem`, `FindSpellBookSlotByID` |
|
||||
|
||||
+21
@@ -291,6 +291,7 @@ build instructions.
|
||||
- [`C_QuestLog.IsUnitOnQuest(unit, questID)`](#c_questlogisunitonquestunit-questid)
|
||||
- [`C_QuestLog.GetTitleForQuestID(questID)`](#c_questloggettitleforquestidquestid)
|
||||
- [`C_QuestLog.GetQuestDetails(questID)`](#c_questloggetquestdetailsquestid)
|
||||
- [`C_QuestLog.GetNumQuestObjectives(questID)`](#c_questloggetnumquestobjectivesquestid)
|
||||
- [`C_QuestLog.IsQuestDataCachedByID(questID)`](#c_questlogisquestdatacachedbyidquestid)
|
||||
- [`GetQuestLogLeaderBoardID(objectiveIndex [, questIndex])`](#getquestlogleaderboardidobjectiveindex--questindex)
|
||||
|
||||
@@ -7135,6 +7136,26 @@ Reagents for Reclaimers Inc. level 40 (no tag)
|
||||
with `d.choiceItems = {{id=6793, count=1}, {id=6794, count=1}}`,
|
||||
`d.rewardMoney = 3500`, `d.rewardMoneyAtMaxLevel = 1920`, etc.
|
||||
|
||||
### `C_QuestLog.GetNumQuestObjectives(questID)`
|
||||
|
||||
The quest's objective count — exactly the length
|
||||
`GetQuestDetails(questID).requirements` would have — read straight from
|
||||
the quest cache with **no Lua tables or strings materialized**. Returns
|
||||
`nil` when the quest isn't cached (same contract as `GetQuestDetails`).
|
||||
|
||||
```lua
|
||||
local n = C_QuestLog.GetNumQuestObjectives(1467) -- 1
|
||||
```
|
||||
|
||||
Use this instead of `GetQuestDetails` when only the count matters —
|
||||
e.g. bounds-checking authored objective indices across every step of a
|
||||
guide at load time. `GetQuestDetails` copies the quest's description /
|
||||
objectives / completion text into Lua strings and builds ~20 table
|
||||
fields per call; harmless one at a time, but a login-path loop over
|
||||
hundreds of cached quests can put real pressure on vanilla's
|
||||
fixed-size Lua memory pool. This accessor costs a few dozen byte reads
|
||||
regardless of cache temperature.
|
||||
|
||||
### `C_QuestLog.IsQuestDataCachedByID(questID)`
|
||||
|
||||
Returns `true` if the quest's static data is currently in the
|
||||
|
||||
@@ -134,6 +134,43 @@ void PushRequirements(void *L, const uint8_t *data) {
|
||||
}
|
||||
}
|
||||
|
||||
// `C_QuestLog.GetNumQuestObjectives(questID)` — the quest's objective
|
||||
// count (the length `GetQuestDetails(questID).requirements` would have),
|
||||
// read straight from the cache block with zero Lua table/string
|
||||
// materialization. Exists so per-step validation loops (guide addons
|
||||
// bounds-checking objective indices at load time) stay O(1)-cheap even
|
||||
// with a warm quest cache — materializing full detail tables for hundreds
|
||||
// of quests inside a login-path loop can exhaust vanilla's fixed Lua
|
||||
// memory pool. Returns nil when the quest isn't cached (same contract as
|
||||
// GetQuestDetails).
|
||||
int __fastcall Script_GetNumQuestObjectives(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(L,
|
||||
"Usage: C_QuestLog.GetNumQuestObjectives(questID)");
|
||||
return 0;
|
||||
}
|
||||
const int questID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
if (questID <= 0)
|
||||
return 0;
|
||||
const uint8_t *data = Quest::Cache::Peek(static_cast<uint32_t>(questID));
|
||||
if (data == nullptr)
|
||||
return 0;
|
||||
|
||||
int count = 0;
|
||||
auto *npcOrGo = reinterpret_cast<const int32_t *>(
|
||||
data + Quest::Cache::OFF_REQUIRED_NPC_OR_GO);
|
||||
auto *items = reinterpret_cast<const uint32_t *>(
|
||||
data + Quest::Cache::OFF_REQUIRED_ITEM);
|
||||
for (int i = 0; i < Quest::Cache::OBJECTIVE_COUNT; ++i) {
|
||||
if (npcOrGo[i] != 0)
|
||||
++count;
|
||||
if (items[i] != 0)
|
||||
++count;
|
||||
}
|
||||
Game::Lua::PushNumber(L, static_cast<double>(count));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_GetQuestDetails(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::Error(L, "Usage: C_QuestLog.GetQuestDetails(questID)");
|
||||
@@ -245,6 +282,8 @@ int __fastcall Script_GetQuestDetails(void *L) {
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_QuestLog", "GetQuestDetails",
|
||||
&Script_GetQuestDetails);
|
||||
Game::Lua::RegisterTableFunction("C_QuestLog", "GetNumQuestObjectives",
|
||||
&Script_GetNumQuestObjectives);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user