From 6ae5306899faf51e6a70baf8dd6a16847240e165 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 27 Dec 2020 21:53:46 +0100 Subject: [PATCH] HPacket Long --- .../PacketStringUtils.java | 1 + .../main/java/gearth/protocol/HPacket.java | 35 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java index bbe89cf..f9d69b9 100644 --- a/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java +++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java @@ -204,6 +204,7 @@ public class PacketStringUtils { else if (c == 'd') builder.append("{d:").append(p.readDouble()).append('}'); else if (c == 'b') builder.append("{b:").append(p.readByte()).append('}'); else if (c == 'B') builder.append("{b:").append(p.readBoolean()).append('}'); + else if (c == 'l') builder.append("{l:").append(p.readLong()).append('}'); else return; } } diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index 40f05e1..5fcd43c 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -247,6 +247,14 @@ public class HPacket implements StringifyAble { } return this; } + public HPacket replaceLong(int index, long l) { + isEdited = true; + ByteBuffer b = ByteBuffer.allocate(8).putLong(l); + for (int j = 0; j < 8; j++) { + packetInBytes[index + j] = b.array()[j]; + } + return this; + } public HPacket replaceDouble(int index, double d) { isEdited = true; ByteBuffer b = ByteBuffer.allocate(8).putDouble(d); @@ -415,6 +423,16 @@ public class HPacket implements StringifyAble { fixLength(); return this; } + public HPacket appendLong(long l) { + isEdited = true; + packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length + 8); + ByteBuffer byteBuffer = ByteBuffer.allocate(8).putLong(l); + for (int j = 0; j < 8; j++) { + packetInBytes[packetInBytes.length - 8 + j] = byteBuffer.array()[j]; + } + fixLength(); + return this; + } public HPacket appendDouble(double d) { isEdited = true; packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length + 8); @@ -502,6 +520,9 @@ public class HPacket implements StringifyAble { else if (o instanceof Boolean) { appendBoolean((Boolean) o); } + else if (o instanceof Long) { + appendLong((Long) o); + } else { throw new InvalidParameterException(); } @@ -509,20 +530,6 @@ public class HPacket implements StringifyAble { return this; } - - public HPacket removeFrom(int index) { - return removeRange(index, packetInBytes.length - index); - } - public HPacket removeRange(int index, int length) { - isEdited = true; - for (int i = index; i < packetInBytes.length - length; i++) { - packetInBytes[i] = packetInBytes[i + length]; - } - packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length - length); - fixLength(); - return this; - } - public boolean isReplaced() { return isEdited; }