Beispiel #1
0
        public static Zone LoadFromStream(string name, string displayName, Stream stream)
        {
            BinaryReader binaryReader = new BinaryReader(stream);

            //Header
            byte[] magic = binaryReader.ReadBytes(4);

            if (magic[0] != 'Z' ||
                magic[1] != 'O' ||
                magic[2] != 'N' ||
                magic[3] != 'E')
            {
                return(null);
            }

            Zone zone = new Zone();

            zone.Name        = name;
            zone.DisplayName = displayName;
            zone.Version     = binaryReader.ReadUInt32();

            if (!Enum.IsDefined(typeof(ZoneType), (int)zone.Version))
            {
                Debug.LogWarning("Could not decode zone " + name + ". Unknown ZONE version " + zone.Version);
                return(null);
            }

            zone.ZoneType = (ZoneType)(int)zone.Version;

            if (zone.ZoneType == ZoneType.H1Z1)
            {
                binaryReader.ReadUInt32();
            }

            zone.Offsets                   = new Dictionary <string, uint>();
            zone.Offsets["ecos"]           = binaryReader.ReadUInt32();
            zone.Offsets["floras"]         = binaryReader.ReadUInt32();
            zone.Offsets["invisibleWalls"] = binaryReader.ReadUInt32();
            zone.Offsets["objects"]        = binaryReader.ReadUInt32();
            zone.Offsets["lights"]         = binaryReader.ReadUInt32();
            zone.Offsets["unknowns"]       = binaryReader.ReadUInt32();

            if (zone.ZoneType == ZoneType.H1Z1)
            {
                zone.Offsets["decals"] = binaryReader.ReadUInt32();
            }

            zone.QuadsPerTile  = binaryReader.ReadUInt32();
            zone.TileSize      = binaryReader.ReadSingle();
            zone.TileHeight    = binaryReader.ReadSingle();
            zone.VertsPerTile  = binaryReader.ReadUInt32();
            zone.TilesPerChunk = binaryReader.ReadUInt32();
            zone.StartX        = binaryReader.ReadInt32();
            zone.StartY        = binaryReader.ReadInt32();
            zone.ChunksX       = binaryReader.ReadUInt32();
            zone.ChunksY       = binaryReader.ReadUInt32();

            //Ecos
            zone.Ecos = new List <Eco>();
            uint ecosLength = binaryReader.ReadUInt32();

            for (uint i = 0; i < ecosLength; i++)
            {
                zone.Ecos.Add(Eco.ReadFromStream(binaryReader.BaseStream));
            }

            //Floras
            zone.Floras = new List <Flora>();
            uint florasLength = binaryReader.ReadUInt32();

            for (uint i = 0; i < florasLength; i++)
            {
                zone.Floras.Add(Flora.ReadFromStream(binaryReader.BaseStream, zone.ZoneType));
            }

            //Invisible Walls
            zone.InvisibleWalls = new List <InvisibleWall>();
            uint invisibleWallsLength = binaryReader.ReadUInt32();

            for (uint i = 0; i < invisibleWallsLength; i++)
            {
                zone.InvisibleWalls.Add(InvisibleWall.ReadFromStream(binaryReader.BaseStream));
            }

            //Objects
            zone.Objects = new List <Object>();
            uint objectsLength = binaryReader.ReadUInt32();

            for (uint i = 0; i < objectsLength; i++)
            {
                zone.Objects.Add(Object.ReadFromStream(binaryReader.BaseStream, zone.ZoneType));
            }

            //Lights
            zone.Lights = new List <Light>();
            uint lightsLength = binaryReader.ReadUInt32();

            for (uint i = 0; i < lightsLength; i++)
            {
                zone.Lights.Add(Light.ReadFromStream(binaryReader.BaseStream));
            }

            //Unknowns
            uint unknownsLength = binaryReader.ReadUInt32();

            zone.Unknowns = new List <Unknown>((int)unknownsLength);

            //for (int i = 0; i < unknownsLength; i++)
            //{
            //    //zone.Unknowns.Add(Unknown.ReadFromStream(binaryReader.BaseStream));
            //    //???
            //}

            //Decals
            if (zone.ZoneType == ZoneType.H1Z1)
            {
                uint decalsLength = binaryReader.ReadUInt32();
                zone.Decals = new List <Decal>((int)decalsLength);

                for (int i = 0; i < decalsLength; i++)
                {
                    zone.Decals.Add(Decal.ReadFromStream(binaryReader.BaseStream));
                }
            }

            return(zone);
        }