fix(content-pack): unpackZone now creates the zone subdirectory

packZone stores files relative to the zone subdirectory (e.g. just
'MyZone_32_32.adt'), so unpacking to 'custom_zones/' produced files at
'custom_zones/MyZone_32_32.adt' — without the zone subdir the loader
expects. Now reads the info JSON to extract the zone name and unpacks
to 'custom_zones/<zoneName>/' so imported zones load correctly.
This commit is contained in:
Kelsi 2026-05-06 04:32:28 -07:00
parent a0e363f706
commit 8d78b5f8c6

View file

@ -108,11 +108,21 @@ bool ContentPacker::unpackZone(const std::string& wcpPath, const std::string& de
in.read(reinterpret_cast<char*>(&fileCount), 4);
in.read(reinterpret_cast<char*>(&infoSize), 4);
// Skip info JSON
in.seekg(infoSize, std::ios::cur);
// Read the info JSON to extract the zone name. packZone stored files
// relative to the zone subdirectory (e.g. "MyZone_32_32.adt"), so we
// need to recreate that subdirectory under destDir for the loader to
// find the zone.
std::string infoJson(infoSize, '\0');
in.read(infoJson.data(), infoSize);
std::string zoneName;
try {
auto info = nlohmann::json::parse(infoJson);
zoneName = info.value("name", "");
} catch (...) {}
namespace fs = std::filesystem;
fs::create_directories(destDir);
std::string zoneDir = zoneName.empty() ? destDir : destDir + "/" + zoneName;
fs::create_directories(zoneDir);
for (uint32_t i = 0; i < fileCount; i++) {
uint16_t pathLen;
@ -126,13 +136,13 @@ bool ContentPacker::unpackZone(const std::string& wcpPath, const std::string& de
std::vector<char> data(dataSize);
in.read(data.data(), dataSize);
std::string fullPath = destDir + "/" + path;
std::string fullPath = zoneDir + "/" + path;
fs::create_directories(fs::path(fullPath).parent_path());
std::ofstream fout(fullPath, std::ios::binary);
fout.write(data.data(), dataSize);
}
LOG_INFO("Content pack extracted to: ", destDir, " (", fileCount, " files)");
LOG_INFO("Content pack extracted to: ", zoneDir, " (", fileCount, " files)");
return true;
}