Skip to content

Commit

Permalink
update to viaversion 5
Browse files Browse the repository at this point in the history
  • Loading branch information
creeper123123321 committed Jun 18, 2024
1 parent e6676c9 commit 5515f50
Show file tree
Hide file tree
Showing 39 changed files with 208 additions and 202 deletions.
16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))

val vvVer = "4.10.3-SNAPSHOT"
val vbVer = "4.10.3-SNAPSHOT"
val vrVer = "3.1.2-SNAPSHOT"
val vvVer = "5.0.1-SNAPSHOT"
val vbVer = "5.0.1-SNAPSHOT"
val vrVer = "4.0.0"
implementation("com.viaversion:viaversion-common:$vvVer") { isTransitive = false }
implementation("com.viaversion:viabackwards-common:$vbVer") { isTransitive = false }
implementation("com.viaversion:viarewind-common:$vrVer") { isTransitive = false }
implementation("net.raphimc:ViaAprilFools:2.0.12-SNAPSHOT")
implementation("net.raphimc:ViaLegacy:2.2.23-SNAPSHOT")
implementation("net.raphimc:ViaAprilFools:3.0.1-SNAPSHOT")
implementation("net.raphimc:ViaLegacy:3.0.1-SNAPSHOT")

val nettyVer = "4.1.107.Final"
val nettyVer = "4.1.111.Final"
implementation("io.netty:netty-handler-proxy:$nettyVer")
implementation("io.netty:netty-resolver-dns:$nettyVer")
implementation("io.netty:netty-transport-native-epoll:$nettyVer:linux-aarch_64")
Expand All @@ -79,13 +79,13 @@ dependencies {
implementation("io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.25.Final:linux-aarch_64")
implementation("io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.25.Final:linux-x86_64")

implementation("com.google.guava:guava:33.2.0-jre")
implementation("com.google.guava:guava:33.2.1-jre")
implementation("com.velocitypowered:velocity-native:3.3.0-SNAPSHOT")
implementation("net.coobird:thumbnailator:0.4.20")
implementation("org.powernukkit.fastutil:fastutil-lite:8.1.1")
implementation("org.yaml:snakeyaml:2.2")

val log4jVer = "2.22.1"
val log4jVer = "2.23.1"
val slf4jVer = "2.0.12"
implementation("com.lmax:disruptor:3.4.4")
implementation("net.minecrell:terminalconsoleappender:1.3.0")
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/viaversion/aas/codec/CompressionCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.viaversion.aas.config.VIAaaSConfig;
import com.viaversion.aas.handler.MinecraftHandler;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
outBuf.writeByte(0);
outBuf.writeBytes(msg);
} else {
Type.VAR_INT.writePrimitive(outBuf, uncompressedSize);
Types.VAR_INT.writePrimitive(outBuf, uncompressedSize);
var compatibleIn = MoreByteBufUtils.ensureCompatible(ctx.alloc(), compressor, msg);
try {
compressor.deflate(compatibleIn, outBuf);
Expand All @@ -112,7 +113,7 @@ private ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg) {
protected void decode(ChannelHandlerContext ctx, ByteBuf input, List<Object> out) throws Exception {
if (!input.isReadable() || !ctx.channel().isActive()) return;

var claimedUncompressedSize = Type.VAR_INT.readPrimitive(input);
var claimedUncompressedSize = Types.VAR_INT.readPrimitive(input);
if (claimedUncompressedSize == 0) { // Uncompressed
out.add(input.retain());
return;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/viaversion/aas/codec/FrameCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.viaversion.aas.UtilKt;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.exception.CancelDecoderException;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
Expand Down Expand Up @@ -31,7 +32,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
in.readerIndex(index);
if (result == -1) return; // not readable

int length = Type.VAR_INT.readPrimitive(in);
int length = Types.VAR_INT.readPrimitive(in);

if (length >= 2097152 || length < 0) throw UtilKt.getBadLength();
if (!in.isReadable(length)) {
Expand All @@ -45,7 +46,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
if (msg.readableBytes() >= 2097152) throw UtilKt.getBadLength();
Type.VAR_INT.writePrimitive(out, msg.readableBytes());
Types.VAR_INT.writePrimitive(out, msg.readableBytes());
out.writeBytes(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -19,11 +20,11 @@ public void setThreshold(int threshold) {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
threshold = Type.VAR_INT.readPrimitive(byteBuf);
threshold = Types.VAR_INT.readPrimitive(byteBuf);
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.VAR_INT.writePrimitive(byteBuf, threshold);
Types.VAR_INT.writePrimitive(byteBuf, threshold);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -11,12 +12,12 @@ public abstract class AbstractCookieRequest implements Packet {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
identifier = Type.STRING.read(byteBuf);
identifier = Types.STRING.read(byteBuf);
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, identifier);
Types.STRING.write(byteBuf, identifier);
}

public String getIdentifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -12,14 +13,14 @@ public abstract class AbstractCookieResponse implements Packet {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
id = Type.STRING.read(byteBuf);
payload = Type.OPTIONAL_BYTE_ARRAY_PRIMITIVE.read(byteBuf);
id = Types.STRING.read(byteBuf);
payload = Types.OPTIONAL_BYTE_ARRAY_PRIMITIVE.read(byteBuf);
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, id);
Type.OPTIONAL_BYTE_ARRAY_PRIMITIVE.write(byteBuf, payload);
Types.STRING.write(byteBuf, id);
Types.OPTIONAL_BYTE_ARRAY_PRIMITIVE.write(byteBuf, payload);
}

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.util.ComponentUtil;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -47,18 +47,16 @@ public void setMsgForVersion(JsonElement msg, ProtocolVersion protocolVersion) {
@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
if (protocolVersion.olderThan(ProtocolVersion.v1_20_3)) {
msg = JsonParser.parseString(Type.STRING.read(byteBuf));
msg = JsonParser.parseString(Types.STRING.read(byteBuf));
} else {
msgTag = Type.TAG.read(byteBuf);
msgTag = Types.TAG.read(byteBuf);
}
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
if (protocolVersion.olderThan(ProtocolVersion.v1_20_3)) {
Type.STRING.write(byteBuf, msg.toString());
Types.STRING.write(byteBuf, msg.toString());
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -21,11 +22,11 @@ public void setMsg(JsonElement msg) {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
msg = JsonParser.parseString(Type.STRING.read(byteBuf));
msg = JsonParser.parseString(Types.STRING.read(byteBuf));
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, msg.toString());
Types.STRING.write(byteBuf, msg.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -13,13 +14,13 @@ public class ConfigurationPluginMessage implements Packet {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
channel = Type.STRING.read(byteBuf);
channel = Types.STRING.read(byteBuf);
data = UtilKt.readRemainingBytes(byteBuf);
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, channel);
Type.REMAINING_BYTES.write(byteBuf, data);
Types.STRING.write(byteBuf, channel);
Types.REMAINING_BYTES.write(byteBuf, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -13,14 +14,14 @@ public class ConfigurationTransfer implements Packet {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
host = Type.STRING.read(byteBuf);
port = Type.VAR_INT.readPrimitive(byteBuf);
host = Types.STRING.read(byteBuf);
port = Types.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);
Types.STRING.write(byteBuf, host);
Types.VAR_INT.writePrimitive(byteBuf, port);
}

public String getHost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.viaversion.aas.util.IntendedState;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -15,18 +16,18 @@ public class Handshake implements Packet {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
protocolId = Type.VAR_INT.readPrimitive(byteBuf);
address = Type.STRING.read(byteBuf);
protocolId = Types.VAR_INT.readPrimitive(byteBuf);
address = Types.STRING.read(byteBuf);
port = byteBuf.readUnsignedShort();
intendedState = IntendedState.values()[Type.VAR_INT.readPrimitive(byteBuf)];
intendedState = IntendedState.values()[Types.VAR_INT.readPrimitive(byteBuf)];
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.VAR_INT.writePrimitive(byteBuf, protocolId);
Type.STRING.write(byteBuf, address);
Types.VAR_INT.writePrimitive(byteBuf, protocolId);
Types.STRING.write(byteBuf, address);
byteBuf.writeShort(port);
Type.VAR_INT.writePrimitive(byteBuf, intendedState.ordinal());
Types.VAR_INT.writePrimitive(byteBuf, intendedState.ordinal());
}

public int getProtocolId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.viaversion.aas.protocol.AspirinProtocolsKt;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,12 +21,12 @@ public class CryptoRequest implements Packet {

@Override
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
serverId = Type.STRING.read(byteBuf);
serverId = Types.STRING.read(byteBuf);
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8)
|| protocolVersion.equalTo(AspirinProtocolsKt.getSharewareVersion())) {
publicKey = KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)));
nonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf);
.generatePublic(new X509EncodedKeySpec(Types.BYTE_ARRAY_PRIMITIVE.read(byteBuf)));
nonce = Types.BYTE_ARRAY_PRIMITIVE.read(byteBuf);
} else {
publicKey = KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(UtilKt.readByteArray(byteBuf, byteBuf.readUnsignedShort())));
Expand All @@ -39,11 +40,11 @@ public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) th
@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {

Type.STRING.write(byteBuf, serverId);
Types.STRING.write(byteBuf, serverId);
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8)
|| protocolVersion.equalTo(AspirinProtocolsKt.getSharewareVersion())) {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, publicKey.getEncoded());
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, nonce);
Types.BYTE_ARRAY_PRIMITIVE.write(byteBuf, publicKey.getEncoded());
Types.BYTE_ARRAY_PRIMITIVE.write(byteBuf, nonce);
} else {
byte[] encodedKey = publicKey.getEncoded();
byteBuf.writeShort(encodedKey.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.StringType;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -44,27 +45,27 @@ public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) th
username = new StringType(16).read(byteBuf);
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion.olderThan(ProtocolVersion.v1_19_3)) {
profileKey = Type.OPTIONAL_PROFILE_KEY.read(byteBuf);
profileKey = Types.OPTIONAL_PROFILE_KEY.read(byteBuf);
}

if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
profileId = Type.UUID.read(byteBuf);
profileId = Types.UUID.read(byteBuf);
} else if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
profileId = Type.OPTIONAL_UUID.read(byteBuf);
profileId = Types.OPTIONAL_UUID.read(byteBuf);
}
}

@Override
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, username);
Types.STRING.write(byteBuf, username);
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion.olderThan(ProtocolVersion.v1_19_3)) {
Type.OPTIONAL_PROFILE_KEY.write(byteBuf, profileKey);
Types.OPTIONAL_PROFILE_KEY.write(byteBuf, profileKey);
}
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
Type.UUID.write(byteBuf, profileId);
Types.UUID.write(byteBuf, profileId);
} else if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
Type.OPTIONAL_UUID.write(byteBuf, profileId);
Types.OPTIONAL_UUID.write(byteBuf, profileId);
}
}
}
Loading

0 comments on commit 5515f50

Please sign in to comment.