diff options
author | alemi <me@alemi.dev> | 2023-03-06 02:18:24 +0100 |
---|---|---|
committer | alemi <me@alemi.dev> | 2023-03-06 02:18:24 +0100 |
commit | 62df0cf4ba6661c178e6f5901b9514953459edca (patch) | |
tree | a3819e93e78a9710155a9571cba1ed24c9e12075 /src/main | |
parent | dd9b4bb539326c949f4452547239d3c1c02442cb (diff) |
feat: better chat patch, still not optional
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/ftbsc/bscv/patches/ChatPatch.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/main/java/ftbsc/bscv/patches/ChatPatch.java b/src/main/java/ftbsc/bscv/patches/ChatPatch.java index b8bc887..0441c28 100644 --- a/src/main/java/ftbsc/bscv/patches/ChatPatch.java +++ b/src/main/java/ftbsc/bscv/patches/ChatPatch.java @@ -3,29 +3,40 @@ package ftbsc.bscv.patches; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; -import net.minecraft.client.gui.NewChatGui; +import ftbsc.lll.tools.InsnSequence; +import ftbsc.lll.tools.PatternMatcher; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screen.Screen; + import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; public class ChatPatch { - @Patch(value = NewChatGui.class, reason = "add hook to prevent chat from being cleared") + @Patch(value = Minecraft.class, reason = "add hook to prevent chat from being cleared") public abstract static class ChatClearInterceptor implements Opcodes { - /* - * TODO this patch is pretty bad because it prevents everyone from clearing the chat history. - * - * A better (but more complex) approach would be to patch in Minecraft.setScreen() and prevent clearing - * chat history upon getting into main menu / multiplayer menu - */ + // TODO this should be optional @Target - abstract void clearMessages(boolean clearSent); + abstract void setScreen(Screen screen); @Injector public void inject(ClassNode clazz, MethodNode main) { - main.instructions.insert(new InsnNode(RETURN)); + InsnSequence match = PatternMatcher.builder() + .opcodes(ALOAD, GETFIELD, INVOKEVIRTUAL, ICONST_1, INVOKEVIRTUAL) + .ignoreLineNumbers() + .ignoreLabels() + .ignoreFrames() + .build() + .find(main); + + LabelNode skip = new LabelNode(); + JumpInsnNode jump = new JumpInsnNode(GOTO, skip); + + main.instructions.insertBefore(match.getFirst(), jump); + main.instructions.insert(match.getLast(), skip); } } |