예제 #1
0
        public Grib1WaveSpectra2DDirFreq(System.IO.Stream raf)
        {
            SupportClass.Skip(raf, 4);

            byte[] ver = GribNumbers.ReadBytes(raf, 4);
            System.Text.Encoding enc = System.Text.Encoding.ASCII;
            version = enc.GetString(ver);

            SupportClass.Skip(raf, 2);

            directionNumber = raf.ReadByte();
            frequencyNumber = raf.ReadByte();
            numberOfDirections = raf.ReadByte();
            numberOfFrequencies = raf.ReadByte();
            dirScaleFactor = GribNumbers.int4(raf);
            freqScaleFactor = GribNumbers.int4(raf);

            SupportClass.Skip(raf, 37);

            directions = new double[numberOfDirections];
            frequencies = new double[numberOfFrequencies];

            for (int i = 0; i < numberOfDirections; i++)
            {
                int val = GribNumbers.int4(raf);
                directions[i] = (double)val / (double)dirScaleFactor;
            }

            for (int i = 0; i < numberOfFrequencies; i++)
            {
                int val = GribNumbers.int4(raf);
                frequencies[i] = (double)val / (double)freqScaleFactor;
            }
        }
예제 #2
0
        public FileHeader(System.IO.BinaryReader br)
        {
            majorVersion = 0;
            minorVersion = 0;
            stringCount = 0;
            infoCount = 0;
            ruleCount = 0;
            layoutOptions = new LayoutOptions();

            byte[] magicCode = br.ReadBytes(4);
            if (magicCode[0] != 'K' && magicCode[1] != 'M' && magicCode[2] != 'K' && magicCode[3] != 'L')
            {
                throw new Exception("Invalid KeyMagic keyboard layout file.");
            }

            majorVersion = br.ReadByte();
            minorVersion = br.ReadByte();

            if (majorVersion == 1 && minorVersion > 4)
            {
                throw new Exception("Cannot load this keyboard layout file because this is newer version of keyboard layout file.");
            }

            stringCount = br.ReadInt16();
            if (majorVersion == 1 && minorVersion > 3)
            {
                infoCount = br.ReadInt16();
            }
            ruleCount = br.ReadInt16();

            layoutOptions.trackCaps = br.ReadBoolean();
            layoutOptions.autoBksp = br.ReadBoolean();
            layoutOptions.eat = br.ReadBoolean();
            layoutOptions.posBased = br.ReadBoolean();
        }
예제 #3
0
        public static DecodedObject<int> decodeLength(System.IO.Stream stream)
        {
            int result = 0;
            int bt = stream.ReadByte();
            if (bt == -1)
                throw new System.ArgumentException("Unexpected EOF when decoding!");

            int len = 1;
            if (bt < 128)
            {
                result = bt;
            }
            else
            {
                // Decode length bug fixed. Thanks to John
                for (int i = bt - 128; i > 0; i--)
                {
                    int fBt = stream.ReadByte();
                    if (fBt == -1)
                        throw new System.ArgumentException("Unexpected EOF when decoding!");

                    result = result << 8;
                    result = result | fBt;
                    len++;
                }
            }
            return new DecodedObject<int>(result, len);
        }
예제 #4
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.entityId = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.effectId = DataInput.ReadByte();
     this.effectAmplifier = DataInput.ReadByte();
     this.duration = IPAddress.NetworkToHostOrder(DataInput.ReadInt16());
 }
예제 #5
0
        public override ScalarValue Decode(System.IO.Stream in_Renamed)
        {
            long value_Renamed = 0;
            uint byt;
            try
            {
                byt =(uint) in_Renamed.ReadByte();

                if ((byt & 0x40) > 0)
                {
                    value_Renamed = - 1;
                }

                value_Renamed = (value_Renamed << 7) | (byt & 0x7f);

                while ((byt & STOP_BIT) == 0)
                {
                    byt = (uint)in_Renamed.ReadByte();
                    value_Renamed = (value_Renamed << 7) | (byt & 0x7f);
                }
            }
            catch (System.IO.IOException e)
            {
                throw new RuntimeException(e);
            }

            return CreateValue(value_Renamed);
        }
 public OtherModelAddition( System.IO.Stream stream, uint refStringStart )
 {
     Str = stream.ReadAsciiNulltermFromLocationAndReset( stream.ReadUInt32().SwapEndian() + refStringStart );
     Unknown1 = (byte)stream.ReadByte();
     Unknown2 = (byte)stream.ReadByte();
     stream.DiscardBytes( 0x1A );
 }
