@@ -20,6 +20,8 @@ public class NbtTree : ICopyable<NbtTree>
2020 private Stream _stream = null ;
2121 private TagNodeCompound _root = null ;
2222 private string _rootName = "" ;
23+ List < TagNodeCompound > compoundTagCache = new List < TagNodeCompound > ( ) ;
24+ private string lastTagName = "" ;
2325
2426 private static TagNodeNull _nulltag = new TagNodeNull ( ) ;
2527
@@ -83,9 +85,15 @@ public NbtTree (Stream s)
8385 /// <param name="s">An open, readable data stream containing NBT data.</param>
8486 public void ReadFrom ( Stream s )
8587 {
86- if ( s != null ) {
88+ if ( s != null ) {
89+
8790 _stream = s ;
88- _root = ReadRoot ( ) ;
91+ try {
92+ _root = ReadRoot ( ) ;
93+ }
94+ catch ( Exception e ) {
95+ Console . Write ( e . Message ) ;
96+ }
8997 _stream = null ;
9098 }
9199 }
@@ -249,6 +257,7 @@ private TagNode ReadByteArray ()
249257
250258 int length = BitConverter . ToInt32 ( lenBytes , 0 ) ;
251259 if ( length < 0 ) {
260+ Console . Write ( "Negative lenght while reading byte array with name: " + this . lastTagName ) ;
252261 throw new NBTException ( NBTException . MSG_READ_NEG ) ;
253262 }
254263
@@ -269,11 +278,7 @@ private TagNode ReadString ()
269278 Array . Reverse ( lenBytes ) ;
270279 }
271280
272- short len = BitConverter . ToInt16 ( lenBytes , 0 ) ;
273- if ( len < 0 ) {
274- throw new NBTException ( NBTException . MSG_READ_NEG ) ;
275- }
276-
281+ ushort len = BitConverter . ToUInt16 ( lenBytes , 0 ) ;
277282 byte [ ] strBytes = new byte [ len ] ;
278283 _stream . Read ( strBytes , 0 , len ) ;
279284
@@ -305,6 +310,7 @@ private TagNode ReadList ()
305310
306311 int length = BitConverter . ToInt32 ( lenBytes , 0 ) ;
307312 if ( length < 0 ) {
313+ Console . Write ( "Negative lenght while reading tag list with name: " + this . lastTagName ) ;
308314 throw new NBTException ( NBTException . MSG_READ_NEG ) ;
309315 }
310316
@@ -322,7 +328,9 @@ private TagNode ReadCompound ()
322328 {
323329 TagNodeCompound val = new TagNodeCompound ( ) ;
324330
325- while ( ReadTag ( val ) ) ;
331+ while ( ReadTag ( val ) ) {
332+
333+ }
326334
327335 return val ;
328336 }
@@ -338,6 +346,7 @@ private TagNode ReadIntArray ()
338346
339347 int length = BitConverter . ToInt32 ( lenBytes , 0 ) ;
340348 if ( length < 0 ) {
349+ Console . Write ( "Negative lenght while reading int array with name: " + this . lastTagName ) ;
341350 throw new NBTException ( NBTException . MSG_READ_NEG ) ;
342351 }
343352
@@ -367,6 +376,7 @@ private TagNode ReadLongArray ()
367376
368377 int length = BitConverter . ToInt32 ( lenBytes , 0 ) ;
369378 if ( length < 0 ) {
379+ Console . Write ( "Negative lenght while reading long array with name: " + this . lastTagName ) ;
370380 throw new NBTException ( NBTException . MSG_READ_NEG ) ;
371381 }
372382
@@ -396,6 +406,7 @@ private TagNode ReadShortArray ()
396406
397407 int length = BitConverter . ToInt32 ( lenBytes , 0 ) ;
398408 if ( length < 0 ) {
409+ Console . Write ( "Negative lenght while reading short array with name: " + this . lastTagName ) ;
399410 throw new NBTException ( NBTException . MSG_READ_NEG ) ;
400411 }
401412
@@ -419,7 +430,13 @@ private TagNodeCompound ReadRoot ()
419430 TagType type = ( TagType ) _stream . ReadByte ( ) ;
420431 if ( type == TagType . TAG_COMPOUND ) {
421432 _rootName = ReadString ( ) . ToTagString ( ) . Data ; // name
422- return ReadValue ( type ) as TagNodeCompound ;
433+
434+ TagNodeCompound root1 = ReadValue ( type ) as TagNodeCompound ;
435+ if ( root1 == null )
436+ Console . WriteLine ( "Read value return null." ) ;
437+ else
438+ Console . WriteLine ( "Read value return normal value." ) ;
439+ return root1 ;
423440 }
424441
425442 return null ;
@@ -430,6 +447,7 @@ private bool ReadTag (TagNodeCompound parent)
430447 TagType type = ( TagType ) _stream . ReadByte ( ) ;
431448 if ( type != TagType . TAG_END ) {
432449 string name = ReadString ( ) . ToTagString ( ) . Data ;
450+ lastTagName = name ;
433451 parent [ name ] = ReadValue ( type ) ;
434452 return true ;
435453 }
0 commit comments