private bool f_import_scene() { if (container == null) { return(false); } var file = new OpenFileDialog(); file.Multiselect = true; file.Filter = ".scn_part|*.scn_part"; if (file.ShowDialog() == DialogResult.OK) { for (int i = 0; i < file.FileNames.Length; i++) { using (var fs = new FileStream(file.FileName, FileMode.Open, FileAccess.Read, FileShare.None)) using (var br = new BinaryReader(fs)) { SceneChunk chunk = null; var type = br.ReadEnum <ChunkType>(); string name = br.ReadCString(); string subname = br.ReadCString(); switch (type) { case ChunkType.Bone: chunk = new BoneChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.bone }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.BoneSystem: chunk = new BoneSystemChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.bone_system }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.Box: chunk = new BoxChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.box }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.ModelData: chunk = new ModelChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.model }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.Shape: chunk = new ShapeChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.shape }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.SkyDirect1: chunk = new SkyDirect1Chunk(container) { Name = name, SubName = subname, Image = Properties.Resources.sky }; chunk.Deserialize(fs); container.Add(chunk); break; default: return(false); } } } return(true); } return(false); }
public static SceneContainer ReadFrom(Stream stream) { var container = new SceneContainer(); using (var r = new BinaryReader(stream)) { container.Header.Deserialize(stream); // CoreLib::Scene::CSceneGroup var chunkCount = r.ReadUInt32(); if (container.Header.Unk2 >= 0.2000000029802322f) { r.ReadByte(); // ToDo ReadString } for (var i = 0; i < chunkCount; i++) { var type = r.ReadEnum <ChunkType>(); var name = r.ReadCString(); var subName = r.ReadCString(); SceneChunk chunk; switch (type) { case ChunkType.ModelData: chunk = new ModelChunk(container) { Name = name, SubName = subName }; chunk.Deserialize(stream); container.Add(chunk); break; case ChunkType.Box: chunk = new BoxChunk(container) { Name = name, SubName = subName }; chunk.Deserialize(stream); container.Add(chunk); break; case ChunkType.Bone: chunk = new BoneChunk(container) { Name = name, SubName = subName }; chunk.Deserialize(stream); container.Add(chunk); break; case ChunkType.BoneSystem: chunk = new BoneSystemChunk(container) { Name = name, SubName = subName }; chunk.Deserialize(stream); container.Add(chunk); break; case ChunkType.Shape: chunk = new ShapeChunk(container) { Name = name, SubName = subName }; chunk.Deserialize(stream); container.Add(chunk); break; case ChunkType.SkyDirect1: chunk = new SkyDirect1Chunk(container) { Name = name, SubName = subName }; chunk.Deserialize(stream); container.Add(chunk); break; default: throw new Exception($"Unknown chunk type: 0x{(int)type:X4} StreamPosition: {r.BaseStream.Position}"); } } } return(container); }