From 7aec71bdecf6c2bb649e686c2fa1c3742d073fdb Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 28 Jul 2018 21:41:46 +0300 Subject: [PATCH] Fix long strings reading/writing --- .gitignore | 1 + SubstrateCS/Source/Nbt/NbtTree.cs | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 013fcec7..791191dc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ SubstrateCS/Release/ *.sdf *.user +**/UserPrefs.xml diff --git a/SubstrateCS/Source/Nbt/NbtTree.cs b/SubstrateCS/Source/Nbt/NbtTree.cs index eff53ab6..bd15a772 100644 --- a/SubstrateCS/Source/Nbt/NbtTree.cs +++ b/SubstrateCS/Source/Nbt/NbtTree.cs @@ -269,10 +269,7 @@ private TagNode ReadString () Array.Reverse(lenBytes); } - short len = BitConverter.ToInt16(lenBytes, 0); - if (len < 0) { - throw new NBTException(NBTException.MSG_READ_NEG); - } + ushort len = BitConverter.ToUInt16(lenBytes, 0); byte[] strBytes = new byte[len]; _stream.Read(strBytes, 0, len); @@ -574,7 +571,7 @@ private void WriteString (TagNodeString val) System.Text.Encoding str = Encoding.UTF8; byte[] gzBytes = str.GetBytes(val.Data); - byte[] lenBytes = BitConverter.GetBytes((short)gzBytes.Length); + byte[] lenBytes = BitConverter.GetBytes((ushort)gzBytes.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes);