Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests

This commit is contained in:
Evil Factory
2022-04-08 12:52:28 -03:00
990 changed files with 44338 additions and 38589 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
@@ -221,7 +222,7 @@ namespace Steamworks
}
// Remove it before we do anything, incase the continuation throws exceptions
ResultCallbacks.Remove( result.AsyncCall );
ResultCallbacks.Remove( result.AsyncCall, out _ );
// At this point whatever async routine called this
// continues running.
@@ -262,7 +263,7 @@ namespace Steamworks
public bool server;
}
static Dictionary<ulong, ResultCallback> ResultCallbacks = new Dictionary<ulong, ResultCallback>();
static ConcurrentDictionary<ulong, ResultCallback> ResultCallbacks = new ConcurrentDictionary<ulong, ResultCallback>();
/// <summary>
/// Watch for a steam api call
@@ -305,6 +306,15 @@ namespace Steamworks
} );
}
private static void RemoveCallbacks(Func<KeyValuePair<ulong, ResultCallback>, bool> predicate)
{
var toRemove = ResultCallbacks.Where( predicate ).Select(kvp => kvp.Key).ToArray();
foreach (var key in toRemove)
{
ResultCallbacks.Remove(key, out _);
}
}
internal static void ShutdownServer()
{
ServerPipe = 0;
@@ -314,8 +324,7 @@ namespace Steamworks
Callbacks[callback.Key].RemoveAll( x => x.server );
}
ResultCallbacks = ResultCallbacks.Where( x => !x.Value.server )
.ToDictionary( x => x.Key, x => x.Value );
RemoveCallbacks(x => x.Value.server);
}
internal static void ShutdownClient()
@@ -327,8 +336,7 @@ namespace Steamworks
Callbacks[callback.Key].RemoveAll( x => !x.server );
}
ResultCallbacks = ResultCallbacks.Where( x => x.Value.server )
.ToDictionary( x => x.Key, x => x.Value );
RemoveCallbacks(x => !x.Value.server);
}
}
}

View File

