mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-26 19:18:12 +01:00
Ensure that fake cancellation packets can be created.
This commit is contained in:
parent
ede60970b9
commit
25d41ed51c
@ -26,6 +26,7 @@ import com.comphenix.protocol.injector.ListenerInvoker;
|
|||||||
import com.comphenix.protocol.injector.player.NetworkFieldInjector.FakePacket;
|
import com.comphenix.protocol.injector.player.NetworkFieldInjector.FakePacket;
|
||||||
|
|
||||||
import net.minecraft.server.Packet;
|
import net.minecraft.server.Packet;
|
||||||
|
import net.sf.cglib.proxy.Callback;
|
||||||
import net.sf.cglib.proxy.Enhancer;
|
import net.sf.cglib.proxy.Enhancer;
|
||||||
import net.sf.cglib.proxy.MethodInterceptor;
|
import net.sf.cglib.proxy.MethodInterceptor;
|
||||||
import net.sf.cglib.proxy.MethodProxy;
|
import net.sf.cglib.proxy.MethodProxy;
|
||||||
@ -46,10 +47,13 @@ class InjectedArrayList extends ArrayList<Packet> {
|
|||||||
private transient Set<Packet> ignoredPackets;
|
private transient Set<Packet> ignoredPackets;
|
||||||
private transient ClassLoader classLoader;
|
private transient ClassLoader classLoader;
|
||||||
|
|
||||||
|
private transient InvertedIntegerCallback callback;
|
||||||
|
|
||||||
public InjectedArrayList(ClassLoader classLoader, PlayerInjector injector, Set<Packet> ignoredPackets) {
|
public InjectedArrayList(ClassLoader classLoader, PlayerInjector injector, Set<Packet> ignoredPackets) {
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.ignoredPackets = ignoredPackets;
|
this.ignoredPackets = ignoredPackets;
|
||||||
|
this.callback = new InvertedIntegerCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -96,6 +100,8 @@ class InjectedArrayList extends ArrayList<Packet> {
|
|||||||
int packetID = invoker.getPacketID(source);
|
int packetID = invoker.getPacketID(source);
|
||||||
Class<?> type = invoker.getPacketClassFromID(packetID, true);
|
Class<?> type = invoker.getPacketClassFromID(packetID, true);
|
||||||
|
|
||||||
|
System.out.println(type.getName());
|
||||||
|
|
||||||
// We want to subtract the byte amount that were added to the running
|
// We want to subtract the byte amount that were added to the running
|
||||||
// total of outstanding packets. Otherwise, cancelling too many packets
|
// total of outstanding packets. Otherwise, cancelling too many packets
|
||||||
// might cause a "disconnect.overflow" error.
|
// might cause a "disconnect.overflow" error.
|
||||||
@ -122,15 +128,20 @@ class InjectedArrayList extends ArrayList<Packet> {
|
|||||||
ex.setCallbackType(InvertedIntegerCallback.class);
|
ex.setCallbackType(InvertedIntegerCallback.class);
|
||||||
|
|
||||||
Class<?> proxyClass = ex.createClass();
|
Class<?> proxyClass = ex.createClass();
|
||||||
|
Enhancer.registerCallbacks(proxyClass, new Callback[] { callback });
|
||||||
// Temporarily associate the fake packet class
|
|
||||||
invoker.registerPacketClass(proxyClass, packetID);
|
|
||||||
|
|
||||||
Packet fake = (Packet) Enhancer.create(proxyClass, new InvertedIntegerCallback());
|
|
||||||
|
|
||||||
// Remove this association
|
try {
|
||||||
invoker.unregisterPacketClass(proxyClass);
|
// Temporarily associate the fake packet class
|
||||||
return fake;
|
invoker.registerPacketClass(proxyClass, packetID);
|
||||||
|
return (Packet) proxyClass.newInstance();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Don't pollute the throws tree
|
||||||
|
throw new RuntimeException("Cannot create fake class.", e);
|
||||||
|
} finally {
|
||||||
|
// Remove this association
|
||||||
|
invoker.unregisterPacketClass(proxyClass);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user