Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Razor/Network/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace Assistant
Expand Down Expand Up @@ -789,24 +790,32 @@ public unsafe sealed class PacketReader
private int m_Pos;
private int m_Length;
private bool m_Dyn;
private GCHandle m_Handle;

public PacketReader(byte* buff, int len, bool dyn)
{
m_Data = buff;
m_Length = len;
m_Pos = 0;
m_Dyn = dyn;
GC.SuppressFinalize(this);
}

public PacketReader(byte[] buff, bool dyn)
{
fixed (byte* p = buff)
m_Data = p;
m_Handle = GCHandle.Alloc(buff, GCHandleType.Pinned);
m_Data = (byte*)m_Handle.AddrOfPinnedObject();
m_Length = buff.Length;
m_Pos = 0;
m_Dyn = dyn;
}

~PacketReader()
{
if (m_Handle.IsAllocated)
m_Handle.Free();
}

public void MoveToData()
{
m_Pos = m_Dyn ? 3 : 1;
Expand Down
Loading