/// <summary> /// Get the name of the element. /// </summary> /// <returns>The element's name.</returns> private string GetName() { var nameAttributeOffset = this.GetNameAttributeOffset(); var nameAttribute = Xmb2Variant.FromByteArray(this.Xmb2, nameAttributeOffset); if (nameAttribute == null) { return(null); } if (nameAttribute.ValueType == Xmb2Variant.Type.String) { return(nameAttribute.Value as string); } else if (nameAttribute.ValueType != Xmb2Variant.Type.Bool) { return(null); } else { var boolValue = (bool)nameAttribute.Value; if (boolValue) { return("True"); } else { return("False"); } } }
public void Dump(byte[] xmb2, StringBuilder output, int indent) { for (var i = 0; i < indent; i++) { output.Append(" "); } output.Append('<').Append(this.Name); // TODO attributes var variantRelativeOffsetTableOffset = this.Offset + this.AttributeStartOffset + 8; for (var i = 0; i < this.AttributeCount; i++) { var variantRelativeOffsetOffset = variantRelativeOffsetTableOffset + (i * sizeof(int)); var variantRelativeOffset = BitConverter.ToInt32(this.Xmb2, (int)variantRelativeOffsetOffset); var variantOffset = variantRelativeOffsetOffset + variantRelativeOffset; var variant = Xmb2Variant.FromByteArray(this.Xmb2, variantOffset); output.Append(" 0x").Append(variant.NameHash.ToString("x")).Append("=\"").Append(variant.GetTextValue()).Append('\"'); } if (this.ElementCount != 0) { output.Append(">\n"); foreach (var element in this.GetElements()) { element.Dump(xmb2, output, indent + 2); } for (var i = 0; i < indent; i++) { output.Append(" "); } output.Append("</").Append(this.Name).Append(">\n"); return; } if (this.ElementStartOffset == 0) { output.Append(" />\n"); return; } output.Append('>').Append(this.GetTextValue()); output.Append("</").Append(this.Name).Append(">\n"); }
public Xmb2Variant GetAttributeByName(uint nameHash) { var variantRelativeOffsetTableOffset = this.Offset + this.AttributeStartOffset + 8; for (var i = 0; i < this.AttributeCount; i++) { var variantRelativeOffsetOffset = variantRelativeOffsetTableOffset + (i * sizeof(int)); var variantRelativeOffset = BitConverter.ToInt32(this.Xmb2, (int)variantRelativeOffsetOffset); var variantOffset = variantRelativeOffsetOffset + variantRelativeOffset; var variant = Xmb2Variant.FromByteArray(this.Xmb2, variantOffset); if (variant.NameHash == nameHash) { return(variant); } } return(null); }
/// <summary> /// Get this element's value attribute. /// </summary> /// <returns>The value attribute.</returns> private Xmb2Variant GetValueAttribute() { if (this.ElementCount != 0) { return(null); } if (this.ElementStartOffset == 0) { return(null); } var attributeOffset = this.Offset + this.ElementStartOffset; if (attributeOffset == 0) { return(null); } return(Xmb2Variant.FromByteArray(this.Xmb2, attributeOffset)); }