cleanup, close #125, fix #95

This commit is contained in:
creeper123123321 2021-05-14 20:25:49 -03:00
parent 105e64b11a
commit db97205169
41 changed files with 252 additions and 1272 deletions

View File

@ -10,7 +10,7 @@ plugins {
} }
def ENV = System.getenv() def ENV = System.getenv()
def vvVer = "4.0.0-21w19a" def vvVer = "4.0.0-21w19a-SNAPSHOT"
description = "Client-side and server-side ViaVersion implementation for Fabric" description = "Client-side and server-side ViaVersion implementation for Fabric"
version = "0.4.0+" + ENV.GITHUB_RUN_NUMBER + "-" + getBranch() version = "0.4.0+" + ENV.GITHUB_RUN_NUMBER + "-" + getBranch()

View File

@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1G -XX:+UseG1GC # rip my ram
org.gradle.jvmargs=-Xmx512M

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,14 +1,13 @@
package com.viaversion.fabric.mc18.handler; package com.viaversion.fabric.common.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException; import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelDecoderException; import com.viaversion.viaversion.exception.CancelDecoderException;
import com.viaversion.viaversion.util.PipelineUtil; import com.viaversion.viaversion.util.PipelineUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
@ -16,8 +15,6 @@ import java.util.List;
@ChannelHandler.Sharable @ChannelHandler.Sharable
public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> { public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info; private final UserConnection info;
private boolean handledCompression;
private boolean skipDoubleTransform;
public FabricDecodeHandler(UserConnection info) { public FabricDecodeHandler(UserConnection info) {
this.info = info; this.info = info;
@ -30,12 +27,6 @@ public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
// https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java // https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (skipDoubleTransform) {
skipDoubleTransform = false;
out.add(bytebuf.retain());
return;
}
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null); if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null);
if (!info.shouldTransformPacket()) { if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain()); out.add(bytebuf.retain());
@ -44,38 +35,25 @@ public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf); ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try { try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate); info.transformIncoming(transformedBuf, CancelDecoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
skipDoubleTransform = true;
}
out.add(transformedBuf.retain()); out.add(transformedBuf.retain());
} finally { } finally {
transformedBuf.release(); transformedBuf.release();
} }
} }
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException { private void reorder(ChannelHandlerContext ctx) {
if (handledCompression) return false;
int decoderIndex = ctx.pipeline().names().indexOf("decompress"); int decoderIndex = ctx.pipeline().names().indexOf("decompress");
if (decoderIndex == -1) return false; if (decoderIndex == -1) return;
handledCompression = true;
if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) { if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder"); ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder"); ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder); ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder); ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder); ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder); ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
} }
return false;
} }
@Override @Override
@ -83,4 +61,12 @@ public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
} }
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof PipelineReorderEvent) {
reorder(ctx);
}
super.userEventTriggered(ctx, evt);
}
} }

View File

@ -1,22 +1,19 @@
package com.viaversion.fabric.mc18.handler; package com.viaversion.fabric.common.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException; import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelEncoderException; import com.viaversion.viaversion.exception.CancelEncoderException;
import com.viaversion.viaversion.util.PipelineUtil; import com.viaversion.viaversion.util.PipelineUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
@ChannelHandler.Sharable @ChannelHandler.Sharable
public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> { public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
private final UserConnection info; private final UserConnection info;
private boolean handledCompression;
public FabricEncodeHandler(UserConnection info) { public FabricEncodeHandler(UserConnection info) {
this.info = info; this.info = info;
@ -32,39 +29,14 @@ public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf); ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try { try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformOutgoing(transformedBuf, CancelEncoderException::generate); info.transformOutgoing(transformedBuf, CancelEncoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
}
out.add(transformedBuf.retain()); out.add(transformedBuf.retain());
} finally { } finally {
transformedBuf.release(); transformedBuf.release();
} }
} }
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int encoderIndex = ctx.pipeline().names().indexOf("compress");
if (encoderIndex == -1) return false;
handledCompression = true;
if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;

View File

