/// <summary> /// Creates a new field. /// </summary> /// <param name="name">Name of the field.</param> /// <param name="type">Type (as defined by SDNA) of the field.</param> /// <param name="sdna">Structure DNA for the file.</param> public FieldDefinition(string name, TypeDefinition type, StructureDNA sdna) { Name = name; Type = type; structure = null; isInitialized = false; this.sdna = sdna; }
/// <summary> /// Creates a new type as defined by SDNA. /// </summary> /// <param name="name">Name of the type.</param> /// <param name="size">Size of the type in bytes.</param> /// <param name="s">Structure DNA for the type.</param> public TypeDefinition(string name, short size, StructureDNA s) { Name = name; Size = size; int index = s.TypeNameList.IndexOf(name); IsPrimitive = s.StructureTypeIndices.IndexOf((short)index) == -1; // not found means primitive }
/// <summary> /// Creates a new field. /// </summary> /// <param name="nameIndex">Index of SDNA.NameList containing the name of the field.</param> /// <param name="typeIndex">Index of SDNA.TypeList containing the type of the field.</param> /// <param name="sdna">Structure DNA in which the field is contained.</param> public FieldDefinition(short nameIndex, short typeIndex, StructureDNA sdna) { Name = sdna.NameList[nameIndex]; Type = sdna.TypeList[typeIndex]; this.sdna = sdna; if (Type.Name.Count(v => { return(v == '['); }) > 2) { throw new Exception("A 3D array is present and this program is not set up to handle that."); } isInitialized = false; structure = null; }
/// <summary> /// Parses a file block. If the file block is SDNA or another block with block.count == 0, it will return null. /// </summary> /// <param name="block">The block to parse.</param> /// <param name="blocksParsed">Number of blocks parsed so far.</param> /// <param name="file">Source file for the structures.</param> /// <returns>An array of PopulatedStructures, or { null } if no structures are defined.</returns> public static Structure[] ParseFileBlock(FileBlock block, int blocksParsed, BlenderFile file) { if (block.Count == 0 || block.Code == "DNA1") { return(null); } StructureDNA sdna = file.StructureDNA; if (block.Data.Length != sdna.StructureList[block.SDNAIndex].StructureTypeSize * block.Count) { // generally, these are things like raw data; packed files, preview images, and arrays of pointers that are themselves pointed to. // I have no idea what TEST and REND do. file.RawBlockMessages.Add(blocksParsed + " " + block.OldMemoryAddress.ToString("X" + (file.PointerSize * 2)) + " " + block.Code + " " + block.SDNAIndex + " " + sdna.StructureList[block.SDNAIndex].StructureTypeSize * block.Count + " " + block.Data.Length); return(null); } Structure[] output = new Structure[block.Count]; if (block.Count > 1) { for (int i = 0; i < block.Count; i++) { byte[] data = new byte[block.Size / block.Count]; for (int j = 0; j < block.Size / block.Count; j++) { data[j] = block.Data[i * (block.Size / block.Count) + j]; } output[i] = new Structure(data, sdna.StructureList[block.SDNAIndex], file); output[i].Size = sdna.StructureList[block.SDNAIndex].StructureTypeSize; output[i].TypeName = sdna.StructureList[block.SDNAIndex].StructureTypeName; output[i].ContainingBlock = block; } } else { output[0] = new Structure(block.Data, sdna.StructureList[block.SDNAIndex], file); output[0].Size = sdna.StructureList[block.SDNAIndex].StructureTypeSize; output[0].TypeName = sdna.StructureList[block.SDNAIndex].StructureTypeName; output[0].ContainingBlock = block; } return(output); }
/// <summary> /// Reads the file blocks from the file. Returns the block with the code <pre>DNA1</pre>, which is the file's /// structure DNA. /// </summary> /// <param name="fileReader">Reference to file reader for current file.</param> /// <returns>File's Structure DNA.</returns> private StructureDNA readBlocks(BinaryReader fileReader) { StructureDNA dna = null; do { FileBlock b = FileBlock.ReadBlock(fileReader, PointerSize); if (b.Code == "DNA1") { dna = (StructureDNA)b; } fileBlocks.Add(b); } while(fileReader.BaseStream.Position < fileReader.BaseStream.Length); if (dna == null) { throw new InvalidDataException("This file contains no structure DNA! What are you trying to pull?!"); } return(dna); }