fix version sent in 1.8/1.12 detector

This commit is contained in:
creeper123123321 2024-05-13 09:12:16 -03:00
parent bab35223bb
commit 9065c5260c
7 changed files with 19 additions and 29 deletions

View File

@ -224,6 +224,7 @@ modrinth {
dependencies { dependencies {
optional.project "P7dR8mSH" // fabric api optional.project "P7dR8mSH" // fabric api
optional.project "9CJED7xi" // legacy fabric api optional.project "9CJED7xi" // legacy fabric api
embedded.project "P1OZGk5p" // viaversion
} }
} }

View File

@ -1,18 +0,0 @@
package com.viaversion.fabric.mc1122.mixin.pipeline.client;
import com.viaversion.fabric.mc1122.service.HandshakeInterceptor;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(HandshakeC2SPacket.class)
public class MixinHandshakeC2SPacket implements HandshakeInterceptor {
@Shadow
private int protocolVersion;
@Override
public void viaFabric$setProtocolVersion(int version) {
this.protocolVersion = version;
}
}

View File

@ -0,0 +1,11 @@
package com.viaversion.fabric.mc1122.mixin.pipeline.client;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(HandshakeC2SPacket.class)
public interface MixinHandshakeC2SPacketAccessor {
@Accessor
void setProtocolVersion(int version);
}

View File

@ -1,6 +0,0 @@
package com.viaversion.fabric.mc1122.service;
public interface HandshakeInterceptor {
void viaFabric$setProtocolVersion(final int version);
}

View File

@ -22,6 +22,7 @@ import com.viaversion.fabric.common.AddressParser;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.viaversion.fabric.mc1122.mixin.pipeline.client.MixinHandshakeC2SPacketAccessor;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*; import io.netty.channel.*;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -34,6 +35,7 @@ import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.c2s.query.QueryRequestC2SPacket; import net.minecraft.network.packet.c2s.query.QueryRequestC2SPacket;
import net.minecraft.network.packet.s2c.query.QueryPongS2CPacket; import net.minecraft.network.packet.s2c.query.QueryPongS2CPacket;
import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket; import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket;
import net.minecraft.realms.RealmsSharedConstants;
import net.minecraft.server.ServerMetadata; import net.minecraft.server.ServerMetadata;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -113,8 +115,8 @@ public class ProtocolAutoDetector {
HandshakeC2SPacket handshakeC2SPacket = new HandshakeC2SPacket(address.getHostString(), HandshakeC2SPacket handshakeC2SPacket = new HandshakeC2SPacket(address.getHostString(),
address.getPort(), NetworkState.STATUS); address.getPort(), NetworkState.STATUS);
((HandshakeInterceptor) handshakeC2SPacket).viaFabric$setProtocolVersion( ((MixinHandshakeC2SPacketAccessor) handshakeC2SPacket).setProtocolVersion(
Via.getAPI().getServerVersion().lowestSupportedVersion()); RealmsSharedConstants.NETWORK_PROTOCOL_VERSION);
clientConnection.send(handshakeC2SPacket); clientConnection.send(handshakeC2SPacket);
clientConnection.send(new QueryRequestC2SPacket()); clientConnection.send(new QueryRequestC2SPacket());
}); });

View File

@ -9,7 +9,7 @@
"client": [ "client": [
"client.MixinClientConnection", "client.MixinClientConnection",
"client.MixinClientConnectionChInit", "client.MixinClientConnectionChInit",
"client.MixinHandshakeC2SPacket" "client.MixinHandshakeC2SPacketAccessor"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View File

@ -34,11 +34,11 @@ import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.c2s.query.QueryRequestC2SPacket; import net.minecraft.network.packet.c2s.query.QueryRequestC2SPacket;
import net.minecraft.network.packet.s2c.query.QueryPongS2CPacket; import net.minecraft.network.packet.s2c.query.QueryPongS2CPacket;
import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket; import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket;
import net.minecraft.realms.RealmsSharedConstants;
import net.minecraft.server.ServerMetadata; import net.minecraft.server.ServerMetadata;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.Via;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -110,7 +110,7 @@ public class ProtocolAutoDetector {
} }
}); });
clientConnection.send(new HandshakeC2SPacket(Via.getAPI().getServerVersion().lowestSupportedVersion(), address.getHostString(), clientConnection.send(new HandshakeC2SPacket(RealmsSharedConstants.NETWORK_PROTOCOL_VERSION, address.getHostString(),
address.getPort(), NetworkState.STATUS)); address.getPort(), NetworkState.STATUS));
clientConnection.send(new QueryRequestC2SPacket()); clientConnection.send(new QueryRequestC2SPacket());
}); });