From 0a17672051918aec329d19f77eadbd5bc5468b20 Mon Sep 17 00:00:00 2001 From: Wide_Cat Date: Fri, 27 Dec 2024 14:56:16 +0000 Subject: [PATCH] Use a mixin instead of ASM for GetFovEvent fix compatibility with liquidbounce --- .../meteorclient/asm/Asm.java | 5 +- .../transformers/GameRendererTransformer.java | 67 ------------------- .../meteorclient/mixin/GameRendererMixin.java | 6 ++ 3 files changed, 8 insertions(+), 70 deletions(-) delete mode 100644 src/main/java/meteordevelopment/meteorclient/asm/transformers/GameRendererTransformer.java diff --git a/src/main/java/meteordevelopment/meteorclient/asm/Asm.java b/src/main/java/meteordevelopment/meteorclient/asm/Asm.java index 5f2fa1627d..06e260bfdc 100644 --- a/src/main/java/meteordevelopment/meteorclient/asm/Asm.java +++ b/src/main/java/meteordevelopment/meteorclient/asm/Asm.java @@ -5,7 +5,7 @@ package meteordevelopment.meteorclient.asm; -import meteordevelopment.meteorclient.asm.transformers.GameRendererTransformer; +import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.asm.transformers.PacketInflaterTransformer; import net.fabricmc.loader.api.FabricLoader; import org.objectweb.asm.ClassReader; @@ -41,7 +41,6 @@ public static void init() { if (INSTANCE != null) return; INSTANCE = new Asm(System.getProperty("meteor.asm.export") != null); - INSTANCE.add(new GameRendererTransformer()); INSTANCE.add(new PacketInflaterTransformer()); } @@ -76,7 +75,7 @@ private void export(String name, byte[] bytes) { new File(path.toUri()).getParentFile().mkdirs(); Files.write(path, bytes); } catch (IOException e) { - e.printStackTrace(); + MeteorClient.LOG.error("Failed to export transformer '{}': ", name, e); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/asm/transformers/GameRendererTransformer.java b/src/main/java/meteordevelopment/meteorclient/asm/transformers/GameRendererTransformer.java deleted file mode 100644 index 53d90d925e..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/asm/transformers/GameRendererTransformer.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.asm.transformers; - -import meteordevelopment.meteorclient.asm.AsmTransformer; -import meteordevelopment.meteorclient.asm.Descriptor; -import meteordevelopment.meteorclient.asm.MethodInfo; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.*; - -public class GameRendererTransformer extends AsmTransformer { - private final MethodInfo getFovMethod; - - public GameRendererTransformer() { - super(mapClassName("net/minecraft/class_757")); - - getFovMethod = new MethodInfo("net/minecraft/class_4184", null, new Descriptor("Lnet/minecraft/class_4184;", "F", "Z", "F"), true); - } - - @Override - public void transform(ClassNode klass) { - // Modify GameRenderer.getFov() - MethodNode method = getMethod(klass, getFovMethod); - if (method == null) error("[Meteor Client] Could not find method GameRenderer.getFov()"); - - int injectionCount = 0; - - //noinspection DataFlowIssue - for (AbstractInsnNode insn : method.instructions) { - if (insn instanceof LdcInsnNode in && in.cst instanceof Float && (float) in.cst == 90) { - InsnList insns = new InsnList(); - generateEventCall(insns, new LdcInsnNode(in.cst)); - - method.instructions.insert(insn, insns); - method.instructions.remove(insn); - injectionCount++; - } - else if ( - (insn instanceof MethodInsnNode in1 && in1.name.equals("intValue") && insn.getNext() instanceof InsnNode _in && _in.getOpcode() == Opcodes.I2F) - || - (insn instanceof MethodInsnNode in2 && in2.owner.equals(klass.name) && in2.name.startsWith("redirect") && in2.name.endsWith("getFov")) // Wi Zoom compatibility - ) { - InsnList insns = new InsnList(); - - insns.add(new VarInsnNode(Opcodes.FSTORE, method.maxLocals)); - generateEventCall(insns, new VarInsnNode(Opcodes.FLOAD, method.maxLocals)); - - method.instructions.insert(insn.getNext(), insns); - injectionCount++; - } - } - - if (injectionCount < 2) error("[Meteor Client] Failed to modify GameRenderer.getFov()"); - } - - private void generateEventCall(InsnList insns, AbstractInsnNode loadPreviousFov) { - insns.add(new FieldInsnNode(Opcodes.GETSTATIC, "meteordevelopment/meteorclient/MeteorClient", "EVENT_BUS", "Lmeteordevelopment/orbit/IEventBus;")); - insns.add(loadPreviousFov); - insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "meteordevelopment/meteorclient/events/render/GetFovEvent", "get", "(F)Lmeteordevelopment/meteorclient/events/render/GetFovEvent;")); - insns.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "meteordevelopment/orbit/IEventBus", "post", "(Ljava/lang/Object;)Ljava/lang/Object;")); - insns.add(new TypeInsnNode(Opcodes.CHECKCAST, "meteordevelopment/meteorclient/events/render/GetFovEvent")); - insns.add(new FieldInsnNode(Opcodes.GETFIELD, "meteordevelopment/meteorclient/events/render/GetFovEvent", "fov", "F")); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java index 3e91843f36..e733c5fbed 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java @@ -10,6 +10,7 @@ import com.llamalad7.mixinextras.sugar.Local; import com.mojang.blaze3d.systems.RenderSystem; import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.events.render.GetFovEvent; import meteordevelopment.meteorclient.events.render.Render3DEvent; import meteordevelopment.meteorclient.events.render.RenderAfterWorldEvent; import meteordevelopment.meteorclient.mixininterface.IVec3d; @@ -150,6 +151,11 @@ private float applyCameraTransformationsMathHelperLerpProxy(float original) { return Modules.get().get(NoRender.class).noNausea() ? 0 : original; } + @ModifyReturnValue(method = "getFov",at = @At("RETURN")) + private float modifyFov(float original) { + return MeteorClient.EVENT_BUS.post(GetFovEvent.get(original)).fov; + } + // Freecam @Unique