From 40432e083b11271cf3148b9c38156cf759436699 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 5 Sep 2023 23:22:33 -0400 Subject: Initial code dump. --- src/main/java/org/chrisoft/trashyaddon/Addon.java | 45 ++++++++++ .../trashyaddon/commands/BlockDataCommand.java | 59 +++++++++++++ .../trashyaddon/commands/EntityDataCommand.java | 47 ++++++++++ .../trashyaddon/commands/MapDumpCommand.java | 81 ++++++++++++++++++ .../trashyaddon/commands/MapTallyCommand.java | 99 ++++++++++++++++++++++ .../org/chrisoft/trashyaddon/hud/HudExample.java | 23 +++++ .../trashyaddon/modules/ModuleExample.java | 11 +++ 7 files changed, 365 insertions(+) create mode 100644 src/main/java/org/chrisoft/trashyaddon/Addon.java create mode 100644 src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java create mode 100644 src/main/java/org/chrisoft/trashyaddon/commands/EntityDataCommand.java create mode 100644 src/main/java/org/chrisoft/trashyaddon/commands/MapDumpCommand.java create mode 100644 src/main/java/org/chrisoft/trashyaddon/commands/MapTallyCommand.java create mode 100644 src/main/java/org/chrisoft/trashyaddon/hud/HudExample.java create mode 100644 src/main/java/org/chrisoft/trashyaddon/modules/ModuleExample.java (limited to 'src/main/java') diff --git a/src/main/java/org/chrisoft/trashyaddon/Addon.java b/src/main/java/org/chrisoft/trashyaddon/Addon.java new file mode 100644 index 0000000..2e4f504 --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/Addon.java @@ -0,0 +1,45 @@ +package org.chrisoft.trashyaddon; + +import org.chrisoft.trashyaddon.commands.BlockDataCommand; +import org.chrisoft.trashyaddon.commands.EntityDataCommand; +import com.mojang.logging.LogUtils; +import meteordevelopment.meteorclient.addons.MeteorAddon; +import meteordevelopment.meteorclient.commands.Commands; +import org.chrisoft.trashyaddon.commands.MapDumpCommand; +import org.chrisoft.trashyaddon.commands.MapTallyCommand; +import org.slf4j.Logger; + +public class Addon extends MeteorAddon { + public static final Logger LOG = LogUtils.getLogger(); + //public static final Category CATEGORY = new Category("Example"); + //public static final HudGroup HUD_GROUP = new HudGroup("Example"); + + @Override + public void onInitialize() { + LOG.info("Initializing Meteor Trash Addons"); + + // Modules + //Modules.get().add(new ModuleExample()); + + // Commands + Commands.add(new EntityDataCommand()); + Commands.add(new BlockDataCommand()); + Commands.add(new MapDumpCommand()); + Commands.add(new MapTallyCommand()); + + // HUD + //Hud.get().register(HudExample.INFO); + } + + /* + @Override + public void onRegisterCategories() { + Modules.registerCategory(CATEGORY); + } + */ + + @Override + public String getPackage() { + return "org.chrisoft.trashyaddon"; + } +} diff --git a/src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java b/src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java new file mode 100644 index 0000000..185de2e --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java @@ -0,0 +1,59 @@ +package org.chrisoft.trashyaddon.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.commands.Command; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.RaycastContext; +import net.minecraft.command.CommandSource; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.util.math.Box; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; + +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +public class BlockDataCommand extends Command { + private final MinecraftClient mc = MinecraftClient.getInstance(); + public BlockDataCommand() { + super("bd", "Dump client side data of targeted block."); + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder.executes(context -> { + double RANGE = 5; + Entity player = mc.cameraEntity; + Vec3d rot = player.getRotationVec(mc.getTickDelta()); + Vec3d min = player.getCameraPosVec(mc.getTickDelta()); + Vec3d max = min.add(rot.multiply(RANGE)); + RaycastContext rc = new RaycastContext(min, max, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, player); + BlockHitResult bh = mc.world.raycast(rc); + if (bh == null) { + error("no block picked"); + return 100; + } + BlockPos bp = bh.getBlockPos(); + BlockState bs = mc.world.getBlockState(bp); + if (bs == null) + { + error("no block state"); + return 100; + } + info(Text.literal("block is ").append(bs.getBlock().getName())); + BlockEntity be = mc.world.getBlockEntity(bp); + if (be == null) + { + error("block has no block entity"); + return SINGLE_SUCCESS; + } + NbtCompound bd = be.createNbt(); + info(bd.toString()); + + return SINGLE_SUCCESS; + }); + } +} diff --git a/src/main/java/org/chrisoft/trashyaddon/commands/EntityDataCommand.java b/src/main/java/org/chrisoft/trashyaddon/commands/EntityDataCommand.java new file mode 100644 index 0000000..562860a --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/commands/EntityDataCommand.java @@ -0,0 +1,47 @@ +package org.chrisoft.trashyaddon.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.commands.Command; +import net.minecraft.command.CommandSource; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.util.math.Box; +import net.minecraft.entity.projectile.ProjectileUtil; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.hit.EntityHitResult; + +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; + +public class EntityDataCommand extends Command { + private final MinecraftClient mc = MinecraftClient.getInstance(); + public EntityDataCommand() { + super("ed", "Erectile Dysfunction /s (Dump client side data of targeted entity.)"); + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder.executes(context -> { + //info("erectile dysfunction start"); + double RANGE = 5; + Entity player = mc.cameraEntity; + Vec3d rot = player.getRotationVec(mc.getTickDelta()); + Vec3d min = player.getCameraPosVec(mc.getTickDelta()); + Vec3d max = min.add(rot.multiply(RANGE)); + Box box = player.getBoundingBox().stretch(rot.multiply(RANGE)); + EntityHitResult eh = ProjectileUtil.raycast(player, min, max, box, x -> true ,RANGE * RANGE); + if (eh == null) { + error("no entity found"); + return 100; + } + Entity e = eh.getEntity(); + info(Text.literal("entity is ").append(e.getType().getName())); + NbtCompound d = new NbtCompound(); + e.writeNbt(d); + info(d.toString()); + + return SINGLE_SUCCESS; + }); + } +} diff --git a/src/main/java/org/chrisoft/trashyaddon/commands/MapDumpCommand.java b/src/main/java/org/chrisoft/trashyaddon/commands/MapDumpCommand.java new file mode 100644 index 0000000..667501a --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/commands/MapDumpCommand.java @@ -0,0 +1,81 @@ +package org.chrisoft.trashyaddon.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.commands.Command; +import net.minecraft.command.CommandSource; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.decoration.ItemFrameEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.item.FilledMapItem; +import net.minecraft.item.map.MapState; +import net.minecraft.util.Util; + +import java.io.File; +import java.io.FileOutputStream; +import java.nio.ByteOrder; +import java.util.zip.GZIPOutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Vector; +import java.util.OptionalInt; + +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; + +public class MapDumpCommand extends Command { + private final MinecraftClient mc = MinecraftClient.getInstance(); + public MapDumpCommand() { + super("md", "Dump all maps in view distance."); + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder.executes(context -> { + int nmaps = 0; + Vector bufs = new Vector<>(); + for (Entity e : mc.world.getEntities()) { + if (e.getType() != EntityType.ITEM_FRAME && e.getType() != EntityType.GLOW_ITEM_FRAME) + continue; + ItemFrameEntity ife = (ItemFrameEntity) e; + OptionalInt oid = ife.getMapId(); + if (oid.isEmpty()) + continue; + int id = oid.getAsInt(); + MapState mapState = FilledMapItem.getMapState(id, mc.world); + if (mapState == null) + continue; + String name = ife.getHeldItemStack().hasCustomName() ? ife.getHeldItemStack().getName().getString() : ""; + byte[] u8name = name.getBytes(StandardCharsets.UTF_8); + int bsz = 4 + 4 + u8name.length + 16384; + ByteBuffer buf = ByteBuffer.allocate(bsz); + buf.order(ByteOrder.LITTLE_ENDIAN); + buf.putInt(id); + buf.putInt(u8name.length); + buf.put(u8name); + buf.put(mapState.colors); + bufs.add(buf); + ++nmaps; + } + info("Maps found: " + nmaps); + try { + File dirpath = new File(MeteorClient.FOLDER, "mapman"); + if (!dirpath.isDirectory()) + dirpath.mkdir(); + File dumppath = new File(dirpath, "md-" + Util.getFormattedCurrentTime() + ".gz"); + FileOutputStream fo = new FileOutputStream(dumppath); + GZIPOutputStream output = new GZIPOutputStream(fo); + for (ByteBuffer buf : bufs) + output.write(buf.array()); + output.close(); + fo.close(); + info("Maps dumped to " + dumppath.toString()); + } + catch (Exception e) { + error("Cannot write output:" + e.getMessage()); + return 0; + } + return SINGLE_SUCCESS; + }); + } +} diff --git a/src/main/java/org/chrisoft/trashyaddon/commands/MapTallyCommand.java b/src/main/java/org/chrisoft/trashyaddon/commands/MapTallyCommand.java new file mode 100644 index 0000000..cce0687 --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/commands/MapTallyCommand.java @@ -0,0 +1,99 @@ +package org.chrisoft.trashyaddon.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.commands.Command; +import meteordevelopment.meteorclient.utils.player.ChatUtils; +import meteordevelopment.orbit.EventPriority; +import meteordevelopment.orbit.listeners.IListener; +import meteordevelopment.meteorclient.events.packets.InventoryEvent; +import net.minecraft.command.CommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.item.FilledMapItem; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.InventoryS2CPacket; +import net.minecraft.util.Util; + +import java.io.File; +import java.io.FileOutputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashSet; +import java.util.List; +import java.util.zip.GZIPOutputStream; + +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; + +public class MapTallyCommand extends Command { + IListener invListener; + HashSet ids = new HashSet<>(); + private final MinecraftClient mc = MinecraftClient.getInstance(); + public MapTallyCommand() { + super("mt", "Tally maps inside containers opened after execution of this command."); + invListener = null; + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder.then(literal("stop").executes(context -> { + if (invListener != null) { + info(ids.size() + " distinct map(s) total found."); + try { + ByteBuffer buf = ByteBuffer.allocate(4 * ids.size()); + buf.order(ByteOrder.LITTLE_ENDIAN); + for (int id : ids) + buf.putInt(id); + File dirpath = new File(MeteorClient.FOLDER, "mapman"); + if (!dirpath.isDirectory()) + dirpath.mkdir(); + File dumppath = new File(dirpath, "mt-" + Util.getFormattedCurrentTime() + ".gz"); + FileOutputStream fo = new FileOutputStream(dumppath); + GZIPOutputStream output = new GZIPOutputStream(fo); + output.write(buf.array()); + output.close(); + fo.close(); + info("Tally saved to " + dumppath.toString()); + } + catch (Exception e) { + error("Cannot write output:" + e.getMessage()); + return 0; + } + ids.clear(); + MeteorClient.EVENT_BUS.unsubscribe(invListener); + invListener = null; + } else error("Map tally not running."); + return SINGLE_SUCCESS; + })); + builder.executes(context -> { + if (invListener == null) { + ids.clear(); + invListener = new IListener() { + @Override + public void call(Object target) { + InventoryEvent e = (InventoryEvent)target; + List stacks = e.packet.getContents(); + if (stacks.size() == 46 || stacks.size() <= 36) { + // player inventory / 3x3 crafting table or invalid + return; + } + int nmaps = 0; + for (ItemStack s : stacks.subList(0, stacks.size() - 36)) { + if (s.getItem() instanceof FilledMapItem) { + ids.add(FilledMapItem.getMapId(s)); + ++nmaps; + } + } + info("Found " + nmaps + " map(s) in that container."); + } + @Override public Class getTarget() { return InventoryEvent.class; } + @Override public int getPriority() { return EventPriority.MEDIUM; } + @Override public boolean isStatic() { return false; } + }; + MeteorClient.EVENT_BUS.subscribe(invListener); + info("Open the containers that contain maps you wish to tally..."); + } + else error("Already tallying!"); + return SINGLE_SUCCESS; + }); + } +} diff --git a/src/main/java/org/chrisoft/trashyaddon/hud/HudExample.java b/src/main/java/org/chrisoft/trashyaddon/hud/HudExample.java new file mode 100644 index 0000000..eeaaac6 --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/hud/HudExample.java @@ -0,0 +1,23 @@ +package org.chrisoft.trashyaddon.hud; + +import org.chrisoft.trashyaddon.Addon; +import meteordevelopment.meteorclient.systems.hud.HudElement; +import meteordevelopment.meteorclient.systems.hud.HudElementInfo; +import meteordevelopment.meteorclient.systems.hud.HudRenderer; +import meteordevelopment.meteorclient.utils.render.color.Color; +import meteordevelopment.meteorclient.systems.hud.Hud; + +public class HudExample extends HudElement { + public static final HudElementInfo INFO = new HudElementInfo<>(Hud.GROUP, "example", "HUD element example.", HudExample::new); + + public HudExample() { + super(INFO); + } + + @Override + public void render(HudRenderer renderer) { + setSize(renderer.textWidth("Example element", true), renderer.textHeight(true)); + + renderer.text("Example element", x, y, Color.WHITE, true); + } +} diff --git a/src/main/java/org/chrisoft/trashyaddon/modules/ModuleExample.java b/src/main/java/org/chrisoft/trashyaddon/modules/ModuleExample.java new file mode 100644 index 0000000..216ad6b --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/modules/ModuleExample.java @@ -0,0 +1,11 @@ +package org.chrisoft.trashyaddon.modules; + +import org.chrisoft.trashyaddon.Addon; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.systems.modules.Categories; + +public class ModuleExample extends Module { + public ModuleExample() { + super(Categories.Misc, "example", "An example module in a custom category."); + } +} -- cgit v1.2.3