diff --git a/README.md b/README.md index 11e2d94d..61b6db32 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ In the Frame rows, a name that starts with `:` is a method of the widget that th | [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID`, `ClosestGameObjectPosition` | | [Glue](docs/API.md#glue) | `C_Glue.IsOnGlueScreen` | | [GameTooltip](docs/API.md#gametooltip) | `GameTooltip:AddSpellByID`, `GameTooltip:AddTexture`, `GameTooltip:GetGameObject`, `GameTooltip:GetItem`, `GameTooltip:GetMinimumWidth`, `GameTooltip:GetOwner`, `GameTooltip:GetPadding`, `GameTooltip:GetSpell`, `GameTooltip:GetUnit`, `GameTooltip:GetUnitGUID`, `GameTooltip:HasGameObject`, `GameTooltip:HasItem`, `GameTooltip:HasSpell`, `GameTooltip:HasUnit`, `GameTooltip:IsEquippedItem`, `GameTooltip:IsUnit`, `GameTooltip:SetAnchorType`, `GameTooltip:SetEquipmentSet`, `GameTooltip:SetFrameStack`, `GameTooltip:SetHyperlink` (full links, `spell:`, `quest:`), `GameTooltip:SetHyperlinkCompareItem`, `GameTooltip:SetInventoryItemByID`, `GameTooltip:SetItemByGUID`, `GameTooltip:SetItemByID`, `GameTooltip:SetSpellByID`, `GameTooltip:SetTalentByID`, `GameTooltip:SetTotem`, `GameTooltip:SetUnitAura`, `OnTooltipSetItem`, `OnTooltipSetSpell`, `OnTooltipSetUnit`, `OnTooltipSetGameObject`, `OnTooltipSetFrameStack` (scripts) | -| [Gossip](docs/API.md#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`, `GetNumGossipActiveQuests`, `GetNumGossipAvailableQuests` | +| [Gossip](docs/API.md#gossip) | `C_GossipInfo.CloseGossip`, `C_GossipInfo.GetActiveQuests`, `C_GossipInfo.GetAvailableQuests`, `C_GossipInfo.GetNumActiveQuests`, `C_GossipInfo.GetNumAvailableQuests`, `C_GossipInfo.GetNumOptions`, `C_GossipInfo.GetOptions`, `C_GossipInfo.GetPoiForUiMapID`, `C_GossipInfo.GetPoiInfo`, `C_GossipInfo.GetText`, `C_GossipInfo.SelectActiveQuest`, `C_GossipInfo.SelectAvailableQuest`, `C_GossipInfo.SelectOption`, `C_GossipInfo.SelectOptionByIndex`, `GetNumGossipActiveQuests`, `GetNumGossipAvailableQuests` | | [Hooks](docs/API.md#hooks) | `hooksecurefunc` | | [Input](docs/API.md#input) | `GetMouseButtonClicked`, `IsLeftAltKeyDown`, `IsLeftControlKeyDown`, `IsLeftShiftKeyDown`, `IsModifierKeyDown`, `IsMouseButtonDown`, `IsRightAltKeyDown`, `IsRightControlKeyDown`, `IsRightShiftKeyDown` | | [Instance](docs/API.md#instance) | `GetInstanceInfo`, `IsActiveBattlefieldArena` | @@ -275,6 +275,7 @@ when launching with `-console`), not as Lua functions. See the | `COMBAT_LOG_EVENT` | `timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, ...` ([details](docs/API.md#combat_log_event_unfiltered--combat_log_event-events)) | | `COMBAT_LOG_EVENT_UNFILTERED` | same as `COMBAT_LOG_EVENT` | | `CURSOR_CHANGED` | `isDefault, newCursorType, oldCursorType, oldCursorVirtualID` | +| `DYNAMIC_GOSSIP_POI_UPDATED` | *(none)* | | `EQUIPMENT_SETS_CHANGED` | *(none)* | | `EQUIPMENT_SWAP_PENDING` | `setID` | | `EQUIPMENT_SWAP_FINISHED` | `success, setID` | diff --git a/docs/API.md b/docs/API.md index b3d069a6..d57a0156 100644 --- a/docs/API.md +++ b/docs/API.md @@ -198,6 +198,7 @@ build instructions. - [`UPDATE_INVENTORY_DURABILITY` event](#update_inventory_durability-event) - [`PLAYER_AVG_ITEM_LEVEL_READY` event](#player_avg_item_level_ready-event) - [`HEARTHSTONE_BOUND` event](#hearthstone_bound-event) + - [`DYNAMIC_GOSSIP_POI_UPDATED` event](#dynamic_gossip_poi_updated-event) - [Player input-state events (`PLAYER_STARTED_MOVING` / `LOOKING` / `TURNING` + `STOPPED_*`)](#player-input-state-events) - [`GLOBAL_MOUSE_DOWN` / `GLOBAL_MOUSE_UP` events](#global_mouse_down--global_mouse_up-events) - [`AUCTION_MULTISELL_START` / `AUCTION_MULTISELL_UPDATE` / `AUCTION_MULTISELL_FAILURE` events](#c_auctionhousepostitemitemlocation-duration-quantity-numstacks-bid-buyout) @@ -429,6 +430,8 @@ build instructions. - [`C_GossipInfo.SelectAvailableQuest(questID)`](#c_gossipinfoselectavailablequestquestid) - [`C_GossipInfo.SelectActiveQuest(questID)`](#c_gossipinfoselectactivequestquestid) - [`C_GossipInfo.CloseGossip()`](#c_gossipinfoclosegossip) + - [`C_GossipInfo.GetPoiForUiMapID(uiMapID)`](#c_gossipinfogetpoiforuimapiduimapid) + - [`C_GossipInfo.GetPoiInfo(uiMapID, gossipPoiID)`](#c_gossipinfogetpoiinfouimapid-gossippoiid) - [`GetNumGossipAvailableQuests()` / `GetNumGossipActiveQuests()`](#getnumgossipavailablequests--getnumgossipactivequests) - [Hooks](#hooks) @@ -4518,6 +4521,12 @@ Character switch is handled automatically: the character-entry init re-zeroes the flag, so each new character's first update is also treated as sync and suppressed. +### `DYNAMIC_GOSSIP_POI_UPDATED` event + +Fires (with no payload) when a gossip point of interest is added to the map or +removed from it. When it fires, read the marker again with +[`C_GossipInfo.GetPoiForUiMapID`](#c_gossipinfogetpoiforuimapiduimapid). + ### Player input-state events Three pairs of zero-payload events fired from a single per-frame @@ -9779,6 +9788,40 @@ Picks an in-progress quest by `questID`. Same shape as Closes the gossip window. Direct passthrough to the engine's `CloseGossip`. Returns nothing. +### `C_GossipInfo.GetPoiForUiMapID(uiMapID)` + +Returns the ID of the gossip point of interest on the map `uiMapID`, or nil. +Some gossip options add this marker to the map, for example the directions +that a city guard gives. There is only one marker at a time, and its ID is +always `1`. + +The function returns nil when there is no marker, or when the marker is not +inside the map. The marker goes away when the player comes within 10 yards of +it, or 8 minutes after it was added. + +### `C_GossipInfo.GetPoiInfo(uiMapID, gossipPoiID)` + +Returns a table that describes the gossip point of interest on the map +`uiMapID`, or nil. It returns nil in the same conditions as +`GetPoiForUiMapID`, and when `gossipPoiID` is not the ID that +`GetPoiForUiMapID` returns. + +| Field | Type | Description | +|----------------|---------|-------------| +| `name` | string | The name of the location, for example `"Stormwind Bank"`. | +| `textureIndex` | number | The icon index. It is the same index that `GetMapLandmarkInfo` returns for this marker. | +| `position` | vector2 | The position on the map, from 0 to 1 on each axis. | +| `inBattleMap` | boolean | Always `false`. | + +```lua +local mapID = C_Map.GetBestMapForUnit("player") +local poiID = C_GossipInfo.GetPoiForUiMapID(mapID) +if poiID then + local info = C_GossipInfo.GetPoiInfo(mapID, poiID) + print(info.name, info.position:GetXY()) +end +``` + ### `GetNumGossipAvailableQuests()` / `GetNumGossipActiveQuests()` Returns the number of quests that `GetGossipAvailableQuests()` / diff --git a/src/Offsets.h b/src/Offsets.h index 874efbf4..ed8a15b9 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -10410,6 +10410,9 @@ enum Offsets { // via the 0x006DAC10 / 0x004A67A0 / 0x004A7360 decompiles. VAR_GOSSIP_POI_BLIP = 0x00CEA7D4, VAR_GOSSIP_POI_NAME = 0x00CEA6E0, // char[0x40], slot 1 of the names at 0x00CEA6A0 + // u32, wall-clock seconds (0x00429580) + 480 at each set; both clears + // zero it with x/y (0x006D93FB, 0x006D9A3A). 0 = no marker. + VAR_GOSSIP_POI_EXPIRY = 0x00CEAAA4, OFF_STATIC_BLIP_ICON = 0x08, // u32, POI icon index (the packet's icon) OFF_STATIC_BLIP_X = 0x10, // float, world X (north) OFF_STATIC_BLIP_Y = 0x14, // float, world Y (west) diff --git a/src/gossip/Poi.cpp b/src/gossip/Poi.cpp index 9e97cd2b..053de46d 100644 --- a/src/gossip/Poi.cpp +++ b/src/gossip/Poi.cpp @@ -25,11 +25,20 @@ // // The packet carries no POI id, and there is only ever one marker, so its // `gossipPoiID` is the engine's slot number, 1. +// +// `DYNAMIC_GOSSIP_POI_UPDATED` fires when the marker is set or cleared. Every +// change runs the world map rebuild 0x004A67A0 (the setter after a packet, the +// 480 s expiry and the 10-yard clear in 0x006D93A0), but that rebuild also +// runs for every map view change, so the event comes from a once-per-frame +// diff of the record instead: x, y and the expiry, which each set rewrites +// and each clear zeroes. #include "Game.h" #include "Offsets.h" +#include "event/Custom.h" #include "map/Area.h" #include "map/Vector2.h" +#include "tick/WorldTick.h" #include @@ -43,6 +52,32 @@ template T BlipField(uintptr_t off) { return *reinterpret_cast(Offsets::VAR_GOSSIP_POI_BLIP + off); } +const Game::Doc::Event kPoiUpdatedDoc{ + "GossipInfo", "Fires when a gossip point of interest is added to or removed from the map.", + {}}; +const Event::Custom::AutoReserve _evtPoiUpdated{"DYNAMIC_GOSSIP_POI_UPDATED", + &kPoiUpdatedDoc}; + +struct Snapshot { + uint32_t x, y, expiry; +}; + +// The record as of the last fire. DLL-lived like the record itself, so a +// /reload with a marker up does not fire a phantom change. +Snapshot g_last{}; + +void OnTick() { + const Snapshot now{BlipField(Offsets::OFF_STATIC_BLIP_X), + BlipField(Offsets::OFF_STATIC_BLIP_Y), + *reinterpret_cast(Offsets::VAR_GOSSIP_POI_EXPIRY)}; + if (now.x == g_last.x && now.y == g_last.y && now.expiry == g_last.expiry) + return; + g_last = now; + Event::Custom::Fire(_evtPoiUpdated.Slot(), ""); +} + +const Tick::WorldTick::AutoSubscribe _tick{&OnTick}; + // Projects the live marker onto `uiMapID`. False when there is no marker or // it isn't on that map. bool ProjectOnMap(int uiMapID, double *outPx, double *outPy) {