items.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. #include <optional>
  5. #include <span>
  6. namespace sunrise::middleware::content::packages::tables::items {
  7. /** Ordinary socket lanes an item definition can declare. */
  8. inline constexpr std::size_t kSocketCapacity = 12;
  9. /** All bits set marks a socket lane with no initial plug. */
  10. inline constexpr std::uint16_t kUnavailablePlug = 0xFFFF;
  11. /** All bits set marks an item definition with no insertion or enable requirement set. */
  12. inline constexpr std::uint16_t kUnavailableMaterialRequirementSetIndex = 0xFFFFU;
  13. /** Declared stat contributions one definition carries. Shipped rows stay far below this. */
  14. inline constexpr std::size_t kStatCapacity = 64;
  15. /** Sandbox perk indices one definition declares. The widest shipped item declares 4. */
  16. inline constexpr std::size_t kSandboxPerkCapacity = 4;
  17. /** Material override rows one definition declares over its 3 art stages. Widest shipped is 30. */
  18. inline constexpr std::size_t kRenderOverrideCapacity = 32;
  19. /** All bits set marks an art index the definition does not declare. */
  20. inline constexpr std::uint16_t kUnavailableArtIndex = 0xFFFF;
  21. /** Generic art plus one row for each of Titan, Hunter, and Warlock. */
  22. inline constexpr std::size_t kArtClassCapacity = 4;
  23. /** All bits set marks a socket lane whose type the definition does not declare. */
  24. inline constexpr std::uint16_t kUnavailableSocketType = 0xFFFF;
  25. /** A signed material override key is empty at minus one. */
  26. inline constexpr std::int8_t kEmptyOverrideKey = -1;
  27. /** One material override row, tagged with the art stage that declared it. */
  28. struct RenderOverride {
  29. std::uint8_t stage{};
  30. std::int8_t key{kEmptyOverrideKey};
  31. std::uint16_t value{};
  32. };
  33. /** One item row read from its own definition blob. */
  34. struct Row {
  35. std::uint32_t definitionHash{};
  36. std::uint16_t definitionIndex{};
  37. std::uint8_t bucketId{};
  38. std::int32_t maxStackSize{};
  39. bool instanced{};
  40. std::optional<std::int8_t> equipmentSlot{};
  41. std::int32_t rawEquipmentSlot{};
  42. bool hasSocketEntryList{};
  43. std::uint16_t socketEntryListIndex{};
  44. bool hasSockets{};
  45. std::uint8_t socketCount{};
  46. std::uint16_t initialPlugs[kSocketCapacity]{};
  47. std::uint16_t socketTypes[kSocketCapacity]{};
  48. /** Plug category used by a few native sockets to expand a seed into its whole safe family. */
  49. std::uint32_t plugCategoryHash{};
  50. /** Native material sets used when this definition is inserted or enabled as a plug. */
  51. std::uint16_t insertionMaterialRequirementSetIndex{kUnavailableMaterialRequirementSetIndex};
  52. std::uint16_t enabledMaterialRequirementSetIndex{kUnavailableMaterialRequirementSetIndex};
  53. std::uint8_t statCount{};
  54. std::uint8_t statRows[kStatCapacity]{};
  55. std::int32_t statValues[kStatCapacity]{};
  56. /** Gear art definition index, read straight from the art block. */
  57. std::uint16_t gearArtIndex{kUnavailableArtIndex};
  58. /** Generic, Titan, Hunter, and Warlock art arrangements declared by the art block. */
  59. std::uint16_t artArrangementIndices[kArtClassCapacity]{};
  60. std::uint8_t sandboxPerkCount{};
  61. std::uint16_t sandboxPerks[kSandboxPerkCapacity]{};
  62. std::uint8_t renderOverrideCount{};
  63. RenderOverride renderOverrides[kRenderOverrideCapacity]{};
  64. };
  65. /**
  66. * Reads the art indices, material override rows and sandbox perks one definition declares.
  67. * All three live behind self-relative blob offsets and are valid only against the serialized
  68. * definition, never against a loaded definition in process memory.
  69. * @param definition Whole item definition bytes.
  70. * @param row Receives the art, material override and sandbox perk fields.
  71. */
  72. void read_appearance(std::span<const std::byte> definition, Row& row) noexcept;
  73. /**
  74. * Reads the fixed fields of one item definition blob.
  75. * @param definition Whole item definition bytes.
  76. * @param row Receives every field the blob declares.
  77. * @return True when the blob is long enough to carry the fixed fields.
  78. */
  79. [[nodiscard]] bool read_definition(std::span<const std::byte> definition, Row& row) noexcept;
  80. /** Visitor called for each native item-definition index an ordinary socket list names. */
  81. using AllowedPlugVisitor = bool (*)(void* context, std::uint32_t itemDefinitionIndex) noexcept;
  82. /**
  83. * Visits the embedded, reusable, and randomized plug-list members declared for one socket
  84. * lane.
  85. * The initial plug is a separate fixed field and is intentionally left to the caller.
  86. *
  87. * @param definition Whole base-item definition bytes.
  88. * @param plugSetTable Whole shared plug-set
  89. * definition table from investment-root slot 51.
  90. * @param lane Ordinary socket lane to inspect.
  91. *
  92. * @param visitor Required bounded consumer.
  93. * @param context Opaque consumer state.
  94. * @return
  95. * True when every referenced array is structurally valid and accepted by the visitor.
  96. */
  97. [[nodiscard]] bool visit_allowed_plugs(std::span<const std::byte> definition,
  98. std::span<const std::byte> plugSetTable,
  99. std::uint8_t lane,
  100. AllowedPlugVisitor visitor,
  101. void* context) noexcept;
  102. } // namespace sunrise::middleware::content::packages::tables::items