From 3b4067eb515f31a174c98177b42af1dd316e4391 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Wed, 28 Feb 2024 23:34:09 +0100 Subject: [PATCH] Implemented MC|TPack custom payload translation --- .../Protocol1_4_2to1_3_1_2.java | 8 ++--- .../Protocol1_6_1to1_5_2.java | 29 +++++++++++++++++++ .../Protocol1_8to1_7_6_10.java | 14 ++++----- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/Protocol1_4_2to1_3_1_2.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/Protocol1_4_2to1_3_1_2.java index 6ce9546..838e466 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/Protocol1_4_2to1_3_1_2.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/Protocol1_4_2to1_3_1_2.java @@ -271,7 +271,7 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol { final String channel = wrapper.read(Types1_6_4.STRING); // channel - int length = wrapper.read(Type.SHORT); // length + short length = wrapper.read(Type.SHORT); // length if (channel.equals("MC|TrList")) { wrapper.passthrough(Type.INT); // window Id @@ -284,12 +284,12 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol { @@ -293,6 +295,33 @@ public class Protocol1_6_1to1_5_2 extends StatelessProtocol { + String channel = wrapper.read(Types1_6_4.STRING); // channel + short length = wrapper.read(Type.SHORT); // length + + if (channel.equals("MC|TPack")) { + channel = "MC|RPack"; + final String[] data = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); // data + final String url = data[0]; + final String resolution = data[1]; + if (!resolution.equals("16")) { + wrapper.cancel(); + return; + } + + wrapper.write(Type.REMAINING_BYTES, url.getBytes(StandardCharsets.UTF_8)); + length = (short) PacketUtil.calculateLength(wrapper); + } + + wrapper.resetReader(); + wrapper.write(Types1_6_4.STRING, channel); // channel + wrapper.write(Type.SHORT, length); // length + }); + } + }); this.registerServerbound(ServerboundPackets1_6_4.SERVER_PING, wrapper -> { wrapper.clearPacket(); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java index b52932d..2ef6d34 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java @@ -1120,9 +1120,7 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol