3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Remove 1.8 PS compat hack

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-10-25 10:36:09 +02:00
Ursprung cdc35aa5dc
Commit 58fd0bdc9e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 5 neuen und 80 gelöschten Zeilen

Datei anzeigen

@ -48,7 +48,6 @@ import java.lang.reflect.Method;
public final class ClassGenerator {
private static final boolean useModules = hasModuleMethod();
private static HandlerSupplier constructor = new HandlerSupplier.DefaultHandlerSupplier();
private static String psPackage;
private static Class psConnectListener;
public static HandlerSupplier handlerSupplier() {
@ -72,19 +71,10 @@ public final class ClassGenerator {
addSpigotCompatibility(pool, BukkitEncodeHandler.class, encodeSuper);
} else {
// ProtocolSupport compatibility
Class encodeSuper;
Class decodeSuper;
if (isMultiplatformPS()) {
psConnectListener = makePSConnectListener(pool);
return;
} else {
String psPackage = getOldPSPackage();
decodeSuper = Class.forName(psPackage.equals("unknown") ? "protocolsupport.protocol.pipeline.common.PacketDecoder" : psPackage + ".wrapped.WrappedDecoder");
encodeSuper = Class.forName(psPackage.equals("unknown") ? "protocolsupport.protocol.pipeline.common.PacketEncoder" : psPackage + ".wrapped.WrappedEncoder");
}
// Generate the classes
addPSCompatibility(pool, BukkitDecodeHandler.class, decodeSuper);
addPSCompatibility(pool, BukkitEncodeHandler.class, encodeSuper);
}
@ -99,11 +89,11 @@ public final class ClassGenerator {
pool.importPackage("com.viaversion.viaversion.api.connection");
pool.importPackage("io.netty.handler.codec");
// Implement Methods
generated.addMethod(CtMethod.make("public MessageToByteEncoder newEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {\n" +
" return new BukkitEncodeHandler(info, minecraftEncoder);\n" +
generated.addMethod(CtMethod.make("public MessageToMessageEncoder<ByteBuf> newEncodeHandler(UserConnection connection) {\n" +
" return new BukkitEncodeHandler(connection);\n" +
" }", generated));
generated.addMethod(CtMethod.make("public ByteToMessageDecoder newDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {\n" +
" return new BukkitDecodeHandler(info, minecraftDecoder);\n" +
generated.addMethod(CtMethod.make("public MessageToMessageDecoder<ByteBuf> newDecodeHandler(UserConnection connection) {\n" +
" return new BukkitDecodeHandler(connection);\n" +
" }", generated));
constructor = (HandlerSupplier) toClass(generated).getConstructor().newInstance();
@ -147,54 +137,6 @@ public final class ClassGenerator {
}
}
private static void addPSCompatibility(ClassPool pool, Class input, Class superclass) {
boolean newPS = getOldPSPackage().equals("unknown");
String newName = "com.viaversion.viaversion.classgenerator.generated." + input.getSimpleName();
try {
CtClass generated = pool.getAndRename(input.getName(), newName);
if (superclass != null) {
CtClass toExtend = pool.get(superclass.getName());
generated.setSuperclass(toExtend);
if (!newPS) {
// Override setRealEncoder / setRealDecoder
pool.importPackage(getOldPSPackage());
pool.importPackage(getOldPSPackage() + ".wrapped");
if (superclass.getName().endsWith("Decoder")) {
// Decoder
generated.addMethod(CtMethod.make("public void setRealDecoder(IPacketDecoder dec) {\n" +
" ((WrappedDecoder) this.minecraftDecoder).setRealDecoder(dec);\n" +
" }", generated));
} else {
// Encoder
pool.importPackage("protocolsupport.api");
pool.importPackage("java.lang.reflect");
generated.addMethod(CtMethod.make("public void setRealEncoder(IPacketEncoder enc) {\n" +
" try {\n" +
// Tell ProtocolSupport to decode MINECRAFT_FUTURE packets using the default decoder (for 1.9.4)
" Field field = enc.getClass().getDeclaredField(\"version\");\n" +
" field.setAccessible(true);\n" +
" ProtocolVersion version = (ProtocolVersion) field.get(enc);\n" +
" if (version == ProtocolVersion.MINECRAFT_FUTURE) enc = enc.getClass().getConstructor(\n" +
" new Class[]{ProtocolVersion.class}).newInstance(new Object[] {ProtocolVersion.getLatest()});\n" +
" } catch (Exception e) {\n" +
// I guess we're not on 1.9.4
" }\n" +
" ((WrappedEncoder) this.minecraftEncoder).setRealEncoder(enc);\n" +
" }", generated));
}
}
}
toClass(generated);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (CannotCompileException e) {
e.printStackTrace();
}
}
private static Class makePSConnectListener(ClassPool pool) {
HandshakeProtocolType type = handshakeVersionMethod();
try {
@ -275,23 +217,6 @@ public final class ClassGenerator {
return psConnectListener;
}
public static String getOldPSPackage() {
if (psPackage == null) {
try {
Class.forName("protocolsupport.protocol.core.IPacketDecoder");
psPackage = "protocolsupport.protocol.core";
} catch (ClassNotFoundException e) {
try {
Class.forName("protocolsupport.protocol.pipeline.IPacketDecoder");
psPackage = "protocolsupport.protocol.pipeline";
} catch (ClassNotFoundException e1) {
psPackage = "unknown";
}
}
}
return psPackage;
}
public static boolean isMultiplatformPS() {
try {
Class.forName("protocolsupport.zplatform.impl.spigot.network.pipeline.SpigotPacketEncoder");

Datei anzeigen

@ -90,7 +90,7 @@ public final class BukkitEncodeHandler extends MessageToMessageEncoder<ByteBuf>
pipeline.addAfter(BukkitChannelInitializer.MINECRAFT_DECOMPRESSOR, BukkitChannelInitializer.VIA_DECODER, pipeline.remove(BukkitChannelInitializer.VIA_DECODER));
return true;
}
return true;
return false;
}
private void recompress(final ChannelHandlerContext ctx, final ByteBuf buf) throws Exception {