Exemple #1
0
        public Sprite(System.IO.BinaryReader r)
        {
            // 2 Load texture
            //ushort width = r.ReadUInt16();
            //ushort height = r.ReadUInt16();
            //byte[] colorData = r.ReadBytes(width * height * 4);
            //texture = new Texture2D(Game1.graphics.GraphicsDevice, width, height);
            //texture.SetData(colorData);

            // 3 Load position
            position.X = r.ReadSingle();
            position.Y = r.ReadSingle();

            // 4 Load rotation
            rotation = r.ReadSingle();

            // 5 Load textureKey
            byte length = r.ReadByte();
            textureKey = new string(r.ReadChars(length));
            baseTexture = Repainter.GetTextureCopy(Library.textures[textureKey]);
            texture = baseTexture;

            // 6 Load layer
            layer = r.ReadSingle();

            // Set other data
            baseOrigin = new Vector2(baseTexture.Width / 2, baseTexture.Height / 2);
            origin = baseOrigin;
            needsRedraw = true;
            identifier = SaveFileManager.SaveTypeIdentifier.Sprite;
            color = Color.White;
            IsDead = false;

            Console.WriteLine(ToString() + " loaded at position: " + position.ToString());
        }
Exemple #2
0
        public void Load( System.IO.BinaryReader reader )
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );

            if ( cc != this._fourCC )
                throw new ApplicationException( this._fourCC.ToString() + " not found in stream" );

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

            if ( cc != this._compFourCC )
                throw new ApplicationException( this._compFourCC.ToString() + " not found in stream" );

            this._sizeComp = reader.ReadInt32();
            this._sizeDecomp = reader.ReadInt32();
            this._dataComp = reader.ReadBytes( this._sizeComp );

            reader.BaseStream.Seek( 0 - this._sizeComp, System.IO.SeekOrigin.Current );
            this._dataDecomp = new byte[this._sizeDecomp];
        }
        //16+имя
        public PackContentHeader(System.IO.BinaryReader br, int _number)
        {
            this.number = _number;
            int length = br.ReadInt32();
            name = new string(br.ReadChars(length + 1));
            offset = br.ReadInt32();
            loadedformat = br.ReadInt32();
            headersize = br.ReadInt32();

            //когдато я бы л молодой и глупый и теперь пишу этот кастыль
            if (loadedformat == ElementType.MeshOptimazedForStore || loadedformat == ElementType.MeshOptimazedForLoading)
            {
                mh = new MeshContentadditionalheader();
                mh.load(br, loadedformat);
            }
            else
            {
                size = br.ReadInt32();
            }
        }
Exemple #4
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 );
        }
Exemple #5
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 PTypeEnumeration.@byte: 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);
            }
        }
        private void Mod_LoadEntityString(SDHeader header, ref CModel.SModel _SModel, ref System.IO.BinaryReader br)
        {
            if (header.lumps[LUMP_ENTITIES].filelen > MAX_MAP_ENTSTRING)
            {
                // entity string exceeds maximum
                _SModel.map_entitystring = null;
                return;
            }

            br.BaseStream.Seek(header.lumps[LUMP_ENTITIES].fileofs, System.IO.SeekOrigin.Begin);
            if (br.BaseStream.Position < (header.lumps[LUMP_ENTITIES].fileofs + header.lumps[LUMP_ENTITIES].filelen))
            {
                _SModel.map_entitystring = CShared.Com_ToString(br.ReadChars(header.lumps[LUMP_ENTITIES].filelen));
                _SModel.map_entitystring = _SModel.map_entitystring.Replace("\r", "").Replace("\n", "\r\n");
            }
            else
            {
                _SModel.map_entitystring = null;
            }
        }
        private void Mod_LoadTexinfo(SDHeader header, ref CModel.SModel _SModel, ref System.IO.BinaryReader br)
        {
            List<CModel.SMTexInfo> MTexInfo = new List<CModel.SMTexInfo>();

            br.BaseStream.Seek(header.lumps[LUMP_TEXINFO].fileofs, System.IO.SeekOrigin.Begin);
            while (br.BaseStream.Position < (header.lumps[LUMP_TEXINFO].fileofs + header.lumps[LUMP_TEXINFO].filelen))
            {
                CModel.SMTexInfo _MTexInfo;
                string texture;
                int next;

                _MTexInfo.vecs = new Microsoft.Xna.Framework.Vector4[2];
                for (int i = 0; i < 2; i++)
                {
                    _MTexInfo.vecs[i].X = br.ReadSingle();
                    _MTexInfo.vecs[i].Y = br.ReadSingle();
                    _MTexInfo.vecs[i].Z = br.ReadSingle();
                    _MTexInfo.vecs[i].W = br.ReadSingle();
                }

                _MTexInfo.flags = (ESurface)br.ReadInt32();
                br.ReadInt32(); // value
                texture = CShared.Com_ToString(br.ReadChars(32));
                texture = "textures/" + texture;

                next = br.ReadInt32();
                if (next > 0)
                    _MTexInfo.next = next;
                else
                    _MTexInfo.next = 0;

                _MTexInfo.image = CProgram.gQ2Game.gCMain.gCImage.FindImage(texture, out _MTexInfo.Width, out _MTexInfo.Height, CImage.EImageType.IT_WALL);

                // TODO
                //out->image = GL_FindImage (name, it_wall);
                //if (!out->image)
                //{
                //    ri.Con_Printf (PRINT_ALL, "Couldn't load %s\n", name);
                //    out->image = r_notexture;
                //}

                _MTexInfo.numframes = 0;

                MTexInfo.Add(_MTexInfo);
            }

            // count animation frames
            for (int i = 0; i < MTexInfo.Count; i++)
            {
                CModel.SMTexInfo _MTexInfo = MTexInfo[i];
                _MTexInfo.numframes = 1;

                for (int step = _MTexInfo.next; step != 0 && step != i; step = MTexInfo[step].next)
                {
                    _MTexInfo.numframes++;
                }

                MTexInfo[i] = _MTexInfo;
            }

            _SModel.numtexinfo = MTexInfo.Count;
            _SModel.texinfo = MTexInfo.ToArray();
        }
Exemple #8
0
        public void Load( System.IO.BinaryReader reader )
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );

            if ( cc != this._fourCC )
                throw new ApplicationException( this._fourCC.ToString() + " not found in stream" );

            this._size = reader.ReadInt32();
            long finalPosition = reader.BaseStream.Position + this._size;
            this._mapPart = OEIShared.Utils.CommonUtils.ConvertZeroTerminatedBytesToString( reader.ReadBytes( 128 ) ).TrimEnd( '\0' );

            this._ddsGroup = new DDSGroup(reader);

            for( int i = 0; i < 18; i++ )
                this._texVectors[i] = reader.ReadSingle();

            this._vertexCount = reader.ReadInt32();
            this._triangleCount = reader.ReadInt32();

            this._vertices = new Vertex[this._vertexCount];
            for ( int i = 0; i < this._vertexCount; i++ )
                this._vertices[i] = new Vertex( reader );

            this._triangles = new Triangle[this._triangleCount];
            for ( int i = 0; i < this._triangleCount; i++ )
                this._triangles[i] = new Triangle( reader );

            this._ddsGroup.Load( reader );
            this._ddsGroup.FirstVertex = this._vertices[0];

            this._unkownDataSize = (int)( finalPosition - reader.BaseStream.Position );
            if ( this._unkownDataSize > 0 )
                this._unknownData = reader.ReadBytes( this._unkownDataSize );
        }
		public string ReadString(int bytes, System.IO.BinaryReader rdr)
		{
			char[] buffer;
			if (bytes == 0 ||bytes >rdr.BaseStream.Length-rdr.BaseStream.Position)
				return null;
			try 
			{			
				buffer = rdr.ReadChars(bytes);
			}
			catch(System.IO.EndOfStreamException)
			{
				return null;
			}
			string str = new string(buffer);

			if (str.IndexOf('\0') >= 0)
				str = str.Substring(0, str.IndexOf('\0'));

			return str;
		}
Exemple #10
0
        /// <summary>
        /// Load the TRN direct from a binary reader stream.
        /// Stream must be aligned with the beginning of a TRN
        /// </summary>
        /// <param name="reader"></param>
        public void Load( System.IO.BinaryReader reader )
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );

            if ( cc != this._fourCC )
                throw new ApplicationException( this._fourCC.ToString() + " not found in stream" );

            this._majorFileVersion = reader.ReadUInt16();
            this._minorFileVersion = reader.ReadUInt16();
            this._numPackets = reader.ReadInt32();

            PacketPointer[] packetPointers = new PacketPointer[this._numPackets];
            for ( int i = 0; i < this._numPackets; i++ )
            {
                packetPointers[i].Type = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );
                packetPointers[i].Address = reader.ReadInt32();
            }

            int curTRRNIndex = 0;
            int curTRRNX = 0;
            int curTRRNY = 0;
            // use the above info to find the TRWH
            foreach( PacketPointer ptr in packetPointers )
            {
                if ( ptr.Type == new OEIShared.Utils.FourCC( "TRWH" ) )
                {
                    if ( this._TRWH == null )
                    {
                        reader.BaseStream.Position = ptr.Address;
                        this._TRWH = new TRWH( reader );
                        this._TRRNs = new TRRN[ this.Width, this.Height ];
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show( "Ignoring Additional TRWH" );
                    }
                }
                else if ( ptr.Type == new OEIShared.Utils.FourCC( "TRRN" ) )
                {
                    if ( this._TRWH == null )
                        throw new ApplicationException( "TRRN found but no TRWH. Can't load TRRN." );
                    else
                    {
                        curTRRNX = curTRRNIndex % Width;
                        curTRRNY = int.Parse( Math.Floor( curTRRNIndex / (double)Width ).ToString() );
                        curTRRNIndex++;

                        reader.BaseStream.Position = ptr.Address;
                        this._TRRNs[curTRRNX, curTRRNY] = new TRRN( reader );
                        this._vertices.AddRange(this._TRRNs[curTRRNX, curTRRNY].Vertices);
                        this._ddsGroups.Add(this._TRRNs[curTRRNX, curTRRNY].DDSGroup);
                    }
                }
                else if ( ptr.Type == new OEIShared.Utils.FourCC( "ASWM" ) )
                {
                    reader.BaseStream.Position = ptr.Address;
                    this._ASWMs.Add( new ASWM( reader ) );
                }
            }
        }
Exemple #11
0
 public static string ReadCString(System.IO.BinaryReader bin)
 {
     uint len = bin.ReadUInt32();
     return new string(bin.ReadChars((int)len));
 }
Exemple #12
0
 internal RisenPakFile(System.IO.BinaryReader bR, RisenPakFilePart P, RisenPak Container)
 {
     base.name = string.Empty;
     base.parent = P;
     int l = bR.ReadInt32();
     if (l != 0)
         l++;
     base.name = new string(bR.ReadChars(l));
     offset = bR.ReadInt64();
     base.TimeCreated = bR.ReadInt64();
     base.TimeLastAccessed = bR.ReadInt64();
     base.TimeLastModified = bR.ReadInt64();
     base.Attributes = (RisenPakAttributes)bR.ReadUInt32() | RisenPakAttributes.RisenPakAttribute_Packed;
     encrypt = (RisenPakEncryption)bR.ReadUInt32();
     Compression = (RisenPakCompression)bR.ReadUInt32();
     compSize = bR.ReadInt32();
     uncompSize = bR.ReadInt32();
     m_Stream = null;
     _init(Container);
 }
Exemple #13
0
 internal RisenPakDirectory(System.IO.BinaryReader bR, RisenPakFilePart P2, RisenPak Container)
 {
     base.name = string.Empty;
     base.parent = P2;
     int l = bR.ReadInt32();
     if (l != 0)
         l++;
     base.name = new string(bR.ReadChars(l));
     base.TimeCreated = bR.ReadInt64();
     base.TimeLastAccessed = bR.ReadInt64();
     base.TimeLastModified = bR.ReadInt64();
     base.Attributes = (RisenPakAttributes)bR.ReadUInt32() | RisenPakAttributes.RisenPakAttribute_Packed;
     int count = bR.ReadInt32();
     children = new List<RisenPakFilePart>();
     for (int i = 0; i < count; i++)
     {
         RisenPakAttributes attrib = (RisenPakAttributes)bR.ReadUInt32();
         if ((attrib & RisenPakAttributes.RisenPakAttribute_Directory) == RisenPakAttributes.RisenPakAttribute_Directory)
             children.Add(new RisenPakDirectory(bR, this, Container));
         else children.Add(new RisenPakFile(bR, this, Container));
     }
     _init(Container);
 }
        //16+имя
        public static void loadbaseheader(System.IO.BinaryReader br, HeaderInfo hi)
        {
            int length = br.ReadInt32();
            hi.name = new string(br.ReadChars(length + 1));

            hi.offset = br.ReadInt32();
            hi.loadedformat = br.ReadInt32();
            hi.headersize = br.ReadInt32();
            hi.forsavingformat = hi.loadedformat;
        }
Exemple #15
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;
        }
Exemple #16
0
        public void Load( System.IO.BinaryReader reader )
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );

            if ( cc != this._fourCC )
                throw new ApplicationException( this._fourCC.ToString() + " not found in stream" );

            this._size = reader.ReadInt32();
            this._width = reader.ReadInt32();
            this._height = reader.ReadInt32();
            this._padding = reader.ReadInt32();
        }
Exemple #17
0
 public void Load( System.IO.BinaryReader reader )
 {
     this.Type = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );
     this.Address = reader.ReadInt32();
 }