示例#1
0
        public Area(string path)
        {
            this.Props = new List<Prop>();
            this.Events = new List<Event>();

            using (var fs = new FileStream(path, FileMode.Open))
            using (var br = new BinaryReader(fs))
            {
                Version = br.ReadInt16();
                if (Version < 202)
                    throw new Exception("Invalid file version.");

                br.Skip(0x02); // Unk
                br.Skip(0x04); // Unk
                AreaId = br.ReadInt16();
                var regionId = br.ReadInt16(); // Unk
                Server = br.ReadUnicodeString();
                Name = br.ReadUnicodeString();
                br.Skip(0x10); // Unk
                var eventCount = br.ReadInt32();
                var propCount = br.ReadInt32();
                br.Skip(0x14); // Unk
                X1 = br.ReadSingle();
                br.Skip(0x04); // Unk
                Y1 = br.ReadSingle();
                br.Skip(0x0C); // Unk
                X2 = br.ReadSingle();
                br.Skip(0x04); // Unk
                Y2 = br.ReadSingle();
                br.Skip(0x0C); // Unk
                if (Version == 203)
                    br.Skip(0x04); // Unk

                var ver = br.ReadInt16();
                br.Skip(0x02); // Unk
                var propCountCheck = br.ReadInt32();
                if (ver < 202 || propCount != propCountCheck)
                    throw new Exception("Reading error.");

                for (int i = 0; i < propCount; ++i)
                {
                    var prop = new Prop();

                    prop.ClassId = br.ReadInt32();
                    prop.PropId = br.ReadInt64();
                    prop.Name = br.ReadUnicodeString();
                    prop.X = br.ReadSingle();
                    prop.Y = br.ReadSingle();
                    br.Skip(0x04); // Unk (Z?)
                    var shapeCount = br.ReadByte();
                    br.Skip(0x04); // Unk

                    for (int j = 0; j < shapeCount; ++j)
                    {
                        var dirX1 = br.ReadSingle();
                        var dirX2 = br.ReadSingle();
                        var dirY1 = br.ReadSingle();
                        var dirY2 = br.ReadSingle();
                        var lenX = br.ReadSingle();
                        var lenY = br.ReadSingle();
                        br.Skip(0x04); // Unk
                        var posX = br.ReadSingle();
                        var posY = br.ReadSingle();
                        br.Skip(0x10); // Unk

                        prop.Shape.AddRange(GetShapeLines(dirX1, dirX2, dirY1, dirY2, lenX, lenY, posX, posY));
                    }

                    prop.Solid = (br.ReadByte() != 0);
                    br.ReadByte(); // Unk
                    prop.Scale = br.ReadSingle();
                    prop.Direction = br.ReadSingle();
                    br.Skip(0x40); // Unk
                    br.ReadUnicodeString(); // title
                    br.ReadUnicodeString(); // state
                    var parameterCount = br.ReadByte();
                    for (int k = 0; k < parameterCount; ++k)
                    {
                        var def = br.ReadByte();
                        var eventType = br.ReadInt32();
                        var signalType = br.ReadInt32();
                        var name = br.ReadUnicodeString();
                        var xml = br.ReadUnicodeString();

                        // Add identical parameters only once
                        var exists = false;
                        foreach (var param in prop.Parameters)
                        {
                            if (param.EventType == eventType && param.SignalType == signalType && param.Name == name && param.XML == xml)
                            {
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                            prop.Parameters.Add(new PropParameter(eventType, signalType, name, xml));
                    }

                    // Filter Tir anniversary props
                    // TODO: Use prop db to check for the feature?
                    if ((Name == "field_Tir_S_aa" || Name == "field_Tir_S_ba") && prop.ClassId > 44000)
                        continue;

                    this.Props.Add(prop);
                }

                for (int i = 0; i < eventCount; ++i)
                {
                    var ev = new Event();
                    this.Events.Add(ev);

                    ev.EventId = br.ReadInt64();
                    ev.Name = br.ReadUnicodeString();
                    ev.X = br.ReadSingle();
                    ev.Y = br.ReadSingle();
                    br.Skip(0x04); // Unk (Z?)
                    var shapeCount = br.ReadByte();
                    br.Skip(0x04); // Unk

                    for (int j = 0; j < shapeCount; ++j)
                    {
                        var dirX1 = br.ReadSingle();
                        var dirX2 = br.ReadSingle();
                        var dirY1 = br.ReadSingle();
                        var dirY2 = br.ReadSingle();
                        var lenX = br.ReadSingle();
                        var lenY = br.ReadSingle();
                        br.Skip(0x04); // Unk
                        var posX = br.ReadSingle();
                        var posY = br.ReadSingle();
                        br.Skip(0x10); // Unk

                        ev.Shape.AddRange(GetShapeLines(dirX1, dirX2, dirY1, dirY2, lenX, lenY, posX, posY));
                    }

                    ev.EventType = br.ReadInt32();
                    var parameterCount = br.ReadByte();
                    for (int k = 0; k < parameterCount; ++k)
                    {
                        var def = br.ReadByte();
                        var eventType = br.ReadInt32();
                        var signalType = br.ReadInt32();
                        var name = br.ReadUnicodeString();
                        var xml = br.ReadUnicodeString();

                        ev.Parameters.Add(new PropParameter(eventType, signalType, name, xml));
                    }
                }
            }
        }
示例#2
0
文件: Area.cs 项目: LordTaish/rewpa
        private Prop ReadProp(BinaryReader br)
        {
            var prop = new Prop();

            prop.ClassId = br.ReadInt32();
            prop.PropId  = br.ReadInt64();
            prop.Name    = br.ReadUnicodeString();
            prop.X       = br.ReadSingle();
            prop.Y       = br.ReadSingle();
            br.Skip(0x04);             // Unk (Z?)
            var shapeCount = br.ReadByte();

            br.Skip(0x04);             // Unk

            for (int j = 0; j < shapeCount; ++j)
            {
                var shape = new Shape();
                shape.DirX1 = br.ReadSingle();
                shape.DirX2 = br.ReadSingle();
                shape.DirY1 = br.ReadSingle();
                shape.DirY2 = br.ReadSingle();
                shape.LenX  = br.ReadSingle();
                shape.LenY  = br.ReadSingle();
                var shapeType = br.ReadInt32();
                shape.PosX = br.ReadSingle();
                shape.PosY = br.ReadSingle();
                br.Skip(0x10);                 // Unk

                prop.Shapes.Add(shape);
            }

            prop.Solid = (br.ReadByte() != 0);
            br.ReadByte();             // Unk
            prop.Scale     = br.ReadSingle();
            prop.Direction = br.ReadSingle();
            br.Skip(0x40);             // colors
            br.ReadUnicodeString();    // title
            prop.State = br.ReadUnicodeString();
            var parameterCount = br.ReadByte();

            for (int k = 0; k < parameterCount; ++k)
            {
                var def        = br.ReadByte();
                var eventType  = br.ReadInt32();
                var signalType = br.ReadInt32();
                var name       = br.ReadUnicodeString();
                var xml        = br.ReadUnicodeString();

                // Add identical parameters only once
                var exists = false;
                foreach (var param in prop.Parameters)
                {
                    if (param.EventType == eventType && param.SignalType == signalType && param.Name == name && param.XML == xml)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    prop.Parameters.Add(new PropParameter(eventType, signalType, name, xml));
                }
            }

            return(prop);
        }