Example #1
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));
     }
 }
Example #2
0
 internal static Answer Get(System.IO.BinaryReader reader)
 {
     Answer a = new Answer();
     a.DomainName = DomainName.Get(reader);
     ushort s;
     Message.FromBytes(reader.ReadBytes(2), out s);
     a.Type = (Type)s;
     Message.FromBytes(reader.ReadBytes(2), out s);
     a.Class = (Class)s;
     uint ttl;
     Message.FromBytes(reader.ReadBytes(4), out ttl);
     a.Ttl = ttl;
     a.ResponseData = ResponseData.Get(a.Type, reader);
     return a;
 }
Example #3
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();
        }
        public object Deserialize(System.IO.Stream stream)
        {
			long count = ZigZag.DeserializeInt64 (stream);
			if(count == 1) return null;
			int c = (int)(count >> 1);
			return stream.ReadBytes (c);
        }			
Example #5
0
 public void ReadFrom(System.IO.BinaryReader reader)
 {
     Size = reader.ReadUInt16();
     if (Size > Marshal.SizeOf(Size))
     {
         Item.Data = reader.ReadBytes(Size - Marshal.SizeOf(Size));
     }
 }
Example #6
0
        /// <summary>
        /// Reads the content item from the specified reader.
        /// </summary>
        /// <param name="reader">Binary reader to read from.</param>
        internal override void Read(System.IO.BinaryReader reader, BinaryReadInfo readInfo)
        {
            uint length = reader.ReadUInt32();

            ID = reader.ReadUInt32();
            ResourceType = (BinaryResourceType)reader.ReadUInt32();
            Buffer = reader.ReadBytes((int)length - 8);
        }
		public object Deserialize(System.IO.Stream stream)
		{
			long count = ZigZag.DeserializeInt64 (stream);
			if(count == 1) return null;
			var c = (int)(count >> 1);
			var bytes = stream.ReadBytes (c);
			return Encoding.UTF8.GetString(bytes);
		}
Example #8
0
        /// <summary>
        /// 読み込み用コンストラクタ
        /// </summary>
        /// <param name="reader"></param>
        public InternalHeader(System.IO.BinaryReader reader)
        {
            FileNameLength = reader.ReadUInt32();
            Size = reader.ReadUInt32();
            Offset = reader.ReadUInt32();
            FileName = Encoding.UTF8.GetString(reader.ReadBytes((int)FileNameLength));

            HeaderSize = (uint)(4 + 4 + 4 + FileNameLength);
        }
Example #9
0
        public PlayWaveHelper(System.IO.BinaryReader reader)
        {
            int strLen = reader.ReadInt16();
            byte[] bytes = reader.ReadBytes((int)strLen);
            _bankname = Encoding.ASCII.GetString(bytes);

            _index = reader.ReadInt32();
            _weight = reader.ReadByte();
        }
Example #10
0
		public void LoadStateBinary(System.IO.BinaryReader reader)
		{
			int length = reader.ReadInt32();
			byte[] data = reader.ReadBytes(length);
			LoadCoreBinary(data);
			// other variables
			IsLagFrame = reader.ReadBoolean();
			LagCount = reader.ReadInt32();
			Frame = reader.ReadInt32();
		}
Example #11
0
 protected override void readData(System.IO.BinaryReader DataInput)
 {
     this.xCh = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.zCh = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     this.includeInitialize = DataInput.ReadBoolean();
     this.yChMin = IPAddress.NetworkToHostOrder(DataInput.ReadInt16());
     this.yChMax = IPAddress.NetworkToHostOrder(DataInput.ReadInt16());
     this.tempLength = IPAddress.NetworkToHostOrder(DataInput.ReadInt32());
     DataInput.ReadBytes(this.tempLength);
 }
Example #12
0
        public ushort texture_info; // index of the texture info structure

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            plane = source.ReadUInt16();
                    plane_side = source.ReadUInt16();
                    ledge_id = source.ReadUInt32();
                    ledge_num = source.ReadUInt16();
                    texture_info = source.ReadUInt16();
                    lightmap_syles = source.ReadBytes(4);
                    lightmap = source.ReadInt32();
        }
Example #13
0
        public VolkeQuestionMessage(long timeFrame, System.IO.BinaryReader reader)
            : base(timeFrame)
        {
            int x = reader.ReadInt16();
            int y = reader.ReadInt16();
            int size = reader.ReadInt32();
            var imageBytes = reader.ReadBytes(size);

            this.Point = new Point(x, y);
            this.Image = Image.FromStream(new MemoryStream(imageBytes));
        }
