Files
gromandClaude Opus 5 e61976bc0e formats: the world-map goldens, and a nondeterministic continent lookup
The four map tables against the realm's own files. One real bug, and three
findings that are the realm's data rather than ours.

**`WorldMapArea::continent` was a coin flip.** It `find`s the `area_id == 0`
row for a map id, and 5875 had exactly one per map so order never mattered. The
realm ships two for map 0 — 14 "Azeroth" and its own 694 "World" — and the
lookup iterated the `by_id` `HashMap`, whose order is seeded per process. So
`continent(0)` answered Azeroth or World depending on the run. Now it walks
file order, which is the reference's own walk and picks 1.12's row; the test
asserts 14 and passes eight runs in a row where it used to flip.

- **WorldMapArea** 51 -> 132 rows loaded, of 175 in the file. The 43 dropped are
  dropped on purpose: `AreaName` empty, `AreaID` 0, the whole rect zero, one per
  instance map (33 Shadowfang through 533 Naxxramas, then the realm's 800s). An
  instance has no continent art — but `AreaID == 0` is exactly what
  `ui_world_map.rs:146` reads as "this row is a continent", so keeping them
  would put 43 unnamed continents in `GetMapContinents()`. `str_at` folds an
  empty string to `None` and the row falls out; the test now pins that as
  deliberate. The realm's third *named* continent is 694 "World", a second sheet
  over map 0 whose art ships (patch-M) but whose four rect columns are all zero
  — the only named row like that. `map_proj::zone_uv` already refuses a zero
  span and answers 0.0 instead of dividing, so that sheet puts a blip in the
  corner rather than NaN.

- **WorldMapContinent** 2 -> 3 rows. The new row's `MapID` is 42, which the same
  patch *deleted* from `Map.dbc` along with the rest of 1.12's dev test maps
  (13 "Testing", 25 "Scott Test", 29 "CashTest", 37 "Azshara Crater", 42
  "Collin's Test", 44 "<unused> Monastery"). It is inert rather than broken: the
  continent list comes from `WorldMapArea`, and this table is only ever reached
  by `wmc.get(map_id)` for maps 0 and 1, so nothing asks for continent 42.

- **The zone bitmaps are repainted.** `Azeroth.zmp` and `Kalimdor.zmp` have the
  realm's own copies in patch-3 and patch-4, and every id they write is a
  **zone** where 1.12 wrote sub-areas and left the client to roll them up.
  Azeroth: 1874 labelled cells over 34 distinct ids, all zone-level, against
  2630 over 334 of which 310 were sub-areas (Northshire Valley, Crystal Lake,
  Fargodeep Mine). After the one-hop rollup `ui_world_map.rs:193` applies, 1280
  cells agree, 534 name a *different* zone, 816 lost a zone and 60 gained one —
  a redrawn map, not a mechanical flattening. Nothing of ours needed changing:
  the rollup is a no-op on an already-flat grid. The test asserts the structural
  claim behind the number (every labelled cell is a top-level zone), which 1.12's
  own file would fail, so a decode slip cannot hide inside a re-recorded count.

- **WorldMapOverlay** 526 -> 707, and not an extension: 360 ids added, 179
  removed, 347 survivors given a different texture and rect. None of this
  table's numbering is 1.12's, so only the joins are worth asserting.

`dbc_diff` gained `--row=N`, which dumps a row from the winning copy *and* the
baseline — the only way to read a row the realm deleted, which is how the six
test maps above got their names.

benilla-formats: 25 -> 21 failures, no regressions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SgstFWtn1RxEJ5kVrpgYwn
2026-10-31 19:20:54 -06:00

187 lines
6.1 KiB
Rust

//! `WorldMapContinent.dbc`: each continent's ADT tile bounds and its place on the world map sheet,
//! read by the builder `0x4a5d00` and the world-mode projections `0x4a72b0` and `0x4a7360`.
//! vmangos does not load it.
use std::collections::HashMap;
use anyhow::{Context, Result};
use benilla_dbc::{FieldType, Schema, SchemaField};
use crate::dbc::{f32_at, parse, u32_at};
use crate::Chain;
const WORLD_MAP_CONTINENT: &str = "DBFilesClient\\WorldMapContinent.dbc";
/// One `WorldMapContinent.dbc` row.
#[derive(Clone, Debug)]
pub struct WorldMapContinent {
/// `Map.dbc` id: 0 Azeroth, 1 Kalimdor.
pub map_id: u32,
/// ADT tile column bounds, which `0x4a5d00` turns into the continent's sheet rect.
pub left_boundary: u32,
pub right_boundary: u32,
/// ADT tile row bounds.
pub top_boundary: u32,
pub bottom_boundary: u32,
/// World-sheet offsets, x on the u axis and y on v
/// (`0x4a7360`: `u = offset_x/62.625 + 0.5 - wy·k·scale`).
pub offset_x: f32,
pub offset_y: f32,
/// The world-sheet scale, 0.75 on both rows; there is no separate world zoom.
pub scale: f32,
/// The taxi map's rect in world units; no map projection reads it.
pub taxi_min: (f32, f32),
pub taxi_max: (f32, f32),
}
/// `WorldMapContinent.dbc` rows keyed by `MapID`.
pub struct WorldMapContinentCatalog {
by_map_id: HashMap<u32, WorldMapContinent>,
}
impl WorldMapContinentCatalog {
pub fn get(&self, map_id: u32) -> Option<&WorldMapContinent> {
self.by_map_id.get(&map_id)
}
pub fn len(&self) -> usize {
self.by_map_id.len()
}
pub fn is_empty(&self) -> bool {
self.by_map_id.is_empty()
}
}
fn schema() -> Schema {
let mut s = Schema::new("WorldMapContinent");
for name in [
"ID",
"MapID",
"LeftBoundary",
"RightBoundary",
"TopBoundary",
"BottomBoundary",
] {
s.add_field(SchemaField::new(name, FieldType::UInt32));
}
for name in [
"OffsetX", "OffsetY", "Scale", "TaxiMinX", "TaxiMinY", "TaxiMaxX", "TaxiMaxY",
] {
s.add_field(SchemaField::new(name, FieldType::Float32));
}
s
}
/// Read `WorldMapContinent.dbc` off the patch chain into a [`WorldMapContinentCatalog`].
pub fn load_world_map_continent_catalog(chain: &mut Chain) -> Result<WorldMapContinentCatalog> {
let bytes = chain
.read_file(WORLD_MAP_CONTINENT)
.context("reading WorldMapContinent.dbc")?;
let rs = parse(&bytes, schema(), "WorldMapContinent")?;
let mut by_map_id = HashMap::with_capacity(rs.records().len());
for r in rs.records() {
let Some(map_id) = u32_at(r, 1) else { continue };
let (
Some(left_boundary),
Some(right_boundary),
Some(top_boundary),
Some(bottom_boundary),
Some(offset_x),
Some(offset_y),
Some(scale),
Some(taxi_min_x),
Some(taxi_min_y),
Some(taxi_max_x),
Some(taxi_max_y),
) = (
u32_at(r, 2),
u32_at(r, 3),
u32_at(r, 4),
u32_at(r, 5),
f32_at(r, 6),
f32_at(r, 7),
f32_at(r, 8),
f32_at(r, 9),
f32_at(r, 10),
f32_at(r, 11),
f32_at(r, 12),
)
else {
continue;
};
by_map_id.insert(
map_id,
WorldMapContinent {
map_id,
left_boundary,
right_boundary,
top_boundary,
bottom_boundary,
offset_x,
offset_y,
scale,
taxi_min: (taxi_min_x, taxi_min_y),
taxi_max: (taxi_max_x, taxi_max_y),
},
);
}
Ok(WorldMapContinentCatalog { by_map_id })
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn real_world_map_continent_has_azeroth_and_kalimdor() {
let data = crate::wow_data_or_skip!();
let mut chain = crate::open_chain(&data).expect("open chain");
let cat = load_world_map_continent_catalog(&mut chain).expect("load WorldMapContinent");
// Three rows where 5875 had two. The realm's is row 3, and its `MapID` is 42 — which the
// same patch *deleted* from `Map.dbc`, along with the rest of 1.12's dev test maps (13
// "Testing", 25 "Scott Test", 29 "CashTest", 37 "Azshara Crater", 42 "Collin's Test", 44
// "<unused> Monastery"). So the row names a map that does not exist.
//
// It is inert rather than broken: the continent list the world map builds comes from
// `WorldMapArea`'s `AreaID == 0` rows (`ui_world_map.rs:146`), which name maps 0 and 1
// only, and this table is reached by `wmc.get(map_id)` for those — never walked. Nothing
// asks for continent 42.
assert_eq!(cat.len(), 3, "5875 shipped two continents");
assert!(
cat.get(42).is_some(),
"the realm's third row is keyed on the map it deleted"
);
let azeroth = cat.get(0).expect("Azeroth (mapId 0)");
assert_eq!(
(
azeroth.left_boundary,
azeroth.right_boundary,
azeroth.top_boundary,
azeroth.bottom_boundary
),
(23, 47, 15, 61)
);
assert!((azeroth.offset_x - 14.5).abs() < 0.01);
assert!((azeroth.offset_y - (-7.0)).abs() < 0.01);
assert!((azeroth.scale - 0.75).abs() < 0.001);
assert!((azeroth.taxi_min.0 - (-15980.0)).abs() < 0.1);
assert!((azeroth.taxi_min.1 - (-11880.0)).abs() < 0.1);
assert!((azeroth.taxi_max.0 - 5817.0).abs() < 0.1);
assert!((azeroth.taxi_max.1 - 9917.0).abs() < 0.1);
let kalimdor = cat.get(1).expect("Kalimdor (mapId 1)");
assert_eq!(
(
kalimdor.left_boundary,
kalimdor.right_boundary,
kalimdor.top_boundary,
kalimdor.bottom_boundary
),
(23, 48, 9, 52)
);
assert!((kalimdor.scale - 0.75).abs() < 0.001);
}
}