@@ -49,7 +49,8 @@ namespace Steamworks
#endregion
internal int GetAppName( AppId nAppID, out string pchName )
{
IntPtr mempchName = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchName = memory;
var returnValue = _GetAppName( Self, nAppID, mempchName, (1024 * 32) );
pchName = Helpers.MemoryToString( mempchName );
return returnValue;
@@ -62,7 +63,8 @@ namespace Steamworks
#endregion
internal int GetAppInstallDir( AppId nAppID, out string pchDirectory )
{
IntPtr mempchDirectory = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchDirectory = memory;
var returnValue = _GetAppInstallDir( Self, nAppID, mempchDirectory, (1024 * 32) );
pchDirectory = Helpers.MemoryToString( mempchDirectory );
return returnValue;

View File

@@ -159,7 +159,8 @@ namespace Steamworks
#endregion
internal bool BGetDLCDataByIndex( int iDLC, ref AppId pAppID, [MarshalAs( UnmanagedType.U1 )] ref bool pbAvailable, out string pchName )
{
IntPtr mempchName = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchName = memory;
var returnValue = _BGetDLCDataByIndex( Self, iDLC, ref pAppID, ref pbAvailable, mempchName, (1024 * 32) );
pchName = Helpers.MemoryToString( mempchName );
return returnValue;
@@ -203,7 +204,8 @@ namespace Steamworks
#endregion
internal bool GetCurrentBetaName( out string pchName )
{
IntPtr mempchName = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchName = memory;
var returnValue = _GetCurrentBetaName( Self, mempchName, (1024 * 32) );
pchName = Helpers.MemoryToString( mempchName );
return returnValue;
@@ -239,7 +241,8 @@ namespace Steamworks
#endregion
internal uint GetAppInstallDir( AppId appID, out string pchFolder )
{
IntPtr mempchFolder = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchFolder = memory;
var returnValue = _GetAppInstallDir( Self, appID, mempchFolder, (1024 * 32) );
pchFolder = Helpers.MemoryToString( mempchFolder );
return returnValue;
@@ -330,7 +333,8 @@ namespace Steamworks
#endregion
internal int GetLaunchCommandLine( out string pszCommandLine )
{
IntPtr mempszCommandLine = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempszCommandLine = memory;
var returnValue = _GetLaunchCommandLine( Self, mempszCommandLine, (1024 * 32) );
pszCommandLine = Helpers.MemoryToString( mempszCommandLine );
return returnValue;

View File

@@ -82,7 +82,8 @@ namespace Steamworks
#endregion
internal GameSearchErrorCode_t RetrieveConnectionDetails( SteamId steamIDHost, out string pchConnectionDetails )
{
IntPtr mempchConnectionDetails = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchConnectionDetails = memory;
var returnValue = _RetrieveConnectionDetails( Self, steamIDHost, mempchConnectionDetails, (1024 * 32) );
pchConnectionDetails = Helpers.MemoryToString( mempchConnectionDetails );
return returnValue;

View File

@@ -60,7 +60,8 @@ namespace Steamworks
#endregion
internal bool GetResultItemProperty( SteamInventoryResult_t resultHandle, uint unItemIndex, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchPropertyName, out string pchValueBuffer, ref uint punValueBufferSizeOut )
{
IntPtr mempchValueBuffer = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchValueBuffer = memory;
var returnValue = _GetResultItemProperty( Self, resultHandle, unItemIndex, pchPropertyName, mempchValueBuffer, ref punValueBufferSizeOut );
pchValueBuffer = Helpers.MemoryToString( mempchValueBuffer );
return returnValue;
@@ -327,7 +328,8 @@ namespace Steamworks
#endregion
internal bool GetItemDefinitionProperty( InventoryDefId iDefinition, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchPropertyName, out string pchValueBuffer, ref uint punValueBufferSizeOut )
{
IntPtr mempchValueBuffer = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchValueBuffer = memory;
var returnValue = _GetItemDefinitionProperty( Self, iDefinition, pchPropertyName, mempchValueBuffer, ref punValueBufferSizeOut );
pchValueBuffer = Helpers.MemoryToString( mempchValueBuffer );
return returnValue;

View File

@@ -266,8 +266,10 @@ namespace Steamworks
#endregion
internal bool GetLobbyDataByIndex( SteamId steamIDLobby, int iLobbyData, out string pchKey, out string pchValue )
{
IntPtr mempchKey = Helpers.TakeMemory();
IntPtr mempchValue = Helpers.TakeMemory();
using var memoryKey = Helpers.TakeMemory();
using var memoryValue = Helpers.TakeMemory();
IntPtr mempchKey = memoryKey;
IntPtr mempchValue = memoryValue;
var returnValue = _GetLobbyDataByIndex( Self, steamIDLobby, iLobbyData, mempchKey, (1024 * 32), mempchValue, (1024 * 32) );
pchKey = Helpers.MemoryToString( mempchKey );
pchValue = Helpers.MemoryToString( mempchValue );

View File

@@ -143,7 +143,8 @@ namespace Steamworks
#endregion
internal bool GetConnectionName( Connection hPeer, out string pszName )
{
IntPtr mempszName = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempszName = memory;
var returnValue = _GetConnectionName( Self, hPeer, mempszName, (1024 * 32) );
pszName = Helpers.MemoryToString( mempszName );
return returnValue;
@@ -223,7 +224,8 @@ namespace Steamworks
#endregion
internal int GetDetailedConnectionStatus( Connection hConn, out string pszBuf )
{
IntPtr mempszBuf = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempszBuf = memory;
var returnValue = _GetDetailedConnectionStatus( Self, hConn, mempszBuf, (1024 * 32) );
pszBuf = Helpers.MemoryToString( mempszBuf );
return returnValue;

View File

@@ -92,7 +92,8 @@ namespace Steamworks
#endregion
internal void ConvertPingLocationToString( ref NetPingLocation location, out string pszBuf )
{
IntPtr mempszBuf = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempszBuf = memory;
_ConvertPingLocationToString( Self, ref location, mempszBuf, (1024 * 32) );
pszBuf = Helpers.MemoryToString( mempszBuf );
}
@@ -323,7 +324,8 @@ namespace Steamworks
#endregion
internal void SteamNetworkingIPAddr_ToString( ref NetAddress addr, out string buf, [MarshalAs( UnmanagedType.U1 )] bool bWithPort )
{
IntPtr membuf = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr membuf = memory;
_SteamNetworkingIPAddr_ToString( Self, ref addr, membuf, (1024 * 32), bWithPort );
buf = Helpers.MemoryToString( membuf );
}
@@ -347,7 +349,8 @@ namespace Steamworks
#endregion
internal void SteamNetworkingIdentity_ToString( ref NetIdentity identity, out string buf )
{
IntPtr membuf = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr membuf = memory;
_SteamNetworkingIdentity_ToString( Self, ref identity, membuf, (1024 * 32) );
buf = Helpers.MemoryToString( membuf );
}

View File

@@ -50,7 +50,8 @@ namespace Steamworks
#endregion
internal bool GetBeaconDetails( PartyBeaconID_t ulBeaconID, ref SteamId pSteamIDBeaconOwner, ref SteamPartyBeaconLocation_t pLocation, out string pchMetadata )
{
IntPtr mempchMetadata = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchMetadata = memory;
var returnValue = _GetBeaconDetails( Self, ulBeaconID, ref pSteamIDBeaconOwner, ref pLocation, mempchMetadata, (1024 * 32) );
pchMetadata = Helpers.MemoryToString( mempchMetadata );
return returnValue;
@@ -153,7 +154,8 @@ namespace Steamworks
#endregion
internal bool GetBeaconLocationData( SteamPartyBeaconLocation_t BeaconLocation, SteamPartyBeaconLocationData eData, out string pchDataStringOut )
{
IntPtr mempchDataStringOut = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchDataStringOut = memory;
var returnValue = _GetBeaconLocationData( Self, BeaconLocation, eData, mempchDataStringOut, (1024 * 32) );
pchDataStringOut = Helpers.MemoryToString( mempchDataStringOut );
return returnValue;

View File

@@ -98,7 +98,8 @@ namespace Steamworks
#endregion
internal bool GetQueryUGCPreviewURL( UGCQueryHandle_t handle, uint index, out string pchURL )
{
IntPtr mempchURL = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchURL = memory;
var returnValue = _GetQueryUGCPreviewURL( Self, handle, index, mempchURL, (1024 * 32) );
pchURL = Helpers.MemoryToString( mempchURL );
return returnValue;
@@ -112,7 +113,8 @@ namespace Steamworks
#endregion
internal bool GetQueryUGCMetadata( UGCQueryHandle_t handle, uint index, out string pchMetadata )
{
IntPtr mempchMetadata = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchMetadata = memory;
var returnValue = _GetQueryUGCMetadata( Self, handle, index, mempchMetadata, (1024 * 32) );
pchMetadata = Helpers.MemoryToString( mempchMetadata );
return returnValue;
@@ -161,8 +163,10 @@ namespace Steamworks
#endregion
internal bool GetQueryUGCAdditionalPreview( UGCQueryHandle_t handle, uint index, uint previewIndex, out string pchURLOrVideoID, out string pchOriginalFileName, ref ItemPreviewType pPreviewType )
{
IntPtr mempchURLOrVideoID = Helpers.TakeMemory();
IntPtr mempchOriginalFileName = Helpers.TakeMemory();
using var memoryUrlOrId = Helpers.TakeMemory();
using var memoryFileName = Helpers.TakeMemory();
IntPtr mempchURLOrVideoID = memoryUrlOrId;
IntPtr mempchOriginalFileName = memoryFileName;
var returnValue = _GetQueryUGCAdditionalPreview( Self, handle, index, previewIndex, mempchURLOrVideoID, (1024 * 32), mempchOriginalFileName, (1024 * 32), ref pPreviewType );
pchURLOrVideoID = Helpers.MemoryToString( mempchURLOrVideoID );
pchOriginalFileName = Helpers.MemoryToString( mempchOriginalFileName );
@@ -188,8 +192,10 @@ namespace Steamworks
#endregion
internal bool GetQueryUGCKeyValueTag( UGCQueryHandle_t handle, uint index, uint keyValueTagIndex, out string pchKey, out string pchValue )
{
IntPtr mempchKey = Helpers.TakeMemory();
IntPtr mempchValue = Helpers.TakeMemory();
using var memoryKey = Helpers.TakeMemory();
using var memoryValue = Helpers.TakeMemory();
IntPtr mempchKey = memoryKey;
IntPtr mempchValue = memoryValue;
var returnValue = _GetQueryUGCKeyValueTag( Self, handle, index, keyValueTagIndex, mempchKey, (1024 * 32), mempchValue, (1024 * 32) );
pchKey = Helpers.MemoryToString( mempchKey );
pchValue = Helpers.MemoryToString( mempchValue );
@@ -204,7 +210,8 @@ namespace Steamworks
#endregion
internal bool GetQueryUGCKeyValueTag( UGCQueryHandle_t handle, uint index, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchKey, out string pchValue )
{
IntPtr mempchValue = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchValue = memory;
var returnValue = _GetQueryUGCKeyValueTag( Self, handle, index, pchKey, mempchValue, (1024 * 32) );
pchValue = Helpers.MemoryToString( mempchValue );
return returnValue;
@@ -793,7 +800,8 @@ namespace Steamworks
#endregion
internal bool GetItemInstallInfo( PublishedFileId nPublishedFileID, ref ulong punSizeOnDisk, out string pchFolder, ref uint punTimeStamp )
{
IntPtr mempchFolder = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchFolder = memory;
var returnValue = _GetItemInstallInfo( Self, nPublishedFileID, ref punSizeOnDisk, mempchFolder, (1024 * 32), ref punTimeStamp );
pchFolder = Helpers.MemoryToString( mempchFolder );
return returnValue;

View File

@@ -93,7 +93,8 @@ namespace Steamworks
#endregion
internal bool GetUserDataFolder( out string pchBuffer )
{
IntPtr mempchBuffer = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchBuffer = memory;
var returnValue = _GetUserDataFolder( Self, mempchBuffer, (1024 * 32) );
pchBuffer = Helpers.MemoryToString( mempchBuffer );
return returnValue;

View File

@@ -433,7 +433,8 @@ namespace Steamworks
#endregion
internal int GetMostAchievedAchievementInfo( out string pchName, ref float pflPercent, [MarshalAs( UnmanagedType.U1 )] ref bool pbAchieved )
{
IntPtr mempchName = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchName = memory;
var returnValue = _GetMostAchievedAchievementInfo( Self, mempchName, (1024 * 32), ref pflPercent, ref pbAchieved );
pchName = Helpers.MemoryToString( mempchName );
return returnValue;
@@ -446,7 +447,8 @@ namespace Steamworks
#endregion
internal int GetNextMostAchievedAchievementInfo( int iIteratorPrevious, out string pchName, ref float pflPercent, [MarshalAs( UnmanagedType.U1 )] ref bool pbAchieved )
{
IntPtr mempchName = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchName = memory;
var returnValue = _GetNextMostAchievedAchievementInfo( Self, iIteratorPrevious, mempchName, (1024 * 32), ref pflPercent, ref pbAchieved );
pchName = Helpers.MemoryToString( mempchName );
return returnValue;

View File

@@ -268,7 +268,8 @@ namespace Steamworks
#endregion
internal bool GetEnteredGamepadTextInput( out string pchText )
{
IntPtr mempchText = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchText = memory;
var returnValue = _GetEnteredGamepadTextInput( Self, mempchText, (1024 * 32) );
pchText = Helpers.MemoryToString( mempchText );
return returnValue;
@@ -382,7 +383,8 @@ namespace Steamworks
#endregion
internal int FilterText( out string pchOutFilteredText, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchInputMessage, [MarshalAs( UnmanagedType.U1 )] bool bLegalOnly )
{
IntPtr mempchOutFilteredText = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchOutFilteredText = memory;
var returnValue = _FilterText( Self, mempchOutFilteredText, (1024 * 32), pchInputMessage, bLegalOnly );
pchOutFilteredText = Helpers.MemoryToString( mempchOutFilteredText );
return returnValue;

View File

@@ -60,7 +60,8 @@ namespace Steamworks
#endregion
internal bool GetOPFStringForApp( AppId unVideoAppID, out string pchBuffer, ref int pnBufferSize )
{
IntPtr mempchBuffer = Helpers.TakeMemory();
using var memory = Helpers.TakeMemory();
IntPtr mempchBuffer = memory;
var returnValue = _GetOPFStringForApp( Self, unVideoAppID, mempchBuffer, ref pnBufferSize );
pchBuffer = Helpers.MemoryToString( mempchBuffer );
return returnValue;

View File

@@ -147,7 +147,7 @@ namespace Steamworks.Data
public override string ToString()
{
var ptr = Helpers.TakeMemory();
using var ptr = Helpers.TakeMemory();
var self = this;
InternalToString( ref self, ptr, Helpers.MemoryBufferSize, true );
return Helpers.MemoryToString( ptr );

View File

@@ -83,7 +83,7 @@ namespace Steamworks
var friend = new Friend( data.SteamIDUser );
var buffer = Helpers.TakeMemory();
using var buffer = Helpers.TakeMemory();
var type = ChatEntryType.ChatMsg;
var len = Internal.GetFriendMessage( data.SteamIDUser, data.MessageID, buffer, Helpers.MemoryBufferSize, ref type );

View File

@@ -72,7 +72,7 @@ namespace Steamworks
{
SteamId steamid = default;
ChatEntryType chatEntryType = default;
var buffer = Helpers.TakeMemory();
using var buffer = Helpers.TakeMemory();
var readData = Internal.GetLobbyChatEntry( callback.SteamIDLobby, (int)callback.ChatID, ref steamid, buffer, Helpers.MemoryBufferSize, ref chatEntryType );

View File

@@ -29,14 +29,7 @@ namespace Steamworks
{
if (x.AppID == SteamClient.AppId)
{
OnDownloadItemResult?.Invoke(x.Result);
Ugc.Item item = new Ugc.Item(x.PublishedFileId);
if (item.IsInstalled && (onItemInstalled?.ContainsKey(x.PublishedFileId) ?? false))
{
onItemInstalled[x.PublishedFileId]?.Invoke();
onItemInstalled.Remove(x.PublishedFileId);
}
OnDownloadItemResult?.Invoke(x.Result, x.PublishedFileId);
}
}, server );
Dispatch.Install<ItemInstalled_t>(x =>
@@ -44,11 +37,6 @@ namespace Steamworks
if (x.AppID == SteamClient.AppId)
{
GlobalOnItemInstalled?.Invoke(x.PublishedFileId);
if (onItemInstalled?.ContainsKey(x.PublishedFileId) ?? false)
{
onItemInstalled[x.PublishedFileId]?.Invoke();
onItemInstalled.Remove(x.PublishedFileId);
}
}
}, server);
}
@@ -56,7 +44,7 @@ namespace Steamworks
/// <summary>
/// Posted after Download call
/// </summary>
public static event Action<Result> OnDownloadItemResult;
public static event Action<Result, ulong> OnDownloadItemResult;
public static async Task<bool> DeleteFileAsync( PublishedFileId fileId )
{
@@ -70,20 +58,8 @@ namespace Steamworks
/// <param name="fileId">The ID of the file you want to download</param>
/// <param name="highPriority">If true this should go straight to the top of the download list</param>
/// <returns>true if nothing went wrong and the download is started</returns>
public static bool Download( PublishedFileId fileId, Action onInstalled = null, bool highPriority = false )
public static bool Download( PublishedFileId fileId, bool highPriority = false )
{
if (onInstalled != null)
{
onItemInstalled ??= new Dictionary<PublishedFileId, Action>();
if (!onItemInstalled.ContainsKey(fileId))
{
onItemInstalled.Add(fileId, onInstalled);
}
else
{
onItemInstalled[fileId] += onInstalled;
}
}
return Internal.DownloadItem( fileId, highPriority );
}
@@ -104,7 +80,7 @@ namespace Steamworks
progress?.Invoke( 0.0f );
if ( Download( fileId, null, true ) == false )
if ( Download( fileId, highPriority: true ) == false )
return item.IsInstalled;
// Steam docs about Download:
@@ -114,20 +90,31 @@ namespace Steamworks
// Wait for DownloadItemResult_t
{
Action<Result> onDownloadStarted = null;
Action<Result, ulong> onDownloadStarted = null;
try
{
var downloadStarted = false;
onDownloadStarted = r => downloadStarted = true;
onDownloadStarted = (r, id) => downloadStarted = true;
OnDownloadItemResult += onDownloadStarted;
int iters = 0;
while ( downloadStarted == false )
{
if ( ct.IsCancellationRequested )
break;
ct.ThrowIfCancellationRequested();
iters++;
if (iters >= 1000 / milisecondsUpdateDelay)
{
if (!item.IsDownloading && !item.IsInstalled)
{
//force download to start if it's not started
if ( Download( fileId, highPriority: true ) == false )
return item.IsInstalled;
}
iters = 0;
}
await Task.Delay( milisecondsUpdateDelay );
}
}
@@ -144,8 +131,7 @@ namespace Steamworks
{
while ( true )
{
if ( ct.IsCancellationRequested )
break;
ct.ThrowIfCancellationRequested();
progress?.Invoke( 0.2f + item.DownloadAmount * 0.8f );
@@ -199,11 +185,17 @@ namespace Steamworks
return result.Value.Result == Result.OK;
}
private static Dictionary<PublishedFileId, Action> onItemInstalled;
public static event Action<ulong> GlobalOnItemInstalled;
public static Action<ulong> GlobalOnItemInstalled;
public static uint NumSubscribedItems { get { return Internal.GetNumSubscribedItems(); } }
public static PublishedFileId[] GetSubscribedItems()
{
uint numSubscribed = NumSubscribedItems;
PublishedFileId[] ids = new PublishedFileId[numSubscribed];
Internal.GetSubscribedItems(ids, numSubscribed);
return ids;
}
}
}

View File

@@ -69,19 +69,13 @@ namespace Steamworks.Ugc
public Editor WithContent( System.IO.DirectoryInfo t ) { this.ContentFolder = t; return this; }
public Editor WithContent( string folderName ) { return WithContent( new System.IO.DirectoryInfo( folderName ) ); }
RemoteStoragePublishedFileVisibility? Visibility;
public Visibility? Visibility;
public Editor WithPublicVisibility() { Visibility = RemoteStoragePublishedFileVisibility.Public; return this; }
public Editor WithFriendsOnlyVisibility() { Visibility = RemoteStoragePublishedFileVisibility.FriendsOnly; return this; }
public Editor WithPrivateVisibility() { Visibility = RemoteStoragePublishedFileVisibility.Private; return this; }
public Editor WithVisibility(Visibility visibility) { Visibility = visibility; return this; }
public List<string> Tags { get; private set; }
Dictionary<string, List<string>> KeyValueTags;
HashSet<string> KeyValueTagsToRemove;
public bool IsPublic => Visibility == RemoteStoragePublishedFileVisibility.Public;
public bool IsFriendsOnly => Visibility == RemoteStoragePublishedFileVisibility.FriendsOnly;
public bool IsPrivate => Visibility == RemoteStoragePublishedFileVisibility.Private;
Dictionary<string, List<string>> keyValueTags;
HashSet<string> keyValueTagsToRemove;
public Editor WithTag( string tag )
{
@@ -117,13 +111,13 @@ namespace Steamworks.Ugc
/// </summary>
public Editor AddKeyValueTag(string key, string value)
{
if (KeyValueTags == null)
KeyValueTags = new Dictionary<string, List<string>>();
if (keyValueTags == null)
keyValueTags = new Dictionary<string, List<string>>();
if ( KeyValueTags.TryGetValue( key, out var list ) )
if ( keyValueTags.TryGetValue( key, out var list ) )
list.Add( value );
else
KeyValueTags[key] = new List<string>() { value };
keyValueTags[key] = new List<string>() { value };
return this;
}
@@ -135,10 +129,10 @@ namespace Steamworks.Ugc
/// </summary>
public Editor RemoveKeyValueTags(string key)
{
if (KeyValueTagsToRemove == null)
KeyValueTagsToRemove = new HashSet<string>();
if (keyValueTagsToRemove == null)
keyValueTagsToRemove = new HashSet<string>();
KeyValueTagsToRemove.Add(key);
keyValueTagsToRemove.Add(key);
return this;
}
@@ -207,7 +201,7 @@ namespace Steamworks.Ugc
if ( Language != null ) SteamUGC.Internal.SetItemUpdateLanguage( handle, Language );
if ( ContentFolder != null ) SteamUGC.Internal.SetItemContent( handle, ContentFolder.FullName );
if ( PreviewFile != null ) SteamUGC.Internal.SetItemPreview( handle, PreviewFile );
if ( Visibility.HasValue ) SteamUGC.Internal.SetItemVisibility( handle, Visibility.Value );
if ( Visibility.HasValue ) SteamUGC.Internal.SetItemVisibility( handle, (RemoteStoragePublishedFileVisibility)Visibility.Value );
if ( Tags != null && Tags.Count > 0 )
{
using ( var a = SteamParamStringArray.From( Tags.ToArray() ) )
@@ -217,15 +211,15 @@ namespace Steamworks.Ugc
}
}
if ( KeyValueTagsToRemove != null)
if ( keyValueTagsToRemove != null)
{
foreach ( var key in KeyValueTagsToRemove )
foreach ( var key in keyValueTagsToRemove )
SteamUGC.Internal.RemoveItemKeyValueTags( handle, key );
}
if ( KeyValueTags != null )
if ( keyValueTags != null )
{
foreach ( var keyWithValues in KeyValueTags )
foreach ( var keyWithValues in keyValueTags )
{
var key = keyWithValues.Key;
foreach ( var value in keyWithValues.Value )

View File

@@ -9,6 +9,14 @@ using QueryType = Steamworks.Ugc.Query;
namespace Steamworks.Ugc
{
public enum Visibility : int
{
Public = 0,
FriendsOnly = 1,
Private = 2,
Unlisted = 3,
}
public struct Item
{
internal SteamUGCDetails_t details;
@@ -74,20 +82,20 @@ namespace Steamworks.Ugc
/// </summary>
public DateTime Updated => Epoch.ToDateTime( details.TimeUpdated );
/// <summary>
/// True if this is publically visible
/// </summary>
public bool IsPublic => details.Visibility == RemoteStoragePublishedFileVisibility.Public;
public DateTime LatestUpdateTime
{
get
{
var created = Created;
var updated = Updated;
return created > updated ? created : updated;
}
}
/// <summary>
/// True if this item is only visible by friends of the creator
/// The item's visibility, i.e. public, friends-only, unlisted or private
/// </summary>
public bool IsFriendsOnly => details.Visibility == RemoteStoragePublishedFileVisibility.FriendsOnly;
/// <summary>
/// True if this is only visible to the creator
/// </summary>
public bool IsPrivate => details.Visibility == RemoteStoragePublishedFileVisibility.Private;
public Visibility Visibility => (Visibility)details.Visibility;
/// <summary>
/// True if this item has been banned
@@ -122,22 +130,11 @@ namespace Steamworks.Ugc
ulong size = 0;
uint ts = 0;
if ( !SteamUGC.Internal.GetItemInstallInfo( Id, ref size, out var strVal, ref ts ) )
return null;
return strVal;
if (SteamUGC.Internal.GetItemInstallInfo(Id, ref size, out var strVal, ref ts)) { return strVal; }
return null;
}
}
/// <summary>
/// Start downloading this item.
/// If this returns false the item isn't getting downloaded.
/// </summary>
public bool Download( Action onInstalled = null, bool highPriority = false )
{
return SteamUGC.Download( Id, onInstalled, highPriority );
}
/// <summary>
/// If we're downloading, how big the total download is
/// </summary>
@@ -146,7 +143,7 @@ namespace Steamworks.Ugc
get
{
if ( !NeedsUpdate )
return SizeBytes;
return InstalledSize;
ulong downloaded = 0;
ulong total = 0;
@@ -165,7 +162,7 @@ namespace Steamworks.Ugc
get
{
if ( !NeedsUpdate )
return SizeBytes;
return InstalledSize;
ulong downloaded = 0;
ulong total = 0;
@@ -179,7 +176,7 @@ namespace Steamworks.Ugc
/// <summary>
/// If we're installed, how big is the install
/// </summary>
public long SizeBytes
public long InstalledSize
{
get
{
@@ -195,6 +192,13 @@ namespace Steamworks.Ugc
}
}
/// <summary>
/// File size as returned by Steamworks,
/// no download/install required
/// </summary>
public long SizeOfFileInBytes
=> details.FileSize;
/// <summary>
/// If we're downloading our current progress as a delta betwen 0-1
/// </summary>
@@ -204,17 +208,19 @@ namespace Steamworks.Ugc
{
//changed from NeedsUpdate as it's false when validating and redownloading ugc
//possibly similar properties should also be changed
if ( !IsDownloading ) return 1;
ulong downloaded = 0;
ulong total = 0;
if ( SteamUGC.Internal.GetItemDownloadInfo( Id, ref downloaded, ref total ) && total > 0 )
if (SteamUGC.Internal.GetItemDownloadInfo(Id, ref downloaded, ref total) && total > 0)
{
return (float)((double)downloaded / (double)total);
}
if ( NeedsUpdate || !IsInstalled || IsDownloading )
if (NeedsUpdate || !IsInstalled || IsDownloading)
{
return 0;
}
return 1;
return IsDownloadPending || IsDownloading ? 0 : 1;
}
}

View File

@@ -15,7 +15,6 @@ namespace Steamworks.Ugc
AppId consumerApp;
AppId creatorApp;
string searchText;
bool returnLongDescription;
public Query( UgcType type ) : this()
{
@@ -106,18 +105,6 @@ namespace Steamworks.Ugc
}
#endregion
public Query WithLongDescription()
{
returnLongDescription = true;
return this;
}
public Query WithSummaryDescription()
{
returnLongDescription = false;
return this;
}
public async Task<ResultPage?> GetPageAsync( int page )
{
if ( page <= 0 ) throw new System.Exception( "page should be > 0" );
@@ -255,8 +242,6 @@ namespace Steamworks.Ugc
{
SteamUGC.Internal.SetSearchText( handle, searchText );
}
SteamUGC.Internal.SetReturnLongDescription( handle, returnLongDescription );
}
#endregion

View File

@@ -2,6 +2,8 @@ using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Threading;
using System.Collections.Concurrent;
namespace Steamworks
{
@@ -9,33 +11,40 @@ namespace Steamworks
{
public const int MemoryBufferSize = 1024 * 32;
private static IntPtr[] MemoryPool = new IntPtr[]
{
Marshal.AllocHGlobal( MemoryBufferSize ),
Marshal.AllocHGlobal( MemoryBufferSize ),
Marshal.AllocHGlobal( MemoryBufferSize ),
Marshal.AllocHGlobal( MemoryBufferSize )
};
internal struct Memory : IDisposable
{
private const int MaxBagSize = 4;
private static readonly ConcurrentBag<IntPtr> BufferBag = new ConcurrentBag<IntPtr>();
private static int MemoryPoolIndex;
public IntPtr Ptr { get; private set; }
public static unsafe IntPtr TakeMemory()
{
lock ( MemoryPool )
public static implicit operator IntPtr(in Memory m) => m.Ptr;
internal unsafe Memory(int sz)
{
MemoryPoolIndex++;
if ( MemoryPoolIndex >= MemoryPool.Length )
MemoryPoolIndex = 0;
var take = MemoryPool[MemoryPoolIndex];
((byte*)take)[0] = 0;
return take;
Ptr = BufferBag.TryTake(out IntPtr ptr) ? ptr : Marshal.AllocHGlobal(sz);
((byte*)Ptr)[0] = 0;
}
}
public void Dispose()
{
if (Ptr == IntPtr.Zero) { return; }
if (BufferBag.Count < MaxBagSize)
{
BufferBag.Add(Ptr);
}
else
{
Marshal.FreeHGlobal(Ptr);
}
Ptr = IntPtr.Zero;
}
}
public static Memory TakeMemory()
{
return new Memory(MemoryBufferSize);
}
private static byte[][] BufferPool = new byte[4][];
private static int BufferPoolIndex;

View File

@@ -2,34 +2,34 @@
// /*
// Microsoft Public License (Ms-PL)
// MonoGame - Copyright © 2009 The MonoGame Team
//
//
// All rights reserved.
//
//
// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
// accept the license, do not use the software.
//
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
// U.S. copyright law.
//
//
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
//
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
// your patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
@@ -56,7 +56,7 @@ namespace Microsoft.Xna.Framework.Graphics
internal GraphicsResource()
{
}
~GraphicsResource()
@@ -66,7 +66,7 @@ namespace Microsoft.Xna.Framework.Graphics
}
/// <summary>
/// Called before the device is reset. Allows graphics resources to
/// Called before the device is reset. Allows graphics resources to
/// invalidate their state so they can be recreated after the device reset.
/// Warning: This may be called after a call to Dispose() up until
/// the resource is garbage collected.
@@ -117,7 +117,7 @@ namespace Microsoft.Xna.Framework.Graphics
}
public event EventHandler<EventArgs> Disposing;
public GraphicsDevice GraphicsDevice
{
get
@@ -146,7 +146,7 @@ namespace Microsoft.Xna.Framework.Graphics
graphicsDevice.AddResourceReference(_selfReference);
}
}
public bool IsDisposed
{
get
@@ -154,9 +154,9 @@ namespace Microsoft.Xna.Framework.Graphics
return disposed;
}
}
public string Name { get; set; }
public Object Tag { get; set; }
public override string ToString()

View File

@@ -237,9 +237,17 @@ namespace Microsoft.Xna.Framework.Graphics
void CheckValid(Texture2D texture)
{
if (texture == null)
{
throw new ArgumentNullException("texture");
}
if (texture.IsDisposed)
{
throw new InvalidOperationException($"Texture is disposed");
}
if (!_beginCalled)
{
throw new InvalidOperationException("Draw was called, but Begin has not yet been called. Begin must be called successfully before you can call Draw.");
}
}
void CheckValid(SpriteFont spriteFont, string text)
@@ -315,7 +323,7 @@ namespace Microsoft.Xna.Framework.Graphics
}
}
public void Draw(Texture2D texture, VertexPositionColorTexture[] vertices, float layerDepth)
public void Draw(Texture2D texture, VertexPositionColorTexture[] vertices, float layerDepth, int? count = null)
{
CheckValid(texture);
@@ -338,7 +346,7 @@ namespace Microsoft.Xna.Framework.Graphics
break;
}
int iters = vertices.Length / 4;
int iters = count ?? (vertices.Length / 4);
for (int i=0;i<iters;i++)
{
var item = _batcher.CreateBatchItem();

View File

@@ -19,7 +19,7 @@ namespace Microsoft.Xna.Framework.Graphics
_graphicsDevice = graphicsDevice;
_textures = new Texture[maxTextures];
_applyToVertexStage = applyToVertexStage;
for (int i=0;i<maxTextures;i++)
for (int i = 0; i < maxTextures; i++)
{
_dirtyMax |= 1 << i;
}

View File

@@ -2,6 +2,7 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Collections.Generic;
namespace Microsoft.Xna.Framework.Input
@@ -22,5 +23,42 @@ namespace Microsoft.Xna.Framework.Input
{
_keys = keys;
}
public static Keys QwertyToCurrentLayout(Keys qwertyKey)
{
#warning TODO: test Dvorak & other layouts that I'm unaware of that replace letter keys with non-letter keys or vice versa
int scancode = qwertyKey switch
{
Keys.A => 4,
Keys.B => 5,
Keys.C => 6,
Keys.D => 7,
Keys.E => 8,
Keys.F => 9,
Keys.G => 10,
Keys.H => 11,
Keys.I => 12,
Keys.J => 13,
Keys.K => 14,
Keys.L => 15,
Keys.M => 16,
Keys.N => 17,
Keys.O => 18,
Keys.P => 19,
Keys.Q => 20,
Keys.R => 21,
Keys.S => 22,
Keys.T => 23,
Keys.U => 24,
Keys.V => 25,
Keys.W => 26,
Keys.X => 27,
Keys.Y => 28,
Keys.Z => 29,
_ => -1
};
if (scancode < 0) { return qwertyKey; }
return KeyboardUtil.ToXna(Sdl.Keyboard.GetKeyFromScancode(scancode));
}
}
}

View File

@@ -837,6 +837,10 @@ internal static class Sdl
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate Keymod d_sdl_getmodstate();
public static d_sdl_getmodstate GetModState = FuncLoader.LoadFunction<d_sdl_getmodstate>(NativeLibrary, "SDL_GetModState");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int d_sdl_getkeyfromscancode(int scancode);
public static d_sdl_getkeyfromscancode GetKeyFromScancode = FuncLoader.LoadFunction<d_sdl_getkeyfromscancode>(NativeLibrary, "SDL_GetKeyFromScancode");
}
public static class Joystick

View File

@@ -153,6 +153,7 @@ namespace Microsoft.Xna.Framework
return !a.Equals(b);
}
public static implicit operator Point((int X, int Y) tuple) => new Point(tuple.X, tuple.Y);
#endregion
#region Public methods

View File

@@ -247,6 +247,7 @@ namespace Microsoft.Xna.Framework
return value1.X != value2.X || value1.Y != value2.Y;
}
public static implicit operator Vector2((float X, float Y) tuple) => new Vector2(tuple.X, tuple.Y);
#endregion
#region Public Methods

View File

@@ -1368,6 +1368,7 @@ namespace Microsoft.Xna.Framework
return value1;
}
public static implicit operator Vector3((float X, float Y, float Z) tuple) => new Vector3(tuple.X, tuple.Y, tuple.Z);
#endregion
}
}

View File

@@ -1292,6 +1292,7 @@ namespace Microsoft.Xna.Framework
return value1;
}
public static implicit operator Vector4((float X, float Y, float Z, float W) tuple) => new Vector4(tuple.X, tuple.Y, tuple.Z, tuple.W);
#endregion
}
}

View File

@@ -1,4 +1,4 @@
Copyright (c) 2019 FakeFish Games
Copyright (c) 2019 FakeFish Ltd.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions