Skip to content

Commit

Permalink
update to 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
caunt committed Dec 16, 2023
1 parent cb08241 commit ec48b63
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 95 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'org.spongepowered.mixin' version '0.7.+'
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ org.gradle.daemon=false
## Environment Properties

# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.1
minecraft_version=1.20.2
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20,1.21)
minecraft_version_range=[1.20.2,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=47.1.42
forge_version=48.1.0
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[46,)
forge_version_range=[48,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[46,)
loader_version_range=[48,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
Expand All @@ -35,7 +35,7 @@ loader_version_range=[46,)
mapping_channel=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.20.1
mapping_version=1.20.2


## Mod Properties
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
11 changes: 6 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -144,15 +141,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
32 changes: 16 additions & 16 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
maven {
name = 'SpongePowered'
url = 'https://repo.spongepowered.org/maven'
}
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
maven {
name = 'SpongePowered'
url = 'https://repo.spongepowered.org/maven'
}
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}
35 changes: 19 additions & 16 deletions src/main/java/ua/caunt/bungeeforge/mixin/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@


import com.mojang.authlib.properties.Property;
import io.netty.channel.Channel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.Redirect;
import ua.caunt.bungeeforge.bridge.network.ConnectionBridge;

import java.net.InetSocketAddress;
Expand All @@ -15,47 +17,48 @@

@Mixin(value = net.minecraft.network.Connection.class)
public class Connection implements ConnectionBridge {
private String spoofedAddress;
private UUID spoofedId;
private Property[] spoofedProperties;
@Unique
private String bungee$spoofedAddress;
@Unique
private UUID bungee$spoofedId;
@Unique
private Property[] bungee$spoofedProperties;
@Shadow
private SocketAddress address;

@Override
public void bungee$setSpoofedAddress(String spoofedAddress) {
this.spoofedAddress = spoofedAddress;
this.bungee$spoofedAddress = spoofedAddress;
this.address = new InetSocketAddress(spoofedAddress, 0);
}

@Override
public void bungee$setSpoofedId(UUID spoofedId) {
this.spoofedId = spoofedId;
this.bungee$spoofedId = spoofedId;
}

@Override
public void bungee$setSpoofedProperties(Property[] spoofedProperties) {
this.spoofedProperties = spoofedProperties;
this.bungee$spoofedProperties = spoofedProperties;
}

@Override
public Optional<String> bungee$getSpoofedAddress() {
return Optional.ofNullable(spoofedAddress);
return Optional.ofNullable(bungee$spoofedAddress);
}

@Override
public Optional<UUID> bungee$getSpoofedId() {
return Optional.ofNullable(spoofedId);
return Optional.ofNullable(bungee$spoofedId);
}

@Override
public Optional<Property[]> bungee$getSpoofedProperties() {
return Optional.ofNullable(spoofedProperties);
return Optional.ofNullable(bungee$spoofedProperties);
}

@Override
public boolean bungee$hasSpoofedProfile() {
return bungee$getSpoofedAddress().isPresent() && bungee$getSpoofedId().isPresent() && bungee$getSpoofedProperties().isPresent();
}

@Inject(method = "getRemoteAddress", at = @At("HEAD"), cancellable = true)
public void bungee$handleIntention(CallbackInfoReturnable<SocketAddress> cir) {
bungee$getSpoofedAddress().ifPresent(s -> cir.setReturnValue(new InetSocketAddress(s, 0)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.google.gson.Gson;
import com.mojang.authlib.properties.Property;
import com.mojang.util.UUIDTypeAdapter;
import net.minecraft.network.FriendlyByteBuf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import ua.caunt.bungeeforge.bridge.network.protocol.handshake.ClientIntentionPacketBridge;
Expand All @@ -15,52 +15,69 @@

@Mixin(net.minecraft.network.protocol.handshake.ClientIntentionPacket.class)
public class ClientIntentionPacket implements ClientIntentionPacketBridge {
private String spoofedAddress;
private UUID spoofedId;
private Property[] spoofedProperties;
@Unique
private static String bungee$spoofedAddress;
@Unique
private static UUID bungee$spoofedId;
@Unique
private static Property[] bungee$spoofedProperties;

private static final Gson gson = new Gson();
@Unique
private static final Gson bungee$gson = new Gson();

@Redirect(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readUtf(I)Ljava/lang/String;"))
private String bungee$readUtf(FriendlyByteBuf buf, int length) {
private static String bungee$readUtf(FriendlyByteBuf buf, int length) {
var data = buf.readUtf(Short.MAX_VALUE);
var chunks = data.split("\0");

if (chunks.length <= 2)
return data;

var properties = gson.fromJson(chunks[3], Property[].class);
var properties = bungee$gson.fromJson(chunks[3], Property[].class);

spoofedAddress = chunks[1];
spoofedId = UUIDTypeAdapter.fromString(chunks[2]);
spoofedProperties = Arrays.stream(properties)
bungee$spoofedAddress = chunks[1];
bungee$spoofedId = UUID.fromString(ensureDashesInUuid(chunks[2]));
bungee$spoofedProperties = Arrays.stream(properties)
.filter(packet -> !isFmlMarker(packet))
.toArray(Property[]::new);

return Arrays.stream(properties)
.filter(packet -> isFmlMarker(packet))
.filter(ClientIntentionPacket::isFmlMarker)
.findFirst()
.map(property -> chunks[1] + "\0" + property.getValue().split("\u0001")[1] + "\0")
.map(property -> chunks[1] + "\0" + property.value().split("\u0001")[1] + "\0")
.orElseGet(() -> chunks[1]);
}

private static boolean isFmlMarker(Property property)
{
return Objects.equals(property.getName(), "extraData") && property.getValue().startsWith("\u0001FML");
return Objects.equals(property.name(), "extraData") && property.value().startsWith("\u0001FORGE");
}

private static String ensureDashesInUuid(String source) {
if (source.length() > 32)
return source;

var builder = new StringBuilder(source);
builder.insert(8, "-");
builder.insert(13, "-");
builder.insert(18, "-");
builder.insert(23, "-");

return builder.toString();
}

@Override
public String bungee$getSpoofedAddress() {
return spoofedAddress;
return bungee$spoofedAddress;
}

@Override
public UUID bungee$getSpoofedId() {
return spoofedId;
return bungee$spoofedId;
}

@Override
public Property[] bungee$getSpoofedProperties() {
return spoofedProperties;
return bungee$spoofedProperties;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ServerHandshakePacketListenerImpl {

@Inject(method = "handleIntention(Lnet/minecraft/network/protocol/handshake/ClientIntentionPacket;)V", at = @At("HEAD"))
public void bungee$handleIntention(ClientIntentionPacket p_9975_, CallbackInfo ci) {
ClientIntentionPacketBridge clientIntentionPacketBridge = (ClientIntentionPacketBridge) p_9975_;
ClientIntentionPacketBridge clientIntentionPacketBridge = (ClientIntentionPacketBridge) (Object) p_9975_;
ConnectionBridge connectionBridge = (ConnectionBridge) connection;

connectionBridge.bungee$setSpoofedAddress(clientIntentionPacketBridge.bungee$getSpoofedAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import ua.caunt.bungeeforge.bridge.network.ConnectionBridge;
Expand All @@ -20,25 +21,29 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListenerI
@Shadow
Connection connection;

@Shadow
private GameProfile authenticatedProfile;

@Unique
private static final Pattern PROP_PATTERN = Pattern.compile("\\w{0,16}");

@Redirect(method = "handleHello(Lnet/minecraft/network/protocol/login/ServerboundHelloPacket;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl;gameProfile:Lcom/mojang/authlib/GameProfile;", opcode = Opcodes.PUTFIELD))
public void bungee$handleHello(net.minecraft.server.network.ServerLoginPacketListenerImpl instance, GameProfile value) {
@Redirect(method = "startClientVerification(Lcom/mojang/authlib/GameProfile;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl;authenticatedProfile:Lcom/mojang/authlib/GameProfile;", opcode = Opcodes.PUTFIELD))
public void bungee$startClientVerification(net.minecraft.server.network.ServerLoginPacketListenerImpl instance, GameProfile value) {
var connectionBridge = (ConnectionBridge)bungee$getConnection();

if (!connectionBridge.bungee$hasSpoofedProfile()) {
instance.gameProfile = value;
authenticatedProfile = value;
return;
}

var gameProfile = new GameProfile(connectionBridge.bungee$getSpoofedId().get(), value.getName());
var properties = gameProfile.getProperties();

Arrays.stream(connectionBridge.bungee$getSpoofedProperties().get()).filter(property -> PROP_PATTERN.matcher(property.getName()).matches()).forEach(property -> {
properties.put(property.getName(), property);
Arrays.stream(connectionBridge.bungee$getSpoofedProperties().get()).filter(property -> PROP_PATTERN.matcher(property.name()).matches()).forEach(property -> {
properties.put(property.name(), property);
});

instance.gameProfile = gameProfile;
authenticatedProfile = gameProfile;
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/bungeeforge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"mixins": [
"network.Connection",
"network.protocol.handshake.ClientIntentionPacket",
"server.network.ServerConnectionListener",
"server.network.ServerGamePacketListenerImpl",
"server.network.ServerHandshakePacketListenerImpl",
"server.network.ServerLoginPacketListenerImpl"
],
Expand Down

0 comments on commit ec48b63

Please sign in to comment.