From 4e8debffdbe4d1339f3160cdeb35a5ab5a8ff6b8 Mon Sep 17 00:00:00 2001 From: Jade Herd Date: Thu, 23 Jun 2022 11:08:30 -0400 Subject: Replace all Overwrite Mixins with Injects --- .../mixins/MixinClientPacketListener.java | 14 +++++---- .../nochatreports/mixins/MixinDedicatedServer.java | 12 +++++--- .../nochatreports/mixins/MixinLocalPlayer.java | 21 ++++++++----- .../nochatreports/mixins/MixinOptions.java | 12 +++++--- .../nochatreports/mixins/MixinPlayer.java | 12 +++++--- .../mixins/MixinProfileKeyPairManager.java | 34 +++++++++++++--------- .../mixins/MixinServerboundChatPacket.java | 12 +++++--- 7 files changed, 75 insertions(+), 42 deletions(-) (limited to 'src/main/java/com/aizistral') diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinClientPacketListener.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinClientPacketListener.java index 396832a..5e59725 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinClientPacketListener.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinClientPacketListener.java @@ -6,6 +6,9 @@ import org.spongepowered.asm.mixin.Overwrite; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.network.chat.PlayerChatMessage; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientPacketListener.class) public class MixinClientPacketListener { @@ -13,11 +16,12 @@ public class MixinClientPacketListener { /** * @reason Prevents client from trying to validate chat messages relayed * by the server. They will come unsigned as in good old days, so no point. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - private boolean hasValidSignature(PlayerChatMessage message, PlayerInfo info) { - return true; - } + @Inject(method = "hasValidSignature", at = @At("TAIL"), cancellable = true) + private void preventServerValidataion(PlayerChatMessage playerChatMessage, PlayerInfo playerInfo, CallbackInfoReturnable cir) { + cir.setReturnValue(true); + } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinDedicatedServer.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinDedicatedServer.java index 49ce5a8..559a4fa 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinDedicatedServer.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinDedicatedServer.java @@ -5,6 +5,9 @@ import org.spongepowered.asm.mixin.Overwrite; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(DedicatedServer.class) public class MixinDedicatedServer { @@ -12,12 +15,13 @@ public class MixinDedicatedServer { /** * @reason If we are present on server - we won't be using keys for anything, * so this option ceases to make sense. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public boolean enforceSecureProfile() { - return false; + @Inject(method = "enforceSecureProfile", at = @At("RETURN"), cancellable = true) + private void enforceSecureProfile(CallbackInfoReturnable cir) { + cir.setReturnValue(false); } } \ No newline at end of file diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java index 24ed9d0..5e8a05c 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java @@ -13,6 +13,9 @@ import net.minecraft.commands.arguments.ArgumentSignatures; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MessageSignature; import net.minecraft.network.chat.MessageSigner; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LocalPlayer.class) public class MixinLocalPlayer { @@ -20,22 +23,24 @@ public class MixinLocalPlayer { /** * @reason Never sign messages, so that neither server nor other clients have * proof of them being sent from your account. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - private MessageSignature signMessage(MessageSigner signer, Component message) { - return MessageSignature.unsigned(); + @Inject(method = "signMessage", at = @At("HEAD"), cancellable = true) + private void preventSigning(MessageSigner signer, Component message, CallbackInfoReturnable cir) { + cir.setReturnValue(MessageSignature.unsigned()); } /** * @reason Same as above, except commands mostly concern only server. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - private ArgumentSignatures signCommandArguments(MessageSigner signer, ParseResults results, @Nullable Component component) { - return ArgumentSignatures.empty(); + @Inject(method = "signCommandArguments", at = @At("HEAD"), cancellable = true) + private void preventSigningArgs(MessageSigner signer, ParseResults results, @Nullable Component component, CallbackInfoReturnable cir) { + cir.setReturnValue(ArgumentSignatures.empty()); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinOptions.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinOptions.java index 0c53d51..2900e6c 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinOptions.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinOptions.java @@ -10,6 +10,9 @@ import net.minecraft.client.OptionInstance; import net.minecraft.client.Options; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Options.class) public class MixinOptions { @@ -17,11 +20,12 @@ public class MixinOptions { /** * @reason Disable secure chat option, since it will not work anyways. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public OptionInstance onlyShowSecureChat() { + @Inject(method = "onlyShowSecureChat", at = @At("RETURN"), cancellable = true) + private void onlyShowSecureChat(CallbackInfoReturnable> cir) { if (this.alternativeOption == null) { this.alternativeOption = new OptionInstance<>("options.onlyShowSecureChat", OptionInstance.cachedConstantTooltip(Component.translatable("gui.nochatreport.secureChat")), @@ -29,7 +33,7 @@ public class MixinOptions { new OptionInstance.Enum<>(ImmutableList.of(Boolean.FALSE), Codec.BOOL), false, (value) -> {}); } - return this.alternativeOption; + cir.setReturnValue(this.alternativeOption); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayer.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayer.java index e4326fa..dcf05fc 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayer.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayer.java @@ -5,6 +5,9 @@ import org.spongepowered.asm.mixin.Overwrite; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.ProfilePublicKey; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Player.class) public class MixinPlayer { @@ -12,12 +15,13 @@ public class MixinPlayer { /** * @reason Prevents server from trying to validate signatures on incoming * chat messages. Also prevents it from relaying public keys to other clients. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public ProfilePublicKey getProfilePublicKey() { - return null; + @Inject(method = "getProfilePublicKey", at = @At("HEAD"), cancellable = true) + private void noServerValidation(CallbackInfoReturnable cir) { + cir.setReturnValue(null); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinProfileKeyPairManager.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinProfileKeyPairManager.java index 7796180..1422d31 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinProfileKeyPairManager.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinProfileKeyPairManager.java @@ -2,45 +2,53 @@ package com.aizistral.nochatreports.mixins; import java.util.Optional; +import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; +import net.minecraft.network.protocol.login.ClientboundHelloPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import net.minecraft.client.multiplayer.ProfileKeyPairManager; import net.minecraft.util.Signer; import net.minecraft.world.entity.player.ProfilePublicKey; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ProfileKeyPairManager.class) public class MixinProfileKeyPairManager { /** * @reason We don't have to send our keys anywhere, and thus we won't. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public Optional profilePublicKey() { - return Optional.empty(); + @Inject(method = "profilePublicKey", at = @At("HEAD"), cancellable = true) + private void preventServerValidation(CallbackInfoReturnable> cir) { + cir.setReturnValue(Optional.empty()); } /** * @reason We don't have to send our keys anywhere, and thus we won't. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public Optional profilePublicKeyData() { - return Optional.empty(); + @Inject(method = "profilePublicKeyData", at = @At("HEAD"), cancellable = true) + private void dontSendKeys(CallbackInfoReturnable> cir) { + cir.setReturnValue(Optional.empty()); } /** * @reason Prevent client from trying to produce signature in - * {@link ClientHandshakePacketListenerImpl#handleHello(ClientboundHelloPacket)}. - * @author Aizistral + * {@link ClientHandshakePacketListenerImpl#handleHello}. + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public Signer signer() { - return null; + @Inject(method = "signer", at = @At("HEAD"), cancellable = true) + private void preventSignature(CallbackInfoReturnable> cir) { + cir.setReturnValue(null); } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinServerboundChatPacket.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinServerboundChatPacket.java index d1f1814..860c0ca 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinServerboundChatPacket.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinServerboundChatPacket.java @@ -7,6 +7,9 @@ import org.spongepowered.asm.mixin.Overwrite; import net.minecraft.network.chat.MessageSignature; import net.minecraft.network.protocol.game.ServerboundChatPacket; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ServerboundChatPacket.class) public class MixinServerboundChatPacket { @@ -15,12 +18,13 @@ public class MixinServerboundChatPacket { * @reason Strip signatures before relaying messages to other clients, * if they somehow arrive signed. This is important for mod to be able * to operate in server-only mode. - * @author Aizistral + * @author Aizistral (Overwrite) + * @author Aven (Inject) */ - @Overwrite - public MessageSignature getSignature(UUID uuid) { - return MessageSignature.unsigned(); + @Inject(method = "getSignature", at = @At("HEAD"), cancellable = true) + private void stripSignatures(UUID uUID, CallbackInfoReturnable cir) { + cir.setReturnValue(MessageSignature.unsigned()); } } -- cgit v1.2.3