mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-22 11:56:21 +01:00
Fixed Incompatibility with Raknetify
This commit is contained in:
parent
d5876090c0
commit
9cbd8bb559
@ -65,7 +65,6 @@ It should work fine with most if not all mods and modpacks.
|
|||||||
- ***[ViaFabric](https://github.com/ViaVersion/ViaFabric)***
|
- ***[ViaFabric](https://github.com/ViaVersion/ViaFabric)***
|
||||||
- ***[multiconnect](https://github.com/Earthcomputer/multiconnect)***
|
- ***[multiconnect](https://github.com/Earthcomputer/multiconnect)***
|
||||||
- ***[Krypton](https://github.com/astei/krypton)***
|
- ***[Krypton](https://github.com/astei/krypton)***
|
||||||
- ***[Raknetify](https://github.com/RelativityMC/raknetify/tree/master)***
|
|
||||||
|
|
||||||
## Supported Server versions
|
## Supported Server versions
|
||||||
- Release (1.0.0 - 1.20 [23w12a])
|
- Release (1.0.0 - 1.20 [23w12a])
|
||||||
|
@ -22,7 +22,7 @@ import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
|||||||
import de.florianmichael.viafabricplus.protocolhack.constants.PreNettyConstants;
|
import de.florianmichael.viafabricplus.protocolhack.constants.PreNettyConstants;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.constants.BedrockRakNetConstants;
|
import de.florianmichael.viafabricplus.protocolhack.constants.BedrockRakNetConstants;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.RakNetClientConnection;
|
import de.florianmichael.viafabricplus.protocolhack.PipelineInjector;
|
||||||
import de.florianmichael.vialoadingbase.ViaLoadingBase;
|
import de.florianmichael.vialoadingbase.ViaLoadingBase;
|
||||||
import de.florianmichael.vialoadingbase.event.PipelineReorderEvent;
|
import de.florianmichael.vialoadingbase.event.PipelineReorderEvent;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
@ -90,7 +90,7 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler<
|
|||||||
((IClientConnection) clientConnection).viafabricplus_captureAddress(address);
|
((IClientConnection) clientConnection).viafabricplus_captureAddress(address);
|
||||||
|
|
||||||
if (ProtocolHack.getForcedVersions().containsKey(address) ? (ProtocolHack.getForcedVersions().get(address).getVersion() == BedrockProtocolVersion.bedrockLatest.getVersion()) : ProtocolHack.getTargetVersion().isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
|
if (ProtocolHack.getForcedVersions().containsKey(address) ? (ProtocolHack.getForcedVersions().get(address).getVersion() == BedrockProtocolVersion.bedrockLatest.getVersion()) : ProtocolHack.getTargetVersion().isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
|
||||||
RakNetClientConnection.connect(clientConnection, address, lazy, class_);
|
PipelineInjector.connectRakNet(clientConnection, address, lazy, class_);
|
||||||
cir.setReturnValue(clientConnection);
|
cir.setReturnValue(clientConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
package de.florianmichael.viafabricplus.injection.mixin.base;
|
package de.florianmichael.viafabricplus.injection.mixin.base;
|
||||||
|
|
||||||
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
||||||
import de.florianmichael.viafabricplus.injection.reference.ClientConnectionReference;
|
import de.florianmichael.viafabricplus.protocolhack.PipelineInjector;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
@ -39,7 +39,7 @@ public class MixinClientConnection_1 {
|
|||||||
@Inject(method = "initChannel", at = @At("TAIL"))
|
@Inject(method = "initChannel", at = @At("TAIL"))
|
||||||
public void hackNettyPipeline(Channel channel, CallbackInfo ci) {
|
public void hackNettyPipeline(Channel channel, CallbackInfo ci) {
|
||||||
if (channel instanceof SocketChannel) {
|
if (channel instanceof SocketChannel) {
|
||||||
ClientConnectionReference.hackNettyPipeline(field_11663, channel, ((IClientConnection) field_11663).viafabricplus_capturedAddress());
|
PipelineInjector.hookProtocolHack(field_11663, channel, ((IClientConnection) field_11663).viafabricplus_capturedAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
|
||||||
@Mixin(MultiplayerServerListPinger.class)
|
@Mixin(MultiplayerServerListPinger.class)
|
||||||
public class MixinMultiplayerServerListPinger {
|
public class MixinMultiplayerServerListPinger {
|
||||||
@ -35,13 +36,26 @@ public class MixinMultiplayerServerListPinger {
|
|||||||
@Unique
|
@Unique
|
||||||
private ServerInfo viafabricplus_lastConnect;
|
private ServerInfo viafabricplus_lastConnect;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private ServerAddress viafabricplus_wrappedAddress;
|
||||||
|
|
||||||
@Inject(method = "add", at = @At("HEAD"))
|
@Inject(method = "add", at = @At("HEAD"))
|
||||||
public void track(ServerInfo entry, Runnable saver, CallbackInfo ci) {
|
public void track(ServerInfo entry, Runnable saver, CallbackInfo ci) {
|
||||||
viafabricplus_lastConnect = entry;
|
viafabricplus_lastConnect = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;"))
|
@Inject(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AllowedAddressResolver;resolve(Lnet/minecraft/client/network/ServerAddress;)Ljava/util/Optional;"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||||
public ServerAddress doOwnParse(String address) {
|
public void doOwnParse(ServerInfo entry, Runnable saver, CallbackInfo ci, ServerAddress serverAddress) {
|
||||||
return TileServerAddress.parse(((IServerInfo) viafabricplus_lastConnect).viafabricplus_forcedVersion(), address);
|
viafabricplus_wrappedAddress = TileServerAddress.parse(((IServerInfo) viafabricplus_lastConnect).viafabricplus_forcedVersion(), serverAddress.getAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;getAddress()Ljava/lang/String;"))
|
||||||
|
public String replaceWithWrappedAddress(ServerAddress instance) {
|
||||||
|
return viafabricplus_wrappedAddress.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;getPort()I"))
|
||||||
|
public int replaceWithWrappedPort(ServerAddress instance) {
|
||||||
|
return viafabricplus_wrappedAddress.getPort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
|
||||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package de.florianmichael.viafabricplus.injection.reference;
|
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
|
||||||
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
|
||||||
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
|
||||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
|
||||||
import de.florianmichael.viafabricplus.protocolhack.constants.PreNettyConstants;
|
|
||||||
import de.florianmichael.viafabricplus.protocolhack.platform.vialegacy.VFPPreNettyDecoder;
|
|
||||||
import de.florianmichael.viafabricplus.protocolhack.platform.vialegacy.VFPPreNettyEncoder;
|
|
||||||
import de.florianmichael.viafabricplus.protocolhack.replacement.ViaFabricPlusVLBViaDecodeHandler;
|
|
||||||
import de.florianmichael.vialoadingbase.netty.NettyConstants;
|
|
||||||
import de.florianmichael.vialoadingbase.netty.VLBViaEncodeHandler;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import net.minecraft.network.ClientConnection;
|
|
||||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.baseprotocols.PreNettyBaseProtocol;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
|
|
||||||
public class ClientConnectionReference {
|
|
||||||
|
|
||||||
public static void hackNettyPipeline(final ClientConnection connection, final Channel channel, final InetSocketAddress address) {
|
|
||||||
if (ProtocolHack.getForcedVersions().containsKey(address)) {
|
|
||||||
channel.attr(ProtocolHack.FORCED_VERSION).set(ProtocolHack.getForcedVersions().get(address));
|
|
||||||
ProtocolHack.getForcedVersions().remove(address);
|
|
||||||
}
|
|
||||||
final UserConnection user = new UserConnectionImpl(channel, true);
|
|
||||||
channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).set(user);
|
|
||||||
channel.attr(ProtocolHack.LOCAL_MINECRAFT_CONNECTION).set(connection);
|
|
||||||
|
|
||||||
new ProtocolPipelineImpl(user);
|
|
||||||
|
|
||||||
System.out.println("Hacking Netty Pipeline (ViaVersion)");
|
|
||||||
|
|
||||||
channel.pipeline().addBefore("encoder", NettyConstants.HANDLER_ENCODER_NAME, new VLBViaEncodeHandler(user));
|
|
||||||
channel.pipeline().addBefore("decoder", NettyConstants.HANDLER_DECODER_NAME, new ViaFabricPlusVLBViaDecodeHandler(user));
|
|
||||||
|
|
||||||
if (ProtocolHack.getTargetVersion(channel).isOlderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
|
|
||||||
user.getProtocolInfo().getPipeline().add(PreNettyBaseProtocol.INSTANCE);
|
|
||||||
|
|
||||||
channel.pipeline().addBefore("prepender", PreNettyConstants.HANDLER_ENCODER_NAME, new VFPPreNettyEncoder(user));
|
|
||||||
channel.pipeline().addBefore("splitter", PreNettyConstants.HANDLER_DECODER_NAME, new VFPPreNettyDecoder(user));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,14 +15,23 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package de.florianmichael.viafabricplus.protocolhack.platform.viabedrock;
|
package de.florianmichael.viafabricplus.protocolhack;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import de.florianmichael.viafabricplus.injection.reference.ClientConnectionReference;
|
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.constants.BedrockRakNetConstants;
|
import de.florianmichael.viafabricplus.protocolhack.constants.BedrockRakNetConstants;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.constants.PreNettyConstants;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.DisconnectHandler;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.PingEncapsulationCodec;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.RakMessageEncapsulationCodec;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.library_fix.FixedUnconnectedPingEncoder;
|
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.library_fix.FixedUnconnectedPingEncoder;
|
||||||
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.library_fix.FixedUnconnectedPongDecoder;
|
import de.florianmichael.viafabricplus.protocolhack.platform.viabedrock.library_fix.FixedUnconnectedPongDecoder;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.platform.vialegacy.VFPPreNettyDecoder;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.platform.vialegacy.VFPPreNettyEncoder;
|
||||||
|
import de.florianmichael.viafabricplus.protocolhack.replacement.ViaFabricPlusVLBViaDecodeHandler;
|
||||||
|
import de.florianmichael.vialoadingbase.netty.NettyConstants;
|
||||||
|
import de.florianmichael.vialoadingbase.netty.VLBViaEncodeHandler;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.epoll.EpollDatagramChannel;
|
import io.netty.channel.epoll.EpollDatagramChannel;
|
||||||
@ -35,6 +44,8 @@ import net.minecraft.util.Lazy;
|
|||||||
import net.raphimc.viabedrock.netty.BatchLengthCodec;
|
import net.raphimc.viabedrock.netty.BatchLengthCodec;
|
||||||
import net.raphimc.viabedrock.netty.PacketEncapsulationCodec;
|
import net.raphimc.viabedrock.netty.PacketEncapsulationCodec;
|
||||||
import net.raphimc.viabedrock.protocol.BedrockBaseProtocol;
|
import net.raphimc.viabedrock.protocol.BedrockBaseProtocol;
|
||||||
|
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||||
|
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.baseprotocols.PreNettyBaseProtocol;
|
||||||
import org.cloudburstmc.netty.channel.raknet.RakChannelFactory;
|
import org.cloudburstmc.netty.channel.raknet.RakChannelFactory;
|
||||||
import org.cloudburstmc.netty.channel.raknet.RakClientChannel;
|
import org.cloudburstmc.netty.channel.raknet.RakClientChannel;
|
||||||
import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
|
import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
|
||||||
@ -45,9 +56,37 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class RakNetClientConnection {
|
public class PipelineInjector {
|
||||||
|
|
||||||
public static void connect(final ClientConnection clientConnection, final InetSocketAddress address, final Lazy<? extends MultithreadEventLoopGroup> lazy, final Class<? extends AbstractChannel> channelType) {
|
/**
|
||||||
|
* This method adds the channel handlers required for ViaVersion, ViaBackwards, ViaAprilFools and ViaLegacy, it also tracks the Via and Minecraft Connection
|
||||||
|
*/
|
||||||
|
public static void hookProtocolHack(final ClientConnection connection, final Channel channel, final InetSocketAddress address) {
|
||||||
|
if (ProtocolHack.getForcedVersions().containsKey(address)) {
|
||||||
|
channel.attr(ProtocolHack.FORCED_VERSION).set(ProtocolHack.getForcedVersions().get(address));
|
||||||
|
ProtocolHack.getForcedVersions().remove(address);
|
||||||
|
}
|
||||||
|
final UserConnection user = new UserConnectionImpl(channel, true);
|
||||||
|
channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).set(user);
|
||||||
|
channel.attr(ProtocolHack.LOCAL_MINECRAFT_CONNECTION).set(connection);
|
||||||
|
|
||||||
|
new ProtocolPipelineImpl(user);
|
||||||
|
|
||||||
|
channel.pipeline().addBefore("encoder", NettyConstants.HANDLER_ENCODER_NAME, new VLBViaEncodeHandler(user));
|
||||||
|
channel.pipeline().addBefore("decoder", NettyConstants.HANDLER_DECODER_NAME, new ViaFabricPlusVLBViaDecodeHandler(user));
|
||||||
|
|
||||||
|
if (ProtocolHack.getTargetVersion(channel).isOlderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
|
||||||
|
user.getProtocolInfo().getPipeline().add(PreNettyBaseProtocol.INSTANCE);
|
||||||
|
|
||||||
|
channel.pipeline().addBefore("prepender", PreNettyConstants.HANDLER_ENCODER_NAME, new VFPPreNettyEncoder(user));
|
||||||
|
channel.pipeline().addBefore("splitter", PreNettyConstants.HANDLER_DECODER_NAME, new VFPPreNettyDecoder(user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method represents the rak net connection for bedrock edition, it's a replacement of the ClientConnection#connect method
|
||||||
|
*/
|
||||||
|
public static void connectRakNet(final ClientConnection clientConnection, final InetSocketAddress address, final Lazy<? extends MultithreadEventLoopGroup> lazy, final Class<? extends AbstractChannel> channelType) {
|
||||||
Bootstrap nettyBoostrap = new Bootstrap();
|
Bootstrap nettyBoostrap = new Bootstrap();
|
||||||
nettyBoostrap = nettyBoostrap.group(lazy.get());
|
nettyBoostrap = nettyBoostrap.group(lazy.get());
|
||||||
nettyBoostrap = nettyBoostrap.handler(new ChannelInitializer<>() {
|
nettyBoostrap = nettyBoostrap.handler(new ChannelInitializer<>() {
|
||||||
@ -65,7 +104,7 @@ public class RakNetClientConnection {
|
|||||||
|
|
||||||
channelPipeline.addLast("packet_handler", clientConnection);
|
channelPipeline.addLast("packet_handler", clientConnection);
|
||||||
|
|
||||||
ClientConnectionReference.hackNettyPipeline(clientConnection, channel, address);
|
PipelineInjector.hookProtocolHack(clientConnection, channel, address);
|
||||||
final UserConnection user = channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get();
|
final UserConnection user = channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get();
|
||||||
|
|
||||||
user.getProtocolInfo().getPipeline().add(BedrockBaseProtocol.INSTANCE);
|
user.getProtocolInfo().getPipeline().add(BedrockBaseProtocol.INSTANCE);
|
@ -33,7 +33,6 @@
|
|||||||
"breaks": {
|
"breaks": {
|
||||||
"viafabric": "*",
|
"viafabric": "*",
|
||||||
"multiconnect": "*",
|
"multiconnect": "*",
|
||||||
"krypton": "*",
|
"krypton": "*"
|
||||||
"raknetify": "*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user