mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Clear pointers on shutdown
This commit is contained in:
parent
0c19a87813
commit
bb2ede3870
@ -25,6 +25,11 @@ internal static ISteamApps Internal
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
new Event<DlcInstalled_t>( x => OnDlcInstalled?.Invoke( x.AppID ) );
|
||||
|
@ -63,7 +63,18 @@ internal static async void RunCallbacksAsync()
|
||||
|
||||
public static void Shutdown()
|
||||
{
|
||||
// TODO.
|
||||
initialized = false;
|
||||
|
||||
SteamApps.Shutdown();
|
||||
SteamUtils.Shutdown();
|
||||
SteamParental.Shutdown();
|
||||
SteamMusic.Shutdown();
|
||||
SteamVideo.Shutdown();
|
||||
SteamUser.Shutdown();
|
||||
SteamFriends.Shutdown();
|
||||
SteamScreenshots.Shutdown();
|
||||
SteamUserStats.Shutdown();
|
||||
SteamInventory.Shutdown();
|
||||
}
|
||||
|
||||
internal static void RegisterCallback( IntPtr intPtr, int callbackId )
|
||||
|
@ -27,6 +27,10 @@ internal static ISteamFriends Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
static Dictionary<string, string> richPresence;
|
||||
|
||||
|
@ -25,6 +25,10 @@ internal static ISteamInventory Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
|
@ -23,6 +23,10 @@ internal static ISteamMusic Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
|
@ -23,6 +23,10 @@ internal static ISteamParentalSettings Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
|
@ -24,6 +24,11 @@ internal static ISteamRemoteStorage Internal
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new file, writes the bytes to the file, and then closes the file.
|
||||
/// If the target file already exists, it is overwritten
|
||||
|
@ -23,6 +23,10 @@ internal static ISteamScreenshots Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
|
@ -31,6 +31,8 @@ internal static ISteamGameServer Internal
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
new Event<ValidateAuthTicketResponse_t>( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true );
|
||||
|
||||
SteamServerInventory.InstallEvents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -77,6 +79,10 @@ public static void Init( AppId appid, SteamServerInit init )
|
||||
public static void Shutdown()
|
||||
{
|
||||
initialized = false;
|
||||
|
||||
_internal = null;
|
||||
|
||||
SteamServerInventory.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
182
Facepunch.Steamworks/SteamServerInventory.cs
Normal file
182
Facepunch.Steamworks/SteamServerInventory.cs
Normal file
@ -0,0 +1,182 @@
|
||||
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();
|
||||
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
new Event<SteamInventoryDefinitionUpdate_t>( 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<int, InventoryDef>();
|
||||
|
||||
foreach ( var d in Definitions )
|
||||
{
|
||||
_defMap[d.Id] = d;
|
||||
}
|
||||
}
|
||||
|
||||
defUpdateCount++;
|
||||
|
||||
OnDefinitionsUpdated?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static void LoadItemDefinitions()
|
||||
{
|
||||
Internal.LoadItemDefinitions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will call LoadItemDefinitions and wait until Definitions is not null
|
||||
/// </summary>
|
||||
public static async Task<bool> 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<InventoryDef[]> 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<int, InventoryDef> _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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
static async Task<InventoryResult?> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -28,6 +28,11 @@ internal static ISteamUGC Internal
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
public static async Task<bool> DeleteFileAsync( PublishedFileId fileId )
|
||||
{
|
||||
var r = await Internal.DeleteItem( fileId );
|
||||
|
@ -31,6 +31,10 @@ internal static ISteamUser Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
static Dictionary<string, string> richPresence;
|
||||
|
||||
|
@ -20,6 +20,10 @@ internal static ISteamUserStats Internal
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
public static bool StatsRecieved { get; internal set; }
|
||||
|
||||
|
@ -24,6 +24,11 @@ internal static ISteamUtils Internal
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
new Event<IPCountry_t>( x => OnIpCountryChanged?.Invoke() );
|
||||
|
@ -24,6 +24,11 @@ internal static ISteamVideo Internal
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
new Event<BroadcastUploadStart_t>( x => OnBroadcastStarted?.Invoke() );
|
||||
|
Loading…
Reference in New Issue
Block a user