Last active
January 16, 2018 01:31
-
-
Save Turupawn/7fd3e37bd1c451db9322d4a08374d681 to your computer and use it in GitHub Desktop.
Steamworks Update Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "steam_api.h" | |
class CGameManager | |
{ | |
public: | |
void UpdateItem(PublishedFileId_t nPublishedFileID); | |
bool finished = false; | |
AppId_t nConsumerAppID = (AppId_t)517510; | |
private: | |
void onItemUpdated(SubmitItemUpdateResult_t *pCallback, bool bIOFailure); | |
CCallResult<CGameManager, SubmitItemUpdateResult_t> m_SubmitItemUpdateResult; | |
}; | |
//We update the Mod by providing it's ID, we edit the fields by customizing the UGCUpdateHandle_t | |
void CGameManager::UpdateItem(PublishedFileId_t nPublishedFileID) | |
{ | |
UGCUpdateHandle_t handle = SteamUGC()->StartItemUpdate(nConsumerAppID, nPublishedFileID); | |
SteamUGC()->SetItemTitle(handle, "Title test"); | |
SteamUGC()->SetItemDescription(handle, "Description test"); | |
SteamUGC()->SetItemUpdateLanguage(handle, "None"); | |
SteamUGC()->SetItemMetadata(handle, "Test metadata"); | |
SteamUGC()->SetItemVisibility(handle, k_ERemoteStoragePublishedFileVisibilityPublic); | |
SteamParamStringArray_t *pTags = new SteamParamStringArray_t(); | |
pTags->m_ppStrings = new const char*[1]; | |
pTags->m_ppStrings[0] = "stage"; | |
pTags->m_nNumStrings = 1; | |
SteamUGC()->SetItemTags(handle, pTags); | |
SteamUGC()->AddItemKeyValueTag(handle, "test_key", "test_value"); | |
std::string mod_directory = "/home/turupawn/ModExample"; | |
SteamUGC()->SetItemContent(handle, mod_directory.c_str()); | |
std::string preview_image = "/home/turupawn/ModExample/logo.png"; | |
SteamUGC()->SetItemPreview(handle, preview_image.c_str()); | |
std::string pchChangeNote = "This is a changelog"; | |
SteamAPICall_t submit_item_call = SteamUGC()->SubmitItemUpdate(handle, pchChangeNote.c_str() ); | |
m_SubmitItemUpdateResult.Set(submit_item_call, this,&CGameManager::onItemUpdated); | |
} | |
void CGameManager::onItemUpdated(SubmitItemUpdateResult_t *pCallback, bool bIOFailure) | |
{ | |
if(pCallback->m_eResult == k_EResultOK && !bIOFailure) | |
{ | |
std::cout << "Item updated!" << std::endl; | |
} | |
finished = true; | |
} | |
int main() | |
{ | |
if(SteamAPI_Init()) | |
{ | |
CGameManager gameManager; | |
//Let's grab the Mod id from the console for now, you can normally get them by browsing Mods. | |
int mod_id; | |
std::cout << "Enter the mod id: " << std::endl; | |
std::cin >> mod_id; | |
gameManager.UpdateItem(mod_id); | |
while(!gameManager.finished) | |
{ | |
SteamAPI_RunCallbacks(); | |
} | |
} | |
std::cout << "Process finished" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment