Guest User

Untitled

a guest
Jan 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #include <iostream>
  2. #include "steam_api.h"
  3.  
  4. //The Game Manager class is needed to handle Steamworks callbacks
  5. class CGameManager
  6. {
  7. public:
  8. void CreateItem();
  9.  
  10. bool finished = false;
  11. AppId_t nConsumerAppID = (AppId_t)517510;
  12.  
  13. private:
  14. void onItemCreated(CreateItemResult_t *pCallback, bool bIOFailure);
  15. void onItemSubmitted(SubmitItemUpdateResult_t *pCallback, bool bIOFailure);
  16.  
  17. CCallResult<CGameManager, CreateItemResult_t> m_CreateItemResult;
  18. CCallResult<CGameManager, SubmitItemUpdateResult_t> m_SubmitItemUpdateResult;
  19. };
  20.  
  21. //We create a new Item by providing the game ID and we specify we are creating a normal mod that can be subscribed to
  22. void CGameManager::CreateItem()
  23. {
  24. std::cout << "Creating item..." << std::endl;
  25.  
  26. SteamAPICall_t hSteamAPICall = SteamUGC()->CreateItem( nConsumerAppID, k_EWorkshopFileTypeCommunity);
  27. m_CreateItemResult.Set(hSteamAPICall, this,&CGameManager::onItemCreated);
  28. }
  29.  
  30. //Once the mod was created, we can grab the id from the callback params and then customize it with the UGCUpdateHandle_t before making another API call to SubmitItemUpdate
  31. void CGameManager::onItemCreated(CreateItemResult_t *pCallback, bool bIOFailure)
  32. {
  33. if(pCallback->m_eResult == k_EResultOK && !bIOFailure)
  34. {
  35. std::cout << "Item created!" << std::endl;
  36.  
  37. if(pCallback->m_bUserNeedsToAcceptWorkshopLegalAgreement)
  38. {
  39. SteamFriends()->ActivateGameOverlayToWebPage("steam://url/CommunityFilePage/");
  40. }
  41.  
  42. UGCUpdateHandle_t handle = SteamUGC()->StartItemUpdate(nConsumerAppID, pCallback->m_nPublishedFileId);
  43.  
  44. SteamUGC()->SetItemTitle(handle, "Title test");
  45. SteamUGC()->SetItemDescription(handle, "Description test");
  46. SteamUGC()->SetItemUpdateLanguage(handle, "None");
  47. SteamUGC()->SetItemMetadata(handle, "Test metadata");
  48. SteamUGC()->SetItemVisibility(handle, k_ERemoteStoragePublishedFileVisibilityPublic);
  49.  
  50. SteamParamStringArray_t *pTags = new SteamParamStringArray_t();
  51. pTags->m_ppStrings = new const char*[1];
  52. pTags->m_ppStrings[0] = "stage";
  53. pTags->m_nNumStrings = 1;
  54. SteamUGC()->SetItemTags(handle, pTags);
  55. SteamUGC()->AddItemKeyValueTag(handle, "test_key", "test_value");
  56. std::string mod_directory = "/home/turupawn/ModExample";
  57. SteamUGC()->SetItemContent(handle, mod_directory.c_str());
  58. std::string preview_image = "/home/turupawn/ModExample/preview.png";
  59. SteamUGC()->SetItemPreview(handle, preview_image.c_str());
  60.  
  61. std::string pchChangeNote = "This is a changelog";
  62.  
  63. SteamAPICall_t submit_item_call = SteamUGC()->SubmitItemUpdate(handle, pchChangeNote.c_str() );
  64. m_SubmitItemUpdateResult.Set(submit_item_call, this,&CGameManager::onItemSubmitted);
  65. }else
  66. {
  67. finished = true;
  68. }
  69. }
  70.  
  71. void CGameManager::onItemSubmitted(SubmitItemUpdateResult_t *pCallback, bool bIOFailure)
  72. {
  73. if(pCallback->m_eResult == k_EResultOK && !bIOFailure)
  74. {
  75. std::cout << "Item update submitted created!" << std::endl;
  76. }
  77. finished = true;
  78. }
  79.  
  80. int main()
  81. {
  82. //First, let's check if the Steam client is running
  83. if(SteamAPI_Init())
  84. {
  85. CGameManager gameManager;
  86. //Now let's trigger the item creation process
  87. gameManager.CreateItem();
  88.  
  89. //Dont forget to run the callbacks while we wait
  90. while(!gameManager.finished)
  91. {
  92. SteamAPI_RunCallbacks();
  93. }
  94. }
  95.  
  96. std::cout << "Process finished" << std::endl;
  97.  
  98. return 0;
  99. }
Add Comment
Please, Sign In to add comment