public static Eco ReadFromStream(Stream stream) { Eco eco = new Eco(); eco.Index = stream.ReadUInt32(); eco.Name = stream.ReadString(StringCoding.ZeroTerminated); eco.ColorNXMap = stream.ReadString(StringCoding.ZeroTerminated); eco.SpecBlendNyMap = stream.ReadString(StringCoding.ZeroTerminated); eco.DetailRepeat = stream.ReadUInt32(); eco.BlendStrength = stream.ReadSingle(); eco.SpecMin = stream.ReadSingle(); eco.SpecMax = stream.ReadSingle(); eco.SpecSmoothnessMin = stream.ReadSingle(); eco.SpecSmoothnessMax = stream.ReadSingle(); eco.PhysicsMaterial = stream.ReadString(StringCoding.ZeroTerminated); eco.Layers = new List <Layer>(); uint layerCount = stream.ReadUInt32(); for (uint i = 0; i < layerCount; i++) { Layer layer = new Layer(); layer.Density = stream.ReadSingle(); layer.MinScale = stream.ReadSingle(); layer.MaxScale = stream.ReadSingle(); layer.SlopePeak = stream.ReadSingle(); layer.SlopeExtent = stream.ReadSingle(); layer.MinElevation = stream.ReadSingle(); layer.MaxElevation = stream.ReadSingle(); layer.MinAlpha = stream.Read1Byte(); layer.Flora = stream.ReadString(StringCoding.ZeroTerminated); layer.Tints = new List <Layer.Tint>(); uint tintCount = stream.ReadUInt32(); for (uint j = 0; j < tintCount; j++) { Layer.Tint tint = new Layer.Tint(); tint.Color = stream.ReadByteColor(ColorMemberOrder.AlphaLast); tint.Percentage = stream.ReadUInt32(); layer.Tints.Add(tint); } eco.Layers.Add(layer); } return(eco); }
public bool Deserialize(BinaryStream stream, AssetManager assetManager) { // Header string magic = stream.ReadString(4); Assert.AreEqual(MAGIC, magic, "Zone file does not have the correct header!"); Version = stream.ReadUInt32(); if (!Enum.IsDefined(typeof(ZoneType), (int)Version)) { Debug.LogWarning("Could not decode zone " + Name + ". Unknown ZONE version " + Version); return(false); } ZoneType = (ZoneType)(int)Version; if (ZoneType == ZoneType.H1Z1) { stream.ReadUInt32(); } Offsets = new Dictionary <string, uint>(); Offsets["ecos"] = stream.ReadUInt32(); Offsets["floras"] = stream.ReadUInt32(); Offsets["invisibleWalls"] = stream.ReadUInt32(); Offsets["objects"] = stream.ReadUInt32(); Offsets["lights"] = stream.ReadUInt32(); Offsets["unknowns"] = stream.ReadUInt32(); if (ZoneType == ZoneType.H1Z1) { Offsets["decals"] = stream.ReadUInt32(); } QuadsPerTile = stream.ReadUInt32(); TileSize = stream.ReadSingle(); TileHeight = stream.ReadSingle(); VertsPerTile = stream.ReadUInt32(); TilesPerChunk = stream.ReadUInt32(); StartX = stream.ReadInt32(); StartY = stream.ReadInt32(); ChunksX = stream.ReadUInt32(); ChunksY = stream.ReadUInt32(); // Ecos Ecos = new List <Eco>(); uint ecosLength = stream.ReadUInt32(); for (uint i = 0; i < ecosLength; i++) { Ecos.Add(Eco.ReadFromStream(stream)); } // Floras Floras = new List <Flora>(); uint florasLength = stream.ReadUInt32(); for (uint i = 0; i < florasLength; i++) { Floras.Add(Flora.ReadFromStream(stream, ZoneType)); } // Invisible Walls InvisibleWalls = new List <InvisibleWall>(); uint invisibleWallsLength = stream.ReadUInt32(); for (uint i = 0; i < invisibleWallsLength; i++) { InvisibleWalls.Add(InvisibleWall.ReadFromStream(stream)); } // Objects Objects = new List <Object>(); uint objectsLength = stream.ReadUInt32(); for (uint i = 0; i < objectsLength; i++) { Objects.Add(Object.ReadFromStream(stream, ZoneType)); } // Lights Lights = new List <Light>(); uint lightsLength = stream.ReadUInt32(); for (uint i = 0; i < lightsLength; i++) { Lights.Add(Light.ReadFromStream(stream)); } // Unknowns uint unknownsLength = stream.ReadUInt32(); Unknowns = new List <Unknown>((int)unknownsLength); //for (int i = 0; i < unknownsLength; i++) //{ // //Unknowns.Add(Unknown.ReadFromStream(stream)); // //??? //} // Decals if (ZoneType == ZoneType.H1Z1) { uint decalsLength = stream.ReadUInt32(); Decals = new List <Decal>((int)decalsLength); for (int i = 0; i < decalsLength; i++) { Decals.Add(Decal.ReadFromStream(stream)); } } return(true); }