public EditableUtf(string filename) : this() { Source = parseFile(filename); foreach (var node in Source) { Root.Children.Add(ConvertNode(node, Root)); } }
public void AddResources(Utf.IntermediateNode node, string id) { MatFile mat; TxmFile txm; VmsFile vms; Utf.UtfLoader.LoadResourceNode(node, this, out mat, out txm, out vms); if (mat != null) { AddMaterials(mat, id); } if (txm != null) { AddTextures(txm, id); } if (vms != null) { AddMeshes(vms); } }
public static IDrawable GetDrawable(IntermediateNode root, ILibFile resources) { bool cmpnd = false; bool multilevel = false; foreach (var node in root) { var l = node.Name.ToLowerInvariant(); if (l == "sphere") { return(new SphFile(root, resources)); } if (l == "vmeshpart") { return(new ModelFile(root, resources)); } if (l == "cmpnd") { cmpnd = true; } if (l == "multilevel") { multilevel = true; } if (l == "skeleton") { return(new DfmFile(root, resources)); } } if (cmpnd) { return(new CmpFile(root, resources)); } if (multilevel) { return(new ModelFile(root, resources)); } return(null); }
protected static IntermediateNode parseFile(string path, Stream stream) { byte[] nodeBlock; string stringBlock; byte[] dataBlock; using (BinaryReader reader = new BinaryReader(stream)) { byte[] buffer = new byte[TAG_LEN]; reader.Read(buffer, 0, TAG_LEN); string fileType = Encoding.ASCII.GetString(buffer); if (fileType != FILE_TYPE) { throw new FileFormatException(path, fileType, FILE_TYPE); } int formatVersion = reader.ReadInt32(); if (formatVersion != FILE_VERSION) { throw new FileVersionException(path, fileType, formatVersion, FILE_VERSION); } int nodeBlockOffset = reader.ReadInt32(); if (nodeBlockOffset > reader.BaseStream.Length) { throw new FileContentException(fileType, "The node block offset was out of range: " + nodeBlockOffset); } int nodeBlockSize = reader.ReadInt32(); if (nodeBlockOffset + nodeBlockSize > reader.BaseStream.Length) { throw new FileContentException(fileType, "The node block size was out of range: " + nodeBlockSize); } //int zero = reader.ReadInt32(); //int headerSize = reader.ReadInt32(); reader.BaseStream.Seek(2 * sizeof(int), SeekOrigin.Current); int stringBlockOffset = reader.ReadInt32(); if (stringBlockOffset > reader.BaseStream.Length) { throw new FileContentException(fileType, "The string block offset was out of range: " + stringBlockOffset); } int stringBlockSize = reader.ReadInt32(); if (stringBlockOffset + stringBlockSize > reader.BaseStream.Length) { throw new FileContentException(fileType, "The string block size was out of range: " + stringBlockSize); } //int unknown = reader.ReadInt32(); reader.BaseStream.Seek(sizeof(int), SeekOrigin.Current); int dataBlockOffset = reader.ReadInt32(); if (dataBlockOffset > reader.BaseStream.Length) { throw new FileContentException(fileType, "The data block offset was out of range: " + dataBlockOffset); } nodeBlock = new byte[nodeBlockSize]; reader.BaseStream.Seek(nodeBlockOffset, SeekOrigin.Begin); reader.Read(nodeBlock, 0, nodeBlockSize); Array.Resize <byte>(ref buffer, stringBlockSize); reader.BaseStream.Seek(stringBlockOffset, SeekOrigin.Begin); reader.Read(buffer, 0, stringBlockSize); stringBlock = Encoding.ASCII.GetString(buffer); dataBlock = new byte[(int)(reader.BaseStream.Length - dataBlockOffset)]; reader.BaseStream.Seek(dataBlockOffset, SeekOrigin.Begin); reader.Read(dataBlock, 0, dataBlock.Length); } IntermediateNode root = null; using (BinaryReader reader = new BinaryReader(new MemoryStream(nodeBlock))) { root = Node.FromStream(reader, 0, new StringBlock(stringBlock), dataBlock) as IntermediateNode; if (root == null) { throw new FileContentException(UtfFile.FILE_TYPE, "The root node doesn't have any child nodes."); } } return(root); }