private Definition Parse(Definition parent) { Definition def; if (parent == null) { def = this.def; } else { def = new Definition(); } Field temp = null; currentField.Read(InputStream); IStructureOwner struct_owner = (IStructureOwner)def; while (currentField.Type != FieldType.Terminator) { def.Add(temp = FieldUtil.CreateFromDefinitionItem(engine, struct_owner.OwnerObject, currentField)); if (currentField.Type == FieldType.Block || currentField.Type == FieldType.Struct) { Parse(temp.FieldValue as Definition); } currentField.Read(InputStream); } return(def); }
/// <summary> /// Raise an exception for an invalid data reference field in a stream /// </summary> /// <param name="inner"></param> /// <param name="offset_field">Offset of the data reference field</param> /// <param name="offset_data">Offset of the data reference data</param> /// <param name="owner">Owner of the <see cref="StructReference{T}"/> field. Can be null.</param> /// <param name="tag">Tag which this data reference ultimately belongs to</param> public InvalidStructReference( Exception inner, uint offset_field, uint offset_data, IStructureOwner owner, IO.ITagStream tag ) : base(inner, "Invalid Data Reference") { Debug.LogFile.WriteLine( "Invalid data reference: field@{0:X8}\tdata@{1:X8}" + Program.NewLine + "\tIn {2} in {3}", offset_field, offset_data, tag.GetExceptionDescription(), owner != null ? owner.GetType().FullName : "UNKNOWN"); }
/// <summary> /// Raise an exception for an invalid inline struct field in a stream /// </summary> /// <param name="inner"></param> /// <param name="offset_data">Offset of the inline struct data</param> /// <param name="owner">Owner of the <see cref="Struct{T}"/> field. Can be null.</param> /// <param name="tag">Tag which this inline struct ultimately belongs to</param> public InvalidTagStruct( Exception inner, uint offset_data, IStructureOwner owner, IO.ITagStream tag ) : base(inner, "Invalid Tag Struct") { Debug.LogFile.WriteLine( "Invalid inline struct: data@{0:X8}" + Program.NewLine + "\tIn {1} in {2}", offset_data, tag.GetExceptionDescription(), owner != null ? owner.GetType().FullName : "UNKNOWN"); }
/// <summary> /// Raise an exception for an invalid <c>tag_reference</c> field in a stream /// </summary> /// <param name="inner"></param> /// <param name="offset_field">Offset of the <c>tag_reference</c> field</param> /// <param name="offset_data">Offset of the <c>tag_reference</c> data (ie, tag name)</param> /// <param name="owner">Owner of the <see cref="TagReference"/> field. Can be null.</param> /// <param name="tag">Tag which this <c>tag_reference</c> ultimately belongs to</param> /// <param name="group_tag"><c>tag_reference</c>'s group tag</param> /// <param name="value"><c>tag_reference</c>'s tag name data. Can be null.</param> public InvalidTagReference( Exception inner, uint offset_field, uint offset_data, IStructureOwner owner, IO.ITagStream tag, uint group_tag, string value) : base(inner, "Invalid Tag Reference") { Debug.LogFile.WriteLine( "Invalid tag_reference: field@{0:X8}\tdata@{1:X8}\tgroup={2,4}\tpath={3}" + Program.NewLine + "\tIn {4} in {5}", offset_field, offset_data, group_tag, value != null ? value : "UNKNOWN", tag.GetExceptionDescription(), owner != null ? owner.GetType().FullName : "UNKNOWN"); }
/// <summary> /// Construct a struct field /// </summary> /// <param name="owner">specific owner object</param> public Struct(IStructureOwner owner) : this() { this.owner = owner; }
/// <summary> /// Create a new Block definition that is a clone of <paramref name="value"/> /// </summary> /// <param name="value">Block to clone</param> /// <param name="owner"></param> public Block(Block <T> value, IStructureOwner owner) : this(value) { this.owner = owner; }
/// <summary> /// Create a new Block definition with a specified owner /// and a maximum element count of <paramref name="max"/> /// </summary> /// <param name="owner">Owner object of this Block</param> /// <param name="max">Max allowed elements for this block</param> public Block(IStructureOwner owner, int max) : this(max) { this.owner = owner; }
/// <summary> /// Create a new Block with a specified owner /// </summary> /// <param name="owner">Owner object of this Block</param> public Block(IStructureOwner owner) : this() { this.owner = owner; }
/// <summary> /// Performs a deep copy of this field /// </summary> /// <param name="owner">New owner of this field</param> /// <returns>Complete copy guaranteed not to reference any tag data which we copied</returns> /// <remarks>Default implementation just calls <see cref="Clone()"/></remarks> public virtual object Clone(IStructureOwner owner) { return(Clone()); }
/// <summary> /// Performs a deep copy of this field /// </summary> /// <param name="owner">New owner of this field</param> /// <returns>Complete copy guaranteed not to reference any tag data which we copied</returns> /// <remarks>Default implementation just calls <see cref="Clone()"/></remarks> public virtual object Clone(IStructureOwner owner) { return Clone(); }
/// <summary> /// Recreate a field based on properties defined in a definition file's entry data /// </summary> /// <param name="engine">Engine this definition item belongs in</param> /// <param name="owner">Owner object to this field</param> /// <param name="item">Property data for the field</param> /// <returns></returns> public static Field CreateFromDefinitionItem(BlamVersion engine, IStructureOwner owner, DefinitionFile.Item item) { switch (item.Type) { case FieldType.String: return new String((StringType)(item.Flags & 0x0000FFFF), (int)(item.Flags >> 16)); case FieldType.StringId: return new StringId(item.Type == FieldType.OldStringId); case FieldType.ByteInteger: return new ByteInteger(); case FieldType.ShortInteger: return new ShortInteger(); case FieldType.LongInteger: return new LongInteger(); case FieldType.Tag: return new Tag(); case FieldType.ByteEnum: case FieldType.Enum: case FieldType.LongEnum: return new Enum((FieldType)item.Flags); case FieldType.ByteFlags: case FieldType.WordFlags: case FieldType.LongFlags: return new Flags((FieldType)item.Flags); case FieldType.Point2D: return new Point2D(); case FieldType.Rectangle2D: return new Rectangle2D(); case FieldType.RgbColor: case FieldType.ArgbColor: return new Color((FieldType)item.Flags); case FieldType.Angle: case FieldType.Real: case FieldType.RealFraction: return new Real((FieldType)item.Flags); case FieldType.RealPoint2D: return new RealPoint2D(); case FieldType.RealPoint3D: return new RealPoint3D(); case FieldType.RealVector2D: return new RealVector2D(); case FieldType.RealVector3D: return new RealVector3D(); case FieldType.RealQuaternion: return new RealQuaternion(); case FieldType.RealEulerAngles2D: return new RealEulerAngles2D(); case FieldType.RealEulerAngles3D: return new RealEulerAngles3D(); case FieldType.RealPlane2D: return new RealPlane2D(); case FieldType.RealPlane3D: return new RealPlane3D(); case FieldType.RealRgbColor: case FieldType.RealArgbColor: return new RealColor((FieldType)item.Flags); case FieldType.ShortBounds: return new ShortIntegerBounds(); case FieldType.AngleBounds: case FieldType.RealBounds: case FieldType.RealFractionBounds: return new RealBounds((FieldType)item.Flags); case FieldType.TagReference: return new TagReference(owner, Blam.MiscGroups.TagGroupFromHandle((Blam.DatumIndex)item.Flags)); case FieldType.Block: return new Block<Definition>(owner); case FieldType.ByteBlockIndex: case FieldType.ShortBlockIndex: case FieldType.LongBlockIndex: return new BlockIndex((FieldType)item.Flags); case FieldType.Data: return new Data(owner, (DataType)item.Flags); case FieldType.Struct: return new Struct<Definition>(owner); case FieldType.StructReference: return new StructReference<Definition>(owner); case FieldType.Pad: return new Pad(item.Flags); case FieldType.UnknownPad: return new UnknownPad(item.Flags); case FieldType.UselessPad: return new UselessPad(item.Flags); case FieldType.Skip: return new Skip(item.Flags); //case FieldType.Custom: return new Custom(TagGroup.FromUInt(item.Flags)); //case FieldType.CustomData: return null; default: throw new Debug.Exceptions.UnreachableException(item.Type); } }
/// <summary> /// Copy constructor /// </summary> /// <param name="value">field to copy</param> /// <param name="owner"></param> public Struct(Struct <T> value, IStructureOwner owner) : this(value) { this.owner = owner; }
/// <summary> /// Performs a deep copy of this field /// </summary> /// <param name="owner"></param> /// <returns>Complete copy guaranteed not to reference any tag data which we copied</returns> public override object Clone(IStructureOwner owner) { return(new Struct <T>(this, owner)); }
/// <summary> /// Recreate a field based on properties defined in a definition file's entry data /// </summary> /// <param name="engine">Engine this definition item belongs in</param> /// <param name="owner">Owner object to this field</param> /// <param name="item">Property data for the field</param> /// <returns></returns> public static Field CreateFromDefinitionItem(BlamVersion engine, IStructureOwner owner, DefinitionFile.Item item) { switch (item.Type) { case FieldType.String: return(new String((StringType)(item.Flags & 0x0000FFFF), (int)(item.Flags >> 16))); case FieldType.StringId: return(new StringId(item.Type == FieldType.OldStringId)); case FieldType.ByteInteger: return(new ByteInteger()); case FieldType.ShortInteger: return(new ShortInteger()); case FieldType.LongInteger: return(new LongInteger()); case FieldType.Tag: return(new Tag()); case FieldType.ByteEnum: case FieldType.Enum: case FieldType.LongEnum: return(new Enum((FieldType)item.Flags)); case FieldType.ByteFlags: case FieldType.WordFlags: case FieldType.LongFlags: return(new Flags((FieldType)item.Flags)); case FieldType.Point2D: return(new Point2D()); case FieldType.Rectangle2D: return(new Rectangle2D()); case FieldType.RgbColor: case FieldType.ArgbColor: return(new Color((FieldType)item.Flags)); case FieldType.Angle: case FieldType.Real: case FieldType.RealFraction: return(new Real((FieldType)item.Flags)); case FieldType.RealPoint2D: return(new RealPoint2D()); case FieldType.RealPoint3D: return(new RealPoint3D()); case FieldType.RealVector2D: return(new RealVector2D()); case FieldType.RealVector3D: return(new RealVector3D()); case FieldType.RealQuaternion: return(new RealQuaternion()); case FieldType.RealEulerAngles2D: return(new RealEulerAngles2D()); case FieldType.RealEulerAngles3D: return(new RealEulerAngles3D()); case FieldType.RealPlane2D: return(new RealPlane2D()); case FieldType.RealPlane3D: return(new RealPlane3D()); case FieldType.RealRgbColor: case FieldType.RealArgbColor: return(new RealColor((FieldType)item.Flags)); case FieldType.ShortBounds: return(new ShortIntegerBounds()); case FieldType.AngleBounds: case FieldType.RealBounds: case FieldType.RealFractionBounds: return(new RealBounds((FieldType)item.Flags)); case FieldType.TagReference: return(new TagReference(owner, Blam.MiscGroups.TagGroupFromHandle((Blam.DatumIndex)item.Flags))); case FieldType.Block: return(new Block <Definition>(owner)); case FieldType.ByteBlockIndex: case FieldType.ShortBlockIndex: case FieldType.LongBlockIndex: return(new BlockIndex((FieldType)item.Flags)); case FieldType.Data: return(new Data(owner, (DataType)item.Flags)); case FieldType.Struct: return(new Struct <Definition>(owner)); case FieldType.StructReference: return(new StructReference <Definition>(owner)); case FieldType.Pad: return(new Pad(item.Flags)); case FieldType.UnknownPad: return(new UnknownPad(item.Flags)); case FieldType.UselessPad: return(new UselessPad(item.Flags)); case FieldType.Skip: return(new Skip(item.Flags)); //case FieldType.Custom: return new Custom(TagGroup.FromUInt(item.Flags)); //case FieldType.CustomData: return null; default: throw new Debug.Exceptions.UnreachableException(item.Type); } }