econmanager.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _INCLUDE_DYNATTRIB_ECON_MANAGER_H_
  2. #define _INCLUDE_DYNATTRIB_ECON_MANAGER_H_
  3. #include "mmsplugin.h"
  4. #include <map>
  5. #include <memory>
  6. #include <utlmap.h>
  7. #include <utlstring.h>
  8. #include <KeyValues.h>
  9. class ISchemaAttributeType;
  10. // this may need to be updated in the future
  11. class CEconItemAttributeDefinition
  12. {
  13. public:
  14. // TODO implementing ~CEconItemAttributeDefinition segfaults. not sure what's up.
  15. // ideally we implement it to match the game so InsertOrReplace is sure to work correctly
  16. /* 0x00 */ KeyValues *m_KeyValues;
  17. /* 0x04 */ unsigned short m_iIndex;
  18. /* 0x08 */ ISchemaAttributeType *m_AttributeType;
  19. /* 0x0c */ bool m_bHidden;
  20. /* 0x0d */ bool m_bForceOutputDescription;
  21. /* 0x0e */ bool m_bStoreAsInteger;
  22. /* 0x0f */ bool m_bInstanceData;
  23. /* 0x10 */ int m_iAssetClassExportType;
  24. /* 0x14 */ int m_iAssetClassBucket;
  25. /* 0x18 */ bool m_bIsSetBonus;
  26. /* 0x1c */ int m_iIsUserGenerated;
  27. /* 0x20 */ int m_iEffectType;
  28. /* 0x24 */ int m_iDescriptionFormat;
  29. /* 0x28 */ char *m_pszDescriptionString;
  30. /* 0x2c */ char *m_pszArmoryDesc;
  31. /* 0x30 */ char *m_pszName;
  32. /* 0x34 */ char *m_pszAttributeClass;
  33. /* 0x38 */ bool m_bCanAffectMarketName;
  34. /* 0x39 */ bool m_bCanAffectRecipeCompName;
  35. /* 0x3c */ int m_nTagHandle;
  36. /* 0x40 */ string_t m_iszAttributeClass;
  37. };
  38. /**
  39. * Copied implementation of KeyValues::AutoDelete.
  40. */
  41. class AutoKeyValues {
  42. public:
  43. AutoKeyValues() : m_pKeyValues{nullptr} {}
  44. AutoKeyValues(KeyValues *pKeyValues) : m_pKeyValues{pKeyValues->MakeCopy()} {}
  45. AutoKeyValues(const AutoKeyValues &other) : m_pKeyValues{other.m_pKeyValues->MakeCopy()} {}
  46. ~AutoKeyValues() {
  47. if (m_pKeyValues) {
  48. m_pKeyValues->deleteThis();
  49. }
  50. }
  51. KeyValues *operator->() const { return m_pKeyValues; }
  52. operator KeyValues *() const { return m_pKeyValues; }
  53. private:
  54. KeyValues *m_pKeyValues;
  55. };
  56. /**
  57. * Keeps a copy of existing schema items to inject.
  58. */
  59. class CEconManager {
  60. public:
  61. CEconManager() : m_RegisteredAttributes{} {}
  62. bool Init(char *error, size_t maxlength);
  63. bool InsertOrReplaceAttribute(KeyValues *pAttribKV);
  64. bool RegisterAttribute(KeyValues *pAttribKV);
  65. void InstallAttributes();
  66. private:
  67. std::map<std::string, AutoKeyValues> m_RegisteredAttributes;
  68. };
  69. // binary refers to 0x58 when iterating over the attribute map, so we'll refer to that value
  70. // we could also do a runtime assertion
  71. static_assert(sizeof(CEconItemAttributeDefinition) + 0x14 == 0x58, "CEconItemAttributeDefinition size mismatch");
  72. extern CEconManager g_EconManager;
  73. #endif // _INCLUDE_DYNATTRIB_ECON_MANAGER_H_