69 lines
2.7 KiB
C++
69 lines
2.7 KiB
C++
// resource_pack.hpp
|
|
// Resource pack file format and management for Los Pollos Hermanos
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace Resource {
|
|
|
|
// Entry metadata for each resource in the pack
|
|
struct ResourceEntry {
|
|
std::string filename; // Relative path within pack
|
|
uint64_t offset{0}; // Byte offset in data block
|
|
uint64_t size{0}; // Size in bytes
|
|
uint32_t checksum{0}; // CRC32 checksum for verification
|
|
};
|
|
|
|
// Resource pack file format
|
|
// Header: "POLL" (4 bytes) + Version (4 bytes)
|
|
// Metadata: Count + array of ResourceEntry
|
|
// Data: Encrypted data block
|
|
class Pack {
|
|
public:
|
|
Pack() = default;
|
|
~Pack() = default;
|
|
|
|
Pack(const Pack&) = delete; // Deleted copy/move constructors
|
|
auto operator=(const Pack&) -> Pack& = delete;
|
|
Pack(Pack&&) = delete;
|
|
auto operator=(Pack&&) -> Pack& = delete;
|
|
|
|
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool; // Building packs
|
|
auto addDirectory(const std::string& dir_path, const std::string& base_path = "") -> bool;
|
|
|
|
auto savePack(const std::string& pack_file) -> bool; // Pack I/O
|
|
auto loadPack(const std::string& pack_file) -> bool;
|
|
|
|
auto getResource(const std::string& filename) -> std::vector<uint8_t>; // Resource access
|
|
auto hasResource(const std::string& filename) const -> bool;
|
|
auto getResourceList() const -> std::vector<std::string>;
|
|
|
|
auto isLoaded() const -> bool { return loaded_; } // Status queries
|
|
auto getResourceCount() const -> size_t { return resources_.size(); }
|
|
auto getDataSize() const -> size_t { return data_.size(); }
|
|
auto calculatePackChecksum() const -> uint32_t; // Validation
|
|
|
|
private:
|
|
static constexpr std::array<char, 4> MAGIC_HEADER = {'P', 'O', 'L', 'L'}; // Pack format constants
|
|
static constexpr uint32_t VERSION = 1;
|
|
static constexpr const char* DEFAULT_ENCRYPT_KEY = "POLL_RESOURCES_2025";
|
|
|
|
static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t; // Utility methods
|
|
|
|
static void encryptData(std::vector<uint8_t>& data, const std::string& key); // Encryption/decryption
|
|
static void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
|
|
|
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>; // File I/O
|
|
|
|
std::unordered_map<std::string, ResourceEntry> resources_; // Member variables
|
|
std::vector<uint8_t> data_; // Encrypted data block
|
|
bool loaded_{false};
|
|
};
|
|
|
|
} // namespace Resource
|