Archiviert
13
0

Ensure that we don't return enhancer classes as vanilla classes.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-12-04 14:59:08 +01:00
Ursprung 733ecdd59b
Commit 86d3461700
2 geänderte Dateien mit 22 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Set;
import net.minecraft.server.Packet;
import net.sf.cglib.proxy.Factory;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.FieldUtils;
@ -166,7 +167,7 @@ class MinecraftRegistry {
// Optimized lookup
if (lookup.containsKey(packetID)) {
return lookup.get(packetID);
return removeEnhancer(lookup.get(packetID), forceVanilla);
}
// Will most likely not be used
@ -174,10 +175,27 @@ class MinecraftRegistry {
if (Objects.equal(entry.getValue(), packetID)) {
// Attempt to get the vanilla class here too
if (!forceVanilla || entry.getKey().getName().startsWith("net.minecraft.server"))
return entry.getKey();
return removeEnhancer(entry.getKey(), forceVanilla);
}
}
throw new IllegalArgumentException("The packet ID " + packetID + " is not registered.");
}
/**
* Find the first superclass that is not a CBLib proxy object.
* @param clazz - the class whose hierachy we're going to search through.
* @param remove - whether or not to skip enhanced (proxy) classes.
* @return If remove is TRUE, the first superclass that is not a proxy.
*/
private static Class removeEnhancer(Class clazz, boolean remove) {
if (remove) {
// Get the underlying vanilla class
while (Factory.class.isAssignableFrom(clazz) && !clazz.equals(Object.class)) {
clazz = clazz.getSuperclass();
}
}
return clazz;
}
}

Datei anzeigen

@ -27,6 +27,7 @@ import com.comphenix.protocol.injector.player.NetworkFieldInjector.FakePacket;
import net.minecraft.server.Packet;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@ -95,7 +96,7 @@ class InjectedArrayList extends ArrayList<Packet> {
int packetID = invoker.getPacketID(source);
Class<?> type = invoker.getPacketClassFromID(packetID, true);
// We want to subtract the byte amount that were added to the running
// total of outstanding packets. Otherwise, cancelling too many packets
// might cause a "disconnect.overflow" error.