From 42a7ec9d58e1ec338e9a9b5940f9e02ca0a2731c Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Mon, 1 Jan 2024 21:39:31 +0100 Subject: [PATCH] Update to 1.20.4 --- gradle.properties | 10 ++--- gradle/libs.versions.toml | 4 +- .../impl/ImpersonateTextContent.java | 23 ++++++++++ .../impersonate/impl/ServerPlayerSkins.java | 23 +++++----- .../mixin/ServerPlayNetworkHandlerMixin.java | 44 +++++++++++-------- .../impl/mixin/ServerPlayerEntityMixin.java | 6 +-- .../impersonatest/ImpersonateTestSuite.java | 12 +++-- 7 files changed, 80 insertions(+), 42 deletions(-) diff --git a/gradle.properties b/gradle.properties index ed9d048..5e283b6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.8 -loader_version=0.14.21 -fabric_version=0.84.0+1.20.1 +minecraft_version=1.20.4 +yarn_mappings=1.20.4+build.3 +loader_version=0.15.3 +fabric_version=0.92.0+1.20.4 # Other Dependencies jb_annotations_version = 23.0.0 @@ -24,7 +24,7 @@ license_header = LGPL gpl_version = 3 modrinth_id = xBZuWXoj curseforge_id = 360333 -curseforge_versions = 1.20; 1.20.1 +curseforge_versions = 1.20.4 cf_requirements = fabric-api cf_embeddeds = cardinal-components-api release_type = release diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 59e6781..3f4f56b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] -cca = "5.2.1" +cca = "5.4.0" fpa = "0.2-SNAPSHOT" -elmendorf = "0.11.0" +elmendorf = "0.12.0" [libraries] cca-base = { module = "dev.onyxstudios.cardinal-components-api:cardinal-components-base", version.ref = "cca" } diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java b/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java index 908e4bb..20f8d89 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/ImpersonateTextContent.java @@ -17,17 +17,30 @@ */ package io.github.ladysnake.impersonate.impl; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.ladysnake.impersonate.Impersonator; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.CommandOutput; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.MutableText; import net.minecraft.text.StringVisitable; import net.minecraft.text.Style; +import net.minecraft.text.Text; import net.minecraft.text.TextContent; +import org.jetbrains.annotations.Nullable; import java.util.Optional; public class ImpersonateTextContent implements RecipientAwareTextContent { + private static final MapCodec CODEC = RecordCodecBuilder.mapCodec( + instance -> instance.group(Codec.STRING.fieldOf("text").forGetter(ImpersonateTextContent::getString)).apply(instance, text -> new ImpersonateTextContent(text, text, false)) + ); + private static final TextContent.Type TYPE = new TextContent.Type<>(CODEC, "text"); private final String trueText; private final String fakedText; private boolean revealed; @@ -74,6 +87,16 @@ public Optional visit(StringVisitable.Visitor visitor) { return visitor.accept(this.getString()); } + @Override + public MutableText parse(@Nullable ServerCommandSource source, @Nullable Entity sender, int depth) throws CommandSyntaxException { + return Text.literal(this.getString()); + } + + @Override + public Type getType() { + return TYPE; + } + public String getString() { return this.revealed ? this.trueText : this.fakedText; } diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/ServerPlayerSkins.java b/src/main/java/io/github/ladysnake/impersonate/impl/ServerPlayerSkins.java index 8bb4510..f08f8d6 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/ServerPlayerSkins.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/ServerPlayerSkins.java @@ -33,6 +33,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.network.packet.s2c.play.CommonPlayerSpawnInfo; import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket; import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket; @@ -165,16 +166,18 @@ private static void reloadSkinVanilla(ServerPlayerEntity player) { // need to change the player entity on the client ServerWorld targetWorld = (ServerWorld) player.getWorld(); player.networkHandler.sendPacket(new PlayerRespawnS2CPacket( - targetWorld.getDimensionKey(), - targetWorld.getRegistryKey(), - BiomeAccess.hashSeed(targetWorld.getSeed()), - player.interactionManager.getGameMode(), - player.interactionManager.getPreviousGameMode(), - targetWorld.isDebugWorld(), - targetWorld.isFlat(), - PlayerRespawnS2CPacket.KEEP_ATTRIBUTES, - player.getLastDeathPos(), - player.getPortalCooldown() + new CommonPlayerSpawnInfo( + targetWorld.getDimensionKey(), + targetWorld.getRegistryKey(), + BiomeAccess.hashSeed(targetWorld.getSeed()), + player.interactionManager.getGameMode(), + player.interactionManager.getPreviousGameMode(), + targetWorld.isDebugWorld(), + targetWorld.isFlat(), + player.getLastDeathPos(), + player.getPortalCooldown() + ), + PlayerRespawnS2CPacket.KEEP_ATTRIBUTES )); player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch()); player.server.getPlayerManager().sendCommandTree(player); diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayNetworkHandlerMixin.java index 5aedb06..fcb2a04 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayNetworkHandlerMixin.java @@ -24,44 +24,52 @@ import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +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.ModifyArg; -@Mixin(ServerPlayNetworkHandler.class) +@Mixin(ServerCommonNetworkHandler.class) public abstract class ServerPlayNetworkHandlerMixin { @Shadow - public ServerPlayerEntity player; + @Final + protected MinecraftServer server; - @ModifyArg(method = "sendPacket(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;)V")) + @ModifyArg(method = "send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;Z)V")) private Packet resolveFakeTextsInPackets(Packet packet) { - if (packet instanceof ChatMessageS2CPacket chatPacket) { - if (this.existsImpersonator()) { - return PacketMeddling.resolveChatMessage(chatPacket, player); - } - } else if (packet instanceof GameMessageS2CPacket gamePacket) { - if (this.existsImpersonator()) { - Text resolvedText = ((RecipientAwareText) gamePacket.content()).impersonateResolveAll(player); - return new GameMessageS2CPacket(resolvedText, gamePacket.overlay()); - } - } else if (packet instanceof PlayerListS2CPacket listPacket) { - if (this.existsImpersonator()) { - PlayerListS2CPacket copy = PacketMeddling.copyPacket(listPacket, PlayerListS2CPacket::new); - PacketMeddling.resolvePlayerListEntries(copy, player); - return copy; + if (((Object) this) instanceof ServerPlayNetworkHandler self) { + ServerPlayerEntity player = self.player; + if (packet instanceof ChatMessageS2CPacket chatPacket) { + if (this.existsImpersonator()) { + return PacketMeddling.resolveChatMessage(chatPacket, player); + } + } else if (packet instanceof GameMessageS2CPacket gamePacket) { + if (this.existsImpersonator()) { + Text resolvedText = ((RecipientAwareText) gamePacket.content()).impersonateResolveAll(player); + return new GameMessageS2CPacket(resolvedText, gamePacket.overlay()); + } + } else if (packet instanceof PlayerListS2CPacket listPacket) { + if (this.existsImpersonator()) { + PlayerListS2CPacket copy = PacketMeddling.copyPacket(listPacket, PlayerListS2CPacket::new); + PacketMeddling.resolvePlayerListEntries(copy, player); + return copy; + } } + } return packet; } @Unique private boolean existsImpersonator() { - for (ServerPlayerEntity player : this.player.server.getPlayerManager().getPlayerList()) { + for (ServerPlayerEntity player : this.server.getPlayerManager().getPlayerList()) { if (Impersonator.get(player).isImpersonating()) { return true; } diff --git a/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayerEntityMixin.java b/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayerEntityMixin.java index 3084b8a..449e1f3 100644 --- a/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/io/github/ladysnake/impersonate/impl/mixin/ServerPlayerEntityMixin.java @@ -22,7 +22,7 @@ import io.github.ladysnake.impersonate.impl.ImpersonateGamerules; import io.github.ladysnake.impersonate.impl.PlayerEntityExtensions; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket; +import net.minecraft.network.packet.c2s.common.SyncedClientOptions; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -38,8 +38,8 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile super(world, pos, yaw, profile); } - @Inject(method = "setClientSettings", at = @At("RETURN")) - private void removeCapeIfDisallowed(ClientSettingsC2SPacket clientSettingsC2SPacket, CallbackInfo ci) { + @Inject(method = "setClientOptions", at = @At("RETURN")) + private void removeCapeIfDisallowed(SyncedClientOptions clientOptions, CallbackInfo ci) { if (Impersonator.get(this).isImpersonating() && !this.getWorld().getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) { this.impersonate_disableCape(); } diff --git a/src/testmod/java/io/github/ladysnake/impersonatest/ImpersonateTestSuite.java b/src/testmod/java/io/github/ladysnake/impersonatest/ImpersonateTestSuite.java index ed00a5e..deb2b55 100644 --- a/src/testmod/java/io/github/ladysnake/impersonatest/ImpersonateTestSuite.java +++ b/src/testmod/java/io/github/ladysnake/impersonatest/ImpersonateTestSuite.java @@ -18,8 +18,6 @@ package io.github.ladysnake.impersonatest; import com.mojang.authlib.GameProfile; -import io.github.ladysnake.elmendorf.GameTestUtil; -import io.github.ladysnake.elmendorf.impl.MockClientConnection; import io.github.ladysnake.impersonate.Impersonate; import io.github.ladysnake.impersonate.Impersonator; import io.github.ladysnake.impersonate.impl.ImpersonateTextContent; @@ -30,9 +28,11 @@ import net.minecraft.network.message.LastSeenMessageList; import net.minecraft.network.message.MessageBody; import net.minecraft.network.message.MessageChain; +import net.minecraft.network.packet.c2s.common.SyncedClientOptions; import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket; import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ConnectedClientData; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.test.GameTest; @@ -41,6 +41,8 @@ import net.minecraft.text.Text; import net.minecraft.text.TextContent; import net.minecraft.util.Identifier; +import org.ladysnake.elmendorf.GameTestUtil; +import org.ladysnake.elmendorf.impl.MockClientConnection; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -88,12 +90,14 @@ public void nameInChatGetsRevealed(TestContext ctx) throws NoSuchAlgorithmExcept ServerPlayerEntity player = new ServerPlayerEntity( ctx.getWorld().getServer(), ctx.getWorld(), - new GameProfile(senderUuid, "test-mock-player") + new GameProfile(senderUuid, "test-mock-player"), + SyncedClientOptions.createDefault() ); player.networkHandler = new ServerPlayNetworkHandler( ctx.getWorld().getServer(), new MockClientConnection(NetworkSide.CLIENTBOUND), - player + player, + ConnectedClientData.createDefault(player.getGameProfile()) ); Impersonator.get(player).impersonate(IMPERSONATION_KEY, new GameProfile(UUID.randomUUID(), "impersonated")); String text = "Hi";