Exemple #1
0
        public static Event ReadFrom(Area area, BinaryReader br)
        {
            var evnt = new Event(area);

            evnt.EntityId = br.ReadUInt64();
            evnt.Name     = br.ReadWString();
            evnt.Position = br.ReadVector3F_XYZ();
            var shapeCount = br.ReadByte();

            evnt.ShapeType = br.ReadInt32();

            evnt.Shapes = new List <Shape>(shapeCount);
            for (var i = 0; i < shapeCount; ++i)
            {
                var shape = Shape.ReadFrom(br);
                evnt.Shapes.Add(shape);
            }

            evnt.Type = (EventType)br.ReadInt32();

            var parameterCount = br.ReadByte();

            evnt.Parameters = new List <EntityParameter>(parameterCount);
            for (var i = 0; i < parameterCount; ++i)
            {
                var param = EntityParameter.ReadFrom(br);
                evnt.Parameters.Add(param);
            }

            return(evnt);
        }
Exemple #2
0
        /// <summary>
        /// Creates and returns copy of parameter.
        /// </summary>
        /// <returns></returns>
        public EntityParameter Copy()
        {
            var param = new EntityParameter();

            param.IsDefault  = this.IsDefault;
            param.Type       = this.Type;
            param.SignalType = this.SignalType;
            param.Name       = this.Name;
            param.Xml        = this.Xml;

            return(param);
        }
Exemple #3
0
        public static EntityParameter ReadFrom(BinaryReader br)
        {
            var param = new EntityParameter();

            param.IsDefault  = br.ReadBoolean();
            param.Type       = (ParameterType)br.ReadInt32();
            param.SignalType = (SignalType)br.ReadInt32();
            param.Name       = br.ReadWString();
            param.Xml        = br.ReadWString();

            return(param);
        }
Exemple #4
0
        public static Prop ReadFrom(Area area, BinaryReader br)
        {
            var prop = new Prop(area);

            prop.Id       = br.ReadInt32();
            prop.EntityId = br.ReadUInt64();
            prop.Name     = br.ReadWString();
            prop.Position = br.ReadVector3F_XYZ();
            var shapeCount = br.ReadByte();

            prop.ShapeType = br.ReadInt32();

            prop.Shapes = new List <Shape>(shapeCount);
            for (var i = 0; i < shapeCount; ++i)
            {
                var shape = Shape.ReadFrom(br);
                prop.Shapes.Add(shape);
            }

            prop.IsCollision   = br.ReadBoolean();
            prop.FixedAltitude = br.ReadBoolean();
            prop.Scale         = br.ReadSingle();
            prop.Rotation      = br.ReadSingle();
            prop.BottomLeft    = br.ReadVector3F_XZY();
            prop.TopRight      = br.ReadVector3F_XZY();
            prop.ColorOverride = br.ReadColor();

            for (var i = 0; i < ColorCount; ++i)
            {
                prop.Colors[i] = br.ReadColor();
            }

            prop.Title = br.ReadWString();
            prop.State = br.ReadWString();

            var parameterCount = br.ReadByte();

            prop.Parameters = new List <EntityParameter>(parameterCount);
            for (var i = 0; i < parameterCount; ++i)
            {
                var param = EntityParameter.ReadFrom(br);
                prop.Parameters.Add(param);
            }

            prop.LoadData();

            return(prop);
        }
Exemple #5
0
        public static Prop ReadFrom(Area area, BinaryReader br)
        {
            var areaVersion = 201;

            if (area != null)
            {
                areaVersion = area.Version;
            }

            var kr165Hack = false;

            var prop = new Prop(area);

            if (areaVersion > 200)
            {
                prop.Id = br.ReadInt32();
            }

            prop.EntityId = br.ReadUInt64();
            prop.Name     = br.ReadWString();
            prop.Position = br.ReadVector3F_XYZ();
            var shapeCount = br.ReadByte();

            prop.ShapeType = br.ReadInt32();

            prop.Shapes = new List <Shape>(shapeCount);
            if (areaVersion == 200)
            {
                for (var i = 0; i < shapeCount; ++i)
                {
                    var shape = Shape.ReadLegacyFrom(br);
                    prop.Shapes.Add(shape);
                }

                prop.Unk1 = br.ReadByte();

                // KR165 has a different structure for version 200 than KR72,
                // and unfortunately we have no real way to check for this
                // version looking at just the prop and its area. To work
                // around this, we're gonna check the next byte for 0 here.
                // Since there is no prop with the id 0, and the id is stored
                // in little endian, the next byte should be != 0 if it's
                // the KR72 structure. Meanwhile, the KR165 structure appears
                // to always have a 0 here, possibly for padding. If we find
                // this 0 byte, we're gonna read it, and we're gonna use that
                // information to also read the title, further down, which
                // would otherwise require version 201+.
                // If this part doesn't work correctly, parsing KR165 areas
                // will usually throw an exception on parsing the shapes
                // above, because the previous prop in the loop wasn't parsed
                // correctly, and the shapes have some sanity checks.
                var unk2 = br.ReadByte();
                br.BaseStream.Seek(-1, SeekOrigin.Current);
                kr165Hack = (unk2 == 0) || (prop.Unk1 == 0 && unk2 == 1);

                if (kr165Hack)
                {
                    prop.Unk2 = br.ReadByte();
                }

                prop.Id = br.ReadInt32();
            }
            else
            {
                for (var i = 0; i < shapeCount; ++i)
                {
                    var shape = Shape.ReadFrom(br);
                    prop.Shapes.Add(shape);
                }

                prop.IsCollision   = br.ReadBoolean();
                prop.FixedAltitude = br.ReadBoolean();
            }

            prop.Scale    = br.ReadSingle();
            prop.Rotation = br.ReadSingle();

            if (areaVersion > 200)
            {
                prop.BottomLeft = br.ReadVector3F_XZY();
                prop.TopRight   = br.ReadVector3F_XZY();
            }

            prop.ColorOverride = br.ReadColor();
            for (var i = 0; i < ColorCount; ++i)
            {
                prop.Colors[i] = br.ReadColor();
            }

            if (areaVersion > 200 || kr165Hack)
            {
                prop.Title = br.ReadWString();
            }

            prop.State = br.ReadWString();

            var parameterCount = br.ReadByte();

            prop.Parameters = new List <EntityParameter>(parameterCount);
            for (var i = 0; i < parameterCount; ++i)
            {
                var param = EntityParameter.ReadFrom(br);
                prop.Parameters.Add(param);
            }

            prop.LoadData();

            return(prop);
        }