Revert "Hopefully more stable version of the original packet fix"

This reverts commit b21ee9a7e7.
This commit is contained in:
embeddedt 2023-05-17 16:51:25 -04:00
parent f67fa07546
commit 0d4a12eafe
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 18 additions and 21 deletions

View File

@ -11,13 +11,23 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ClientPacketListener.class)
@ClientOnlyMixin
public class ClientPlayNetHandlerMixin {
public class ClientPlayNetHandlerMixin implements IClientNetHandler {
private FriendlyByteBuf savedCopy = null;
/**
* @author embeddedt
* @reason allow the other function to track use of the buffer
* @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) {
return ((IClientNetHandler)instance).getCopiedCustomBuffer();
FriendlyByteBuf copy = instance.getData();
savedCopy = copy;
return copy;
}
@Override
public FriendlyByteBuf getCopiedCustomBuffer() {
FriendlyByteBuf copy = savedCopy;
savedCopy = null;
return copy;
}
}

View File

@ -15,13 +15,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientboundCustomPayloadPacket.class)
@ClientOnlyMixin
public abstract class SCustomPayloadPlayPacketMixin implements IClientNetHandler {
public class SCustomPayloadPlayPacketMixin {
@Shadow private FriendlyByteBuf data;
@Shadow public abstract FriendlyByteBuf getData();
private FriendlyByteBuf usedByteBuf = null;
private boolean needsRelease;
@Inject(method = "<init>(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
@ -34,25 +30,16 @@ public abstract class SCustomPayloadPlayPacketMixin implements IClientNetHandler
this.needsRelease = true;
}
@Override
public FriendlyByteBuf getCopiedCustomBuffer() {
FriendlyByteBuf buf = this.getData();
usedByteBuf = buf;
return buf;
}
@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) {
usedByteBuf = null;
try {
instance.handleCustomPayload(sCustomPayloadPlayPacket);
} finally {
FriendlyByteBuf buf = usedByteBuf;
if(buf != null && buf.refCnt() > 0) {
buf.release();
}
FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer();
if(copied != null)
copied.release();
}
if(this.needsRelease && this.data.refCnt() > 0)
if(this.needsRelease)
this.data.release();
}
}