From f89f82673f8a68b2d796d3443616e0f1d18b5a2f Mon Sep 17 00:00:00 2001 From: Kris Date: Wed, 27 Nov 2024 13:36:17 +0200 Subject: [PATCH] fix: only count server prots towards PACKET_GROUP_END --- .../rsprox/proxy/plugin/DecodingSession.kt | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/proxy/src/main/kotlin/net/rsprox/proxy/plugin/DecodingSession.kt b/proxy/src/main/kotlin/net/rsprox/proxy/plugin/DecodingSession.kt index cbd2350d..d8f48e97 100644 --- a/proxy/src/main/kotlin/net/rsprox/proxy/plugin/DecodingSession.kt +++ b/proxy/src/main/kotlin/net/rsprox/proxy/plugin/DecodingSession.kt @@ -5,7 +5,12 @@ import io.netty.buffer.ByteBuf import io.netty.buffer.Unpooled import net.rsprot.buffer.extensions.toJagByteBuf import net.rsprot.protocol.Prot -import net.rsprox.protocol.session.* +import net.rsprox.protocol.session.AttributeMap +import net.rsprox.protocol.session.Session +import net.rsprox.protocol.session.getBytesConsumed +import net.rsprox.protocol.session.getRemainingBytesInPacketGroup +import net.rsprox.protocol.session.setBytesConsumed +import net.rsprox.protocol.session.setRemainingBytesInPacketGroup import net.rsprox.proxy.binary.BinaryBlob import net.rsprox.proxy.binary.BinaryStream import net.rsprox.shared.StreamDirection @@ -24,10 +29,25 @@ public class DecodingSession( val session = Session(blob.header.localPlayerIndex, AttributeMap()) return stream.flatMap { binaryPacket -> try { + if (binaryPacket.direction == StreamDirection.CLIENT_TO_SERVER) { + val packet = + plugin.decodeClientPacket( + binaryPacket.prot.opcode, + binaryPacket.payload.toJagByteBuf(), + session, + ) + return@flatMap listOf( + DirectionalPacket( + binaryPacket.direction, + binaryPacket.prot, + packet, + ), + ) + } var read = binaryPacket.payload.readableBytes() val prot = binaryPacket.prot val opcode = prot.opcode - if (binaryPacket.direction == StreamDirection.CLIENT_TO_SERVER || opcode < 128) { + if (opcode < 128) { read++ } else { read += 2 @@ -39,22 +59,11 @@ public class DecodingSession( } val remainingBytesInPacketGroup = session.getRemainingBytesInPacketGroup() val packet = - when (binaryPacket.direction) { - StreamDirection.CLIENT_TO_SERVER -> { - plugin.decodeClientPacket( - binaryPacket.prot.opcode, - binaryPacket.payload.toJagByteBuf(), - session, - ) - } - StreamDirection.SERVER_TO_CLIENT -> { - plugin.decodeServerPacket( - binaryPacket.prot.opcode, - binaryPacket.payload.toJagByteBuf(), - session, - ) - } - } + plugin.decodeServerPacket( + binaryPacket.prot.opcode, + binaryPacket.payload.toJagByteBuf(), + session, + ) if (remainingBytesInPacketGroup != null && remainingBytesInPacketGroup > 0) { session.setBytesConsumed((session.getBytesConsumed() ?: 0) + read) if (remainingBytesInPacketGroup - read <= 0) {