Revert "Fix incorrect logic in packet leak patch"

This reverts commit 45d308c6a4.
This commit is contained in:
embeddedt 2023-05-14 19:48:57 -04:00
parent eb925bc3ba
commit 0f2764b79d
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 49 additions and 3 deletions

View File

@ -0,0 +1,33 @@
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,6 +5,7 @@ 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;
@ -31,9 +32,14 @@ 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) {
/* in 1.16, this method creates a copy inside it, but handles freeing correctly */
instance.handleCustomPayload(sCustomPayloadPlayPacket);
try {
instance.handleCustomPayload(sCustomPayloadPlayPacket);
} finally {
FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer();
if(copied != null)
copied.release();
}
if(this.needsRelease)
this.data.release(); /* free our own copy of the data if needed */
this.data.release();
}
}

View File

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