/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(NBTTagList tag, SerializationContext Context) { NBTTagType SubTagType = tag.SubType; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { /*SubTag = new NBTTagList(SubTagType); * SubTag.SetInformation(NBTTagInformation.ListSubtype, (NBTTagType)Context.Stream.ReadByte()); * SubTag.SetInformation(NBTTagInformation.ListSize, Context.ReadInt32()); * Reader.ReadContent(SubTag, Context); * tag[I] = SubTag;*/ Context.Stream.WriteByte((Byte)tag.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)tag.GetInformation(NBTTagInformation.ListSize)); } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }
internal override void SkipTag(BinaryReader reader) { while (true) { NBTTagType nextTag = (NBTTagType)reader.ReadInt32(); NBTTag newTag = null; switch (nextTag) { case NBTTagType.END: return; case NBTTagType.COMPOUND: newTag = new NBTFolder(); break; case NBTTagType.STRING: newTag = new NBTString(); break; case NBTTagType.INT: newTag = new NBTInt(); break; case NBTTagType.DOUBLE: newTag = new NBTDouble(); break; case NBTTagType.STRINGARRAY: newTag = new NBTStringArray(); break; case NBTTagType.FLOAT: newTag = new NBTFloat(); break; case NBTTagType.INTARRAY: newTag = new NBTIntArray(); break; case NBTTagType.BYTE: newTag = new NBTByte(); break; case NBTTagType.BYTEARRAY: newTag = new NBTByteArray(); break; case NBTTagType.FLOATARRAY: newTag = new NBTFloatArray(); break; case NBTTagType.DOUBLEARRAY: newTag = new NBTDoubleArray(); break; } reader.ReadString(); newTag.SkipTag(reader); } }
/// <summary>Adds a new sub <see cref="NBTTagList"/> to the collection</summary> /// <param name="Name">The name of the tag to add to the collection</param> /// <param name="SubType">The subtype of the tags inside the list</param> /// <param name="Capacity">The capacity to start the list with</param> /// <returns>Adds a new sub <see cref="NBTTagList"/> to the collection</returns> public ListBuilder AddSubList(String Name, NBTTagType SubType, Int32 Capacity = 10) { var Tag = new NBTTagList(Name, SubType, Capacity); var Builder = new ListBuilder(Tag); this._Tag.Add(Tag); return(Builder); }
public static ITagReader GetReader(NBTTagType Type) { if (_Readers.TryGetValue(Type, out ITagReader Reader)) { return(Reader); } return(null); }
public static ITagWriter GetWriter(NBTTagType Type) { if (_Writers.TryGetValue(Type, out ITagWriter Writer)) { return(Writer); } return(null); }
public ListTag(string name, NBTTagType type, params object[] obj) : base(name) { this.ListTagType = type; for (int i = 0; i < obj.Length; ++i) { this.Add(obj); } }
/// <summary>Creates the specified list as a tag</summary> /// <param name="Name">The name of the list</param> /// <param name="SubType">The subtype to fill</param> /// <returns>Creates the specified list as a tag</returns> private static (ITag List, Type SubType) CreateList(String Name, NBTTagType SubType) { ITag Out = NBTTagFactory.Create(NBTTagType.List); Out.Name = Name; Out.SetInformation(NBTTagInformation.ListSubtype, SubType); Type TagType = NBTTagFactory.Types.ContainsKey(SubType) ? Types[SubType] : null; return(Out, TagType); }
public bool Exist(string name, NBTTagType type) { if (this.tags.ContainsKey(name)) { Tag tag = this.GetTag(name); if (tag.TagType == type) { return(true); } } return(false); }
public static string ToNameString(this NBTTagType type) { switch (type) { case NBTTagType.END: return("End"); case NBTTagType.BYTE: return("Byte"); case NBTTagType.SHORT: return("Short"); case NBTTagType.INT: return("Int"); case NBTTagType.LONG: return("Long"); case NBTTagType.FLOAT: return("Float"); case NBTTagType.DOUBLE: return("Double"); case NBTTagType.BYTE_ARRAY: return("ByteArray"); case NBTTagType.STRING: return("String"); case NBTTagType.LIST: return("List"); case NBTTagType.COMPOUND: return("Compound"); case NBTTagType.INT_ARRAY: return("IntArray"); case NBTTagType.LONG_ARRAY: return("LongArray"); default: throw new NotSupportedException(); } }
public static string GetCanonicalTagName(NBTTagType type) { switch (type) { case NBTTagType.COMPOUND: return("Tag_Folder"); case NBTTagType.STRING: return("Tag_String"); case NBTTagType.INT: return("Tag_Int32"); case NBTTagType.DOUBLE: return("Tag_Double"); case NBTTagType.STRINGARRAY: return("Tag_StringArray"); case NBTTagType.FLOAT: return("Tag_Float"); case NBTTagType.INTARRAY: return("Tag_Int32Array"); case NBTTagType.BYTE: return("Tag_Byte"); case NBTTagType.FLOATARRAY: return("Tag_FloatArray"); case NBTTagType.BYTEARRAY: return("Tag_ByteArray"); case NBTTagType.DOUBLEARRAY: return("Tag_DoubleArray"); default: return(null); } }
/// <summary>Creates a tag with the specified information</summary> /// <param name="type">The tag type</param> /// <param name="Name">The name of the tag</param> /// <param name="Value">The value of the type</param> /// <returns>Creates a tag with the specified tag type</returns> public static ITag Create(NBTTagType type, String Name, Object Value) { ITag Tag = NBTTagFactory.Create(type); if (Tag == null) { return(Tag); } if (Name != null) { Tag.Name = Name; } if (Value != null) { Tag.SetValue(Value); } return(Tag); }
private void AddTag <T>(T value, NBTTagType type) { this.cacheData.NBTViewerCache.AddNBTViewerCacheRow("", value, type.ToNameString()); }
public bool Exist(string name, NBTTagType type) { return(this.Tags.ContainsKey(name) && this.Tags[name].Type == type); }
public ListTag(NBTTagType type, params object[] obj) : this("", type, obj) { }
public static int ToInt(this NBTTagType type) { return((int)type); }
///DOLATER <summary>Add Description</summary> /// <param name="Tag">FILL IN</param> /// <param name="Name">The name of the instance</param> /// <param name="Type">FILL IN</param> public static void TestTag(ITag Tag, String Name, NBTTagType Type) { Assert.IsTrue(Tag.Name == Name, "Tag had wrong name"); Assert.IsTrue(Tag.Type == Type); }
/// <summary>Creates a new instance of <see cref="NBTTagList"/></summary> /// <param name="Capacity">The capacity to set the collection to</param> /// <param name="SubType">The type of all the sub <see cref="ITag"/></param> /// <param name="Name">The name of this <see cref="NBTTagList"/></param> public NBTTagList(String Name, NBTTagType SubType, Int32 Capacity = 10) : base(Capacity) { this._Name = Name; this._SubType = SubType; }
/// <summary>Creates a new instance of <see cref="NBTTagList"/></summary> /// <param name="Capacity">The capacity to set the collection to</param> /// <param name="SubType">The type of all the sub <see cref="ITag"/></param> public NBTTagList(NBTTagType SubType, Int32 Capacity = 10) : base(Capacity) { this._SubType = SubType; }
internal override void Read(NBTStream stream) { while (stream.Position != stream.Length) { NBTTagType type = (NBTTagType)stream.ReadByteTag(); String name = ""; int len = 0; switch (type) { case NBTTagType.END: return; case NBTTagType.BYTE: this.SetByte(stream.ReadStringTag(), stream.ReadByteTag()); break; case NBTTagType.SHORT: this.SetShort(stream.ReadStringTag(), stream.ReadShortTag()); break; case NBTTagType.INT: this.SetInt(stream.ReadStringTag(), stream.ReadIntTag()); break; case NBTTagType.LONG: this.SetLong(stream.ReadStringTag(), stream.ReadLongTag()); break; case NBTTagType.FLOAT: this.SetFloat(stream.ReadStringTag(), stream.ReadFloatTag()); break; case NBTTagType.DOUBLE: this.SetDouble(stream.ReadStringTag(), stream.ReadDoubleTag()); break; case NBTTagType.BYTE_ARRAY: name = stream.ReadStringTag(); byte[] byteArray = new byte[stream.ReadIntTag()]; for (int i = 0; i < len; ++i) { byteArray[i] = stream.ReadByteTag(); } this.SetByteArray(name, byteArray); break; case NBTTagType.STRING: this.SetString(stream.ReadStringTag(), stream.ReadStringTag()); break; case NBTTagType.LIST: ListTag list = new ListTag(stream.ReadStringTag(), NBTTagType.END); list.Read(stream); this.SetTag(list); break; case NBTTagType.COMPOUND: CompoundTag compound = new CompoundTag(stream.ReadStringTag()); compound.Read(stream); this.SetTag(compound); break; case NBTTagType.INT_ARRAY: name = stream.ReadStringTag(); int[] intArray = new int[stream.ReadIntTag()]; for (int i = 0; i < len; ++i) { intArray[i] = stream.ReadIntTag(); } this.SetIntArray(name, intArray); break; case NBTTagType.LONG_ARRAY: name = stream.ReadStringTag(); long[] longArray = new long[stream.ReadIntTag()]; for (int i = 0; i < len; ++i) { longArray[i] = stream.ReadLongTag(); } this.SetLongArray(stream.ReadStringTag(), longArray); break; default: throw new FormatException(); } } }
/// <summary>Creates a new instance of <see cref="ListBuilder"/></summary> /// <param name="Name">The name of the tag</param> /// <param name="SubType">FILL IN</param> /// <param name="Capacity">FILL IN</param> public ListBuilder(String Name, NBTTagType SubType, Int32 Capacity = 10) { this._Tag = new NBTTagList(Name, SubType, Capacity); }
internal override bool ReadTag(BinaryReader reader) { if (Parent != null) { SkipTag(reader); return(false); } while (true) { NBTTagType nextTag = (NBTTagType)reader.ReadInt32(); NBTTag newTag = null; switch (nextTag) { case NBTTagType.COMPOUND: newTag = new NBTFolder(); break; case NBTTagType.STRING: newTag = new NBTString(); break; case NBTTagType.END: return(true); case NBTTagType.INT: newTag = new NBTInt(); break; case NBTTagType.DOUBLE: newTag = new NBTDouble(); break; case NBTTagType.STRINGARRAY: newTag = new NBTStringArray(); break; case NBTTagType.FLOAT: newTag = new NBTFloat(); break; case NBTTagType.INTARRAY: newTag = new NBTIntArray(); break; case NBTTagType.BYTE: newTag = new NBTByte(); break; case NBTTagType.BYTEARRAY: newTag = new NBTByteArray(); break; case NBTTagType.FLOATARRAY: newTag = new NBTFloatArray(); break; case NBTTagType.DOUBLEARRAY: newTag = new NBTDoubleArray(); break; } newTag.Name = reader.ReadString(); if (newTag.ReadTag(reader)) { tags.Add(newTag.Name, newTag); } newTag.Parent = this; } }
/// <summary>Creates a new instance of <see cref="NBTTagList"/></summary> public NBTTagList(NBTTagType SubType) : base(10) { this._SubType = SubType; }
public ListTag(NBTTagType type) : base("") { this.ListTagType = type; }
/// <summary>Creates a new instance of <see cref="NBTTagList"/></summary> /// <param name="Capacity">The capacity to set the collection to</param> /// <param name="SubType">The type of all the sub <see cref="ITag"/></param> public NBTTagList(NBTTagType SubType, ITag[] SubTags) : base(SubTags.Length) { this._SubType = SubType; this._Tags.AddRange(SubTags); }
public ListTag(string name, NBTTagType type) : base(name) { this.ListTagType = type; }
internal override void Read(NBTStream stream) { while (stream.Offset != stream.Length) { NBTTagType type = (NBTTagType)stream.ReadByte(); string tagName = ""; int len = 0; switch (type) { case NBTTagType.END: return; case NBTTagType.BYTE: tagName = stream.ReadString(); this.PutByte(tagName, stream.ReadByte()); break; case NBTTagType.SHORT: tagName = stream.ReadString(); this.PutShort(tagName, stream.ReadShort()); break; case NBTTagType.INT: tagName = stream.ReadString(); this.PutInt(tagName, stream.ReadInt()); break; case NBTTagType.LONG: tagName = stream.ReadString(); this.PutLong(tagName, stream.ReadLong()); break; case NBTTagType.FLOAT: tagName = stream.ReadString(); this.PutFloat(tagName, stream.ReadFloat()); break; case NBTTagType.DOUBLE: tagName = stream.ReadString(); this.PutDouble(tagName, stream.ReadDouble()); break; case NBTTagType.BYTE_ARRAY: tagName = stream.ReadString(); len = stream.ReadInt(); byte[] b = new byte[len]; for (int i = 0; i < len; ++i) { b[i] = stream.ReadByte(); } this.PutByteArray(tagName, b); break; case NBTTagType.STRING: tagName = stream.ReadString(); this.PutString(tagName, stream.ReadString()); break; case NBTTagType.LIST: tagName = stream.ReadString(); ListTag listtag = new ListTag(NBTTagType.BYTE); listtag.Read(stream); listtag.Name = tagName; this.PutList(listtag); break; case NBTTagType.COMPOUND: tagName = stream.ReadString(); CompoundTag comp = new CompoundTag(); comp.Read(stream); this.PutCompound(tagName, comp); break; case NBTTagType.INT_ARRAY: tagName = stream.ReadString(); len = stream.ReadInt(); int[] n = new int[len]; for (int i = 0; i < len; ++i) { n[i] = stream.ReadInt(); } this.PutIntArray(tagName, n); break; case NBTTagType.LONG_ARRAY: tagName = stream.ReadString(); len = stream.ReadInt(); long[] l = new long[len]; for (int i = 0; i < len; ++i) { l[i] = stream.ReadLong(); } this.PutLongArray(tagName, l); break; default: throw new FormatException(); } } }
/// <summary>Creates a tag with the specified tag type</summary> /// <param name="type">The tag type</param> /// <returns>Creates a tag with the specified tag type</returns> public static ITag Create(NBTTagType type) { return(NBTTagFactory.Types.ContainsKey(type) ? (ITag)Activator.CreateInstance(Types[type]) : null); }