arreglos d'estil en source/core/resources

This commit is contained in:
2025-11-18 12:41:30 +01:00
parent 4477cc4bbc
commit b7db34cdf7
9 changed files with 135 additions and 295 deletions
+18 -44
View File
@@ -1,9 +1,7 @@
// resource_pack.hpp
// Resource pack file format and management for JailDoctor's Dilemma
// Based on Coffee Crisis Arcade Edition resource pack system
#ifndef RESOURCE_PACK_HPP
#define RESOURCE_PACK_HPP
#pragma once
#include <array>
#include <cstdint>
@@ -15,10 +13,10 @@ namespace Resource {
// Entry metadata for each resource in the pack
struct ResourceEntry {
std::string filename; // Relative path within pack
uint64_t offset; // Byte offset in data block
uint64_t size; // Size in bytes
uint32_t checksum; // CRC32 checksum for verification
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
@@ -30,65 +28,41 @@ class Pack {
Pack() = default;
~Pack() = default;
// Disable copy/move
Pack(const Pack&) = delete;
Pack(const Pack&) = delete; // Deleted copy/move constructors
auto operator=(const Pack&) -> Pack& = delete;
Pack(Pack&&) = delete;
auto operator=(Pack&&) -> Pack& = delete;
// Add a single file to the pack
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool;
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;
// Add all files from a directory recursively
auto addDirectory(const std::string& dir_path, const std::string& base_path = "")
-> bool;
// Save the pack to a file
auto savePack(const std::string& pack_file) -> bool;
// Load a pack from a file
auto savePack(const std::string& pack_file) -> bool; // Pack I/O
auto loadPack(const std::string& pack_file) -> bool;
// Get a resource by name
auto getResource(const std::string& filename) -> std::vector<uint8_t>;
// Check if a resource exists
auto getResource(const std::string& filename) -> std::vector<uint8_t>; // Resource access
auto hasResource(const std::string& filename) const -> bool;
// Get list of all resources
auto getResourceList() const -> std::vector<std::string>;
// Check if pack is loaded
auto isLoaded() const -> bool { return loaded_; }
// Get pack statistics
auto isLoaded() const -> bool { return loaded_; } // Status queries
auto getResourceCount() const -> size_t { return resources_.size(); }
auto getDataSize() const -> size_t { return data_.size(); }
// Calculate overall pack checksum (for validation)
auto calculatePackChecksum() const -> uint32_t;
auto calculatePackChecksum() const -> uint32_t; // Validation
private:
static constexpr std::array<char, 4> MAGIC_HEADER = {'J', 'D', 'D', 'I'};
static constexpr std::array<char, 4> MAGIC_HEADER = {'J', 'D', 'D', 'I'}; // Pack format constants
static constexpr uint32_t VERSION = 1;
static constexpr const char* DEFAULT_ENCRYPT_KEY = "JDDI_RESOURCES_2024";
// Calculate CRC32 checksum
static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t;
static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t; // Utility methods
// XOR encryption/decryption
static void encryptData(std::vector<uint8_t>& data, const std::string& key);
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);
// Read file from disk
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>;
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>; // File I/O
// Member data
std::unordered_map<std::string, ResourceEntry> resources_;
std::vector<uint8_t> data_; // Encrypted data block
std::unordered_map<std::string, ResourceEntry> resources_{}; // Member variables
std::vector<uint8_t> data_{}; // Encrypted data block
bool loaded_{false};
};
} // namespace Resource
#endif // RESOURCE_PACK_HPP