/** <summary> Returns an object loaded from the specified stream. </summary> */ public static ObjectData FromStream(Stream stream, bool quickLoad = false) { ObjectData obj = null; ObjectDataHeader objectHeader = new ObjectDataHeader(); ChunkHeader chunkHeader = new ChunkHeader(); try { BinaryReader reader = new BinaryReader(stream, Encoding.Unicode); objectHeader.Read(reader); byte[] data = null; //if ((ObjectTypes)(objectHeader.Flags & 0xF) != ObjectTypes.ScenarioText) { data = ObjectData.ReadChunk(reader, chunkHeader); reader.Close(); reader = new BinaryReader(new MemoryStream(data)); //} switch ((ObjectTypes)(objectHeader.Flags & 0xF)) { case ObjectTypes.Attraction: obj = new Attraction(objectHeader, chunkHeader); break; case ObjectTypes.SmallScenery: obj = new SmallScenery(objectHeader, chunkHeader); break; case ObjectTypes.LargeScenery: obj = new LargeScenery(objectHeader, chunkHeader); break; case ObjectTypes.Wall: obj = new Wall(objectHeader, chunkHeader); break; case ObjectTypes.PathBanner: obj = new PathBanner(objectHeader, chunkHeader); break; case ObjectTypes.Path: obj = new Pathing(objectHeader, chunkHeader); break; case ObjectTypes.PathAddition: obj = new PathAddition(objectHeader, chunkHeader); break; case ObjectTypes.SceneryGroup: obj = new SceneryGroup(objectHeader, chunkHeader); break; case ObjectTypes.ParkEntrance: obj = new ParkEntrance(objectHeader, chunkHeader); break; case ObjectTypes.Water: obj = new Water(objectHeader, chunkHeader); break; case ObjectTypes.ScenarioText: obj = new ScenarioText(objectHeader, chunkHeader); break; default: objectHeader.Flags = (uint)ObjectTypes.None; break; // Set as invalid } if (obj != null) { obj.Read(reader, quickLoad); } reader.Close(); } catch (System.Exception) { objectHeader.Flags = (uint)ObjectTypes.None; obj = new ObjectData(objectHeader, chunkHeader); } return(obj); }
//=========== LOADING ============ #region Loading /**<summary>Returns an object loaded from the specified stream.</summary>*/ public static ObjectData FromStream(Stream stream, bool quickLoad = false) { ObjectData obj = null; ObjectDataHeader objectHeader = new ObjectDataHeader(); ChunkHeader chunkHeader = new ChunkHeader(); byte[] decodedChunkData; BinaryReader reader = new BinaryReader(stream); objectHeader.Read(reader); chunkHeader.Read(reader); decodedChunkData = Chunk.Read(reader, chunkHeader); using (MemoryStream chunkStream = new MemoryStream(decodedChunkData)) { reader = new BinaryReader(chunkStream); switch ((ObjectTypes)(objectHeader.Flags & 0xF)) { case ObjectTypes.Attraction: obj = new Attraction(objectHeader, chunkHeader); break; case ObjectTypes.SmallScenery: obj = new SmallScenery(objectHeader, chunkHeader); break; case ObjectTypes.LargeScenery: obj = new LargeScenery(objectHeader, chunkHeader); break; case ObjectTypes.Wall: obj = new Wall(objectHeader, chunkHeader); break; case ObjectTypes.PathBanner: obj = new PathBanner(objectHeader, chunkHeader); break; case ObjectTypes.Footpath: obj = new Footpath(objectHeader, chunkHeader); break; case ObjectTypes.PathAddition: obj = new PathAddition(objectHeader, chunkHeader); break; case ObjectTypes.SceneryGroup: obj = new SceneryGroup(objectHeader, chunkHeader); break; case ObjectTypes.ParkEntrance: obj = new ParkEntrance(objectHeader, chunkHeader); break; case ObjectTypes.Water: obj = new Water(objectHeader, chunkHeader); break; case ObjectTypes.ScenarioText: obj = new ScenarioText(objectHeader, chunkHeader); break; default: objectHeader.Flags = (uint)ObjectTypes.None; break; // Set as invalid } if (obj != null) { obj.Read(reader, quickLoad); } } return(obj); }