Example #14
0
        public ExportedLevel(System.IO.BinaryReader br)
        {
            string Header = br.ReadString();
            if (Header != fileHeader)
            {
                throw new Exception(LanguageManager.Get("NSMBLevel", "InvalidFile"));
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > version)
            {
                throw new Exception(LanguageManager.Get("NSMBLevel", "OldVersion"));
            }

            LevelFileID = br.ReadUInt16();
            BGDatFileID = br.ReadUInt16();
            int LevelFileLength = br.ReadInt32();
            LevelFile = br.ReadBytes(LevelFileLength);

            int BGFileLength = br.ReadInt32();
            BGDatFile = br.ReadBytes(BGFileLength);
        }
Example #15
0
 public RGBImage(System.IO.BinaryReader br)
 {
     try
     {
         this.Width = br.ReadInt16();
         this.Height = br.ReadInt16();
         this.Size = Convert.ToInt32(this.Width) * Convert.ToInt32(this.Height) * 4;
         this.Data = br.ReadBytes(this.Size);
     }
     catch (Exception ex)
     {
     }
 }
Example #16
0
 public void Read(System.IO.BinaryReader source)
 {
     vectorS.X = source.ReadSingle();
     vectorS.Y = source.ReadSingle();
     vectorS.Z = source.ReadSingle();
     distS = source.ReadSingle();
     vectorT.X = source.ReadSingle();
     vectorT.Y = source.ReadSingle();
     vectorT.Z = source.ReadSingle();
     distT = source.ReadSingle();
     flags = source.ReadUInt32();
     value = source.ReadUInt32();
     name = Encoding.ASCII.GetString(source.ReadBytes(32)).Trim(new char[] { ' ', '\0' });
     next_texinfo = source.ReadUInt32();
 }
Example #17
0
        public ExportedLevel(System.IO.BinaryReader br)
        {
            string Header = br.ReadString();
            if (Header != "NSMBe4 Exported Level")
            {
                ErrorMessage = LanguageManager.Get("NSMBLevel", "InvalidFile");
                ErrorTitle = LanguageManager.Get("NSMBLevel", "Unreadable");
                return;
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > 1)
            {
                ErrorMessage = LanguageManager.Get("NSMBLevel", "OldVersion");
                ErrorTitle = LanguageManager.Get("NSMBLevel", "Unusable");
            }

            // This message conflitcs with the auto-backup and I think it's unecessary ~Piranhaplant
            LevelFileID = br.ReadUInt16();
            BGFileID = br.ReadUInt16();
            //if (SavedLevelFileID != destLevelFile.id) {
            //    DialogResult dr = MessageBox.Show(
            //        LanguageManager.Get("NSMBLevel", "Mismatch"),
            //        LanguageManager.Get("General", "Warning"),
            //        MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //    if (dr == DialogResult.No) {
            //        return;
            //    }
            //}

            int LevelFileLength = br.ReadInt32();
            LevelFile = br.ReadBytes(LevelFileLength);

            int BGFileLength = br.ReadInt32();
            BGFile = br.ReadBytes(BGFileLength);
        }
Example #18
0
 public PaletteImage(System.IO.BinaryReader br, bool compressed)
 {
     try
     {
         this.Width = br.ReadInt16();
         this.Height = br.ReadInt16();
         this.Size = Convert.ToInt32(this.Width) * Convert.ToInt32(this.Height);
         if (compressed)
         {
             this.Size = br.ReadUInt16();
         }
         this.Data = br.ReadBytes(this.Size);
     }
     catch (Exception ex)
     {
     }
 }
Example #19
0
        float mVolume; // category gain

        #endregion Fields

        #region Constructors

        //internal System.Collections.Generic.List<SoundHelper> instances = new System.Collections.Generic.List<SoundHelper>();
        public AudioCategory(System.IO.BinaryReader reader)
        {
            int strLen = reader.ReadInt16();
            byte[] bytes = reader.ReadBytes((int)strLen);
            mName = Encoding.ASCII.GetString(bytes);

            bool mBackgroundMusic = reader.ReadBoolean();
            int volume = reader.ReadInt32(); // 100 * db
            int mBehavior = reader.ReadInt32();
            int mMaxInstances = reader.ReadInt32();
            //GSGE.Debug.logMessage("category " + mName + " maxInstances = " + mMaxInstances);
            GSGE.Debug.assert(mMaxInstances > 0);

            // XACT stores it as a 2 decimal fixed point value
            double attenuation_in_db = volume / 100.0f;
            float gain = (float)Math.Pow(10, attenuation_in_db / 20.0);
            mVolume = gain;
        }
Example #20
0
        public Vector2 vTextureCoord; // (u, v) texture coordinate

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            vPosition.X = source.ReadSingle();
            vPosition.Y = source.ReadSingle();
            vPosition.Z = source.ReadSingle();
            vTextureCoord.X = source.ReadSingle();
            vTextureCoord.Y = source.ReadSingle();
            vLightmapCoord.X = source.ReadSingle();
            vLightmapCoord.Y = source.ReadSingle();
            if (vLightmapCoord.X < 0) vLightmapCoord.X = 0;
            if (vLightmapCoord.X > 1) vLightmapCoord.X = 1;
            if (vLightmapCoord.Y < 0) vLightmapCoord.Y = 0;
            if (vLightmapCoord.Y > 1) vLightmapCoord.Y = 1;
            vNormal.X = source.ReadSingle();
            vNormal.Y = source.ReadSingle();
            vNormal.Z = source.ReadSingle();
            if (vNormal.LengthSquared < 0.9f || vNormal.LengthSquared > 1.1f)
                throw new ApplicationException("Probably wrong format of vertex");
            color = source.ReadBytes(4);
        }
Example #21
0
        public uint width; // width of picture, must be a multiple of 8

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            var n = source.ReadBytes(16);
            name = Encoding.ASCII.GetString(n);
            for (int i=0; i<name.Length; ++i)
                if (name[i] == '\0')
                {
                    name = name.Substring(0,i);
                    break;
                }
            if (name[0] == '{')
            {
                alphaTest = true;
            }
            width = source.ReadUInt32();
            height = source.ReadUInt32();
            offset1 = source.ReadUInt32();
            offset2 = source.ReadUInt32();
            offset4 = source.ReadUInt32();
            offset8 = source.ReadUInt32();
        }
Example #22
0
        protected override void ReadFromStream(System.IO.BinaryReader reader)
        {
            base.ReadFromStream(reader);

            ushort nrPackets = reader.ReadUInt16();
            for (int i = 0; i < nrPackets; i++)
            {
                byte skipCount = reader.ReadByte();
                byte copyCount = reader.ReadByte();

                if (copyCount == 0)
                {
                    byte[] rgbData = reader.ReadBytes(256 * 3);
                    for (int j = 0; j < 256; j++)
                    {
                        Colors[j] = new FLCColor(rgbData[j * 3 + 0], rgbData[j * 3 + 1], rgbData[j * 3 + 2], 255);
                    }
                }
                else
                {
                }
            }
        }
Example #23
0
        public void Load( System.IO.BinaryReader reader )
        {
            this._unknownHeader = reader.ReadBytes( 4 );

            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );

            if ( cc != this._fourCC )
                throw new ApplicationException(
                    string.Format( "{0} not found in stream.\nActual: ({1})\nStream Position: {2}",
                    this._fourCC, cc.IntValue, reader.BaseStream.Position - 4 ) );

            this._unknown0 = reader.ReadInt32();
            this._unknown1 = reader.ReadInt32();
            this._width = reader.ReadInt32();
            this._height = reader.ReadInt32();
            this._unknown3 = reader.ReadBytes( 108 );
            this._textureData = reader.ReadBytes( this._width * this._height * 4 );
        }
