SteamItemDetails_t should read flags properly on windows

This commit is contained in:
Garry Newman 2019-05-16 15:02:00 +01:00
parent 778b1081cb
commit a5bd78a597
4 changed files with 68 additions and 4 deletions

View File

@ -15,6 +15,7 @@ namespace Steamworks
{ {
_GetResultStatus = Marshal.GetDelegateForFunctionPointer<FGetResultStatus>( Marshal.ReadIntPtr( VTable, 0) ); _GetResultStatus = Marshal.GetDelegateForFunctionPointer<FGetResultStatus>( Marshal.ReadIntPtr( VTable, 0) );
_GetResultItems = Marshal.GetDelegateForFunctionPointer<FGetResultItems>( Marshal.ReadIntPtr( VTable, 8) ); _GetResultItems = Marshal.GetDelegateForFunctionPointer<FGetResultItems>( Marshal.ReadIntPtr( VTable, 8) );
_GetResultItems_Windows = Marshal.GetDelegateForFunctionPointer<FGetResultItems_Windows>( Marshal.ReadIntPtr( VTable, 8) );
_GetResultItemProperty = Marshal.GetDelegateForFunctionPointer<FGetResultItemProperty>( Marshal.ReadIntPtr( VTable, 16) ); _GetResultItemProperty = Marshal.GetDelegateForFunctionPointer<FGetResultItemProperty>( Marshal.ReadIntPtr( VTable, 16) );
_GetResultTimestamp = Marshal.GetDelegateForFunctionPointer<FGetResultTimestamp>( Marshal.ReadIntPtr( VTable, 24) ); _GetResultTimestamp = Marshal.GetDelegateForFunctionPointer<FGetResultTimestamp>( Marshal.ReadIntPtr( VTable, 24) );
_CheckResultSteamID = Marshal.GetDelegateForFunctionPointer<FCheckResultSteamID>( Marshal.ReadIntPtr( VTable, 32) ); _CheckResultSteamID = Marshal.GetDelegateForFunctionPointer<FCheckResultSteamID>( Marshal.ReadIntPtr( VTable, 32) );
@ -57,6 +58,7 @@ namespace Steamworks
_GetResultStatus = null; _GetResultStatus = null;
_GetResultItems = null; _GetResultItems = null;
_GetResultItems_Windows = null;
_GetResultItemProperty = null; _GetResultItemProperty = null;
_GetResultTimestamp = null; _GetResultTimestamp = null;
_CheckResultSteamID = null; _CheckResultSteamID = null;
@ -110,10 +112,35 @@ namespace Steamworks
[return: MarshalAs( UnmanagedType.I1 )] [return: MarshalAs( UnmanagedType.I1 )]
private delegate bool FGetResultItems( IntPtr self, SteamInventoryResult_t resultHandle, [In,Out] SteamItemDetails_t[] pOutItemsArray, ref uint punOutItemsArraySize ); private delegate bool FGetResultItems( IntPtr self, SteamInventoryResult_t resultHandle, [In,Out] SteamItemDetails_t[] pOutItemsArray, ref uint punOutItemsArraySize );
private FGetResultItems _GetResultItems; private FGetResultItems _GetResultItems;
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
[return: MarshalAs( UnmanagedType.I1 )]
private delegate bool FGetResultItems_Windows( IntPtr self, SteamInventoryResult_t resultHandle, [In,Out] SteamItemDetails_t.Pack8[] pOutItemsArray, ref uint punOutItemsArraySize );
private FGetResultItems_Windows _GetResultItems_Windows;
#endregion #endregion
internal bool GetResultItems( SteamInventoryResult_t resultHandle, [In,Out] SteamItemDetails_t[] pOutItemsArray, ref uint punOutItemsArraySize ) internal bool GetResultItems( SteamInventoryResult_t resultHandle, [In,Out] SteamItemDetails_t[] pOutItemsArray, ref uint punOutItemsArraySize )
{ {
if ( Config.Os == OsType.Windows )
{
SteamItemDetails_t.Pack8[] pOutItemsArray_windows = pOutItemsArray == null ? null : new SteamItemDetails_t.Pack8[ pOutItemsArray.Length ];
if ( pOutItemsArray_windows != null )
{
for ( int i=0; i<pOutItemsArray.Length; i++ )
{
pOutItemsArray_windows[i] = pOutItemsArray[i];
}
}
var retVal = _GetResultItems_Windows( Self, resultHandle, pOutItemsArray_windows, ref punOutItemsArraySize );
if ( pOutItemsArray_windows != null )
{
for ( int i=0; i<pOutItemsArray.Length; i++ )
{
pOutItemsArray[i] = pOutItemsArray_windows[i];
}
}
return retVal;
}
return _GetResultItems( Self, resultHandle, pOutItemsArray, ref punOutItemsArraySize ); return _GetResultItems( Self, resultHandle, pOutItemsArray, ref punOutItemsArraySize );
} }

View File

@ -10707,7 +10707,21 @@ namespace Steamworks.Data
internal ushort Flags; // m_unFlags uint16 internal ushort Flags; // m_unFlags uint16
#region Marshalling #region Marshalling
internal static SteamItemDetails_t Fill( IntPtr p ) => ((SteamItemDetails_t)(SteamItemDetails_t) Marshal.PtrToStructure( p, typeof(SteamItemDetails_t) ) ); internal static SteamItemDetails_t Fill( IntPtr p ) => Config.PackSmall ? ((SteamItemDetails_t)(SteamItemDetails_t) Marshal.PtrToStructure( p, typeof(SteamItemDetails_t) )) : ((SteamItemDetails_t)(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));
#endregion
#region Packed Versions
[StructLayout( LayoutKind.Sequential, Pack = 8 )]
public struct Pack8
{
internal InventoryItemId ItemId; // m_itemId SteamItemInstanceID_t
internal InventoryDefId Definition; // m_iDefinition SteamItemDef_t
internal ushort Quantity; // m_unQuantity uint16
internal ushort Flags; // m_unFlags uint16
public static implicit operator SteamItemDetails_t ( SteamItemDetails_t.Pack8 d ) => new SteamItemDetails_t{ ItemId = d.ItemId,Definition = d.Definition,Quantity = d.Quantity,Flags = d.Flags, };
public static implicit operator SteamItemDetails_t.Pack8 ( SteamItemDetails_t d ) => new SteamItemDetails_t.Pack8{ ItemId = d.ItemId,Definition = d.Definition,Quantity = d.Quantity,Flags = d.Flags, };
}
#endregion #endregion
} }

