227 lines
6.2 KiB
C#
227 lines
6.2 KiB
C#
using System;
|
|
|
|
namespace UnityEngine.Networking
|
|
{
|
|
// Token: 0x02000039 RID: 57
|
|
internal class NetBuffer
|
|
{
|
|
// Token: 0x0600014A RID: 330 RVA: 0x0000A434 File Offset: 0x00008634
|
|
public NetBuffer()
|
|
{
|
|
this.m_Buffer = new byte[64];
|
|
}
|
|
|
|
// Token: 0x0600014B RID: 331 RVA: 0x0000A44A File Offset: 0x0000864A
|
|
public NetBuffer(byte[] buffer)
|
|
{
|
|
this.m_Buffer = buffer;
|
|
}
|
|
|
|
// Token: 0x1700002A RID: 42
|
|
// (get) Token: 0x0600014C RID: 332 RVA: 0x0000A45C File Offset: 0x0000865C
|
|
public uint Position
|
|
{
|
|
get
|
|
{
|
|
return this.m_Pos;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700002B RID: 43
|
|
// (get) Token: 0x0600014D RID: 333 RVA: 0x0000A478 File Offset: 0x00008678
|
|
public int Length
|
|
{
|
|
get
|
|
{
|
|
return this.m_Buffer.Length;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600014E RID: 334 RVA: 0x0000A498 File Offset: 0x00008698
|
|
public byte ReadByte()
|
|
{
|
|
if ((ulong)this.m_Pos >= (ulong)((long)this.m_Buffer.Length))
|
|
{
|
|
throw new IndexOutOfRangeException("NetworkReader:ReadByte out of range:" + this.ToString());
|
|
}
|
|
return this.m_Buffer[(int)((UIntPtr)(this.m_Pos++))];
|
|
}
|
|
|
|
// Token: 0x0600014F RID: 335 RVA: 0x0000A4F4 File Offset: 0x000086F4
|
|
public void ReadBytes(byte[] buffer, uint count)
|
|
{
|
|
if ((ulong)(this.m_Pos + count) > (ulong)((long)this.m_Buffer.Length))
|
|
{
|
|
throw new IndexOutOfRangeException(string.Concat(new object[]
|
|
{
|
|
"NetworkReader:ReadBytes out of range: (",
|
|
count,
|
|
") ",
|
|
this.ToString()
|
|
}));
|
|
}
|
|
ushort num = 0;
|
|
while ((uint)num < count)
|
|
{
|
|
buffer[(int)num] = this.m_Buffer[(int)((UIntPtr)(this.m_Pos + (uint)num))];
|
|
num += 1;
|
|
}
|
|
this.m_Pos += count;
|
|
}
|
|
|
|
// Token: 0x06000150 RID: 336 RVA: 0x0000A584 File Offset: 0x00008784
|
|
internal ArraySegment<byte> AsArraySegment()
|
|
{
|
|
return new ArraySegment<byte>(this.m_Buffer, 0, (int)this.m_Pos);
|
|
}
|
|
|
|
// Token: 0x06000151 RID: 337 RVA: 0x0000A5AB File Offset: 0x000087AB
|
|
public void WriteByte(byte value)
|
|
{
|
|
this.WriteCheckForSpace(1);
|
|
this.m_Buffer[(int)((UIntPtr)this.m_Pos)] = value;
|
|
this.m_Pos += 1U;
|
|
}
|
|
|
|
// Token: 0x06000152 RID: 338 RVA: 0x0000A5D2 File Offset: 0x000087D2
|
|
public void WriteByte2(byte value0, byte value1)
|
|
{
|
|
this.WriteCheckForSpace(2);
|
|
this.m_Buffer[(int)((UIntPtr)this.m_Pos)] = value0;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 1U))] = value1;
|
|
this.m_Pos += 2U;
|
|
}
|
|
|
|
// Token: 0x06000153 RID: 339 RVA: 0x0000A60C File Offset: 0x0000880C
|
|
public void WriteByte4(byte value0, byte value1, byte value2, byte value3)
|
|
{
|
|
this.WriteCheckForSpace(4);
|
|
this.m_Buffer[(int)((UIntPtr)this.m_Pos)] = value0;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 1U))] = value1;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 2U))] = value2;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 3U))] = value3;
|
|
this.m_Pos += 4U;
|
|
}
|
|
|
|
// Token: 0x06000154 RID: 340 RVA: 0x0000A674 File Offset: 0x00008874
|
|
public void WriteByte8(byte value0, byte value1, byte value2, byte value3, byte value4, byte value5, byte value6, byte value7)
|
|
{
|
|
this.WriteCheckForSpace(8);
|
|
this.m_Buffer[(int)((UIntPtr)this.m_Pos)] = value0;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 1U))] = value1;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 2U))] = value2;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 3U))] = value3;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 4U))] = value4;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 5U))] = value5;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 6U))] = value6;
|
|
this.m_Buffer[(int)((UIntPtr)(this.m_Pos + 7U))] = value7;
|
|
this.m_Pos += 8U;
|
|
}
|
|
|
|
// Token: 0x06000155 RID: 341 RVA: 0x0000A724 File Offset: 0x00008924
|
|
public void WriteBytesAtOffset(byte[] buffer, ushort targetOffset, ushort count)
|
|
{
|
|
uint num = (uint)(count + targetOffset);
|
|
this.WriteCheckForSpace((ushort)num);
|
|
if (targetOffset == 0 && (int)count == buffer.Length)
|
|
{
|
|
buffer.CopyTo(this.m_Buffer, (int)this.m_Pos);
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < (int)count; i++)
|
|
{
|
|
this.m_Buffer[(int)targetOffset + i] = buffer[i];
|
|
}
|
|
}
|
|
if (num > this.m_Pos)
|
|
{
|
|
this.m_Pos = num;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000156 RID: 342 RVA: 0x0000A7A0 File Offset: 0x000089A0
|
|
public void WriteBytes(byte[] buffer, ushort count)
|
|
{
|
|
this.WriteCheckForSpace(count);
|
|
if ((int)count == buffer.Length)
|
|
{
|
|
buffer.CopyTo(this.m_Buffer, (int)this.m_Pos);
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < (int)count; i++)
|
|
{
|
|
checked
|
|
{
|
|
this.m_Buffer[(int)((IntPtr)(unchecked((ulong)this.m_Pos + (ulong)((long)i))))] = buffer[i];
|
|
}
|
|
}
|
|
}
|
|
this.m_Pos += (uint)count;
|
|
}
|
|
|
|
// Token: 0x06000157 RID: 343 RVA: 0x0000A810 File Offset: 0x00008A10
|
|
private void WriteCheckForSpace(ushort count)
|
|
{
|
|
if ((ulong)(this.m_Pos + (uint)count) >= (ulong)((long)this.m_Buffer.Length))
|
|
{
|
|
int num = (int)Math.Ceiling((double)((float)this.m_Buffer.Length * 1.5f));
|
|
while ((ulong)(this.m_Pos + (uint)count) >= (ulong)((long)num))
|
|
{
|
|
num = (int)Math.Ceiling((double)((float)num * 1.5f));
|
|
if (num > 134217728)
|
|
{
|
|
Debug.LogWarning("NetworkBuffer size is " + num + " bytes!");
|
|
}
|
|
}
|
|
byte[] array = new byte[num];
|
|
this.m_Buffer.CopyTo(array, 0);
|
|
this.m_Buffer = array;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000158 RID: 344 RVA: 0x0000A8BC File Offset: 0x00008ABC
|
|
public void FinishMessage()
|
|
{
|
|
ushort num = (ushort)(this.m_Pos - 4U);
|
|
this.m_Buffer[0] = (byte)(num & 255);
|
|
this.m_Buffer[1] = (byte)((num >> 8) & 255);
|
|
}
|
|
|
|
// Token: 0x06000159 RID: 345 RVA: 0x0000A8F6 File Offset: 0x00008AF6
|
|
public void SeekZero()
|
|
{
|
|
this.m_Pos = 0U;
|
|
}
|
|
|
|
// Token: 0x0600015A RID: 346 RVA: 0x0000A900 File Offset: 0x00008B00
|
|
public void Replace(byte[] buffer)
|
|
{
|
|
this.m_Buffer = buffer;
|
|
this.m_Pos = 0U;
|
|
}
|
|
|
|
// Token: 0x0600015B RID: 347 RVA: 0x0000A914 File Offset: 0x00008B14
|
|
public override string ToString()
|
|
{
|
|
return string.Format("NetBuf sz:{0} pos:{1}", this.m_Buffer.Length, this.m_Pos);
|
|
}
|
|
|
|
// Token: 0x040000C3 RID: 195
|
|
private byte[] m_Buffer;
|
|
|
|
// Token: 0x040000C4 RID: 196
|
|
private uint m_Pos;
|
|
|
|
// Token: 0x040000C5 RID: 197
|
|
private const int k_InitialSize = 64;
|
|
|
|
// Token: 0x040000C6 RID: 198
|
|
private const float k_GrowthFactor = 1.5f;
|
|
|
|
// Token: 0x040000C7 RID: 199
|
|
private const int k_BufferSizeWarning = 134217728;
|
|
}
|
|
}
|