Example #24
0
        public SoundHelper(AudioEngine audioengine, System.IO.BinaryReader reader)
        {
            _priority = reader.ReadInt32();

            int volume = reader.ReadInt32();
            double attenuation_in_db = volume / 100.0f;
            GSGE.Debug.assert(attenuation_in_db <= 0);
            gain = (float)Math.Pow(10, attenuation_in_db / 20.0);
            GSGE.Debug.assert(gain <= 1.0f);

            _pitch = (float)(reader.ReadInt32() / 100.0f);

            int trackCount = reader.ReadInt32();
            _tracks = new TrackHelper[trackCount];
            for (int i = 0; i < trackCount; i++)
            {
                _tracks[i] = new TrackHelper(reader);
            }

            int strLen = reader.ReadInt16();
            byte[] bytes = reader.ReadBytes((int)strLen);
            string catname = Encoding.ASCII.GetString(bytes);
            category = audioengine.GetCategory(catname);

            int rpcCount = reader.ReadInt32();
            rpcs = new RPCCurve[rpcCount];
            for (int i = 0; i < rpcCount; i++)
            {
                strLen = reader.ReadInt16();
                bytes = reader.ReadBytes((int)strLen);
                string rpc = Encoding.ASCII.GetString(bytes);

                rpcs[i] = audioengine.GetRPC(rpc);
            }

            strLen = reader.ReadInt16();
            bytes = reader.ReadBytes((int)strLen);
            effect = Encoding.ASCII.GetString(bytes);
        }
        private Boolean ReadValues(System.IO.BinaryReader r)
        {
            Int32 count;
              if(r.BaseStream.Length == 0) return false;
              count = Sql.Read7BitEncodedInt(r);

              if (count == 0) return true;

              for (Int32 i = 0; i < count; i++)
              {
            String    name  = r.ReadString();
            SqlDbType LType = (SqlDbType)r.ReadUInt16();
            Object    value = null;
            Int32 len;
            //Int32 lcid;
            //SqlCompareOptions co;

            switch (LType)
            {
              case SqlDbType.Bit      : value = new SqlBoolean(r.ReadBoolean()); break;
              case SqlDbType.TinyInt  : value = new SqlByte(r.ReadByte()); break;
              case SqlDbType.SmallInt : value = new SqlInt16((Int16)r.ReadInt16()); break;
              case SqlDbType.Int      : value = new SqlInt32((Int32)r.ReadInt32()); break;
              case SqlDbType.BigInt   : value = new SqlInt64(r.ReadInt64()); break;

              case SqlDbType.Binary   :
              case SqlDbType.VarBinary: len = r.ReadUInt16(); value = new SqlBytes(r.ReadBytes(len)); break;

              case SqlDbType.Char     :
              case SqlDbType.VarChar  : //value = new Sql.SqlAnsiString(r); break;
              case SqlDbType.NChar:
              case SqlDbType.NVarChar:
            //co = (SqlCompareOptions)r.ReadUInt16();
            //lcid = r.ReadInt32();
            //value = new SqlString(r.ReadString(), lcid, co);
            value = new SqlString(r.ReadString());
            break;

              case SqlDbType.DateTime     : value = new SqlDateTime(DateTime.FromBinary(r.ReadInt64())); break;
              case SqlDbType.SmallDateTime:
              case SqlDbType.Date         :
              case SqlDbType.DateTime2    : value = DateTime.FromBinary(r.ReadInt64()); break;
              case SqlDbType.Time         : value = TimeSpan.FromTicks(r.ReadInt64()); break;
              case SqlDbType.DateTimeOffset:
            DateTime LDateTime = DateTime.FromBinary(r.ReadInt64());
            value = new DateTimeOffset(LDateTime, TimeSpan.FromTicks(r.ReadInt64()));
            break;

              case SqlDbType.Decimal: value = new SqlDecimal(r.ReadDecimal()); break;
              case SqlDbType.Float  : value = new SqlDouble(r.ReadDouble()); break;
              // Not support SqlDbType.Image
              case SqlDbType.Money  : value = new SqlMoney(r.ReadDecimal()); break;
              case SqlDbType.Real   : value = new SqlSingle(r.ReadDouble()); break;
              case SqlDbType.SmallMoney: value = new SqlMoney(r.ReadDecimal()); break;
              // Not support SqlDbType.Structured
              // Not support SqlDbType.Text
              // Not support SqlDbType.Timestamp
              case SqlDbType.UniqueIdentifier: value = new SqlGuid(r.ReadString()); break;
              // Not support SqlDbType.Variant
              case SqlDbType.Xml:
            XmlReader rXml = XmlReader.Create(new System.IO.StringReader(r.ReadString()));
            value = new SqlXml(rXml);
            break;

              case SqlDbType.Udt:
            // TODO: Пока поддержа только TParams
            //String LTypeName = r.ReadString();
            //value = CreateUdtObject(LTypeName);
            //if (value is IBinarySerialize)
            //  (value as IBinarySerialize).Read(r);
            //else
            //  throw new Exception(String.Format("Невозможно прочитать данные типа UDT '{0}' - не поддерживается IBinarySerialize", LTypeName));
            value = new SqlUdt(r);
            break;

              default:
            throw new Exception(String.Format("Невозможно прочитать данные, тип '{0}' не поддерживается текущей версией {1}", LType.ToString(), this.GetType().Name));
              // Not support SqlDbType.NText
            }
            if (value != null) FData.Add(name, value);
              }

              return true;
        }
