From 12e26e3f5d2fe5c4decbd048b4cebad239c19c48 Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Thu, 6 Dec 2018 15:20:30 -0500 Subject: [PATCH] Add Inventory.EnableItemProperties to turn off per-item properties (not all games need it and it's a bit slow) There could be a whitelist Func or something added later for more control if anyone wants to do that --- Facepunch.Steamworks/Interfaces/Inventory.Item.cs | 3 +++ Facepunch.Steamworks/Interfaces/Inventory.Result.cs | 6 ++++-- Facepunch.Steamworks/Interfaces/Inventory.cs | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Inventory.Item.cs b/Facepunch.Steamworks/Interfaces/Inventory.Item.cs index cbda47d..8ed1982 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.Item.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.Item.cs @@ -116,6 +116,9 @@ public Result SplitStack( int quantity = 1 ) private void UpdatingProperties() { + if (!Inventory.EnableItemProperties) + throw new InvalidOperationException("Item properties are disabled."); + if (updateHandle != 0) return; updateHandle = Inventory.inventory.StartUpdateProperties(); diff --git a/Facepunch.Steamworks/Interfaces/Inventory.Result.cs b/Facepunch.Steamworks/Interfaces/Inventory.Result.cs index 129f64f..7038ce6 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.Result.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.Result.cs @@ -185,10 +185,12 @@ public void Dispose() internal Item ItemFrom( SteamInventoryResult_t handle, SteamItemDetails_t detail, int index ) { - var props = new Dictionary(); + Dictionary props = null; - if ( inventory.GetResultItemProperty(handle, (uint) index, null, out string propertyNames) ) + if ( EnableItemProperties && inventory.GetResultItemProperty(handle, (uint) index, null, out string propertyNames) ) { + props = new Dictionary(); + foreach ( var propertyName in propertyNames.Split( ',' ) ) { if ( inventory.GetResultItemProperty(handle, (uint)index, propertyName, out string propertyValue ) ) diff --git a/Facepunch.Steamworks/Interfaces/Inventory.cs b/Facepunch.Steamworks/Interfaces/Inventory.cs index f612708..8ecc908 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.cs @@ -33,6 +33,12 @@ public partial class Inventory : IDisposable /// public DateTime SerializedExpireTime; + /// + /// Controls whether per-item properties () are available or not. Default true. + /// This can improve performance of full inventory updates. + /// + public bool EnableItemProperties = true; + internal uint LastTimestamp = 0; internal SteamNative.SteamInventory inventory;