Merge remote-tracking branch 'upstream/master' into develop

This commit is contained in:
EvilFactory
2024-10-22 12:42:35 -03:00
417 changed files with 17171 additions and 5895 deletions

View File

@@ -7,8 +7,13 @@ namespace Barotrauma.Extensions
public static Color Multiply(this Color color, float value, bool onlyAlpha = false)
{
return onlyAlpha ?
new Color(color.R, color.G, color.B, (byte)(color.A * value)) :
new Color((byte)(color.R * value), (byte)(color.G * value), (byte)(color.B * value), (byte)(color.A * value));
new Color(color.R, color.G, color.B, MultiplyComponent(color.A, value)) :
new Color(MultiplyComponent(color.R, value), MultiplyComponent(color.G, value), MultiplyComponent(color.B, value), MultiplyComponent(color.A, value));
static byte MultiplyComponent(float colorComponent, float multiplier)
{
return (byte)MathHelper.Clamp(colorComponent * multiplier, 0.0f, 255.0f);
}
}
public static Color Multiply(this Color thisColor, Color color)

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Barotrauma.Extensions
{
@@ -36,5 +37,13 @@ namespace Barotrauma.Extensions
int flagValue = Convert.ToInt32(flag);
return (T)(object)(enumValue & ~flagValue);
}
public static IEnumerable<T> GetIndividualFlags<T>(T flagsEnum) where T : Enum
{
foreach (T value in Enum.GetValues(typeof(T)))
{
if (flagsEnum.HasFlag(value)) { yield return value; }
}
}
}
}

View File

@@ -24,6 +24,9 @@ public sealed class EpicAccountId : AccountId
public new static Option<EpicAccountId> Parse(string str)
{
if (str.IsNullOrWhiteSpace()) { return Option.None; }
//according to the documentation, this is the maximum length of the ID
const int MaxEpicAccountIDLength = 32 + 1;
if (str.Length > MaxEpicAccountIDLength + prefix.Length) { return Option.None; }
if (str.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { str = str[prefix.Length..]; }
if (!str.IsHexString()) { return Option.None; }

View File

@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -144,7 +145,25 @@ namespace Barotrauma
}
public static Identifier[] ToIdentifiers(this string[] strings)
=> ((IEnumerable<string>)strings).ToIdentifiers().ToArray();
=> strings.AsEnumerable().ToIdentifiers().ToArray();
/// <summary>
/// Parses identifiers from a comma separated string.
/// </summary>
public static IEnumerable<Identifier> ToIdentifiers(this string tagsString, string separator = ",")
{
if (string.IsNullOrWhiteSpace(tagsString))
{
return Enumerable.Empty<Identifier>();
}
return tagsString.Split(separator, StringSplitOptions.TrimEntries).AsEnumerable().ToIdentifiers();
}
/// <summary>
/// Parses a comma separated string from a collection of identifier.
/// </summary>
public static string ConvertToString(this IEnumerable<Identifier> tags, string separator = ",")
=> string.Join(separator, tags);
public static Identifier ToIdentifier(this string? s)
{

View File

@@ -210,7 +210,7 @@ namespace Steamworks.Data
internal static extern bool InternalIsIPv6AllZeros( ref NetAddress self );
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_SteamNetworkingIPAddr_SetIPv6", CallingConvention = Platform.CC)]
internal static extern void InternalSetIPv6( ref NetAddress self, ref byte ipv6, ushort nPort );
internal static extern void InternalSetIPv6( ref NetAddress self, IntPtr ipv6, ushort nPort );
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_SteamNetworkingIPAddr_SetIPv4", CallingConvention = Platform.CC)]
internal static extern void InternalSetIPv4( ref NetAddress self, uint nIP, ushort nPort );

View File

@@ -60,18 +60,33 @@ namespace Steamworks.Data
/// Specific IP, specific port
/// </summary>
public static NetAddress From( IPAddress address, ushort port )
{
var addr = address.GetAddressBytes();
{
var local = Cleared;
switch (address.AddressFamily)
{
case System.Net.Sockets.AddressFamily.InterNetwork:
InternalSetIPv4(ref local, address.IpToInt32(), port);
return local;
case System.Net.Sockets.AddressFamily.InterNetworkV6:
var ptr = GetIpv6AddressBytesPtr(address);
InternalSetIPv6(ref local, ptr, port);
FreeMemory(ptr);
return local;
default:
throw new System.NotImplementedException( $"Oops - no {address.AddressFamily} support yet?" );
}
if ( address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork )
{
var local = Cleared;
InternalSetIPv4( ref local, Utility.IpToInt32( address ), port );
return local;
}
static System.IntPtr GetIpv6AddressBytesPtr(IPAddress address)
{
byte[] bytes = address.GetAddressBytes();
var unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
return unmanagedPointer;
}
throw new System.NotImplementedException( "Oops - no IPV6 support yet?" );
}
void FreeMemory(System.IntPtr unmanagedMemory)
=> Marshal.FreeHGlobal(unmanagedMemory);
}
/// <summary>
/// Set everything to zero