Use half fix for packet leak

This commit is contained in:
embeddedt 2023-05-17 16:51:31 -04:00
parent 0d4a12eafe
commit c51d7ae641
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 3 additions and 49 deletions

View File

@ -1,33 +0,0 @@
package org.embeddedt.modernfix.common.mixin.bugfix.packet_leak;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.duck.IClientNetHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ClientPacketListener.class)
@ClientOnlyMixin
public class ClientPlayNetHandlerMixin implements IClientNetHandler {
private FriendlyByteBuf savedCopy = null;
/**
* @author embeddedt
* @reason Release the packet buffer at the end. Needed in f
*/
@Redirect(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;"))
private FriendlyByteBuf saveCopyForRelease(ClientboundCustomPayloadPacket instance) {
FriendlyByteBuf copy = instance.getData();
savedCopy = copy;
return copy;
}
@Override
public FriendlyByteBuf getCopiedCustomBuffer() {
FriendlyByteBuf copy = savedCopy;
savedCopy = null;
return copy;
}
}

View File

@ -5,7 +5,6 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.duck.IClientNetHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -32,14 +31,9 @@ public class SCustomPayloadPlayPacketMixin {
@Redirect(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientGamePacketListener;handleCustomPayload(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V"))
private void handleAndFree(ClientGamePacketListener instance, ClientboundCustomPayloadPacket sCustomPayloadPlayPacket) {
try {
instance.handleCustomPayload(sCustomPayloadPlayPacket);
} finally {
FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer();
if(copied != null)
copied.release();
}
/* in 1.16, this method creates a copy inside it, but does not handle freeing correctly. fixing that breaks mods though */
instance.handleCustomPayload(sCustomPayloadPlayPacket);
if(this.needsRelease)
this.data.release();
this.data.release(); /* free our own copy of the data if needed */
}
}

View File

@ -1,7 +0,0 @@
package org.embeddedt.modernfix.duck;
import net.minecraft.network.FriendlyByteBuf;
public interface IClientNetHandler {
FriendlyByteBuf getCopiedCustomBuffer();
}