Add 1.20.5 packets

This commit is contained in:
FlorianMichael 2024-04-30 23:08:40 +02:00
parent 6587d0d179
commit 251bc6c39f
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 107 additions and 6 deletions

View File

@ -0,0 +1,41 @@
package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
public class ConfigurationTransfer implements Packet {
private String host;
private int port;
@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
host = Type.STRING.read(byteBuf);
port = Type.VAR_INT.readPrimitive(byteBuf);
}
@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, host);
Type.VAR_INT.writePrimitive(byteBuf, port);
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
}

View File

@ -1,6 +1,7 @@
package com.viaversion.aas.codec.packet.handshake;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.aas.util.IntendedState;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
@ -12,13 +13,18 @@ public class Handshake implements Packet {
private String address;
private int port;
private State nextState;
private IntendedState intendedState;
@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
protocolId = Type.VAR_INT.readPrimitive(byteBuf);
address = Type.STRING.read(byteBuf);
port = byteBuf.readUnsignedShort();
nextState = State.values()[Type.VAR_INT.readPrimitive(byteBuf)];
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
intendedState = IntendedState.values()[Type.VAR_INT.readPrimitive(byteBuf) - 1];
} else {
nextState = State.values()[Type.VAR_INT.readPrimitive(byteBuf)];
}
}
@Override
@ -26,7 +32,11 @@ public class Handshake implements Packet {
Type.VAR_INT.writePrimitive(byteBuf, protocolId);
Type.STRING.write(byteBuf, address);
byteBuf.writeShort(port);
byteBuf.writeByte(nextState.ordinal()); // var int is too small, fits in a byte
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
Type.VAR_INT.writePrimitive(byteBuf, intendedState.ordinal() + 1);
} else {
byteBuf.writeByte(nextState.ordinal()); // var int is too small, fits in a byte
}
}
public int getProtocolId() {
@ -60,4 +70,12 @@ public class Handshake implements Packet {
public void setNextState(State nextState) {
this.nextState = nextState;
}
public IntendedState getIntendedState() {
return intendedState;
}
public void setIntendedState(IntendedState intendedState) {
this.intendedState = intendedState;
}
}

View File

@ -16,6 +16,7 @@ public class CryptoRequest implements Packet {
private String serverId;
private PublicKey publicKey;
private byte[] nonce;
private boolean authenticate;
@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
@ -30,6 +31,9 @@ public class CryptoRequest implements Packet {
.generatePublic(new X509EncodedKeySpec(UtilKt.readByteArray(byteBuf, byteBuf.readUnsignedShort())));
nonce = UtilKt.readByteArray(byteBuf, byteBuf.readUnsignedShort());
}
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
authenticate = byteBuf.readBoolean();
}
}
@Override
@ -47,6 +51,9 @@ public class CryptoRequest implements Packet {
byteBuf.writeShort(nonce.length);
byteBuf.writeBytes(nonce);
}
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
byteBuf.writeBoolean(authenticate);
}
}
public String getServerId() {
@ -72,4 +79,12 @@ public class CryptoRequest implements Packet {
public void setNonce(byte[] nonce) {
this.nonce = nonce;
}
public boolean isAuthenticate() {
return authenticate;
}
public void setAuthenticate(boolean authenticate) {
this.authenticate = authenticate;
}
}

View File

@ -0,0 +1,20 @@
package com.viaversion.aas.util;
import com.viaversion.viaversion.api.protocol.packet.State;
public enum IntendedState {
STATUS(State.STATUS),
LOGIN(State.LOGIN),
TRANSFER(State.LOGIN);
private final State state;
IntendedState(State state) {
this.state = state;
}
public State getState() {
return state;
}
}

View File

@ -3,10 +3,7 @@ package com.viaversion.aas.codec.packet
import com.google.common.collect.Range
import com.google.common.collect.RangeMap
import com.google.common.collect.TreeRangeMap
import com.viaversion.aas.codec.packet.configuration.ConfigurationDisconnect
import com.viaversion.aas.codec.packet.configuration.ConfigurationKeepAlive
import com.viaversion.aas.codec.packet.configuration.ConfigurationPluginMessage
import com.viaversion.aas.codec.packet.configuration.FinishConfig
import com.viaversion.aas.codec.packet.configuration.*
import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.codec.packet.login.*
import com.viaversion.aas.codec.packet.play.*
@ -90,6 +87,9 @@ object PacketRegistry {
ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ClientboundConfigurationPackets1_20_2.KEEP_ALIVE.id,
ProtocolVersion.v1_20_5.singleton to ClientboundConfigurationPackets1_20_5.KEEP_ALIVE.id
))
register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationTransfer, Range.atLeast(ProtocolVersion.v1_20_5),
ClientboundConfigurationPackets1_20_5.TRANSFER.id)
register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationPluginMessage, mapOf(
ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ServerboundConfigurationPackets1_20_2.CUSTOM_PAYLOAD.id,
ProtocolVersion.v1_20_5.singleton to ServerboundConfigurationPackets1_20_5.CUSTOM_PAYLOAD.id

View File

@ -13,6 +13,7 @@ class LoginSuccess : Packet {
lateinit var id: UUID
lateinit var username: String
private val properties = mutableListOf<SignableProperty>()
private var strictErrorHandling: Boolean = false
override fun decode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
id = when {
@ -34,6 +35,9 @@ class LoginSuccess : Packet {
this.properties.add(SignableProperty(name, value, signature))
}
}
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
strictErrorHandling = byteBuf.readBoolean()
}
}
override fun encode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
@ -55,5 +59,8 @@ class LoginSuccess : Packet {
Type.OPTIONAL_STRING.write(byteBuf, property.signature)
}
}
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
byteBuf.writeBoolean(strictErrorHandling)
}
}
}