GameTooltip:GetOwner()

This commit is contained in:
Brues
2026-05-24 01:38:28 -05:00
parent 554dec2718
commit 38f1be96ff
4 changed files with 136 additions and 1 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
| Faction | `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` |
| FriendList | `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName` |
| Gossip | `C_GossipInfo.CloseGossip`, `C_GossipInfo.GetActiveQuests`, `C_GossipInfo.GetAvailableQuests`, `C_GossipInfo.GetNumActiveQuests`, `C_GossipInfo.GetNumAvailableQuests`, `C_GossipInfo.GetNumOptions`, `C_GossipInfo.GetOptions`, `C_GossipInfo.GetText`, `C_GossipInfo.SelectActiveQuest`, `C_GossipInfo.SelectAvailableQuest`, `C_GossipInfo.SelectOption`, `C_GossipInfo.SelectOptionByIndex` |
| GameTooltip | `GameTooltip:GetGameObject`, `GameTooltip:GetItem`, `GameTooltip:GetSpell`, `GameTooltip:GetUnitGUID`, `GameTooltip:HasGameObject`, `GameTooltip:HasItem`, `GameTooltip:HasSpell`, `GameTooltip:HasUnit`, `GameTooltip:SetEquipmentSet`, `GameTooltip:SetInventoryItemByID`, `GameTooltip:SetItemByID`, `GameTooltip:SetSpellByID`, `GameTooltip:SetTalentByID`, `GameTooltip:SetUnitAura` |
| GameTooltip | `GameTooltip:GetGameObject`, `GameTooltip:GetItem`, `GameTooltip:GetOwner`, `GameTooltip:GetSpell`, `GameTooltip:GetUnitGUID`, `GameTooltip:HasGameObject`, `GameTooltip:HasItem`, `GameTooltip:HasSpell`, `GameTooltip:HasUnit`, `GameTooltip:SetEquipmentSet`, `GameTooltip:SetInventoryItemByID`, `GameTooltip:SetItemByID`, `GameTooltip:SetSpellByID`, `GameTooltip:SetTalentByID`, `GameTooltip:SetUnitAura` |
| Hooks | `hooksecurefunc` |
| Input | `IsLeftAltKeyDown`, `IsLeftControlKeyDown`, `IsLeftShiftKeyDown`, `IsModifierKeyDown`, `IsRightAltKeyDown`, `IsRightControlKeyDown`, `IsRightShiftKeyDown` |
| Item | `C_Item.DoesItemExist`, `C_Item.DoesItemExistByID`, `C_Item.EquipItemByName`, `C_Item.GetCurrentItemLevel`, `C_Item.GetDetailedItemLevelInfo`, `C_Item.GetItemCount`, `C_Item.GetItemFamily`, `C_Item.GetItemGUID`, `C_Item.GetItemIcon`, `C_Item.GetItemIconByID`, `C_Item.GetItemID`, `C_Item.GetItemInfoInstant`, `C_Item.GetItemInventoryType`, `C_Item.GetItemInventoryTypeByID`, `C_Item.GetItemLink`, `C_Item.GetItemLocation`, `C_Item.GetItemMaxStackSize`, `C_Item.GetItemMaxStackSizeByID`, `C_Item.GetItemName`, `C_Item.GetItemNameByID`, `C_Item.GetItemQuality`, `C_Item.GetItemQualityByID`, `C_Item.GetItemSellPrice`, `C_Item.GetItemSellPriceByID`, `C_Item.GetItemSetID`, `C_Item.GetItemSetIDByID`, `C_Item.GetItemSetInfo`, `C_Item.GetItemSpell`, `C_Item.GetWeaponEnchantInfo`, `C_Item.IsBound`, `C_Item.IsEquippableItem`, `C_Item.IsEquippedItem`, `C_Item.IsItemDataCached`, `C_Item.IsItemDataCachedByID`, `C_Item.IsLocked`, `C_Item.RequestLoadItemData`, `C_Item.RequestLoadItemDataByID`, `C_Item.UseItemByName`, `GetAuctionItemID`, `GetAuctionSellItemID`, `GetAverageItemLevel`, `GetCraftReagentItemID`, `GetInboxItemID`, `GetInventoryItemDurability`, `GetInventoryItemID`, `GetInventoryItemsForSlot`, `GetInventoryItemRepairCost`, `GetItemIcon`, `GetLootRollItemID`, `GetLootSlotItemID`, `GetMerchantItemID`, `GetQuestItemID`, `GetQuestLogItemID`, `GetTradePlayerItemID`, `GetTradeSkillItemID`, `GetTradeSkillReagentItemID`, `GetTradeTargetItemID`, `OffhandHasWeapon` |
+20
View File
@@ -104,6 +104,7 @@ build instructions.
- [`GameTooltip:HasItem()` / `GameTooltip:HasSpell()`](#gametooltiphasitem--gametooltiphasspell)
- [`GameTooltip:GetUnitGUID()` / `GameTooltip:HasUnit()`](#gametooltipgetunitguid--gametooltiphasunit)
- [`GameTooltip:GetGameObject()` / `GameTooltip:HasGameObject()`](#gametooltipgetgameobject--gametooltiphasgameobject)
- [`GameTooltip:GetOwner()`](#gametooltipgetowner)
- [Globals](#globals)
- [`CLASSIC_API_VERSION`](#classic_api_version)
@@ -2199,6 +2200,25 @@ evicted it). `HasGameObject()` stays true in the latter case —
the tooltip-frame slot still has the GUID, even though the live
object has been freed.
### `GameTooltip:GetOwner()`
Returns the frame that called `tooltip:SetOwner(frame, anchor)`, or
`nil` if the tooltip hasn't been owned by anyone since its last
`Clear` / `Hide`. Vanilla 1.12 ships `SetOwner` and `IsOwned` but
never added the matching reader; modern Classic Era's signature is
backported here for parity.
```lua
GameTooltip:SetOwner(SomeFrame, "ANCHOR_TOPLEFT")
local owner = GameTooltip:GetOwner()
-- owner == SomeFrame
```
Returns only the owner frame, not `(owner, anchorPoint)` like modern
Classic. The anchor string is reachable via vanilla's native
[`GameTooltip:GetAnchorType()`](https://wowwiki-archive.fandom.com/wiki/API_GameTooltip_GetAnchorType)
(slot 5 in the GameTooltip method registry).
### `GameTooltip:SetTalentByID(talentID)`
Renders a tooltip for the talent identified by `Talent.dbc` primary
+31
View File
@@ -29,9 +29,32 @@ enum Offsets {
FUN_LOAD_GLUE_SCRIPT_FUNCTIONS = 0x0046ABB0,
// GameTooltip script-method prologue helpers (used to resolve self → CFrameScriptObject*).
// Underlying Lua C API names per [[docs/LuaCAPI.md]] are `lua_rawgeti`
// (0x6F3BC0) and `lua_touserdata` (0x6F3740). The Set* method prologue's
// call sequence
// PushObject(L, idx, 0); // == lua_rawgeti(L, idx, 0) — pushes the
// // lightuserdata at table[0]
// GetObject(L, -1); // == lua_touserdata(L, -1) — extracts
// // the raw CFrameScriptObject *
// is the canonical "Lua frame table → C++ object" path. The reverse
// (`GameTooltip:GetOwner` etc.) is just `lua_rawgeti(L, REGISTRY,
// [cobj+OFF_COBJECT_LUA_REGISTRY_REF])` — the engine pre-allocates
// the registry handle when the frame is created from Lua.
FUN_FRAMESCRIPT_PUSH_OBJECT = 0x6F3BC0,
FUN_FRAMESCRIPT_GET_OBJECT = 0x6F3740,
// CFrameScriptObject layout: the registry refkey allocated when the
// engine first exposes the C++ object to Lua. Pushing a frame back
// to Lua is `lua_rawgeti(L, LUA_REGISTRYINDEX, [cobj+0x08])`.
OFF_COBJECT_LUA_REGISTRY_REF = 0x08,
// Within a CGFrame, the embedded LayoutFrame sub-object starts here.
// Engine code that wants to invoke LayoutFrame methods polymorphically
// (anchoring, positioning) stores the LayoutFrame* — i.e.
// `(Frame*)obj + 0x24` — instead of the bare Frame*. Reverse
// lookups (e.g. GameTooltip:GetOwner) subtract this back out.
OFF_FRAME_LAYOUT_SUBOBJECT = 0x24,
// Inner spell-tooltip builder, called from Script_GameTooltip_SetSpell at 0x00532E92.
// __thiscall(spellID, 0, 0, isPet, 0, 0, 0); we always pass isPet=0.
FUN_GAMETOOLTIP_BUILD_SPELL_TOOLTIP = 0x0052E610,
@@ -91,6 +114,14 @@ enum Offsets {
// Same clear/gating semantics as the unit GUID slot.
OFF_TOOLTIP_GAMEOBJECT_GUID_LO = 0x370,
OFF_TOOLTIP_GAMEOBJECT_GUID_HI = 0x374,
// Owner frame stored by `tooltip:SetOwner(frame, anchor)` and
// compared by `IsOwned`. Holds `owner_CObject + OFF_FRAME_LAYOUT_SUBOBJECT`
// (i.e. the LayoutFrame*, not the bare Frame*), or 0 if unowned.
// Verified via the helper at 0x0052FFE0 invoked by SetOwner's tail
// (writes `[this+0x314] = arg+0x24`) and Script_GameTooltip_IsOwned
// at 0x00530FE0 (reads `[edi+0x314]` and compares against the same
// `+0x24`-offset value).
OFF_TOOLTIP_OWNER = 0x314,
// CGItem → fully-dressed item link string. __fastcall(ecx = CGItem *)
// → const char *. Reads the item's itemID, quality, permanent
+84
View File
@@ -0,0 +1,84 @@
// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
// `GameTooltip:GetOwner()` — backport of the modern Classic Era method.
// Vanilla 1.12 ships `SetOwner` and `IsOwned` but never added the
// matching reader. The owner is stored on the tooltip frame at
// `OFF_TOOLTIP_OWNER`, written by the helper at 0x0052FFE0 called from
// the SetOwner method's tail.
//
// Stored value is `owner_CObject + OFF_FRAME_LAYOUT_SUBOBJECT` (the
// LayoutFrame sub-object), not the bare Frame pointer — multiple
// inheritance lets the engine call LayoutFrame methods polymorphically
// on the stored pointer without an extra cast. We subtract the offset
// back out, then `lua_rawgeti(L, REGISTRY_INDEX, [cobj+0x08])` pushes
// the frame's Lua table. The registry refkey was set up when the
// engine first exposed the frame to Lua (i.e. `CreateFrame`-time), so
// there's no lazy-init to worry about — any frame that's been a
// SetOwner target is by definition already Lua-visible.
//
// Returns only the owner frame, not `(owner, anchorPoint)` like modern
// Classic. The anchor string is already reachable via vanilla's native
// `GameTooltip:GetAnchorType()` (slot 5 in the GameTooltip method
// registry), so addons that want it can call that separately.
#include "Game.h"
#include "Offsets.h"
#include <cstdint>
namespace Tooltip::Owner {
namespace {
// FUN_FRAMESCRIPT_PUSH_OBJECT is `lua_rawgeti` — see Offsets.h comment.
using LuaRawGetI_t = void(__fastcall *)(void *L, int idx, int n);
} // namespace
static int __fastcall Script_GameTooltipGetOwner(void *L) {
if (Game::Lua::Type(L, 1) != Game::Lua::TYPE_TABLE) {
Game::Lua::Error(L, "Usage: GameTooltip:GetOwner()");
return 0;
}
void *tooltip = Game::Lua::ResolveObject(L, 1);
if (tooltip == nullptr)
return 0;
auto *layoutFrame = *reinterpret_cast<uint8_t *const *>(
static_cast<uint8_t *>(tooltip) + Offsets::OFF_TOOLTIP_OWNER);
if (layoutFrame == nullptr) {
Game::Lua::PushNil(L);
return 1;
}
auto *ownerFrame = layoutFrame - Offsets::OFF_FRAME_LAYOUT_SUBOBJECT;
const int refKey = *reinterpret_cast<const int *>(
ownerFrame + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
auto rawgeti = reinterpret_cast<LuaRawGetI_t>(
Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT);
rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey);
return 1;
}
static const Game::Lua::FrameMethodEntry g_methods[] = {
{"GetOwner", &Script_GameTooltipGetOwner},
};
static void RegisterLuaFunctions() {
Game::Lua::RegisterFrameMethods(
reinterpret_cast<void *>(Offsets::VAR_GAMETOOLTIP_METHOD_REGISTRY),
g_methods,
static_cast<int>(sizeof(g_methods) / sizeof(g_methods[0])));
}
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
} // namespace Tooltip::Owner