Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenni0451 committed Jul 25, 2024
2 parents db98613 + 703f3f5 commit 0e35235
Show file tree
Hide file tree
Showing 18 changed files with 411 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For a full user guide go to the [Usage for Players](#usage-for-players-gui) sect
- Classic (c0.0.15 - c0.30 including [CPE](https://wiki.vg/Classic_Protocol_Extension))
- April Fools (3D Shareware, 20w14infinite)
- Combat Snapshots (Combat Test 8c)
- Bedrock Edition 1.21.0 ([Some features are missing](https://github.com/RaphiMC/ViaBedrock#features))
- Bedrock Edition 1.21.2 ([Some features are missing](https://github.com/RaphiMC/ViaBedrock#features))

## Supported Client versions
- Release (1.7.2 - 1.21)
Expand Down
23 changes: 12 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id "maven-publish"
id "idea"
id "net.raphimc.class-token-replacer" version "1.1.2"
id "xyz.wagyourtail.jvmdowngrader" version "0.7.2"
id "xyz.wagyourtail.jvmdowngrader" version "0.9.1"
}

base {
Expand Down Expand Up @@ -55,10 +55,10 @@ repositories {
dependencies {
include "com.viaversion:viaversion-common:5.0.2-SNAPSHOT"
include "com.viaversion:viabackwards-common:5.0.2-SNAPSHOT"
include "com.viaversion:viarewind-common:4.0.1-SNAPSHOT"
include "com.viaversion:viarewind-common:4.0.2-SNAPSHOT"
include "net.raphimc:ViaLegacy:3.0.2-SNAPSHOT"
include "net.raphimc:ViaAprilFools:3.0.1-SNAPSHOT"
include("net.raphimc:ViaBedrock:0.0.9-SNAPSHOT") {
include "net.raphimc:viaaprilfools-common:3.0.1-SNAPSHOT"
include("net.raphimc:ViaBedrock:0.0.10-SNAPSHOT") {
exclude group: "io.netty"
exclude group: "io.jsonwebtoken"
}
Expand All @@ -67,9 +67,9 @@ dependencies {
}

include "com.google.code.gson:gson:2.11.0"
include "com.formdev:flatlaf:3.4.1"
include "com.formdev:flatlaf-extras:3.4.1"
include "org.apache.commons:commons-lang3:3.14.0"
include "com.formdev:flatlaf:3.5"
include "com.formdev:flatlaf-extras:3.5"
include "org.apache.commons:commons-lang3:3.15.0"
include "commons-io:commons-io:2.16.1"
include "net.sf.jopt-simple:jopt-simple:5.0.4"
include "org.apache.logging.log4j:log4j-core:2.23.1"
Expand All @@ -87,10 +87,10 @@ dependencies {
exclude group: "com.google.code.gson", module: "gson"
}
include "net.lenni0451.commons:swing:1.5.1"
include("net.raphimc.netminecraft:all:2.5.0") {
include("net.raphimc.netminecraft:all:2.5.1-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
}
include("net.raphimc:MinecraftAuth:4.0.3-SNAPSHOT") {
include("net.raphimc:MinecraftAuth:4.1.0") {
exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api"
}
Expand All @@ -99,8 +99,8 @@ dependencies {
}
include "gs.mclo:api:3.0.1"

includeJ8(compileOnly("xyz.wagyourtail.jvmdowngrader:jvmdowngrader:0.7.2"))
includeJ8 "xyz.wagyourtail.jvmdowngrader:jvmdowngrader-java-api:0.7.2:downgraded-8"
includeJ8(compileOnly("xyz.wagyourtail.jvmdowngrader:jvmdowngrader:0.9.1"))
includeJ8 "xyz.wagyourtail.jvmdowngrader:jvmdowngrader-java-api:0.9.1:downgraded-8"
}

sourceSets {
Expand Down Expand Up @@ -209,6 +209,7 @@ downgradeJar {
}

downgradeTo = JavaVersion.VERSION_1_8
ignoreWarningsIn.add("net/lenni0451/commons/httpclient/executor/HttpClientExecutor")
archiveClassifier = null
archiveVersion = project.version + "+java8"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/raphimc/viaproxy/ViaProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public static void injectedMain(final String injectionMethod, final String[] arg
final boolean useCLI = args.length > 0 && args[0].equals("cli");

final List<File> potentialCwds = new ArrayList<>();
if (System.getenv("VP_RUN_DIR") != null) {
potentialCwds.add(new File(System.getenv("VP_RUN_DIR")));
}
potentialCwds.add(new File(System.getProperty("user.dir")));
potentialCwds.add(new File("."));
JarUtil.getJarFile().map(File::getParentFile).ifPresent(potentialCwds::add);
Expand All @@ -137,7 +140,12 @@ public static void injectedMain(final String injectionMethod, final String[] arg
JOptionPane.showMessageDialog(null, "Could not find a suitable directory to use as working directory. Make sure that the current folder is writeable.", "ViaProxy", JOptionPane.ERROR_MESSAGE);
System.exit(1);
} else {
throw new IllegalStateException("Could not find a suitable directory to use as working directory. Make sure that the current folder is writeable.");
System.err.println("Could not find a suitable directory to use as working directory. Make sure that the current folder is writeable.");
System.err.println("Attempted to use the following directories:");
for (File failedCwd : failedCwds) {
System.err.println("\t- " + failedCwd.getAbsolutePath());
}
System.exit(1);
}

Logger.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.FoodEffect;
import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties;
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
import com.viaversion.viaversion.api.minecraft.item.data.ToolRule;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
Expand All @@ -46,8 +44,8 @@
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.*;

Expand All @@ -60,9 +58,6 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
@Unique
private final Map<String, Integer> armorMaxDamage_b1_8_1 = new HashMap<>();

@Unique
private final Set<String> swordItems1_8 = new HashSet<>();

@Unique
private final Map<ProtocolVersion, Map<String, ToolProperties>> toolDataChanges = new LinkedHashMap<>();

Expand All @@ -84,17 +79,9 @@ public void loadItemMappings(Protocol1_20_3To1_20_5 protocol, CallbackInfo ci) {

final JsonObject armorMaxDamages = ViaProxyMappingDataLoader.INSTANCE.loadData("armor-damages-b1.8.1.json");
for (Map.Entry<String, JsonElement> entry : armorMaxDamages.entrySet()) {
final String item = entry.getKey();
final int maxDamage = entry.getValue().getAsInt();
this.armorMaxDamage_b1_8_1.put(item, maxDamage);
this.armorMaxDamage_b1_8_1.put(entry.getKey(), entry.getValue().getAsInt());
}

this.swordItems1_8.add("minecraft:wooden_sword");
this.swordItems1_8.add("minecraft:stone_sword");
this.swordItems1_8.add("minecraft:iron_sword");
this.swordItems1_8.add("minecraft:golden_sword");
this.swordItems1_8.add("minecraft:diamond_sword");

ViaProxy.EVENT_MANAGER.registerRunnable(() -> {
final JsonObject itemToolComponents = ViaProxyMappingDataLoader.INSTANCE.loadData("item-tool-components.json");
for (Map.Entry<String, JsonElement> entry : itemToolComponents.entrySet()) {
Expand Down Expand Up @@ -128,25 +115,26 @@ public void loadItemMappings(Protocol1_20_3To1_20_5 protocol, CallbackInfo ci) {
}, ViaLoadingEvent.class);
}

@Inject(method = "toStructuredItem", at = @At("RETURN"))
private void appendItemDataFixComponents(UserConnection user, Item old, CallbackInfoReturnable<Item> cir) {
final StructuredDataContainer data = cir.getReturnValue().dataContainer();
final String identifier = this.protocol.getMappingData().getFullItemMappings().identifier(cir.getReturnValue().identifier());
if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_17_1)) {
if (identifier.equals("minecraft:crossbow")) {
data.set(StructuredDataKey.MAX_DAMAGE, 326);
}
}
if (user.getProtocolInfo().serverProtocolVersion().betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8)) {
if (this.swordItems1_8.contains(identifier)) {
data.set(StructuredDataKey.FOOD1_20_5, new FoodProperties(0, 0F, true, 3600, null, new FoodEffect[0]));
}
@Redirect(method = "appendItemDataFixComponents", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;olderThanOrEqualTo(Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;)Z"))
private boolean changeSwordFixVersionRange(ProtocolVersion instance, ProtocolVersion other) {
if (other == ProtocolVersion.v1_8) {
return instance.betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8);
} else {
return instance.olderThanOrEqualTo(other);
}
}

@Inject(method = "appendItemDataFixComponents", at = @At("RETURN"))
private void appendItemDataFixComponents(UserConnection user, Item item, CallbackInfo ci) {
final StructuredDataContainer data = item.dataContainer();
final String identifier = this.protocol.getMappingData().getFullItemMappings().identifier(item.identifier());

if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
if (this.armorMaxDamage_b1_8_1.containsKey(identifier)) {
data.set(StructuredDataKey.MAX_DAMAGE, this.armorMaxDamage_b1_8_1.get(identifier));
}
}

if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) {
if (this.foodItems_b1_7_3.contains(identifier)) {
data.set(StructuredDataKey.MAX_STACK_SIZE, 1);
Expand Down Expand Up @@ -180,8 +168,10 @@ private int[] blockJsonArrayToIds(final ProtocolVersion protocolVersion, final J
}
}
}
} else if (name.startsWith("-")) { // Block name
ids.remove(this.protocol.getMappingData().blockId(name.substring(1)));
} else { // Block name
ids.add(this.protocol.getMappingData().blockId(element.getAsString()));
ids.add(this.protocol.getMappingData().blockId(name));
}
}
return ids.toIntArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
@Mixin(value = EntityTracker1_9.class, remap = false)
public abstract class MixinEntityTracker1_9 {

@Redirect(method = "handleMetadata", at = @At(value = "INVOKE", target = "Ljava/lang/Math;min(FF)F"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
@Redirect(method = "handleEntityData", at = @At(value = "INVOKE", target = "Ljava/lang/Math;min(FF)F"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
private float removeMin(float a, float b) {
return a;
}

@Redirect(method = "handleMetadata", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(FF)F"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
@Redirect(method = "handleEntityData", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(FF)F"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
private float removeMax(float a, float b) {
return b;
}

@Redirect(method = "handleMetadata", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/minecraft/entitydata/EntityData;getValue()Ljava/lang/Object;"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
@Redirect(method = "handleEntityData", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/minecraft/entitydata/EntityData;getValue()Ljava/lang/Object;"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
private Object remapNaNToZero(EntityData instance) {
if (instance.getValue() instanceof Float && ((Float) instance.getValue()).isNaN()) {
return 0F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private void loadAndScanJar(final File file) throws Throwable {
final URL url = file.toURI().toURL();
final TransformerManager transformerManager = new TransformerManager(new LazyFileClassProvider(Collections.singletonList(file), this.rootClassProvider));
final InjectionClassLoader classLoader = new InjectionClassLoader(transformerManager, PluginManager.class.getClassLoader(), url);
classLoader.addProtectedPackage("io.netty.");

try {
final String[] versions = System.getProperty("java.class.version").split("\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
private final OptionSpec<String> optionTargetAddress;
private final OptionSpec<ProtocolVersion> optionTargetVersion;
private final OptionSpec<Boolean> optionProxyOnlineMode;
private final OptionSpec<Integer> optionConnectTimeout;
private final OptionSpec<AuthMethod> optionAuthMethod;
private final OptionSpec<Integer> optionMinecraftAccountIndex;
private final OptionSpec<Boolean> optionBetacraftAuth;
Expand All @@ -79,6 +80,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
private SocketAddress bindAddress = AddressUtil.parse("0.0.0.0:25568", null);
private SocketAddress targetAddress = AddressUtil.parse("127.0.0.1:25565", null);
private ProtocolVersion targetVersion = ProtocolTranslator.AUTO_DETECT_PROTOCOL;
private int connectTimeout = 8000;
private boolean proxyOnlineMode = false;
private AuthMethod authMethod = AuthMethod.NONE;
private Account account = null;
Expand Down Expand Up @@ -108,6 +110,7 @@ public ViaProxyConfig(final File configFile) {
this.optionTargetAddress = this.optionParser.accepts("target-address").withRequiredArg().ofType(String.class).defaultsTo(AddressUtil.toString(this.targetAddress));
this.optionTargetVersion = this.optionParser.accepts("target-version").withRequiredArg().withValuesConvertedBy(new ProtocolVersionConverter()).defaultsTo(this.targetVersion);
this.optionProxyOnlineMode = this.optionParser.accepts("proxy-online-mode").withRequiredArg().ofType(Boolean.class).defaultsTo(this.proxyOnlineMode);
this.optionConnectTimeout = this.optionParser.accepts("connect-timeout").withRequiredArg().ofType(Integer.class).defaultsTo(this.connectTimeout);
this.optionAuthMethod = this.optionParser.accepts("auth-method").withRequiredArg().ofType(AuthMethod.class).defaultsTo(this.authMethod);
this.optionMinecraftAccountIndex = this.optionParser.accepts("minecraft-account-index").withRequiredArg().ofType(Integer.class).defaultsTo(0);
this.optionBetacraftAuth = this.optionParser.accepts("betacraft-auth").withRequiredArg().ofType(Boolean.class).defaultsTo(this.betacraftAuth);
Expand Down Expand Up @@ -136,6 +139,7 @@ public void reload() {
this.targetVersion = ProtocolVersion.getClosest(this.getString("target-version", this.targetVersion.getName()));
this.checkTargetVersion();
this.targetAddress = AddressUtil.parse(this.getString("target-address", AddressUtil.toString(this.targetAddress)), this.targetVersion);
this.connectTimeout = this.getInt("connect-timeout", this.connectTimeout);
this.proxyOnlineMode = this.getBoolean("proxy-online-mode", this.proxyOnlineMode);
this.authMethod = AuthMethod.byName(this.getString("auth-method", this.authMethod.name()));
final List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
Expand Down Expand Up @@ -174,6 +178,7 @@ public void loadFromArguments(final String[] args) throws IOException {
this.targetVersion = options.valueOf(this.optionTargetVersion);
this.checkTargetVersion();
this.targetAddress = AddressUtil.parse(options.valueOf(this.optionTargetAddress), this.targetVersion);
this.connectTimeout = options.valueOf(this.optionConnectTimeout);
this.proxyOnlineMode = options.valueOf(this.optionProxyOnlineMode);
this.authMethod = options.valueOf(this.optionAuthMethod);
final List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
Expand Down Expand Up @@ -259,6 +264,15 @@ public void setTargetVersion(final ProtocolVersion targetVersion) {
this.set("target-version", targetVersion.getName());
}

public int getConnectTimeout() {
return this.connectTimeout;
}

public void setConnectTimeout(final int connectTimeout) {
this.connectTimeout = connectTimeout;
this.set("connect-timeout", connectTimeout);
}

public boolean isProxyOnlineMode() {
return this.proxyOnlineMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,14 @@ private void connect(final SocketAddress serverAddress, final ProtocolVersion se

this.proxyConnection.getChannel().writeAndFlush(newHandshakePacket).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f2 -> {
if (f2.isSuccess()) {
this.proxyConnection.setP2sConnectionState(intendedState.getConnectionState());
final UserConnection userConnection = this.proxyConnection.getUserConnection();
if (userConnection.has(CookieStorage.class) && TransferDataHolder.hasCookieStorage(this.proxyConnection.getC2P())) {
userConnection.get(CookieStorage.class).cookies().putAll(TransferDataHolder.removeCookieStorage(this.proxyConnection.getC2P()).cookies());
}
this.proxyConnection.setP2sConnectionState(intendedState.getConnectionState());
ChannelUtil.restoreAutoRead(this.proxyConnection.getC2P());
}
});

ChannelUtil.restoreAutoRead(this.proxyConnection.getC2P());
});
}
}, (ThrowingChannelFutureListener) f -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {

final Supplier<ChannelHandler> handlerSupplier = () -> ViaProxy.EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new PassthroughClient2ProxyHandler(), true)).getHandler();
final PassthroughClient2ProxyChannelInitializer channelInitializer = new PassthroughClient2ProxyChannelInitializer(handlerSupplier);
channelInitializer.initChannel(ctx.channel());
ctx.channel().pipeline().addLast(channelInitializer);
ctx.channel().pipeline().fireChannelActive();
}

Expand Down
Loading

0 comments on commit 0e35235

Please sign in to comment.