From 6871d1dc3c3ccb3b3327456680153670385d5844 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 4 Mar 2023 01:30:01 +0100 Subject: [PATCH] feat: replaced invasive PortalGui mod with patch as of now it's just permanently on but some switch will come --- .../ftbsc/bscv/modules/self/PortalGui.java | 20 ------- .../ftbsc/bscv/patches/PortalGuiPatch.java | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 20 deletions(-) delete mode 100644 src/main/java/ftbsc/bscv/modules/self/PortalGui.java create mode 100644 src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java diff --git a/src/main/java/ftbsc/bscv/modules/self/PortalGui.java b/src/main/java/ftbsc/bscv/modules/self/PortalGui.java deleted file mode 100644 index bffb111..0000000 --- a/src/main/java/ftbsc/bscv/modules/self/PortalGui.java +++ /dev/null @@ -1,20 +0,0 @@ -package ftbsc.bscv.modules.self; - -import com.google.auto.service.AutoService; -import ftbsc.bscv.ICommons; -import ftbsc.bscv.api.ILoadable; -import ftbsc.bscv.modules.AbstractModule; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -@AutoService(ILoadable.class) -public class PortalGui extends AbstractModule implements ICommons { - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if (MC.player == null) return; - // TODO is there a more elegant way to do this? - MC.player.isInsidePortal = false; // ACCESSTRANSFORMER - } - -} diff --git a/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java b/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java new file mode 100644 index 0000000..d86acfc --- /dev/null +++ b/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java @@ -0,0 +1,53 @@ +package ftbsc.bscv.patches; + +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.JumpInsnNode; +import org.objectweb.asm.tree.LabelNode; +import org.objectweb.asm.tree.MethodNode; + +import ftbsc.lll.processor.annotations.Injector; +import ftbsc.lll.processor.annotations.Patch; +import ftbsc.lll.processor.annotations.Target; +import ftbsc.lll.tools.PatternMatcher; +import ftbsc.lll.tools.debug.BytecodePrinter; +import net.minecraft.client.entity.player.ClientPlayerEntity; + +@Patch(value = ClientPlayerEntity.class, reason = "prevent minecraft from force closing guis when entering portals") +public abstract class PortalGuiPatch implements Opcodes { + @Target + abstract void handleNetherPortalClient(); + + @Injector + public void inject(ClassNode clazz, MethodNode main) { + LabelNode skip = new LabelNode(); + + System.out.println("Finding first pattern"); + // BytecodePrinter.printAsmMethod(main); + AbstractInsnNode found = PatternMatcher.builder() + .opcodes(ALOAD, GETFIELD, IFEQ) + .ignoreFrames() + .ignoreLabels() + .ignoreLineNumbers() + .build() + .find(main) + .getLast(); + + System.out.println("Finding second pattern"); + AbstractInsnNode after = PatternMatcher.builder() + .opcodes(GETFIELD, ACONST_NULL, CHECKCAST, INVOKEVIRTUAL) + .ignoreFrames() + .ignoreLabels() + .ignoreLineNumbers() + .build() + .find(main) + .getLast(); + + main.instructions.insert(found, new JumpInsnNode(GOTO, skip)); + main.instructions.insert(after, skip); + + BytecodePrinter.printAsmMethod(main); + } +} +