Example #26
0
        public static void getImportLevel(out byte[] levelFile, out byte[] bgFile, out string[] error, System.IO.BinaryReader br)
        {
            string Header = br.ReadString();
            levelFile = null; bgFile = null; error = null;
            if (Header != "NSMBe4 Exported Level") {
                error = new string[] { LanguageManager.Get("NSMBLevel", "InvalidFile") , LanguageManager.Get("NSMBLevel", "Unreadable") };
                return;
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > 1) {
                error = new string[] { LanguageManager.Get("NSMBLevel", "OldVersion"), LanguageManager.Get("NSMBLevel", "Unusable") };
                return;
            }

            // This message conflitcs with the auto-backup and I think it's unecessary ~Piranhaplant

            ushort SavedLevelFileID = br.ReadUInt16();
            ushort SavedBGFileID = br.ReadUInt16();
            //if (SavedLevelFileID != destLevelFile.id) {
            //    DialogResult dr = MessageBox.Show(
            //        LanguageManager.Get("NSMBLevel", "Mismatch"),
            //        LanguageManager.Get("General", "Warning"),
            //        MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //    if (dr == DialogResult.No) {
            //        return;
            //    }
            //}

            int LevelFileLength = br.ReadInt32();
            levelFile = br.ReadBytes(LevelFileLength);

            int BGFileLength = br.ReadInt32();
            bgFile = br.ReadBytes(BGFileLength);
        }
Example #27
0
        /// <summary>
        /// 読み取り用コンストラクタ
        /// </summary>
        /// <param name="reader"></param>
        public TopHeader(System.IO.BinaryReader reader)
        {
            reader.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);

            Signature = Encoding.UTF8.GetString(reader.ReadBytes(4));
            if (Signature != "pack")
                throw new Exception("パックファイルのフォーマットではありません");

            FileCount = reader.ReadUInt32();
            FilePathHeaderLength = reader.ReadUInt32();
            ignoreFiles = Encoding.UTF8.GetString(reader.ReadBytes((int)FilePathHeaderLength)).Split(new char[] { FilePathSeparator }, StringSplitOptions.RemoveEmptyEntries);
            HeaderSize = (uint)(4 + 8 + 8 + FilePathHeaderLength);
        }
Example #28
0
        /// <summary>
        /// Reads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public void Read(System.IO.BinaryReader reader)
        {
            Ident = reader.ReadBytes(16);

            // Check for magic number
            if (Ident[0] != MagicNumber[0] || Ident[1] != MagicNumber[1] || Ident[2] != MagicNumber[2] || Ident[3] != MagicNumber[3])
            {
                // Magic number not present, so it seems to be an invalid ELF file
                throw new NotSupportedException("This is not a valid ELF file");
            }

            Type = (Elf32FileType)reader.ReadUInt16();
            Machine = (Elf32MachineType)reader.ReadUInt16();
            Version = (Elf32Version)reader.ReadUInt32();
            EntryAddress = reader.ReadUInt32();
            ProgramHeaderOffset = reader.ReadUInt32();
            SectionHeaderOffset = reader.ReadUInt32();
            Flags = reader.ReadUInt32();
            ElfHeaderSize = reader.ReadUInt16();
            ProgramHeaderEntrySize = reader.ReadUInt16();
            ProgramHeaderNumber = reader.ReadUInt16();
            SectionHeaderEntrySize = reader.ReadUInt16();
            SectionHeaderNumber = reader.ReadUInt16();
            SectionHeaderStringIndex = reader.ReadUInt16();
        }
Example #29
0
        public static VoxelStruct ReadFromMagicaVoxel(System.IO.BinaryReader br)
        {
            VoxelStruct vs = new VoxelStruct ();

            // check out http://voxel.codeplex.com/wikipage?title=VOX%20Format&referringTitle=Home for the file format used below
            // we're going to return a voxel chunk worth of data
            //ushort[] data = new ushort[32 * 128 * 32];
            VectorInt4[] palette = null;
            Point[] points = null;

            string vox = new string(br.ReadChars(4));
            if (vox != "VOX ") {

                Debug.Log (vox);
                return vs;
            }

            int version = br.ReadInt32();
            vs.version = version;
            VectorInt3 box = new VectorInt3 ();
            bool subsample = false;

            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                // each chunk has an ID, size and child chunks
                string name = new string(br.ReadChars(4));
                int size = br.ReadInt32();
                int chunks = br.ReadInt32();
                // Debug.LogError (chunkName);
                // there are only 2 chunks we only care about, and they are SIZE and XYZI
                if(name == "MAIN"){
                    vs.main = new VoxelStruct.Main ();
                    vs.main.size = size;
                    vs.main.name = name;
                    vs.main.chunks = chunks;
                }
                if (name == "SIZE")
                {

                    box.x = br.ReadInt32();
                    box.y = br.ReadInt32();
                    box.z = br.ReadInt32();

                    vs.size = new VoxelStruct.Size ();
                    vs.size.size = 12;
                    vs.size.name = name;
                    vs.size.chunks = chunks;
                    vs.size.box = box;

                    if (box.x > 32 || box.y > 32) {
                        subsample = true;
                    }

                    br.ReadBytes(size - 4 * 3);
                }
                else if (name == "XYZI")
                {

                    // XYZI contains n voxels
                    int count = br.ReadInt32();
                    //int div = (subsample ? 2 : 1);
                    // each voxel has x, y, z and color index values
                    points = new Point[count];
                    for (int i = 0; i < points.Length; i++) {
                        points [i] = VoxelFormater.CreatePoint (br, subsample);//new Data (stream, subsample);
                    }

                }
                else if (name == "RGBA")
                {

                    int n = size / 4;
                    palette = new VectorInt4[n];
                    for (int i = 0; i < n; i++)
                    {
                        byte r = br.ReadByte();
                        byte g = br.ReadByte();
                        byte b = br.ReadByte();
                        byte a = br.ReadByte();
                        palette[i].x = r;
                        palette[i].y = g;
                        palette[i].z = b;
                        palette[i].w = a;
                    }

                    vs.rgba = new VoxelStruct.Rgba ();
                    vs.rgba.size = size;
                    vs.rgba.name = name;
                    vs.rgba.chunks = chunks;
                    vs.rgba.palette = palette;
                }
                else {
                    br.ReadBytes(size);   // read any excess bytes
                }
            }
            vs.datas = CreateVoxelDatas(points, palette);
            return vs;
        }
Example #30
0
        /// <summary>
        /// Читает P-объект из бинарного ридера, начиная с текущего места
        /// </summary>
        /// <param name="typ"></param>
        /// <param name="br"></param>
        /// <returns></returns>
        internal static object GetPO(PType typ, System.IO.BinaryReader br)
        {
            switch (typ.Vid)
            {
                case PTypeEnumeration.none: return null;
                case PTypeEnumeration.boolean: return br.ReadBoolean();
                case PTypeEnumeration.integer: return br.ReadInt32();
                case PTypeEnumeration.longinteger: return br.ReadInt64();
                case PTypeEnumeration.real: return br.ReadDouble();
                case [email protected]: return br.ReadByte();
                case PTypeEnumeration.fstring:
                    {
                        //int len = ((PTypeFString)typ).Length;
                        int size = ((PTypeFString)typ).Size;
                        byte[] arr = new byte[size];
                        arr = br.ReadBytes(size);
                        string s = System.Text.Encoding.Unicode.GetString(arr);
                        return s;
                    }
                case PTypeEnumeration.sstring:
                    {
                        int len = br.ReadInt32();
                        char[] chrs = br.ReadChars(len);
                        return new string(chrs);
                    }
                case PTypeEnumeration.record:
                    {
                        PTypeRecord r_tp = (PTypeRecord)typ;
                        object[] fields = new object[r_tp.Fields.Length];
                        for (int i = 0; i < r_tp.Fields.Length; i++)
                        {
                            fields[i] = GetPO(r_tp.Fields[i].Type, br);
                        }
                        return fields;
                    }
                case PTypeEnumeration.sequence:
                    {
                        PTypeSequence mts = (PTypeSequence)typ;
                        PType tel = mts.ElementType;
                        long llen = br.ReadInt64();
                        object[] els = new object[llen];
                        for (long ii = 0; ii < llen; ii++) els[ii] = GetPO(tel, br);
                        return els;
                    }
                case PTypeEnumeration.union:
                    {
                        PTypeUnion mtu = (PTypeUnion)typ;
                        int v = br.ReadByte();
                        PType mt = mtu.Variants[v].Type;
                        return new object[] { v, GetPO(mt, br) };
                    }

                default: throw new Exception("Err in TPath Get(): type is not implemented " + typ.Vid);
            }
        }