Пример #1
0
        public void ImportContent(PropertyStream stream)
        {
            this.Name        = stream.GetString(Hashes.FamilyName);
            this.FamilyFunds = stream.GetS32(Hashes.FamilyFunds);
            this.ExportTime  = stream.GetS64(Hashes.ExportTime);
            this.BioText     = stream.GetString(Hashes.BioText);
            this.LifetimeHappinessNotificationShown = stream.GetBoolean(Hashes.LifetimeHappinessNotificationShown);

            this.Members = new List <SimDescription>();
            PropertyStream sims   = stream.GetChild(Hashes.Members);
            int            scount = sims.GetS32(Hashes.SimDescriptionCount);

            for (uint i = 0; i < scount; i++)
            {
                PropertyStream child = sims.GetChild(i);
                SimDescription sim   = new SimDescription();
                sim.ImportContent(child);
                this.Members.Add(sim);
            }

            this.Relationships = new Dictionary <ulong, ulong>();
            PropertyStream relationships = stream.GetChild(Hashes.Relationships);
            uint           ucount        = relationships.GetU32(Hashes.NumRelationships);

            for (uint i = 0; i < ucount; i++)
            {
                PropertyStream child = relationships.GetChild(i);
                UInt64         a     = child.GetU64(Hashes.CurrentSimDescId);
                UInt64         b     = child.GetU64(Hashes.OtherSimDescId);
                this.Relationships.Add(a, b);
            }
        }
        //! Reads/Writes struct properties from/to a stream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            stream.SerializeStruct("Src", m_Src);
            stream.SerializeStruct("Dest", m_Dest);
            m_fSpeed = stream.Serialize<float>("Speed");
        }
Пример #3
0
        public void Write(Stream output)
        {
            output.WriteValueU32(4);

            PropertyStream root = new PropertyStream();

            this.HouseholdContents.ExportContent(root);
            root.Write(output);
        }
Пример #4
0
        public void Read(Stream input)
        {
            uint           version = input.ReadValueU32();
            PropertyStream root    = new PropertyStream();

            root.Read(input);

            this.HouseholdContents = new HouseholdContents();
            this.HouseholdContents.ImportContent(root);
        }
        /// <summary>
        /// This will get and parse named properties
        /// </summary>
        /// <param name="ps">A populated property stream</param>
        /// <returns>A list of NamedProperty objects</returns>
        private List <NamedProperty> ParseNamedProperties(PropertyStream ps)
        {
            NamedPropertyMapper  mapper = new NamedPropertyMapper(_namedPropertyParser);
            List <PropertyEntry> namedPropertyEntries = GetNamedProperties(ps);
            List <NamedProperty> namedProperties      = new List <NamedProperty>();

            foreach (var property in namedPropertyEntries)
            {
                namedProperties.Add(mapper.MapProperty(property));
            }
            return(namedProperties);
        }
Пример #6
0
        /// <summary>
        /// Populates the value of variable length properties
        /// </summary>
        private void PopulateVariableLengthProperties(PropertyStream ps, string storage)
        {
            var variableLengthReader = new VariableLengthStreamReader(_compoundFile);

            foreach (var item in ps.Data)
            {
                if (!TypeMapper.IsFixedLength(item.PropertyTag.Type))
                {
                    object obj = variableLengthReader.GetVariableLengthProperty(item, storage);
                    (item as VariableLengthPropertyEntry).VariableLengthData = obj;
                }
            }
        }
        /// <summary>
        /// This method returns the stream names of named properties
        /// </summary>
        /// <returns></returns>
        private List <PropertyEntry> GetNamedProperties(PropertyStream ps)
        {
            List <PropertyEntry> namedProperties = new List <PropertyEntry>();

            foreach (var item in ps.Data)
            {
                if (item.PropertyTag.ID >= 0x8000 && item.PropertyTag.ID <= 0x8FFF)
                {
                    namedProperties.Add(item);
                }
            }
            return(namedProperties);
        }
        public void ReadPropertyStreamDefaultTest()
        {
            parser  = new MsgParser(@"TestFiles\TestMessage-default.msg");
            msgFile = parser.Parse();
            PropertyStream ps = msgFile.PropertyStream;

            Assert.That(ps.Header, Is.Not.Null);
            Assert.That(ps.Header.NextRecipientId, Is.EqualTo(3));
            Assert.That(ps.Header.NextAttachmentId, Is.EqualTo(1));
            Assert.That(ps.Header.RecipientCount, Is.EqualTo(3));
            Assert.That(ps.Header.AttachmentCount, Is.EqualTo(1));
            Assert.That(ps.NumberOfProperties, Is.EqualTo(24));
        }
