DeserializeAsync

This commit is contained in:
Garry Newman 2019-04-29 11:59:00 +01:00
parent 2260b222f5
commit 0c19a87813
3 changed files with 45 additions and 3 deletions

View File

@ -164,13 +164,13 @@ internal bool SerializeResult( SteamInventoryResult_t resultHandle, IntPtr pOutB
#region FunctionMeta
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
[return: MarshalAs( UnmanagedType.I1 )]
private delegate bool FDeserializeResult( IntPtr self, [In,Out] SteamInventoryResult_t[] pOutResultHandle, IntPtr pBuffer, uint unBufferSize, [MarshalAs( UnmanagedType.U1 )] bool bRESERVED_MUST_BE_FALSE );
private delegate bool FDeserializeResult( IntPtr self, ref SteamInventoryResult_t pOutResultHandle, IntPtr pBuffer, uint unBufferSize, [MarshalAs( UnmanagedType.U1 )] bool bRESERVED_MUST_BE_FALSE );
private FDeserializeResult _DeserializeResult;
#endregion
internal bool DeserializeResult( [In,Out] SteamInventoryResult_t[] pOutResultHandle, IntPtr pBuffer, uint unBufferSize, [MarshalAs( UnmanagedType.U1 )] bool bRESERVED_MUST_BE_FALSE )
internal bool DeserializeResult( ref SteamInventoryResult_t pOutResultHandle, IntPtr pBuffer, uint unBufferSize, [MarshalAs( UnmanagedType.U1 )] bool bRESERVED_MUST_BE_FALSE )
{
return _DeserializeResult( Self, pOutResultHandle, pBuffer, unBufferSize, bRESERVED_MUST_BE_FALSE );
return _DeserializeResult( Self, ref pOutResultHandle, pBuffer, unBufferSize, bRESERVED_MUST_BE_FALSE );
}
#region FunctionMeta

View File

@ -188,5 +188,46 @@ internal static InventoryDef[] GetDefinitions()
return await InventoryResult.GetAsync( sresult );
}
/// <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;
}
}
}

View File

@ -63,6 +63,7 @@ public virtual bool IsVector
if ( VarName == "pOut" ) return false;
if ( VarName == "pOutBuffer" ) return false;
if ( VarName == "pubRGB" ) return false;
if ( VarName == "pOutResultHandle" ) return false;
if ( VarName == "psteamIDClans" ) return true;
if ( VarName == "pScoreDetails" ) return true;