Unstable v0.19.3.0
This commit is contained in:
+159
-234
@@ -1,7 +1,6 @@
|
||||
using Lidgren.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Barotrauma.IO;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -58,7 +57,7 @@ namespace Barotrauma.Networking
|
||||
bool testVal = MsgReader.ReadBoolean(buf, ref resetPos);
|
||||
if (testVal != val || resetPos != bitPos)
|
||||
{
|
||||
DebugConsole.ThrowError("Boolean written incorrectly! " + testVal + ", " + val + "; " + resetPos + ", " + bitPos);
|
||||
DebugConsole.ThrowError($"Boolean written incorrectly! {testVal}, {val}; {resetPos}, {bitPos}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -125,7 +124,7 @@ namespace Barotrauma.Networking
|
||||
SingleUIntUnion su;
|
||||
su.UIntValue = 0; // must initialize every member of the union to avoid warning
|
||||
su.SingleValue = val;
|
||||
|
||||
|
||||
EnsureBufferSize(ref buf, bitPos + 32);
|
||||
|
||||
NetBitWriter.WriteUInt32(su.UIntValue, 32, buf, bitPos);
|
||||
@@ -140,50 +139,48 @@ namespace Barotrauma.Networking
|
||||
WriteBytes(ref buf, ref bitPos, bytes, 0, 8);
|
||||
}
|
||||
|
||||
internal static void WriteColorR8G8B8(ref byte[] buf, ref int bitPos, Microsoft.Xna.Framework.Color val)
|
||||
internal static void WriteColorR8G8B8(ref byte[] buf, ref int bitPos, 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)
|
||||
|
||||
internal static void WriteColorR8G8B8A8(ref byte[] buf, ref int bitPos, 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))
|
||||
{
|
||||
WriteVariableUInt32(ref buf, ref bitPos, (uint)0);
|
||||
WriteVariableUInt32(ref buf, ref bitPos, 0u);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(val);
|
||||
WriteVariableUInt32(ref buf, ref bitPos, (uint)bytes.Length);
|
||||
WriteBytes(ref buf, ref bitPos, bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
internal static int WriteVariableUInt32(ref byte[] buf, ref int bitPos, uint value)
|
||||
internal static void WriteVariableUInt32(ref byte[] buf, ref int bitPos, uint value)
|
||||
{
|
||||
int retval = 1;
|
||||
uint remainingValue = (uint)value;
|
||||
uint remainingValue = value;
|
||||
while (remainingValue >= 0x80)
|
||||
{
|
||||
Write(ref buf, ref bitPos, (byte)(remainingValue | 0x80));
|
||||
remainingValue = remainingValue >> 7;
|
||||
retval++;
|
||||
remainingValue >>= 7;
|
||||
}
|
||||
|
||||
Write(ref buf, ref bitPos, (byte)remainingValue);
|
||||
return retval;
|
||||
}
|
||||
|
||||
internal static void WriteRangedInteger(ref byte[] buf, ref int bitPos, int val, int min, int max)
|
||||
@@ -206,7 +203,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
EnsureBufferSize(ref buf, bitPos + numberOfBits);
|
||||
|
||||
NetBitWriter.WriteUInt32((UInt32)((float)maxVal * unit), numberOfBits, buf, bitPos);
|
||||
NetBitWriter.WriteUInt32((UInt32)(maxVal * unit), numberOfBits, buf, bitPos);
|
||||
bitPos += numberOfBits;
|
||||
}
|
||||
|
||||
@@ -225,9 +222,10 @@ namespace Barotrauma.Networking
|
||||
buf = new byte[byteLen + MsgConstants.BufferOverAllocateAmount];
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf.Length < byteLen)
|
||||
{
|
||||
Array.Resize<byte>(ref buf, byteLen + MsgConstants.BufferOverAllocateAmount);
|
||||
Array.Resize(ref buf, byteLen + MsgConstants.BufferOverAllocateAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,7 +239,7 @@ namespace Barotrauma.Networking
|
||||
return retval > 0;
|
||||
}
|
||||
|
||||
internal static void ReadPadBits(byte[] buf, ref int bitPos)
|
||||
internal static void ReadPadBits(ref int bitPos)
|
||||
{
|
||||
int bitOffset = bitPos % 8;
|
||||
bitPos += (8 - bitOffset) % 8;
|
||||
@@ -326,15 +324,15 @@ namespace Barotrauma.Networking
|
||||
return BitConverter.ToDouble(bytes, 0);
|
||||
}
|
||||
|
||||
internal static Microsoft.Xna.Framework.Color ReadColorR8G8B8(byte[] buf, ref int bitPos)
|
||||
internal static 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)
|
||||
|
||||
internal static Color ReadColorR8G8B8A8(byte[] buf, ref int bitPos)
|
||||
{
|
||||
byte r = ReadByte(buf, ref bitPos);
|
||||
byte g = ReadByte(buf, ref bitPos);
|
||||
@@ -354,8 +352,7 @@ namespace Barotrauma.Networking
|
||||
byte chunk = ReadByte(buf, ref bitPos);
|
||||
result |= (chunk & 0x7f) << shift;
|
||||
shift += 7;
|
||||
if ((chunk & 0x80) == 0)
|
||||
return (uint)result;
|
||||
if ((chunk & 0x80) == 0) { return (uint)result; }
|
||||
}
|
||||
|
||||
// ouch; failed to find enough bytes; malformed variable length number?
|
||||
@@ -378,23 +375,23 @@ namespace Barotrauma.Networking
|
||||
if ((bitPos & 7) == 0)
|
||||
{
|
||||
// read directly
|
||||
string retval = System.Text.Encoding.UTF8.GetString(buf, bitPos >> 3, byteLen);
|
||||
string retval = Encoding.UTF8.GetString(buf, bitPos >> 3, byteLen);
|
||||
bitPos += (8 * byteLen);
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = ReadBytes(buf, ref bitPos, byteLen);
|
||||
return System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
internal static int ReadRangedInteger(byte[] buf, ref int bitPos, int min, int max)
|
||||
{
|
||||
uint range = (uint)(max - min);
|
||||
int numBits = NetUtility.BitsToHoldUInt(range);
|
||||
uint range = (uint)(max - min);
|
||||
int numBits = NetUtility.BitsToHoldUInt(range);
|
||||
|
||||
uint rvalue = NetBitWriter.ReadUInt32(buf, numBits, bitPos);
|
||||
uint rvalue = NetBitWriter.ReadUInt32(buf, numBits, bitPos);
|
||||
bitPos += numBits;
|
||||
|
||||
|
||||
return (int)(min + rvalue);
|
||||
}
|
||||
|
||||
@@ -403,51 +400,33 @@ namespace Barotrauma.Networking
|
||||
int maxInt = (1 << bitCount) - 1;
|
||||
int intVal = ReadRangedInteger(buf, ref bitPos, 0, maxInt);
|
||||
Single range = max - min;
|
||||
return min + (range * ((Single)intVal) / ((Single)maxInt));
|
||||
return min + range * intVal / maxInt;
|
||||
}
|
||||
|
||||
internal static byte[] ReadBytes(byte[] buf, ref int bitPos, int numberOfBytes)
|
||||
{
|
||||
byte[] retval = new byte[numberOfBytes];
|
||||
NetBitWriter.ReadBytes(buf, numberOfBytes, bitPos, retval, 0);
|
||||
bitPos += (8 * numberOfBytes);
|
||||
bitPos += 8 * numberOfBytes;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
class WriteOnlyMessage : IWriteMessage
|
||||
internal sealed class WriteOnlyMessage : IWriteMessage
|
||||
{
|
||||
private byte[] buf = new byte[MsgConstants.InitialBufferSize];
|
||||
private int seekPos = 0;
|
||||
private int lengthBits = 0;
|
||||
private int seekPos;
|
||||
private int lengthBits;
|
||||
|
||||
public int BitPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return seekPos;
|
||||
}
|
||||
set
|
||||
{
|
||||
seekPos = value;
|
||||
}
|
||||
get => seekPos;
|
||||
set => seekPos = value;
|
||||
}
|
||||
|
||||
public int BytePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return seekPos / 8;
|
||||
}
|
||||
}
|
||||
public int BytePosition => seekPos / 8;
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
public byte[] Buffer => buf;
|
||||
|
||||
public int LengthBits
|
||||
{
|
||||
@@ -464,15 +443,9 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public int LengthBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
return (LengthBits + 7) / 8;
|
||||
}
|
||||
}
|
||||
public int LengthBytes => (LengthBits + 7) / 8;
|
||||
|
||||
public void Write(bool val)
|
||||
public void WriteBoolean(bool val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
@@ -482,47 +455,47 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.WritePadBits(ref buf, ref seekPos);
|
||||
}
|
||||
|
||||
public void Write(byte val)
|
||||
public void WriteByte(byte val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(UInt16 val)
|
||||
public void WriteUInt16(UInt16 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Int16 val)
|
||||
public void WriteInt16(Int16 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(UInt32 val)
|
||||
public void WriteUInt32(UInt32 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Int32 val)
|
||||
public void WriteInt32(Int32 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(UInt64 val)
|
||||
public void WriteUInt64(UInt64 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Int64 val)
|
||||
public void WriteInt64(Int64 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Single val)
|
||||
public void WriteSingle(Single val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Double val)
|
||||
public void WriteDouble(Double val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
@@ -531,7 +504,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
|
||||
public void WriteColorR8G8B8A8(Color val)
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8A8(ref buf, ref seekPos, val);
|
||||
@@ -542,14 +515,14 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.WriteVariableUInt32(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(String val)
|
||||
public void WriteString(String val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Identifier val)
|
||||
public void WriteIdentifier(Identifier val)
|
||||
{
|
||||
Write(val.Value);
|
||||
WriteString(val.Value);
|
||||
}
|
||||
|
||||
public void WriteRangedInteger(int val, int min, int max)
|
||||
@@ -562,85 +535,67 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.WriteRangedSingle(ref buf, ref seekPos, val, min, max, bitCount);
|
||||
}
|
||||
|
||||
public void Write(byte[] val, int startPos, int length)
|
||||
public void WriteBytes(byte[] val, int startPos, int length)
|
||||
{
|
||||
MsgWriter.WriteBytes(ref buf, ref seekPos, val, startPos, length);
|
||||
}
|
||||
|
||||
public void PrepareForSending(ref byte[] outBuf, bool compressPastThreshold, out bool isCompressed, out int length)
|
||||
|
||||
public byte[] PrepareForSending(bool compressPastThreshold, out bool isCompressed, out int length)
|
||||
{
|
||||
byte[] outBuf;
|
||||
if (LengthBytes <= MsgConstants.CompressionThreshold || !compressPastThreshold)
|
||||
{
|
||||
isCompressed = false;
|
||||
if (LengthBytes > outBuf.Length) { Array.Resize(ref outBuf, LengthBytes); }
|
||||
outBuf = new byte[LengthBytes];
|
||||
Array.Copy(buf, outBuf, LengthBytes);
|
||||
length = LengthBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
using (System.IO.MemoryStream output = new System.IO.MemoryStream())
|
||||
using MemoryStream output = new MemoryStream();
|
||||
|
||||
using (DeflateStream dstream = new DeflateStream(output, CompressionLevel.Fastest))
|
||||
{
|
||||
using (DeflateStream dstream = new DeflateStream(output, CompressionLevel.Fastest))
|
||||
{
|
||||
dstream.Write(buf, 0, LengthBytes);
|
||||
}
|
||||
|
||||
byte[] compressedBuf = output.ToArray();
|
||||
//don't send the data as compressed if the data takes up more space after compression
|
||||
//(which may happen when sending a sub/save file that's already been compressed with a better compression ratio)
|
||||
if (compressedBuf.Length >= outBuf.Length)
|
||||
{
|
||||
isCompressed = false;
|
||||
if (LengthBytes > outBuf.Length) { Array.Resize(ref outBuf, LengthBytes); }
|
||||
Array.Copy(buf, outBuf, LengthBytes);
|
||||
length = LengthBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
isCompressed = true;
|
||||
if (compressedBuf.Length > outBuf.Length) { Array.Resize(ref outBuf, compressedBuf.Length); }
|
||||
Array.Copy(compressedBuf, outBuf, compressedBuf.Length);
|
||||
length = compressedBuf.Length;
|
||||
DebugConsole.Log("Compressed message: " + LengthBytes + " to " + length);
|
||||
}
|
||||
dstream.Write(buf, 0, LengthBytes);
|
||||
}
|
||||
|
||||
byte[] compressedBuf = output.ToArray();
|
||||
//don't send the data as compressed if the data takes up more space after compression
|
||||
//(which may happen when sending a sub/save file that's already been compressed with a better compression ratio)
|
||||
if (compressedBuf.Length >= LengthBytes)
|
||||
{
|
||||
isCompressed = false;
|
||||
outBuf = new byte[LengthBytes];
|
||||
Array.Copy(buf, outBuf, LengthBytes);
|
||||
length = LengthBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
isCompressed = true;
|
||||
outBuf = compressedBuf;
|
||||
length = outBuf.Length;
|
||||
DebugConsole.Log($"Compressed message: {LengthBytes} to {length}");
|
||||
}
|
||||
}
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
}
|
||||
|
||||
class ReadOnlyMessage : IReadMessage
|
||||
internal sealed class ReadOnlyMessage : IReadMessage
|
||||
{
|
||||
private readonly byte[] buf;
|
||||
private int seekPos = 0;
|
||||
private int lengthBits = 0;
|
||||
private int seekPos;
|
||||
private int lengthBits;
|
||||
|
||||
public int BitPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return seekPos;
|
||||
}
|
||||
set
|
||||
{
|
||||
seekPos = value;
|
||||
}
|
||||
get => seekPos;
|
||||
set => seekPos = value;
|
||||
}
|
||||
|
||||
public int BytePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return seekPos / 8;
|
||||
}
|
||||
}
|
||||
public int BytePosition => seekPos / 8;
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
public byte[] Buffer { get; }
|
||||
|
||||
public int LengthBits
|
||||
{
|
||||
@@ -656,129 +611,126 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public int LengthBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
return (LengthBits + 7) / 8;
|
||||
}
|
||||
}
|
||||
public int LengthBytes => (LengthBits + 7) / 8;
|
||||
|
||||
public NetworkConnection Sender { get; private set; }
|
||||
|
||||
public ReadOnlyMessage(byte[] inBuf, bool isCompressed, int startPos, int inLength, NetworkConnection sender)
|
||||
public NetworkConnection Sender { get; }
|
||||
|
||||
public ReadOnlyMessage(byte[] inBuf, bool isCompressed, int startPos, int byteLength, NetworkConnection sender)
|
||||
{
|
||||
Sender = sender;
|
||||
if (isCompressed)
|
||||
{
|
||||
byte[] decompressedData;
|
||||
using (System.IO.MemoryStream input = new System.IO.MemoryStream(inBuf, startPos, inLength))
|
||||
using (MemoryStream input = new MemoryStream(inBuf, startPos, byteLength))
|
||||
{
|
||||
using (System.IO.MemoryStream output = new System.IO.MemoryStream())
|
||||
using (MemoryStream output = new MemoryStream())
|
||||
{
|
||||
using (DeflateStream dstream = new DeflateStream(input, CompressionMode.Decompress))
|
||||
{
|
||||
dstream.CopyTo(output);
|
||||
}
|
||||
|
||||
decompressedData = output.ToArray();
|
||||
}
|
||||
}
|
||||
buf = new byte[decompressedData.Length];
|
||||
|
||||
Buffer = new byte[decompressedData.Length];
|
||||
try
|
||||
{
|
||||
Array.Copy(decompressedData, 0, buf, 0, decompressedData.Length);
|
||||
Array.Copy(decompressedData, 0, Buffer, 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);
|
||||
throw new ArgumentException(
|
||||
$"Failed to copy the incoming compressed buffer. Source buffer length: {decompressedData.Length}, start position: {0}, length: {decompressedData.Length}, destination buffer length: {Buffer.Length}.", e);
|
||||
}
|
||||
|
||||
lengthBits = decompressedData.Length * 8;
|
||||
DebugConsole.Log("Decompressing message: " + inLength + " to " + LengthBytes);
|
||||
DebugConsole.Log("Decompressing message: " + byteLength + " to " + LengthBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = new byte[inBuf.Length];
|
||||
Buffer = new byte[inBuf.Length];
|
||||
try
|
||||
{
|
||||
Array.Copy(inBuf, startPos, buf, 0, inLength);
|
||||
Array.Copy(inBuf, startPos, Buffer, 0, byteLength);
|
||||
}
|
||||
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);
|
||||
throw new ArgumentException($"Failed to copy the incoming uncompressed buffer. Source buffer length: {inBuf.Length}, start position: {startPos}, length: {byteLength}, destination buffer length: {Buffer.Length}.", e);
|
||||
}
|
||||
lengthBits = inLength * 8;
|
||||
|
||||
lengthBits = byteLength * 8;
|
||||
}
|
||||
|
||||
seekPos = 0;
|
||||
}
|
||||
|
||||
public bool ReadBoolean()
|
||||
{
|
||||
return MsgReader.ReadBoolean(buf, ref seekPos);
|
||||
return MsgReader.ReadBoolean(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public void ReadPadBits()
|
||||
{
|
||||
MsgReader.ReadPadBits(buf, ref seekPos);
|
||||
}
|
||||
public void ReadPadBits() { MsgReader.ReadPadBits(ref seekPos); }
|
||||
|
||||
public byte ReadByte()
|
||||
{
|
||||
return MsgReader.ReadByte(buf, ref seekPos);
|
||||
return MsgReader.ReadByte(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public byte PeekByte()
|
||||
{
|
||||
return MsgReader.PeekByte(buf, ref seekPos);
|
||||
return MsgReader.PeekByte(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public UInt16 ReadUInt16()
|
||||
{
|
||||
return MsgReader.ReadUInt16(buf, ref seekPos);
|
||||
return MsgReader.ReadUInt16(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public Int16 ReadInt16()
|
||||
{
|
||||
return MsgReader.ReadInt16(buf, ref seekPos);
|
||||
return MsgReader.ReadInt16(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public UInt32 ReadUInt32()
|
||||
{
|
||||
return MsgReader.ReadUInt32(buf, ref seekPos);
|
||||
return MsgReader.ReadUInt32(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public Int32 ReadInt32()
|
||||
{
|
||||
return MsgReader.ReadInt32(buf, ref seekPos);
|
||||
return MsgReader.ReadInt32(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public UInt64 ReadUInt64()
|
||||
{
|
||||
return MsgReader.ReadUInt64(buf, ref seekPos);
|
||||
return MsgReader.ReadUInt64(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public Int64 ReadInt64()
|
||||
{
|
||||
return MsgReader.ReadInt64(buf, ref seekPos);
|
||||
return MsgReader.ReadInt64(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public Single ReadSingle()
|
||||
{
|
||||
return MsgReader.ReadSingle(buf, ref seekPos);
|
||||
return MsgReader.ReadSingle(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public Double ReadDouble()
|
||||
{
|
||||
return MsgReader.ReadDouble(buf, ref seekPos);
|
||||
return MsgReader.ReadDouble(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public UInt32 ReadVariableUInt32()
|
||||
{
|
||||
return MsgReader.ReadVariableUInt32(buf, ref seekPos);
|
||||
return MsgReader.ReadVariableUInt32(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public String ReadString()
|
||||
{
|
||||
return MsgReader.ReadString(buf, ref seekPos);
|
||||
return MsgReader.ReadString(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public Identifier ReadIdentifier()
|
||||
@@ -788,35 +740,35 @@ namespace Barotrauma.Networking
|
||||
|
||||
public Color ReadColorR8G8B8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8(buf, ref seekPos);
|
||||
return MsgReader.ReadColorR8G8B8(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
|
||||
public Color ReadColorR8G8B8A8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8A8(buf, ref seekPos);
|
||||
return MsgReader.ReadColorR8G8B8A8(Buffer, ref seekPos);
|
||||
}
|
||||
|
||||
public int ReadRangedInteger(int min, int max)
|
||||
{
|
||||
return MsgReader.ReadRangedInteger(buf, ref seekPos, min, max);
|
||||
return MsgReader.ReadRangedInteger(Buffer, ref seekPos, min, max);
|
||||
}
|
||||
|
||||
public Single ReadRangedSingle(Single min, Single max, int bitCount)
|
||||
{
|
||||
return MsgReader.ReadRangedSingle(buf, ref seekPos, min, max, bitCount);
|
||||
return MsgReader.ReadRangedSingle(Buffer, ref seekPos, min, max, bitCount);
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(int numberOfBytes)
|
||||
{
|
||||
return MsgReader.ReadBytes(buf, ref seekPos, numberOfBytes);
|
||||
return MsgReader.ReadBytes(Buffer, ref seekPos, numberOfBytes);
|
||||
}
|
||||
}
|
||||
|
||||
class ReadWriteMessage : IWriteMessage, IReadMessage
|
||||
internal sealed class ReadWriteMessage : IWriteMessage, IReadMessage
|
||||
{
|
||||
private byte[] buf;
|
||||
private int seekPos = 0;
|
||||
private int lengthBits = 0;
|
||||
private int seekPos;
|
||||
private int lengthBits;
|
||||
|
||||
public ReadWriteMessage()
|
||||
{
|
||||
@@ -825,40 +777,22 @@ namespace Barotrauma.Networking
|
||||
lengthBits = 0;
|
||||
}
|
||||
|
||||
public ReadWriteMessage(byte[] b, int sPos, int lBits, bool copyBuf)
|
||||
public ReadWriteMessage(byte[] b, int bitPos, int lBits, bool copyBuf)
|
||||
{
|
||||
buf = copyBuf ? (byte[])b.Clone() : b;
|
||||
seekPos = sPos;
|
||||
seekPos = bitPos;
|
||||
lengthBits = lBits;
|
||||
}
|
||||
|
||||
public int BitPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return seekPos;
|
||||
}
|
||||
set
|
||||
{
|
||||
seekPos = value;
|
||||
}
|
||||
get => seekPos;
|
||||
set => seekPos = value;
|
||||
}
|
||||
|
||||
public int BytePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return seekPos / 8;
|
||||
}
|
||||
}
|
||||
public int BytePosition => seekPos / 8;
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
public byte[] Buffer => buf;
|
||||
|
||||
public int LengthBits
|
||||
{
|
||||
@@ -874,17 +808,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public int LengthBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
return (LengthBits + 7) / 8;
|
||||
}
|
||||
}
|
||||
public int LengthBytes => (LengthBits + 7) / 8;
|
||||
|
||||
public NetworkConnection Sender { get { return null; } }
|
||||
public NetworkConnection Sender => null;
|
||||
|
||||
public void Write(bool val)
|
||||
public void WriteBoolean(bool val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
@@ -894,47 +822,47 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.WritePadBits(ref buf, ref seekPos);
|
||||
}
|
||||
|
||||
public void Write(byte val)
|
||||
public void WriteByte(byte val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(UInt16 val)
|
||||
public void WriteUInt16(UInt16 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Int16 val)
|
||||
public void WriteInt16(Int16 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(UInt32 val)
|
||||
public void WriteUInt32(UInt32 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Int32 val)
|
||||
public void WriteInt32(Int32 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(UInt64 val)
|
||||
public void WriteUInt64(UInt64 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Int64 val)
|
||||
public void WriteInt64(Int64 val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Single val)
|
||||
public void WriteSingle(Single val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Double val)
|
||||
public void WriteDouble(Double val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
@@ -943,7 +871,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
|
||||
public void WriteColorR8G8B8A8(Color val)
|
||||
{
|
||||
MsgWriter.WriteColorR8G8B8A8(ref buf, ref seekPos, val);
|
||||
@@ -954,14 +882,14 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.WriteVariableUInt32(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(String val)
|
||||
public void WriteString(String val)
|
||||
{
|
||||
MsgWriter.Write(ref buf, ref seekPos, val);
|
||||
}
|
||||
|
||||
public void Write(Identifier val)
|
||||
public void WriteIdentifier(Identifier val)
|
||||
{
|
||||
Write(val.Value);
|
||||
WriteString(val.Value);
|
||||
}
|
||||
|
||||
public void WriteRangedInteger(int val, int min, int max)
|
||||
@@ -974,7 +902,7 @@ namespace Barotrauma.Networking
|
||||
MsgWriter.WriteRangedSingle(ref buf, ref seekPos, val, min, max, bitCount);
|
||||
}
|
||||
|
||||
public void Write(byte[] val, int startPos, int length)
|
||||
public void WriteBytes(byte[] val, int startPos, int length)
|
||||
{
|
||||
MsgWriter.WriteBytes(ref buf, ref seekPos, val, startPos, length);
|
||||
}
|
||||
@@ -984,10 +912,7 @@ namespace Barotrauma.Networking
|
||||
return MsgReader.ReadBoolean(buf, ref seekPos);
|
||||
}
|
||||
|
||||
public void ReadPadBits()
|
||||
{
|
||||
MsgReader.ReadPadBits(buf, ref seekPos);
|
||||
}
|
||||
public void ReadPadBits() { MsgReader.ReadPadBits(ref seekPos); }
|
||||
|
||||
public byte ReadByte()
|
||||
{
|
||||
@@ -1058,7 +983,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8(buf, ref seekPos);
|
||||
}
|
||||
|
||||
|
||||
public Color ReadColorR8G8B8A8()
|
||||
{
|
||||
return MsgReader.ReadColorR8G8B8A8(buf, ref seekPos);
|
||||
@@ -1079,10 +1004,10 @@ namespace Barotrauma.Networking
|
||||
return MsgReader.ReadBytes(buf, ref seekPos, numberOfBytes);
|
||||
}
|
||||
|
||||
public void PrepareForSending(ref byte[] outBuf, bool compressPastThreshold, out bool isCompressed, out int outLength)
|
||||
public byte[] PrepareForSending(bool compressPastThreshold, out bool isCompressed, out int outLength)
|
||||
{
|
||||
throw new InvalidOperationException("ReadWriteMessages are not to be sent");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user