From 2108dc3b76894b5fe890ce4c7658a50654b43b65 Mon Sep 17 00:00:00 2001 From: Matthew Oldfield Date: Mon, 10 Jul 2017 15:15:53 +0100 Subject: [PATCH 1/3] 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 @@ namespace Facepunch.Steamworks 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 @@ namespace Facepunch.Steamworks 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 @@ namespace SteamNative } // 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 From 27f640fd5ad3c4c213d50e9eaad48640a8babfd3 Mon Sep 17 00:00:00 2001 From: Matthew Oldfield Date: Mon, 10 Jul 2017 19:15:36 +0100 Subject: [PATCH 2/3] Updated from feedback given --- Facepunch.Steamworks/Interfaces/Workshop.cs | 20 +++++++++---------- .../SteamNative/SteamNative.SteamUGC.cs | 7 ++----- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.cs b/Facepunch.Steamworks/Interfaces/Workshop.cs index a9bde30..cdbe3a8 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.cs @@ -123,25 +123,23 @@ namespace Facepunch.Steamworks 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. + /// This is mostly useful for getting all subscribed items install location + /// on initial load to load all workshop content /// - public Item[] GetSubscribedItems(uint amount) + public unsafe Item[] GetSubscribedItems() { Item[] items; + uint subAmount; + var amount = ugc.GetNumSubscribedItems(); PublishedFileId_t[] vecSubscribedItems = new PublishedFileId_t[amount]; - uint subAmount = ugc.GetSubscribedItems(vecSubscribedItems, amount); - + fixed (PublishedFileId_t* vecSubscribedItems_ptr = vecSubscribedItems) + { + subAmount = ugc.GetSubscribedItems(vecSubscribedItems_ptr, amount); + } if (subAmount < amount) items = new Item[subAmount]; else diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs b/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs index d44321b..7c5650f 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.SteamUGC.cs @@ -284,12 +284,9 @@ namespace SteamNative } // uint - public uint GetSubscribedItems( PublishedFileId_t[] pvecPublishedFileID /*PublishedFileId_t **/, uint cMaxEntries /*uint32*/ ) + public uint GetSubscribedItems( PublishedFileId_t* pvecPublishedFileID /*PublishedFileId_t **/, uint cMaxEntries /*uint32*/ ) { - fixed (PublishedFileId_t* pvecPublishedFileID_ptr = pvecPublishedFileID) - { - return platform.ISteamUGC_GetSubscribedItems((IntPtr)pvecPublishedFileID_ptr, cMaxEntries); - } + return platform.ISteamUGC_GetSubscribedItems( (IntPtr) pvecPublishedFileID, cMaxEntries ); } // SteamAPICall_t From e6c395b2f67472cc4446c25a69971965aec4994f Mon Sep 17 00:00:00 2001 From: Matthew Oldfield Date: Wed, 12 Jul 2017 23:21:33 +0100 Subject: [PATCH 3/3] Removed GetSubscribedItems, could not find a nice way to change to property --- Facepunch.Steamworks/Interfaces/Workshop.cs | 30 --------------------- 1 file changed, 30 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.cs b/Facepunch.Steamworks/Interfaces/Workshop.cs index cdbe3a8..a0122e7 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.cs @@ -123,36 +123,6 @@ namespace Facepunch.Steamworks return new Item( itemid, this ); } - /// - /// 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 - /// on initial load to load all workshop content - /// - public unsafe Item[] GetSubscribedItems() - { - Item[] items; - uint subAmount; - var amount = ugc.GetNumSubscribedItems(); - PublishedFileId_t[] vecSubscribedItems = new PublishedFileId_t[amount]; - fixed (PublishedFileId_t* vecSubscribedItems_ptr = vecSubscribedItems) - { - subAmount = ugc.GetSubscribedItems(vecSubscribedItems_ptr, 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. ///