diff --git a/src/main/java/me/rigamortis/seppuku/impl/command/LastInvCommand.java b/src/main/java/me/rigamortis/seppuku/impl/command/LastInvCommand.java new file mode 100644 index 0000000..58109fd --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/command/LastInvCommand.java @@ -0,0 +1,43 @@ +package me.rigamortis.seppuku.impl.command; + +import me.rigamortis.seppuku.Seppuku; +import me.rigamortis.seppuku.api.command.Command; +import me.rigamortis.seppuku.api.event.render.EventRender2D; +import me.rigamortis.seppuku.impl.module.world.InfEnderChestModule; +import net.minecraft.client.Minecraft; +import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; + +/** + * @author Seth (riga) + */ +public final class LastInvCommand extends Command { + + public LastInvCommand() { + super("LastInv", new String[]{"EnderChest", "Echest", "Portable"}, "Opens your previous inventory if \"MoreInv\" is enabled.", "LastInv"); + } + + @Override + public void exec(String input) { + if (!this.clamp(input, 1, 1)) { + this.printUsage(); + return; + } + + Seppuku.INSTANCE.getEventManager().addEventListener(this); // subscribe to the event listener + } + + @Listener + public void render(EventRender2D event) { + final InfEnderChestModule mod = (InfEnderChestModule) Seppuku.INSTANCE.getModuleManager().find(InfEnderChestModule.class); + if(mod != null) { + if(mod.getScreen() != null) { + Minecraft.getMinecraft().displayGuiScreen(mod.getScreen()); + Seppuku.INSTANCE.logChat("Opening the last inventory."); + } else { + Seppuku.INSTANCE.logChat("Inventory already closed."); + } + } + Seppuku.INSTANCE.getEventManager().removeEventListener(this); + } + +} \ No newline at end of file diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java index ab2608a..34d04a8 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java @@ -68,6 +68,7 @@ public final class CommandManager { this.commandList.add(new SkullCommand()); this.commandList.add(new GiveCommand()); this.commandList.add(new CalcStrongholdCommand()); + this.commandList.add(new LastInvCommand()); //create commands for every value within every module loadValueCommands(); diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java index 6543a68..e3d9a67 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java @@ -158,6 +158,7 @@ public final class ModuleManager { add(new NoEffectsModule()); add(new NoEntityTraceModule()); add(new MultitaskModule()); + add(new InfEnderChestModule()); // p2w experience if (Seppuku.INSTANCE.getCapeManager().hasCape()) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/world/InfEnderChestModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/world/InfEnderChestModule.java new file mode 100644 index 0000000..3f1c328 --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/module/world/InfEnderChestModule.java @@ -0,0 +1,149 @@ +package me.rigamortis.seppuku.impl.module.world; + +import me.rigamortis.seppuku.Seppuku; +import me.rigamortis.seppuku.api.event.EventStageable; +import me.rigamortis.seppuku.api.event.minecraft.EventDisplayGui; +import me.rigamortis.seppuku.api.event.network.EventReceivePacket; +import me.rigamortis.seppuku.api.event.network.EventSendPacket; +import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate; +import me.rigamortis.seppuku.api.event.player.EventRightClickBlock; +import me.rigamortis.seppuku.api.module.Module; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.ClickType; +import net.minecraft.network.play.client.CPacketClickWindow; +import net.minecraft.network.play.client.CPacketCloseWindow; +import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock; +import net.minecraft.network.play.server.SPacketCloseWindow; +import net.minecraft.util.EnumHand; +import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; + +/** + * @author Seth (riga) + * @author noil + *

+ * this exploit was found originally by riga and polished up by noil. + * if you choose to use this code/exploit + * please include credit where credit is due. -noil + */ +public final class InfEnderChestModule extends Module { + + private GuiContainer screen; + + private boolean enderChestDesynced; + private boolean hideEnderChestGui = false; + + public InfEnderChestModule() { + super("InfEnderChest", new String[]{"EnderChest", "EChest", "InfiniteEChest", "InfiniteEnderChest", "InfEChest"}, "Replaces your inventory with an Ender Chest after you open one.", "NONE", -1, ModuleType.WORLD); + } + + @Override + public void onDisable() { + super.onDisable(); + if (Minecraft.getMinecraft().world != null) { + Minecraft.getMinecraft().player.connection.sendPacket(new CPacketCloseWindow(Minecraft.getMinecraft().player.inventoryContainer.windowId)); + this.resetBackupEnderChest(); + Seppuku.INSTANCE.logChat("Container closed."); + } + } + + @Listener + public void onUpdate(EventPlayerUpdate event) { + if (event.getStage() != EventStageable.EventStage.PRE) + return; + + final Minecraft mc = Minecraft.getMinecraft(); + if (mc.player == null) + return; + + if (this.enderChestDesynced && this.hideEnderChestGui) { + if (mc.currentScreen instanceof GuiContainer && !(mc.currentScreen instanceof GuiInventory)) { + mc.currentScreen = null; + this.hideEnderChestGui = false; + } + } + } + + @Listener + public void onRightClickBlock(EventRightClickBlock event) { + if (event.getPos() != null) { + final Block block = Minecraft.getMinecraft().world.getBlockState(event.getPos()).getBlock(); + if (block == Blocks.ENDER_CHEST) { + final float deltaX = (float) (event.getVec().x - (double) event.getPos().getX()); + final float deltaY = (float) (event.getVec().y - (double) event.getPos().getY()); + final float deltaZ = (float) (event.getVec().z - (double) event.getPos().getZ()); + Minecraft.getMinecraft().player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(event.getPos(), event.getFacing(), EnumHand.MAIN_HAND, deltaX, deltaY, deltaZ)); + this.enderChestDesynced = true; + } else if (block instanceof BlockContainer) { + this.resetBackupEnderChest(); + } + } + } + + @Listener + public void onDisplayGui(EventDisplayGui event) { + if (event.getScreen() instanceof GuiContainer && !(event.getScreen() instanceof GuiInventory)) { + this.screen = (GuiContainer) event.getScreen(); + } else if (event.getScreen() instanceof GuiInventory) { + if (this.enderChestDesynced && this.getScreen() != null) { + this.hideEnderChestGui = false; + event.setCanceled(true); + Minecraft.getMinecraft().displayGuiScreen(this.screen); + } + } + } + + @Listener + public void onReceivePacket(EventReceivePacket event) { + if (event.getStage() == EventStageable.EventStage.PRE) { + if (event.getPacket() instanceof SPacketCloseWindow) { + final SPacketCloseWindow packetCloseWindow = (SPacketCloseWindow) event.getPacket(); + if (this.getScreen() != null && packetCloseWindow.windowId == this.getScreen().inventorySlots.windowId) { + this.resetBackupEnderChest(); + Seppuku.INSTANCE.logChat("Container closed."); + } + } + } + } + + @Listener + public void onSendPacket(EventSendPacket event) { + if (event.getStage() == EventStageable.EventStage.PRE) { + if (event.getPacket() instanceof CPacketCloseWindow) { + final CPacketCloseWindow packetCloseWindow = (CPacketCloseWindow) event.getPacket(); + if (this.getScreen() != null && this.enderChestDesynced) { + event.setCanceled(true); + } + } else if (event.getPacket() instanceof CPacketClickWindow) { + final CPacketClickWindow packetClickWindow = (CPacketClickWindow) event.getPacket(); + if (packetClickWindow.getClickType().equals(ClickType.THROW) && this.enderChestDesynced && this.getScreen() != null) { // is desynced + this.hideEnderChestGui = true; + } else if (packetClickWindow.getClickType().equals(ClickType.THROW) && !this.enderChestDesynced) { // is not desynced + this.resetBackupEnderChest(); + } + } + } + } + + public boolean hasBackupEnderChest() { + return this.enderChestDesynced; + } + + public void resetBackupEnderChest() { + this.enderChestDesynced = false; + this.hideEnderChestGui = false; + this.setScreen(null); + } + + public GuiContainer getScreen() { + return screen; + } + + public void setScreen(GuiContainer screen) { + this.screen = screen; + } +} diff --git a/src/main/resources/seppuku_at.cfg b/src/main/resources/seppuku_at.cfg index 7fe4d47..e8bb793 100644 --- a/src/main/resources/seppuku_at.cfg +++ b/src/main/resources/seppuku_at.cfg @@ -114,4 +114,7 @@ public net.minecraft.network.play.client.CPacketCloseWindow field_149556_a public-f net.minecraft.util.text.TextComponentString field_150267_b # text #smallshield stuff public net.minecraft.client.renderer.ItemRenderer field_187471_h # equippedProgressOffHand - public net.minecraft.client.renderer.RenderGlobal field_72738_E # damagedBlocks \ No newline at end of file + public net.minecraft.client.renderer.RenderGlobal field_72738_E # damagedBlocks + public net.minecraft.network.play.server.SPacketCloseWindow field_148896_a # windowId + public net.minecraft.network.play.server.SPacketSetSlot field_149179_a # windowId + public net.minecraft.network.play.server.SPacketSetSlot field_149177_b # slot \ No newline at end of file