@ -0,0 +1,4 @@
package com.viaversion.fabric.common.handler;
public class PipelineReorderEvent {
}

View File

@ -0,0 +1,125 @@
package com.viaversion.fabric.common.provider;
import com.viaversion.fabric.common.platform.FabricViaAPI;
import com.viaversion.fabric.common.platform.FabricViaConfig;
import com.viaversion.fabric.common.util.JLoggerToLog4j;
import com.viaversion.viaversion.api.ViaAPI;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.libs.gson.JsonArray;
import com.viaversion.viaversion.libs.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.nio.file.Path;
import java.util.UUID;
import java.util.logging.Logger;
public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config;
private final File dataFolder;
private final ViaAPI<UUID> api;
{
Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric");
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
@Override
public boolean isProxy() {
return false;
}
@Override
public void onReload() {
}
@Override
public Logger getLogger() {
return logger;
}
@Override
public ViaVersionConfig getConf() {
return config;
}
@Override
public ViaAPI<UUID> getApi() {
return api;
}
@Override
public File getDataFolder() {
return dataFolder;
}
@Override
public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override
public String getPlatformName() {
return "ViaFabric";
}
@Override
public String getPlatformVersion() {
return FabricLoader.getInstance().getModContainer("viafabric")
.get().getMetadata().getVersion().getFriendlyString();
}
@Override
public boolean isPluginEnabled() {
return true;
}
@Override
public ConfigurationProvider getConfigurationProvider() {
return config;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
JsonArray mods = new JsonArray();
FabricLoader.getInstance().getAllMods().stream().map((mod) -> {
JsonObject jsonMod = new JsonObject();
jsonMod.addProperty("id", mod.getMetadata().getId());
jsonMod.addProperty("name", mod.getMetadata().getName());
jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString());
JsonArray authors = new JsonArray();
mod.getMetadata().getAuthors().stream().map(it -> {
JsonObject info = new JsonObject();
JsonObject contact = new JsonObject();
it.getContact().asMap().entrySet().stream()
.forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
info.add("contact", contact);
info.addProperty("name", it.getName());
return info;
}).forEach(authors::add);
jsonMod.add("authors", authors);
return jsonMod;
}).forEach(mods::add);
platformSpecific.add("mods", mods);
return platformSpecific;
}
}

View File

@ -25,6 +25,7 @@ public class ProtocolUtils {
Integer.parseInt(s + '0'); Integer.parseInt(s + '0');
return true; return true;
} catch (NumberFormatException e2) { } catch (NumberFormatException e2) {
if (ProtocolVersion.getClosest(s) != null) return true;
return ProtocolVersion.getProtocols().stream() return ProtocolVersion.getProtocols().stream()
.map(ProtocolVersion::getName) .map(ProtocolVersion::getName)
.flatMap(str -> Stream.concat( .flatMap(str -> Stream.concat(

View File

@ -1,86 +0,0 @@
package com.viaversion.fabric.mc114.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelDecoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
private boolean skipDoubleTransform;
public FabricDecodeHandler(UserConnection info) {
this.info = info;
}
public UserConnection getInfo() {
return info;
}
// https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (skipDoubleTransform) {
skipDoubleTransform = false;
out.add(bytebuf.retain());
return;
}
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
skipDoubleTransform = true;
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int decoderIndex = ctx.pipeline().names().indexOf("decompress");
if (decoderIndex == -1) return false;
handledCompression = true;
if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,73 +0,0 @@
package com.viaversion.fabric.mc114.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelEncoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
public FabricEncodeHandler(UserConnection info) {
this.info = info;
}
@Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (!info.checkOutgoingPacket()) throw CancelEncoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformOutgoing(transformedBuf, CancelEncoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int encoderIndex = ctx.pipeline().names().indexOf("compress");
if (encoderIndex == -1) return false;
handledCompression = true;
if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,7 +1,7 @@
package com.viaversion.fabric.mc114.mixin.debug.client; package com.viaversion.fabric.mc114.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc114.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;

View File

@ -1,12 +1,15 @@
package com.viaversion.fabric.mc114.mixin.pipeline; package com.viaversion.fabric.mc114.mixin.pipeline;
import com.viaversion.fabric.common.handler.PipelineReorderEvent;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
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;
@Mixin(ClientConnection.class) @Mixin(ClientConnection.class)
@ -28,4 +31,10 @@ public class MixinClientConnection {
logger.debug(message, t); logger.debug(message, t);
} }
} }
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
private void reorderCompression(int compressionThreshold, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent());
}
} }

View File

@ -1,8 +1,8 @@
package com.viaversion.fabric.mc114.mixin.pipeline; package com.viaversion.fabric.mc114.mixin.pipeline;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc114.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc114.handler.FabricEncodeHandler; import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel; import io.netty.channel.Channel;

View File

@ -1,9 +1,9 @@
package com.viaversion.fabric.mc114.mixin.pipeline.client; package com.viaversion.fabric.mc114.mixin.pipeline.client;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc114.ViaFabric; import com.viaversion.fabric.mc114.ViaFabric;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc114.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc114.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc114.handler.clientside.ProtocolDetectionHandler; import com.viaversion.fabric.mc114.handler.clientside.ProtocolDetectionHandler;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol; import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;

View File

@ -1,65 +1,34 @@
package com.viaversion.fabric.mc114.platform; package com.viaversion.fabric.mc114.platform;
import com.viaversion.fabric.common.platform.FabricViaAPI; import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.FabricViaConfig; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.mc114.ViaFabric; import com.viaversion.fabric.mc114.ViaFabric;
import com.viaversion.fabric.mc114.commands.NMSCommandSender; import com.viaversion.fabric.mc114.commands.NMSCommandSender;
import com.viaversion.fabric.common.commands.UserCommandSender; import com.viaversion.viaversion.api.Via;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.fabric.common.util.JLoggerToLog4j; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.network.MessageType; import net.minecraft.network.MessageType;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class FabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config;
private final File dataFolder;
private final ViaAPI<UUID> api;
public FabricPlatform() {
Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
public class FabricPlatform extends AbstractFabricPlatform {
public static MinecraftServer getServer() { public static MinecraftServer getServer() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getIntegratedServer(); return getIntegratedServer();
@ -76,27 +45,6 @@ public class FabricPlatform implements ViaPlatform<UUID> {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
} }
@Override
public Logger getLogger() {
return logger;
}
@Override
public String getPlatformName() {
return "ViaFabric";
}
@Override
public String getPlatformVersion() {
return ViaFabric.getVersion();
}
@Override
public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override @Override
public FutureTaskId runAsync(Runnable runnable) { public FutureTaskId runAsync(Runnable runnable) {
return new FutureTaskId(CompletableFuture return new FutureTaskId(CompletableFuture
@ -215,59 +163,4 @@ public class FabricPlatform implements ViaPlatform<UUID> {
} }
return false; // Can't know if it worked return false; // Can't know if it worked
} }
@Override
public boolean isPluginEnabled() {
return true;
}
@Override
public ViaAPI<UUID> getApi() {
return api;
}
@Override
public ViaVersionConfig getConf() {
return config;
}
@Override
public ConfigurationProvider getConfigurationProvider() {
return config;
}
@Override
public File getDataFolder() {
return dataFolder;
}
@Override
public void onReload() {
// Nothing to do
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> mods = new ArrayList<>();
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
mods.add(new PluginInfo(true,
mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")",
mod.getMetadata().getVersion().getFriendlyString(),
null,
mod.getMetadata().getAuthors().stream()
.map(info -> info.getName()
+ (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap()))
.collect(Collectors.toList())
));
}
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
return platformSpecific;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
} }

View File

@ -1,86 +0,0 @@
package com.viaversion.fabric.mc115.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelDecoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
private boolean skipDoubleTransform;
public FabricDecodeHandler(UserConnection info) {
this.info = info;
}
public UserConnection getInfo() {
return info;
}
// https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (skipDoubleTransform) {
skipDoubleTransform = false;
out.add(bytebuf.retain());
return;
}
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
skipDoubleTransform = true;
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int decoderIndex = ctx.pipeline().names().indexOf("decompress");
if (decoderIndex == -1) return false;
handledCompression = true;
if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,73 +0,0 @@
package com.viaversion.fabric.mc115.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelEncoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
public FabricEncodeHandler(UserConnection info) {
this.info = info;
}
@Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (!info.checkOutgoingPacket()) throw CancelEncoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformOutgoing(transformedBuf, CancelEncoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int encoderIndex = ctx.pipeline().names().indexOf("compress");
if (encoderIndex == -1) return false;
handledCompression = true;
if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,7 +1,7 @@
package com.viaversion.fabric.mc115.mixin.debug.client; package com.viaversion.fabric.mc115.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc115.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;

View File

@ -1,12 +1,15 @@
package com.viaversion.fabric.mc115.mixin.pipeline; package com.viaversion.fabric.mc115.mixin.pipeline;
import com.viaversion.fabric.common.handler.PipelineReorderEvent;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
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;
@Mixin(ClientConnection.class) @Mixin(ClientConnection.class)
@ -28,4 +31,9 @@ public class MixinClientConnection {
logger.debug(message, t); logger.debug(message, t);
} }
} }
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
private void reorderCompression(int compressionThreshold, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent());
}
} }

View File

@ -1,8 +1,8 @@
package com.viaversion.fabric.mc115.mixin.pipeline; package com.viaversion.fabric.mc115.mixin.pipeline;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc115.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc115.handler.FabricEncodeHandler; import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel; import io.netty.channel.Channel;

View File

@ -1,9 +1,9 @@
package com.viaversion.fabric.mc115.mixin.pipeline.client; package com.viaversion.fabric.mc115.mixin.pipeline.client;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc115.ViaFabric; import com.viaversion.fabric.mc115.ViaFabric;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc115.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc115.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc115.handler.clientside.ProtocolDetectionHandler; import com.viaversion.fabric.mc115.handler.clientside.ProtocolDetectionHandler;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol; import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;

View File

@ -3,6 +3,7 @@ package com.viaversion.fabric.mc115.platform;
import com.viaversion.fabric.common.commands.UserCommandSender; import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.FabricViaAPI; import com.viaversion.fabric.common.platform.FabricViaAPI;
import com.viaversion.fabric.common.platform.FabricViaConfig; import com.viaversion.fabric.common.platform.FabricViaConfig;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.JLoggerToLog4j; import com.viaversion.fabric.common.util.JLoggerToLog4j;
import com.viaversion.fabric.mc115.ViaFabric; import com.viaversion.fabric.mc115.ViaFabric;
@ -47,19 +48,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class FabricPlatform implements ViaPlatform<UUID> { public class FabricPlatform extends AbstractFabricPlatform {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config;
private final File dataFolder;
private final ViaAPI<UUID> api;
public FabricPlatform() {
Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
public static MinecraftServer getServer() { public static MinecraftServer getServer() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getIntegratedServer(); return getIntegratedServer();
@ -76,27 +65,6 @@ public class FabricPlatform implements ViaPlatform<UUID> {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
} }
@Override
public Logger getLogger() {
return logger;
}
@Override
public String getPlatformName() {
return "ViaFabric";
}
@Override
public String getPlatformVersion() {
return ViaFabric.getVersion();
}
@Override
public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override @Override
public FutureTaskId runAsync(Runnable runnable) { public FutureTaskId runAsync(Runnable runnable) {
return new FutureTaskId(CompletableFuture return new FutureTaskId(CompletableFuture
@ -215,59 +183,4 @@ public class FabricPlatform implements ViaPlatform<UUID> {
} }
return false; // Can't know if it worked return false; // Can't know if it worked
} }
@Override
public boolean isPluginEnabled() {
return true;
}
@Override
public ViaAPI<UUID> getApi() {
return api;
}
@Override
public ViaVersionConfig getConf() {
return config;
}
@Override
public ConfigurationProvider getConfigurationProvider() {
return config;
}
@Override
public File getDataFolder() {
return dataFolder;
}
@Override
public void onReload() {
// Nothing to do
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> mods = new ArrayList<>();
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
mods.add(new PluginInfo(true,
mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")",
mod.getMetadata().getVersion().getFriendlyString(),
null,
mod.getMetadata().getAuthors().stream()
.map(info -> info.getName()
+ (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap()))
.collect(Collectors.toList())
));
}
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
return platformSpecific;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
} }

View File

@ -1,86 +0,0 @@
package com.viaversion.fabric.mc116.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelDecoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
private boolean skipDoubleTransform;
public FabricDecodeHandler(UserConnection info) {
this.info = info;
}
public UserConnection getInfo() {
return info;
}
// https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (skipDoubleTransform) {
skipDoubleTransform = false;
out.add(bytebuf.retain());
return;
}
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
skipDoubleTransform = true;
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int decoderIndex = ctx.pipeline().names().indexOf("decompress");
if (decoderIndex == -1) return false;
handledCompression = true;
if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,73 +0,0 @@
package com.viaversion.fabric.mc116.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelEncoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
public FabricEncodeHandler(UserConnection info) {
this.info = info;
}
@Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (!info.checkOutgoingPacket()) throw CancelEncoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformOutgoing(transformedBuf, CancelEncoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int encoderIndex = ctx.pipeline().names().indexOf("compress");
if (encoderIndex == -1) return false;
handledCompression = true;
if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,7 +1,7 @@
package com.viaversion.fabric.mc116.mixin.debug.client; package com.viaversion.fabric.mc116.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc116.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;

View File

@ -1,12 +1,15 @@
package com.viaversion.fabric.mc116.mixin.pipeline; package com.viaversion.fabric.mc116.mixin.pipeline;
import com.viaversion.fabric.common.handler.PipelineReorderEvent;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
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;
@Mixin(ClientConnection.class) @Mixin(ClientConnection.class)
@ -28,4 +31,9 @@ public class MixinClientConnection {
logger.debug(message, t); logger.debug(message, t);
} }
} }
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
private void reorderCompression(int compressionThreshold, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent());
}
} }

View File

@ -1,8 +1,8 @@
package com.viaversion.fabric.mc116.mixin.pipeline; package com.viaversion.fabric.mc116.mixin.pipeline;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc116.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc116.handler.FabricEncodeHandler; import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel; import io.netty.channel.Channel;

View File

@ -1,9 +1,9 @@
package com.viaversion.fabric.mc116.mixin.pipeline.client; package com.viaversion.fabric.mc116.mixin.pipeline.client;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc116.ViaFabric; import com.viaversion.fabric.mc116.ViaFabric;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc116.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc116.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc116.handler.clientside.ProtocolDetectionHandler; import com.viaversion.fabric.mc116.handler.clientside.ProtocolDetectionHandler;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol; import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;

View File

@ -1,64 +1,33 @@
package com.viaversion.fabric.mc116.platform; package com.viaversion.fabric.mc116.platform;
import com.viaversion.fabric.common.platform.FabricViaAPI; import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.FabricViaConfig; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.mc116.ViaFabric; import com.viaversion.fabric.mc116.ViaFabric;
import com.viaversion.fabric.mc116.commands.NMSCommandSender; import com.viaversion.fabric.mc116.commands.NMSCommandSender;
import com.viaversion.fabric.common.commands.UserCommandSender; import com.viaversion.viaversion.api.Via;
import com.viaversion.fabric.common.util.JLoggerToLog4j; import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class FabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config;
private final File dataFolder;
private final ViaAPI<UUID> api;
public FabricPlatform() {
Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
public class FabricPlatform extends AbstractFabricPlatform {
public static MinecraftServer getServer() { public static MinecraftServer getServer() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getIntegratedServer(); return getIntegratedServer();
@ -75,27 +44,6 @@ public class FabricPlatform implements ViaPlatform<UUID> {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
} }
@Override
public Logger getLogger() {
return logger;
}
@Override
public String getPlatformName() {
return "ViaFabric";
}
@Override
public String getPlatformVersion() {
return ViaFabric.getVersion();
}
@Override
public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override @Override
public FutureTaskId runAsync(Runnable runnable) { public FutureTaskId runAsync(Runnable runnable) {
return new FutureTaskId(CompletableFuture return new FutureTaskId(CompletableFuture
@ -216,59 +164,4 @@ public class FabricPlatform implements ViaPlatform<UUID> {
} }
return false; // Can't know if it worked return false; // Can't know if it worked
} }
@Override
public boolean isPluginEnabled() {
return true;
}
@Override
public ViaAPI<UUID> getApi() {
return api;
}
@Override
public ViaVersionConfig getConf() {
return config;
}
@Override
public ConfigurationProvider getConfigurationProvider() {
return config;
}
@Override
public File getDataFolder() {
return dataFolder;
}
@Override
public void onReload() {
// Nothing to do
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> mods = new ArrayList<>();
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
mods.add(new PluginInfo(true,
mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")",
mod.getMetadata().getVersion().getFriendlyString(),
null,
mod.getMetadata().getAuthors().stream()
.map(info -> info.getName()
+ (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap()))
.collect(Collectors.toList())
));
}
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
return platformSpecific;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
} }

View File

@ -1,86 +0,0 @@
package com.viaversion.fabric.mc117.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelDecoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
private boolean skipDoubleTransform;
public FabricDecodeHandler(UserConnection info) {
this.info = info;
}
public UserConnection getInfo() {
return info;
}
// https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (skipDoubleTransform) {
skipDoubleTransform = false;
out.add(bytebuf.retain());
return;
}
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformIncoming(transformedBuf, CancelDecoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
skipDoubleTransform = true;
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int decoderIndex = ctx.pipeline().names().indexOf("decompress");
if (decoderIndex == -1) return false;
handledCompression = true;
if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,73 +0,0 @@
package com.viaversion.fabric.mc117.handler;
import com.viaversion.fabric.common.handler.CommonTransformer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.exception.CancelCodecException;
import com.viaversion.viaversion.exception.CancelEncoderException;
import com.viaversion.viaversion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ChannelHandler.Sharable
public class FabricEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
private final UserConnection info;
private boolean handledCompression;
public FabricEncodeHandler(UserConnection info) {
this.info = info;
}
@Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (!info.checkOutgoingPacket()) throw CancelEncoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
return;
}
ByteBuf transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf);
try {
boolean needsCompress = handleCompressionOrder(ctx, transformedBuf);
info.transformOutgoing(transformedBuf, CancelEncoderException::generate);
if (needsCompress) {
CommonTransformer.compress(ctx, transformedBuf);
}
out.add(transformedBuf.retain());
} finally {
transformedBuf.release();
}
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
if (handledCompression) return false;
int encoderIndex = ctx.pipeline().names().indexOf("compress");
if (encoderIndex == -1) return false;
handledCompression = true;
if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) {
// Need to decompress this packet due to bad order
CommonTransformer.decompress(ctx, buf);
ChannelHandler encoder = ctx.pipeline().get("via-encoder");
ChannelHandler decoder = ctx.pipeline().get("via-decoder");
ctx.pipeline().remove(encoder);
ctx.pipeline().remove(decoder);
ctx.pipeline().addAfter("compress", "via-encoder", encoder);
ctx.pipeline().addAfter("decompress", "via-decoder", decoder);
return true;
}
return false;
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

View File

@ -1,7 +1,7 @@
package com.viaversion.fabric.mc117.mixin.debug.client; package com.viaversion.fabric.mc117.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc117.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;

View File

@ -1,12 +1,15 @@
package com.viaversion.fabric.mc117.mixin.pipeline; package com.viaversion.fabric.mc117.mixin.pipeline;
import com.viaversion.fabric.common.handler.PipelineReorderEvent;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
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;
@Mixin(ClientConnection.class) @Mixin(ClientConnection.class)
@ -28,4 +31,9 @@ public class MixinClientConnection {
logger.debug(message, t); logger.debug(message, t);
} }
} }
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
private void reorderCompression(int compressionThreshold, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent());
}
} }

View File

@ -1,8 +1,8 @@
package com.viaversion.fabric.mc117.mixin.pipeline; package com.viaversion.fabric.mc117.mixin.pipeline;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc117.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc117.handler.FabricEncodeHandler; import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel; import io.netty.channel.Channel;

View File

@ -1,9 +1,9 @@
package com.viaversion.fabric.mc117.mixin.pipeline.client; package com.viaversion.fabric.mc117.mixin.pipeline.client;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc117.ViaFabric; import com.viaversion.fabric.mc117.ViaFabric;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc117.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc117.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc117.handler.clientside.ProtocolDetectionHandler; import com.viaversion.fabric.mc117.handler.clientside.ProtocolDetectionHandler;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol; import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;

View File

@ -1,64 +1,33 @@
package com.viaversion.fabric.mc117.platform; package com.viaversion.fabric.mc117.platform;
import com.viaversion.fabric.common.platform.FabricViaAPI; import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.FabricViaConfig; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.mc117.ViaFabric; import com.viaversion.fabric.mc117.ViaFabric;
import com.viaversion.fabric.mc117.commands.NMSCommandSender; import com.viaversion.fabric.mc117.commands.NMSCommandSender;
import com.viaversion.fabric.common.commands.UserCommandSender; import com.viaversion.viaversion.api.Via;
import com.viaversion.fabric.common.util.JLoggerToLog4j; import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class FabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config;
private final File dataFolder;
private final ViaAPI<UUID> api;
public FabricPlatform() {
Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
public class FabricPlatform extends AbstractFabricPlatform {
public static MinecraftServer getServer() { public static MinecraftServer getServer() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getIntegratedServer(); return getIntegratedServer();
@ -75,27 +44,6 @@ public class FabricPlatform implements ViaPlatform<UUID> {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
} }
@Override
public Logger getLogger() {
return logger;
}
@Override
public String getPlatformName() {
return "ViaFabric";
}
@Override
public String getPlatformVersion() {
return ViaFabric.getVersion();
}
@Override
public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override @Override
public FutureTaskId runAsync(Runnable runnable) { public FutureTaskId runAsync(Runnable runnable) {
return new FutureTaskId(CompletableFuture return new FutureTaskId(CompletableFuture
@ -216,59 +164,4 @@ public class FabricPlatform implements ViaPlatform<UUID> {
} }
return false; // Can't know if it worked return false; // Can't know if it worked
} }
@Override
public boolean isPluginEnabled() {
return true;
}
@Override
public ViaAPI<UUID> getApi() {
return api;
}
@Override
public ViaVersionConfig getConf() {
return config;
}
@Override
public ConfigurationProvider getConfigurationProvider() {
return config;
}
@Override
public File getDataFolder() {
return dataFolder;
}
@Override
public void onReload() {
// Nothing to do
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> mods = new ArrayList<>();
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
mods.add(new PluginInfo(true,
mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")",
mod.getMetadata().getVersion().getFriendlyString(),
null,
mod.getMetadata().getAuthors().stream()
.map(info -> info.getName()
+ (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap()))
.collect(Collectors.toList())
));
}
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
return platformSpecific;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
} }

View File

@ -1,7 +1,7 @@
package com.viaversion.fabric.mc18.mixin.debug.client; package com.viaversion.fabric.mc18.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc18.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.ProtocolInfo;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;

View File

@ -1,15 +1,24 @@
package com.viaversion.fabric.mc18.mixin.pipeline; package com.viaversion.fabric.mc18.mixin.pipeline;
import com.viaversion.fabric.common.handler.PipelineReorderEvent;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientConnection.class) @Mixin(ClientConnection.class)
public class MixinClientConnection { public class MixinClientConnection {
@Shadow @Shadow
private Channel channel; private Channel channel;
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
private void reorderCompression(int compressionThreshold, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent());
}
/* /*
@Redirect( @Redirect(
method = "exceptionCaught", method = "exceptionCaught",

View File

@ -1,8 +1,8 @@
package com.viaversion.fabric.mc18.mixin.pipeline; package com.viaversion.fabric.mc18.mixin.pipeline;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc18.handler.FabricDecodeHandler; import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc18.handler.FabricEncodeHandler; import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel; import io.netty.channel.Channel;

View File

@ -1,9 +1,9 @@
package com.viaversion.fabric.mc18.mixin.pipeline.client; package com.viaversion.fabric.mc18.mixin.pipeline.client;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc18.ViaFabric; import com.viaversion.fabric.mc18.ViaFabric;
import com.viaversion.fabric.common.handler.CommonTransformer; import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.mc18.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc18.handler.FabricEncodeHandler;
import com.viaversion.fabric.mc18.handler.clientside.ProtocolDetectionHandler; import com.viaversion.fabric.mc18.handler.clientside.ProtocolDetectionHandler;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol; import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;

View File

@ -1,40 +1,23 @@
package com.viaversion.fabric.mc18.platform; package com.viaversion.fabric.mc18.platform;
import com.viaversion.fabric.common.platform.FabricViaAPI; import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.FabricViaConfig; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.mc18.ViaFabric; import com.viaversion.fabric.mc18.ViaFabric;
import com.viaversion.fabric.mc18.commands.NMSCommandSender; import com.viaversion.fabric.mc18.commands.NMSCommandSender;
import com.viaversion.fabric.common.commands.UserCommandSender; import com.viaversion.viaversion.api.Via;
import com.viaversion.fabric.common.util.JLoggerToLog4j; import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
@ -42,22 +25,8 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class FabricPlatform implements ViaPlatform<UUID> {
private final Logger logger = new JLoggerToLog4j(LogManager.getLogger("ViaVersion"));
private final FabricViaConfig config;
private final File dataFolder;
private final ViaAPI<UUID> api;
public FabricPlatform() {
Path configDir = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric");
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
dataFolder = configDir.toFile();
api = new FabricViaAPI();
}
public class FabricPlatform extends AbstractFabricPlatform {
public static MinecraftServer getServer() { public static MinecraftServer getServer() {
// In 1.8.9 integrated server instance exists even if it's not running // In 1.8.9 integrated server instance exists even if it's not running
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
@ -69,27 +38,6 @@ public class FabricPlatform implements ViaPlatform<UUID> {
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy)); return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
} }
@Override
public Logger getLogger() {
return logger;
}
@Override
public String getPlatformName() {
return "ViaFabric";
}
@Override
public String getPlatformVersion() {
return ViaFabric.getVersion();
}
@Override
public String getPluginVersion() {
return FabricLoader.getInstance().getModContainer("viaversion").map(ModContainer::getMetadata)
.map(ModMetadata::getVersion).map(Version::getFriendlyString).orElse("UNKNOWN");
}
@Override @Override
public FutureTaskId runAsync(Runnable runnable) { public FutureTaskId runAsync(Runnable runnable) {
return new FutureTaskId(CompletableFuture return new FutureTaskId(CompletableFuture
@ -210,59 +158,4 @@ public class FabricPlatform implements ViaPlatform<UUID> {
} }
return false; // Can't know if it worked return false; // Can't know if it worked
} }
@Override
public boolean isPluginEnabled() {
return true;
}
@Override
public ViaAPI<UUID> getApi() {
return api;
}
@Override
public ViaVersionConfig getConf() {
return config;
}
@Override
public ConfigurationProvider getConfigurationProvider() {
return config;
}
@Override
public File getDataFolder() {
return dataFolder;
}
@Override
public void onReload() {
// Nothing to do
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> mods = new ArrayList<>();
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
mods.add(new PluginInfo(true,
mod.getMetadata().getId() + " (" + mod.getMetadata().getName() + ")",
mod.getMetadata().getVersion().getFriendlyString(),
null,
mod.getMetadata().getAuthors().stream()
.map(info -> info.getName()
+ (info.getContact().asMap().isEmpty() ? "" : " " + info.getContact().asMap()))
.collect(Collectors.toList())
));
}
platformSpecific.add("mods", GsonUtil.getGson().toJsonTree(mods));
return platformSpecific;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
} }