View File

@ -255,7 +255,16 @@ namespace Generator
if ( arg.IsVector ) if ( arg.IsVector )
{ {
WriteLine( $"{arg.TypeName}.Pack8[] {arg.VarName}_windows = {arg.VarName};" ); WriteLine( $"{arg.TypeName}.Pack8[] {arg.VarName}_windows = {arg.VarName} == null ? null : new {arg.TypeName}.Pack8[ {arg.VarName}.Length ];" );
StartBlock( $"if ( {arg.VarName}_windows != null )" );
{
StartBlock( $"for ( int i=0; i<{arg.VarName}.Length; i++ )" );
{
WriteLine( $"{arg.VarName}_windows[i] = {arg.VarName}[i];" );
}
EndBlock();
}
EndBlock();
} }
else else
{ {
@ -274,7 +283,22 @@ namespace Generator
{ {
if ( !arg.WindowsSpecific ) continue; if ( !arg.WindowsSpecific ) continue;
WriteLine( $"{arg.VarName} = {arg.VarName}_windows;" ); if ( arg.IsVector )
{
StartBlock( $"if ( {arg.VarName}_windows != null )" );
{
StartBlock( $"for ( int i=0; i<{arg.VarName}.Length; i++ )" );
{
WriteLine( $"{arg.VarName}[i] = {arg.VarName}_windows[i];" );
}
EndBlock();
}
EndBlock();
}
else
{
WriteLine( $"{arg.VarName} = {arg.VarName}_windows;" );
}
} }
if ( !returnType.IsVoid ) if ( !returnType.IsVoid )

View File

@ -60,7 +60,6 @@ namespace Generator
{ {
get get
{ {
if ( Name.Contains( "SteamItemDetails_t" ) ) return true;
if ( Name.Contains( "MatchMakingKeyValuePair_t" ) ) return true; if ( Name.Contains( "MatchMakingKeyValuePair_t" ) ) return true;
if ( Fields.Any( x => x.Type.Contains( "CSteamID" ) ) ) if ( Fields.Any( x => x.Type.Contains( "CSteamID" ) ) )