Compare commits
1 commit
dev
...
betterchat
Author | SHA1 | Date | |
---|---|---|---|
33ece210f5 |
2 changed files with 59 additions and 4 deletions
21
src/main/java/ftbsc/bscv/modules/hud/Terminal.java
Normal file
21
src/main/java/ftbsc/bscv/modules/hud/Terminal.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue