From 56cc99e0e665d3a7efc722dbbbd238fa0e475419 Mon Sep 17 00:00:00 2001 From: Eduardo Alonso Date: Thu, 7 Jan 2021 13:27:10 +0100 Subject: [PATCH 1/2] Fix encoding for appended strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a packet is constructed using the expression form, PacketStringUtils will encode properly the string like this: String latin = new String(actualString.toString().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); This does not happen if the packet is constructed using the Object... constructor, and packets like this: new HPacket(10, 2, 100000, "Dragón de Fuego Azul", 3).toExpression(); will show � instead of ó. Whereas: new HPacket("{l}{h:10}{i:2}{i:100000}{s:\"Dragón de Fuego Azul\"}{i:3}").toExpression(); would display the string correctly. --- G-Earth/src/main/java/gearth/protocol/HPacket.java | 1 + 1 file changed, 1 insertion(+) diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index c1cfb94..4b2bf1c 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -491,6 +491,7 @@ public class HPacket implements StringifyAble { return this; } public HPacket appendString(String s) { + s = new String(s.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); return appendString(s, StandardCharsets.ISO_8859_1); } From 21b0b22a2c32e1a32dea2fcc7f9efb98cad72f1d Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Thu, 7 Jan 2021 14:35:59 +0100 Subject: [PATCH 2/2] Update HPacket.java --- G-Earth/src/main/java/gearth/protocol/HPacket.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index 4b2bf1c..08cf1d2 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -491,7 +491,6 @@ public class HPacket implements StringifyAble { return this; } public HPacket appendString(String s) { - s = new String(s.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); return appendString(s, StandardCharsets.ISO_8859_1); } @@ -516,7 +515,7 @@ public class HPacket implements StringifyAble { appendInt((Integer)o); } else if (o instanceof String) { - appendString((String)o); + appendString((String)o, StandardCharsets.UTF_8); } else if (o instanceof Boolean) { appendBoolean((Boolean) o); @@ -618,4 +617,4 @@ public class HPacket implements StringifyAble { System.out.println(packetverify.toString().equals(packet.toString())); } -} \ No newline at end of file +}