mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-15 10:45:35 +01:00
Merge remote-tracking branch 'origin/main' into 1.20-recode
# Conflicts: # gradle.properties
This commit is contained in:
commit
0ea3c22fb8
@ -27,7 +27,7 @@ snake_yml_version=2.0
|
||||
vialegacy_version=2.2.16
|
||||
viaaprilfools_version=2.0.7-SNAPSHOT
|
||||
viabedrock_version=0.0.1-SNAPSHOT
|
||||
minecraftauth_version=2.1.1
|
||||
minecraftauth_version=2.1.2
|
||||
|
||||
# lenni0451 libs
|
||||
mcstructs_text_version=2.2.5
|
||||
|
@ -57,10 +57,7 @@ public class FontCacheFix {
|
||||
|
||||
public enum BuiltinEmptyGlyph1_12_2 implements Glyph {
|
||||
|
||||
VERY_MISSING(() -> BuiltinEmptyGlyph1_12_2.createRectImage((x, y) -> {
|
||||
boolean bl = x == 0 || x + 1 == 5 || y == 0 || y + 1 == 8;
|
||||
return bl ? -1 : 0;
|
||||
}));
|
||||
VERY_MISSING(() -> BuiltinEmptyGlyph1_12_2.createRectImage((x, y) -> x == 0 || x + 1 == 5 || y == 0 || y + 1 == 8 ? -1 : 0));
|
||||
|
||||
final NativeImage image;
|
||||
|
||||
@ -71,9 +68,9 @@ public class FontCacheFix {
|
||||
private static NativeImage createRectImage(BuiltinEmptyGlyph1_12_2.ColorSupplier colorSupplier) {
|
||||
final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, 5, 8, false);
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
nativeImage.setColor(j, i, colorSupplier.getColor(j, i));
|
||||
for (int y = 0; y < 8; ++y) {
|
||||
for (int x = 0; x < 5; ++x) {
|
||||
nativeImage.setColor(x, y, colorSupplier.getColor(x, y));
|
||||
}
|
||||
}
|
||||
nativeImage.untrack();
|
||||
@ -88,6 +85,7 @@ public class FontCacheFix {
|
||||
@Override
|
||||
public GlyphRenderer bake(Function<RenderableGlyph, GlyphRenderer> function) {
|
||||
return function.apply(new RenderableGlyph() {
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return BuiltinEmptyGlyph1_12_2.this.image.getWidth();
|
||||
@ -118,7 +116,7 @@ public class FontCacheFix {
|
||||
@FunctionalInterface
|
||||
interface ColorSupplier {
|
||||
|
||||
int getColor(int var1, int var2);
|
||||
int getColor(int x, int y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,9 +99,9 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler<
|
||||
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelRegistered(ctx);
|
||||
|
||||
if (ProtocolHack.getRakNetPingSessions().contains(viafabricplus_capturedAddress)) {
|
||||
if (RakNetClientConnection.getRakNetPingSessions().contains(viafabricplus_capturedAddress)) {
|
||||
channelActive(ctx);
|
||||
ProtocolHack.getRakNetPingSessions().remove(viafabricplus_capturedAddress);
|
||||
RakNetClientConnection.getRakNetPingSessions().remove(viafabricplus_capturedAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package de.florianmichael.viafabricplus.injection.mixin.base;
|
||||
|
||||
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viabedrock.RakNetClientConnection;
|
||||
import de.florianmichael.vialoadingbase.model.ComparableProtocolVersion;
|
||||
import net.minecraft.client.network.MultiplayerServerListPinger;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
@ -40,7 +41,11 @@ public class MixinMultiplayerServerListPinger {
|
||||
public void trackSessions(ServerInfo entry, Runnable saver, CallbackInfo ci, ServerAddress serverAddress, Optional optional, InetSocketAddress inetSocketAddress) {
|
||||
final ComparableProtocolVersion version = ((IServerInfo) entry).viafabricplus_forcedVersion();
|
||||
|
||||
if (version != null) ProtocolHack.getForcedVersions().put(inetSocketAddress, version);
|
||||
if (ProtocolHack.isEqualToOrForced(inetSocketAddress, BedrockProtocolVersion.bedrockLatest)) ProtocolHack.getRakNetPingSessions().add(inetSocketAddress);
|
||||
if (version != null) {
|
||||
ProtocolHack.getForcedVersions().put(inetSocketAddress, version);
|
||||
}
|
||||
if (ProtocolHack.getTargetVersion(inetSocketAddress).isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
|
||||
RakNetClientConnection.getRakNetPingSessions().add(inetSocketAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,8 @@ public abstract class MixinClientPlayNetworkHandler {
|
||||
|
||||
@Shadow public abstract void sendPacket(Packet<?> packet);
|
||||
|
||||
@Shadow @Final private ClientConnection connection;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void fixPlayerListOrdering(MinecraftClient client, Screen screen, ClientConnection connection, ServerInfo serverInfo, GameProfile profile, WorldSession worldSession, CallbackInfo ci) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_1)) {
|
||||
@ -152,7 +154,7 @@ public abstract class MixinClientPlayNetworkHandler {
|
||||
|
||||
@Inject(method = "onSetTradeOffers", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true)
|
||||
public void checkLoginPacket(SetTradeOffersS2CPacket packet, CallbackInfo ci) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_13_2) && this.client.player == null) {
|
||||
if (ProtocolHack.getTargetVersion(connection.channel).isOlderThanOrEqualTo(ProtocolVersion.v1_13_2) && this.client.player == null) {
|
||||
ViaFabricPlus.LOGGER.error("Server tried to send Play packet in Login process, dropping \"SetTradeOffers\"");
|
||||
ci.cancel();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class MixinConnectScreen_1 {
|
||||
|
||||
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetSocketAddress;getHostName()Ljava/lang/String;", ordinal = 0))
|
||||
public String replaceAddress(InetSocketAddress instance) {
|
||||
if (ProtocolHack.isOlderThanOrEqualToOrForced(instance, ProtocolVersion.v1_17) || ProtocolHack.isEqualToOrForced(instance, BedrockProtocolVersion.bedrockLatest)) {
|
||||
if (ProtocolHack.getTargetVersion(instance).isOlderThanOrEqualTo(ProtocolVersion.v1_17) || ProtocolHack.getTargetVersion(instance).isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
|
||||
return field_33737.getAddress();
|
||||
}
|
||||
return instance.getHostName();
|
||||
@ -74,7 +74,7 @@ public class MixinConnectScreen_1 {
|
||||
|
||||
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetSocketAddress;getPort()I"))
|
||||
public int replacePort(InetSocketAddress instance) {
|
||||
if (ProtocolHack.isOlderThanOrEqualToOrForced(instance, ProtocolVersion.v1_17) || ProtocolHack.isEqualToOrForced(instance, BedrockProtocolVersion.bedrockLatest)) {
|
||||
if (ProtocolHack.getTargetVersion(instance).isOlderThanOrEqualTo(ProtocolVersion.v1_17) || ProtocolHack.getTargetVersion(instance).isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
|
||||
return field_33737.getPort();
|
||||
}
|
||||
return instance.getPort();
|
||||
|
@ -82,40 +82,34 @@ public class ProtocolHack {
|
||||
public final static AttributeKey<ComparableProtocolVersion> FORCED_VERSION = AttributeKey.newInstance("viafabricplus-forced-version");
|
||||
|
||||
private final static Map<InetSocketAddress, ComparableProtocolVersion> forcedVersions = new HashMap<>();
|
||||
private final static List<InetSocketAddress> rakNetPingSessions = new ArrayList<>();
|
||||
|
||||
public static ComparableProtocolVersion getTargetVersion() {
|
||||
if (MinecraftClient.getInstance() == null || MinecraftClient.getInstance().getNetworkHandler() == null) return getTargetVersion(null);
|
||||
if (MinecraftClient.getInstance() == null || MinecraftClient.getInstance().getNetworkHandler() == null) {
|
||||
return getTargetVersion((Channel) null);
|
||||
}
|
||||
|
||||
return getTargetVersion(MinecraftClient.getInstance().getNetworkHandler().getConnection().channel);
|
||||
}
|
||||
|
||||
public static ComparableProtocolVersion getTargetVersion(final Channel channel) {
|
||||
if (channel != null && channel.hasAttr(FORCED_VERSION)) return channel.attr(FORCED_VERSION).get();
|
||||
if (channel != null && channel.hasAttr(FORCED_VERSION)) {
|
||||
return channel.attr(FORCED_VERSION).get();
|
||||
}
|
||||
|
||||
return ViaLoadingBase.getInstance().getTargetVersion();
|
||||
}
|
||||
|
||||
public static ComparableProtocolVersion getTargetVersion(final InetSocketAddress socketAddress) {
|
||||
if (forcedVersions.containsKey(socketAddress)) {
|
||||
return forcedVersions.get(socketAddress);
|
||||
}
|
||||
return getTargetVersion();
|
||||
}
|
||||
|
||||
public static Map<InetSocketAddress, ComparableProtocolVersion> getForcedVersions() {
|
||||
return forcedVersions;
|
||||
}
|
||||
|
||||
public static List<InetSocketAddress> getRakNetPingSessions() {
|
||||
return rakNetPingSessions;
|
||||
}
|
||||
|
||||
public static boolean isEqualToOrForced(final InetSocketAddress socketAddress, final ProtocolVersion version) {
|
||||
if (forcedVersions.containsKey(socketAddress)) return forcedVersions.get(socketAddress).isEqualTo(version);
|
||||
|
||||
return ProtocolHack.getTargetVersion().isEqualTo(version);
|
||||
}
|
||||
|
||||
public static boolean isOlderThanOrEqualToOrForced(final InetSocketAddress socketAddress, final ProtocolVersion version) {
|
||||
if (forcedVersions.containsKey(socketAddress)) return forcedVersions.get(socketAddress).isOlderThanOrEqualTo(version);
|
||||
|
||||
return ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(version);
|
||||
}
|
||||
|
||||
public static void injectVLBPipeline(final ClientConnection connection, final Channel channel, final InetSocketAddress address) {
|
||||
if (ProtocolHack.getForcedVersions().containsKey(address)) {
|
||||
channel.attr(ProtocolHack.FORCED_VERSION).set(ProtocolHack.getForcedVersions().get(address));
|
||||
|
@ -19,8 +19,8 @@ package de.florianmichael.viafabricplus.protocolhack.netty;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viabedrock.DisconnectAdapter;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viabedrock.RakNetClientConnection;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viabedrock.codec.PingEncapsulationCodec;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.viabedrock.codec.RakMessageEncapsulationCodec;
|
||||
import de.florianmichael.vialoadingbase.model.ComparableProtocolVersion;
|
||||
@ -50,8 +50,8 @@ public class ViaFabricPlusVLBPipeline extends VLBPipeline {
|
||||
public final static String VIA_BEDROCK_ENCRYPTION_HANDLER_NAME = "via-bedrock-encryption";
|
||||
|
||||
// ViaLegacy (pre Netty)
|
||||
public final static String VIA_LEGACY_PRE_NETTY_LENGTH_PREPENDER_HANDLER_NAME = "via-legacy-decoder";
|
||||
public final static String VIA_LEGACY_PRE_NETTY_LENGTH_REMOVER_HANDLER_NAME = "via-legacy-encoder";
|
||||
public final static String VIA_LEGACY_PRE_NETTY_LENGTH_PREPENDER_HANDLER_NAME = "via-legacy-pre-netty-length-prepender";
|
||||
public final static String VIA_LEGACY_PRE_NETTY_LENGTH_REMOVER_HANDLER_NAME = "via-legacy-pre-netty-length-remover";
|
||||
|
||||
private final InetSocketAddress address;
|
||||
private final ComparableProtocolVersion version;
|
||||
@ -93,7 +93,7 @@ public class ViaFabricPlusVLBPipeline extends VLBPipeline {
|
||||
pipeline.remove("timeout");
|
||||
|
||||
// Pinging in RakNet is something different
|
||||
if (ProtocolHack.getRakNetPingSessions().contains(address)) {
|
||||
if (RakNetClientConnection.getRakNetPingSessions().contains(address)) {
|
||||
pipeline.replace(VIA_BEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, VIA_BEDROCK_PING_ENCAPSULATION_HANDLER_NAME, new PingEncapsulationCodec(address));
|
||||
|
||||
pipeline.remove(VIA_BEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME);
|
||||
|
@ -32,9 +32,13 @@ import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RakNetClientConnection {
|
||||
private final static List<InetSocketAddress> rakNetPingSessions = new ArrayList<>();
|
||||
|
||||
public static void connectRakNet(final ClientConnection clientConnection, final InetSocketAddress address, final Lazy lazy, final Class channelType) {
|
||||
final Bootstrap nettyBoostrap = new Bootstrap().group((EventLoopGroup) lazy.get()).handler(new ChannelInitializer<>() {
|
||||
@Override
|
||||
@ -55,10 +59,14 @@ public class RakNetClientConnection {
|
||||
}
|
||||
}).channelFactory(channelType == EpollSocketChannel.class ? RakChannelFactory.client(EpollDatagramChannel.class) : RakChannelFactory.client(NioDatagramChannel.class));
|
||||
|
||||
if (ProtocolHack.getRakNetPingSessions().contains(address)) {
|
||||
if (getRakNetPingSessions().contains(address)) {
|
||||
nettyBoostrap.bind(new InetSocketAddress(0)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE).syncUninterruptibly();
|
||||
} else {
|
||||
nettyBoostrap.connect(address.getAddress(), address.getPort()).syncUninterruptibly();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<InetSocketAddress> getRakNetPingSessions() {
|
||||
return rakNetPingSessions;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user