public unsafe NbtTag ReadTag( byte typeId, bool readTagName ) { NbtTag tag = default( NbtTag ); if( typeId == 0 ) { tag.TagId = NbtTagType.Invalid; return tag; } tag.Name = readTagName ? ReadString() : null; tag.TagId = (NbtTagType)typeId; switch( (NbtTagType)typeId ) { case NbtTagType.Int8: tag.Value = reader.ReadByte(); break; case NbtTagType.Int16: tag.Value = ReadInt16(); break; case NbtTagType.Int32: tag.Value = ReadInt32(); break; case NbtTagType.Int64: tag.Value = ReadInt64(); break; case NbtTagType.Real32: int temp32 = ReadInt32(); tag.Value = *((float*)&temp32); break; case NbtTagType.Real64: long temp64 = ReadInt64(); tag.Value = *((double*)&temp64); break; case NbtTagType.Int8Array: tag.Value = reader.ReadBytes( ReadInt32() ); break; case NbtTagType.String: tag.Value = ReadString(); break; case NbtTagType.List: NbtList list = new NbtList(); list.ChildTagId = (NbtTagType)reader.ReadByte(); list.ChildrenValues = new object[ReadInt32()]; for( int i = 0; i < list.ChildrenValues.Length; i++ ) list.ChildrenValues[i] = ReadTag( (byte)list.ChildTagId, false ).Value; tag.Value = list; break; case NbtTagType.Compound: Dictionary<string, NbtTag> children = new Dictionary<string, NbtTag>(); NbtTag child; while( (child = ReadTag( reader.ReadByte(), true )).TagId != NbtTagType.Invalid ) children[child.Name] = child; tag.Value = children; break; case NbtTagType.Int32Array: int[] array = new int[ReadInt32()]; for( int i = 0; i < array.Length; i++ ) array[i] = ReadInt32(); tag.Value = array; break; default: throw new InvalidDataException( "Unrecognised tag id: " + typeId ); } return tag; }
public unsafe NbtTag ReadTag(byte typeId, bool readTagName) { NbtTag tag = default(NbtTag); if (typeId == 0) { tag.TagId = NbtTagType.Invalid; return(tag); } tag.Name = readTagName ? ReadString() : null; tag.TagId = (NbtTagType)typeId; switch ((NbtTagType)typeId) { case NbtTagType.Int8: tag.Value = reader.ReadByte(); break; case NbtTagType.Int16: tag.Value = ReadInt16(); break; case NbtTagType.Int32: tag.Value = ReadInt32(); break; case NbtTagType.Int64: tag.Value = ReadInt64(); break; case NbtTagType.Real32: int temp32 = ReadInt32(); tag.Value = *((float *)&temp32); break; case NbtTagType.Real64: long temp64 = ReadInt64(); tag.Value = *((double *)&temp64); break; case NbtTagType.Int8Array: tag.Value = reader.ReadBytes(ReadInt32()); break; case NbtTagType.String: tag.Value = ReadString(); break; case NbtTagType.List: NbtList list = new NbtList(); list.ChildTagId = (NbtTagType)reader.ReadByte(); list.ChildrenValues = new object[ReadInt32()]; for (int i = 0; i < list.ChildrenValues.Length; i++) { list.ChildrenValues[i] = ReadTag((byte)list.ChildTagId, false).Value; } tag.Value = list; break; case NbtTagType.Compound: Dictionary <string, NbtTag> children = new Dictionary <string, NbtTag>(); NbtTag child; while ((child = ReadTag(reader.ReadByte(), true)).TagId != NbtTagType.Invalid) { children[child.Name] = child; } tag.Value = children; break; case NbtTagType.Int32Array: int[] array = new int[ReadInt32()]; for (int i = 0; i < array.Length; i++) { array[i] = ReadInt32(); } tag.Value = array; break; default: throw new InvalidDataException("Unrecognised tag id: " + typeId); } return(tag); }