private static IEnumerable <string> GetStrings(NbtTag tag, string name) { var ret = new List <string>(); switch (tag.TagType) { case TagType.TagByte: ret.Add(String.Format("TagByte({0}) : {1}", name, ((TagByte)tag).Data)); break; case TagType.TagShort: ret.Add(String.Format("TagShort({0}) : {1}", name, ((TagShort)tag).Data)); break; case TagType.TagInt: ret.Add(String.Format("TagInt({0}) : {1}", name, ((TagInt)tag).Data)); break; case TagType.TagLong: ret.Add(String.Format("TagLong({0}) : {1}", name, ((TagLong)tag).Data)); break; case TagType.TagFloat: ret.Add(String.Format("TagFloat({0}) : {1}", name, ((TagFloat)tag).Data)); break; case TagType.TagDouble: ret.Add(String.Format("TagDouble({0}) : {1}", name, ((TagDouble)tag).Data)); break; case TagType.TagByteArray: ret.Add(String.Format("TagByteAray({0}) : [{1} entries]", name, ((TagByteArray)tag).Data.Length)); break; case TagType.TagString: ret.Add(String.Format("TagString({0}) : {1}", name, ((TagString)tag).Data)); break; case TagType.TagList: ret.Add(String.Format("TagList({0}) : {1} entries of type {2}", name, ((TagList)tag).Count, (tag as TagList).ValueType)); ret.Add("{"); foreach (var listitem in ((TagList)tag).Tags) { ret.AddRange(GetStrings(listitem, "[none]").Select(sitem => "\t" + sitem)); } ret.Add("}"); break; case TagType.TagCompound: ret.AddRange(NbtStringArr(tag as TagCompound, name)); break; case TagType.TagIntArray: ret.Add(String.Format("TagIntAray({0}) : [{1} entries]", name, ((TagIntArray)tag).Data.Length)); break; } return(ret); }
private static void WriteTag(string name, NbtTag tag) { fstr.WriteByte((byte)tag.TagType); if (tag.TagType == TagType.TagEnd) { return; } WriteString(name); WriteValue(tag); }
/// <summary> /// Adds the tag to the list /// </summary> /// <param name="tag">The tag to add</param> public void Add(NbtTag tag) { if (tag == null) { throw new ArgumentNullException("tag"); } if (tag.TagType != ValueType) { throw new InvalidOperationException("Attempted to add a tag with wrong tag type."); } tags.Add(tag); }
private static void WriteValue(NbtTag tag) { switch (tag.TagType) { case TagType.TagEnd: break; case TagType.TagByte: WriteByte(tag as TagByte); break; case TagType.TagShort: WriteShort(tag as TagShort); break; case TagType.TagInt: WriteInt(tag as TagInt); break; case TagType.TagLong: WriteLong(tag as TagLong); break; case TagType.TagFloat: WriteFloat(tag as TagFloat); break; case TagType.TagDouble: WriteDouble(tag as TagDouble); break; case TagType.TagByteArray: WriteByteArray(tag as TagByteArray); break; case TagType.TagString: WriteString(tag as TagString); break; case TagType.TagList: WriteList(tag as TagList); break; case TagType.TagCompound: WriteCompound(tag as TagCompound); break; case TagType.TagIntArray: WriteIntArray(tag as TagIntArray); break; } }
private static dynamic GetTagValue(NbtTag tag) { switch (tag.TagType) { case TagType.TagByte: return(((TagByte)tag).Data); case TagType.TagShort: return(((TagShort)tag).Data); case TagType.TagInt: return(((TagInt)tag).Data); case TagType.TagLong: return(((TagLong)tag).Data); case TagType.TagFloat: return(((TagFloat)tag).Data); case TagType.TagDouble: return(((TagDouble)tag).Data); case TagType.TagByteArray: return(((TagByteArray)tag).Data); case TagType.TagString: return(((TagString)tag).Data); case TagType.TagList: return(((TagList)tag).Clone()); case TagType.TagCompound: return(((TagCompound)tag).Clone()); case TagType.TagIntArray: return(((TagIntArray)tag).Data); default: throw new ArgumentException("Not a valid TagType", "tag"); } }
private static Type GetTagType(NbtTag tag) { switch (tag.TagType) { case TagType.TagByte: return(typeof(byte)); case TagType.TagShort: return(typeof(short)); case TagType.TagInt: return(typeof(int)); case TagType.TagLong: return(typeof(long)); case TagType.TagFloat: return(typeof(float)); case TagType.TagDouble: return(typeof(double)); case TagType.TagByteArray: return(typeof(byte[])); case TagType.TagString: return(typeof(string)); case TagType.TagList: return(typeof(TagList)); case TagType.TagCompound: return(typeof(TagCompound)); case TagType.TagIntArray: return(typeof(int[])); default: throw new ArgumentException("Not a valid TagType", "tag"); } }
private static void AssignValue(FieldInfo field, NbtTag tag, object target) { field.SetValue(target, GetTagValue(tag)); }
private static void AssignValue(MethodInfo method, NbtTag tag, object target) { method.Invoke(target, new object[] { GetTagValue(tag) }); }
private static void AssignValue(PropertyInfo prop, NbtTag tag, object target) { prop.SetValue(target, GetTagValue(tag)); }
private static bool Validate(FieldInfo field, NbtTag tag) { return(field.FieldType == GetTagType(tag)); }
private static bool Validate(PropertyInfo prop, NbtTag tag) { return(prop.PropertyType == GetTagType(tag)); }
private static bool Validate(MethodInfo method, NbtTag tag) { return(method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == GetTagType(tag)); }