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) @Mixin(ClientPacketListener.class)
@ClientOnlyMixin @ClientOnlyMixin
public class ClientPlayNetHandlerMixin { public class ClientPlayNetHandlerMixin implements IClientNetHandler {
private FriendlyByteBuf savedCopy = null;
/** /**
* @author embeddedt * @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;")) @Redirect(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;"))
private FriendlyByteBuf saveCopyForRelease(ClientboundCustomPayloadPacket instance) { 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) @Mixin(ClientboundCustomPayloadPacket.class)
@ClientOnlyMixin @ClientOnlyMixin
public abstract class SCustomPayloadPlayPacketMixin implements IClientNetHandler { public class SCustomPayloadPlayPacketMixin {
@Shadow private FriendlyByteBuf data; @Shadow private FriendlyByteBuf data;
@Shadow public abstract FriendlyByteBuf getData();
private FriendlyByteBuf usedByteBuf = null;
private boolean needsRelease; private boolean needsRelease;
@Inject(method = "<init>(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN")) @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; 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")) @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) { private void handleAndFree(ClientGamePacketListener instance, ClientboundCustomPayloadPacket sCustomPayloadPlayPacket) {
usedByteBuf = null;
try { try {
instance.handleCustomPayload(sCustomPayloadPlayPacket); instance.handleCustomPayload(sCustomPayloadPlayPacket);
} finally { } finally {
FriendlyByteBuf buf = usedByteBuf; FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer();
if(buf != null && buf.refCnt() > 0) { if(copied != null)
buf.release(); copied.release();
}
} }
if(this.needsRelease && this.data.refCnt() > 0) if(this.needsRelease)
this.data.release(); this.data.release();
} }
} }