ISteamCallback was a nice idea but IL2CPP support makes it unfeasible

This commit is contained in:
Garry Newman 2019-04-30 16:43:27 +01:00
parent 86e4576baf
commit 93d20de83b
21 changed files with 6293 additions and 1873 deletions

View File

@ -1,11 +0,0 @@
using System;
namespace Steamworks
{
public interface ISteamCallback
{
int GetCallbackId();
int GetStructSize();
ISteamCallback Fill( IntPtr ptr );
}
}

View File

@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Steamworks
{
/// <summary>
/// Results are Steam Callbacks that are direct responses to function calls
/// </summary>
public struct Result<T> where T : struct, ISteamCallback
{
public ulong CallHandle;
public Result( ulong callbackHandle )
{
CallHandle = callbackHandle;
}
public bool IsComplete( out bool failed )
{
return SteamUtils.IsCallComplete( CallHandle, out failed );
}
public async Task<T?> GetResult()
{
bool failed = false;
while ( !IsComplete( out failed ) )
{
await Task.Delay( 1 );
}
if ( failed )
return null;
return SteamUtils.GetResult<T>( CallHandle );
}
}
}

View File

@ -352,7 +352,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<FileDetailsResult_t?> GetFileDetails( string pszFileName ) internal async Task<FileDetailsResult_t?> GetFileDetails( string pszFileName )
{ {
return await (new Result<FileDetailsResult_t>( _GetFileDetails( Self, pszFileName ) )).GetResult(); return await FileDetailsResult_t.GetResultAsync( _GetFileDetails( Self, pszFileName ) );
} }
#region FunctionMeta #region FunctionMeta

View File

