mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
* docs(container): describe the C_Container functions
Descriptors for the 17 undocumented C_Container functions and the
ItemQuestInfo structure. SwapItems, MoveItem, AutoStoreItem,
GetContainerItemCharges, GetContainerItemRepairCost and
IsContainerItemOpenable are not in retail's API and are marked as
ClassicAPI extensions.
* docs(aura): describe the C_UnitAuras functions
Descriptors for the 16 undocumented C_UnitAuras functions, plus the
AuraData structure that GetAuraDataByAuraInstanceID already named but
nothing defined. The four positional getters share the Classic Era
UnitAura return list.
* docs(equipmentset): describe the C_EquipmentSet functions
Descriptors for the 18 undocumented C_EquipmentSet functions,
GameTooltip:SetEquipmentSet, and the EQUIPMENT_SETS_CHANGED,
EQUIPMENT_SWAP_PENDING and EQUIPMENT_SWAP_FINISHED events. They
describe what the functions return here, which differs from retail in
places: an icon path, not a file ID; numMissing, not numLost;
GetIgnoredSlots lists slot numbers.
* docs(faction): describe the reputation functions
Descriptors for GetFactionIDByIndex, GetFactionInfoByID,
GetFactionParentID, the 17 undocumented C_Reputation functions, the
FactionData structure, and the FACTION_STANDING_CHANGED event.
C_Reputation.IsFactionInactive and SetFactionInactive mirror stock
globals, but no Blizzard client has them under C_Reputation, so they
are marked as ClassicAPI extensions.
* docs(player): describe the player functions and events
Descriptors for C_PlayerInfo.CanUseItem, GetName, GetClass, GetRace,
GetSex and IsConnected; GetPlayerFacing, GetPlayerInfoByGUID,
UnitNameFromGUID and IsLoggedIn; the four C_PlayerCache functions; and
the PLAYER_EQUIPMENT_CHANGED, UPDATE_INVENTORY_DURABILITY,
HEARTHSTONE_BOUND and six PLAYER_STARTED/STOPPED_MOVING, LOOKING and
TURNING events. They describe what the functions return here: sex is 2
or 3, not the UnitSex enum, and GetPlayerInfoByGUID has no level.
C_PlayerCache is ours, so its functions are marked as extensions.
GetCritChance and GetRangedCritChance move from system "PaperDollInfo"
to "PlayerGlobals": PaperDollInfo is the C_PaperDollInfo namespace's
system, and a global must not share it.
* docs(map): describe the C_Map functions
Descriptors for the 30 undocumented C_Map and C_MapExplorationInfo
functions, the UiMapDetails, UiMapLayerInfo, UiMapPoint,
AreaTriggerInfo, MapOverlayInfo and MapOverlayTile structures, and the
USER_WAYPOINT_UPDATED event. mapType is a plain number because no
Enum.UIMapType is registered, and flags is always 0. GetAreaTriggerInfo,
GetAreaTriggers, GetAreas, GetMapAreaIDs, GetMapOverlays and
GetUnexploredMapTextures are marked as ClassicAPI extensions.
* docs(loot): describe the C_Loot and C_LootHistory functions
Descriptors for the six C_Loot functions and the four C_LootHistory
functions, the LootableUnit, ScannedCorpse and ScannedLootItem
structures, and the LOOT_SCAN_COMPLETED and three LOOT_HISTORY_* events.
Every C_Loot function here and C_LootHistory.Clear are marked as
ClassicAPI extensions; Blizzard's C_Loot has none of them.
* docs(sound): describe the sound functions
Descriptors for the six undocumented C_Sound functions, the PlaySound,
PlaySoundFile, StopSound, MuteSoundFile and UnmuteSoundFile globals, the
PlaySoundParams and RecentSoundFile structures, the ItemSoundType and
Vocalerrorsounds enums, and the SOUNDKIT_FINISHED event.
C_Sound.PlaySound's second argument is documented as the channel name it
takes here, not retail's UISoundSubType. GetRecentSoundFiles is marked as
a ClassicAPI extension.
* docs(console): describe the console functions
Descriptors for ConsoleExec, ConsoleEcho, ConsoleIsActive,
ConsoleGetColorFromType, ConsoleGetFontHeight, SetConsoleKey,
CalculateStringEditDistance, ConsoleGetAllCommands and
ConsolePrintAllMatchingCommands, the ConsoleCommandInfo structure, and
the ConsoleCommandType and ConsoleCategory enums. The game and glue
registrations of each function share one descriptor. ConsoleExec and
ConsoleEcho return nothing here, and SetConsoleKey takes a key code.
* docs(voicechat): describe the text-to-speech functions
Descriptors for the four C_VoiceChat text-to-speech functions, the ten
C_TTSSettings functions, the VoiceTtsVoiceType structure, and the five
VOICE_CHAT_TTS_* events. The event payloads follow the shapes the
client sends here. GetSpeechVoiceID, SetVoiceOptionByName and
RefreshVoices are marked as ClassicAPI extensions.
* docs(api): correct entries that drifted from the code
Fixes entries that the descriptor pass found to differ from what the
functions do: C_PlayerInfo.GetSex never returns 1, the name and race
getters need a visible unit for unit locations too, RememberPlayer
raises on missing arguments, mutes outlive a reload, scan results fill
in during a scan, LootHistory names can be nil and ROLL_CHANGED can
carry playerIndex 0, GetMapRectOnMap's fallback and Kalimdor ID, dungeon
maps have no parent, and GetBestMapForUnit gives zones, not subzones.
HEARTHSTONE_BOUND and the player input-state events now describe only
their behavior; the packet handlers, engine addresses and hook notes
are gone.
* docs(loot): say when LOOT_HISTORY_FULL_UPDATE fires
The comment above the loot-history event names said FULL_UPDATE was
never fired from C++, but FireFullUpdate sends it when a roll opens a
new item, when the 128-item ring evicts the oldest entry, and from
C_LootHistory.Clear.
* docs(api): describe behavior, not implementation
API.md is the contract for addon authors, so it no longer names engine
addresses, struct offsets, internal type and field names, packet
opcodes, hook mechanics, source files or our C++ modules, and drops
provenance notes and remarks about which client version lacks what.
Where that text carried a real behavior, the behavior stays in plain
words: "when the server answers" in place of an opcode, "ignores the
merchant and repair cursor modes" in place of the function it skips.
Also: C_Spell.GetSpellPowerCost no longer calls GetSpellInfo's cost the
base cost (both are the effective cost), the C_Spell cast-info note no
longer calls the functions player-only, the name-cache intro says the
game empties its cache on each world entry, and examples use a generic
realm name.
* docs(item): describe the item functions
Descriptors for the 95 undocumented item registrations: the C_Item
readers, lock, use and equip calls, the GetItemInfo family, the
Get*ItemID companions, the GameTooltip item methods, the ItemData,
ItemSetInfo and ItemEnchantInfo structures, the InventoryType,
ItemClass and ItemQuality enums, and the ITEM_DATA_LOAD_RESULT and
GET_ITEM_INFO_RECEIVED events. They describe what the functions return
here where it differs from retail: GetItemSetInfo returns a table,
GetWeaponEnchantInfo returns twelve values, and RequestLoadItemData
returns whether the request went out. GetItemIDForItemInfo's return is
now optional, since input that names no item returns nothing.
* docs(unit): describe the unit functions
Descriptors for the 49 undocumented unit functions, the PowerType enum,
and the PLAYER_FOCUS_CHANGED and UPDATE_SHAPESHIFT_FORM events. They
describe what the functions do here: UnitHealthMissing has no
usePredicted argument, IsFalling and IsSwimming take no unit,
UnitPowerType returns no color, and UnitPosition keeps its Y-first
return order.
* docs(baselib): describe the Lua library additions
Descriptors for the Lua 5.1 functions added to the game's Lua: select,
unpack with a range, xpcall with arguments, collectgarbage options,
debugstack, the math hyperbolics, fmod and modf, string.match, gmatch,
reverse, byte, split, join and trim with their global aliases, and
strreplace, plus Mixin and CreateFromMixins. strreplace is the one
ClassicAPI extension; retail binds the other aliases itself.
* docs(api): correct entries the item and unit descriptors contradicted
UnitIsMinion, UnitIsPet and UnitIsOtherPlayersPet raise on a string that
is not a unit token; only a token that names no unit, or a non-string,
returns false. GetItemCooldown does not take item names. A full request
queue makes RequestLoadItemData return false. GetInventoryItemID needs a
player, so pets and totems return nil. GetItemNameByID keeps a link's
random suffix. GetInventoryItemRepairCost raises on a non-number slot.
The Get*ItemID intro no longer calls the companions stock functions.
Also settles two entries that contradicted themselves: the summoning
ritual's channel events do fire, and GetSecondsUntilDailyReset counts to
UTC midnight. C_PlayerInfo.UnitPosition gets a line under UnitPosition.
* fix(docs): map the remaining widget method registries to systems
Methods registered on the Button, Slider, StatusBar, MessageFrame,
SimpleHTML, ScrollingMessageFrame, PlayerModel and DressUpModel
registries had descriptors, but the browser listed them as an unmapped
registry. The five Blizzard has use its names (SimpleButtonAPI and so
on); the other three are named the same way.
* docs(ui): describe the frame, texture and input functions
Descriptors for the texture, region, frame, button, editbox and tooltip
methods ClassicAPI adds, the C_Texture atlas, C_XMLUtil, C_ColorUtil,
C_UIColor and C_NamePlate functions, the binding, modifier-key, cursor
and screen globals, the AtlasInfo, XML template and DBColorExport
structures, Enum.UICursorType, and the nameplate, cursor and
MODIFIER_STATE_CHANGED events. IsMouseButtonDown, GetMouseButtonName and
GetCursorDelta move to the InputGlobals system.
* docs(spell): describe the spell, action and creature functions
Descriptors for the remaining spell, spellbook, tracking, action bar,
talent, totem, loss-of-control, macro, combat, tradeskill, targeting,
GUID, class, C_CreatureInfo and C_GameObjectInfo registrations, their
structures, and the LEARNED_SPELL_IN_SKILL_LINE, PLAYER_TOTEM_UPDATE,
LOSS_OF_CONTROL_*, CREATURE_DATA_LOAD_RESULT and
GAMEOBJECT_DATA_LOAD_RESULT events. The IsItemAction,
HasBonusActionBar and IsStackableAction globals move from the
C_ActionBar system to ActionBarGlobals.
* docs(world): describe the gossip, quest, social and vendor functions
Descriptors for C_GossipInfo, the friends and /who functions, C_QuestLog
and the quest globals, C_TaxiMap, C_MerchantFrame, C_AuctionHouse.PostItem,
the mail, group, instance, coin-text, chat, character-order and
expansion globals, their structures, the FlightPath enums, and the
QUEST_DATA_LOAD_RESULT and AUCTION_MULTISELL_* events. Globals that
named a namespaced system (QuestLog, PartyInfo, CurrencyInfo) move to
the matching *Globals system, and GetCoinText gets separate global and
C_CurrencyInfo descriptors.
* docs(lua): describe the cvar, encoding, time, addon and Lua functions
Descriptors for the cvar, C_EncodingUtil, C_DateAndTime, C_Timer,
C_AddOns, coroutine, table, security-account, event, script, clipboard
and hooksecurefunc registrations, the CalendarTime and SavedAccountInfo
structures, and the Base64Variant, CompressionMethod and
AddOnSecurityStatus enums.
* docs(api): correct entries the last descriptor pass contradicted
SelectOption takes an optional password for boxCoded options.
IsWhoQueryPending clears when the answer arrives, not after a timer, and
SendWhoQueryByName raises on a nil or non-string name. SetTalentByID
raises on a nil or non-number talentID. The gossip getters also read the
quest greeting window. GetPoint returns three values for an anchor with
no relative frame. RegisterAtlas's rectangle is optional.
GetSecondsUntilDailyReset returns nothing before login.
CopyToClipboard is a Blizzard function, not an extension, and always
returns the length. ConvertHSLToRGB, DoesTemplateExist,
GetNamePlateForGUID, GetNamePlateGUIDs and SetModernScriptArgs are
labelled as ClassicAPI extensions, and C_AuctionHouse.PostItem is
described as retail's function plus a numStacks argument.
IsAddOnLoadable's descriptor notes the nil reason for an unknown name.
* docs: start every function and event summary with a verb
Function summaries now read "Returns …", "Returns whether …" and so on,
not a bare "Whether …", "The …" or "How many …", and event summaries
read "Fires when …" instead of describing the past ("A cast ended").
A few two-sentence summaries become one sentence, and the two range
check toggles say what they do rather than "Used with …".
* refactor(lua): require a descriptor on every registration
The registrars and Event::Custom::AutoReserve no longer default their
doc argument, so a function, method table, enum, alias or custom event
registered without a descriptor does not compile. The _classicapi_
debug functions, which the documentation export skips, pass nullptr
explicitly.
* docs: stop calling namespaced Blizzard globals extensions
A function is a ClassicAPI extension only when no Blizzard client ships
it under any name. C_XMLUtil.DoesTemplateExist (the global
DoesTemplateExist), C_PlayerInfo.UnitPosition, C_Reputation.
IsFactionInactive and SetFactionInactive, and C_Macro.CreateMacro and
EditMacro are Blizzard globals under a namespace Blizzard never gave
them, so their descriptors and API.md no longer label them extensions.
* refactor(baselib): register newproxy through the registrars
newproxy set its global by hand so its C closure could carry the weak
table of valid metatables as an upvalue, which left it the one global
with no descriptor. The weak table now lives in the registry (made on
first use in each Lua state), so newproxy is a plain C function that
RegisterGlobalFunction and RegisterGlueFunction bind with a descriptor.
Behavior is unchanged.
* docs(api): drop the C++ module name from the aura timing heading
* docs(api): fix descriptor errors found in review
- UnitSpellTargetName is a Blizzard function (Unit system): drop the
extension flag and file it under UnitGlobals.
- Flag the ClassicAPI-only spell functions as extensions: GetSpellRadius
(global and C_Spell), GetSpellReagents, GetSpellDispelType,
IsNextMeleeSpell, ResetsMeleeSwing, GetSpellMechanicByID,
GetSpellEffectMechanics, GetSpellEffectInfo, GetSpellRequiredTargetLevel,
GetSpellLevelInfo and C_SpellBook.GetPlayerSpellsByAura. No Blizzard
client ships any of them.
- Name the Region registry SimpleScriptRegionAPI, as retail does, and
make the no-counterpart comment cover all three rows it applies to.
- Start the VOICE_CHAT_TTS_SPEAK_TEXT_UPDATE summary with a verb.
- Type GetCurrentChatEvent's guid return as WOWGUID, matching
GetCurrentChatGUID.
- Say that the itemInfo argument also accepts an item string.
* docs(api): document the methods the source count missed
_classicapi_UndocumentedAPI() still listed 23 names. Each sat in a method
array that already had a partial doc array, so the source count read it
as documented.
- GameTooltip: SetUnitAura, SetUnit, GetUnit, GetUnitGUID, HasUnit.
GetUnitGUID and HasUnit are extensions; no Blizzard client ships them.
- FontString: GetStringHeight, GetUnboundedStringWidth, GetWrappedWidth,
GetNumLines, GetLineHeight, IsTruncated, SetMaxLines, GetMaxLines,
GetFieldSize.
- ModelScene actor: GetObjectType, IsObjectType, GetName, GetParent,
HasScript, GetScript, SetScript, HookScript, as our object methods
return them (1/nil, no HookScript result).
- GetAverageItemLevel moves to PaperDollInfoGlobals: PaperDollInfo is the
C_PaperDollInfo namespace.
The in-game check now reports 0.
432 lines
20 KiB
C++
432 lines
20 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/>.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "dbc/Lookup.h"
|
|
#include "item/Arg.h"
|
|
#include "item/BagFamily.h"
|
|
#include "item/Data.h"
|
|
#include "item/ID.h"
|
|
#include "item/Icon.h"
|
|
#include "item/Link.h"
|
|
#include "item/Location.h"
|
|
#include "item/Record.h"
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
|
|
namespace Item::Info {
|
|
|
|
static const char *PushedOrEmpty(const char *s) { return (s != nullptr && s[0] != 0) ? s : ""; }
|
|
|
|
static int CurrentLocaleIndex() { return Game::Read<int>(Offsets::VAR_LOCALE_INDEX); }
|
|
|
|
static const char *LookupItemClassName(uint32_t classID) {
|
|
return PushedOrEmpty(DBC::LocalizedField(
|
|
Offsets::VAR_ITEMCLASS_RECORDS, Offsets::VAR_ITEMCLASS_COUNT,
|
|
classID, Offsets::OFF_ITEMCLASS_NAMES));
|
|
}
|
|
|
|
static const char *LookupItemSubClassName(uint32_t classID, uint32_t subClassID) {
|
|
const int count = Game::Read<int>(Offsets::VAR_ITEMSUBCLASS_COUNT);
|
|
if (count <= 0)
|
|
return "";
|
|
auto *records = Game::Read<const uint8_t *>(Offsets::VAR_ITEMSUBCLASS_RECORDS);
|
|
if (records == nullptr)
|
|
return "";
|
|
const int locale = CurrentLocaleIndex();
|
|
for (int i = 0; i < count; i++) {
|
|
const uint8_t *record = records + i * Offsets::OFF_ITEMSUBCLASS_RECORD_STRIDE;
|
|
if (*reinterpret_cast<const uint32_t *>(record + 0x00) != classID)
|
|
continue;
|
|
if (*reinterpret_cast<const uint32_t *>(record + 0x04) != subClassID)
|
|
continue;
|
|
// Mirror Script_GetItemInfo's fallback chain at 0x48E311..0x48E32C:
|
|
// try the verbose name first, fall back to the short name.
|
|
const char *verbose = Game::Read<const char *>(
|
|
record, Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4);
|
|
if (verbose != nullptr && verbose[0] != 0)
|
|
return verbose;
|
|
const char *shortName = Game::Read<const char *>(
|
|
record, Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4);
|
|
return PushedOrEmpty(shortName);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
static const char *LookupInvType(uint32_t invType) {
|
|
if (invType > Offsets::INVTYPE_TABLE_MAX_INDEX)
|
|
return "";
|
|
auto **table = reinterpret_cast<const char **>(Offsets::VAR_INVTYPE_STRING_TABLE);
|
|
return PushedOrEmpty(table[invType]);
|
|
}
|
|
|
|
// `GetItemInfoInstant` is the modern "synchronous, never blocks" item
|
|
// info call. In modern WoW the trailing 6 fields come from client-side
|
|
// `Item-sparse.db2` and so the call always returns the full 7-tuple.
|
|
// 1.12 has no client-side item DB — those fields live only in the
|
|
// network-fed `DBCache_ItemStats`. We mirror the contract by:
|
|
// - always returning the itemID (echoed from input) so callers using
|
|
// `GetItemInfoInstant(link_or_id)` as an ID extractor never see nil
|
|
// - returning the remaining 6 fields from the cache when present,
|
|
// nil when not (preserving the 7-tuple shape)
|
|
// - not warming the cache; "Instant" implies no side effects. Callers
|
|
// that need the full info should use `GetItemInfo`, which already
|
|
// triggers the warmup via the `Script_GetItemInfo` hook.
|
|
static int __fastcall Script_GetItemInfoInstant(void *L) {
|
|
const int itemID = Item::Arg::ResolveItemID(L, 1);
|
|
if (itemID <= 0)
|
|
return 0;
|
|
|
|
Game::Lua::PushNumber(L, static_cast<double>(itemID));
|
|
|
|
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
|
if (record == nullptr) {
|
|
for (int i = 0; i < 6; ++i)
|
|
Game::Lua::PushNil(L);
|
|
return 7;
|
|
}
|
|
|
|
const uint32_t classID =
|
|
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_CLASS);
|
|
const uint32_t subClassID =
|
|
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_SUBCLASS);
|
|
const uint32_t displayInfoID =
|
|
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
|
|
const uint32_t invType =
|
|
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE);
|
|
|
|
char iconPath[260];
|
|
if (!Item::Icon::PathForDisplayInfoID(displayInfoID, iconPath, sizeof(iconPath)))
|
|
iconPath[0] = 0;
|
|
|
|
Game::Lua::PushString(L, LookupItemClassName(classID));
|
|
Game::Lua::PushString(L, LookupItemSubClassName(classID, subClassID));
|
|
Game::Lua::PushString(L, LookupInvType(invType));
|
|
Game::Lua::PushString(L, iconPath);
|
|
Game::Lua::PushNumber(L, static_cast<double>(classID));
|
|
Game::Lua::PushNumber(L, static_cast<double>(subClassID));
|
|
return 7;
|
|
}
|
|
|
|
// `C_Item.GetItemIDForItemInfo(itemInfo)` — the itemID alone, from the same
|
|
// resolver `GetItemInfoInstant` echoes: an itemID, an `"item:N"` string or an
|
|
// item link. ItemMixin:GetItemID falls back to it when GetItemInfoInstant
|
|
// returns nothing. Returns nothing for input that names no item.
|
|
static const Game::Doc::Field kGetItemIDForItemInfoArgs[] = {
|
|
Game::Doc::Req("itemInfo", "ItemInfo"),
|
|
};
|
|
static const Game::Doc::Field kGetItemIDForItemInfoRets[] = {
|
|
Game::Doc::Opt("itemID", "number", nullptr,
|
|
"Nil for an item name or input that names no item."),
|
|
};
|
|
static const Game::Doc::Function kGetItemIDForItemInfo{
|
|
"Returns the item ID of an item ID, item string or item link.", kGetItemIDForItemInfoArgs,
|
|
kGetItemIDForItemInfoRets};
|
|
|
|
static int __fastcall Script_GetItemIDForItemInfo(void *L) {
|
|
const int itemID = Item::Arg::ResolveItemID(L, 1);
|
|
if (itemID <= 0)
|
|
return 0;
|
|
Game::Lua::PushNumber(L, static_cast<double>(itemID));
|
|
return 1;
|
|
}
|
|
|
|
// Pushes the icon path for `itemID` and returns 1, or returns 0 (= nil
|
|
// to Lua) if the item isn't cached, the displayInfoID is missing, or
|
|
// the icon record's path slot is empty. Shared by all three
|
|
// icon-accessor entry points.
|
|
static int PushIconForItemID(void *L, int itemID) {
|
|
if (itemID <= 0)
|
|
return 0;
|
|
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
|
if (record == nullptr) {
|
|
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
|
return 0;
|
|
}
|
|
const uint32_t displayInfoID = Game::Read<uint32_t>(
|
|
record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
|
|
char iconPath[260];
|
|
if (!Item::Icon::PathForDisplayInfoID(displayInfoID, iconPath, sizeof(iconPath)))
|
|
return 0;
|
|
Game::Lua::PushString(L, iconPath);
|
|
return 1;
|
|
}
|
|
|
|
// `GetItemIcon(itemID)` — global, takes a numeric itemID only. Modern
|
|
// WoW returns a fileID:number; we surface the icon path string since
|
|
// 1.12 has no fileID system. Direct passthrough to
|
|
// `texture:SetTexture(...)`.
|
|
static int __fastcall Script_GetItemIcon(void *L) {
|
|
if (!Game::Lua::IsNumber(L, 1)) {
|
|
Game::Lua::Error(L, "Usage: GetItemIcon(itemID)");
|
|
return 0;
|
|
}
|
|
return PushIconForItemID(L, static_cast<int>(Game::Lua::ToNumber(L, 1)));
|
|
}
|
|
|
|
// `C_Item.GetItemIcon(itemLocation)` — table-shape ItemLocation form.
|
|
// Routes through `Item::Location::Resolve` → CGItem → itemID, then the
|
|
// same cache lookup as the other variants.
|
|
static int __fastcall Script_C_Item_GetItemIcon(void *L) {
|
|
if (!Item::Location::IsLocationArg(L, 1)) {
|
|
Game::Lua::Error(L, "Usage: C_Item.GetItemIcon(itemLocation)");
|
|
return 0;
|
|
}
|
|
const int itemID = Item::ID::FromCGItem(Item::Location::Resolve(L, 1));
|
|
return PushIconForItemID(L, itemID);
|
|
}
|
|
|
|
// `C_Item.GetItemIconByID(itemInfo)` — accepts numeric itemID or
|
|
// `"item:NN"` string (full chat links work too via the same parser
|
|
// `GetItemInfoInstant` uses).
|
|
static int __fastcall Script_C_Item_GetItemIconByID(void *L) {
|
|
return PushIconForItemID(L, Item::Arg::ResolveItemID(L, 1));
|
|
}
|
|
|
|
// `C_Item.GetItemFamily(item)` — returns the BagFamily bitmask for an
|
|
// item (modern encoding: `1 << (ID-1)`), or `nil` if the item isn't
|
|
// in the cache. Used by auto-routing addons that decide which
|
|
// specialty bag a looted item should land in.
|
|
//
|
|
// Accepts a numeric `itemID` or a string containing `"item:NNN"` (full
|
|
// chat links work) — same parser as `GetItemInfoInstant`.
|
|
//
|
|
// **Auto-warmup on cache miss.** Returns nil for uncached items but
|
|
// kicks off the cache fill in the background, so a follow-up call
|
|
// after `GET_ITEM_INFO_RECEIVED` lands the value. Mirrors the
|
|
// observed 1.15 behavior (nil first, value after retry) — the engine
|
|
// itself triggers the load. We diverge from 1.15 in one detail: we
|
|
// fire `GET_ITEM_INFO_RECEIVED` when the data arrives (matching our
|
|
// other implicit-warmup paths like `GetItemInfo` and `SetItemByID`),
|
|
// whereas 1.15's `GetItemFamily` is a silent fill. Consistency
|
|
// within our DLL's event surface > faithful 1.15 mimicry — addons
|
|
// that already listen for the event get notified for free.
|
|
//
|
|
// Modern WoW returns 0 for items the cache lookup fails on; we return
|
|
// nil so callers can distinguish "item not cached" from "item exists
|
|
// but has family 0 (general-purpose)". Both are safe to treat as "no
|
|
// preference" but keeping them distinct helps debugging.
|
|
//
|
|
// 1.12 vanilla server data leaves the `m_bagFamily` field empty on the
|
|
// **bags/quivers** themselves — Soul/Herb/Enchanting/Engineering bags AND
|
|
// quivers/ammo pouches all read 0. Individual loot items do carry the
|
|
// field reliably (arrows, bullets, shards, herbs return their proper raw
|
|
// IDs). For a bag whose field is empty we recover the family from its
|
|
// class + subclass (the same signal the "Soul Bag" tooltip line uses), so
|
|
// a Felcloth Bag reports the Soul Shard family (0x4), a quiver 0x1, an
|
|
// ammo pouch 0x2 — see `Item::BagFamily`.
|
|
static int __fastcall Script_C_Item_GetItemFamily(void *L) {
|
|
const int itemID = Item::Arg::ResolveItemID(L, 1);
|
|
if (itemID <= 0)
|
|
return 0;
|
|
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
|
if (record == nullptr) {
|
|
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
|
return 0;
|
|
}
|
|
// Family field if populated, else derived from the container subclass
|
|
// (Turtle leaves bags' m_bagFamily at 0 — see Item::BagFamily).
|
|
Game::Lua::PushNumber(
|
|
L, static_cast<double>(Item::BagFamily::BitmaskForRecord(record)));
|
|
return 1;
|
|
}
|
|
|
|
// `C_Item.GetItemInfo(itemInfo)` — the full modern info tuple, sourced
|
|
// entirely from the cached `ItemStats_C` record (+ the class/subclass/invtype
|
|
// DBC name lookups this file already does for `GetItemInfoInstant`). Accepts
|
|
// a numeric itemID, an `"item:NNN"` string, or a full chat link — same parser
|
|
// as `GetItemInfoInstant`.
|
|
//
|
|
// Returns (18 values):
|
|
// itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType,
|
|
// itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice,
|
|
// classID, subclassID, bindType, expansionID, setID, isCraftingReagent,
|
|
// itemDescription
|
|
//
|
|
// `expansionID` is always 0 (vanilla) and `isCraftingReagent` always false
|
|
// (no such flag in 1.12's item data); `setID` is nil when the item has no
|
|
// set. On a cache miss it warms the cache and returns nothing (nil) —
|
|
// the value lands on a retry after `GET_ITEM_INFO_RECEIVED`,
|
|
// matching the modern async contract.
|
|
static int __fastcall Script_C_Item_GetItemInfo(void *L) {
|
|
const Item::Arg::Resolved arg = Item::Arg::Resolve(L, 1);
|
|
const int itemID = arg.itemID;
|
|
if (itemID <= 0)
|
|
return 0;
|
|
|
|
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
|
if (record == nullptr) {
|
|
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
|
return 0; // nil this call; GET_ITEM_INFO_RECEIVED fires when ready
|
|
}
|
|
|
|
auto u32 = [record](int off) {
|
|
return *reinterpret_cast<const uint32_t *>(record + off);
|
|
};
|
|
const uint32_t quality = u32(Offsets::OFF_ITEMSTATS_QUALITY);
|
|
const uint32_t itemLevel = u32(Offsets::OFF_ITEMSTATS_ITEM_LEVEL);
|
|
const uint32_t reqLevel = u32(Offsets::OFF_ITEMSTATS_REQUIRED_LEVEL);
|
|
const uint32_t classID = u32(Offsets::OFF_ITEMSTATS_CLASS);
|
|
const uint32_t subClassID = u32(Offsets::OFF_ITEMSTATS_SUBCLASS);
|
|
const uint32_t stackCount = u32(Offsets::OFF_ITEMSTATS_STACKABLE);
|
|
const uint32_t invType = u32(Offsets::OFF_ITEMSTATS_INVENTORY_TYPE);
|
|
const uint32_t displayInfoID = u32(Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
|
|
const uint32_t sellPrice = u32(Offsets::OFF_ITEMSTATS_SELL_PRICE);
|
|
const uint32_t bindType = u32(Offsets::OFF_ITEMSTATS_BONDING);
|
|
const uint32_t setID = u32(Offsets::OFF_ITEMSTATS_ITEM_SET);
|
|
const char *name = Game::Read<const char *>(
|
|
record, Offsets::OFF_ITEMSTATS_NAME);
|
|
const char *description = Game::Read<const char *>(
|
|
record, Offsets::OFF_ITEMSTATS_DESCRIPTION);
|
|
|
|
// Apply the link's random suffix ("... of the Owl") to both the name and
|
|
// the reconstructed link when the input carried one (arg.suffix); with no
|
|
// suffix these reduce to the base name / plain `item:N:0:0:0` link.
|
|
char suffixedName[128];
|
|
const char *displayName =
|
|
Item::Link::NameFromIDSuffix(static_cast<uint32_t>(itemID), arg.suffix,
|
|
suffixedName, sizeof(suffixedName))
|
|
? suffixedName
|
|
: name;
|
|
|
|
char iconPath[260];
|
|
if (!Item::Icon::PathForDisplayInfoID(displayInfoID, iconPath, sizeof(iconPath)))
|
|
iconPath[0] = 0;
|
|
char link[256];
|
|
const bool haveLink = Item::Link::BasicFromIDSuffix(static_cast<uint32_t>(itemID),
|
|
arg.suffix, link, sizeof(link));
|
|
|
|
Game::Lua::PushString(L, PushedOrEmpty(displayName)); // 1 itemName
|
|
if (haveLink)
|
|
Game::Lua::PushString(L, link); // 2 itemLink
|
|
else
|
|
Game::Lua::PushNil(L);
|
|
Game::Lua::PushNumber(L, static_cast<double>(quality)); // 3 itemQuality
|
|
Game::Lua::PushNumber(L, static_cast<double>(itemLevel)); // 4 itemLevel
|
|
Game::Lua::PushNumber(L, static_cast<double>(reqLevel)); // 5 itemMinLevel
|
|
Game::Lua::PushString(L, LookupItemClassName(classID)); // 6 itemType
|
|
Game::Lua::PushString(L, LookupItemSubClassName(classID, subClassID)); // 7 itemSubType
|
|
Game::Lua::PushNumber(L, static_cast<double>(stackCount)); // 8 itemStackCount
|
|
Game::Lua::PushString(L, LookupInvType(invType)); // 9 itemEquipLoc
|
|
Game::Lua::PushString(L, iconPath); // 10 itemTexture
|
|
Game::Lua::PushNumber(L, static_cast<double>(sellPrice)); // 11 sellPrice
|
|
Game::Lua::PushNumber(L, static_cast<double>(classID)); // 12 classID
|
|
Game::Lua::PushNumber(L, static_cast<double>(subClassID)); // 13 subclassID
|
|
Game::Lua::PushNumber(L, static_cast<double>(bindType)); // 14 bindType
|
|
Game::Lua::PushNumber(L, 0.0); // 15 expansionID (classic)
|
|
if (setID != 0)
|
|
Game::Lua::PushNumber(L, static_cast<double>(setID)); // 16 setID
|
|
else
|
|
Game::Lua::PushNil(L);
|
|
Game::Lua::PushBool(L, false); // 17 isCraftingReagent
|
|
Game::Lua::PushString(L, PushedOrEmpty(description)); // 18 itemDescription
|
|
return 18;
|
|
}
|
|
|
|
// --- Documentation ----------------------------------------------------------
|
|
|
|
static const Game::Doc::Field kItemInfoArgs[] = {
|
|
Game::Doc::Req("itemInfo", "ItemInfo", "An item ID, an item string or an item link."),
|
|
};
|
|
|
|
static const Game::Doc::Field kGetItemInfoRets[] = {
|
|
Game::Doc::Req("itemName", "cstring", "With the random suffix of the link, if it has one."),
|
|
Game::Doc::Opt("itemLink", "cstring"),
|
|
Game::Doc::Req("itemQuality", "number", "An Enum.ItemQuality value."),
|
|
Game::Doc::Req("itemLevel", "number"),
|
|
Game::Doc::Req("itemMinLevel", "number"),
|
|
Game::Doc::Req("itemType", "cstring", "The localized item class name."),
|
|
Game::Doc::Req("itemSubType", "cstring", "The localized item subclass name."),
|
|
Game::Doc::Req("itemStackCount", "number"),
|
|
Game::Doc::Req("itemEquipLoc", "cstring",
|
|
"An INVTYPE_ key, or \"\" when the item is not worn."),
|
|
Game::Doc::Req("itemTexture", "string", "The icon's texture path, not a file ID."),
|
|
Game::Doc::Req("sellPrice", "number", "In copper."),
|
|
Game::Doc::Req("classID", "number"),
|
|
Game::Doc::Req("subclassID", "number"),
|
|
Game::Doc::Req("bindType", "number"),
|
|
Game::Doc::Req("expansionID", "number", "Always 0."),
|
|
Game::Doc::Opt("setID", "number", nullptr, "Nil when the item is not part of a set."),
|
|
Game::Doc::Req("isCraftingReagent", "bool", "Always false."),
|
|
Game::Doc::Req("itemDescription", "cstring", "\"\" when the item has no description."),
|
|
};
|
|
static const Game::Doc::Function kGetItemInfo{
|
|
"Returns the item's static data; returns nothing and asks the server when the data is not "
|
|
"loaded.",
|
|
kItemInfoArgs, kGetItemInfoRets};
|
|
|
|
static const Game::Doc::Field kGetItemInfoInstantRets[] = {
|
|
Game::Doc::Req("itemID", "number"),
|
|
Game::Doc::Opt("itemType", "cstring", nullptr,
|
|
"The localized item class name; nil, like the fields after it, when the "
|
|
"item's data is not loaded."),
|
|
Game::Doc::Opt("itemSubType", "cstring"),
|
|
Game::Doc::Opt("itemEquipLoc", "cstring", nullptr,
|
|
"An INVTYPE_ key, or \"\" when the item is not worn."),
|
|
Game::Doc::Opt("icon", "string", nullptr, "The icon's texture path, not a file ID."),
|
|
Game::Doc::Opt("classID", "number"),
|
|
Game::Doc::Opt("subClassID", "number"),
|
|
};
|
|
static const Game::Doc::Function kGetItemInfoInstant{
|
|
"Returns the item's class, slot and icon without asking the server; returns nothing for "
|
|
"input that names no item.",
|
|
kItemInfoArgs, kGetItemInfoInstantRets};
|
|
|
|
static const Game::Doc::Field kIconRets[] = {
|
|
Game::Doc::Opt("icon", "string", nullptr,
|
|
"The icon's texture path; nil when the item's data is not loaded, which also "
|
|
"asks the server for it."),
|
|
};
|
|
static const Game::Doc::Field kGetItemIconGlobalArgs[] = {
|
|
Game::Doc::Req("itemID", "number"),
|
|
};
|
|
static const Game::Doc::Function kGetItemIconGlobal{
|
|
"Returns the item's icon.", kGetItemIconGlobalArgs, kIconRets, "ItemGlobals"};
|
|
static const Game::Doc::Field kLocationArgs[] = {
|
|
Game::Doc::Req("itemLocation", "ItemLocation", "An item location or an item GUID."),
|
|
};
|
|
static const Game::Doc::Function kGetItemIcon{"Returns the icon of the item at a location.",
|
|
kLocationArgs, kIconRets};
|
|
static const Game::Doc::Function kGetItemIconByID{"Returns the item's icon.", kItemInfoArgs,
|
|
kIconRets};
|
|
|
|
static const Game::Doc::Field kGetItemFamilyRets[] = {
|
|
Game::Doc::Opt("result", "number", nullptr,
|
|
"The bag family bitmask, 0 for none; nil when the item's data is not loaded, "
|
|
"which also asks the server for it."),
|
|
};
|
|
static const Game::Doc::Function kGetItemFamily{
|
|
"Returns which kinds of special bag the item fits in.", kItemInfoArgs, kGetItemFamilyRets};
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterTableFunction("C_Item", "GetItemInfo", &Script_C_Item_GetItemInfo,
|
|
&kGetItemInfo);
|
|
Game::Lua::RegisterTableFunction("C_Item", "GetItemInfoInstant", &Script_GetItemInfoInstant,
|
|
&kGetItemInfoInstant);
|
|
Game::Lua::RegisterTableFunction("C_Item", "GetItemIDForItemInfo",
|
|
&Script_GetItemIDForItemInfo, &kGetItemIDForItemInfo);
|
|
Game::Lua::RegisterGlobalFunction("GetItemIcon", &Script_GetItemIcon, &kGetItemIconGlobal);
|
|
Game::Lua::RegisterTableFunction("C_Item", "GetItemIcon", &Script_C_Item_GetItemIcon,
|
|
&kGetItemIcon);
|
|
Game::Lua::RegisterTableFunction("C_Item", "GetItemIconByID", &Script_C_Item_GetItemIconByID,
|
|
&kGetItemIconByID);
|
|
Game::Lua::RegisterTableFunction("C_Item", "GetItemFamily", &Script_C_Item_GetItemFamily,
|
|
&kGetItemFamily);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace Item::Info
|