Team Fortress 2 Source Code as on 22/4/2020
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.

354 lines
20 KiB

  1. //====== Copyright � 1996-2014 Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to Steam Inventory
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMINVENTORY_H
  7. #define ISTEAMINVENTORY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. // callbacks
  13. #if defined( VALVE_CALLBACK_PACK_SMALL )
  14. #pragma pack( push, 4 )
  15. #elif defined( VALVE_CALLBACK_PACK_LARGE )
  16. #pragma pack( push, 8 )
  17. #else
  18. #error isteamclient.h must be included
  19. #endif
  20. // Every individual instance of an item has a globally-unique ItemInstanceID.
  21. // This ID is unique to the combination of (player, specific item instance)
  22. // and will not be transferred to another player or re-used for another item.
  23. typedef uint64 SteamItemInstanceID_t;
  24. static const SteamItemInstanceID_t k_SteamItemInstanceIDInvalid = ~(SteamItemInstanceID_t)0;
  25. // Types of items in your game are identified by a 32-bit "item definition number".
  26. // Valid definition numbers are between 1 and 999999999; numbers less than or equal to
  27. // zero are invalid, and numbers greater than or equal to one billion (1x10^9) are
  28. // reserved for internal Steam use.
  29. typedef int32 SteamItemDef_t;
  30. enum ESteamItemFlags
  31. {
  32. // Item status flags - these flags are permanently attached to specific item instances
  33. k_ESteamItemNoTrade = 1 << 0, // This item is account-locked and cannot be traded or given away.
  34. // Action confirmation flags - these flags are set one time only, as part of a result set
  35. k_ESteamItemRemoved = 1 << 8, // The item has been destroyed, traded away, expired, or otherwise invalidated
  36. k_ESteamItemConsumed = 1 << 9, // The item quantity has been decreased by 1 via ConsumeItem API.
  37. // All other flag bits are currently reserved for internal Steam use at this time.
  38. // Do not assume anything about the state of other flags which are not defined here.
  39. };
  40. struct SteamItemDetails_t
  41. {
  42. SteamItemInstanceID_t m_itemId;
  43. SteamItemDef_t m_iDefinition;
  44. uint16 m_unQuantity;
  45. uint16 m_unFlags; // see ESteamItemFlags
  46. };
  47. typedef int32 SteamInventoryResult_t;
  48. static const SteamInventoryResult_t k_SteamInventoryResultInvalid = -1;
  49. //-----------------------------------------------------------------------------
  50. // Purpose: Steam Inventory query and manipulation API
  51. //-----------------------------------------------------------------------------
  52. class ISteamInventory
  53. {
  54. public:
  55. // INVENTORY ASYNC RESULT MANAGEMENT
  56. //
  57. // Asynchronous inventory queries always output a result handle which can be used with
  58. // GetResultStatus, GetResultItems, etc. A SteamInventoryResultReady_t callback will
  59. // be triggered when the asynchronous result becomes ready (or fails).
  60. //
  61. // Find out the status of an asynchronous inventory result handle. Possible values:
  62. // k_EResultPending - still in progress
  63. // k_EResultOK - done, result ready
  64. // k_EResultExpired - done, result ready, maybe out of date (see DeserializeResult)
  65. // k_EResultInvalidParam - ERROR: invalid API call parameters
  66. // k_EResultServiceUnavailable - ERROR: service temporarily down, you may retry later
  67. // k_EResultLimitExceeded - ERROR: operation would exceed per-user inventory limits
  68. // k_EResultFail - ERROR: unknown / generic error
  69. METHOD_DESC(Find out the status of an asynchronous inventory result handle.)
  70. virtual EResult GetResultStatus( SteamInventoryResult_t resultHandle ) = 0;
  71. // Copies the contents of a result set into a flat array. The specific
  72. // contents of the result set depend on which query which was used.
  73. METHOD_DESC(Copies the contents of a result set into a flat array. The specific contents of the result set depend on which query which was used.)
  74. virtual bool GetResultItems( SteamInventoryResult_t resultHandle,
  75. OUT_ARRAY_COUNT( punOutItemsArraySize,Output array) SteamItemDetails_t *pOutItemsArray,
  76. uint32 *punOutItemsArraySize ) = 0;
  77. // Returns the server time at which the result was generated. Compare against
  78. // the value of IClientUtils::GetServerRealTime() to determine age.
  79. METHOD_DESC(Returns the server time at which the result was generated. Compare against the value of IClientUtils::GetServerRealTime() to determine age.)
  80. virtual uint32 GetResultTimestamp( SteamInventoryResult_t resultHandle ) = 0;
  81. // Returns true if the result belongs to the target steam ID, false if the
  82. // result does not. This is important when using DeserializeResult, to verify
  83. // that a remote player is not pretending to have a different user's inventory.
  84. METHOD_DESC(Returns true if the result belongs to the target steam ID or false if the result does not. This is important when using DeserializeResult to verify that a remote player is not pretending to have a different users inventory.)
  85. virtual bool CheckResultSteamID( SteamInventoryResult_t resultHandle, CSteamID steamIDExpected ) = 0;
  86. // Destroys a result handle and frees all associated memory.
  87. METHOD_DESC(Destroys a result handle and frees all associated memory.)
  88. virtual void DestroyResult( SteamInventoryResult_t resultHandle ) = 0;
  89. // INVENTORY ASYNC QUERY
  90. //
  91. // Captures the entire state of the current user's Steam inventory.
  92. // You must call DestroyResult on this handle when you are done with it.
  93. // Returns false and sets *pResultHandle to zero if inventory is unavailable.
  94. // Note: calls to this function are subject to rate limits and may return
  95. // cached results if called too frequently. It is suggested that you call
  96. // this function only when you are about to display the user's full inventory,
  97. // or if you expect that the inventory may have changed.
  98. METHOD_DESC(Captures the entire state of the current users Steam inventory.)
  99. virtual bool GetAllItems( SteamInventoryResult_t *pResultHandle ) = 0;
  100. // Captures the state of a subset of the current user's Steam inventory,
  101. // identified by an array of item instance IDs. The results from this call
  102. // can be serialized and passed to other players to "prove" that the current
  103. // user owns specific items, without exposing the user's entire inventory.
  104. // For example, you could call GetItemsByID with the IDs of the user's
  105. // currently equipped cosmetic items and serialize this to a buffer, and
  106. // then transmit this buffer to other players upon joining a game.
  107. METHOD_DESC(Captures the state of a subset of the current users Steam inventory identified by an array of item instance IDs.)
  108. virtual bool GetItemsByID( SteamInventoryResult_t *pResultHandle, ARRAY_COUNT( unCountInstanceIDs ) const SteamItemInstanceID_t *pInstanceIDs, uint32 unCountInstanceIDs ) = 0;
  109. // RESULT SERIALIZATION AND AUTHENTICATION
  110. //
  111. // Serialized result sets contain a short signature which can't be forged
  112. // or replayed across different game sessions. A result set can be serialized
  113. // on the local client, transmitted to other players via your game networking,
  114. // and deserialized by the remote players. This is a secure way of preventing
  115. // hackers from lying about posessing rare/high-value items.
  116. // Serializes a result set with signature bytes to an output buffer. Pass
  117. // NULL as an output buffer to get the required size via punOutBufferSize.
  118. // The size of a serialized result depends on the number items which are being
  119. // serialized. When securely transmitting items to other players, it is
  120. // recommended to use "GetItemsByID" first to create a minimal result set.
  121. // Results have a built-in timestamp which will be considered "expired" after
  122. // an hour has elapsed. See DeserializeResult for expiration handling.
  123. virtual bool SerializeResult( SteamInventoryResult_t resultHandle, OUT_BUFFER_COUNT(punOutBufferSize) void *pOutBuffer, uint32 *punOutBufferSize ) = 0;
  124. // Deserializes a result set and verifies the signature bytes. Returns false
  125. // if bRequireFullOnlineVerify is set but Steam is running in Offline mode.
  126. // Otherwise returns true and then delivers error codes via GetResultStatus.
  127. //
  128. // The bRESERVED_MUST_BE_FALSE flag is reserved for future use and should not
  129. // be set to true by your game at this time.
  130. //
  131. // DeserializeResult has a potential soft-failure mode where the handle status
  132. // is set to k_EResultExpired. GetResultItems() still succeeds in this mode.
  133. // The "expired" result could indicate that the data may be out of date - not
  134. // just due to timed expiration (one hour), but also because one of the items
  135. // in the result set may have been traded or consumed since the result set was
  136. // generated. You could compare the timestamp from GetResultTimestamp() to
  137. // ISteamUtils::GetServerRealTime() to determine how old the data is. You could
  138. // simply ignore the "expired" result code and continue as normal, or you
  139. // could challenge the player with expired data to send an updated result set.
  140. virtual bool DeserializeResult( SteamInventoryResult_t *pOutResultHandle, BUFFER_COUNT(punOutBufferSize) const void *pBuffer, uint32 unBufferSize, bool bRESERVED_MUST_BE_FALSE = false ) = 0;
  141. // INVENTORY ASYNC MODIFICATION
  142. //
  143. // GenerateItems() creates one or more items and then generates a SteamInventoryCallback_t
  144. // notification with a matching nCallbackContext parameter. This API is insecure, and could
  145. // be abused by hacked clients. It is, however, very useful as a development cheat or as
  146. // a means of prototyping item-related features for your game. The use of GenerateItems can
  147. // be restricted to certain item definitions or fully blocked via the Steamworks website.
  148. // If punArrayQuantity is not NULL, it should be the same length as pArrayItems and should
  149. // describe the quantity of each item to generate.
  150. virtual bool GenerateItems( SteamInventoryResult_t *pResultHandle, ARRAY_COUNT(unArrayLength) const SteamItemDef_t *pArrayItemDefs, ARRAY_COUNT(unArrayLength) const uint32 *punArrayQuantity, uint32 unArrayLength ) = 0;
  151. // GrantPromoItems() checks the list of promotional items for which the user may be eligible
  152. // and grants the items (one time only). On success, the result set will include items which
  153. // were granted, if any. If no items were granted because the user isn't eligible for any
  154. // promotions, this is still considered a success.
  155. METHOD_DESC(GrantPromoItems() checks the list of promotional items for which the user may be eligible and grants the items (one time only).)
  156. virtual bool GrantPromoItems( SteamInventoryResult_t *pResultHandle ) = 0;
  157. // AddPromoItem() / AddPromoItems() are restricted versions of GrantPromoItems(). Instead of
  158. // scanning for all eligible promotional items, the check is restricted to a single item
  159. // definition or set of item definitions. This can be useful if your game has custom UI for
  160. // showing a specific promo item to the user.
  161. virtual bool AddPromoItem( SteamInventoryResult_t *pResultHandle, SteamItemDef_t itemDef ) = 0;
  162. virtual bool AddPromoItems( SteamInventoryResult_t *pResultHandle, ARRAY_COUNT(unArrayLength) const SteamItemDef_t *pArrayItemDefs, uint32 unArrayLength ) = 0;
  163. // ConsumeItem() removes items from the inventory, permanently. They cannot be recovered.
  164. // Not for the faint of heart - if your game implements item removal at all, a high-friction
  165. // UI confirmation process is highly recommended. Similar to GenerateItems, punArrayQuantity
  166. // can be NULL or else an array of the same length as pArrayItems which describe the quantity
  167. // of each item to destroy. ConsumeItem can be restricted to certain item definitions or
  168. // fully blocked via the Steamworks website to minimize support/abuse issues such as the
  169. // clasic "my brother borrowed my laptop and deleted all of my rare items".
  170. METHOD_DESC(ConsumeItem() removes items from the inventory permanently.)
  171. virtual bool ConsumeItem( SteamInventoryResult_t *pResultHandle, SteamItemInstanceID_t itemConsume, uint32 unQuantity ) = 0;
  172. // ExchangeItems() is an atomic combination of GenerateItems and DestroyItems. It can be
  173. // used to implement crafting recipes or transmutations, or items which unpack themselves
  174. // into other items. Like GenerateItems, this is a flexible and dangerous API which is
  175. // meant for rapid prototyping. You can configure restrictions on ExchangeItems via the
  176. // Steamworks website, such as limiting it to a whitelist of input/output combinations
  177. // corresponding to recipes.
  178. // (Note: although GenerateItems may be hard or impossible to use securely in your game,
  179. // ExchangeItems is perfectly reasonable to use once the whitelists are set accordingly.)
  180. virtual bool ExchangeItems( SteamInventoryResult_t *pResultHandle,
  181. ARRAY_COUNT(unArrayGenerateLength) const SteamItemDef_t *pArrayGenerate, ARRAY_COUNT(unArrayGenerateLength) const uint32 *punArrayGenerateQuantity, uint32 unArrayGenerateLength,
  182. ARRAY_COUNT(unArrayDestroyLength) const SteamItemInstanceID_t *pArrayDestroy, ARRAY_COUNT(unArrayDestroyLength) const uint32 *punArrayDestroyQuantity, uint32 unArrayDestroyLength ) = 0;
  183. // TransferItemQuantity() is intended for use with items which are "stackable" (can have
  184. // quantity greater than one). It can be used to split a stack into two, or to transfer
  185. // quantity from one stack into another stack of identical items. To split one stack into
  186. // two, pass k_SteamItemInstanceIDInvalid for itemIdDest and a new item will be generated.
  187. virtual bool TransferItemQuantity( SteamInventoryResult_t *pResultHandle, SteamItemInstanceID_t itemIdSource, uint32 unQuantity, SteamItemInstanceID_t itemIdDest ) = 0;
  188. // TIMED DROPS AND PLAYTIME CREDIT
  189. //
  190. // Applications which use timed-drop mechanics should call SendItemDropHeartbeat() when
  191. // active gameplay begins, and at least once every two minutes afterwards. The backend
  192. // performs its own time calculations, so the precise timing of the heartbeat is not
  193. // critical as long as you send at least one heartbeat every two minutes. Calling the
  194. // function more often than that is not harmful, it will simply have no effect. Note:
  195. // players may be able to spoof this message by hacking their client, so you should not
  196. // attempt to use this as a mechanism to restrict playtime credits. It is simply meant
  197. // to distinguish between being in any kind of gameplay situation vs the main menu or
  198. // a pre-game launcher window. (If you are stingy with handing out playtime credit, it
  199. // will only encourage players to run bots or use mouse/kb event simulators.)
  200. //
  201. // Playtime credit accumulation can be capped on a daily or weekly basis through your
  202. // Steamworks configuration.
  203. //
  204. METHOD_DESC(Applications which use timed-drop mechanics should call SendItemDropHeartbeat() when active gameplay begins and at least once every two minutes afterwards.)
  205. virtual void SendItemDropHeartbeat() = 0;
  206. // Playtime credit must be consumed and turned into item drops by your game. Only item
  207. // definitions which are marked as "playtime item generators" can be spawned. The call
  208. // will return an empty result set if there is not enough playtime credit for a drop.
  209. // Your game should call TriggerItemDrop at an appropriate time for the user to receive
  210. // new items, such as between rounds or while the player is dead. Note that players who
  211. // hack their clients could modify the value of "dropListDefinition", so do not use it
  212. // to directly control rarity. It is primarily useful during testing and development,
  213. // where you may wish to perform experiments with different types of drops.
  214. METHOD_DESC(Playtime credit must be consumed and turned into item drops by your game.)
  215. virtual bool TriggerItemDrop( SteamInventoryResult_t *pResultHandle, SteamItemDef_t dropListDefinition ) = 0;
  216. // IN-GAME TRADING
  217. //
  218. // TradeItems() implements limited in-game trading of items, if you prefer not to use
  219. // the overlay or an in-game web browser to perform Steam Trading through the website.
  220. // You should implement a UI where both players can see and agree to a trade, and then
  221. // each client should call TradeItems simultaneously (+/- 5 seconds) with matching
  222. // (but reversed) parameters. The result is the same as if both players performed a
  223. // Steam Trading transaction through the web. Each player will get an inventory result
  224. // confirming the removal or quantity changes of the items given away, and the new
  225. // item instance id numbers and quantities of the received items.
  226. // (Note: new item instance IDs are generated whenever an item changes ownership.)
  227. virtual bool TradeItems( SteamInventoryResult_t *pResultHandle, CSteamID steamIDTradePartner,
  228. ARRAY_COUNT(nArrayGiveLength) const SteamItemInstanceID_t *pArrayGive, ARRAY_COUNT(nArrayGiveLength) const uint32 *pArrayGiveQuantity, uint32 nArrayGiveLength,
  229. ARRAY_COUNT(nArrayGetLength) const SteamItemInstanceID_t *pArrayGet, ARRAY_COUNT(nArrayGetLength) const uint32 *pArrayGetQuantity, uint32 nArrayGetLength ) = 0;
  230. // ITEM DEFINITIONS
  231. //
  232. // Item definitions are a mapping of "definition IDs" (integers between 1 and 1000000)
  233. // to a set of string properties. Some of these properties are required to display items
  234. // on the Steam community web site. Other properties can be defined by applications.
  235. // Use of these functions is optional; there is no reason to call LoadItemDefinitions
  236. // if your game hardcodes the numeric definition IDs (eg, purple face mask = 20, blue
  237. // weapon mod = 55) and does not allow for adding new item types without a client patch.
  238. //
  239. // LoadItemDefinitions triggers the automatic load and refresh of item definitions.
  240. // Every time new item definitions are available (eg, from the dynamic addition of new
  241. // item types while players are still in-game), a SteamInventoryDefinitionUpdate_t
  242. // callback will be fired.
  243. METHOD_DESC(LoadItemDefinitions triggers the automatic load and refresh of item definitions.)
  244. virtual bool LoadItemDefinitions() = 0;
  245. // GetItemDefinitionIDs returns the set of all defined item definition IDs (which are
  246. // defined via Steamworks configuration, and not necessarily contiguous integers).
  247. // If pItemDefIDs is null, the call will return true and *punItemDefIDsArraySize will
  248. // contain the total size necessary for a subsequent call. Otherwise, the call will
  249. // return false if and only if there is not enough space in the output array.
  250. virtual bool GetItemDefinitionIDs(
  251. OUT_ARRAY_COUNT(punItemDefIDsArraySize,List of item definition IDs) SteamItemDef_t *pItemDefIDs,
  252. DESC(Size of array is passed in and actual size used is returned in this param) uint32 *punItemDefIDsArraySize ) = 0;
  253. // GetItemDefinitionProperty returns a string property from a given item definition.
  254. // Note that some properties (for example, "name") may be localized and will depend
  255. // on the current Steam language settings (see ISteamApps::GetCurrentGameLanguage).
  256. // Property names are always composed of ASCII letters, numbers, and/or underscores.
  257. // Pass a NULL pointer for pchPropertyName to get a comma - separated list of available
  258. // property names.
  259. virtual bool GetItemDefinitionProperty( SteamItemDef_t iDefinition, const char *pchPropertyName,
  260. OUT_STRING_COUNT(punValueBufferSize) char *pchValueBuffer, uint32 *punValueBufferSize ) = 0;
  261. };
  262. #define STEAMINVENTORY_INTERFACE_VERSION "STEAMINVENTORY_INTERFACE_V001"
  263. // SteamInventoryResultReady_t callbacks are fired whenever asynchronous
  264. // results transition from "Pending" to "OK" or an error state. There will
  265. // always be exactly one callback per handle.
  266. struct SteamInventoryResultReady_t
  267. {
  268. enum { k_iCallback = k_iClientInventoryCallbacks + 0 };
  269. SteamInventoryResult_t m_handle;
  270. EResult m_result;
  271. };
  272. // SteamInventoryFullUpdate_t callbacks are triggered when GetAllItems
  273. // successfully returns a result which is newer / fresher than the last
  274. // known result. (It will not trigger if the inventory hasn't changed,
  275. // or if results from two overlapping calls are reversed in flight and
  276. // the earlier result is already known to be stale/out-of-date.)
  277. // The normal ResultReady callback will still be triggered immediately
  278. // afterwards; this is an additional notification for your convenience.
  279. struct SteamInventoryFullUpdate_t
  280. {
  281. enum { k_iCallback = k_iClientInventoryCallbacks + 1 };
  282. SteamInventoryResult_t m_handle;
  283. };
  284. // A SteamInventoryDefinitionUpdate_t callback is triggered whenever
  285. // item definitions have been updated, which could be in response to
  286. // LoadItemDefinitions() or any other async request which required
  287. // a definition update in order to process results from the server.
  288. struct SteamInventoryDefinitionUpdate_t
  289. {
  290. enum { k_iCallback = k_iClientInventoryCallbacks + 2 };
  291. };
  292. #pragma pack( pop )
  293. #endif // ISTEAMCONTROLLER_H