aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-03-20 23:28:27 +0100
committer alemi <me@alemi.dev>2023-03-20 23:28:27 +0100
commit33ece210f588d865ed228bb4b1012ecf20170f1a (patch)
tree43ffce69a3588e408b3699570ff5ff9564fdcb7e /src/main
parented0d7d9621f357a01a30d353731972befda848d8 (diff)
chore: initial work on a better chat patchbetterchat
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/ftbsc/bscv/modules/hud/Terminal.java21
-rw-r--r--src/main/java/ftbsc/bscv/patches/ChatPatch.java42
2 files changed, 59 insertions, 4 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/hud/Terminal.java b/src/main/java/ftbsc/bscv/modules/hud/Terminal.java
new file mode 100644
index 0000000..432f78b
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/modules/hud/Terminal.java
@@ -0,0 +1,21 @@
+package ftbsc.bscv.modules.hud;
+
+import ftbsc.bscv.modules.AbstractModule;
+import ftbsc.bscv.tools.Setting;
+import net.minecraftforge.common.ForgeConfigSpec;
+
+public class Terminal extends AbstractModule {
+
+ public final ForgeConfigSpec.ConfigValue<Integer> msg_count;
+
+ public Terminal() {
+ super();
+
+ this.msg_count = Setting.Number.builder()
+ .min(-1)
+ .fallback(100)
+ .name("msg-count")
+ .comment("How many messages to keep in chat, set to 0 for unlimited")
+ .build(this);
+ }
+}
diff --git a/src/main/java/ftbsc/bscv/patches/ChatPatch.java b/src/main/java/ftbsc/bscv/patches/ChatPatch.java
index 0441c28..7ec733d 100644
--- a/src/main/java/ftbsc/bscv/patches/ChatPatch.java
+++ b/src/main/java/ftbsc/bscv/patches/ChatPatch.java
@@ -1,12 +1,21 @@
package ftbsc.bscv.patches;
+import ftbsc.bscv.modules.hud.Terminal;
+import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target;
+import ftbsc.lll.proxies.FieldProxy;
import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.PatternMatcher;
+import ftbsc.lll.tools.debug.BytecodePrinter;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.NewChatGui;
import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.util.text.ITextComponent;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.eventbus.api.Event;
+import net.minecraftforge.eventbus.api.Cancelable;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
@@ -14,6 +23,13 @@ import org.objectweb.asm.tree.*;
public class ChatPatch {
+ @Cancelable
+ public static class ClearChatEvent extends Event {}
+
+ public static boolean shouldPreventChatClearing() {
+ return MinecraftForge.EVENT_BUS.post(new ClearChatEvent());
+ }
+
@Patch(value = Minecraft.class, reason = "add hook to prevent chat from being cleared")
public abstract static class ChatClearInterceptor implements Opcodes {
@@ -23,21 +39,39 @@ public class ChatPatch {
abstract void setScreen(Screen screen);
@Injector
- public void inject(ClassNode clazz, MethodNode main) {
+ public void inject(ClassNode clazz, MethodNode method) {
InsnSequence match = PatternMatcher.builder()
.opcodes(ALOAD, GETFIELD, INVOKEVIRTUAL, ICONST_1, INVOKEVIRTUAL)
.ignoreLineNumbers()
.ignoreLabels()
.ignoreFrames()
.build()
- .find(main);
+ .find(method);
LabelNode skip = new LabelNode();
+
JumpInsnNode jump = new JumpInsnNode(GOTO, skip);
- main.instructions.insertBefore(match.getFirst(), jump);
- main.instructions.insert(match.getLast(), skip);
+ method.instructions.insertBefore(match.getFirst(), jump);
+ method.instructions.insert(match.getLast(), skip);
}
}
+ @Patch(value = NewChatGui.class, reason = "make max number of messages in chat configurable (instead of just 100)")
+ public abstract static class ChatHistoryRemoveInterceptor implements Opcodes {
+
+ @Target
+ abstract void addMessage(ITextComponent txt, int idk1, int idk2, boolean idk3);
+
+ @Find(parent = Terminal.class)
+ abstract FieldProxy msg_count();
+
+ @Injector
+ public void inject(ClassNode clazz, MethodNode method) {
+ InsnSequence match = PatternMatcher.builder()
+ .opcodes(ALOAD, ICONST_2, INVOKESPECIAL, INVOKEINTERFACE, GOTO)
+ .build()
+ .find(method);
+ }
+ }
}