whiteoutlib 0.1.3

Read and write Blizzard game assets from Rust: models (MDX, M2, M3), textures (BLP, DDS, PNG, JPEG, BMP, TGA, TIFF, GIF) and archives (CASC, MPQ).
Documentation
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Fernando Sahmkow
/// @file d3_root.h
/// @brief Diablo III root manifest parser (hierarchical directory format).
///
/// Internal header — not part of the public include path.
#pragma once

#include "common/entry_index.h"
#include "root.h"

#include <span>
#include <vector>

namespace whiteout::interfaces {
class WorkerPool;
}

namespace whiteout::storages::casc {

class D3Root final : public RootManifest {
public:
    /// Parse a D3 root file.
    /// @param data     Raw (BLTE-decoded) root directory bytes.
    /// @param resolver Callback that resolves CKey → file data (for sub-directories).
    ///                 May be nullptr if sub-directory resolution is not needed.
    /// @return Parsed root, or nullptr on failure.
    static std::unique_ptr<D3Root> parse(std::span<const u8> data, CKeyResolver resolver = nullptr,
                                         interfaces::WorkerPool* pool = nullptr);

    // --- RootManifest interface ---
    std::vector<const RootEntry*> findByPath(const std::string& path) const override;
    std::vector<const RootEntry*> findByNormalizedPath(
        const std::string& normalizedPath) const override;
    bool hasPath(const std::string& normalizedPath) const override;
    std::vector<const RootEntry*> findByFileDataId(
        u32 fileDataId, FileIdHint hint = FileIdHint::None) const override;
    bool hasFileDataId(u32 fileDataId, FileIdHint hint = FileIdHint::None) const override;
    RootFormat format() const override {
        return RootFormat::Diablo3;
    }

protected:
    const std::vector<RootEntry>& entries() const override {
        return m_entries;
    }
    std::vector<RootEntry>& mutableEntries() override {
        return m_entries;
    }

private:
    /// All entries in flat storage.
    std::vector<RootEntry> m_entries;

    /// Path-based lookup (lowercase normalized).
    EntryIndex<std::string> m_byPath;

    /// FileDataId-based lookup (fileIndex = SNO ID).
    EntryIndex<u32> m_byFileDataId;

    void buildIndices(interfaces::WorkerPool* pool = nullptr);
};

} // namespace whiteout::storages::casc