예제 #7
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     base.readData(DataInput);
     this.xPosition = DataInput.ReadByte();
     this.yPosition = DataInput.ReadByte();
     this.zPosition = DataInput.ReadByte();
 }
        /// <summary>
        /// When a segment's data is compressed, it follows the following run-length algorithm:
        /// If a byte of data has a value of (int)1 thru (int) 127, then the following x bytes are uncompressed.
        /// If a byte of data has a value of (int)129 thru (int) 255, then the following byte is repeated 127 less times.
        /// </summary>
        internal override void ParseSegment(System.IO.FileStream file)
        {
            Length = file.Read4ByteInt();
            RawDataFileOffset = (int)file.Position;

            List<byte> bytes = new List<byte>();
            while (file.Position < RawDataFileOffset + Length)
            {
                byte b = (byte)file.ReadByte();

                if (b > 0 && b < 128)
                {
                    for (int i = 0; i < b; ++i)
                    {
                        bytes.Add((byte)file.ReadByte());
                    }
                }
                else if (b > 128)
                {
                    byte nextByte = (byte)file.ReadByte();
                    for (int i = 0; i < b - 127; ++i)
                    {
                        bytes.Add(nextByte);
                    }
                }
                else
                {
                    throw new Exception("Bad compressed data byte encountered at file offset " + file.Position);
                }
            }

            UncompressedLength = bytes.Count;
            Data = bytes.ToArray();
        }
        public CharacterModelDefinition( System.IO.Stream stream, uint refStringStart )
        {
            Strings = new string[100];

            for ( uint i = 0; i < 100; ++i ) {
                Strings[i] = stream.ReadAsciiNulltermFromLocationAndReset( stream.ReadUInt32().SwapEndian() + refStringStart );
            }

            CustomIndex = stream.ReadUInt32().SwapEndian();
            CustomCount = (byte)stream.ReadByte();
            OtherCount = (byte)stream.ReadByte();
            Unknown0x20AreaCount = (byte)stream.ReadByte();
            Unknown1d = (byte)stream.ReadByte();
            OtherIndex = stream.ReadUInt32().SwapEndian();
            Unknown0x20AreaIndex = stream.ReadUInt32().SwapEndian();
            Unknown4a = (byte)stream.ReadByte();
            Unknown4b = (byte)stream.ReadByte();
            Unknown4c = (byte)stream.ReadByte();
            Unknown4d = (byte)stream.ReadByte();
            stream.DiscardBytes( 4 );
            Unknown0x80AreaIndex = stream.ReadUInt32().SwapEndian();
            Unknown0x80AreaCount = (byte)stream.ReadByte();
            Unknown7b = (byte)stream.ReadByte();
            stream.DiscardBytes( 2 );

            stream.DiscardBytes( 80 );
        }
예제 #10
0
파일: Light.cs 프로젝트: angelog/Coral
        public override void Deserialize(System.IO.BinaryReader reader)
        {
            base.Deserialize(reader);

            Color = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            Brightness = reader.ReadInt32();
        }
예제 #11
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.xPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.yPosition = DataInput.ReadByte();
     this.zPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.type = IPAddress.NetworkToHostOrder(DataInput.ReadInt16());
     this.metadata = DataInput.ReadByte();
 }
예제 #12
0
파일: Message.cs 프로젝트: angelog/Coral
        public override void Deserialize(System.IO.BinaryReader reader)
        {
            base.Deserialize(reader);

            Text = reader.ReadString();
            Color = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            DisplayTime = reader.ReadInt32();
        }
예제 #13
0
 public override IGORR.Server.Logic.GameObject CreateServer(IGORR.Server.Logic.IMap map, int objectID, Microsoft.Xna.Framework.Point p, System.IO.BinaryReader bin)
 {
     string color = "" + (char)bin.ReadByte() + (char)bin.ReadByte() + (char)bin.ReadByte() + (char)bin.ReadByte();
     int radius = bin.ReadInt32();
     color += (char)(byte)(radius / 256);
     color += (char)(byte)(radius % 256);
     return new IGORR.Server.Logic.DummyObject(10003, map, new Microsoft.Xna.Framework.Rectangle(p.X, p.Y, 16, 16), objectID, color);
 }
예제 #14
0
 public EndGameAction(System.IO.BinaryReader reader)
 {
     this.hasCheckmate = reader.ReadBoolean();
     if (this.hasCheckmate)
         this.looser = (PlayerColor)reader.ReadByte();
     else
         this.stalemateReason = (StalemateReason)reader.ReadByte();
 }
