mirror of
https://github.com/ViaVersion/ViaLegacy.git
synced 2025-01-03 18:38:34 +01:00
Implemented MC|TPack custom payload translation
This commit is contained in:
parent
9bc0af52d5
commit
3b4067eb51
@ -271,7 +271,7 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol<ClientboundPackets
|
|||||||
public void register() {
|
public void register() {
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final String channel = wrapper.read(Types1_6_4.STRING); // channel
|
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")) {
|
if (channel.equals("MC|TrList")) {
|
||||||
wrapper.passthrough(Type.INT); // window Id
|
wrapper.passthrough(Type.INT); // window Id
|
||||||
@ -284,12 +284,12 @@ public class Protocol1_4_2to1_3_1_2 extends StatelessProtocol<ClientboundPackets
|
|||||||
}
|
}
|
||||||
wrapper.write(Type.BOOLEAN, false); // unavailable
|
wrapper.write(Type.BOOLEAN, false); // unavailable
|
||||||
}
|
}
|
||||||
length = PacketUtil.calculateLength(wrapper);
|
length = (short) PacketUtil.calculateLength(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.resetReader();
|
wrapper.resetReader();
|
||||||
wrapper.write(Type.STRING, channel); // channel
|
wrapper.write(Types1_6_4.STRING, channel); // channel
|
||||||
wrapper.write(Type.UNSIGNED_SHORT, length); // length
|
wrapper.write(Type.SHORT, length); // length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,6 +29,7 @@ import net.raphimc.vialegacy.ViaLegacy;
|
|||||||
import net.raphimc.vialegacy.api.protocol.StatelessProtocol;
|
import net.raphimc.vialegacy.api.protocol.StatelessProtocol;
|
||||||
import net.raphimc.vialegacy.api.remapper.LegacyItemRewriter;
|
import net.raphimc.vialegacy.api.remapper.LegacyItemRewriter;
|
||||||
import net.raphimc.vialegacy.api.splitter.PreNettySplitter;
|
import net.raphimc.vialegacy.api.splitter.PreNettySplitter;
|
||||||
|
import net.raphimc.vialegacy.api.util.PacketUtil;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.metadata.MetadataRewriter;
|
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.metadata.MetadataRewriter;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.rewriter.ItemRewriter;
|
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.rewriter.ItemRewriter;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.rewriter.SoundRewriter;
|
import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.rewriter.SoundRewriter;
|
||||||
@ -40,6 +41,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Type
|
|||||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.metadata.MetaIndex1_8to1_7_6;
|
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.metadata.MetaIndex1_8to1_7_6;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
|
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_5_2, ClientboundPackets1_6_1, ServerboundPackets1_5_2, ServerboundPackets1_6_4> {
|
public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_5_2, ClientboundPackets1_6_1, ServerboundPackets1_5_2, ServerboundPackets1_6_4> {
|
||||||
@ -293,6 +295,33 @@ public class Protocol1_6_1to1_5_2 extends StatelessProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.registerClientbound(ClientboundPackets1_5_2.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||||
|
@Override
|
||||||
|
public void register() {
|
||||||
|
handler(wrapper -> {
|
||||||
|
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 -> {
|
this.registerServerbound(ServerboundPackets1_6_4.SERVER_PING, wrapper -> {
|
||||||
wrapper.clearPacket();
|
wrapper.clearPacket();
|
||||||
|
@ -1120,9 +1120,7 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case "MC|Brand": {
|
case "MC|Brand": {
|
||||||
final byte[] data = wrapper.read(Type.REMAINING_BYTES);
|
wrapper.write(Type.STRING, new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8)); // brand
|
||||||
final String brand = new String(data, StandardCharsets.UTF_8);
|
|
||||||
wrapper.write(Type.STRING, brand);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "MC|TrList":
|
case "MC|TrList":
|
||||||
@ -1150,12 +1148,11 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "MC|RPack": {
|
case "MC|RPack": {
|
||||||
final byte[] data = wrapper.read(Type.REMAINING_BYTES);
|
final String url = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8); // url
|
||||||
final String resourcePackURL = new String(data, StandardCharsets.UTF_8);
|
|
||||||
wrapper.setPacketType(ClientboundPackets1_8.RESOURCE_PACK);
|
|
||||||
wrapper.clearPacket();
|
wrapper.clearPacket();
|
||||||
wrapper.write(Type.STRING, resourcePackURL);
|
wrapper.setPacketType(ClientboundPackets1_8.RESOURCE_PACK);
|
||||||
wrapper.write(Type.STRING, "legacy");
|
wrapper.write(Type.STRING, url); // url
|
||||||
|
wrapper.write(Type.STRING, "legacy"); // hash
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1261,7 +1258,6 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
if (item != null && item.identifier() == ItemList1_6.writtenBook.itemID && direction == 255) { // If placed item is a book then cancel it and send a MC|BOpen to the client
|
if (item != null && item.identifier() == ItemList1_6.writtenBook.itemID && direction == 255) { // If placed item is a book then cancel it and send a MC|BOpen to the client
|
||||||
final PacketWrapper openBook = PacketWrapper.create(ClientboundPackets1_8.PLUGIN_MESSAGE, wrapper.user());
|
final PacketWrapper openBook = PacketWrapper.create(ClientboundPackets1_8.PLUGIN_MESSAGE, wrapper.user());
|
||||||
openBook.write(Type.STRING, "MC|BOpen"); // channel
|
openBook.write(Type.STRING, "MC|BOpen"); // channel
|
||||||
openBook.write(Type.REMAINING_BYTES, new byte[0]); // data
|
|
||||||
openBook.send(Protocol1_8to1_7_6_10.class);
|
openBook.send(Protocol1_8to1_7_6_10.class);
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user