summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-03-04 01:30:01 +0100
committer alemi <me@alemi.dev>2023-03-04 01:30:01 +0100
commit6871d1dc3c3ccb3b3327456680153670385d5844 (patch)
treefd92f2a6822eb10f74e6a8095da80fa08eabc369 /src
parent5ac2a187bac8ff46174a55c53983ac6b851b6252 (diff)
feat: replaced invasive PortalGui mod with patch
as of now it's just permanently on but some switch will come
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/PortalGui.java20
-rw-r--r--src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java53
2 files changed, 53 insertions, 20 deletions
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);
+ }
+}
+