예제 #15
0
파일: Mapper033.cs 프로젝트: Blizz9/FanCut
 public override void LoadState(System.IO.BinaryReader stream)
 {
     base.LoadState(stream);
     irq_enabled = stream.ReadBoolean();
     irq_counter = stream.ReadByte();
     old_irq_counter = stream.ReadInt32();
     irq_reload = stream.ReadByte();
     irq_clear = stream.ReadBoolean();
 }
예제 #16
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.xLocation = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.yLocation = IPAddress.NetworkToHostOrder(DataInput.ReadInt16());
     this.zLocation = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.instrumentType = DataInput.ReadByte();
     this.pitch = DataInput.ReadByte();
     this.blockId = IPAddress.NetworkToHostOrder(DataInput.ReadInt16()) &4095;
 }
예제 #17
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.respawnDimension = DataInput.ReadInt32();
     this.difficulty = DataInput.ReadByte();
     this.gameType = DataInput.ReadByte();
     this.worldHeight = DataInput.ReadInt16();
     String s = readString(DataInput, 16);
     this.terrainType = s;
 }
예제 #18
0
파일: Prop.cs 프로젝트: angelog/Coral
        public override void Deserialize(System.IO.BinaryReader reader)
        {
            base.Deserialize(reader);

            Texture = reader.ReadString();
            Tiled = reader.ReadBoolean();

            Blending = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
        }
예제 #19
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.entityId = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.xPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.yPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.zPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.yaw = DataInput.ReadByte();
     this.pitch = DataInput.ReadByte();
 }
예제 #20
0
 public override object Deserialize(System.IO.BinaryReader binaryReader)
 {
     bool hasValue = binaryReader.ReadBoolean ();
     if (!hasValue)
         return null;
     int typeID = binaryReader.ReadByte ();
     switch (typeID) {
     case 1:
         return binaryReader.ReadBoolean ();
     case 2:
         return binaryReader.ReadByte ();
     case 128:
         return binaryReader.ReadSByte ();
     case 3:
         return binaryReader.ReadInt16 ();
     case 129:
         return binaryReader.ReadUInt16 ();
     case 4:
         return binaryReader.ReadInt32 ();
     case 130:
         return binaryReader.ReadUInt32 ();
     case 5:
         return binaryReader.ReadInt64 ();
     case 131:
         return binaryReader.ReadUInt64 ();
     case 9:
         return binaryReader.ReadDouble ();
     case 16:
         return binaryReader.ReadString ();
     case 144:
         return binaryReader.ReadChar ();
     case 24:
         return new DateTime (binaryReader.ReadInt64 ());
     case 32:
         return new Guid (binaryReader.ReadBytes (16));
     case 36:
         return binaryReader.ReadBytes (binaryReader.ReadInt32 ());
     case 37:
         {
             int count = binaryReader.ReadInt32 ();
             string[] r = new string[count];
             for (int n = 0; n != count; n++)
                 r [n] = binaryReader.ReadString ();
             return r;
         }
     case 38:
         {
             int count = binaryReader.ReadInt32 ();
             long[] r = new long[count];
             for (int n = 0; n != count; n++)
                 r [n] = binaryReader.ReadInt64 ();
             return r;
         }
     default:
         throw new Exception (string.Format ("Serialization for type <{0}> is not supported", typeID));
     }
 }
예제 #21
0
 public void Read(System.IO.BinaryReader br)
 {
     XOrigin = br.ReadUInt16();
     YOrigin = br.ReadUInt16();
     Width = br.ReadUInt16();
     Height = br.ReadUInt16();
     PixelDepth = br.ReadByte();
     Descriptor = br.ReadByte();
 }
예제 #22
0
 /// <summary>
 /// Load state
 /// </summary>
 /// <param name="stream">The stream that should be used to read data</param>
 public void LoadState(System.IO.BinaryReader stream)
 {
     AccumRate = stream.ReadByte();
     accumClock = stream.ReadInt32();
     accumulationRegister = stream.ReadByte();
     frequency = stream.ReadInt32();
     freqTimer = stream.ReadInt32();
     cycles = stream.ReadInt32();
     enabled = stream.ReadBoolean();
 }
