Release v0.15.12.0
This commit is contained in:
@@ -5,6 +5,7 @@ using Barotrauma.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -138,6 +139,26 @@ namespace Barotrauma.Networking
|
||||
byte[] bytes = BitConverter.GetBytes(val);
|
||||
WriteBytes(ref buf, ref bitPos, bytes, 0, 8);
|
||||
}
|
||||
|
||||
internal static void WriteColorR8G8B8(ref byte[] buf, ref int bitPos, Microsoft.Xna.Framework.Color val)
|
||||
{
|
||||
EnsureBufferSize(ref buf, bitPos + 24);
|
||||
|
||||
Write(ref buf, ref bitPos, val.R);
|
||||
Write(ref buf, ref bitPos, val.G);
|
||||
Write(ref buf, ref bitPos, val.B);
|
||||
}
|
||||
|
||||
internal static void WriteColorR8G8B8A8(ref byte[] buf, ref int bitPos, Microsoft.Xna.Framework.Color val)
|
||||
{
|
||||
EnsureBufferSize(ref buf, bitPos + 32);
|
||||
|
||||
Write(ref buf, ref bitPos, val.R);
|
||||
Write(ref buf, ref bitPos, val.G);
|
||||
Write(ref buf, ref bitPos, val.B);
|
||||
Write(ref buf, ref bitPos, val.A);
|
||||
}
|
||||
|
||||
internal static void Write(ref byte[] buf, ref int bitPos, string val)
|
||||
{
|
||||
if (string.IsNullOrEmpty(val))
|
||||
@@ -217,7 +238,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
byte retval = NetBitWriter.ReadByte(buf, 1, bitPos);
|
||||
bitPos++;
|
||||
return (retval > 0 ? true : false);
|
||||
return retval > 0;
|
||||
}
|
||||
|
||||
internal static void ReadPadBits(byte[] buf, ref int bitPos)
|
||||
@@ -299,6 +320,23 @@ namespace Barotrauma.Networking
|
||||
return BitConverter.ToDouble(bytes, 0);
|
||||
}
|
||||
|
||||
internal static Microsoft.Xna.Framework.Color ReadColorR8G8B8(byte[] buf, ref int bitPos)
|
||||
{
|
||||
byte r = ReadByte(buf, ref bitPos);
|
||||
byte g = ReadByte(buf, ref bitPos);
|
||||
byte b = ReadByte(buf, ref bitPos);
|
||||
return new Color(r, g, b, (byte)255);
|
||||
}
|
||||
|
||||
internal static Microsoft.Xna.Framework.Color ReadColorR8G8B8A8(byte[] buf, ref int bitPos)
|
||||
{
|
||||
byte r = ReadByte(buf, ref bitPos);
|
||||
byte g = ReadByte(buf, ref bitPos);
|
||||
byte b = ReadByte(buf, ref bitPos);
|
||||
byte a = ReadByte(buf, ref bitPos);
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
|
||||
internal static UInt32 ReadVariableUInt32(byte[] buf, ref int bitPos)
|
||||
{
|
||||
int bitLength = buf.Length * 8;
|
||||
@@ -482,6 +520,16 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void WriteColorR8G8B8(Color val)
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void WriteColorR8G8B8A8(Color val)
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8A8(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void WriteVariableUInt32(UInt32 val)
|
||||
{
|
||||
MsgWriter.WriteVariableUInt32(ref buf, ref seekPos, val);
|
||||
@@ -624,14 +672,28 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
buf = new byte[decompressedData.Length];
|
||||
Array.Copy(decompressedData, 0, buf, 0, decompressedData.Length);
|
||||
try
|
||||
{
|
||||
Array.Copy(decompressedData, 0, buf, 0, decompressedData.Length);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
throw new ArgumentException($"Failed to copy the incoming compressed buffer. Source buffer length: {decompressedData.Length}, start position: {0}, length: {decompressedData.Length}, destination buffer length: {buf.Length}.", e);
|
||||
}
|
||||
lengthBits = decompressedData.Length * 8;
|
||||
DebugConsole.Log("Decompressing message: " + inLength + " to " + LengthBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = new byte[inBuf.Length];
|
||||
Array.Copy(inBuf, startPos, buf, 0, inLength);
|
||||
try
|
||||
{
|
||||
Array.Copy(inBuf, startPos, buf, 0, inLength);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
throw new ArgumentException($"Failed to copy the incoming uncompressed buffer. Source buffer length: {inBuf.Length}, start position: {startPos}, length: {inLength}, destination buffer length: {buf.Length}.", e);
|
||||
}
|
||||
lengthBits = inLength * 8;
|
||||
}
|
||||
seekPos = 0;
|
||||
@@ -702,6 +764,17 @@ namespace Barotrauma.Networking
|
||||
return MsgReader.ReadString(buf, ref seekPos);
|
||||
}
|
||||
|
||||
public Color ReadColorR8G8B8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8(buf, ref seekPos);
|
||||
}
|
||||
|
||||
public Color ReadColorR8G8B8A8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8A8(buf, ref seekPos);
|
||||
}
|
||||
|
||||
|
||||
public int ReadRangedInteger(int min, int max)
|
||||
{
|
||||
return MsgReader.ReadRangedInteger(buf, ref seekPos, min, max);
|
||||
@@ -845,6 +918,16 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void WriteColorR8G8B8(Color val)
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void WriteColorR8G8B8A8(Color val)
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8A8(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void WriteVariableUInt32(UInt32 val)
|
||||
{
|
||||
MsgWriter.WriteVariableUInt32(ref buf, ref seekPos, val);
|
||||
@@ -936,6 +1019,16 @@ namespace Barotrauma.Networking
|
||||
return MsgReader.ReadString(buf, ref seekPos);
|
||||
}
|
||||
|
||||
public Color ReadColorR8G8B8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8(buf, ref seekPos);
|
||||
}
|
||||
|
||||
public Color ReadColorR8G8B8A8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8A8(buf, ref seekPos);
|
||||
}
|
||||
|
||||
public int ReadRangedInteger(int min, int max)
|
||||
{
|
||||
return MsgReader.ReadRangedInteger(buf, ref seekPos, min, max);
|
||||
|
||||
Reference in New Issue
Block a user