mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-20 11:42:49 +00:00
feat(world): record the zone files a world loads, with sizes and hashes
ZoneFileLog keeps the .luz, .lvl, .lutriggers, terrain .raw and navmesh a world read while loading its zone: absolute path of the loose file (or the name in the pack), size and an FNV-1a hash of the bytes read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -154,6 +154,17 @@ bool AssetManager::GetFile(std::string fixedName, char** data, uint32_t* len) co
|
||||
return success;
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> AssetManager::GetLoosePath(std::string fixedName) const {
|
||||
// The same name fixing as GetFile
|
||||
std::transform(fixedName.begin(), fixedName.end(), fixedName.begin(), [](uint8_t c) { return std::tolower(c); });
|
||||
std::replace(fixedName.begin(), fixedName.end(), '\\', '/');
|
||||
if (this->m_AssetBundleType == eAssetBundleType::Unpacked) GeneralUtils::ReplaceInString(fixedName, "brickmodels", "BrickModels");
|
||||
const auto path = m_ResPath / fixedName;
|
||||
std::error_code code;
|
||||
if (!std::filesystem::exists(path, code)) return std::nullopt;
|
||||
return path;
|
||||
}
|
||||
|
||||
AssetStream AssetManager::GetFile(const char* name) const {
|
||||
char* buf; uint32_t len;
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include "Pack.h"
|
||||
#include "PackIndex.h"
|
||||
@@ -44,6 +46,12 @@ struct AssetMemoryBuffer : std::streambuf {
|
||||
setg(eback(), eback() + off, egptr());
|
||||
return gptr() - eback();
|
||||
}
|
||||
|
||||
// Every byte of the file (empty when it wasn't found)
|
||||
std::string_view Bytes() const {
|
||||
if (!m_Success) return {};
|
||||
return std::string_view(eback(), static_cast<size_t>(egptr() - eback()));
|
||||
}
|
||||
};
|
||||
|
||||
struct AssetStream : std::istream {
|
||||
@@ -56,6 +64,11 @@ struct AssetStream : std::istream {
|
||||
operator bool() {
|
||||
return reinterpret_cast<AssetMemoryBuffer*>(rdbuf())->m_Success;
|
||||
}
|
||||
|
||||
// Every byte of the file, whatever has been read of it so far
|
||||
std::string_view Bytes() const {
|
||||
return reinterpret_cast<const AssetMemoryBuffer*>(rdbuf())->Bytes();
|
||||
}
|
||||
};
|
||||
|
||||
class AssetManager {
|
||||
@@ -78,6 +91,10 @@ public:
|
||||
[[nodiscard]]
|
||||
bool GetFile(std::string name, char** data, uint32_t* len) const;
|
||||
|
||||
// Where GetFile reads name from when it is a loose file in res; nullopt when it comes from a pack or isn't there
|
||||
[[nodiscard]]
|
||||
std::optional<std::filesystem::path> GetLoosePath(std::string name) const;
|
||||
|
||||
[[nodiscard]]
|
||||
AssetStream GetFile(const char* name) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user