Skip to content

Commit

Permalink
Update to 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jan 2, 2024
1 parent 5f36d65 commit 42a7ec9
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 42 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImpersonateTextContent> 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<ImpersonateTextContent> TYPE = new TextContent.Type<>(CODEC, "text");
private final String trueText;
private final String fakedText;
private boolean revealed;
Expand Down Expand Up @@ -74,6 +87,16 @@ public <T> Optional<T> visit(StringVisitable.Visitor<T> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 42a7ec9

Please sign in to comment.