Пример #9
0
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_ChildEntityPath = stream.Serialize<string>("ChildEntityPath");

            if (m_ChildEntityPath.Length > 0)
            {
                m_ChildEntity = new Entity();
                m_ChildEntity.LoadFromXML(m_ChildEntityPath, null);
                m_ChildEntity.Init();
                AddChild(m_ChildEntity);
            }
        }
Пример #10
0
        public void ImportContent(PropertyStream stream)
        {
            PropertyStream child = stream.GetChild(HashHousehold);

            this.Household = new Household();
            this.Household.ImportContent(child);

            int count = stream.GetS32(HashInventoryCount);

            this.Inventories = stream.GetS32s(HashInventoryKeyIndices);

            if (this.Inventories.Length != count)
            {
                throw new Exception("count mismatch");
            }
        }
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_strTemplatePath = stream.Serialize<string>("TemplatePath");

            if (m_strTemplatePath.Length > 0)
            {
                LoadFromXML(m_strTemplatePath, this);
            }

            // serialize the instance data
            if(GetNumChildren() > 0)
            {
                m_InstanceData.m_Instance = GetChild(0);
                stream.SerializeStruct("InstanceData", m_InstanceData);
            }
        }
Пример #12
0
        /// <summary>
        /// The class will read and parse a property stream.
        /// See https://msdn.microsoft.com/en-us/library/ee203894(v=exchg.80).aspx for the structure.
        /// </summary>
        /// <param name="storage">Which storage to read from. If null, read from the top-level storage</param>
        /// <returns>A populated Property Stream</returns>
        internal PropertyStream ReadPropertyStream(string storage = null)
        {
            PropertyStream ps = new PropertyStream();

            ps.Header = new Headers.TopLevelHeader();
            CFStream propStream;

            byte[] data;
            if (storage == null) // we want the top-level property stream
            {
                propStream = _compoundFile.RootStorage.GetStream(PropertyStream.STREAM_NAME);
                data       = propStream.GetData();
                ps.Header.NextRecipientId  = BitConverter.ToInt32(data, 8);
                ps.Header.NextAttachmentId = BitConverter.ToInt32(data, 12);
                ps.Header.RecipientCount   = BitConverter.ToInt32(data, 16);
                ps.Header.AttachmentCount  = BitConverter.ToInt32(data, 20);
                ps.NumberOfProperties      = (data.Length - Headers.TopLevelHeader.HEADER_SIZE_BYTES) / PropertyEntry.SIZE_BYTES;
                ps.Data = new List <PropertyEntry>();
                for (int i = 0; i < ps.NumberOfProperties; i++)
                {
                    //start reading at 32
                    ps.Data.Add(ReadPropertyEntry(data.Skip(Headers.TopLevelHeader.HEADER_SIZE_BYTES).Skip(i * 16).Take(16).ToArray()));
                }
            }
            else //we want the attachment/recipient property stream
            {
                propStream            = _compoundFile.RootStorage.GetStorage(storage).GetStream(PropertyStream.STREAM_NAME);
                data                  = propStream.GetData();
                ps.NumberOfProperties = (data.Length - Headers.BaseHeader.HEADER_SIZE_BYTES) / PropertyEntry.SIZE_BYTES;
                ps.Data               = new List <PropertyEntry>();
                for (int i = 0; i < ps.NumberOfProperties; i++)
                {
                    //start reading at 8
                    ps.Data.Add(ReadPropertyEntry(data.Skip(Headers.BaseHeader.HEADER_SIZE_BYTES).Skip(i * 16).Take(16).ToArray()));
                }
            }
            PopulateVariableLengthProperties(ps, storage);
            return(ps);
        }
Пример #13
0
        //! recursive read from XML
        void ReadEntity(XmlTextReader xmlReader, Entity parent)
        {
            Entity entity = null;
            string entityTypeName = xmlReader.Name;

            if (parent != null)
            {
                // create entity
                string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
                string fullTypeName = assemblyName + "." + entityTypeName;
                entity = Assembly.GetExecutingAssembly().CreateInstance(fullTypeName) as Entity;
            }
            else
            {
                string thisTypeName = GetType().Name;
                Debug.Assert(thisTypeName == entityTypeName, "Trying to load an entity of type " + entityTypeName + " into an " + thisTypeName);
                entity = this;
            }

            // read children
            while(xmlReader.Read())
            {
                if(xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                else if(xmlReader.NodeType == XmlNodeType.Element)
                {
                    if (xmlReader.Name == "Properties")
                    {
                        // read properties
                        PropertyStream stream = new PropertyStream();
                        stream.ReadFromXML(xmlReader, null);
                        entity.Serialize(stream);
                    }
                    else
                    {
                        ReadEntity(xmlReader, entity);
                    }
                }
            } // end while

            if(parent != null)
            {
                // Add entity after it has been serialized to ensure proper event handling inside of AddChild()
                parent.AddChild(entity);
            }
        }
Пример #14
0
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_bEnabled = stream.Serialize<bool>("Enabled");
            m_bVisible = stream.Serialize<bool>("Visible");

            stream.SerializeReference("Visitor", m_VisitorRef);
        }
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            stream.SerializeReference("Material", MaterialRef);
        }
Пример #16
0
 public void ExportContent(PropertyStream stream)
 {
     throw new NotImplementedException();
 }
Пример #17
0
 //! serializes the entity to/from a PropertyStream
 public override void Serialize(PropertyStream stream)
 {
     base.Serialize(stream);
 }
Пример #18
0
 //! Reads/Writes struct properties from/to a stream
 public override void Serialize(PropertyStream stream)
 {
     base.Serialize(stream);
     m_AutoStart = stream.Serialize<bool>("AutoStart");
 }
Пример #19
0
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_strPath = stream.Serialize<string>("Path");
        }
Пример #20
0
 //! serializes the entity to/from a PropertyStream
 public virtual void Serialize(PropertyStream stream)
 {
     m_ID = stream.Serialize<uint>("ID");
     m_Name = stream.Serialize<string>("Name");
 }
 //! serialize the instance data
 public override void Serialize(PropertyStream stream)
 {
     m_Instance.Serialize(stream);
 }
Пример #22
0
 public void ImportContent(PropertyStream stream)
 {
     this.FirstName = stream.GetString(Hashes.FirstName);
     this.LastName  = stream.GetString(Hashes.LastName);
     this.Flags     = stream.GetU32(Hashes.Flags);
 }
Пример #23
0
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_vPosition = stream.Serialize<Vector2>("Position");
            m_fRotation = stream.Serialize<float>("Rotation");
            m_vScale = stream.Serialize<Vector2>("Scale");
            m_vCenter = stream.Serialize<Vector2>("Center");
            m_BoundingBox = stream.Serialize<BoundingBox>("BBox");
            m_bHFlip = stream.Serialize<bool>("HFlip");
            m_bVFlip = stream.Serialize<bool>("VFlip");
        }
Пример #24
0
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_vPosition = stream.Serialize<Vector3>("Position");
            m_vRotation = stream.Serialize<Vector3>("Rotation");
            m_vScale = stream.Serialize<Vector3>("Scale");
            m_vCenter = stream.Serialize<Vector3>("Center");
            m_BoundingBox = stream.Serialize<BoundingBox>("BBox");
        }
Пример #25
0
        //! serializes the entity to/from a PropertyStream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            m_FOV = stream.Serialize<float>("FOV");
            m_ZNear = stream.Serialize<float>("ZNear");
            m_ZFar = stream.Serialize<float>("ZFar");
            m_eType = (E_Type)stream.Serialize<int>("Projection");
            m_vUpVector = stream.Serialize<Vector3>("UpVector");
        }
Пример #26
0
        //! Reads/Writes struct properties from/to a stream
        public override void Serialize(PropertyStream stream)
        {
            base.Serialize(stream);

            bool bLighting = stream.Serialize<bool>("Lighting");
            SetFlag(E_Flag.MF_Lighting, bLighting);

            m_Color = stream.Serialize<Color>("Color");
            m_Color.A = (byte)(stream.Serialize<float>("Alpha")*255.0f);

            stream.SerializeArray<string>("Textures", m_strTextures);
            for(int i=0; i<m_strTextures.Count; ++i)
            {
                if(m_strTextures[i].Length > 0)
                {
                    // remove extension
                    string path = m_strTextures[i].Split('.')[0];
                    m_aTextures[i] = Engine.Instance().Content.Load<Texture2D>(path);
                }
                else
                {
                    m_aTextures[i] = null;
                }
            }
        }