diff --git a/Facepunch.Steamworks/Utility/Utf8String.cs b/Facepunch.Steamworks/Utility/Utf8String.cs index 3599753..74b101e 100644 --- a/Facepunch.Steamworks/Utility/Utf8String.cs +++ b/Facepunch.Steamworks/Utility/Utf8String.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; using System.Runtime.InteropServices; using System.Text; @@ -10,6 +6,8 @@ namespace Steamworks { internal unsafe class Utf8StringToNative : ICustomMarshaler { + internal static readonly Encoding Utf8NoBom = new UTF8Encoding( false, false ); + public IntPtr MarshalManagedToNative(object managedObj) { if ( managedObj == null ) @@ -19,10 +17,10 @@ namespace Steamworks { fixed ( char* strPtr = str ) { - int len = Encoding.UTF8.GetByteCount( str ); + int len = Utf8NoBom.GetByteCount( str ); var mem = Marshal.AllocHGlobal( len + 1 ); - var wlen = System.Text.Encoding.UTF8.GetBytes( strPtr, str.Length, (byte*)mem, len + 1 ); + var wlen = Utf8NoBom.GetBytes( strPtr, str.Length, (byte*)mem, len + 1 ); ( (byte*)mem )[wlen] = 0; @@ -64,7 +62,7 @@ namespace Steamworks dataLen++; } - return Encoding.UTF8.GetString( bytes, dataLen ); + return Utf8StringToNative.Utf8NoBom.GetString( bytes, dataLen ); } } }