mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
Introduce Item::TooltipItem::CurrentID -- the single "what item is this tooltip showing" resolver. It trusts the link-path itemID (+0x398), and otherwise resolves the CGItem GUID (+0x380) but only when no unit / gameobject / spell id is set, since the clear does not zero the item GUID and it goes stale after the tooltip moves on. - GameTooltip:GetItem / HasItem now route through CurrentID: fixes GetItem returning nil for CGItem tooltips (bag / equipped / merchant / loot) and HasItem false-positiving on a unit tooltip after an item hover. - Add GameTooltip:IsEquippedItem() (3.3.5 backport, registry index 63), resolving the displayed item via CurrentID + the equipment-slot walk. - SetHyperlinkCompareItem: the comparisonTooltip (4th arg) fallback uses CurrentID; stat deltas now show by default and hide only for an explicit false / 0 (was: show only for a truthy shift). - GetItem round-trips the random-suffix id in the link for auction/compare items (no CGItem instance) via the compare descriptor. - FrameXML GameTooltip_ShowCompareItem falls back to self.compareLink, so a caller can hand it an explicit link when the tooltip's item state was rebuilt out from under it (e.g. an AH addon appending source lines). - Offsets: compare-descriptor + FontString offsets; drop the duplicate tooltip item-id/guid offsets in favor of the canonical OFF_TOOLTIP_*.
66 lines
2.4 KiB
C++
66 lines
2.4 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 "item/TooltipItem.h"
|
|
|
|
#include "Offsets.h"
|
|
#include "item/ID.h"
|
|
#include "item/Location.h"
|
|
|
|
namespace Item::TooltipItem {
|
|
|
|
int CurrentID(const void *tooltipObj, uint64_t *outGuid) {
|
|
if (outGuid != nullptr)
|
|
*outGuid = 0;
|
|
if (tooltipObj == nullptr)
|
|
return 0;
|
|
auto *c = static_cast<const uint8_t *>(tooltipObj);
|
|
|
|
const uint64_t itemGuid =
|
|
*reinterpret_cast<const uint64_t *>(c + Offsets::OFF_TOOLTIP_ITEM_GUID_LO);
|
|
|
|
// Link item: the itemID field is authoritative (and reliably cleared).
|
|
const int linkItemID = *reinterpret_cast<const int *>(c + Offsets::OFF_TOOLTIP_ITEM_ID);
|
|
if (linkItemID > 0) {
|
|
if (outGuid != nullptr)
|
|
*outGuid = itemGuid;
|
|
return linkItemID;
|
|
}
|
|
|
|
// CGItem item: only the GUID is stored, and +0x380 isn't zeroed by the
|
|
// clear — so it lingers after the tooltip switches to a unit / GO /
|
|
// spell. Each of those sets its own (cleared-then-written) id, so trust
|
|
// the item GUID only when none of them is currently shown, then resolve
|
|
// it to the itemID (this also yields the dressed link for callers).
|
|
if (itemGuid == 0)
|
|
return 0;
|
|
if (*reinterpret_cast<const uint64_t *>(c + Offsets::OFF_TOOLTIP_UNIT_GUID_LO) != 0)
|
|
return 0;
|
|
if (*reinterpret_cast<const uint64_t *>(c + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO) != 0)
|
|
return 0;
|
|
if (*reinterpret_cast<const int *>(c + Offsets::OFF_TOOLTIP_SPELL_ID) > 0)
|
|
return 0;
|
|
|
|
const uint8_t *cg = Item::Location::ResolveByGUID(itemGuid);
|
|
if (cg == nullptr)
|
|
return 0;
|
|
const int id = Item::ID::FromCGItem(cg);
|
|
if (id <= 0)
|
|
return 0;
|
|
if (outGuid != nullptr)
|
|
*outGuid = itemGuid;
|
|
return id;
|
|
}
|
|
|
|
} // namespace Item::TooltipItem
|