From 2108dc3b76894b5fe890ce4c7658a50654b43b65 Mon Sep 17 00:00:00 2001 From: Matthew Oldfield Date: Mon, 10 Jul 2017 15:15:53 +0100 Subject: [PATCH] Implemented Workshop Item Subscription Added subscribing to items as well as the UGC interfaces GetNumSubscribedItems and GetSubscribedItems. Edited SteamUGC Method GetSubscribedItems to accept array instead of a ptr to allow c# calling --- .../Interfaces/Workshop.Item.cs | 13 ++++++++ Facepunch.Steamworks/Interfaces/Workshop.cs | 31 +++++++++++++++++++ .../SteamNative/SteamNative.SteamUGC.cs | 7 +++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs index 5045028..21d943d 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs @@ -63,6 +63,19 @@ public void Download( bool highPriority = true ) workshop.OnItemInstalled += OnItemInstalled; } + public void Subscribe() + { + workshop.ugc.SubscribeItem(Id); + SubscriptionCount++; + } + + public void UnSubscribe() + { + workshop.ugc.UnsubscribeItem(Id); + SubscriptionCount--; + } + + private void OnFileDownloaded( ulong fileid, Callbacks.Result result ) { if ( fileid != Id ) return; diff --git a/Facepunch.Steamworks/Interfaces/Workshop.cs b/Facepunch.Steamworks/Interfaces/Workshop.cs index 27e04e1..a9bde30 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.cs @@ -123,6 +123,37 @@ public Item GetItem( ulong itemid ) return new Item( itemid, this ); } + /// + /// The amount of item's the user is subscribed to for this App + /// + public uint GetAmountSubsribed() + { + return ugc.GetNumSubscribedItems(); + } + /// + /// Creates a list of all item's that the user is currently subscribed + /// to for this App. This does not query titles or descriptions but + /// allows you to get the directories, state and ID of any subscribed Item. + /// This is mostly useful for getting all subscribed items install location. + /// + public Item[] GetSubscribedItems(uint amount) + { + Item[] items; + PublishedFileId_t[] vecSubscribedItems = new PublishedFileId_t[amount]; + uint subAmount = ugc.GetSubscribedItems(vecSubscribedItems, amount); + + if (subAmount < amount) + items = new Item[subAmount]; + else + items = new Item[amount]; + + for(int i =0, length = items.Length; i /// How a query should be ordered. diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs b/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs index 7c5650f..d44321b 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs @@ -284,9 +284,12 @@ public bool GetQueryUGCStatistic( UGCQueryHandle_t handle /*UGCQueryHandle_t*/, } // uint - public uint GetSubscribedItems( PublishedFileId_t* pvecPublishedFileID /*PublishedFileId_t **/, uint cMaxEntries /*uint32*/ ) + public uint GetSubscribedItems( PublishedFileId_t[] pvecPublishedFileID /*PublishedFileId_t **/, uint cMaxEntries /*uint32*/ ) { - return platform.ISteamUGC_GetSubscribedItems( (IntPtr) pvecPublishedFileID, cMaxEntries ); + fixed (PublishedFileId_t* pvecPublishedFileID_ptr = pvecPublishedFileID) + { + return platform.ISteamUGC_GetSubscribedItems((IntPtr)pvecPublishedFileID_ptr, cMaxEntries); + } } // SteamAPICall_t