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.

385 lines
20 KiB

  1. //====== Copyright 1996-2013, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to steam ugc
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMUGC_H
  7. #define ISTEAMUGC_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. typedef uint64 UGCQueryHandle_t;
  21. typedef uint64 UGCUpdateHandle_t;
  22. const UGCQueryHandle_t k_UGCQueryHandleInvalid = 0xffffffffffffffffull;
  23. const UGCUpdateHandle_t k_UGCUpdateHandleInvalid = 0xffffffffffffffffull;
  24. // Matching UGC types for queries
  25. enum EUGCMatchingUGCType
  26. {
  27. k_EUGCMatchingUGCType_Items = 0, // both mtx items and ready-to-use items
  28. k_EUGCMatchingUGCType_Items_Mtx = 1,
  29. k_EUGCMatchingUGCType_Items_ReadyToUse = 2,
  30. k_EUGCMatchingUGCType_Collections = 3,
  31. k_EUGCMatchingUGCType_Artwork = 4,
  32. k_EUGCMatchingUGCType_Videos = 5,
  33. k_EUGCMatchingUGCType_Screenshots = 6,
  34. k_EUGCMatchingUGCType_AllGuides = 7, // both web guides and integrated guides
  35. k_EUGCMatchingUGCType_WebGuides = 8,
  36. k_EUGCMatchingUGCType_IntegratedGuides = 9,
  37. k_EUGCMatchingUGCType_UsableInGame = 10, // ready-to-use items and integrated guides
  38. k_EUGCMatchingUGCType_ControllerBindings = 11,
  39. k_EUGCMatchingUGCType_GameManagedItems = 12, // game managed items (not managed by users)
  40. k_EUGCMatchingUGCType_All = ~0, // return everything
  41. };
  42. // Different lists of published UGC for a user.
  43. // If the current logged in user is different than the specified user, then some options may not be allowed.
  44. enum EUserUGCList
  45. {
  46. k_EUserUGCList_Published,
  47. k_EUserUGCList_VotedOn,
  48. k_EUserUGCList_VotedUp,
  49. k_EUserUGCList_VotedDown,
  50. k_EUserUGCList_WillVoteLater,
  51. k_EUserUGCList_Favorited,
  52. k_EUserUGCList_Subscribed,
  53. k_EUserUGCList_UsedOrPlayed,
  54. k_EUserUGCList_Followed,
  55. };
  56. // Sort order for user published UGC lists (defaults to creation order descending)
  57. enum EUserUGCListSortOrder
  58. {
  59. k_EUserUGCListSortOrder_CreationOrderDesc,
  60. k_EUserUGCListSortOrder_CreationOrderAsc,
  61. k_EUserUGCListSortOrder_TitleAsc,
  62. k_EUserUGCListSortOrder_LastUpdatedDesc,
  63. k_EUserUGCListSortOrder_SubscriptionDateDesc,
  64. k_EUserUGCListSortOrder_VoteScoreDesc,
  65. k_EUserUGCListSortOrder_ForModeration,
  66. };
  67. // Combination of sorting and filtering for queries across all UGC
  68. enum EUGCQuery
  69. {
  70. k_EUGCQuery_RankedByVote = 0,
  71. k_EUGCQuery_RankedByPublicationDate = 1,
  72. k_EUGCQuery_AcceptedForGameRankedByAcceptanceDate = 2,
  73. k_EUGCQuery_RankedByTrend = 3,
  74. k_EUGCQuery_FavoritedByFriendsRankedByPublicationDate = 4,
  75. k_EUGCQuery_CreatedByFriendsRankedByPublicationDate = 5,
  76. k_EUGCQuery_RankedByNumTimesReported = 6,
  77. k_EUGCQuery_CreatedByFollowedUsersRankedByPublicationDate = 7,
  78. k_EUGCQuery_NotYetRated = 8,
  79. k_EUGCQuery_RankedByTotalVotesAsc = 9,
  80. k_EUGCQuery_RankedByVotesUp = 10,
  81. k_EUGCQuery_RankedByTextSearch = 11,
  82. k_EUGCQuery_RankedByTotalUniqueSubscriptions = 12,
  83. };
  84. enum EItemUpdateStatus
  85. {
  86. k_EItemUpdateStatusInvalid = 0, // The item update handle was invalid, job might be finished, listen too SubmitItemUpdateResult_t
  87. k_EItemUpdateStatusPreparingConfig = 1, // The item update is processing configuration data
  88. k_EItemUpdateStatusPreparingContent = 2, // The item update is reading and processing content files
  89. k_EItemUpdateStatusUploadingContent = 3, // The item update is uploading content changes to Steam
  90. k_EItemUpdateStatusUploadingPreviewFile = 4, // The item update is uploading new preview file image
  91. k_EItemUpdateStatusCommittingChanges = 5 // The item update is committing all changes
  92. };
  93. enum EItemState
  94. {
  95. k_EItemStateNone = 0, // item not tracked on client
  96. k_EItemStateSubscribed = 1, // current user is subscribed to this item. Not just cached.
  97. k_EItemStateLegacyItem = 2, // item was created with ISteamRemoteStorage
  98. k_EItemStateInstalled = 4, // item is installed and usable (but maybe out of date)
  99. k_EItemStateNeedsUpdate = 8, // items needs an update. Either because it's not installed yet or creator updated content
  100. k_EItemStateDownloading = 16, // item update is currently downloading
  101. k_EItemStateDownloadPending = 32, // DownloadItem() was called for this item, content isn't available until DownloadItemResult_t is fired
  102. };
  103. enum EItemStatistic
  104. {
  105. k_EItemStatistic_NumSubscriptions = 0,
  106. k_EItemStatistic_NumFavorites = 1,
  107. k_EItemStatistic_NumFollowers = 2,
  108. k_EItemStatistic_NumUniqueSubscriptions = 3,
  109. k_EItemStatistic_NumUniqueFavorites = 4,
  110. k_EItemStatistic_NumUniqueFollowers = 5,
  111. k_EItemStatistic_NumUniqueWebsiteViews = 6,
  112. k_EItemStatistic_ReportScore = 7,
  113. };
  114. const uint32 kNumUGCResultsPerPage = 50;
  115. const uint32 k_cchDeveloperMetadataMax = 5000;
  116. // Details for a single published file/UGC
  117. struct SteamUGCDetails_t
  118. {
  119. PublishedFileId_t m_nPublishedFileId;
  120. EResult m_eResult; // The result of the operation.
  121. EWorkshopFileType m_eFileType; // Type of the file
  122. AppId_t m_nCreatorAppID; // ID of the app that created this file.
  123. AppId_t m_nConsumerAppID; // ID of the app that will consume this file.
  124. char m_rgchTitle[k_cchPublishedDocumentTitleMax]; // title of document
  125. char m_rgchDescription[k_cchPublishedDocumentDescriptionMax]; // description of document
  126. uint64 m_ulSteamIDOwner; // Steam ID of the user who created this content.
  127. uint32 m_rtimeCreated; // time when the published file was created
  128. uint32 m_rtimeUpdated; // time when the published file was last updated
  129. uint32 m_rtimeAddedToUserList; // time when the user added the published file to their list (not always applicable)
  130. ERemoteStoragePublishedFileVisibility m_eVisibility; // visibility
  131. bool m_bBanned; // whether the file was banned
  132. bool m_bAcceptedForUse; // developer has specifically flagged this item as accepted in the Workshop
  133. bool m_bTagsTruncated; // whether the list of tags was too long to be returned in the provided buffer
  134. char m_rgchTags[k_cchTagListMax]; // comma separated list of all tags associated with this file
  135. // file/url information
  136. UGCHandle_t m_hFile; // The handle of the primary file
  137. UGCHandle_t m_hPreviewFile; // The handle of the preview file
  138. char m_pchFileName[k_cchFilenameMax]; // The cloud filename of the primary file
  139. int32 m_nFileSize; // Size of the primary file
  140. int32 m_nPreviewFileSize; // Size of the preview file
  141. char m_rgchURL[k_cchPublishedFileURLMax]; // URL (for a video or a website)
  142. // voting information
  143. uint32 m_unVotesUp; // number of votes up
  144. uint32 m_unVotesDown; // number of votes down
  145. float m_flScore; // calculated score
  146. // collection details
  147. uint32 m_unNumChildren;
  148. };
  149. //-----------------------------------------------------------------------------
  150. // Purpose: Steam UGC support API
  151. //-----------------------------------------------------------------------------
  152. class ISteamUGC
  153. {
  154. public:
  155. // Query UGC associated with a user. Creator app id or consumer app id must be valid and be set to the current running app. unPage should start at 1.
  156. virtual UGCQueryHandle_t CreateQueryUserUGCRequest( AccountID_t unAccountID, EUserUGCList eListType, EUGCMatchingUGCType eMatchingUGCType, EUserUGCListSortOrder eSortOrder, AppId_t nCreatorAppID, AppId_t nConsumerAppID, uint32 unPage ) = 0;
  157. // Query for all matching UGC. Creator app id or consumer app id must be valid and be set to the current running app. unPage should start at 1.
  158. virtual UGCQueryHandle_t CreateQueryAllUGCRequest( EUGCQuery eQueryType, EUGCMatchingUGCType eMatchingeMatchingUGCTypeFileType, AppId_t nCreatorAppID, AppId_t nConsumerAppID, uint32 unPage ) = 0;
  159. // Query for the details of the given published file ids (the RequestUGCDetails call is deprecated and replaced with this)
  160. virtual UGCQueryHandle_t CreateQueryUGCDetailsRequest( PublishedFileId_t *pvecPublishedFileID, uint32 unNumPublishedFileIDs ) = 0;
  161. // Send the query to Steam
  162. virtual SteamAPICall_t SendQueryUGCRequest( UGCQueryHandle_t handle ) = 0;
  163. // Retrieve an individual result after receiving the callback for querying UGC
  164. virtual bool GetQueryUGCResult( UGCQueryHandle_t handle, uint32 index, SteamUGCDetails_t *pDetails ) = 0;
  165. virtual bool GetQueryUGCPreviewURL( UGCQueryHandle_t handle, uint32 index, char *pchURL, uint32 cchURLSize ) = 0;
  166. virtual bool GetQueryUGCMetadata( UGCQueryHandle_t handle, uint32 index, char *pchMetadata, uint32 cchMetadatasize ) = 0;
  167. virtual bool GetQueryUGCChildren( UGCQueryHandle_t handle, uint32 index, PublishedFileId_t* pvecPublishedFileID, uint32 cMaxEntries ) = 0;
  168. virtual bool GetQueryUGCStatistic( UGCQueryHandle_t handle, uint32 index, EItemStatistic eStatType, uint32 *pStatValue ) = 0;
  169. virtual uint32 GetQueryUGCNumAdditionalPreviews( UGCQueryHandle_t handle, uint32 index ) = 0;
  170. virtual bool GetQueryUGCAdditionalPreview( UGCQueryHandle_t handle, uint32 index, uint32 previewIndex, char *pchURLOrVideoID, uint32 cchURLSize, bool *pbIsImage ) = 0;
  171. virtual uint32 GetQueryUGCNumKeyValueTags( UGCQueryHandle_t handle, uint32 index ) = 0;
  172. virtual bool GetQueryUGCKeyValueTag( UGCQueryHandle_t handle, uint32 index, uint32 keyValueTagIndex, char *pchKey, uint32 cchKeySize, char *pchValue, uint32 cchValueSize ) = 0;
  173. // Release the request to free up memory, after retrieving results
  174. virtual bool ReleaseQueryUGCRequest( UGCQueryHandle_t handle ) = 0;
  175. // Options to set for querying UGC
  176. virtual bool AddRequiredTag( UGCQueryHandle_t handle, const char *pTagName ) = 0;
  177. virtual bool AddExcludedTag( UGCQueryHandle_t handle, const char *pTagName ) = 0;
  178. virtual bool SetReturnKeyValueTags( UGCQueryHandle_t handle, bool bReturnKeyValueTags ) = 0;
  179. virtual bool SetReturnLongDescription( UGCQueryHandle_t handle, bool bReturnLongDescription ) = 0;
  180. virtual bool SetReturnMetadata( UGCQueryHandle_t handle, bool bReturnMetadata ) = 0;
  181. virtual bool SetReturnChildren( UGCQueryHandle_t handle, bool bReturnChildren ) = 0;
  182. virtual bool SetReturnAdditionalPreviews( UGCQueryHandle_t handle, bool bReturnAdditionalPreviews ) = 0;
  183. virtual bool SetReturnTotalOnly( UGCQueryHandle_t handle, bool bReturnTotalOnly ) = 0;
  184. virtual bool SetLanguage( UGCQueryHandle_t handle, const char *pchLanguage ) = 0;
  185. virtual bool SetAllowCachedResponse( UGCQueryHandle_t handle, uint32 unMaxAgeSeconds ) = 0;
  186. // Options only for querying user UGC
  187. virtual bool SetCloudFileNameFilter( UGCQueryHandle_t handle, const char *pMatchCloudFileName ) = 0;
  188. // Options only for querying all UGC
  189. virtual bool SetMatchAnyTag( UGCQueryHandle_t handle, bool bMatchAnyTag ) = 0;
  190. virtual bool SetSearchText( UGCQueryHandle_t handle, const char *pSearchText ) = 0;
  191. virtual bool SetRankedByTrendDays( UGCQueryHandle_t handle, uint32 unDays ) = 0;
  192. virtual bool AddRequiredKeyValueTag( UGCQueryHandle_t handle, const char *pKey, const char *pValue ) = 0;
  193. // DEPRECATED - Use CreateQueryUGCDetailsRequest call above instead!
  194. virtual SteamAPICall_t RequestUGCDetails( PublishedFileId_t nPublishedFileID, uint32 unMaxAgeSeconds ) = 0;
  195. // Steam Workshop Creator API
  196. virtual SteamAPICall_t CreateItem( AppId_t nConsumerAppId, EWorkshopFileType eFileType ) = 0; // create new item for this app with no content attached yet
  197. virtual UGCUpdateHandle_t StartItemUpdate( AppId_t nConsumerAppId, PublishedFileId_t nPublishedFileID ) = 0; // start an UGC item update. Set changed properties before commiting update with CommitItemUpdate()
  198. virtual bool SetItemTitle( UGCUpdateHandle_t handle, const char *pchTitle ) = 0; // change the title of an UGC item
  199. virtual bool SetItemDescription( UGCUpdateHandle_t handle, const char *pchDescription ) = 0; // change the description of an UGC item
  200. virtual bool SetItemUpdateLanguage( UGCUpdateHandle_t handle, const char *pchLanguage ) = 0; // specify the language of the title or description that will be set
  201. virtual bool SetItemMetadata( UGCUpdateHandle_t handle, const char *pchMetaData ) = 0; // change the metadata of an UGC item (max = k_cchDeveloperMetadataMax)
  202. virtual bool SetItemVisibility( UGCUpdateHandle_t handle, ERemoteStoragePublishedFileVisibility eVisibility ) = 0; // change the visibility of an UGC item
  203. virtual bool SetItemTags( UGCUpdateHandle_t updateHandle, const SteamParamStringArray_t *pTags ) = 0; // change the tags of an UGC item
  204. virtual bool SetItemContent( UGCUpdateHandle_t handle, const char *pszContentFolder ) = 0; // update item content from this local folder
  205. virtual bool SetItemPreview( UGCUpdateHandle_t handle, const char *pszPreviewFile ) = 0; // change preview image file for this item. pszPreviewFile points to local image file, which must be under 1MB in size
  206. virtual bool RemoveItemKeyValueTags( UGCUpdateHandle_t handle, const char *pchKey ) = 0; // remove any existing key-value tags with the specified key
  207. virtual bool AddItemKeyValueTag( UGCUpdateHandle_t handle, const char *pchKey, const char *pchValue ) = 0; // add new key-value tags for the item. Note that there can be multiple values for a tag.
  208. virtual SteamAPICall_t SubmitItemUpdate( UGCUpdateHandle_t handle, const char *pchChangeNote ) = 0; // commit update process started with StartItemUpdate()
  209. virtual EItemUpdateStatus GetItemUpdateProgress( UGCUpdateHandle_t handle, uint64 *punBytesProcessed, uint64* punBytesTotal ) = 0;
  210. // Steam Workshop Consumer API
  211. virtual SteamAPICall_t SetUserItemVote( PublishedFileId_t nPublishedFileID, bool bVoteUp ) = 0;
  212. virtual SteamAPICall_t GetUserItemVote( PublishedFileId_t nPublishedFileID ) = 0;
  213. virtual SteamAPICall_t AddItemToFavorites( AppId_t nAppId, PublishedFileId_t nPublishedFileID ) = 0;
  214. virtual SteamAPICall_t RemoveItemFromFavorites( AppId_t nAppId, PublishedFileId_t nPublishedFileID ) = 0;
  215. virtual SteamAPICall_t SubscribeItem( PublishedFileId_t nPublishedFileID ) = 0; // subscribe to this item, will be installed ASAP
  216. virtual SteamAPICall_t UnsubscribeItem( PublishedFileId_t nPublishedFileID ) = 0; // unsubscribe from this item, will be uninstalled after game quits
  217. virtual uint32 GetNumSubscribedItems() = 0; // number of subscribed items
  218. virtual uint32 GetSubscribedItems( PublishedFileId_t* pvecPublishedFileID, uint32 cMaxEntries ) = 0; // all subscribed item PublishFileIDs
  219. // get EItemState flags about item on this client
  220. virtual uint32 GetItemState( PublishedFileId_t nPublishedFileID ) = 0;
  221. // get info about currently installed content on disc for items that have k_EItemStateInstalled set
  222. // if k_EItemStateLegacyItem is set, pchFolder contains the path to the legacy file itself (not a folder)
  223. virtual bool GetItemInstallInfo( PublishedFileId_t nPublishedFileID, uint64 *punSizeOnDisk, char *pchFolder, uint32 cchFolderSize, uint32 *punTimeStamp ) = 0;
  224. // get info about pending update for items that have k_EItemStateNeedsUpdate set. punBytesTotal will be valid after download started once
  225. virtual bool GetItemDownloadInfo( PublishedFileId_t nPublishedFileID, uint64 *punBytesDownloaded, uint64 *punBytesTotal ) = 0;
  226. // download new or update already installed item. If function returns true, wait for DownloadItemResult_t. If the item is already installed,
  227. // then files on disk should not be used until callback received. If item is not subscribed to, it will be cached for some time.
  228. // If bHighPriority is set, any other item download will be suspended and this item downloaded ASAP.
  229. virtual bool DownloadItem( PublishedFileId_t nPublishedFileID, bool bHighPriority ) = 0;
  230. // game servers can set a specific workshop folder before issuing any UGC commands.
  231. // This is helpful if you want to support multiple game servers running out of the same install folder
  232. virtual bool BInitWorkshopForGameServer( DepotId_t unWorkshopDepotID, const char *pszFolder ) = 0;
  233. // SuspendDownloads( true ) will suspend all workshop downloads until SuspendDownloads( false ) is called or the game ends
  234. virtual void SuspendDownloads( bool bSuspend ) = 0;
  235. };
  236. #define STEAMUGC_INTERFACE_VERSION "STEAMUGC_INTERFACE_VERSION007"
  237. //-----------------------------------------------------------------------------
  238. // Purpose: Callback for querying UGC
  239. //-----------------------------------------------------------------------------
  240. struct SteamUGCQueryCompleted_t
  241. {
  242. enum { k_iCallback = k_iClientUGCCallbacks + 1 };
  243. UGCQueryHandle_t m_handle;
  244. EResult m_eResult;
  245. uint32 m_unNumResultsReturned;
  246. uint32 m_unTotalMatchingResults;
  247. bool m_bCachedData; // indicates whether this data was retrieved from the local on-disk cache
  248. };
  249. //-----------------------------------------------------------------------------
  250. // Purpose: Callback for requesting details on one piece of UGC
  251. //-----------------------------------------------------------------------------
  252. struct SteamUGCRequestUGCDetailsResult_t
  253. {
  254. enum { k_iCallback = k_iClientUGCCallbacks + 2 };
  255. SteamUGCDetails_t m_details;
  256. bool m_bCachedData; // indicates whether this data was retrieved from the local on-disk cache
  257. };
  258. //-----------------------------------------------------------------------------
  259. // Purpose: result for ISteamUGC::CreateItem()
  260. //-----------------------------------------------------------------------------
  261. struct CreateItemResult_t
  262. {
  263. enum { k_iCallback = k_iClientUGCCallbacks + 3 };
  264. EResult m_eResult;
  265. PublishedFileId_t m_nPublishedFileId; // new item got this UGC PublishFileID
  266. bool m_bUserNeedsToAcceptWorkshopLegalAgreement;
  267. };
  268. //-----------------------------------------------------------------------------
  269. // Purpose: result for ISteamUGC::SubmitItemUpdate()
  270. //-----------------------------------------------------------------------------
  271. struct SubmitItemUpdateResult_t
  272. {
  273. enum { k_iCallback = k_iClientUGCCallbacks + 4 };
  274. EResult m_eResult;
  275. bool m_bUserNeedsToAcceptWorkshopLegalAgreement;
  276. };
  277. //-----------------------------------------------------------------------------
  278. // Purpose: a Workshop item has been installed or updated
  279. //-----------------------------------------------------------------------------
  280. struct ItemInstalled_t
  281. {
  282. enum { k_iCallback = k_iClientUGCCallbacks + 5 };
  283. AppId_t m_unAppID;
  284. PublishedFileId_t m_nPublishedFileId;
  285. };
  286. //-----------------------------------------------------------------------------
  287. // Purpose: result of DownloadItem(), existing item files can be accessed again
  288. //-----------------------------------------------------------------------------
  289. struct DownloadItemResult_t
  290. {
  291. enum { k_iCallback = k_iClientUGCCallbacks + 6 };
  292. AppId_t m_unAppID;
  293. PublishedFileId_t m_nPublishedFileId;
  294. EResult m_eResult;
  295. };
  296. //-----------------------------------------------------------------------------
  297. // Purpose: result of AddItemToFavorites() or RemoveItemFromFavorites()
  298. //-----------------------------------------------------------------------------
  299. struct UserFavoriteItemsListChanged_t
  300. {
  301. enum { k_iCallback = k_iClientUGCCallbacks + 7 };
  302. PublishedFileId_t m_nPublishedFileId;
  303. EResult m_eResult;
  304. bool m_bWasAddRequest;
  305. };
  306. //-----------------------------------------------------------------------------
  307. // Purpose: The result of a call to SetUserItemVote()
  308. //-----------------------------------------------------------------------------
  309. struct SetUserItemVoteResult_t
  310. {
  311. enum { k_iCallback = k_iClientUGCCallbacks + 8 };
  312. PublishedFileId_t m_nPublishedFileId;
  313. EResult m_eResult;
  314. bool m_bVoteUp;
  315. };
  316. //-----------------------------------------------------------------------------
  317. // Purpose: The result of a call to GetUserItemVote()
  318. //-----------------------------------------------------------------------------
  319. struct GetUserItemVoteResult_t
  320. {
  321. enum { k_iCallback = k_iClientUGCCallbacks + 9 };
  322. PublishedFileId_t m_nPublishedFileId;
  323. EResult m_eResult;
  324. bool m_bVotedUp;
  325. bool m_bVotedDown;
  326. bool m_bVoteSkipped;
  327. };
  328. #pragma pack( pop )
  329. #endif // ISTEAMUGC_H