Advertisement
expired6978

ItemDataInterface

Aug 25th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.89 KB | None | 0 0
  1. #pragma once
  2.  
  3. struct SKSESerializationInterface;
  4. class Actor;
  5. class ItemAttributeData;
  6.  
  7. #include "skse/GameThreads.h"
  8. #include "skse/GameExtraData.h"
  9.  
  10. #include "interfaces/IPluginInterface.h"
  11.  
  12. #include <vector>
  13. #include <map>
  14. #include <unordered_map>
  15.  
  16. typedef std::map<SInt32, UInt32> ColorMap;
  17.  
  18. struct ModifiedItem
  19. {
  20.     ModifiedItem::ModifiedItem()
  21.     {
  22.         pForm = NULL;
  23.         pExtraData = NULL;
  24.         isWorn = false;
  25.     }
  26.     TESForm         * pForm;
  27.     BaseExtraList   * pExtraData;
  28.     bool            isWorn;
  29.  
  30.     operator bool() const
  31.     {
  32.         return (pForm && pExtraData);
  33.     }
  34.  
  35.     ItemAttributeData * GetAttributeData(TESObjectREFR * reference, bool makeUnique = true, bool allowNewEntry = true, bool allowSelf = false, UInt32 * idOut = NULL);
  36. };
  37.  
  38. struct ModifiedItemIdentifier
  39. {
  40.     enum
  41.     {
  42.         kTypeNone = 0,
  43.         kTypeRank = (1 << 0),
  44.         kTypeUID = (1 << 1),
  45.         kTypeSlot = (1 << 2),
  46.         kTypeSelf = (1 << 3)
  47.     };
  48.  
  49.     enum
  50.     {
  51.         kHandSlot_Left = 0,
  52.         kHandSlot_Right
  53.     };
  54.  
  55.     UInt16          type = kTypeNone;
  56.     UInt16          uid = 0;
  57.     UInt32          ownerForm = 0;
  58.     UInt32          weaponSlot = 0;
  59.     UInt32          slotMask = 0;
  60.     UInt32          rankId = 0;
  61.     TESForm         * form = NULL;
  62.     BaseExtraList   * extraData = NULL;
  63.  
  64.     void SetRankID(UInt32 _rank)
  65.     {
  66.         type |= kTypeRank;
  67.         rankId = _rank;
  68.     }
  69.     void SetSlotMask(UInt32 _slotMask, UInt32 _weaponSlot = 0)
  70.     {
  71.         type |= kTypeSlot;
  72.         slotMask = _slotMask;
  73.         weaponSlot = _weaponSlot;
  74.     }
  75.     void SetUniqueID(UInt16 _uid, UInt32 _ownerForm)
  76.     {
  77.         type |= kTypeUID;
  78.         uid = _uid;
  79.         ownerForm = _ownerForm;
  80.     }
  81.  
  82.     bool IsSelf()
  83.     {
  84.         return (type & kTypeSelf) == kTypeSelf;
  85.     }
  86.  
  87.     void SetSelf()
  88.     {
  89.         type |= kTypeSelf;
  90.     }
  91. };
  92.  
  93. class ModifiedItemFinder
  94. {
  95. public:
  96.     ModifiedItemFinder(ModifiedItemIdentifier & identifier) : m_identifier(identifier) { }
  97.     bool Accept(InventoryEntryData* pEntryData);
  98.     ModifiedItem& Found() {
  99.         return m_found;
  100.     };
  101. private:
  102.     ModifiedItemIdentifier m_identifier;
  103.     ModifiedItem    m_found;
  104. };
  105.  
  106. class ItemAttributeData
  107. {
  108. public:
  109.     ItemAttributeData::~ItemAttributeData()
  110.     {
  111.         if (m_tintData) {
  112.             delete m_tintData;
  113.             m_tintData = NULL;
  114.         }
  115.     }
  116.  
  117.     void Save(SKSESerializationInterface * intfc, UInt32 kVersion);
  118.     bool Load(SKSESerializationInterface * intfc, UInt32 kVersion);
  119.  
  120.     class TintData
  121.     {
  122.     public:
  123.         TintData::~TintData()
  124.         {
  125.             m_colorMap.clear();
  126.         }
  127.  
  128.         ColorMap m_colorMap;
  129.  
  130.         void Save(SKSESerializationInterface * intfc, UInt32 kVersion);
  131.         bool Load(SKSESerializationInterface * intfc, UInt32 kVersion);
  132.     };
  133.  
  134.     TintData    * m_tintData = NULL;
  135. };
  136.  
  137.  
  138. static const UInt32 ITEM_ATTRIBUTE_RANK = 0;
  139. static const UInt32 ITEM_ATTRIBUTE_UID = 1;
  140. static const UInt32 ITEM_ATTRIBUTE_OWNERFORM = 2;
  141. static const UInt32 ITEM_ATTRIBUTE_FORMID = 3;
  142. static const UInt32 ITEM_ATTRIBUTE_DATA = 4;
  143.  
  144. typedef std::tuple<UInt32, UInt16, UInt32, UInt32, ItemAttributeData*> ItemAttribute;
  145.  
  146. class ItemDataInterface : public SafeDataHolder<std::vector<ItemAttribute>>, public IPluginInterface
  147. {
  148. public:
  149.     typedef std::vector<ItemAttribute> Data;
  150.  
  151.     enum
  152.     {
  153.         kCurrentPluginVersion = 1
  154.     };
  155.     virtual UInt32 GetVersion();
  156.  
  157.     virtual void Save(SKSESerializationInterface * intfc, UInt32 kVersion);
  158.     virtual bool Load(SKSESerializationInterface * intfc, UInt32 kVersion);
  159.     virtual void Revert();
  160.  
  161.     virtual UInt32 GetItemUniqueID(TESObjectREFR * reference, ModifiedItemIdentifier & identifier, bool makeUnique);
  162.     virtual void SetItemDyeColor(UInt32 uniqueID, SInt32 maskIndex, UInt32 color);
  163.     virtual UInt32 GetItemDyeColor(UInt32 uniqueID, SInt32 maskIndex);
  164.     virtual void ClearItemDyeColor(UInt32 uniqueID, SInt32 maskIndex);
  165.     virtual TESForm * GetFormFromUniqueID(UInt32 uniqueID);
  166.     virtual TESForm * GetOwnerOfUniqueID(UInt32 uniqueID);
  167.  
  168.     ItemAttributeData * GetExistingData(TESObjectREFR * reference, ModifiedItemIdentifier & identifier);
  169.     ItemAttributeData * CreateData(UInt32 rankId, UInt16 uid, UInt32 ownerId, UInt32 formId);
  170.     ItemAttributeData * GetData(UInt32 rankId);
  171.     bool UpdateUIDByRank(UInt32 rankId, UInt16 uid, UInt32 formId);
  172.     bool UpdateUID(UInt16 oldId, UInt32 oldFormId, UInt16 newId, UInt32 newFormId);
  173.     bool EraseByRank(UInt32 rankId);
  174.     bool EraseByUID(UInt32 uid, UInt32 formId);
  175.  
  176.     enum
  177.     {
  178.         kInvalidRank = 0
  179.     };
  180.  
  181.     void UseRankID() { m_nextRank++; }
  182.     UInt32 GetNextRankID() const { return m_nextRank; }
  183.     UInt32  m_nextRank = 1;
  184. };
  185.  
  186. class DyeMap : public SafeDataHolder<std::unordered_map<UInt32, UInt32>>
  187. {
  188. public:
  189.     typedef std::unordered_map<UInt32, UInt32> Data;
  190.  
  191.     UInt32 GetDyeColor(TESForm * form);
  192.     bool IsValidDye(TESForm * form);
  193.     void RegisterDyeForm(TESForm * form, UInt32 color);
  194.     void UnregisterDyeForm(TESForm * form);
  195.     void Revert();
  196. };
  197.  
  198. class NIOVTaskUpdateItemDye : public TaskDelegate
  199. {
  200. public:
  201.     NIOVTaskUpdateItemDye::NIOVTaskUpdateItemDye(Actor * actor, ModifiedItemIdentifier & identifier);
  202.     virtual void Run();
  203.     virtual void Dispose() {
  204.         delete this;
  205.     };
  206.  
  207. private:
  208.     UInt32 m_formId;
  209.     ModifiedItemIdentifier m_identifier;
  210. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement