mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-15 10:45:35 +01:00
fixed mixin crash, implemented legacy srv handling in <= 1.3
This commit is contained in:
parent
63b0eb40b2
commit
e42e7e0b87
@ -1,5 +1,6 @@
|
||||
package de.florianmichael.viafabricplus;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
@ -88,6 +89,8 @@ public class ViaFabricPlus {
|
||||
providers.use(EncryptionProvider.class, new ViaFabricPlusEncryptionProvider());
|
||||
providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher());
|
||||
providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider());
|
||||
|
||||
Via.getManager().setDebug(true);
|
||||
});
|
||||
builder = builder.onProtocolReload(protocolVersion -> {
|
||||
FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(viaFabricPlusAddon -> viaFabricPlusAddon.onChangeVersion(protocolVersion));
|
||||
|
@ -5,6 +5,8 @@ import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.platform.PreNettyConstants;
|
||||
import de.florianmichael.viafabricplus.platform.VFPPreNettyDecoder;
|
||||
import de.florianmichael.viafabricplus.platform.VFPPreNettyEncoder;
|
||||
import de.florianmichael.viafabricplus.platform.VFPVLBViaDecodeHandler;
|
||||
import de.florianmichael.vialoadingbase.ViaLoadingBase;
|
||||
import de.florianmichael.vialoadingbase.netty.VLBViaEncodeHandler;
|
||||
@ -13,8 +15,6 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import net.raphimc.vialegacy.netty.PreNettyDecoder;
|
||||
import net.raphimc.vialegacy.netty.PreNettyEncoder;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.baseprotocols.PreNettyBaseProtocol;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -45,8 +45,8 @@ public class MixinClientConnection_1 {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
|
||||
user.getProtocolInfo().getPipeline().add(PreNettyBaseProtocol.INSTANCE);
|
||||
|
||||
channel.pipeline().addBefore("prepender", PreNettyConstants.HANDLER_ENCODER_NAME, new PreNettyEncoder(user));
|
||||
channel.pipeline().addBefore("splitter", PreNettyConstants.HANDLER_DECODER_NAME, new PreNettyDecoder(user));
|
||||
channel.pipeline().addBefore("prepender", PreNettyConstants.HANDLER_ENCODER_NAME, new VFPPreNettyEncoder(user));
|
||||
channel.pipeline().addBefore("splitter", PreNettyConstants.HANDLER_DECODER_NAME, new VFPPreNettyDecoder(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,14 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.vialoadingbase.ViaLoadingBase;
|
||||
import de.florianmichael.vialoadingbase.platform.ProtocolRange;
|
||||
import net.minecraft.client.network.AllowedAddressResolver;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@ -16,9 +19,12 @@ public class MixinServerAddress {
|
||||
|
||||
@Shadow @Final private static ServerAddress INVALID;
|
||||
|
||||
@Unique
|
||||
private final static ProtocolRange viafabricplus_srvRange = new ProtocolRange(ProtocolVersion.v1_16_4, LegacyProtocolVersion.r1_3_1tor1_3_2);
|
||||
|
||||
@Inject(method = "parse", at = @At("RETURN"), cancellable = true)
|
||||
private static void fixAddress(String address, CallbackInfoReturnable<ServerAddress> cir) {
|
||||
if (!cir.getReturnValue().equals(INVALID) && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_16_4)) {
|
||||
if (!cir.getReturnValue().equals(INVALID) && viafabricplus_srvRange.contains(ViaLoadingBase.getClassWrapper().getTargetVersion())) {
|
||||
cir.setReturnValue(AllowedAddressResolver.DEFAULT.redirectResolver.lookupRedirect(cir.getReturnValue()).orElse(cir.getReturnValue()));
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class MixinConnectScreen_1 {
|
||||
|
||||
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetSocketAddress;getHostName()Ljava/lang/String;", ordinal = 1))
|
||||
public String replaceAddress(InetSocketAddress instance) {
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_17)) return field_33737.getAddress();
|
||||
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_17)) return field_33737.getAddress().replace(".", "");
|
||||
|
||||
return instance.getHostString();
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion.protocol1_13to1_12_2;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler;
|
||||
import de.florianmichael.viafabricplus.settings.groups.DebugSettings;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -16,7 +18,7 @@ import java.util.List;
|
||||
public class MixinConnectionData_NeighbourUpdater {
|
||||
|
||||
@Inject(method = "updateBlock", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void preventBlockSpam(int x, int y, int z, List<BlockChangeRecord1_8> records, CallbackInfo ci, int blockState, int newBlockState) {
|
||||
public void preventBlockSpam(int x, int y, int z, List<BlockChangeRecord1_8> records, CallbackInfo ci, int blockState, ConnectionHandler handler, Position position, int newBlockState) {
|
||||
if (!DebugSettings.getClassWrapper().cancelEqualBlockChangeUpdates.getValue()) return;
|
||||
if (blockState == newBlockState) ci.cancel();
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package de.florianmichael.viafabricplus.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.raphimc.vialegacy.netty.PreNettyDecoder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VFPPreNettyDecoder extends PreNettyDecoder {
|
||||
|
||||
public VFPPreNettyDecoder(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
if (!in.isReadable() || in.readableBytes() <= 0) {
|
||||
return;
|
||||
}
|
||||
Via.getPlatform().getLogger().info("Decoding pre netty packet: " + in.copy().readUnsignedByte());
|
||||
}
|
||||
super.decode(ctx, in, out);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package de.florianmichael.viafabricplus.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.raphimc.vialegacy.netty.PreNettyEncoder;
|
||||
|
||||
public class VFPPreNettyEncoder extends PreNettyEncoder {
|
||||
|
||||
public VFPPreNettyEncoder(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
final ByteBuf myBuf = in.copy();
|
||||
Type.VAR_INT.readPrimitive(myBuf); // length
|
||||
Via.getPlatform().getLogger().info("Encoding pre netty packet: " + (Type.VAR_INT.readPrimitive(myBuf) & 255));
|
||||
}
|
||||
super.encode(ctx, in, out);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user