From f00f22f2ea325ddcd5f8662d294b49afb2356a30 Mon Sep 17 00:00:00 2001 From: My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com> Date: Wed, 3 Nov 2021 01:43:17 -0400 Subject: [PATCH] duplicate a field with our own name for runnable --- .../PacketThreadUtilTransformer.kt | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/skytils/skytilsmod/asm/transformers/PacketThreadUtilTransformer.kt b/src/main/kotlin/skytils/skytilsmod/asm/transformers/PacketThreadUtilTransformer.kt index 44bc05dfa..f85bb5cc8 100644 --- a/src/main/kotlin/skytils/skytilsmod/asm/transformers/PacketThreadUtilTransformer.kt +++ b/src/main/kotlin/skytils/skytilsmod/asm/transformers/PacketThreadUtilTransformer.kt @@ -23,14 +23,34 @@ import dev.falsehonesty.asmhelper.dsl.instructions.JumpCondition import dev.falsehonesty.asmhelper.dsl.modify import net.minecraft.network.INetHandler import net.minecraft.network.Packet +import org.objectweb.asm.Opcodes import skytils.skytilsmod.events.impl.MainReceivePacketEvent fun insertReceivePacketEvent() = modify("net/minecraft/network/PacketThreadUtil$1") { - val netHandler = classNode.fields.find { it.desc == "Lnet/minecraft/network/INetHandler;" || it.desc == "Lep;" } - ?: error("couldn't find INetHandler field") - val packet = - classNode.fields.find { it.desc == "Lnet/minecraft/network/Packet;" || it.desc == "Lff;" } - ?: error("couldn't find Packet field") + classNode.visitField( + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, + "skytils\$handler", + "Lnet/minecraft/network/INetHandler;", + null, + null + ).visitEnd() + classNode.visitField( + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, + "skytils\$packet", + "Lnet/minecraft/network/Packet;", + null, + null + ).visitEnd() + classNode.methods.find { it.name == "" }?.apply { + instructions.insert(InsnListBuilder(this).apply { + aload(0) + aload(1) + putField(classNode.name, "skytils\$packet", "Lnet/minecraft/network/Packet;") + aload(0) + aload(2) + putField(classNode.name, "skytils\$handler", "Lnet/minecraft/network/INetHandler;") + }.build()) + } findMethod("run", "()V").apply { instructions.insert(InsnListBuilder(this).apply { invokeStatic( @@ -39,9 +59,17 @@ fun insertReceivePacketEvent() = modify("net/minecraft/network/PacketThreadUtil$ "(Lnet/minecraft/network/INetHandler;Lnet/minecraft/network/Packet;)Z" ) { aload(0) - getField("net/minecraft/network/PacketThreadUtil$1", netHandler.name, netHandler.desc) + getField( + "net/minecraft/network/PacketThreadUtil$1", + "skytils\$handler", + "Lnet/minecraft/network/INetHandler;" + ) aload(0) - getField("net/minecraft/network/PacketThreadUtil$1", packet.name, packet.desc) + getField( + "net/minecraft/network/PacketThreadUtil$1", + "skytils\$packet", + "Lnet/minecraft/network/Packet;" + ) } ifClause(JumpCondition.EQUAL) { methodReturn()