|
30 | 30 | import com.comphenix.protocol.reflect.VolatileField;
|
31 | 31 | import com.comphenix.protocol.reflect.accessors.Accessors;
|
32 | 32 | import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
| 33 | +import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract; |
33 | 34 | import com.comphenix.protocol.utility.ByteBuddyFactory;
|
34 | 35 | import com.comphenix.protocol.utility.ByteBuddyGenerated;
|
35 | 36 | import com.comphenix.protocol.utility.MinecraftFields;
|
|
56 | 57 | import java.lang.reflect.Field;
|
57 | 58 | import java.lang.reflect.InvocationTargetException;
|
58 | 59 | import java.lang.reflect.Method;
|
| 60 | +import java.lang.reflect.Modifier; |
59 | 61 | import java.net.Socket;
|
60 | 62 | import java.net.SocketAddress;
|
61 | 63 | import java.util.*;
|
@@ -84,6 +86,7 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
84 | 86 |
|
85 | 87 | // Versioning
|
86 | 88 | private static Class<?> PACKET_SET_PROTOCOL = null;
|
| 89 | + private static FieldAccessor PROTOCOL_VERSION_ACCESSOR = null; |
87 | 90 |
|
88 | 91 | private static AtomicInteger keyId = new AtomicInteger();
|
89 | 92 | private static AttributeKey<Integer> PROTOCOL_KEY;
|
@@ -662,15 +665,21 @@ private void handleLogin(Class<?> packetClass, Object packet) {
|
662 | 665 | if (PACKET_SET_PROTOCOL == null) {
|
663 | 666 | try {
|
664 | 667 | PACKET_SET_PROTOCOL = PacketType.Handshake.Client.SET_PROTOCOL.getPacketClass();
|
| 668 | + |
| 669 | + // resolve the protocol version field here - if we're unable to find it we don't need to worry about it |
| 670 | + Field protocolVersionField = FuzzyReflection.fromClass(PACKET_SET_PROTOCOL, true).getField(FuzzyFieldContract.newBuilder() |
| 671 | + .banModifier(Modifier.STATIC) |
| 672 | + .typeExact(int.class) |
| 673 | + .build()); |
| 674 | + PROTOCOL_VERSION_ACCESSOR = Accessors.getFieldAccessor(protocolVersionField); |
665 | 675 | } catch (Throwable ex) {
|
666 | 676 | PACKET_SET_PROTOCOL = getClass(); // If we can't find it don't worry about it
|
667 | 677 | }
|
668 | 678 | }
|
669 | 679 |
|
670 | 680 | if (PACKET_SET_PROTOCOL.equals(packetClass)) {
|
671 |
| - FuzzyReflection fuzzy = FuzzyReflection.fromObject(packet); |
672 | 681 | try {
|
673 |
| - int protocol = (int) fuzzy.invokeMethod(packet, "getProtocol", int.class); |
| 682 | + int protocol = (int) PROTOCOL_VERSION_ACCESSOR.get(packet); |
674 | 683 | originalChannel.attr(PROTOCOL_KEY).set(protocol);
|
675 | 684 | } catch (Throwable ex) {
|
676 | 685 | // Oh well
|
|
0 commit comments