From dda27d2c61f27a429b7658be8e2bea0a61794725 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 6 May 2019 15:45:43 +0100 Subject: [PATCH] Delete SteamServerInventory.cs --- Facepunch.Steamworks/SteamInventory.cs | 2 + Facepunch.Steamworks/SteamServerInventory.cs | 185 ------------------- 2 files changed, 2 insertions(+), 185 deletions(-) delete mode 100644 Facepunch.Steamworks/SteamServerInventory.cs diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index 71d2cde..59c7d3a 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -37,10 +37,12 @@ namespace Steamworks { SteamInventoryFullUpdate_t.Install( x => OnInventoryUpdated?.Invoke( x.Handle ) ); SteamInventoryDefinitionUpdate_t.Install( x => LoadDefinitions() ); + SteamInventoryDefinitionUpdate_t.Install( x => OnServerDefinitionsUpdated(), true ); } public static event Action OnInventoryUpdated; public static event Action OnDefinitionsUpdated; + public static event Action OnServerDefinitionsUpdated; static void LoadDefinitions() { diff --git a/Facepunch.Steamworks/SteamServerInventory.cs b/Facepunch.Steamworks/SteamServerInventory.cs deleted file mode 100644 index 2eb8492..0000000 --- a/Facepunch.Steamworks/SteamServerInventory.cs +++ /dev/null @@ -1,185 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using Steamworks.Data; - -namespace Steamworks -{ - public static class SteamServerInventory - { - static ISteamInventory _internal; - internal static ISteamInventory Internal - { - get - { - if ( _internal == null ) - { - _internal = new ISteamInventory(); - _internal.InitClient(); - } - - return _internal; - } - } - internal static void Shutdown() - { - _internal = null; - } - - internal static void InstallEvents() - { - SteamInventoryDefinitionUpdate_t.Install( x => DefinitionsUpdated(), true ); - } - - public static event Action OnDefinitionsUpdated; - - internal static int defUpdateCount = 0; - - internal static void DefinitionsUpdated() - { - Definitions = GetDefinitions(); - - if ( Definitions != null ) - { - _defMap = new Dictionary(); - - foreach ( var d in Definitions ) - { - _defMap[d.Id] = d; - } - } - - defUpdateCount++; - - OnDefinitionsUpdated?.Invoke(); - } - - - /// - /// Call this if you're going to want to access definition information. You should be able to get - /// away with calling this once at the start if your game, assuming your items don't change all the time. - /// This will trigger OnDefinitionsUpdated at which point Definitions should be set. - /// - public static void LoadItemDefinitions() - { - Internal.LoadItemDefinitions(); - } - - /// - /// Will call LoadItemDefinitions and wait until Definitions is not null - /// - public static async Task WaitForDefinitions( float timeoutSeconds = 10 ) - { - LoadItemDefinitions(); - - var sw = Stopwatch.StartNew(); - - while ( Definitions == null ) - { - if ( sw.Elapsed.TotalSeconds > timeoutSeconds ) - return false; - - await Task.Delay( 10 ); - } - - return true; - } - - internal static InventoryDef FindDefinition( InventoryDefId defId ) - { - if ( _defMap.TryGetValue( defId, out var val ) ) - return val; - - return null; - } - - public static string Currency { get; internal set; } - - public static async Task GetDefinitionsWithPricesAsync() - { - var priceRequest = await Internal.RequestPrices(); - if ( !priceRequest.HasValue || priceRequest.Value.Result != Result.OK ) - return null; - - Currency = priceRequest?.Currency; - - var num = Internal.GetNumItemsWithPrices(); - - if ( num <= 0 ) - return null; - - var defs = new InventoryDefId[num]; - var currentPrices = new ulong[num]; - var baseprices = new ulong[num]; - - var gotPrices = Internal.GetItemsWithPrices( defs, currentPrices, baseprices, num ); - if ( !gotPrices ) - return null; - - return defs.Select( x => new InventoryDef( x ) ).ToArray(); - } - - public static InventoryDef[] Definitions { get; internal set; } - public static Dictionary _defMap; - - internal static InventoryDef[] GetDefinitions() - { - uint num = 0; - if ( !Internal.GetItemDefinitionIDs( null, ref num ) ) - return null; - - var defs = new InventoryDefId[num]; - - if ( !Internal.GetItemDefinitionIDs( defs, ref num ) ) - return null; - - return defs.Select( x => new InventoryDef( x ) ).ToArray(); - } - - /// - /// Deserializes a result set and verifies the signature bytes. - /// This call has a potential soft-failure mode where the Result is expired, it will - /// still succeed in this mode.The "expired" - /// result could indicate that the data may be out of date - not just due to timed - /// expiration( one hour ), but also because one of the items in the result set may - /// have been traded or consumed since the result set was generated.You could compare - /// the timestamp from GetResultTimestamp to ISteamUtils::GetServerRealTime to determine - /// how old the data is. You could simply ignore the "expired" result code and - /// continue as normal, or you could request the player with expired data to send - /// an updated result set. - /// You should call CheckResultSteamID on the result handle when it completes to verify - /// that a remote player is not pretending to have a different user's inventory. - /// - static async Task DeserializeAsync( byte[] data, int dataLength = -1 ) - { - if ( data == null ) - throw new ArgumentException( "data should nto be null" ); - - if ( dataLength == -1 ) - dataLength = data.Length; - - var sresult = DeserializeResult( data, dataLength ); - if ( !sresult.HasValue ) return null; - - return await InventoryResult.GetAsync( sresult.Value ); - } - - internal static unsafe SteamInventoryResult_t? DeserializeResult( byte[] data, int dataLength = -1 ) - { - var sresult = default( SteamInventoryResult_t ); - - fixed ( byte* ptr = data ) - { - if ( !Internal.DeserializeResult( ref sresult, (IntPtr)ptr, (uint)dataLength, false ) ) - return null; - } - - return sresult; - } - - } -} \ No newline at end of file