diff --git a/Server/src/main/core/game/world/update/flag/PlayerFlags530.kt b/Server/src/main/core/game/world/update/flag/PlayerFlags530.kt index bcc1e3356..a83f0235c 100644 --- a/Server/src/main/core/game/world/update/flag/PlayerFlags530.kt +++ b/Server/src/main/core/game/world/update/flag/PlayerFlags530.kt @@ -11,7 +11,6 @@ import core.tools.* import core.api.* import core.game.world.GameWorld -import java.nio.charset.StandardCharsets import kotlin.reflect.* import kotlin.math.max @@ -28,12 +27,13 @@ sealed class PlayerFlags530 (p: Int, o: Int, f: EntityFlag) : EFlagProvider (530 else buffer.p1 (context.chatIcon) val chatBuf = ByteArray(256) - chatBuf[0] = context.text.length.toByte() + val encodedText = CP1252.toBytes(context.text) + chatBuf[0] = encodedText.size.toByte() val offset = 1 + StringUtils.encryptPlayerChat ( chatBuf, 0, 1, - context.text.length, - context.text.toByteArray(StandardCharsets.UTF_8) + encodedText.size, + encodedText ) buffer.p1 (offset + 1) buffer.putReverse (chatBuf, 0, offset) diff --git a/Server/src/main/core/net/packet/out/CommunicationMessage.java b/Server/src/main/core/net/packet/out/CommunicationMessage.java index 5cd5e592d..77e86af95 100644 --- a/Server/src/main/core/net/packet/out/CommunicationMessage.java +++ b/Server/src/main/core/net/packet/out/CommunicationMessage.java @@ -6,6 +6,7 @@ import core.net.packet.IoBuffer; import core.net.packet.OutgoingPacket; import core.net.packet.PacketHeader; import core.net.packet.context.MessageContext; +import core.tools.CP1252; import core.tools.StringUtils; import core.game.bots.AIPlayer; @@ -21,20 +22,21 @@ public final class CommunicationMessage implements OutgoingPacket= 128 && out < 160) { - int cp1252 = charMap[out - 128]; + int cp1252 = CHAR_MAP[out - 128]; if (cp1252 == 0) { cp1252 = 63; } @@ -20,4 +24,26 @@ public class CP1252 { } return (char) out; } + + public static byte getByte(char value) { + if ((value > 0 && value < 128) || (value >= 160 && value <= 255)) { + return (byte) value; + } + + for (int i = 0; i < CHAR_MAP.length; i++) { + if (CHAR_MAP[i] != 0 && CHAR_MAP[i] == value) { + return (byte) (i + 128); + } + } + + return 63; + } + + public static byte[] toBytes(CharSequence value) { + byte[] out = new byte[value.length()]; + for (int i = 0; i < value.length(); i++) { + out[i] = getByte(value.charAt(i)); + } + return out; + } } diff --git a/Server/src/main/core/tools/StringUtils.java b/Server/src/main/core/tools/StringUtils.java index 84ac0e3e0..bc55800b6 100644 --- a/Server/src/main/core/tools/StringUtils.java +++ b/Server/src/main/core/tools/StringUtils.java @@ -502,7 +502,7 @@ public final class StringUtils { return ""; int charsDecoded = 0; int i_4_ = 0; - String s = ""; + StringBuilder s = new StringBuilder(totalChars); for (;;) { byte i_7_ = (byte) buffer.get(); if (i_7_ >= 0) @@ -511,7 +511,7 @@ public final class StringUtils { i_4_ = anIntArray241[i_4_]; int i_8_; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (totalChars <= ++charsDecoded) break; i_4_ = 0; @@ -521,7 +521,7 @@ public final class StringUtils { else i_4_++; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (++charsDecoded >= totalChars) break; i_4_ = 0; @@ -531,7 +531,7 @@ public final class StringUtils { else i_4_ = anIntArray241[i_4_]; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (totalChars <= ++charsDecoded) break; i_4_ = 0; @@ -541,7 +541,7 @@ public final class StringUtils { else i_4_ = anIntArray241[i_4_]; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (totalChars <= ++charsDecoded) break; @@ -552,7 +552,7 @@ public final class StringUtils { else i_4_++; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (++charsDecoded >= totalChars) break; i_4_ = 0; @@ -562,7 +562,7 @@ public final class StringUtils { else i_4_ = anIntArray241[i_4_]; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (totalChars <= ++charsDecoded) break; i_4_ = 0; @@ -572,7 +572,7 @@ public final class StringUtils { else i_4_++; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (totalChars <= ++charsDecoded) break; i_4_ = 0; @@ -582,13 +582,13 @@ public final class StringUtils { else i_4_++; if ((i_8_ = anIntArray241[i_4_]) < 0) { - s += (char) (byte) (i_8_ ^ 0xffffffff); + s.append(CP1252.getFromByte((byte) (i_8_ ^ 0xffffffff))); if (++charsDecoded >= totalChars) break; i_4_ = 0; } } - return s; + return s.toString(); } catch (RuntimeException runtimeexception) { runtimeexception.printStackTrace(); }