mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-27 11:37:34 +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 });
|
||||||
|
|
||||||
|
try {
|
||||||
// Temporarily associate the fake packet class
|
// Temporarily associate the fake packet class
|
||||||
invoker.registerPacketClass(proxyClass, packetID);
|
invoker.registerPacketClass(proxyClass, packetID);
|
||||||
|
return (Packet) proxyClass.newInstance();
|
||||||
|
|
||||||
Packet fake = (Packet) Enhancer.create(proxyClass, new InvertedIntegerCallback());
|
} catch (Exception e) {
|
||||||
|
// Don't pollute the throws tree
|
||||||
|
throw new RuntimeException("Cannot create fake class.", e);
|
||||||
|
} finally {
|
||||||
// Remove this association
|
// Remove this association
|
||||||
invoker.unregisterPacketClass(proxyClass);
|
invoker.unregisterPacketClass(proxyClass);
|
||||||
return fake;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user