feat: better chat patch, still not optional
This commit is contained in:
parent
dd9b4bb539
commit
62df0cf4ba
1 changed files with 21 additions and 10 deletions
|
@ -3,29 +3,40 @@ package ftbsc.bscv.patches;
|
||||||
import ftbsc.lll.processor.annotations.Injector;
|
import ftbsc.lll.processor.annotations.Injector;
|
||||||
import ftbsc.lll.processor.annotations.Patch;
|
import ftbsc.lll.processor.annotations.Patch;
|
||||||
import ftbsc.lll.processor.annotations.Target;
|
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.Opcodes;
|
||||||
import org.objectweb.asm.tree.*;
|
import org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
|
||||||
public class ChatPatch {
|
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 {
|
public abstract static class ChatClearInterceptor implements Opcodes {
|
||||||
|
|
||||||
/*
|
// TODO this should be optional
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Target
|
@Target
|
||||||
abstract void clearMessages(boolean clearSent);
|
abstract void setScreen(Screen screen);
|
||||||
|
|
||||||
@Injector
|
@Injector
|
||||||
public void inject(ClassNode clazz, MethodNode main) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue