fix: read and keep a zone file's scenes as the client does

LuzFile::ReadLUZFile, LuzReader::ReadScenes and ZoneLoader::ReadZoneFile
(1.10.64):
- a version older than 20 is read as 20;
- before version 30 a scene is a bare u32 SceneTable ID: in ID order,
  each one with a SceneTable row gets the next index (-1 past 255) as
  its ID and the row's sceneName as its file; the others are left out;
- from 30 to 32 the file has no scene IDs: a scene's ID is its index in
  the file (they all had ID 0, colliding);
- a later scene with the same ID and layer replaces an earlier one, a
  scene ID with no layer 0 scene is left out, and before version 41
  only the layer 0 scenes are loaded.

No 1.10.64 zone file has a duplicate scene, a scene without a layer 0
scene or another layer before version 41, so what live zones load is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-26 21:29:58 -05:00
parent c1dea4205b
commit d0d280d3ad
5 changed files with 178 additions and 12 deletions

View File

@@ -32,6 +32,13 @@ Zone::Zone(const LWOZONEID zoneID) :
m_CheckSum = 0;
m_WorldID = 0;
m_SceneCount = 0;
m_SceneTableLookup = [](uint32_t sceneTableID) -> std::optional<std::string> {
auto query = CDClientDatabase::CreatePreppedStmt("SELECT sceneName FROM SceneTable WHERE sceneID = ?;");
query.bind(1, static_cast<int32_t>(sceneTableID));
auto result = query.execQuery();
if (result.eof() || result.fieldIsNull("sceneName")) return std::nullopt;
return std::string(result.getStringField("sceneName"));
};
}
Zone::~Zone() {
@@ -63,13 +70,7 @@ void Zone::LoadZoneIntoMemory() {
ZoneFile zoneFile;
zoneFile.Read(file);
// The oldest files name their scenes by SceneTable ID
zoneFile.ResolveSceneTable([](uint32_t sceneTableID) -> std::optional<std::string> {
auto query = CDClientDatabase::CreatePreppedStmt("SELECT sceneName FROM SceneTable WHERE sceneID = ?;");
query.bind(1, static_cast<int32_t>(sceneTableID));
auto result = query.execQuery();
if (result.eof() || result.fieldIsNull("sceneName")) return std::nullopt;
return std::string(result.getStringField("sceneName"));
});
zoneFile.ResolveSceneTable(m_SceneTableLookup);
m_FileFormatVersion = zoneFile.fileFormatVersion;
m_WorldID = zoneFile.worldID;
if (static_cast<LWOMAPID>(m_WorldID) != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID());