Esempio n. 1
0
        /// <summary>
        /// Reads BSP info from Stream Reader
        /// </summary>
        /// <param name="reader">Stream Reader to read from</param>
        public static BSPInfo ReadInfo(BinaryReader reader)
        {
            BSPInfo info = new BSPInfo();

            //Read identifier
            info.Identifier = reader.ReadInt32();

            //Validate identifier
            //Little-endian "VBSP"   0x50534256
            if (info.Identifier != 0x50534256)
            {
                throw new FileFormatException();
            }

            //Read version
            info.Version = reader.ReadInt32();

            //Read game lumps
            info.Lumps = new Lump[64];

            for (int i = 0; i < 64; i++)
            {
                info.Lumps[i] = ReadLump(reader);
            }

            //Read map revision number
            info.MapRevision = reader.ReadInt32();

            //Return value
            return(info);
        }
Esempio n. 2
0
        /// <summary>
        /// Writes BSP File header
        /// </summary>
        /// <param name="w">Binary Writer to write to</param>
        /// <param name="i">Informations about BSP info</param>
        public static void WriteHeader(BinaryWriter w, BSPInfo i)
        {
            //Set offset
            w.BaseStream.Position = 0;

            //Write header informations
            w.Write(i.Identifier);
            w.Write(i.Version);
            //Write lump informations
            foreach (Lump l in i.Lumps)
            {
                WriteLump(w, l);
            }
            //Write map revision number
            w.Write(i.MapRevision);
        }