예제 #23
0
 protected internal override void Deserialize(System.IO.BinaryReader br)
 {
     Subtype = br.ReadByte();
     CarId = br.ReadByte();
     if (Subtype == (byte)ACSProtocol.MessageType.ACSP_CE_COLLISION_WITH_CAR)
         OtherCarId = br.ReadByte();
     RelativeVelocity = br.ReadSingle();
     WorldPosition = readVector3f(br);
     RelativePosition = readVector3f(br);
 }
예제 #24
0
 public void Read(System.IO.BinaryReader br)
 {
     this.IdLength = br.ReadByte();
     this.ColorMapType = br.ReadByte();
     this.ImageType = br.ReadByte();
     this.ColorMap = new tgaColorMap();
     this.ImageSpec = new tgaImageSpec();
     this.ColorMap.Read(br);
     this.ImageSpec.Read(br);
 }
        protected override int ProcessIncoming(NetContext context, Connection connection, System.IO.Stream incoming)
        {
            if (incoming.Length < 2) return 0; // can't read that; start/end markers take at least 2 bytes

            switch(incoming.ReadByte())
            {
                case 0x00:
                    var ws = (WebSocketConnection) connection;
                    if(!ws.AllowIncomingDataFrames) throw new InvalidOperationException("Data frames disabled");
                    // data frame is 0x00 [data] 0xFF
                    int len = 0, cur;
                    while((cur = incoming.ReadByte()) != 0xFF && cur >= 0)
                    {
                        len++;
                    }
                    if(cur < 0) throw new EndOfStreamException();

                    incoming.Position = 1;
                    string value;
                    if (len == 0) value = "";
                    else if (len <= NetContext.BufferSize)
                    {
                        byte[] buffer = null;
                        try
                        {
                            buffer = context.GetBuffer();
                            NetContext.Fill(incoming, buffer, len);
                            value = Encoding.UTF8.GetString(buffer, 0, len);
                        } finally
                        {
                            context.Recycle(buffer);
                        }
                    } else
                    {
                        var buffer = new byte[len];
                        NetContext.Fill(incoming, buffer, len);
                        value = Encoding.UTF8.GetString(buffer, 0, len);
                    }
                    context.Handler.OnReceived(connection, value);
                    return len + 2;
                case 0xFF:
                    // shutdown is 0xFF 0x00
                    if(incoming.ReadByte() == 0x00)
                    {
                        GracefulShutdown(context, connection);
                        return 2;
                    } else
                    {
                        throw new InvalidOperationException("protocol fail");
                    }
                default:
                    throw new InvalidOperationException("protocol fail");
            }
        }
예제 #26
0
        public int vislist; // Beginning of visibility lists

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            type = source.ReadInt32();
            vislist = source.ReadInt32();
            box.Read(source);
            lface_id = source.ReadUInt16();
            lface_num = source.ReadUInt16();
            sndwater = source.ReadByte();
            sndsky = source.ReadByte();
            sndslime = source.ReadByte();
            sndlava = source.ReadByte();
        }
        public Unknown0x80byteArea( System.IO.Stream stream, uint refStringStart )
        {
            UnknownUInt = stream.ReadUInt32().SwapEndian();
            stream.DiscardBytes( 4 );
            UnknownByte1 = (byte)stream.ReadByte();
            UnknownByte2 = (byte)stream.ReadByte();
            stream.DiscardBytes( 2 );
            UnknownFloat1 = stream.ReadUInt32().SwapEndian().UIntToFloat();
            UnknownFloat2 = stream.ReadUInt32().SwapEndian().UIntToFloat();

            stream.DiscardBytes( 0x6C );
        }
예제 #28
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.entityId = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.name = readString(DataInput, 16);
     this.xPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.yPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.zPosition = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.rotation = DataInput.ReadByte();
     this.pitch = DataInput.ReadByte();
     this.currentItem = IPAddress.NetworkToHostOrder(DataInput.ReadInt16());
     readWatchableObjects(DataInput);
 }
예제 #29
0
        public void Read(System.IO.BinaryReader br)
        {
            for (int i = 0; i < 256; i++)
            {
                byte r = br.ReadByte();
                byte g = br.ReadByte();
                byte b = br.ReadByte();

                br.ReadByte();

                m_colors[i] = new Color(r, g, b, 0);
            }
        }
예제 #30
0
        private int ReadLength(System.IO.BinaryReader reader)
        {
            int len = reader.ReadByte();

            if ((len & 0x80) != 0x00)
            {
                len &= 0x7f;
                len = (len << 0x08) | reader.ReadByte();
            }

            len = (len << 0x08) | reader.ReadByte();
            return len;
        }