GetByte() public method

public GetByte ( ) : byte
return byte
        public static Color GetColor(this NetDataReader reader)
        {
            float r = reader.GetByte() * 0.01f;
            float g = reader.GetByte() * 0.01f;
            float b = reader.GetByte() * 0.01f;
            float a = reader.GetByte() * 0.01f;

            return(new Color(r, g, b, a));
        }
        public static ulong GetPackedULong(this NetDataReader reader)
        {
            byte a0 = reader.GetByte();

            if (a0 < 241)
            {
                return(a0);
            }

            byte a1 = reader.GetByte();

            if (a0 >= 241 && a0 <= 248)
            {
                return(240 + 256 * (a0 - ((ulong)241)) + a1);
            }

            byte a2 = reader.GetByte();

            if (a0 == 249)
            {
                return(2288 + (((ulong)256) * a1) + a2);
            }

            byte a3 = reader.GetByte();

            if (a0 == 250)
            {
                return(a1 + (((ulong)a2) << 8) + (((ulong)a3) << 16));
            }

            byte a4 = reader.GetByte();

            if (a0 == 251)
            {
                return(a1 + (((ulong)a2) << 8) + (((ulong)a3) << 16) + (((ulong)a4) << 24));
            }

            byte a5 = reader.GetByte();

            if (a0 == 252)
            {
                return(a1 + (((ulong)a2) << 8) + (((ulong)a3) << 16) + (((ulong)a4) << 24) + (((ulong)a5) << 32));
            }

            byte a6 = reader.GetByte();

            if (a0 == 253)
            {
                return(a1 + (((ulong)a2) << 8) + (((ulong)a3) << 16) + (((ulong)a4) << 24) + (((ulong)a5) << 32) + (((ulong)a6) << 40));
            }

            byte a7 = reader.GetByte();

            if (a0 == 254)
            {
                return(a1 + (((ulong)a2) << 8) + (((ulong)a3) << 16) + (((ulong)a4) << 24) + (((ulong)a5) << 32) + (((ulong)a6) << 40) + (((ulong)a7) << 48));
            }

            byte a8 = reader.GetByte();

            if (a0 == 255)
            {
                return(a1 + (((ulong)a2) << 8) + (((ulong)a3) << 16) + (((ulong)a4) << 24) + (((ulong)a5) << 32) + (((ulong)a6) << 40) + (((ulong)a7) << 48) + (((ulong)a8) << 56));
            }
            throw new System.IndexOutOfRangeException("ReadPackedULong() failure: " + a0);
        }
        public static object GetValue(this NetDataReader reader, Type type)
        {
            #region Generic Values
            if (type.IsEnum)
            {
                type = type.GetEnumUnderlyingType();
            }

            if (type == typeof(bool))
            {
                return(reader.GetBool());
            }

            if (type == typeof(byte))
            {
                return(reader.GetByte());
            }

            if (type == typeof(char))
            {
                return(reader.GetChar());
            }

            if (type == typeof(double))
            {
                return(reader.GetDouble());
            }

            if (type == typeof(float))
            {
                return(reader.GetFloat());
            }

            if (type == typeof(int))
            {
                return(reader.GetPackedInt());
            }

            if (type == typeof(long))
            {
                return(reader.GetPackedLong());
            }

            if (type == typeof(sbyte))
            {
                return(reader.GetSByte());
            }

            if (type == typeof(short))
            {
                return(reader.GetPackedShort());
            }

            if (type == typeof(string))
            {
                return(reader.GetString());
            }

            if (type == typeof(uint))
            {
                return(reader.GetPackedUInt());
            }

            if (type == typeof(ulong))
            {
                return(reader.GetPackedULong());
            }

            if (type == typeof(ushort))
            {
                return(reader.GetPackedUShort());
            }
            #endregion

            #region Unity Values
            if (type == typeof(Color))
            {
                return(reader.GetColor());
            }

            if (type == typeof(Quaternion))
            {
                return(reader.GetQuaternion());
            }

            if (type == typeof(Vector2))
            {
                return(reader.GetVector2());
            }

            if (type == typeof(Vector2Int))
            {
                return(reader.GetVector2Int());
            }

            if (type == typeof(Vector3))
            {
                return(reader.GetVector3());
            }

            if (type == typeof(Vector3Int))
            {
                return(reader.GetVector3Int());
            }

            if (type == typeof(Vector4))
            {
                return(reader.GetVector4());
            }
            #endregion

            if (typeof(INetSerializable).IsAssignableFrom(type))
            {
                object instance = Activator.CreateInstance(type);
                (instance as INetSerializable).Deserialize(reader);
                return(instance);
            }

            throw new ArgumentException("NetDataReader cannot read type " + type.Name);
        }
 public override void Read(T inf, NetDataReader r)
 {
     Property.SetValue(inf, Enum.ToObject(PropertyType, r.GetByte()), null);
 }
 public override void Read(T inf, NetDataReader r)
 {
     Setter(inf, r.GetByte());
 }
Example #6
0
        public static object GetValue(this NetDataReader reader, Type type)
        {
            #region Generic Values

            if (type.IsPrimitive)
            {
                if (type == typeof(bool))
                {
                    return(reader.GetBool());
                }

                if (type == typeof(byte))
                {
                    return(reader.GetByte());
                }

                if (type == typeof(ushort))
                {
                    return(reader.GetUShort());
                }

                if (type == typeof(int))
                {
                    return(reader.GetInt());
                }

                if (type == typeof(float))
                {
                    return(reader.GetFloat());
                }

                if (type == typeof(short))
                {
                    return(reader.GetShort());
                }

                if (type == typeof(string))
                {
                    return(reader.GetString());
                }

                if (type == typeof(uint))
                {
                    return(reader.GetUInt());
                }

                if (type == typeof(long))
                {
                    return(reader.GetLong());
                }

                if (type == typeof(char))
                {
                    return(reader.GetChar());
                }

                if (type == typeof(double))
                {
                    return(reader.GetDouble());
                }

                if (type == typeof(sbyte))
                {
                    return(reader.GetSByte());
                }


                if (type == typeof(ulong))
                {
                    return(reader.GetULong());
                }

                throw new ArgumentException("NetDataReader cannot read type " + type.Name);
            }
            else if (type.IsArray)
            {
                if (type == typeof(bool[]))
                {
                    return(reader.GetBoolArray());
                }

                if (type == typeof(byte[]))
                {
                    return(reader.GetBytesWithLength());
                }

                if (type == typeof(double[]))
                {
                    return(reader.GetDoubleArray());
                }

                if (type == typeof(float[]))
                {
                    return(reader.GetFloatArray());
                }

                if (type == typeof(int[]))
                {
                    return(reader.GetIntArray());
                }

                if (type == typeof(long[]))
                {
                    return(reader.GetLongArray());
                }

                if (type == typeof(short[]))
                {
                    return(reader.GetShortArray());
                }

                if (type == typeof(uint[]))
                {
                    return(reader.GetUIntArray());
                }

                if (type == typeof(ulong[]))
                {
                    return(reader.GetULongArray());
                }

                if (type == typeof(ushort[]))
                {
                    return(reader.GetUShortArray());
                }

                throw new ArgumentException("NetDataReader cannot read type " + type.Name);
            }
            else if (typeof(INetSerializable).IsAssignableFrom(type))
            {
                object instance = Activator.CreateInstance(type);
                ((INetSerializable)instance).Deserialize(reader);
                return(instance);
            }
            else
            {
                #region Unity Values
#if UNITY_2019
                if (type == typeof(Color))
                {
                    return(reader.GetColor());
                }

                if (type == typeof(Quaternion))
                {
                    return(reader.GetQuaternion());
                }

                if (type == typeof(Vector2))
                {
                    return(reader.GetVector2());
                }

                if (type == typeof(Vector2Int))
                {
                    return(reader.GetVector2Int());
                }

                if (type == typeof(Vector3))
                {
                    return(reader.GetVector3());
                }

                if (type == typeof(Vector3Int))
                {
                    return(reader.GetVector3Int());
                }

                if (type == typeof(Vector4))
                {
                    return(reader.GetVector4());
                }
#endif
                #endregion

                if (type == typeof(string))
                {
                    return(reader.GetString());
                }

                throw new ArgumentException("NetDataReader cannot read type " + type.Name);
            }
            #endregion
        }
Example #7
0
        private void HandleNatIntroduction(NetDataReader dr)
        {
            // read intro
            byte hostByte = dr.GetByte();
            NetEndPoint remoteInternal = dr.GetNetEndPoint();
            NetEndPoint remoteExternal = dr.GetNetEndPoint();
            string token = dr.GetString(MaxTokenLength);

            NetUtils.DebugWrite(ConsoleColor.Cyan, "[NAT] introduction received; we are designated " + (hostByte == HostByte ? "host" : "client"));
            NetDataWriter writer = new NetDataWriter();

            // send internal punch
            writer.Put(hostByte);
            writer.Put(token);
            _netBase.SendRaw(NetPacket.CreateRawPacket(PacketProperty.NatPunchMessage, writer), remoteInternal);
            NetUtils.DebugWrite(ConsoleColor.Cyan, "[NAT] internal punch sent to " + remoteInternal);

            // send external punch
            writer.Reset();
            writer.Put(hostByte);
            writer.Put(token);
            _netBase.SendRaw(NetPacket.CreateRawPacket(PacketProperty.NatPunchMessage, writer), remoteExternal);
            NetUtils.DebugWrite(ConsoleColor.Cyan, "[NAT] external punch sent to " + remoteExternal);
        }
Example #8
0
        private void HandleNatPunch(NetEndPoint senderEndPoint, NetDataReader dr)
        {
            byte fromHostByte = dr.GetByte();
            if (fromHostByte != HostByte && fromHostByte != ClientByte)
            {
                //garbage
                return;
            }

            //Read info
            string additionalInfo = dr.GetString(MaxTokenLength);
            NetUtils.DebugWrite(ConsoleColor.Green, "[NAT] punch received from {0} - additional info: {1}", senderEndPoint, additionalInfo);

            //Release punch success to client; enabling him to Connect() to msg.Sender if token is ok
            lock (_successEvents)
            {
                _successEvents.Enqueue(new SuccessEventData { TargetEndPoint = senderEndPoint, Token = additionalInfo });
            }
        }