whiteoutlib 0.1.4

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
//
// AUTO-GENERATED by scripts/gen_sno_defs.py — do not edit manually.

#pragma once

#include "../sno_defs.h"

#include <cstddef>
#include <span>
#include <utility>

namespace whiteout {
namespace sno {
namespace d4 {

/// Compiled type registry for Diablo IV SNO formats.
///
/// Loaded once from the static tables generated by gen_sno_defs.py.
class SnoTypeRegistry final : public sno::SnoTypeRegistry {
public:
    /// Get the singleton instance (built from the compiled-in data).
    static const SnoTypeRegistry& instance();

    const SnoTypeDef* findType(u32 typeHash) const override;
    u32 typeHashFromKey(u32 key) const override;
    const char* typeName(const SnoTypeDef& def) const override;
    std::span<const SnoFieldDef> fields(const SnoTypeDef& def) const override;
    const char* fieldName(const SnoFieldDef& def) const override;
    u32 typeHashFromName(const char* name) const override;

private:
    SnoTypeRegistry();

    const SnoTypeDef* m_types = nullptr;
    size_t m_typeCount = 0;

    const SnoFieldDef* m_fields = nullptr;
    size_t m_fieldCount = 0;

    const char* const* m_typeNames = nullptr;
    const char* const* m_fieldNames = nullptr;

    // Sorted array of (formatHash, typeHash) pairs for binary search
    const std::pair<u32, u32>* m_formatMap = nullptr;
    size_t m_formatMapCount = 0;

    // Hash table: typeHash → index into m_types
    static constexpr size_t kHashBuckets = 8192;
    [[maybe_unused]] u32 m_hashTable[kHashBuckets] = {}; // stores index+1, 0 = empty
    [[maybe_unused]] u32 m_hashNext[1] = {}; // placeholder — actual memory is m_types-sized
    // We use the static arrays directly and build a simple open-addressing table.
    u32* m_hashLookup = nullptr; // typeHash → dense index (allocated in ctor)
};

} // namespace d4
} // namespace sno
} // namespace whiteout