mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 01:23:51 +00:00
Replace MPQ runtime with loose file asset system
Extract assets from MPQ archives into organized loose files indexed by manifest.json, enabling fully parallel reads without StormLib serialization. Add asset_extract and blp_convert tools, PNG texture override support.
This commit is contained in:
parent
5fda1a3157
commit
aa16a687c2
16 changed files with 1427 additions and 101 deletions
67
tools/asset_extract/manifest_writer.cpp
Normal file
67
tools/asset_extract/manifest_writer.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "manifest_writer.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace wowee {
|
||||
namespace tools {
|
||||
|
||||
uint32_t ManifestWriter::computeCRC32(const uint8_t* data, size_t size) {
|
||||
return static_cast<uint32_t>(::crc32(::crc32(0L, Z_NULL, 0), data, static_cast<uInt>(size)));
|
||||
}
|
||||
|
||||
bool ManifestWriter::write(const std::string& outputPath,
|
||||
const std::string& basePath,
|
||||
const std::vector<FileEntry>& entries) {
|
||||
// Write JSON manually to avoid pulling nlohmann/json into the tool
|
||||
// (though it would also work fine). This keeps the tool dependency-light.
|
||||
std::ofstream file(outputPath);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
file << "{\n";
|
||||
file << " \"version\": 1,\n";
|
||||
file << " \"basePath\": \"" << basePath << "\",\n";
|
||||
file << " \"fileCount\": " << entries.size() << ",\n";
|
||||
file << " \"entries\": {\n";
|
||||
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
const auto& e = entries[i];
|
||||
|
||||
// Escape backslashes in WoW path for JSON
|
||||
std::string escapedKey;
|
||||
for (char c : e.wowPath) {
|
||||
if (c == '\\') escapedKey += "\\\\";
|
||||
else if (c == '"') escapedKey += "\\\"";
|
||||
else escapedKey += c;
|
||||
}
|
||||
|
||||
std::string escapedPath;
|
||||
for (char c : e.filesystemPath) {
|
||||
if (c == '\\') escapedPath += "\\\\";
|
||||
else if (c == '"') escapedPath += "\\\"";
|
||||
else escapedPath += c;
|
||||
}
|
||||
|
||||
// CRC32 as hex
|
||||
std::ostringstream hexCrc;
|
||||
hexCrc << std::hex << std::setfill('0') << std::setw(8) << e.crc32;
|
||||
|
||||
file << " \"" << escapedKey << "\": {\"p\": \"" << escapedPath
|
||||
<< "\", \"s\": " << e.size
|
||||
<< ", \"h\": \"" << hexCrc.str() << "\"}";
|
||||
|
||||
if (i + 1 < entries.size()) file << ",";
|
||||
file << "\n";
|
||||
}
|
||||
|
||||
file << " }\n";
|
||||
file << "}\n";
|
||||
|
||||
return file.good();
|
||||
}
|
||||
|
||||
} // namespace tools
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue