public static int ConnectEndPoint(int hostId, EndPoint endPoint, int exceptionConnectionId, out byte error)
{
error = 0;
byte[] buffer = new byte[] { 0x5f, 0x24, 0x13, 0xf6 };
if (endPoint == null)
{
throw new NullReferenceException("Null EndPoint provided");
}
if (((endPoint.GetType().FullName != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPoint.GetType().FullName != "UnityEngine.PS4.SceEndPoint")) && (endPoint.GetType().FullName != "UnityEngine.PSVita.SceEndPoint"))
{
throw new ArgumentException("Endpoint of type XboxOneEndPoint or SceEndPoint required");
}
if (endPoint.GetType().FullName == "UnityEngine.XboxOne.XboxOneEndPoint")
{
EndPoint point = endPoint;
if (point.AddressFamily != AddressFamily.InterNetworkV6)
{
throw new ArgumentException("XboxOneEndPoint has an invalid family");
}
SocketAddress address = point.Serialize();
if (address.Size != 14)
{
throw new ArgumentException("XboxOneEndPoint has an invalid size");
}
if ((address[0] != 0) || (address[1] != 0))
{
throw new ArgumentException("XboxOneEndPoint has an invalid family signature");
}
if (((address[2] != buffer[0]) || (address[3] != buffer[1])) || ((address[4] != buffer[2]) || (address[5] != buffer[3])))
{
throw new ArgumentException("XboxOneEndPoint has an invalid signature");
}
byte[] buffer2 = new byte[8];
for (int j = 0; j < buffer2.Length; j++)
{
buffer2[j] = address[6 + j];
}
IntPtr ptr = new IntPtr(BitConverter.ToInt64(buffer2, 0));
if (ptr == IntPtr.Zero)
{
throw new ArgumentException("XboxOneEndPoint has an invalid SOCKET_STORAGE pointer");
}
byte[] buffer3 = new byte[2];
Marshal.Copy(ptr, buffer3, 0, buffer3.Length);
AddressFamily family = (AddressFamily) ((buffer3[1] << 8) + buffer3[0]);
if (family != AddressFamily.InterNetworkV6)
{
throw new ArgumentException("XboxOneEndPoint has corrupt or invalid SOCKET_STORAGE pointer");
}
return Internal_ConnectEndPoint(hostId, ptr, 0x80, exceptionConnectionId, out error);
}
SocketAddress address2 = endPoint.Serialize();
if (address2.Size != 0x10)
{
throw new ArgumentException("EndPoint has an invalid size");
}
if (address2[0] != address2.Size)
{
throw new ArgumentException("EndPoint has an invalid size value");
}
if (address2[1] != 2)
{
throw new ArgumentException("EndPoint has an invalid family value");
}
byte[] source = new byte[0x10];
for (int i = 0; i < source.Length; i++)
{
source[i] = address2[i];
}
IntPtr destination = Marshal.AllocHGlobal(source.Length);
Marshal.Copy(source, 0, destination, source.Length);
int num4 = Internal_ConnectEndPoint(hostId, destination, 0x10, exceptionConnectionId, out error);
Marshal.FreeHGlobal(destination);
return num4;
}