diff --git a/src/main/java/me/rigamortis/seppuku/api/event/render/EventDrawToast.java b/src/main/java/me/rigamortis/seppuku/api/event/render/EventDrawToast.java new file mode 100644 index 0000000..67a355e --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/api/event/render/EventDrawToast.java @@ -0,0 +1,6 @@ +package me.rigamortis.seppuku.api.event.render; + +import me.rigamortis.seppuku.api.event.EventCancellable; + +public class EventDrawToast extends EventCancellable { +} diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/PatchManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/PatchManager.java index 9e52515..6542c48 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/PatchManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/PatchManager.java @@ -62,6 +62,7 @@ public final class PatchManager { this.patchList.add(new GuiChatPatch()); this.patchList.add(new ParticleManagerPatch()); this.patchList.add(new GuiPlayerTabOverlayPatch()); + this.patchList.add(new GuiToastPatch()); //load custom external patches //TODO this needs more testing diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/misc/NoToast.java b/src/main/java/me/rigamortis/seppuku/impl/module/misc/NoToast.java index c734548..0d4e56d 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/misc/NoToast.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/misc/NoToast.java @@ -1,20 +1,17 @@ package me.rigamortis.seppuku.impl.module.misc; -import me.rigamortis.seppuku.api.event.player.EventUpdateWalkingPlayer; +import me.rigamortis.seppuku.api.event.render.EventDrawToast; import me.rigamortis.seppuku.api.module.Module; -import net.minecraft.client.Minecraft; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; public final class NoToast extends Module { - private final Minecraft mc = Minecraft.getMinecraft(); - public NoToast() { super("NoToast", new String[]{"Toast"}, "Prevents toasts from being displayed on screen.", "NONE", -1, ModuleType.WORLD); } @Listener - public void onWalkingUpdate(EventUpdateWalkingPlayer event) { - mc.getToastGui().clear(); + public void onToast(EventDrawToast event) { + event.setCanceled(true); } } diff --git a/src/main/java/me/rigamortis/seppuku/impl/patch/GuiToastPatch.java b/src/main/java/me/rigamortis/seppuku/impl/patch/GuiToastPatch.java new file mode 100644 index 0000000..1bc4165 --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/patch/GuiToastPatch.java @@ -0,0 +1,46 @@ +package me.rigamortis.seppuku.impl.patch; + +import me.rigamortis.seppuku.Seppuku; +import me.rigamortis.seppuku.api.event.render.EventDrawToast; +import me.rigamortis.seppuku.api.patch.ClassPatch; +import me.rigamortis.seppuku.api.patch.MethodPatch; +import me.rigamortis.seppuku.impl.management.PatchManager; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.*; + +import static org.objectweb.asm.Opcodes.*; + +public class GuiToastPatch extends ClassPatch { + + public GuiToastPatch() { + super("net.minecraft.client.gui.toasts.GuiToast", "bkc"); + } + + @MethodPatch( + mcpName = "drawToast", + notchName = "a", + mcpDesc = "(Lnet/minecraft/client/gui/ScaledResolution;)V", + notchDesc = "(Lbit;)V") + public void drawToast(MethodNode methodNode, PatchManager.Environment env) { + //create a list of instructions + final InsnList insnList = new InsnList(); + //call our hook function + insnList.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "drawToastHook", "()Z", false)); + //create a label to jump to + final LabelNode jmp = new LabelNode(); + //add "if equals" + insnList.add(new JumpInsnNode(IFEQ, jmp)); + //return so the rest of the function doesnt get called + insnList.add(new InsnNode(RETURN)); + //add our label + insnList.add(jmp); + //insert the list of instructs at the top of the function + methodNode.instructions.insert(insnList); + } + + public static boolean drawToastHook() { + final EventDrawToast event = new EventDrawToast(); + Seppuku.INSTANCE.getEventManager().dispatchEvent(event); + return event.isCanceled(); + } +}