From f7f20a0d9772c5ac59e2d1c4d0670da55a93ac19 Mon Sep 17 00:00:00 2001 From: deirn Date: Thu, 9 Jan 2025 00:16:52 +0700 Subject: [PATCH] simplify handler mixins, fixed memory leak closes #19 --- gradle.properties | 2 +- .../impl/handler/AbstractPacketHandler.java | 26 +++++------ .../impl/handler/ClientPlayPacketHandler.java | 14 ++---- .../impl/handler/PacketHandlerHolder.java | 7 +++ .../impl/handler/ServerPlayPacketHandler.java | 14 ++---- .../MixinClientboundCustomPayloadPacket.java | 8 ++-- .../impl/mixin/MixinConnection.java | 45 +++++++++++++++++++ .../MixinServerCommonPacketListenerImpl.java | 10 ----- ...ServerConfigurationPacketListenerImpl.java | 24 +++------- .../MixinServerGamePacketListenerImpl.java | 23 ++-------- .../MixinServerboundCustomPayloadPacket.java | 8 ++-- .../MixinClientCommonPacketListenerImpl.java | 10 ----- ...ClientConfigurationPacketListenerImpl.java | 21 ++------- .../client/MixinClientPacketListener.java | 23 ++-------- src/main/resources/badpackets.mixins.json | 1 + 15 files changed, 96 insertions(+), 140 deletions(-) create mode 100644 src/main/java/lol/bai/badpackets/impl/handler/PacketHandlerHolder.java create mode 100644 src/main/java/lol/bai/badpackets/impl/mixin/MixinConnection.java diff --git a/gradle.properties b/gradle.properties index 27a8b17..d54da67 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ group = lol.bai majorVersion = 0 fabricLoader = 0.15.11 -fabricApi = 0.99.3+1.21 +fabricApi = 0.102.0+1.21 forge = 51.0.8 neo = 21.0.8-beta diff --git a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java index ac32aa1..1124f65 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java @@ -1,15 +1,5 @@ package lol.bai.badpackets.impl.handler; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.stream.Collectors; - import io.netty.buffer.Unpooled; import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.PacketSender; @@ -28,6 +18,16 @@ import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; + public abstract class AbstractPacketHandler implements PacketSender { protected final ChannelRegistry registry; @@ -169,10 +169,4 @@ public boolean canSend(ResourceLocation id) { return sendableChannels.contains(id); } - public interface Holder { - - boolean badpackets_receive(CustomPacketPayload payload); - - } - } diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java index 67d8e5f..0b19eb7 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java @@ -1,8 +1,5 @@ package lol.bai.badpackets.impl.handler; -import java.util.Set; -import java.util.function.Consumer; - import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.play.ClientPlayContext; import lol.bai.badpackets.impl.platform.PlatformProxy; @@ -16,6 +13,9 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; +import java.util.Set; +import java.util.function.Consumer; + public class ClientPlayPacketHandler extends AbstractPacketHandler implements ClientPlayContext { private final Minecraft client; @@ -34,7 +34,7 @@ public static ClientPlayPacketHandler get() { throw new IllegalStateException("Cannot get c2s sender when not in play stage!"); } - return ((ClientPlayPacketHandler.Holder) listener).badpackets_getHandler(); + return ((PacketHandlerHolder) listener).badpackets_handler(); } @Override @@ -65,10 +65,4 @@ public ClientPacketListener handler() { return listener; } - public interface Holder extends AbstractPacketHandler.Holder { - - ClientPlayPacketHandler badpackets_getHandler(); - - } - } diff --git a/src/main/java/lol/bai/badpackets/impl/handler/PacketHandlerHolder.java b/src/main/java/lol/bai/badpackets/impl/handler/PacketHandlerHolder.java new file mode 100644 index 0000000..04593ae --- /dev/null +++ b/src/main/java/lol/bai/badpackets/impl/handler/PacketHandlerHolder.java @@ -0,0 +1,7 @@ +package lol.bai.badpackets.impl.handler; + +public interface PacketHandlerHolder> { + + T badpackets_handler(); + +} diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java index 0966b33..b7abb94 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java @@ -1,8 +1,5 @@ package lol.bai.badpackets.impl.handler; -import java.util.Set; -import java.util.function.Consumer; - import lol.bai.badpackets.api.PacketReceiver; import lol.bai.badpackets.api.play.ServerPlayContext; import lol.bai.badpackets.impl.platform.PlatformProxy; @@ -18,6 +15,9 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; +import java.util.Set; +import java.util.function.Consumer; + public class ServerPlayPacketHandler extends AbstractPacketHandler implements ServerPlayContext { private final MinecraftServer server; @@ -30,7 +30,7 @@ public ServerPlayPacketHandler(MinecraftServer server, ServerGamePacketListenerI } public static ServerPlayPacketHandler get(ServerPlayer player) { - return ((ServerPlayPacketHandler.Holder) player.connection).badpackets_getHandler(); + return ((PacketHandlerHolder) player.connection).badpackets_handler(); } @Override @@ -65,10 +65,4 @@ public ServerGamePacketListenerImpl handler() { return handler; } - public interface Holder extends AbstractPacketHandler.Holder { - - ServerPlayPacketHandler badpackets_getHandler(); - - } - } diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java index f2d559e..bd44ee6 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java @@ -1,10 +1,8 @@ package lol.bai.badpackets.impl.mixin; -import java.util.function.Function; - import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import lol.bai.badpackets.impl.handler.AbstractPacketHandler; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; import lol.bai.badpackets.impl.registry.ChannelCodecFinder; import lol.bai.badpackets.impl.registry.ChannelRegistry; import net.minecraft.network.codec.StreamCodec; @@ -17,6 +15,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.function.Function; + @Mixin(ClientboundCustomPayloadPacket.class) public abstract class MixinClientboundCustomPayloadPacket { @@ -25,7 +25,7 @@ public abstract class MixinClientboundCustomPayloadPacket { @Inject(method = "handle(Lnet/minecraft/network/protocol/common/ClientCommonPacketListener;)V", at = @At("HEAD"), cancellable = true) private void badpackets_handle(ClientCommonPacketListener listener, CallbackInfo ci) { - if (listener instanceof AbstractPacketHandler.Holder holder && holder.badpackets_receive(payload())) { + if (listener instanceof PacketHandlerHolder holder && holder.badpackets_handler().receive(payload())) { ci.cancel(); } } diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/MixinConnection.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinConnection.java new file mode 100644 index 0000000..05a6a01 --- /dev/null +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinConnection.java @@ -0,0 +1,45 @@ +package lol.bai.badpackets.impl.mixin; + +import io.netty.channel.ChannelHandlerContext; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; +import net.minecraft.network.Connection; +import net.minecraft.network.PacketListener; +import net.minecraft.network.ProtocolInfo; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Connection.class) +public class MixinConnection { + + @Shadow + @Nullable + private volatile PacketListener packetListener; + + @Inject(method = "setupInboundProtocol", at = @At("HEAD")) + private void badpackets_cleanOldListener(ProtocolInfo info, T listener, CallbackInfo ci) { + badpackets_cleanListener(); + } + + @Inject(method = "channelInactive", at = @At("HEAD")) + private void badpackets_cleanListener(ChannelHandlerContext ctx, CallbackInfo ci) { + badpackets_cleanListener(); + } + + @Inject(method = "handleDisconnection", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketListener;onDisconnect(Lnet/minecraft/network/DisconnectionDetails;)V")) + private void badpackets_cleanListener(CallbackInfo ci) { + badpackets_cleanListener(); + } + + @Unique + private void badpackets_cleanListener() { + if (this.packetListener instanceof PacketHandlerHolder holder) { + holder.badpackets_handler().remove(); + } + } + +} diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerCommonPacketListenerImpl.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerCommonPacketListenerImpl.java index 699dbdb..b3a5c86 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerCommonPacketListenerImpl.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerCommonPacketListenerImpl.java @@ -1,6 +1,5 @@ package lol.bai.badpackets.impl.mixin; -import net.minecraft.network.DisconnectionDetails; import net.minecraft.network.protocol.common.ServerboundPongPacket; import net.minecraft.server.network.ServerCommonPacketListenerImpl; import org.spongepowered.asm.mixin.Mixin; @@ -17,15 +16,6 @@ private void badpackets_onPong(ServerboundPongPacket packet, CallbackInfo ci) { badpackets_onPong(packet.getId()); } - @Inject(method = "onDisconnect", at = @At("HEAD")) - private void badpackets_removePacketHandler(DisconnectionDetails details, CallbackInfo ci) { - badpackets_removePacketHandler(); - } - - @Unique - protected void badpackets_removePacketHandler() { - } - @Unique protected void badpackets_onPong(int id) { } diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerConfigurationPacketListenerImpl.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerConfigurationPacketListenerImpl.java index 03d052d..f6e5657 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerConfigurationPacketListenerImpl.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerConfigurationPacketListenerImpl.java @@ -1,13 +1,9 @@ package lol.bai.badpackets.impl.mixin; -import java.util.Queue; - import lol.bai.badpackets.impl.Constants; -import lol.bai.badpackets.impl.handler.AbstractPacketHandler; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; import lol.bai.badpackets.impl.handler.ServerConfigPacketHandler; import net.minecraft.network.Connection; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.network.ConfigurationTask; @@ -23,8 +19,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import java.util.Queue; + @Mixin(ServerConfigurationPacketListenerImpl.class) -public abstract class MixinServerConfigurationPacketListenerImpl extends MixinServerCommonPacketListenerImpl implements ServerConfigPacketHandler.TaskFinisher, AbstractPacketHandler.Holder { +public abstract class MixinServerConfigurationPacketListenerImpl extends MixinServerCommonPacketListenerImpl implements ServerConfigPacketHandler.TaskFinisher, PacketHandlerHolder { @Shadow @Final @@ -51,11 +49,6 @@ private void badpackets_initPacketHandler(CallbackInfo ci) { configurationTasks.addAll(ServerConfigPacketHandler.CUSTOM_TASKS.values()); } - @Inject(method = "handleConfigurationFinished", at = @At("RETURN")) - private void badpackets_removePacketHandler(ServerboundFinishConfigurationPacket packet, CallbackInfo ci) { - badpackets_packetHandler.remove(); - } - @Inject(method = "startNextTask", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/server/network/ServerConfigurationPacketListenerImpl;currentTask:Lnet/minecraft/server/network/ConfigurationTask;")) private void badpackets_attachCustomTaskContext(CallbackInfo ci, ConfigurationTask task) { if (task instanceof ServerConfigPacketHandler.CustomTask custom) { @@ -71,13 +64,8 @@ private void badpackets_detachCustomTaskContext(ConfigurationTask.Type type, Cal } @Override - protected void badpackets_removePacketHandler() { - badpackets_packetHandler.remove(); - } - - @Override - public boolean badpackets_receive(CustomPacketPayload payload) { - return badpackets_packetHandler.receive(payload); + public ServerConfigPacketHandler badpackets_handler() { + return badpackets_packetHandler; } @Override diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerGamePacketListenerImpl.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerGamePacketListenerImpl.java index deabcb4..7339771 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerGamePacketListenerImpl.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerGamePacketListenerImpl.java @@ -1,10 +1,8 @@ package lol.bai.badpackets.impl.mixin; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; import lol.bai.badpackets.impl.handler.ServerPlayPacketHandler; import net.minecraft.network.Connection; -import net.minecraft.network.DisconnectionDetails; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.network.protocol.game.ServerboundConfigurationAcknowledgedPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.CommonListenerCookie; @@ -16,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerGamePacketListenerImpl.class) -public class MixinServerGamePacketListenerImpl extends MixinServerCommonPacketListenerImpl implements ServerPlayPacketHandler.Holder { +public class MixinServerGamePacketListenerImpl extends MixinServerCommonPacketListenerImpl implements PacketHandlerHolder { @Unique private ServerPlayPacketHandler badpacket_packetHandler; @@ -26,23 +24,8 @@ private void badpackets_createServerPacketHandler(MinecraftServer minecraftServe badpacket_packetHandler = new ServerPlayPacketHandler(minecraftServer, (ServerGamePacketListenerImpl) (Object) this, connection); } - @Inject(method = "onDisconnect", at = @At("HEAD")) - private void badpackets_removeServerPacketHandler(DisconnectionDetails details, CallbackInfo ci) { - badpacket_packetHandler.remove(); - } - - @Inject(method = "handleConfigurationAcknowledged", at = @At("RETURN")) - private void badpacekts_removePacketHandler(ServerboundConfigurationAcknowledgedPacket packet, CallbackInfo ci) { - badpacket_packetHandler.remove(); - } - - @Override - public boolean badpackets_receive(CustomPacketPayload payload) { - return badpacket_packetHandler.receive(payload); - } - @Override - public ServerPlayPacketHandler badpackets_getHandler() { + public ServerPlayPacketHandler badpackets_handler() { return badpacket_packetHandler; } diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerboundCustomPayloadPacket.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerboundCustomPayloadPacket.java index 1f0a37f..eeda40e 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerboundCustomPayloadPacket.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinServerboundCustomPayloadPacket.java @@ -1,10 +1,8 @@ package lol.bai.badpackets.impl.mixin; -import java.util.function.Function; - import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import lol.bai.badpackets.impl.handler.AbstractPacketHandler; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; import lol.bai.badpackets.impl.registry.ChannelCodecFinder; import lol.bai.badpackets.impl.registry.ChannelRegistry; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -18,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.function.Function; + @Mixin(ServerboundCustomPayloadPacket.class) public abstract class MixinServerboundCustomPayloadPacket { @@ -26,7 +26,7 @@ public abstract class MixinServerboundCustomPayloadPacket { @Inject(method = "handle(Lnet/minecraft/network/protocol/common/ServerCommonPacketListener;)V", at = @At("HEAD"), cancellable = true) private void badpackets_handle(ServerCommonPacketListener listener, CallbackInfo ci) { - if (listener instanceof AbstractPacketHandler.Holder holder && holder.badpackets_receive(payload())) { + if (listener instanceof PacketHandlerHolder holder && holder.badpackets_handler().receive(payload())) { ci.cancel(); } } diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientCommonPacketListenerImpl.java b/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientCommonPacketListenerImpl.java index ed00e98..3cec8bd 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientCommonPacketListenerImpl.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientCommonPacketListenerImpl.java @@ -1,7 +1,6 @@ package lol.bai.badpackets.impl.mixin.client; import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; -import net.minecraft.network.DisconnectionDetails; import net.minecraft.network.protocol.common.ClientboundPingPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -12,20 +11,11 @@ @Mixin(ClientCommonPacketListenerImpl.class) public abstract class MixinClientCommonPacketListenerImpl { - @Inject(method = "onDisconnect", at = @At("HEAD")) - private void badpackets_removeClientPacketHandler(DisconnectionDetails details, CallbackInfo ci) { - badpackets_removeClientPacketHandler(details); - } - @Inject(method = "handlePing", at = @At("HEAD"), cancellable = true) private void badpackets_handlePing(ClientboundPingPacket packet, CallbackInfo ci) { if (badpackets_handlePing(packet.getId())) ci.cancel(); } - @Unique - protected void badpackets_removeClientPacketHandler(DisconnectionDetails details) { - } - @Unique protected boolean badpackets_handlePing(int id) { return false; diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientConfigurationPacketListenerImpl.java b/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientConfigurationPacketListenerImpl.java index 16b7d8a..b6784eb 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientConfigurationPacketListenerImpl.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientConfigurationPacketListenerImpl.java @@ -1,15 +1,12 @@ package lol.bai.badpackets.impl.mixin.client; import lol.bai.badpackets.impl.Constants; -import lol.bai.badpackets.impl.handler.AbstractPacketHandler; import lol.bai.badpackets.impl.handler.ClientConfigPacketHandler; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientConfigurationPacketListenerImpl; import net.minecraft.client.multiplayer.CommonListenerCookie; import net.minecraft.network.Connection; -import net.minecraft.network.DisconnectionDetails; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.network.protocol.configuration.ClientboundFinishConfigurationPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -17,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientConfigurationPacketListenerImpl.class) -public abstract class MixinClientConfigurationPacketListenerImpl extends MixinClientCommonPacketListenerImpl implements AbstractPacketHandler.Holder { +public abstract class MixinClientConfigurationPacketListenerImpl extends MixinClientCommonPacketListenerImpl implements PacketHandlerHolder { @Unique private ClientConfigPacketHandler badpackets_packetHandler; @@ -27,24 +24,14 @@ private void badpackets_createPacketHandler(Minecraft minecraft, Connection conn badpackets_packetHandler = new ClientConfigPacketHandler(minecraft, (ClientConfigurationPacketListenerImpl) (Object) this, connection); } - @Inject(method = "handleConfigurationFinished", at = @At("RETURN")) - private void badpacekts_removePacketHandler(ClientboundFinishConfigurationPacket $$0, CallbackInfo ci) { - badpackets_packetHandler.remove(); - } - - @Override - protected void badpackets_removeClientPacketHandler(DisconnectionDetails details) { - badpackets_packetHandler.remove(); - } - @Override protected boolean badpackets_handlePing(int id) { return id == Constants.PING_PONG; } @Override - public boolean badpackets_receive(CustomPacketPayload payload) { - return badpackets_packetHandler.receive(payload); + public ClientConfigPacketHandler badpackets_handler() { + return badpackets_packetHandler; } } diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientPacketListener.java b/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientPacketListener.java index 2552faf..a5b7e08 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientPacketListener.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientPacketListener.java @@ -1,13 +1,11 @@ package lol.bai.badpackets.impl.mixin.client; import lol.bai.badpackets.impl.handler.ClientPlayPacketHandler; +import lol.bai.badpackets.impl.handler.PacketHandlerHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.multiplayer.CommonListenerCookie; import net.minecraft.network.Connection; -import net.minecraft.network.DisconnectionDetails; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.network.protocol.game.ClientboundStartConfigurationPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -15,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPacketListener.class) -public abstract class MixinClientPacketListener extends MixinClientCommonPacketListenerImpl implements ClientPlayPacketHandler.Holder { +public abstract class MixinClientPacketListener extends MixinClientCommonPacketListenerImpl implements PacketHandlerHolder { @Unique private ClientPlayPacketHandler badpacket_packetHandler; @@ -26,23 +24,8 @@ private void badpackets_createClientPacketHandler(Minecraft client, Connection c } @Override - protected void badpackets_removeClientPacketHandler(DisconnectionDetails details) { - badpacket_packetHandler.remove(); - } - - @Inject(method = "handleConfigurationStart", at = @At("RETURN")) - private void badpackets_removeHandler(ClientboundStartConfigurationPacket $$0, CallbackInfo ci) { - badpacket_packetHandler.remove(); - } - - @Override - public ClientPlayPacketHandler badpackets_getHandler() { + public ClientPlayPacketHandler badpackets_handler() { return badpacket_packetHandler; } - @Override - public boolean badpackets_receive(CustomPacketPayload payload) { - return badpacket_packetHandler.receive(payload); - } - } diff --git a/src/main/resources/badpackets.mixins.json b/src/main/resources/badpackets.mixins.json index 131397a..d394832 100644 --- a/src/main/resources/badpackets.mixins.json +++ b/src/main/resources/badpackets.mixins.json @@ -6,6 +6,7 @@ "refmap" : "badpackets.refmap.json", "mixins" : [ "MixinClientboundCustomPayloadPacket", + "MixinConnection", "MixinCustomPacketPayload_1", "MixinPlayerList", "MixinServerboundCustomPayloadPacket",