Fix some inconsistencies

This commit is contained in:
zontreck 2025-02-03 12:16:21 -07:00
parent cfd97a687c
commit 4957fe633e
4 changed files with 25 additions and 15 deletions

View file

@ -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";
}

View file

@ -17,23 +17,23 @@ class NbtIo {
}
// This function will read the file and check if it is infact gzipped
static Future<CompoundTag> read(String file) async {
static Future<Tag> 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<CompoundTag> readCompressed(String file) async {
static Future<Tag> 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<void> write(String file, CompoundTag tag) async {
@ -60,7 +60,7 @@ class NbtIo {
return base64Encoder.encode(_io.bytes);
}
static Future<CompoundTag> readBase64String(String encoded) async {
static Future<Tag> readBase64String(String encoded) async {
_io = ByteLayer();
List<int> 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<CompoundTag> readFromStreamCompressed(Uint8List list) async {
static Future<Tag> 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<CompoundTag> readFromStream(Uint8List list) async {
static Future<Tag> 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);
}
}
}
}

View file

@ -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();