Update ProtocolLib for 1.6.1.
A lot of methods changed from accepting DataInputStream to DataInput, which messed with the part that dynamically finds the "readPacket" method. Changed to accepting any method whose signature contains a parameter derived from DataInput.
Dieser Commit ist enthalten in:
Ursprung
0b3fe5470a
Commit
5e5243e3fb
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.comphenix.protocol.injector.packet;
|
package com.comphenix.protocol.injector.packet;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -33,6 +34,8 @@ import net.sf.cglib.proxy.NoOp;
|
|||||||
|
|
||||||
import com.comphenix.protocol.Packets;
|
import com.comphenix.protocol.Packets;
|
||||||
import com.comphenix.protocol.error.ErrorReporter;
|
import com.comphenix.protocol.error.ErrorReporter;
|
||||||
|
import com.comphenix.protocol.error.Report;
|
||||||
|
import com.comphenix.protocol.error.ReportType;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.injector.ListenerInvoker;
|
import com.comphenix.protocol.injector.ListenerInvoker;
|
||||||
@ -50,6 +53,8 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
class ProxyPacketInjector implements PacketInjector {
|
class ProxyPacketInjector implements PacketInjector {
|
||||||
|
public static final ReportType REPORT_CANNOT_FIND_READ_PACKET_METHOD = new ReportType("Cannot find read packet method for ID %s.");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a way to update the packet ID to class lookup table.
|
* Represents a way to update the packet ID to class lookup table.
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
@ -134,7 +139,7 @@ class ProxyPacketInjector implements PacketInjector {
|
|||||||
*/
|
*/
|
||||||
private static FuzzyMethodContract readPacket = FuzzyMethodContract.newBuilder().
|
private static FuzzyMethodContract readPacket = FuzzyMethodContract.newBuilder().
|
||||||
returnTypeVoid().
|
returnTypeVoid().
|
||||||
parameterExactType(DataInputStream.class).
|
parameterDerivedOf(DataInput.class).
|
||||||
parameterCount(1).
|
parameterCount(1).
|
||||||
build();
|
build();
|
||||||
|
|
||||||
@ -155,6 +160,9 @@ class ProxyPacketInjector implements PacketInjector {
|
|||||||
// Share callback filter
|
// Share callback filter
|
||||||
private CallbackFilter filter;
|
private CallbackFilter filter;
|
||||||
|
|
||||||
|
// Determine if the read packet method was found
|
||||||
|
private boolean readPacketIntercepted = false;
|
||||||
|
|
||||||
public ProxyPacketInjector(ClassLoader classLoader, ListenerInvoker manager,
|
public ProxyPacketInjector(ClassLoader classLoader, ListenerInvoker manager,
|
||||||
PlayerInjectionHandler playerInjection, ErrorReporter reporter) throws FieldAccessException {
|
PlayerInjectionHandler playerInjection, ErrorReporter reporter) throws FieldAccessException {
|
||||||
|
|
||||||
@ -224,17 +232,21 @@ class ProxyPacketInjector implements PacketInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filter == null) {
|
if (filter == null) {
|
||||||
|
readPacketIntercepted = false;
|
||||||
|
|
||||||
filter = new CallbackFilter() {
|
filter = new CallbackFilter() {
|
||||||
@Override
|
@Override
|
||||||
public int accept(Method method) {
|
public int accept(Method method) {
|
||||||
// Skip methods defined in Object
|
// Skip methods defined in Object
|
||||||
if (method.getDeclaringClass().equals(Object.class))
|
if (method.getDeclaringClass().equals(Object.class)) {
|
||||||
return 0;
|
return 0;
|
||||||
else if (readPacket.isMatch(MethodInfo.fromMethod(method), null))
|
} else if (readPacket.isMatch(MethodInfo.fromMethod(method), null)) {
|
||||||
|
readPacketIntercepted = true;
|
||||||
return 1;
|
return 1;
|
||||||
else
|
} else {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +264,12 @@ class ProxyPacketInjector implements PacketInjector {
|
|||||||
// Add a static reference
|
// Add a static reference
|
||||||
Enhancer.registerStaticCallbacks(proxy, new Callback[] { NoOp.INSTANCE, modifierReadPacket, modifierRest });
|
Enhancer.registerStaticCallbacks(proxy, new Callback[] { NoOp.INSTANCE, modifierReadPacket, modifierRest });
|
||||||
|
|
||||||
|
// Check that we found the read method
|
||||||
|
if (!readPacketIntercepted) {
|
||||||
|
reporter.reportWarning(this,
|
||||||
|
Report.newBuilder(REPORT_CANNOT_FIND_READ_PACKET_METHOD).messageParam(packetID));
|
||||||
|
}
|
||||||
|
|
||||||
// Override values
|
// Override values
|
||||||
previous.put(packetID, old);
|
previous.put(packetID, old);
|
||||||
registry.put(proxy, packetID);
|
registry.put(proxy, packetID);
|
||||||
|
@ -161,8 +161,8 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
|||||||
/**
|
/**
|
||||||
* Add a new required parameter whose type must be a superclass of the given type.
|
* Add a new required parameter whose type must be a superclass of the given type.
|
||||||
* <p>
|
* <p>
|
||||||
* If a parameter is of type Number, any derived class (Integer, Long, etc.) will match it.
|
* If a method parameter is of type Number, then any derived class here (Integer, Long, etc.) will match it.
|
||||||
* @param type - a type or derived type of the matching parameter.
|
* @param type - a type or less derived type of the matching parameter.
|
||||||
* @return This builder, for chaining.
|
* @return This builder, for chaining.
|
||||||
*/
|
*/
|
||||||
public Builder parameterSuperOf(Class<?> type) {
|
public Builder parameterSuperOf(Class<?> type) {
|
||||||
@ -170,6 +170,18 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new required parameter whose type must be a derived class of the given class.
|
||||||
|
* <p>
|
||||||
|
* If the method parameter has the type Integer, then the class Number here will match it.
|
||||||
|
* @param type - a type or more derived type of the matching parameter.
|
||||||
|
* @return This builder, for chaining.
|
||||||
|
*/
|
||||||
|
public Builder parameterDerivedOf(Class<?> type) {
|
||||||
|
member.paramMatchers.add(new ParameterClassMatcher(FuzzyMatchers.matchDerived(type)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new required parameter whose type must match the given class matcher.
|
* Add a new required parameter whose type must match the given class matcher.
|
||||||
* @param classMatcher - the class matcher.
|
* @param classMatcher - the class matcher.
|
||||||
@ -204,6 +216,19 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new required parameter whose type must be a derived class of the given class.
|
||||||
|
* <p>
|
||||||
|
* If the method parameter has the type Integer, then the class Number here will match it.
|
||||||
|
* @param type - a type or more derived type of the matching parameter.
|
||||||
|
* @param index - the expected position in the parameter list.
|
||||||
|
* @return This builder, for chaining.
|
||||||
|
*/
|
||||||
|
public Builder parameterDerivedOf(Class<?> type, int index) {
|
||||||
|
member.paramMatchers.add(new ParameterClassMatcher(FuzzyMatchers.matchDerived(type), index));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new required parameter whose type must match the given class matcher and index.
|
* Add a new required parameter whose type must match the given class matcher and index.
|
||||||
* @param classMatcher - the class matcher.
|
* @param classMatcher - the class matcher.
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren