public ShipActionPacket(Stream stream, int index)
            : base()
        {

            if (stream != null)
            {
                if (stream.CanSeek)
                {
                    stream.Position = index;
                }
                if (index < stream.Length - 3)
                {
                    SubPacketType = (ShipActionSubPackets.ShipActionSubPacketType)stream.ToInt32();
                }
                if (index < stream.Length - 4)
                {
                    SubPacketData = stream.GetMemoryStream(index + 4);
                    _subPacket = GetSubPacket(SubPacketData);
                }
                else
                {
                    _subPacket = null;
                    SubPacketData = null;
                }
            }
        }
        public ShipAction2Packet(Stream stream, int index) : base()
        {
            try
            {
                if (stream != null)
                {
                    if (stream.CanSeek)
                    {
                        stream.Position = index;
                    }
                    if (index < stream.Length - 3)
                    {
                        SubPacketType = (ShipAction2SubPacketType)stream.ToInt32();
                    }
                    if (index < stream.Length - 4)
                    {
                        SubPacketData = stream.GetMemoryStream(index + 4);

                        _subPacket = GetSubPacket(SubPacketData);
                    }
                    else
                    {
                        _subPacket = null;
                        SubPacketData = null;
                    }
                }
            }
            catch (Exception ex)
            {
                AddError(ex);
            }
        }
        // GameStartSubPacket = 0,
        //GameOverSubPacket = 6,
        //Unknown1SubPacket = 8,
        //Unknown2SubPacket = 9,
        //GameTextMessageSubPacket = 10,
        //JumpStartSubPacket = 12,
        //JumpCompleteSubPacket = 13,
        //AllShipSettingsSubPacket = 15,
        public GameMessagePacket(Stream stream, int index)
        {
            try
            {
                if (stream != null)
                {
                    if (stream.CanSeek)
                    {
                        stream.Position = index;
                    }
                    if (stream.Length > 3)
                    {
                        SubPacketType = (GameMessageSubPacketType)stream.ToInt32();
                       
                    }
                    if (stream.Length >= 4)
                    {
                        SubPacketData = stream.GetMemoryStream(index + 4);

                     
                        _subPacket = GetSubPacket(stream, index + 4);
                    }
                    else
                    {
                        _subPacket = null;
                        SubPacketData = null;
                    }
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex);
            }
        }
Ejemplo n.º 4
0
        static KeyValuePair<int, object> GetIntermediateType(Type CastType, int index, Stream stream)
        {
            int retVal = index;
            object intermediateObject = null;
            Type cTp = CastType;
            if (cTp.IsEnum)
            {
             
                
                cTp = Enum.GetUnderlyingType(cTp);
            }
            if (cTp == typeof(byte) || cTp == typeof(byte?))
            {

                if (retVal < stream.Length)
                {
                    intermediateObject = Convert.ToByte(stream.ReadByte());
                    retVal = 1;
                }
            }
            if (cTp == typeof(short) || cTp == typeof(short?))
            {

                if (retVal < stream.Length - 1)
                {
                    intermediateObject = stream.ToInt16();
                    retVal = 2;
                }
            }
            if (cTp == typeof(int) || cTp == typeof(int?))
            {

                if (retVal < stream.Length - 3)
                {

                    intermediateObject = stream.ToInt32();
                    retVal = 4;
                }
            }
            if (cTp == typeof(float) || cTp == typeof(float?))
            {

                if (retVal < stream.Length - 3)
                {

                    intermediateObject = stream.ToSingle();
                    retVal = 4;
                }
            }
            if (cTp == typeof(long) || cTp == typeof(long?))
            {

                if (retVal < stream.Length - 7)
                {

                    intermediateObject = stream.ToInt64();
                    retVal = 8;
                }
            }
            if (CastType == typeof(ArtemisString))
            {
                if (retVal < stream.Length - 3)
                {
                    ArtemisString artyString = new ArtemisString(stream, index);
                    intermediateObject = artyString;
                    retVal = artyString.Length * 2 + 4;
                }
            }
            return new KeyValuePair<int,object>(retVal, intermediateObject);
        }