diff --git a/README.md b/README.md
index d1948b33..06399dcb 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
| [LossOfControl](docs/API.md#lossofcontrol) | `C_LossOfControl.GetActiveLossOfControlData`, `C_LossOfControl.GetActiveLossOfControlDataCount` |
| [Macros](docs/API.md#macros) | `GetLooseMacroIcons`, `GetLooseMacroItemIcons`, `GetMacroIcons`, `GetMacroItemIcons`, `GetMacroSpell` |
| [Mail](docs/API.md#mail) | `GetInboxItemLink`, `GetSendMailItemLink` |
-| [Map](docs/API.md#map) | `C_Map.GetAreaTriggerInfo`, `C_Map.GetAreaTriggers`, `C_Map.GetBestMapForUnit`, `C_Map.GetMapOverlays` |
+| [Map](docs/API.md#map) | `C_Map.GetAreaTriggerInfo`, `C_Map.GetAreaTriggers`, `C_Map.GetBestMapForUnit`, `C_Map.GetMapOverlays`, `C_Map.GetMapWorldSize` |
| [MerchantFrame](docs/API.md#merchantframe) | `C_MerchantFrame.GetBuybackItemID`, `C_MerchantFrame.GetItemInfo`, `C_MerchantFrame.GetNumJunkItems`, `C_MerchantFrame.IsMerchantItemRefundable`, `C_MerchantFrame.IsSellAllJunkEnabled`, `C_MerchantFrame.SellAllJunkItems` |
| [NamePlate](docs/API.md#nameplate) | `C_NamePlate.GetNamePlateForGUID`, `C_NamePlate.GetNamePlateForUnit`, `C_NamePlate.GetNamePlateGUIDs`, `C_NamePlate.GetNamePlates` |
| [NameCache](docs/API.md#namecache) | `C_PlayerCache.GetPlayerInfoByName`, `C_PlayerCache.IsEnabled`, `C_PlayerCache.IsScanEnabled`, `C_PlayerCache.RememberPlayer`, `C_PlayerCache.SetEnabled`, `C_PlayerCache.SetScanEnabled`, `GetPlayerInfoByGUID`, `UnitNameFromGUID` |
diff --git a/docs/API.md b/docs/API.md
index 944edced..1712cc06 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -285,6 +285,7 @@ build instructions.
- [`C_Map.GetAreaTriggerInfo(triggerID)` / `C_Map.GetAreaTriggers([mapID])`](#c_mapgetareatriggerinfotriggerid--c_mapgetareatriggersmapid)
- [`C_Map.GetBestMapForUnit(unitToken)`](#c_mapgetbestmapforunitunittoken)
- [`C_Map.GetMapOverlays([areaID])`](#c_mapgetmapoverlaysareaid)
+ - [`C_Map.GetMapWorldSize([areaID])`](#c_mapgetmapworldsizeareaid)
- [MerchantFrame](#merchantframe)
- [`C_MerchantFrame.GetItemInfo(slot)`](#c_merchantframegetiteminfoslot)
@@ -6848,6 +6849,31 @@ end
> reliable for placement; it's only the tile count they imply that
> lies.
+### `C_Map.GetMapWorldSize([areaID])`
+
+Returns a zone's world size in yards as `width, height` — the physical extent the
+map represents, read straight from the `WorldMapArea.dbc` placement rect.
+Addons use it to turn map-relative percents into yard distances (range
+rings, "N yards away" readouts, proximity checks).
+
+Retail takes a `uiMapID`; here it's an `areaID` (`AreaTable.dbc` id — the
+same identity
+[`C_Map.GetBestMapForUnit`](#c_mapgetbestmapforunitunittoken) returns and
+[`C_Map.GetMapOverlays`](#c_mapgetmapoverlaysareaid) accepts), returns that
+zone's size; with no argument, the world map's currently **viewed** zone
+(same resolution `GetMapOverlays()` uses with no arg). Returns `nil, nil`
+when the zone can't be resolved.
+
+`width` is the east-west span (world Y), `height` the north-south span
+(world X) — the same denominators behind the
+[`C_Map.GetAreaTriggerInfo`](#c_mapgetareatriggerinfotriggerid--c_mapgetareatriggersmapid)
+map-percent transform, so `mapX/100 * width` and `mapY/100 * height` give a
+point's offset in yards within the zone.
+
+```lua
+local w, h = C_Map.GetMapWorldSize(85) -- Tirisfal: ~4518.7, 3012.5
+```
+
### `C_Map.GetAreaTriggerInfo(triggerID)` / `C_Map.GetAreaTriggers([mapID])`
ClassicAPI extension. Exposes `AreaTrigger.dbc` — the client's 517
diff --git a/src/map/Area.cpp b/src/map/Area.cpp
new file mode 100644
index 00000000..4a8af7d8
--- /dev/null
+++ b/src/map/Area.cpp
@@ -0,0 +1,55 @@
+// 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 .
+
+#include "map/Area.h"
+
+#include "Offsets.h"
+#include "dbc/Lookup.h"
+
+namespace Map::Area {
+
+int RowForAreaID(uint32_t areaID) {
+ const int count =
+ *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT);
+ for (int id = 1; id <= count; ++id) {
+ const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
+ Offsets::VAR_WORLDMAP_AREA_COUNT,
+ static_cast(id));
+ if (rec != nullptr &&
+ *reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID) ==
+ areaID)
+ return id;
+ }
+ return -1;
+}
+
+int CurrentViewRow() {
+ const int continent =
+ *reinterpret_cast(Offsets::VAR_WORLDMAP_CONTINENT_INDEX);
+ if (continent < 0)
+ return *reinterpret_cast(
+ Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW);
+ const uint8_t *blob = *reinterpret_cast(
+ Offsets::VAR_WORLDMAP_CONTINENT_DATA);
+ if (blob == nullptr)
+ return -1;
+ const uint8_t *entry = blob + continent * Offsets::WORLDMAP_CONTINENT_STRIDE;
+ const int zone =
+ *reinterpret_cast(Offsets::VAR_WORLDMAP_ZONE_INDEX);
+ if (zone < 0)
+ return *reinterpret_cast(entry + 0x04);
+ const int *zoneRows = *reinterpret_cast(entry + 0x10);
+ return (zoneRows != nullptr) ? zoneRows[zone] : -1;
+}
+
+} // namespace Map::Area
diff --git a/src/map/Area.h b/src/map/Area.h
new file mode 100644
index 00000000..68d25165
--- /dev/null
+++ b/src/map/Area.h
@@ -0,0 +1,41 @@
+// 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 .
+
+#pragma once
+
+#include
+
+// `Map::Area` — shared `WorldMapArea.dbc` row resolution. A WorldMapArea
+// row is the client's per-zone map descriptor (directory name + the
+// world-coordinate rect used for world↔map transforms); every C_Map.*
+// reader that keys off "which zone" resolves a row first. Both
+// `Map::Overlays` (GetMapOverlays) and `Map::WorldSize` (GetMapWorldSize)
+// go through here so the two ways of naming a zone — an AreaTable areaID
+// argument, or the world map's current continent/zone view — live in one
+// place.
+namespace Map::Area {
+
+// WorldMapArea row for an AreaTable `areaID` (the stable zone identity
+// `C_Map.GetBestMapForUnit` returns). Linear walk of the ~175-row table.
+// Returns -1 when no row carries that areaID.
+int RowForAreaID(uint32_t areaID);
+
+// WorldMapArea row for the world map's currently *viewed* zone — the same
+// continent/zone selection the engine's map-name resolver (FUN_004a6cf0,
+// behind GetMapInfo) performs: continent index → per-continent blob, zone
+// index (-1 = whole continent) → that continent's zone-row array; no
+// continent selected falls back to the default-row global. Returns -1 when
+// the continent blob isn't resident.
+int CurrentViewRow();
+
+} // namespace Map::Area
diff --git a/src/map/Overlays.cpp b/src/map/Overlays.cpp
index 35f36469..da5ea703 100644
--- a/src/map/Overlays.cpp
+++ b/src/map/Overlays.cpp
@@ -97,6 +97,7 @@
#include "Game.h"
#include "Offsets.h"
#include "dbc/Lookup.h"
+#include "map/Area.h"
#include
#include
@@ -279,46 +280,8 @@ const ResolvedOverlay *CachedResolve(int overlayId, const char *basePath,
return g_cache[overlayId];
}
-// WorldMapArea row id for the world map's current view — the same
-// resolution the engine's current-map-name getter (FUN_004a6cf0, behind
-// GetMapInfo) performs: continent/zone selection indexes into the
-// per-continent data blob; no continent selected falls back to the
-// default row global.
-int CurrentWorldMapAreaRow() {
- const int continent =
- *reinterpret_cast(Offsets::VAR_WORLDMAP_CONTINENT_INDEX);
- if (continent < 0)
- return *reinterpret_cast(
- Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW);
- const uint8_t *blob = *reinterpret_cast(
- Offsets::VAR_WORLDMAP_CONTINENT_DATA);
- if (blob == nullptr)
- return -1;
- const uint8_t *entry = blob + continent * Offsets::WORLDMAP_CONTINENT_STRIDE;
- const int zone =
- *reinterpret_cast(Offsets::VAR_WORLDMAP_ZONE_INDEX);
- if (zone < 0)
- return *reinterpret_cast(entry + 0x04);
- const int *zoneRows = *reinterpret_cast(entry + 0x10);
- return (zoneRows != nullptr) ? zoneRows[zone] : -1;
-}
-
-// WorldMapArea row id for an AreaTable areaID. Linear walk — the table
-// has ~175 rows; called once per Lua call.
-int WorldMapAreaRowForAreaID(uint32_t areaID) {
- const int count =
- *reinterpret_cast(Offsets::VAR_WORLDMAP_AREA_COUNT);
- for (int id = 1; id <= count; ++id) {
- const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
- Offsets::VAR_WORLDMAP_AREA_COUNT,
- static_cast(id));
- if (rec != nullptr &&
- *reinterpret_cast(rec + Offsets::OFF_WMA_AREA_ID) ==
- areaID)
- return id;
- }
- return -1;
-}
+// WorldMapArea row resolution (areaID → row, current view → row) lives in
+// the shared `Map::Area` helper — `GetMapWorldSize` keys off the same rows.
// Pushes the `tiles` array for one overlay (leaves it on the stack top).
void PushTiles(void *L, const ResolvedOverlay *r, const char *basePath,
@@ -405,10 +368,10 @@ void PushTiles(void *L, const ResolvedOverlay *r, const char *basePath,
int __fastcall Script_GetMapOverlays(void *L) {
int wmaRow = -1;
if (Game::Lua::IsNumber(L, 1)) {
- wmaRow = WorldMapAreaRowForAreaID(
+ wmaRow = Map::Area::RowForAreaID(
static_cast(Game::Lua::ToNumber(L, 1)));
} else {
- wmaRow = CurrentWorldMapAreaRow();
+ wmaRow = Map::Area::CurrentViewRow();
}
Game::Lua::SetTop(L, 0);
diff --git a/src/map/WorldSize.cpp b/src/map/WorldSize.cpp
new file mode 100644
index 00000000..948d6e1e
--- /dev/null
+++ b/src/map/WorldSize.cpp
@@ -0,0 +1,82 @@
+// 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 .
+
+// `C_Map.GetMapWorldSize([areaID])` — the world size (in yards) of a zone,
+// as `width, height`. This is the physical extent the map represents: the
+// span of the `WorldMapArea.dbc` placement rect. Modern addons use it to
+// convert map-relative percents to yard distances (e.g. tracking-range
+// rings, "X yards away" readouts).
+//
+// With a numeric `areaID` (AreaTable id — the same identity
+// `C_Map.GetBestMapForUnit` returns and `C_Map.GetMapOverlays` accepts),
+// returns that zone's size. With no argument, returns the world map's
+// currently viewed zone (same resolution `GetMapOverlays()` uses with no
+// arg). Returns nothing (→ nil, nil) when the zone can't be resolved.
+//
+// WoW's world axes are +X north, +Y west; the WorldMapArea rect bounds
+// them as locTop/locBottom (world X) and locLeft/locRight (world Y). Map
+// width is the horizontal (east-west) extent and height the vertical
+// (north-south):
+// width = locLeft - locRight (world Y span)
+// height = locTop - locBottom (world X span)
+// The same spans are the denominators in the world→map percent transform
+// (see `Map::AreaTriggers`), so a point's `mapX% * width / 100` is its
+// offset in yards from the zone's east edge, and likewise for height.
+
+#include "Game.h"
+#include "Offsets.h"
+#include "dbc/Lookup.h"
+#include "map/Area.h"
+
+#include
+
+namespace Map::WorldSize {
+
+namespace {
+
+int __fastcall Script_GetMapWorldSize(void *L) {
+ const int row = Game::Lua::IsNumber(L, 1)
+ ? Map::Area::RowForAreaID(
+ static_cast(Game::Lua::ToNumber(L, 1)))
+ : Map::Area::CurrentViewRow();
+
+ Game::Lua::SetTop(L, 0);
+ if (row <= 0)
+ return 0; // no values -> nil, nil
+
+ const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
+ Offsets::VAR_WORLDMAP_AREA_COUNT,
+ static_cast(row));
+ if (rec == nullptr)
+ return 0;
+
+ const float left = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_LEFT);
+ const float right = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_RIGHT);
+ const float top = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_TOP);
+ const float bottom = *reinterpret_cast(rec + Offsets::OFF_WMA_LOC_BOTTOM);
+
+ Game::Lua::PushNumber(L, static_cast(left) - right); // width (world Y span)
+ Game::Lua::PushNumber(L, static_cast(top) - bottom); // height (world X span)
+ return 2;
+}
+
+void RegisterLuaFunctions() {
+ Game::Lua::RegisterTableFunction("C_Map", "GetMapWorldSize",
+ &Script_GetMapWorldSize);
+}
+
+const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
+
+} // namespace
+
+} // namespace Map::WorldSize