Revert "The bytebuf doesn't need to be rewritten"

This reverts commit ac877d0b1a.
This commit is contained in:
Myles 2021-02-09 16:32:31 +00:00
parent f04a748e54
commit 50bfc86706
2 changed files with 36 additions and 20 deletions

View File

@ -31,12 +31,15 @@ public class BukkitDecodeHandler extends ByteToMessageDecoder {
throw CancelDecoderException.generate(null); throw CancelDecoderException.generate(null);
} }
ByteBuf transformedBuf = null;
try {
if (info.shouldTransformPacket()) { if (info.shouldTransformPacket()) {
info.transformIncoming(bytebuf, CancelDecoderException::generate); transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate);
} }
try { try {
list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf)); list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, transformedBuf == null ? bytebuf : transformedBuf));
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) { if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause(); throw (Exception) e.getCause();
@ -44,6 +47,11 @@ public class BukkitDecodeHandler extends ByteToMessageDecoder {
throw (Error) e.getCause(); throw (Error) e.getCause();
} }
} }
} finally {
if (transformedBuf != null) {
transformedBuf.release();
}
}
} }
@Override @Override

View File

@ -28,12 +28,15 @@ public class SpongeDecodeHandler extends ByteToMessageDecoder {
throw CancelDecoderException.generate(null); throw CancelDecoderException.generate(null);
} }
ByteBuf transformedBuf = null;
try {
if (info.shouldTransformPacket()) { if (info.shouldTransformPacket()) {
info.transformIncoming(bytebuf, CancelDecoderException::generate); transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate);
} }
try { try {
list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf)); list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, transformedBuf == null ? bytebuf : transformedBuf));
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) { if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause(); throw (Exception) e.getCause();
@ -41,6 +44,11 @@ public class SpongeDecodeHandler extends ByteToMessageDecoder {
throw (Error) e.getCause(); throw (Error) e.getCause();
} }
} }
} finally {
if (transformedBuf != null) {
transformedBuf.release();
}
}
} }
@Override @Override