From 53d4c1fe2f9b6ff322884b97a2ab204d7e6f5842 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 16 Oct 2026 11:13:19 -0500 Subject: [PATCH] fix: load the zone without scene lookups when its raw terrain is missing or unreadable Log at debug when it parses; build the terrain mesh only for the OBJ export; read the zone name and description only for version 31 and later, as the client does. Co-Authored-By: Claude Opus 5.5 --- dZoneManager/Zone.cpp | 39 ++++++++++++++++++--------------------- dZoneManager/Zone.h | 2 -- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index e019a7320..a5c8a1885 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -94,39 +94,36 @@ void Zone::LoadZoneIntoMemory() { } BinaryIO::ReadString(file, m_ZoneRawPath, BinaryIO::ReadType::String); - BinaryIO::ReadString(file, m_ZoneName, BinaryIO::ReadType::String); - BinaryIO::ReadString(file, m_ZoneDesc, BinaryIO::ReadType::String); - - auto zoneFolderPath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1); - if (!Game::assetManager->HasFile(zoneFolderPath + m_ZoneRawPath)) { - LOG("Failed to find %s", (zoneFolderPath + m_ZoneRawPath).c_str()); - throw std::runtime_error("Aborting Zone loading due to no Zone Raw File."); + if (m_FileFormatVersion > Zone::FileFormatVersion::PrePreAlpha) { + BinaryIO::ReadString(file, m_ZoneName, BinaryIO::ReadType::String); + BinaryIO::ReadString(file, m_ZoneDesc, BinaryIO::ReadType::String); } - auto rawFile = Game::assetManager->GetFile(zoneFolderPath + m_ZoneRawPath); + // The terrain gives the scene at a position. Like the client, a missing or unreadable .raw is logged + // and the zone loads without it. + const auto rawPath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1) + m_ZoneRawPath; if (m_FileFormatVersion < Zone::FileFormatVersion::PrePreAlpha) { - LOG("Zone %s uses legacy raw terrain format (version %u) which is not supported", m_ZoneFilePath.c_str(), static_cast(m_FileFormatVersion)); - throw std::runtime_error("Aborting Zone loading due to unsupported Raw File version."); + LOG("Zone %s uses the legacy raw terrain format (version %u), which is not supported; no scene lookups", m_ZoneFilePath.c_str(), static_cast(m_FileFormatVersion)); + } else if (!Game::assetManager->HasFile(rawPath)) { + LOG("Failed to find %s; no scene lookups", rawPath.c_str()); } else { + auto rawFile = Game::assetManager->GetFile(rawPath); if (Raw::ReadRaw(rawFile, m_Raw)) { - LOG("Successfully parsed %s", (zoneFolderPath + m_ZoneRawPath).c_str()); + LOG_DEBUG("Successfully parsed %s", rawPath.c_str()); } else { - LOG("Failed to parse %s", (zoneFolderPath + m_ZoneRawPath).c_str()); - throw std::runtime_error("Aborting Zone loading due to invalid Raw File."); + LOG("Failed to parse %s; no scene lookups", rawPath.c_str()); + m_Raw = Raw::Raw{}; } } - // Optionally export terrain mesh to OBJ for debugging/visualization if (Game::config->GetValue("export_terrain_to_obj") == "1") { + Raw::TerrainMesh terrainMesh; + Raw::GenerateTerrainMesh(m_Raw, terrainMesh); + LOG("Generated terrain mesh with %zu vertices and %zu triangles", terrainMesh.vertices.size(), terrainMesh.triangles.size() / 3); - // Generate terrain mesh - Raw::GenerateTerrainMesh(m_Raw, m_TerrainMesh); - LOG("Generated terrain mesh with %zu vertices and %zu triangles", m_TerrainMesh.vertices.size(), m_TerrainMesh.triangles.size() / 3); - - // Write to OBJ - std::string objFileName = "terrain_" + std::to_string(m_ZoneID.GetMapID()) + ".obj"; - if (Raw::WriteTerrainMeshToOBJ(m_TerrainMesh, objFileName)) { + const std::string objFileName = "terrain_" + std::to_string(m_ZoneID.GetMapID()) + ".obj"; + if (Raw::WriteTerrainMeshToOBJ(terrainMesh, objFileName)) { LOG("Exported terrain mesh to %s", objFileName.c_str()); } } diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index 4dae16754..9dd5b1629 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -234,7 +234,6 @@ public: void SetSpawnRot(const NiQuaternion& rot) { m_SpawnpointRotation = rot; } const Raw::Raw& GetZoneRaw() const { return m_Raw; } - const Raw::TerrainMesh& GetTerrainMesh() const { return m_TerrainMesh; } const SceneRef* GetScene(LWOSCENEID sceneID) const; const std::vector& GetSceneTransitions() const { return m_SceneTransitions; } const std::map& GetScenes() const { return m_Scenes; } @@ -256,7 +255,6 @@ private: std::string m_ZoneDesc; //Description of the zone by a level designer std::string m_ZoneRawPath; //Path to the .raw file of this zone. Raw::Raw m_Raw; // The Raw data for this zone - Raw::TerrainMesh m_TerrainMesh; // Pre-generated terrain mesh for fast scene lookups std::map m_Scenes; std::vector m_SceneTransitions;