mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
C_Item.GetItemNameByID and C_Item.GetItemInfo resolved an item link down to just the itemID and dropped the random suffix (3rd `item:` field), so "item:12022:0:769:0" returned "Iridium Chain" instead of "Iridium Chain of the Owl" (and GetItemInfo's rebuilt link lost the 769). The global GetItemInfo applies it; now these match. Item::Arg::Resolve parses the suffix alongside the itemID. New Item::Link::NameFromIDSuffix builds the suffix-decorated name from (itemID, suffixID) without a live CGItem, via the engine's inner name builder (FUN_005d8b00 = the formatter behind FUN_ITEM_BUILD_INSTANCE_NAME, which reads the localized "of the X" suffix from ItemRandomProperties). Item::Link::BasicFromIDSuffix preserves the suffix in the rebuilt link (payload + bracketed name); BasicFromItemID is now a suffix=0 wrapper. GetItemNameByID and GetItemInfo route through these; numeric/suffixless input still yields the base name. Numeric item stats are unaffected (the suffix only decorates the name/link). Enchant/unique fields are normalized to 0 in the rebuilt link (suffix is what affects the name). Verified in-game: item:12022:0:769:0 -> "Iridium Chain of the Owl" (name + link); bare 12022 / item:12022:0:0:0 -> "Iridium Chain".
69 lines
3.5 KiB
C++
69 lines
3.5 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/>.
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
namespace Item::Link {
|
|
|
|
// Builds the fully-decorated per-instance item hyperlink for `cgItem`
|
|
// via the engine's internal link builder at `FUN_GAMETOOLTIP_BUILD_ITEM_LINK`
|
|
// (`0x0052AE00`). The returned string sits in the engine's long-lived
|
|
// scratch buffer; safe to `PushString` immediately (Lua copies the
|
|
// content). Returns nullptr if `cgItem` is null or the engine can't
|
|
// resolve the instance block. The link includes enchant ID, random
|
|
// suffix factor, unique ID, and any random-suffix-decorated name —
|
|
// same output `GetInventoryItemLink` / `GetContainerItemLink` would
|
|
// produce for the same slot.
|
|
const char *FromCGItem(const uint8_t *cgItem);
|
|
|
|
// Writes the item's per-instance decorated *display name* into `out` —
|
|
// the same `[Name]` the engine stamps into `FromCGItem`'s link, e.g.
|
|
// "Iridium Chain of the Owl" (or the base name when the instance carries
|
|
// no random suffix). Reads the suffix ID off the CGItem descriptor
|
|
// (`+0x98`) and formats it through the engine's own name builder
|
|
// (`FUN_ITEM_BUILD_INSTANCE_NAME`). Returns false (and leaves `out`
|
|
// empty) for a null item or an empty build result, so callers can fall
|
|
// back to the base ItemStats name. Use whenever a name is returned
|
|
// alongside a `FromCGItem` link, so the two agree.
|
|
bool NameFromCGItem(const uint8_t *cgItem, char *out, size_t outSize);
|
|
|
|
// Builds a basic itemID-only hyperlink (`"|cffRRGGBB|Hitem:N:0:0:0|h[Name]|h|r"`)
|
|
// into `out` from the cached ItemStats record for `itemID`. No
|
|
// enchant / random-suffix decoration — use this when the caller has
|
|
// only an itemID and no live CGItem (mail inbox attachments, cursor
|
|
// drag-source items, vendor roster previews). Returns true on
|
|
// success, false if the item isn't cached or the buffer is too small.
|
|
//
|
|
// `outSize` should be at least 256 to comfortably fit the longest
|
|
// possible link (`item:` payload + colored prefix + bracketed name).
|
|
bool BasicFromItemID(uint32_t itemID, char *out, size_t outSize);
|
|
|
|
// Writes the suffix-decorated display name for `(itemID, suffixID)` into
|
|
// `out` WITHOUT a live item instance — the by-string analog of
|
|
// NameFromCGItem. `suffixID` is the 3rd `item:` field (random property /
|
|
// suffix); 0 = base name. Applies the "... of the Owl" suffix via the
|
|
// engine's inner builder (FUN_ITEM_BUILD_NAME_FROM_ID) when the item is
|
|
// cached and the suffix is a valid ItemRandomProperties row. Returns false
|
|
// (out empty) if the item isn't cached or has no name — warm and retry.
|
|
bool NameFromIDSuffix(uint32_t itemID, int suffixID, char *out, size_t outSize);
|
|
|
|
// Like BasicFromItemID but preserves the random `suffixID` in both the
|
|
// `item:` payload (`item:N:0:suffix:0`) and the bracketed, suffix-decorated
|
|
// name. `suffixID` 0 reduces exactly to BasicFromItemID.
|
|
bool BasicFromIDSuffix(uint32_t itemID, int suffixID, char *out, size_t outSize);
|
|
|
|
} // namespace Item::Link
|