fix(editor): clamp project mapId and zone tile coords on load

A hand-edited project.json could carry a 0 or massively-OOR mapId
(would break DBC indexing) or tile coords outside 0..63 (would
produce garbage ADT filenames). Defaults restore safe values.
This commit is contained in:
Kelsi 2026-05-06 06:45:09 -07:00
parent 721efb2ecb
commit 0a5583310c

View file

@ -49,6 +49,10 @@ bool EditorProject::load(const std::string& path) {
startMapId = j.value("startMapId", 9000u);
projectDir = std::filesystem::path(path).parent_path().string();
// Cap mapId to a reasonable range. mapId 0 is reserved for Eastern
// Kingdoms; >65535 wraps DBC fields. Custom zones live in 9000+.
if (startMapId == 0 || startMapId > 65535) startMapId = 9000;
zones.clear();
if (j.contains("zones") && j["zones"].is_array()) {
for (const auto& jz : j["zones"]) {
@ -58,6 +62,10 @@ bool EditorProject::load(const std::string& path) {
z.tileY = jz.value("tileY", 32);
z.biome = jz.value("biome", "");
z.description = jz.value("description", "");
// Tile coords valid 0..63 in WoW. Out-of-range values would
// produce garbage ADT filenames or off-map terrain placement.
if (z.tileX < 0 || z.tileX > 63) z.tileX = 32;
if (z.tileY < 0 || z.tileY > 63) z.tileY = 32;
if (!z.mapName.empty()) zones.push_back(z);
}
}