From db354524d155182e13d297f98ece2845d0008d6f Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 30 Mar 2023 23:12:22 +0200 Subject: [PATCH] Log class of sent packages Signed-off-by: PlexSheep --- .../cscherr/plextool/mixin/PlexToolMixin.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/cscherr/plextool/mixin/PlexToolMixin.java b/src/main/java/de/cscherr/plextool/mixin/PlexToolMixin.java index f9fbcb1..002f0e9 100644 --- a/src/main/java/de/cscherr/plextool/mixin/PlexToolMixin.java +++ b/src/main/java/de/cscherr/plextool/mixin/PlexToolMixin.java @@ -1,17 +1,37 @@ package de.cscherr.plextool.mixin; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.slf4j.Logger; +import java.time.Duration; import de.cscherr.plextool.PlexTool; -import net.minecraft.client.gui.screen.TitleScreen; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.listener.ServerPlayPacketListener; +import net.minecraft.network.packet.Packet; +import java.util.function.BooleanSupplier; +import net.minecraft.util.Identifier; -@Mixin(TitleScreen.class) +@Mixin(ClientPlayNetworkHandler.class) public class PlexToolMixin { - @Inject(at = @At("HEAD"), method = "init()V") - private void init(CallbackInfo info) { - PlexTool.LOGGER.info("This line is printed by my mod mixin!"); + // 'V' is appended because the return type is void + // see https://fabricmc.net/wiki/tutorial:mixin_injects + public final Logger PLEX_LOGGER = PlexTool.LOGGER; + public boolean log_packets = true; + @Inject(at = @At("HEAD"), method = "sendPacket()V") + // Method signature is diffrent, but thats what the mixin library wants according to its errors. + // I could not find this in the documentation. + private void sendPacket(Packet packet, CallbackInfo callInfo) { + // this works! + // I am now logging every packet i send! Yay me! + if log_packets { + this.PLEX_LOGGER.info("Sending Packet: " + packet.toString()); + } } + } \ No newline at end of file