diff --git a/src/main/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtil.java b/src/main/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtil.java index 69c0145fe..76caf6dd3 100644 --- a/src/main/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtil.java +++ b/src/main/java/com/comphenix/protocol/injector/netty/channel/ChannelProtocolUtil.java @@ -12,7 +12,6 @@ import com.comphenix.protocol.reflect.accessors.FieldAccessor; import com.comphenix.protocol.reflect.accessors.MethodAccessor; import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract; -import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.utility.MinecraftReflection; import io.netty.channel.Channel; @@ -31,7 +30,7 @@ final class ChannelProtocolUtil { .declaringClassExactType(networkManagerClass) .build()); - BiFunction baseResolver = null; + BiFunction baseResolver = null; if (attributeKeys.isEmpty()) { // since 1.20.5 the protocol is stored as final field in de-/encoder baseResolver = new Post1_20_5WrappedResolver(); @@ -75,10 +74,10 @@ final class ChannelProtocolUtil { } // decorate the base resolver by wrapping its return value into our packet type value - PROTOCOL_RESOLVER = baseResolver.andThen(nmsProtocol -> PacketType.Protocol.fromVanilla((Enum) nmsProtocol)); + PROTOCOL_RESOLVER = baseResolver; } - private static final class Pre1_20_2DirectResolver implements BiFunction { + private static final class Pre1_20_2DirectResolver implements BiFunction { private final AttributeKey attributeKey; @@ -87,12 +86,12 @@ public Pre1_20_2DirectResolver(AttributeKey attributeKey) { } @Override - public Object apply(Channel channel, PacketType.Sender sender) { - return channel.attr(this.attributeKey).get(); + public PacketType.Protocol apply(Channel channel, PacketType.Sender sender) { + return PacketType.Protocol.fromVanilla((Enum) channel.attr(this.attributeKey).get()); } } - private static final class Post1_20_2WrappedResolver implements BiFunction { + private static final class Post1_20_2WrappedResolver implements BiFunction { private final AttributeKey serverBoundKey; private final AttributeKey clientBoundKey; @@ -106,7 +105,7 @@ public Post1_20_2WrappedResolver(AttributeKey serverBoundKey, AttributeK } @Override - public Object apply(Channel channel, PacketType.Sender sender) { + public PacketType.Protocol apply(Channel channel, PacketType.Sender sender) { AttributeKey key = this.getKeyForSender(sender); Object codecData = channel.attr(key).get(); if (codecData == null) { @@ -114,7 +113,7 @@ public Object apply(Channel channel, PacketType.Sender sender) { } FieldAccessor protocolAccessor = this.getProtocolAccessor(codecData.getClass()); - return protocolAccessor.get(codecData); + return PacketType.Protocol.fromVanilla((Enum) protocolAccessor.get(codecData)); } private AttributeKey getKeyForSender(PacketType.Sender sender) { @@ -141,22 +140,26 @@ private FieldAccessor getProtocolAccessor(Class codecClass) { /** * Since 1.20.5 the protocol is stored as final field in de-/encoder */ - private static final class Post1_20_5WrappedResolver implements BiFunction { + private static final class Post1_20_5WrappedResolver implements BiFunction { // lazy initialized when needed private Function serverProtocolAccessor; private Function clientProtocolAccessor; @Override - public Object apply(Channel channel, PacketType.Sender sender) { + public PacketType.Protocol apply(Channel channel, PacketType.Sender sender) { String key = this.getKeyForSender(sender); Object codecHandler = channel.pipeline().get(key); if (codecHandler == null) { + String unconfiguratedKey = this.getUnconfiguratedKeyForSender(sender); + if (channel.pipeline().get(unconfiguratedKey) != null) { + return PacketType.Protocol.HANDSHAKING; + } return null; } Function protocolAccessor = this.getProtocolAccessor(codecHandler.getClass(), sender); - return protocolAccessor.apply(codecHandler); + return PacketType.Protocol.fromVanilla((Enum) protocolAccessor.apply(codecHandler)); } private Function getProtocolAccessor(Class codecHandler, PacketType.Sender sender) { @@ -187,6 +190,17 @@ private String getKeyForSender(PacketType.Sender sender) { } } + private String getUnconfiguratedKeyForSender(PacketType.Sender sender) { + switch (sender) { + case SERVER: + return "outbound_config"; + case CLIENT: + return "inbound_config"; + default: + throw new IllegalArgumentException("Illegal packet sender " + sender.name()); + } + } + private Function getProtocolAccessor(Class codecHandler) { Class protocolInfoClass = MinecraftReflection.getProtocolInfoClass(); diff --git a/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java b/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java index 4c1426d70..0aa92c529 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java +++ b/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java @@ -60,7 +60,7 @@ private static void initialize() { DATA_WRAPPER = AutoWrapper.wrap(ServerData.class, SERVER_DATA_CLASS); SAMPLE_WRAPPER = AutoWrapper.wrap(PlayerSample.class, PLAYER_SAMPLE_CLASS); - FAVICON_WRAPPER = AutoWrapper.wrap(Favicon.class, MinecraftReflection.getMinecraftClass("network.protocol.status.ServerPing$a")); + FAVICON_WRAPPER = AutoWrapper.wrap(Favicon.class, MinecraftReflection.getMinecraftClass("network.protocol.status.ServerPing$a", "network.protocol.status.ServerStatus$Favicon")); PROFILE_LIST_CONVERTER = BukkitConverters.getListConverter(BukkitConverters.getWrappedGameProfileConverter());