From 89b95fbf861b8da2a9db5130b7ad355216d59427 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Mon, 2 Jan 2023 01:00:50 +0100 Subject: Fix `MixinServerStatusPinger$1` --- .../mixins/client/MixinGuiMessageTagIcon.java | 2 +- .../mixins/client/MixinServerStatusPinger$1.java | 33 ++++++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTagIcon.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTagIcon.java index 6ef1488..7c130bd 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTagIcon.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTagIcon.java @@ -21,7 +21,7 @@ import net.minecraft.resources.ResourceLocation; @Mixin(GuiMessageTag.Icon.class) public abstract class MixinGuiMessageTagIcon { private static final ResourceLocation TEXTURE_NCR = new ResourceLocation("nochatreports", "textures/gui/encrypted_tag.png"); - @Shadow(aliases = "field_39768") @Mutable static Icon[] $VALUES; + @Shadow(aliases = "field_39768", remap = false) @Mutable static Icon[] $VALUES; @Invoker("") static Icon create(String name, int ordinal, int u, int v, int width, int height) { diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java index 7da207f..fb0d66b 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java @@ -1,5 +1,7 @@ package com.aizistral.nochatreports.mixins.client; +import java.lang.reflect.Field; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -17,8 +19,18 @@ import net.minecraft.network.protocol.status.ServerStatus; @Mixin(targets = "net/minecraft/client/multiplayer/ServerStatusPinger$1") public class MixinServerStatusPinger$1 { - @Shadow @Final - private ServerData val$data; + private static final Field SERVER_DATA_FIELD; + + static { + // We use reflection here because Mixin's AP dies when trying to process @Shadow of this lol + try { + Class pinger = Class.forName("net.minecraft.client.multiplayer.ServerStatusPinger$1"); + SERVER_DATA_FIELD = pinger.getDeclaredField("val$p_105460_"); + SERVER_DATA_FIELD.setAccessible(true); + } catch (Exception ex) { + throw new RuntimeException("Reflection failed in MixinServerStatusPinger$1", ex); + } + } /** * @reason Ensure "preventsChatReports" property is transferred from {@link ServerStatus} to @@ -29,14 +41,17 @@ public class MixinServerStatusPinger$1 { @Inject(method = "handleStatusResponse(Lnet/minecraft/network/protocol/status/ClientboundStatusResponsePacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;getPlayers()Lnet/minecraft/network/protocol/status/ServerStatus$Players;", ordinal = 0, shift = At.Shift.BEFORE)) private void getNoChatReports(ClientboundStatusResponsePacket packet, CallbackInfo info) { - boolean preventsReports = ((ServerDataExtension) packet.getStatus()).preventsChatReports(); - ((ServerDataExtension) this.val$data).setPreventsChatReports(preventsReports); - - if (NCRConfig.getCommon().enableDebugLog()) { - NoChatReports.LOGGER.info("Received status response packet from server, preventsChatReports: {}", - preventsReports); + try { + boolean preventsReports = ((ServerDataExtension) packet.getStatus()).preventsChatReports(); + ((ServerDataExtension) SERVER_DATA_FIELD.get(this)).setPreventsChatReports(preventsReports); + + if (NCRConfig.getCommon().enableDebugLog()) { + NoChatReports.LOGGER.info("Received status response packet from server, preventsChatReports: {}", + preventsReports); + } + } catch (IllegalArgumentException | IllegalAccessException ex) { + throw new RuntimeException("Failed to get ServerData field via reflection", ex); } - } } -- cgit v1.2.3