mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Cleanup
This commit is contained in:
parent
1b2463cc0b
commit
e6126a0e40
@ -9,7 +9,7 @@ namespace Facepunch.Steamworks.Test
|
||||
public partial class Server
|
||||
{
|
||||
[TestMethod]
|
||||
public void Invetory()
|
||||
public void InventoryDeserialize()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
|
@ -79,20 +79,18 @@ internal void Fill()
|
||||
} ).ToArray();
|
||||
}
|
||||
|
||||
internal byte[] Serialize()
|
||||
internal unsafe byte[] Serialize()
|
||||
{
|
||||
uint size = 0;
|
||||
inventory.inventory.SerializeResult( Handle, IntPtr.Zero, out size );
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal((int) size);
|
||||
|
||||
if ( !inventory.inventory.SerializeResult( Handle, ptr, out size ) )
|
||||
return null;
|
||||
|
||||
var data = new byte[size];
|
||||
|
||||
Marshal.Copy( ptr, data, 0, (int)size );
|
||||
Marshal.FreeHGlobal( ptr );
|
||||
fixed ( byte* ptr = data )
|
||||
{
|
||||
if ( !inventory.inventory.SerializeResult( Handle, (IntPtr) ptr, out size ) )
|
||||
return null;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -206,22 +206,21 @@ private Definition FindDefinition( int def )
|
||||
return Definitions.FirstOrDefault( x => x.Id == def );
|
||||
}
|
||||
|
||||
public Result Deserialize( byte[] data, int dataLength = -1 )
|
||||
public unsafe Result Deserialize( byte[] data, int dataLength = -1 )
|
||||
{
|
||||
if ( dataLength == -1 )
|
||||
dataLength = data.Length;
|
||||
|
||||
int resultHandle = -1;
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal( dataLength);
|
||||
Marshal.Copy( data, 0, ptr, dataLength );
|
||||
var result = inventory.DeserializeResult( out resultHandle, ptr, (uint)dataLength, false );
|
||||
Marshal.FreeHGlobal( ptr );
|
||||
fixed ( byte* ptr = data )
|
||||
{
|
||||
var result = inventory.DeserializeResult( out resultHandle, (IntPtr) ptr, (uint)dataLength, false );
|
||||
if ( !result || resultHandle == -1 )
|
||||
return null;
|
||||
|
||||
if ( !result || resultHandle == -1 )
|
||||
return null;
|
||||
|
||||
return new Result( this, resultHandle );
|
||||
return new Result( this, resultHandle );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user