Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.7 KiB

  1. //========= Copyright � 1996-2003, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ECON_ITEM_SYSTEM_H
  7. #define ECON_ITEM_SYSTEM_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "econ_item_view.h"
  12. #include "game_item_schema.h"
  13. #include "game/shared/econ/iecon_item_system.h"
  14. //==================================================================================
  15. // ITEM SYSTEM
  16. //==================================================================================
  17. #define INVALID_ITEM_INDEX -1
  18. #define GC_MOTD_CACHE_FILE "cfg/motd_entries.txt"
  19. // The item system parses and creates a list of item classes from the item_classes.txt file.
  20. //-----------------------------------------------------------------------------
  21. // Criteria used by the system to generate a random attribute
  22. struct randomattributecriteria_t
  23. {
  24. randomattributecriteria_t()
  25. {
  26. entityType = AE_MAX_TYPES;
  27. iAttributeLevel = 0;
  28. pItem = NULL;
  29. }
  30. entityquality_t entityType;
  31. int iAttributeLevel;
  32. CEconItemView *pItem;
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Container for all the static item definitions in the item data files
  36. //-----------------------------------------------------------------------------
  37. class CEconItemSystem : public IEconItemSystem
  38. {
  39. public:
  40. CEconItemSystem( void );
  41. virtual ~CEconItemSystem( void );
  42. // Setup & parse in the item data files.
  43. void Init( void );
  44. void Shutdown( void );
  45. // Return the static item data for the specified item index
  46. const GameItemDefinition_t *GetStaticDataForItemByDefIndex( item_definition_index_t iItemDefIndex ) const
  47. {
  48. return static_cast< const GameItemDefinition_t* >( m_itemSchema.GetItemDefinition( iItemDefIndex ) );
  49. }
  50. const CEconItemDefinition *GetStaticDataForItemByName( const char *pszDefName ) const
  51. {
  52. return m_itemSchema.GetItemDefinitionByName( pszDefName );
  53. }
  54. const CEconItemAttributeDefinition *GetStaticDataForAttributeByDefIndex( attrib_definition_index_t iAttribDefinitionIndex ) const
  55. {
  56. return m_itemSchema.GetAttributeDefinition( iAttribDefinitionIndex );
  57. }
  58. const CEconItemAttributeDefinition *GetStaticDataForAttributeByName( const char *pszDefName ) const
  59. {
  60. return m_itemSchema.GetAttributeDefinitionByName( pszDefName );
  61. }
  62. // Select and return a random item's definition index matching the specified criteria
  63. int GenerateRandomItem( CItemSelectionCriteria *pCriteria, entityquality_t *outEntityQuality );
  64. // Select and return the base item definition index for a class's load-out slot
  65. // Note: baseitemcriteria_t is game-specific and/or may not exist!
  66. virtual int GenerateBaseItem( struct baseitemcriteria_t *pCriteria ) { return INVALID_ITEM_INDEX; }
  67. // Return a random item quality
  68. entityquality_t GetRandomQualityForItem( bool bPreventUnique = false );
  69. // Generate an attribute of the specified definition
  70. CEconItemAttribute *GenerateAttribute( attrib_definition_index_t iAttributeDefinition, float flValue );
  71. // Generate an attribute by name. Used for debugging.
  72. CEconItemAttribute *GenerateAttribute( const char *pszName, float flValue );
  73. // Decrypt the item files and return the keyvalue
  74. bool DecryptItemFiles( KeyValues *pKV, const char *pName );
  75. GameItemSchema_t *GetItemSchema() { return &m_itemSchema; }
  76. // Open the server's whitelist, and if it exists, set the appropriate items allowed.
  77. void ReloadWhitelist( void );
  78. void ResetAttribStringCache( void );
  79. // Public interface.
  80. virtual IEconItemSchema* GetItemSchemaInterface() { return GetItemSchema(); }
  81. virtual void RequestReservedItemDefinitionList() {};
  82. virtual void ReserveItemDefinition( uint32 nDefIndex, const char* pszUserName ) {};
  83. virtual void ReleaseItemDefReservation( uint32 nDefIndex, const char* pszUserName ) {};
  84. protected:
  85. // Read the specified item schema file. Init the item schema with the contents
  86. void ParseItemSchemaFile( const char *pFilename );
  87. // Key to decrypt the item description files
  88. const unsigned char *GetEncryptionKey( void ) { return (unsigned char *)"A5fSXbf7"; }
  89. private:
  90. GameItemSchema_t m_itemSchema;
  91. };
  92. CEconItemSystem *ItemSystem( void );
  93. // CGCFetchWebResource
  94. class CGCFetchWebResource : public GCSDK::CGCClientJob
  95. {
  96. public:
  97. CGCFetchWebResource( GCSDK::CGCClient *pClient, CUtlString strName, CUtlString strURL, bool bForceSkipCache = false, KeyValues *pkvGETParams = NULL );
  98. virtual ~CGCFetchWebResource();
  99. bool BYieldingRunGCJob();
  100. void OnHTTPCompleted( HTTPRequestCompleted_t *arg, bool bFailed );
  101. private:
  102. CUtlString m_strName;
  103. CUtlString m_strURL;
  104. bool m_bForceSkipCache;
  105. bool m_bHTTPCompleted;
  106. KeyValues *m_pkvGETParams;
  107. CCallResult< CGCFetchWebResource, HTTPRequestCompleted_t > callback;
  108. };
  109. #endif // ECON_ITEM_SYSTEM_H