@ -118,7 +118,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SetPersonaNameResponse_t?> SetPersonaName( string pchPersonaName ) internal async Task<SetPersonaNameResponse_t?> SetPersonaName( string pchPersonaName )
{ {
return await (new Result<SetPersonaNameResponse_t>( _SetPersonaName( Self, pchPersonaName ) )).GetResult(); return await SetPersonaNameResponse_t.GetResultAsync( _SetPersonaName( Self, pchPersonaName ) );
} }
#region FunctionMeta #region FunctionMeta
@ -381,7 +381,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<DownloadClanActivityCountsResult_t?> DownloadClanActivityCounts( [In,Out] SteamId[] psteamIDClans, int cClansToRequest ) internal async Task<DownloadClanActivityCountsResult_t?> DownloadClanActivityCounts( [In,Out] SteamId[] psteamIDClans, int cClansToRequest )
{ {
return await (new Result<DownloadClanActivityCountsResult_t>( _DownloadClanActivityCounts( Self, psteamIDClans, cClansToRequest ) )).GetResult(); return await DownloadClanActivityCountsResult_t.GetResultAsync( _DownloadClanActivityCounts( Self, psteamIDClans, cClansToRequest ) );
} }
#region FunctionMeta #region FunctionMeta
@ -557,7 +557,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<ClanOfficerListResponse_t?> RequestClanOfficerList( SteamId steamIDClan ) internal async Task<ClanOfficerListResponse_t?> RequestClanOfficerList( SteamId steamIDClan )
{ {
return await (new Result<ClanOfficerListResponse_t>( _RequestClanOfficerList( Self, steamIDClan ) )).GetResult(); return await ClanOfficerListResponse_t.GetResultAsync( _RequestClanOfficerList( Self, steamIDClan ) );
} }
#region FunctionMeta #region FunctionMeta
@ -762,7 +762,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<JoinClanChatRoomCompletionResult_t?> JoinClanChatRoom( SteamId steamIDClan ) internal async Task<JoinClanChatRoomCompletionResult_t?> JoinClanChatRoom( SteamId steamIDClan )
{ {
return await (new Result<JoinClanChatRoomCompletionResult_t>( _JoinClanChatRoom( Self, steamIDClan ) )).GetResult(); return await JoinClanChatRoomCompletionResult_t.GetResultAsync( _JoinClanChatRoom( Self, steamIDClan ) );
} }
#region FunctionMeta #region FunctionMeta
@ -922,7 +922,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<FriendsGetFollowerCount_t?> GetFollowerCount( SteamId steamID ) internal async Task<FriendsGetFollowerCount_t?> GetFollowerCount( SteamId steamID )
{ {
return await (new Result<FriendsGetFollowerCount_t>( _GetFollowerCount( Self, steamID ) )).GetResult(); return await FriendsGetFollowerCount_t.GetResultAsync( _GetFollowerCount( Self, steamID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -933,7 +933,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<FriendsIsFollowing_t?> IsFollowing( SteamId steamID ) internal async Task<FriendsIsFollowing_t?> IsFollowing( SteamId steamID )
{ {
return await (new Result<FriendsIsFollowing_t>( _IsFollowing( Self, steamID ) )).GetResult(); return await FriendsIsFollowing_t.GetResultAsync( _IsFollowing( Self, steamID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -944,7 +944,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<FriendsEnumerateFollowingList_t?> EnumerateFollowingList( uint unStartIndex ) internal async Task<FriendsEnumerateFollowingList_t?> EnumerateFollowingList( uint unStartIndex )
{ {
return await (new Result<FriendsEnumerateFollowingList_t>( _EnumerateFollowingList( Self, unStartIndex ) )).GetResult(); return await FriendsEnumerateFollowingList_t.GetResultAsync( _EnumerateFollowingList( Self, unStartIndex ) );
} }
#region FunctionMeta #region FunctionMeta

View File

@ -483,7 +483,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<GSReputation_t?> GetServerReputation() internal async Task<GSReputation_t?> GetServerReputation()
{ {
return await (new Result<GSReputation_t>( _GetServerReputation( Self ) )).GetResult(); return await GSReputation_t.GetResultAsync( _GetServerReputation( Self ) );
} }
#region FunctionMeta #region FunctionMeta
@ -561,7 +561,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<AssociateWithClanResult_t?> AssociateWithClan( SteamId steamIDClan ) internal async Task<AssociateWithClanResult_t?> AssociateWithClan( SteamId steamIDClan )
{ {
return await (new Result<AssociateWithClanResult_t>( _AssociateWithClan( Self, steamIDClan ) )).GetResult(); return await AssociateWithClanResult_t.GetResultAsync( _AssociateWithClan( Self, steamIDClan ) );
} }
#region FunctionMeta #region FunctionMeta
@ -572,7 +572,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<ComputeNewPlayerCompatibilityResult_t?> ComputeNewPlayerCompatibility( SteamId steamIDNewPlayer ) internal async Task<ComputeNewPlayerCompatibilityResult_t?> ComputeNewPlayerCompatibility( SteamId steamIDNewPlayer )
{ {
return await (new Result<ComputeNewPlayerCompatibilityResult_t>( _ComputeNewPlayerCompatibility( Self, steamIDNewPlayer ) )).GetResult(); return await ComputeNewPlayerCompatibilityResult_t.GetResultAsync( _ComputeNewPlayerCompatibility( Self, steamIDNewPlayer ) );
} }
} }

View File

@ -336,7 +336,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SteamInventoryEligiblePromoItemDefIDs_t?> RequestEligiblePromoItemDefinitionsIDs( SteamId steamID ) internal async Task<SteamInventoryEligiblePromoItemDefIDs_t?> RequestEligiblePromoItemDefinitionsIDs( SteamId steamID )
{ {
return await (new Result<SteamInventoryEligiblePromoItemDefIDs_t>( _RequestEligiblePromoItemDefinitionsIDs( Self, steamID ) )).GetResult(); return await SteamInventoryEligiblePromoItemDefIDs_t.GetResultAsync( _RequestEligiblePromoItemDefinitionsIDs( Self, steamID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -359,7 +359,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SteamInventoryStartPurchaseResult_t?> StartPurchase( [In,Out] InventoryDefId[] pArrayItemDefs, [In,Out] uint[] punArrayQuantity, uint unArrayLength ) internal async Task<SteamInventoryStartPurchaseResult_t?> StartPurchase( [In,Out] InventoryDefId[] pArrayItemDefs, [In,Out] uint[] punArrayQuantity, uint unArrayLength )
{ {
return await (new Result<SteamInventoryStartPurchaseResult_t>( _StartPurchase( Self, pArrayItemDefs, punArrayQuantity, unArrayLength ) )).GetResult(); return await SteamInventoryStartPurchaseResult_t.GetResultAsync( _StartPurchase( Self, pArrayItemDefs, punArrayQuantity, unArrayLength ) );
} }
#region FunctionMeta #region FunctionMeta
@ -370,7 +370,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SteamInventoryRequestPricesResult_t?> RequestPrices() internal async Task<SteamInventoryRequestPricesResult_t?> RequestPrices()
{ {
return await (new Result<SteamInventoryRequestPricesResult_t>( _RequestPrices( Self ) )).GetResult(); return await SteamInventoryRequestPricesResult_t.GetResultAsync( _RequestPrices( Self ) );
} }
#region FunctionMeta #region FunctionMeta

View File

@ -121,7 +121,7 @@ namespace Steamworks
#endregion #endregion
internal gameserveritem_t GetServerDetails( HServerListRequest hRequest, int iServer ) internal gameserveritem_t GetServerDetails( HServerListRequest hRequest, int iServer )
{ {
return new gameserveritem_t().Fill( _GetServerDetails( Self, hRequest, iServer ) ); return gameserveritem_t.Fill( _GetServerDetails( Self, hRequest, iServer ) );
} }
#region FunctionMeta #region FunctionMeta

View File

@ -104,7 +104,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageFileWriteAsyncComplete_t?> FileWriteAsync( string pchFile, IntPtr pvData, uint cubData ) internal async Task<RemoteStorageFileWriteAsyncComplete_t?> FileWriteAsync( string pchFile, IntPtr pvData, uint cubData )
{ {
return await (new Result<RemoteStorageFileWriteAsyncComplete_t>( _FileWriteAsync( Self, pchFile, pvData, cubData ) )).GetResult(); return await RemoteStorageFileWriteAsyncComplete_t.GetResultAsync( _FileWriteAsync( Self, pchFile, pvData, cubData ) );
} }
#region FunctionMeta #region FunctionMeta
@ -115,7 +115,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageFileReadAsyncComplete_t?> FileReadAsync( string pchFile, uint nOffset, uint cubToRead ) internal async Task<RemoteStorageFileReadAsyncComplete_t?> FileReadAsync( string pchFile, uint nOffset, uint cubToRead )
{ {
return await (new Result<RemoteStorageFileReadAsyncComplete_t>( _FileReadAsync( Self, pchFile, nOffset, cubToRead ) )).GetResult(); return await RemoteStorageFileReadAsyncComplete_t.GetResultAsync( _FileReadAsync( Self, pchFile, nOffset, cubToRead ) );
} }
#region FunctionMeta #region FunctionMeta
@ -162,7 +162,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageFileShareResult_t?> FileShare( string pchFile ) internal async Task<RemoteStorageFileShareResult_t?> FileShare( string pchFile )
{ {
return await (new Result<RemoteStorageFileShareResult_t>( _FileShare( Self, pchFile ) )).GetResult(); return await RemoteStorageFileShareResult_t.GetResultAsync( _FileShare( Self, pchFile ) );
} }
#region FunctionMeta #region FunctionMeta
@ -358,7 +358,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageDownloadUGCResult_t?> UGCDownload( UGCHandle_t hContent, uint unPriority ) internal async Task<RemoteStorageDownloadUGCResult_t?> UGCDownload( UGCHandle_t hContent, uint unPriority )
{ {
return await (new Result<RemoteStorageDownloadUGCResult_t>( _UGCDownload( Self, hContent, unPriority ) )).GetResult(); return await RemoteStorageDownloadUGCResult_t.GetResultAsync( _UGCDownload( Self, hContent, unPriority ) );
} }
#region FunctionMeta #region FunctionMeta
@ -415,7 +415,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageDownloadUGCResult_t?> UGCDownloadToLocation( UGCHandle_t hContent, string pchLocation, uint unPriority ) internal async Task<RemoteStorageDownloadUGCResult_t?> UGCDownloadToLocation( UGCHandle_t hContent, string pchLocation, uint unPriority )
{ {
return await (new Result<RemoteStorageDownloadUGCResult_t>( _UGCDownloadToLocation( Self, hContent, pchLocation, unPriority ) )).GetResult(); return await RemoteStorageDownloadUGCResult_t.GetResultAsync( _UGCDownloadToLocation( Self, hContent, pchLocation, unPriority ) );
} }
} }

View File

@ -147,7 +147,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SteamUGCQueryCompleted_t?> SendQueryUGCRequest( UGCQueryHandle_t handle ) internal async Task<SteamUGCQueryCompleted_t?> SendQueryUGCRequest( UGCQueryHandle_t handle )
{ {
return await (new Result<SteamUGCQueryCompleted_t>( _SendQueryUGCRequest( Self, handle ) )).GetResult(); return await SteamUGCQueryCompleted_t.GetResultAsync( _SendQueryUGCRequest( Self, handle ) );
} }
#region FunctionMeta #region FunctionMeta
@ -480,7 +480,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SteamUGCRequestUGCDetailsResult_t?> RequestUGCDetails( PublishedFileId nPublishedFileID, uint unMaxAgeSeconds ) internal async Task<SteamUGCRequestUGCDetailsResult_t?> RequestUGCDetails( PublishedFileId nPublishedFileID, uint unMaxAgeSeconds )
{ {
return await (new Result<SteamUGCRequestUGCDetailsResult_t>( _RequestUGCDetails( Self, nPublishedFileID, unMaxAgeSeconds ) )).GetResult(); return await SteamUGCRequestUGCDetailsResult_t.GetResultAsync( _RequestUGCDetails( Self, nPublishedFileID, unMaxAgeSeconds ) );
} }
#region FunctionMeta #region FunctionMeta
@ -491,7 +491,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<CreateItemResult_t?> CreateItem( AppId nConsumerAppId, WorkshopFileType eFileType ) internal async Task<CreateItemResult_t?> CreateItem( AppId nConsumerAppId, WorkshopFileType eFileType )
{ {
return await (new Result<CreateItemResult_t>( _CreateItem( Self, nConsumerAppId, eFileType ) )).GetResult(); return await CreateItemResult_t.GetResultAsync( _CreateItem( Self, nConsumerAppId, eFileType ) );
} }
#region FunctionMeta #region FunctionMeta
@ -705,7 +705,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SubmitItemUpdateResult_t?> SubmitItemUpdate( UGCUpdateHandle_t handle, string pchChangeNote ) internal async Task<SubmitItemUpdateResult_t?> SubmitItemUpdate( UGCUpdateHandle_t handle, string pchChangeNote )
{ {
return await (new Result<SubmitItemUpdateResult_t>( _SubmitItemUpdate( Self, handle, pchChangeNote ) )).GetResult(); return await SubmitItemUpdateResult_t.GetResultAsync( _SubmitItemUpdate( Self, handle, pchChangeNote ) );
} }
#region FunctionMeta #region FunctionMeta
@ -727,7 +727,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<SetUserItemVoteResult_t?> SetUserItemVote( PublishedFileId nPublishedFileID, [MarshalAs( UnmanagedType.U1 )] bool bVoteUp ) internal async Task<SetUserItemVoteResult_t?> SetUserItemVote( PublishedFileId nPublishedFileID, [MarshalAs( UnmanagedType.U1 )] bool bVoteUp )
{ {
return await (new Result<SetUserItemVoteResult_t>( _SetUserItemVote( Self, nPublishedFileID, bVoteUp ) )).GetResult(); return await SetUserItemVoteResult_t.GetResultAsync( _SetUserItemVote( Self, nPublishedFileID, bVoteUp ) );
} }
#region FunctionMeta #region FunctionMeta
@ -738,7 +738,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<GetUserItemVoteResult_t?> GetUserItemVote( PublishedFileId nPublishedFileID ) internal async Task<GetUserItemVoteResult_t?> GetUserItemVote( PublishedFileId nPublishedFileID )
{ {
return await (new Result<GetUserItemVoteResult_t>( _GetUserItemVote( Self, nPublishedFileID ) )).GetResult(); return await GetUserItemVoteResult_t.GetResultAsync( _GetUserItemVote( Self, nPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -749,7 +749,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<UserFavoriteItemsListChanged_t?> AddItemToFavorites( AppId nAppId, PublishedFileId nPublishedFileID ) internal async Task<UserFavoriteItemsListChanged_t?> AddItemToFavorites( AppId nAppId, PublishedFileId nPublishedFileID )
{ {
return await (new Result<UserFavoriteItemsListChanged_t>( _AddItemToFavorites( Self, nAppId, nPublishedFileID ) )).GetResult(); return await UserFavoriteItemsListChanged_t.GetResultAsync( _AddItemToFavorites( Self, nAppId, nPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -760,7 +760,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<UserFavoriteItemsListChanged_t?> RemoveItemFromFavorites( AppId nAppId, PublishedFileId nPublishedFileID ) internal async Task<UserFavoriteItemsListChanged_t?> RemoveItemFromFavorites( AppId nAppId, PublishedFileId nPublishedFileID )
{ {
return await (new Result<UserFavoriteItemsListChanged_t>( _RemoveItemFromFavorites( Self, nAppId, nPublishedFileID ) )).GetResult(); return await UserFavoriteItemsListChanged_t.GetResultAsync( _RemoveItemFromFavorites( Self, nAppId, nPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -771,7 +771,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageSubscribePublishedFileResult_t?> SubscribeItem( PublishedFileId nPublishedFileID ) internal async Task<RemoteStorageSubscribePublishedFileResult_t?> SubscribeItem( PublishedFileId nPublishedFileID )
{ {
return await (new Result<RemoteStorageSubscribePublishedFileResult_t>( _SubscribeItem( Self, nPublishedFileID ) )).GetResult(); return await RemoteStorageSubscribePublishedFileResult_t.GetResultAsync( _SubscribeItem( Self, nPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -782,7 +782,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoteStorageUnsubscribePublishedFileResult_t?> UnsubscribeItem( PublishedFileId nPublishedFileID ) internal async Task<RemoteStorageUnsubscribePublishedFileResult_t?> UnsubscribeItem( PublishedFileId nPublishedFileID )
{ {
return await (new Result<RemoteStorageUnsubscribePublishedFileResult_t>( _UnsubscribeItem( Self, nPublishedFileID ) )).GetResult(); return await RemoteStorageUnsubscribePublishedFileResult_t.GetResultAsync( _UnsubscribeItem( Self, nPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -885,7 +885,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<StartPlaytimeTrackingResult_t?> StartPlaytimeTracking( [In,Out] PublishedFileId[] pvecPublishedFileID, uint unNumPublishedFileIDs ) internal async Task<StartPlaytimeTrackingResult_t?> StartPlaytimeTracking( [In,Out] PublishedFileId[] pvecPublishedFileID, uint unNumPublishedFileIDs )
{ {
return await (new Result<StartPlaytimeTrackingResult_t>( _StartPlaytimeTracking( Self, pvecPublishedFileID, unNumPublishedFileIDs ) )).GetResult(); return await StartPlaytimeTrackingResult_t.GetResultAsync( _StartPlaytimeTracking( Self, pvecPublishedFileID, unNumPublishedFileIDs ) );
} }
#region FunctionMeta #region FunctionMeta
@ -896,7 +896,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<StopPlaytimeTrackingResult_t?> StopPlaytimeTracking( [In,Out] PublishedFileId[] pvecPublishedFileID, uint unNumPublishedFileIDs ) internal async Task<StopPlaytimeTrackingResult_t?> StopPlaytimeTracking( [In,Out] PublishedFileId[] pvecPublishedFileID, uint unNumPublishedFileIDs )
{ {
return await (new Result<StopPlaytimeTrackingResult_t>( _StopPlaytimeTracking( Self, pvecPublishedFileID, unNumPublishedFileIDs ) )).GetResult(); return await StopPlaytimeTrackingResult_t.GetResultAsync( _StopPlaytimeTracking( Self, pvecPublishedFileID, unNumPublishedFileIDs ) );
} }
#region FunctionMeta #region FunctionMeta
@ -907,7 +907,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<StopPlaytimeTrackingResult_t?> StopPlaytimeTrackingForAllItems() internal async Task<StopPlaytimeTrackingResult_t?> StopPlaytimeTrackingForAllItems()
{ {
return await (new Result<StopPlaytimeTrackingResult_t>( _StopPlaytimeTrackingForAllItems( Self ) )).GetResult(); return await StopPlaytimeTrackingResult_t.GetResultAsync( _StopPlaytimeTrackingForAllItems( Self ) );
} }
#region FunctionMeta #region FunctionMeta
@ -918,7 +918,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<AddUGCDependencyResult_t?> AddDependency( PublishedFileId nParentPublishedFileID, PublishedFileId nChildPublishedFileID ) internal async Task<AddUGCDependencyResult_t?> AddDependency( PublishedFileId nParentPublishedFileID, PublishedFileId nChildPublishedFileID )
{ {
return await (new Result<AddUGCDependencyResult_t>( _AddDependency( Self, nParentPublishedFileID, nChildPublishedFileID ) )).GetResult(); return await AddUGCDependencyResult_t.GetResultAsync( _AddDependency( Self, nParentPublishedFileID, nChildPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -929,7 +929,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoveUGCDependencyResult_t?> RemoveDependency( PublishedFileId nParentPublishedFileID, PublishedFileId nChildPublishedFileID ) internal async Task<RemoveUGCDependencyResult_t?> RemoveDependency( PublishedFileId nParentPublishedFileID, PublishedFileId nChildPublishedFileID )
{ {
return await (new Result<RemoveUGCDependencyResult_t>( _RemoveDependency( Self, nParentPublishedFileID, nChildPublishedFileID ) )).GetResult(); return await RemoveUGCDependencyResult_t.GetResultAsync( _RemoveDependency( Self, nParentPublishedFileID, nChildPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -940,7 +940,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<AddAppDependencyResult_t?> AddAppDependency( PublishedFileId nPublishedFileID, AppId nAppID ) internal async Task<AddAppDependencyResult_t?> AddAppDependency( PublishedFileId nPublishedFileID, AppId nAppID )
{ {
return await (new Result<AddAppDependencyResult_t>( _AddAppDependency( Self, nPublishedFileID, nAppID ) )).GetResult(); return await AddAppDependencyResult_t.GetResultAsync( _AddAppDependency( Self, nPublishedFileID, nAppID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -951,7 +951,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<RemoveAppDependencyResult_t?> RemoveAppDependency( PublishedFileId nPublishedFileID, AppId nAppID ) internal async Task<RemoveAppDependencyResult_t?> RemoveAppDependency( PublishedFileId nPublishedFileID, AppId nAppID )
{ {
return await (new Result<RemoveAppDependencyResult_t>( _RemoveAppDependency( Self, nPublishedFileID, nAppID ) )).GetResult(); return await RemoveAppDependencyResult_t.GetResultAsync( _RemoveAppDependency( Self, nPublishedFileID, nAppID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -962,7 +962,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<GetAppDependenciesResult_t?> GetAppDependencies( PublishedFileId nPublishedFileID ) internal async Task<GetAppDependenciesResult_t?> GetAppDependencies( PublishedFileId nPublishedFileID )
{ {
return await (new Result<GetAppDependenciesResult_t>( _GetAppDependencies( Self, nPublishedFileID ) )).GetResult(); return await GetAppDependenciesResult_t.GetResultAsync( _GetAppDependencies( Self, nPublishedFileID ) );
} }
#region FunctionMeta #region FunctionMeta
@ -973,7 +973,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<DeleteItemResult_t?> DeleteItem( PublishedFileId nPublishedFileID ) internal async Task<DeleteItemResult_t?> DeleteItem( PublishedFileId nPublishedFileID )
{ {
return await (new Result<DeleteItemResult_t>( _DeleteItem( Self, nPublishedFileID ) )).GetResult(); return await DeleteItemResult_t.GetResultAsync( _DeleteItem( Self, nPublishedFileID ) );
} }
} }

View File

@ -290,7 +290,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<EncryptedAppTicketResponse_t?> RequestEncryptedAppTicket( IntPtr pDataToInclude, int cbDataToInclude ) internal async Task<EncryptedAppTicketResponse_t?> RequestEncryptedAppTicket( IntPtr pDataToInclude, int cbDataToInclude )
{ {
return await (new Result<EncryptedAppTicketResponse_t>( _RequestEncryptedAppTicket( Self, pDataToInclude, cbDataToInclude ) )).GetResult(); return await EncryptedAppTicketResponse_t.GetResultAsync( _RequestEncryptedAppTicket( Self, pDataToInclude, cbDataToInclude ) );
} }
#region FunctionMeta #region FunctionMeta
@ -335,7 +335,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<StoreAuthURLResponse_t?> RequestStoreAuthURL( string pchRedirectURL ) internal async Task<StoreAuthURLResponse_t?> RequestStoreAuthURL( string pchRedirectURL )
{ {
return await (new Result<StoreAuthURLResponse_t>( _RequestStoreAuthURL( Self, pchRedirectURL ) )).GetResult(); return await StoreAuthURLResponse_t.GetResultAsync( _RequestStoreAuthURL( Self, pchRedirectURL ) );
} }
#region FunctionMeta #region FunctionMeta
@ -394,7 +394,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<MarketEligibilityResponse_t?> GetMarketEligibility() internal async Task<MarketEligibilityResponse_t?> GetMarketEligibility()
{ {
return await (new Result<MarketEligibilityResponse_t>( _GetMarketEligibility( Self ) )).GetResult(); return await MarketEligibilityResponse_t.GetResultAsync( _GetMarketEligibility( Self ) );
} }
} }

View File

@ -258,7 +258,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<UserStatsReceived_t?> RequestUserStats( SteamId steamIDUser ) internal async Task<UserStatsReceived_t?> RequestUserStats( SteamId steamIDUser )
{ {
return await (new Result<UserStatsReceived_t>( _RequestUserStats( Self, steamIDUser ) )).GetResult(); return await UserStatsReceived_t.GetResultAsync( _RequestUserStats( Self, steamIDUser ) );
} }
#region FunctionMeta #region FunctionMeta
@ -329,7 +329,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<LeaderboardFindResult_t?> FindOrCreateLeaderboard( string pchLeaderboardName, LeaderboardSort eLeaderboardSortMethod, LeaderboardDisplay eLeaderboardDisplayType ) internal async Task<LeaderboardFindResult_t?> FindOrCreateLeaderboard( string pchLeaderboardName, LeaderboardSort eLeaderboardSortMethod, LeaderboardDisplay eLeaderboardDisplayType )
{ {
return await (new Result<LeaderboardFindResult_t>( _FindOrCreateLeaderboard( Self, pchLeaderboardName, eLeaderboardSortMethod, eLeaderboardDisplayType ) )).GetResult(); return await LeaderboardFindResult_t.GetResultAsync( _FindOrCreateLeaderboard( Self, pchLeaderboardName, eLeaderboardSortMethod, eLeaderboardDisplayType ) );
} }
#region FunctionMeta #region FunctionMeta
@ -340,7 +340,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<LeaderboardFindResult_t?> FindLeaderboard( string pchLeaderboardName ) internal async Task<LeaderboardFindResult_t?> FindLeaderboard( string pchLeaderboardName )
{ {
return await (new Result<LeaderboardFindResult_t>( _FindLeaderboard( Self, pchLeaderboardName ) )).GetResult(); return await LeaderboardFindResult_t.GetResultAsync( _FindLeaderboard( Self, pchLeaderboardName ) );
} }
#region FunctionMeta #region FunctionMeta
@ -395,7 +395,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<LeaderboardScoresDownloaded_t?> DownloadLeaderboardEntries( SteamLeaderboard_t hSteamLeaderboard, LeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd ) internal async Task<LeaderboardScoresDownloaded_t?> DownloadLeaderboardEntries( SteamLeaderboard_t hSteamLeaderboard, LeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd )
{ {
return await (new Result<LeaderboardScoresDownloaded_t>( _DownloadLeaderboardEntries( Self, hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd ) )).GetResult(); return await LeaderboardScoresDownloaded_t.GetResultAsync( _DownloadLeaderboardEntries( Self, hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd ) );
} }
#region FunctionMeta #region FunctionMeta
@ -406,7 +406,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<LeaderboardScoresDownloaded_t?> DownloadLeaderboardEntriesForUsers( SteamLeaderboard_t hSteamLeaderboard, [In,Out] SteamId[] prgUsers, int cUsers ) internal async Task<LeaderboardScoresDownloaded_t?> DownloadLeaderboardEntriesForUsers( SteamLeaderboard_t hSteamLeaderboard, [In,Out] SteamId[] prgUsers, int cUsers )
{ {
return await (new Result<LeaderboardScoresDownloaded_t>( _DownloadLeaderboardEntriesForUsers( Self, hSteamLeaderboard, prgUsers, cUsers ) )).GetResult(); return await LeaderboardScoresDownloaded_t.GetResultAsync( _DownloadLeaderboardEntriesForUsers( Self, hSteamLeaderboard, prgUsers, cUsers ) );
} }
#region FunctionMeta #region FunctionMeta
@ -429,7 +429,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<LeaderboardScoreUploaded_t?> UploadLeaderboardScore( SteamLeaderboard_t hSteamLeaderboard, LeaderboardUploadScoreMethod eLeaderboardUploadScoreMethod, int nScore, [In,Out] int[] pScoreDetails, int cScoreDetailsCount ) internal async Task<LeaderboardScoreUploaded_t?> UploadLeaderboardScore( SteamLeaderboard_t hSteamLeaderboard, LeaderboardUploadScoreMethod eLeaderboardUploadScoreMethod, int nScore, [In,Out] int[] pScoreDetails, int cScoreDetailsCount )
{ {
return await (new Result<LeaderboardScoreUploaded_t>( _UploadLeaderboardScore( Self, hSteamLeaderboard, eLeaderboardUploadScoreMethod, nScore, pScoreDetails, cScoreDetailsCount ) )).GetResult(); return await LeaderboardScoreUploaded_t.GetResultAsync( _UploadLeaderboardScore( Self, hSteamLeaderboard, eLeaderboardUploadScoreMethod, nScore, pScoreDetails, cScoreDetailsCount ) );
} }
#region FunctionMeta #region FunctionMeta
@ -440,7 +440,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<LeaderboardUGCSet_t?> AttachLeaderboardUGC( SteamLeaderboard_t hSteamLeaderboard, UGCHandle_t hUGC ) internal async Task<LeaderboardUGCSet_t?> AttachLeaderboardUGC( SteamLeaderboard_t hSteamLeaderboard, UGCHandle_t hUGC )
{ {
return await (new Result<LeaderboardUGCSet_t>( _AttachLeaderboardUGC( Self, hSteamLeaderboard, hUGC ) )).GetResult(); return await LeaderboardUGCSet_t.GetResultAsync( _AttachLeaderboardUGC( Self, hSteamLeaderboard, hUGC ) );
} }
#region FunctionMeta #region FunctionMeta
@ -451,7 +451,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<NumberOfCurrentPlayers_t?> GetNumberOfCurrentPlayers() internal async Task<NumberOfCurrentPlayers_t?> GetNumberOfCurrentPlayers()
{ {
return await (new Result<NumberOfCurrentPlayers_t>( _GetNumberOfCurrentPlayers( Self ) )).GetResult(); return await NumberOfCurrentPlayers_t.GetResultAsync( _GetNumberOfCurrentPlayers( Self ) );
} }
#region FunctionMeta #region FunctionMeta
@ -462,7 +462,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<GlobalAchievementPercentagesReady_t?> RequestGlobalAchievementPercentages() internal async Task<GlobalAchievementPercentagesReady_t?> RequestGlobalAchievementPercentages()
{ {
return await (new Result<GlobalAchievementPercentagesReady_t>( _RequestGlobalAchievementPercentages( Self ) )).GetResult(); return await GlobalAchievementPercentagesReady_t.GetResultAsync( _RequestGlobalAchievementPercentages( Self ) );
} }
#region FunctionMeta #region FunctionMeta
@ -507,7 +507,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<GlobalStatsReceived_t?> RequestGlobalStats( int nHistoryDays ) internal async Task<GlobalStatsReceived_t?> RequestGlobalStats( int nHistoryDays )
{ {
return await (new Result<GlobalStatsReceived_t>( _RequestGlobalStats( Self, nHistoryDays ) )).GetResult(); return await GlobalStatsReceived_t.GetResultAsync( _RequestGlobalStats( Self, nHistoryDays ) );
} }
#region FunctionMeta #region FunctionMeta

View File

@ -273,7 +273,7 @@ namespace Steamworks
#endregion #endregion
internal async Task<CheckFileSignature_t?> CheckFileSignature( string szFileName ) internal async Task<CheckFileSignature_t?> CheckFileSignature( string szFileName )
{ {
return await (new Result<CheckFileSignature_t>( _CheckFileSignature( Self, szFileName ) )).GetResult(); return await CheckFileSignature_t.GetResultAsync( _CheckFileSignature( Self, szFileName ) );
} }
#region FunctionMeta #region FunctionMeta

View File

@ -2,6 +2,7 @@ using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Linq; using System.Linq;
using Steamworks.Data; using Steamworks.Data;
using System.Threading.Tasks;
namespace Steamworks.Data namespace Steamworks.Data
{ {

View File

@ -2,6 +2,7 @@ using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Linq; using System.Linq;
using Steamworks.Data; using Steamworks.Data;
using System.Threading.Tasks;
namespace Steamworks namespace Steamworks
{ {

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Linq; using System.Linq;
using Steamworks.Data; using Steamworks.Data;
using System.Threading.Tasks;
namespace Steamworks.Data namespace Steamworks.Data
{ {

View File

@ -250,38 +250,10 @@ namespace Steamworks
} }
} }
internal static bool IsCallComplete( SteamAPICall_t call, out bool failed ) internal static bool IsCallComplete( SteamAPICall_t call, out bool failed )
{ {
failed = false; failed = false;
return Internal.IsAPICallCompleted( call, ref failed ); return Internal.IsAPICallCompleted( call, ref failed );
} }
internal static T? GetResult<T>( SteamAPICall_t call ) where T : struct, ISteamCallback
{
var t = new T();
var size = t.GetStructSize();
var ptr = Marshal.AllocHGlobal( size );
try
{
bool failed = false;
if ( !Internal.GetAPICallResult( call, ptr, size, t.GetCallbackId(), ref failed ) )
return null;
if ( failed )
return null;
t = (T)t.Fill( ptr );
return t;
}
finally
{
Marshal.FreeHGlobal( ptr );
}
}
} }
} }

View File

@ -110,6 +110,7 @@ namespace Generator
WriteLine( "using System.Runtime.InteropServices;" ); WriteLine( "using System.Runtime.InteropServices;" );
WriteLine( "using System.Linq;" ); WriteLine( "using System.Linq;" );
WriteLine( "using Steamworks.Data;" ); WriteLine( "using Steamworks.Data;" );
WriteLine( "using System.Threading.Tasks;" );
WriteLine(); WriteLine();
StartBlock( "namespace " + NamespaceName ); StartBlock( "namespace " + NamespaceName );
} }

View File

@ -64,7 +64,7 @@ namespace Generator
// Main struct // Main struct
// //
WriteLine( "[StructLayout( LayoutKind.Sequential, Pack = 4 )]" ); WriteLine( "[StructLayout( LayoutKind.Sequential, Pack = 4 )]" );
StartBlock( $"{Cleanup.Expose( name )} struct {name}{(isCallback?" : Steamworks.ISteamCallback":"")}" ); StartBlock( $"{Cleanup.Expose( name )} struct {name}" );
{ {
// //
// The fields // The fields
@ -74,43 +74,69 @@ namespace Generator
if ( isCallback ) if ( isCallback )
{ {
WriteLine( "#region ISteamCallback" ); WriteLine( "#region SteamCallback" );
{ {
WriteLine( $"public int GetCallbackId() => {c.CallbackId};" );
if ( defaultPack == 4 ) if ( defaultPack == 4 )
{ {
WriteLine( $"public int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( typeof({name}) );" ); WriteLine( $"internal static readonly int StructSize = System.Runtime.InteropServices.Marshal.SizeOf( typeof({name}) );" );
WriteLine( $"public Steamworks.ISteamCallback Fill( IntPtr p ) => (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) ) );" ); WriteLine( $"internal static {name} Fill( IntPtr p ) => (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) ) );" );
} }
else else
{ {
WriteLine( $"public int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( Config.PackSmall ? typeof({name}) : typeof(Pack8) );" ); WriteLine( $"internal static readonly int StructSize = System.Runtime.InteropServices.Marshal.SizeOf( Config.PackSmall ? typeof({name}) : typeof(Pack8) );" );
WriteLine( $"public Steamworks.ISteamCallback Fill( IntPtr p ) => Config.PackSmall ? (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) )) : (({name})(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));" ); WriteLine( $"internal static {name} Fill( IntPtr p ) => Config.PackSmall ? (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) )) : (({name})(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));" );
} }
WriteLine();
WriteLine( $"static Action<{name}> actionClient;" ); WriteLine( $"static Action<{name}> actionClient;" );
WriteLine( $"[MonoPInvokeCallback] static void OnClient( IntPtr thisptr, IntPtr pvParam ) => actionClient?.Invoke( ({name})default({name}).Fill( pvParam ) );" ); WriteLine( $"[MonoPInvokeCallback] static void OnClient( IntPtr thisptr, IntPtr pvParam ) => actionClient?.Invoke( Fill( pvParam ) );" );
WriteLine( $"static Action<{name}> actionServer;" ); WriteLine( $"static Action<{name}> actionServer;" );
WriteLine( $"[MonoPInvokeCallback] static void OnServer( IntPtr thisptr, IntPtr pvParam ) => actionServer?.Invoke( ({name})default({name}).Fill( pvParam ) );" ); WriteLine( $"[MonoPInvokeCallback] static void OnServer( IntPtr thisptr, IntPtr pvParam ) => actionServer?.Invoke( Fill( pvParam ) );" );
StartBlock( $"public static void Install( Action<{name}> action, bool server = false )" ); StartBlock( $"public static void Install( Action<{name}> action, bool server = false )" );
{ {
StartBlock( "if ( server )" ); StartBlock( "if ( server )" );
{ {
WriteLine( $"Event.Register( OnServer, default({name}).GetStructSize(), {c.CallbackId}, true );" ); WriteLine( $"Event.Register( OnServer, StructSize, {c.CallbackId}, true );" );
WriteLine( $"actionServer = action;" ); WriteLine( $"actionServer = action;" );
} }
Else(); Else();
{ {
WriteLine( $"Event.Register( OnClient, default({name}).GetStructSize(), {c.CallbackId}, false );" ); WriteLine( $"Event.Register( OnClient, StructSize, {c.CallbackId}, false );" );
WriteLine( $"actionClient = action;" ); WriteLine( $"actionClient = action;" );
} }
EndBlock(); EndBlock();
} }
EndBlock(); EndBlock();
StartBlock( $"public static async Task<{name}?> GetResultAsync( SteamAPICall_t handle )" );
{
WriteLine( $"bool failed = false;" );
WriteLine();
StartBlock( $"while ( !SteamUtils.IsCallComplete( handle, out failed ) )" );
{
WriteLine( $"await Task.Delay( 1 );" );
}
EndBlock();
WriteLine( $"if ( failed ) return null;" );
WriteLine( $"" );
WriteLine( $"var ptr = Marshal.AllocHGlobal( StructSize );" );
WriteLine( $"" );
WriteLine( $"try" );
WriteLine( $"{{" );
WriteLine( $" if ( !SteamUtils.Internal.GetAPICallResult( handle, ptr, StructSize, {c.CallbackId}, ref failed ) || failed )" );
WriteLine( $" return null;" );
WriteLine( $"" );
WriteLine( $" return Fill( ptr );" );
WriteLine( $"}}" );
WriteLine( $"finally" );
WriteLine( $"{{" );
WriteLine( $" Marshal.FreeHGlobal( ptr );" );
WriteLine( $"}}" );
}
EndBlock();
} }
WriteLine( "#endregion" ); WriteLine( "#endregion" );
} }
@ -120,13 +146,13 @@ namespace Generator
{ {
if ( defaultPack == 4 ) if ( defaultPack == 4 )
{ {
WriteLine( $"public int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( typeof({name}) );" ); //WriteLine( $"internal static int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( typeof({name}) );" );
WriteLine( $"public {name} Fill( IntPtr p ) => (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) ) );" ); WriteLine( $"internal static {name} Fill( IntPtr p ) => (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) ) );" );
} }
else else
{ {
WriteLine( $"public int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( Config.PackSmall ? typeof({name}) : typeof(Pack8) );" ); //WriteLine( $"internal static int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( Config.PackSmall ? typeof({name}) : typeof(Pack8) );" );
WriteLine( $"public {name} Fill( IntPtr p ) => Config.PackSmall ? (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) )) : (({name})(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));" ); WriteLine( $"internal static {name} Fill( IntPtr p ) => Config.PackSmall ? (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) )) : (({name})(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));" );
} }
} }
WriteLine( "#endregion" ); WriteLine( "#endregion" );

View File

@ -114,7 +114,7 @@ internal class StructType : BaseType
{ {
if ( NativeType.EndsWith( "*" ) ) if ( NativeType.EndsWith( "*" ) )
{ {
return $"return new {TypeName}().Fill( {varname} );"; return $"return {TypeName}.Fill( {varname} );";
} }
return base.Return( varname ); return base.Return( varname );
@ -125,7 +125,7 @@ internal class SteamApiCallType : BaseType
{ {
public string CallResult; public string CallResult;
public override string TypeName => "SteamAPICall_t"; public override string TypeName => "SteamAPICall_t";
public override string Return( string varname ) => $"return await (new Result<{CallResult}>( {varname} )).GetResult();"; public override string Return( string varname ) => $"return await {CallResult}.GetResultAsync( {varname} );";
public override string ReturnType => $"async Task<{CallResult}?>"; public override string ReturnType => $"async Task<{CallResult}?>";
} }