From 4957fe633ef8dd5ea4b2e21c091327832c977bbf Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 3 Feb 2025 12:16:21 -0700 Subject: [PATCH] Fix some inconsistencies --- lib/consts.dart | 4 ++-- lib/nbt/NbtIo.dart | 28 ++++++++++++++++++---------- lib/packets/packets.dart | 6 ++++-- pubspec.yaml | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/consts.dart b/lib/consts.dart index dda2544..d6914ad 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -1,5 +1,5 @@ class Constants { - static const VERSION = "1.4.012225+0413"; - static const NBT_REVISION = "1.3.012225+0304"; + static const VERSION = "1.4.020325+1215"; + static const NBT_REVISION = "1.4.020325+1215"; static const ARGS_REVISION = "1.4.012225+0413"; } diff --git a/lib/nbt/NbtIo.dart b/lib/nbt/NbtIo.dart index f16d610..a7585a0 100644 --- a/lib/nbt/NbtIo.dart +++ b/lib/nbt/NbtIo.dart @@ -17,23 +17,23 @@ class NbtIo { } // This function will read the file and check if it is infact gzipped - static Future read(String file) async { + static Future read(String file) async { await _read(file); if (_io.readByte() == TagType.Compound.byte) { _io.resetPosition(); - return Tag.readNamedTag(_io) as CompoundTag; + return Tag.readNamedTag(_io); } else { // Is likely gzip compressed return readCompressed(file); } } - static Future readCompressed(String file) async { + static Future readCompressed(String file) async { _io = ByteLayer(); await _io.readFromFile(file); await _io.decompress(); _io.resetPosition(); - return Tag.readNamedTag(_io) as CompoundTag; + return Tag.readNamedTag(_io); } static Future write(String file, CompoundTag tag) async { @@ -60,7 +60,7 @@ class NbtIo { return base64Encoder.encode(_io.bytes); } - static Future readBase64String(String encoded) async { + static Future readBase64String(String encoded) async { _io = ByteLayer(); List bytes = base64Encoder.decode(encoded); for (int byte in bytes) { @@ -68,7 +68,7 @@ class NbtIo { } _io.decompress(); _io.resetPosition(); - return Tag.readNamedTag(_io) as CompoundTag; + return Tag.readNamedTag(_io); } /// Writes the NBT Data to stream in compressed mode @@ -80,7 +80,7 @@ class NbtIo { return _io.bytes; } - static Future readFromStreamCompressed(Uint8List list) async { + static Future readFromStreamCompressed(Uint8List list) async { _io = ByteLayer(); try { _io.writeBytes(list); @@ -90,7 +90,7 @@ class NbtIo { } catch (E) { print(E); } finally { - return Tag.readNamedTag(_io) as CompoundTag; + return Tag.readNamedTag(_io); } } @@ -101,7 +101,7 @@ class NbtIo { return _io.bytes; } - static Future readFromStream(Uint8List list) async { + static Future readFromStream(Uint8List list) async { _io = ByteLayer(); try { _io.writeBytes(list); @@ -109,7 +109,15 @@ class NbtIo { } catch (E) { print(E); } finally { - return Tag.readNamedTag(_io) as CompoundTag; + if (_io.readByte() == TagType.Compound.byte) { + _io.resetPosition(); + return Tag.readNamedTag(_io); + } else { + _io.resetPosition(); + _io.decompress(); + _io.resetPosition(); + return Tag.readNamedTag(_io); + } } } } diff --git a/lib/packets/packets.dart b/lib/packets/packets.dart index 7e028e6..93464de 100644 --- a/lib/packets/packets.dart +++ b/lib/packets/packets.dart @@ -123,7 +123,8 @@ class PacketServer { } CompoundTag tag = - await NbtIo.readFromStream(Uint8List.fromList(remainingBytes)); + await NbtIo.readFromStream(Uint8List.fromList(remainingBytes)) + as CompoundTag; StringBuilder builder = StringBuilder(); Tag.writeStringifiedNamedTag(tag, builder, 0); @@ -327,7 +328,8 @@ class PacketClient { pktBytes = await xtea.decipher(pktBytes); } - NBTTag = await NbtIo.readFromStream(Uint8List.fromList(pktBytes)); + NBTTag = await NbtIo.readFromStream(Uint8List.fromList(pktBytes)) + as CompoundTag; } responseWait.complete(); diff --git a/pubspec.yaml b/pubspec.yaml index b9bd3da..91275d5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: libac_dart description: "Aria's Creations code library" -version: 1.4.012225+0413 +version: 1.4.020325+1215 homepage: "https://zontreck.com" environment: