From 881cbd9bdb5b399d078e407c5e4301bf34d01e89 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Wed, 10 Jan 2024 17:24:33 +0100 Subject: chore: hack to have BSCV as interface static --- src/main/java/ftbsc/bscv/Boscovicino.java | 36 +++++-- src/main/java/ftbsc/bscv/ICommons.java | 3 +- .../java/ftbsc/bscv/commands/AbstractCommand.java | 3 +- src/main/java/ftbsc/bscv/commands/Cursor.java | 2 + src/main/java/ftbsc/bscv/commands/ItemCommand.java | 4 + src/main/java/ftbsc/bscv/commands/ModCommands.java | 8 +- src/main/java/ftbsc/bscv/commands/Teleport.java | 4 + .../java/ftbsc/bscv/modules/AbstractModule.java | 5 +- src/main/java/ftbsc/bscv/modules/QuickModule.java | 3 +- src/main/java/ftbsc/bscv/modules/defense/Aura.java | 12 +-- .../java/ftbsc/bscv/modules/hud/ActiveModules.java | 3 +- .../java/ftbsc/bscv/modules/hud/Coordinates.java | 2 +- .../java/ftbsc/bscv/modules/hud/EntityList.java | 3 +- .../java/ftbsc/bscv/modules/hud/Highlighter.java | 12 +-- .../java/ftbsc/bscv/modules/hud/InfoDisplay.java | 116 ++++++++++----------- .../java/ftbsc/bscv/modules/hud/PlayerList.java | 1 + .../java/ftbsc/bscv/modules/motion/GuiMove.java | 7 +- .../ftbsc/bscv/modules/motion/VanillaFlight.java | 36 +++---- .../ftbsc/bscv/modules/network/PacketLogger.java | 24 ++--- .../java/ftbsc/bscv/modules/self/AntiHunger.java | 1 + .../ftbsc/bscv/modules/self/AutoDisconnect.java | 1 + .../java/ftbsc/bscv/modules/self/AutoFish.java | 20 ++-- .../java/ftbsc/bscv/modules/self/AutoTool.java | 47 ++++----- .../java/ftbsc/bscv/modules/self/FastInteract.java | 4 - src/main/java/ftbsc/bscv/modules/self/Freecam.java | 53 +++++----- .../java/ftbsc/bscv/modules/self/HandChanger.java | 12 +-- src/main/java/ftbsc/bscv/modules/vision/Chams.java | 2 - .../java/ftbsc/bscv/modules/vision/Fullbright.java | 11 +- .../java/ftbsc/bscv/modules/vision/StorageESP.java | 2 - src/main/java/ftbsc/bscv/system/Bindings.java | 11 +- src/main/java/ftbsc/bscv/system/Macros.java | 2 +- 31 files changed, 232 insertions(+), 218 deletions(-) diff --git a/src/main/java/ftbsc/bscv/Boscovicino.java b/src/main/java/ftbsc/bscv/Boscovicino.java index b104f96..cfb151b 100644 --- a/src/main/java/ftbsc/bscv/Boscovicino.java +++ b/src/main/java/ftbsc/bscv/Boscovicino.java @@ -26,6 +26,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; @Mod(Boscovicino.MOD_ID) public class Boscovicino implements ICommons { @@ -35,9 +37,6 @@ public class Boscovicino implements ICommons { private final CommandDispatcher dispatcher = new CommandDispatcher<>(); - private static Boscovicino INSTANCE; - public static Boscovicino getInstance() { return INSTANCE; } - public final ForgeConfigSpec spec; public final Modules modules; @@ -48,23 +47,27 @@ public class Boscovicino implements ICommons { @SuppressWarnings({"unused", "FieldCanBeLocal"}) // it just needs to exist to be used by player private final Ruler ruler; //TODO remove - public Boscovicino() throws IOException { + public Boscovicino() throws IOException, ReflectiveOperationException { + // add listener FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onSetupComplete); + // initialise config ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder(); CommandDispatcher dp = this.dispatcher; + // load modules this.modules = new Modules(cfg, dp); this.modules.load(); - this.modules.finish(); this.ruler = new Ruler(); //TODO remove + // macros and bindings ForgeConfigSpec.Builder bindingSpec = new ForgeConfigSpec.Builder(); this.bindings = new Bindings(bindingSpec); this.macros = new Macros(this); + //friends ForgeConfigSpec.Builder friendSpec = new ForgeConfigSpec.Builder(); this.friends = new Friends(friendSpec, dp); @@ -77,8 +80,27 @@ public class Boscovicino implements ICommons { // register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); - // create instance - INSTANCE = this; + // set the ICommons instance with reflection magic + // should go without saying, but don't access BSCV's members before loading is complete + Field instance = ICommons.class.getDeclaredField("BSCV"); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setInt(instance, instance.getModifiers() & ~Modifier.FINAL); //make non final + instance.set(null, this); //set instance + modifiersField.setInt(instance, instance.getModifiers() & Modifier.FINAL); //make it final again + } + + /** + * Fake constructor, only used to set the temporary value of {@link ICommons#BSCV}. + * The sole purpose of this is to make the language server shut up about null pointer exceptions. + * @param ignored dummy parameter to distinguish from real constructor. + */ + Boscovicino(boolean ignored) { + this.modules = null; + this.ruler = null; + this.bindings = null; + this.macros = null; + this.friends = null; + this.spec = null; } public static void log(String message, Object... args) { diff --git a/src/main/java/ftbsc/bscv/ICommons.java b/src/main/java/ftbsc/bscv/ICommons.java index 1abe0e5..3a1e61b 100644 --- a/src/main/java/ftbsc/bscv/ICommons.java +++ b/src/main/java/ftbsc/bscv/ICommons.java @@ -3,5 +3,6 @@ package ftbsc.bscv; import net.minecraft.client.Minecraft; public interface ICommons { - public static final Minecraft MC = Minecraft.getInstance(); + Minecraft MC = Minecraft.getInstance(); + Boscovicino BSCV = new Boscovicino(true); //actually overwritten via reflection with the real instance } diff --git a/src/main/java/ftbsc/bscv/commands/AbstractCommand.java b/src/main/java/ftbsc/bscv/commands/AbstractCommand.java index 5fc1651..cf2f7fe 100644 --- a/src/main/java/ftbsc/bscv/commands/AbstractCommand.java +++ b/src/main/java/ftbsc/bscv/commands/AbstractCommand.java @@ -6,7 +6,6 @@ import java.util.List; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.ICommand; import net.minecraft.command.CommandSource; @@ -19,7 +18,7 @@ public abstract class AbstractCommand implements ICommand, ICommons { } public CommandDispatcher getDispatcher() { - return Boscovicino.getInstance().modules.getDispatcher(); + return BSCV.modules.getDispatcher(); } public List> subcommands() { diff --git a/src/main/java/ftbsc/bscv/commands/Cursor.java b/src/main/java/ftbsc/bscv/commands/Cursor.java index a54433d..afb8ade 100644 --- a/src/main/java/ftbsc/bscv/commands/Cursor.java +++ b/src/main/java/ftbsc/bscv/commands/Cursor.java @@ -21,6 +21,8 @@ public class Cursor extends AbstractCommand { .then( Commands.literal("info") .executes(ctx -> { + if (MC.level == null || MC.hitResult == null) + return 0; switch (MC.hitResult.getType()) { case BLOCK: BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; diff --git a/src/main/java/ftbsc/bscv/commands/ItemCommand.java b/src/main/java/ftbsc/bscv/commands/ItemCommand.java index e1e1b80..cbc7ede 100644 --- a/src/main/java/ftbsc/bscv/commands/ItemCommand.java +++ b/src/main/java/ftbsc/bscv/commands/ItemCommand.java @@ -24,6 +24,8 @@ public class ItemCommand extends AbstractCommand { .then( Commands.literal("damage") .executes(ctx -> { + if(MC.player == null) + return 0; Slot slot = Inventory.hotbar(MC.player).get(MC.player.inventory.selected); if (!slot.hasItem()) return 0; log( @@ -49,6 +51,8 @@ public class ItemCommand extends AbstractCommand { ) ) .executes(ctx -> { + if(MC.player == null) + return 0; Slot slot = Inventory.hotbar(MC.player).get(MC.player.inventory.selected); if (!slot.hasItem()) return 0; log(slot.getItem().toString()); diff --git a/src/main/java/ftbsc/bscv/commands/ModCommands.java b/src/main/java/ftbsc/bscv/commands/ModCommands.java index b2836c4..1532def 100644 --- a/src/main/java/ftbsc/bscv/commands/ModCommands.java +++ b/src/main/java/ftbsc/bscv/commands/ModCommands.java @@ -22,7 +22,7 @@ public class ModCommands extends AbstractCommand { .then( Commands.literal("off") .executes(ctx -> { - for (IModule mod : Boscovicino.getInstance().modules.mods) { + for (IModule mod : BSCV.modules.mods) { if (mod.isEnabled()) { mod.disable(); } @@ -33,7 +33,7 @@ public class ModCommands extends AbstractCommand { .then( Commands.literal("re-enable") // this is to fix some jankyness in event subscriptions .executes(ctx -> { - for (IModule mod : Boscovicino.getInstance().modules.mods) { + for (IModule mod : BSCV.modules.mods) { if (mod.isEnabled()) { mod.disable(); mod.enable(); @@ -43,8 +43,8 @@ public class ModCommands extends AbstractCommand { }) ) .executes(ctx -> { - String mods = Boscovicino.getInstance().modules.mods.stream() - .map(x -> x.getName()) + String mods = BSCV.modules.mods.stream() + .map(ILoadable::getName) .collect(Collectors.joining(",")); Boscovicino.log("[ %s ]", mods); return 1; diff --git a/src/main/java/ftbsc/bscv/commands/Teleport.java b/src/main/java/ftbsc/bscv/commands/Teleport.java index 698d94c..752118a 100644 --- a/src/main/java/ftbsc/bscv/commands/Teleport.java +++ b/src/main/java/ftbsc/bscv/commands/Teleport.java @@ -23,6 +23,8 @@ public class Teleport extends AbstractCommand { .then( Commands.argument("distance", DoubleArgumentType.doubleArg()) .executes( ctx -> { + if(MC.player == null) + return 0; double distance = ctx.getArgument("distance", Double.class); MC.player.setPos( MC.player.position().x, @@ -41,6 +43,8 @@ public class Teleport extends AbstractCommand { .then( Commands.argument("z", DoubleArgumentType.doubleArg()) .executes( ctx -> { + if(MC.player == null) + return 0; double x = ctx.getArgument("x", Double.class); double y = ctx.getArgument("y", Double.class); double z = ctx.getArgument("z", Double.class); diff --git a/src/main/java/ftbsc/bscv/modules/AbstractModule.java b/src/main/java/ftbsc/bscv/modules/AbstractModule.java index aa992b4..c7665e3 100644 --- a/src/main/java/ftbsc/bscv/modules/AbstractModule.java +++ b/src/main/java/ftbsc/bscv/modules/AbstractModule.java @@ -2,7 +2,6 @@ package ftbsc.bscv.modules; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.BoolArgumentType; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.ICommons; import ftbsc.bscv.api.IModule; import net.minecraft.command.CommandSource; @@ -27,12 +26,12 @@ public abstract class AbstractModule implements IModule, ICommons { @Override public ForgeConfigSpec.Builder getConfigBuilder() { - return Boscovicino.getInstance().modules.getCfgBuilder(); + return BSCV.modules.getCfgBuilder(); } @Override public CommandDispatcher getDispatcher() { - return Boscovicino.getInstance().modules.getDispatcher(); + return BSCV.modules.getDispatcher(); } public AbstractModule() { diff --git a/src/main/java/ftbsc/bscv/modules/QuickModule.java b/src/main/java/ftbsc/bscv/modules/QuickModule.java index 648b020..0fd0399 100644 --- a/src/main/java/ftbsc/bscv/modules/QuickModule.java +++ b/src/main/java/ftbsc/bscv/modules/QuickModule.java @@ -1,6 +1,5 @@ package ftbsc.bscv.modules; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.tools.Keybind; import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.InputMappings; @@ -14,7 +13,7 @@ public abstract class QuickModule extends AbstractModule { public static final int UNBOUND = InputMappings.UNKNOWN.getValue(); - private class ToggleHook { + private static class ToggleHook { private final KeyBinding key; private final QuickModule mod; private boolean debounce; diff --git a/src/main/java/ftbsc/bscv/modules/defense/Aura.java b/src/main/java/ftbsc/bscv/modules/defense/Aura.java index 79c16fc..a2f9894 100644 --- a/src/main/java/ftbsc/bscv/modules/defense/Aura.java +++ b/src/main/java/ftbsc/bscv/modules/defense/Aura.java @@ -2,7 +2,6 @@ package ftbsc.bscv.modules.defense; import com.google.auto.service.AutoService; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.QuickModule; import ftbsc.bscv.modules.self.AutoTool; @@ -24,18 +23,13 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) public class Aura extends QuickModule { - private enum LookType { + public enum LookType { NONE, PACKET, ONCE, // RESET } - @Override - protected int getDefaultKey() { - return UNBOUND; - } - public final ForgeConfigSpec.ConfigValue reach; public final ForgeConfigSpec.ConfigValue strenght; public final ForgeConfigSpec.ConfigValue tool; @@ -105,7 +99,7 @@ public class Aura extends QuickModule { @Override public void enable() { super.enable(); - this.autotool = (AutoTool) Boscovicino.getInstance().modules.get(AutoTool.class); + this.autotool = (AutoTool) BSCV.modules.get(AutoTool.class); } private void lookAtHidden(EntityAnchorArgument.Type anchor, Vector3d target) { @@ -139,7 +133,7 @@ public class Aura extends QuickModule { if (!this.neutral.get() && e.getClassification(false).isFriendly()) continue; if (e instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) e; - if (Boscovicino.getInstance().friends.isFriend(player.getGameProfile().getId())) { + if (BSCV.friends.isFriend(player.getGameProfile().getId())) { continue; } } diff --git a/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java b/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java index 0886282..5a4c11f 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java +++ b/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java @@ -1,7 +1,6 @@ package ftbsc.bscv.modules.hud; import com.google.auto.service.AutoService; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.api.IModule; import ftbsc.bscv.modules.HudModule; @@ -18,7 +17,7 @@ public class ActiveModules extends HudModule { if (event.getType() != ElementType.TEXT) return; if (this.shouldHide()) return; int offset = 0; - for (IModule m : Boscovicino.getInstance().modules.mods) { + for (IModule m : BSCV.modules.mods) { if (m.isEnabled() && !m.getGroup().equalsIgnoreCase("HUD")) { TextBuilder() .txt(this.affixed(m.getName())) diff --git a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java index 1cd37db..7ebfffa 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java +++ b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java @@ -26,7 +26,7 @@ public class Coordinates extends HudModule { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (event.phase == Phase.START) return; - if (MC.player == null) return; + if (MC.player == null || MC.level == null) return; this.posX = MC.player.getX(); this.posY = MC.player.getY(); diff --git a/src/main/java/ftbsc/bscv/modules/hud/EntityList.java b/src/main/java/ftbsc/bscv/modules/hud/EntityList.java index e3fb69b..364fc1e 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/EntityList.java +++ b/src/main/java/ftbsc/bscv/modules/hud/EntityList.java @@ -38,6 +38,7 @@ public class EntityList extends HudModule { @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent event) { if (event.getType() != ElementType.TEXT) return; + if (MC.level == null) return; if (this.shouldHide()) return; List entities = new ArrayList<>(); @@ -65,7 +66,7 @@ public class EntityList extends HudModule { .y(this.y.get() + offset) .scale(this.scale.get()) .style( - this.search.get().length() > 0 && u.toLowerCase().contains(this.search.get().toLowerCase()) + this.search.get().isEmpty() && u.toLowerCase().contains(this.search.get().toLowerCase()) ? Style.EMPTY.withBold(true).withColor(Color.fromLegacyFormat(TextFormatting.GOLD)) : Style.EMPTY.withColor(Color.fromLegacyFormat(TextFormatting.WHITE)) ) diff --git a/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java b/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java index f5cc542..91858ac 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java +++ b/src/main/java/ftbsc/bscv/modules/hud/Highlighter.java @@ -1,30 +1,22 @@ package ftbsc.bscv.modules.hud; +import com.google.auto.service.AutoService; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; - +import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.tools.Inventory; import ftbsc.bscv.tools.Setting; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.inventory.container.Slot; -import net.minecraft.item.EnchantedBookItem; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; import net.minecraftforge.client.event.GuiContainerEvent; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.gui.GuiUtils; -import java.util.ArrayList; -import java.util.List; import java.util.regex.Pattern; -import ftbsc.bscv.api.ILoadable; -import com.google.auto.service.AutoService; - @AutoService(ILoadable.class) public class Highlighter extends AbstractModule { diff --git a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java index 2df6b10..1703ffd 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java +++ b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java @@ -25,13 +25,13 @@ import static ftbsc.bscv.tools.Text.TextBuilder; @AutoService(ILoadable.class) public class InfoDisplay extends HudModule { - private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0); - private double instant_speed = 0.0; - private double average_speed = 0.0; - private double instant_tps = 0.0; - private int instant_ping = 0; - private Queue speed_history = new LinkedList<>(); - private Queue tps_history = new LinkedList<>(); + private Vector3d lastPosition = new Vector3d(0.0, 0.0, 0.0); + private double instantSpeed = 0.0; + private double averageSpeed = 0.0; + private double instantTps = 0.0; + private int instantPing = 0; + private final Queue speedHistory = new LinkedList<>(); + private final Queue tpsHistory = new LinkedList<>(); public final ForgeConfigSpec.ConfigValue logo; public final ForgeConfigSpec.ConfigValue speed; @@ -43,16 +43,16 @@ public class InfoDisplay extends HudModule { // public final ForgeConfigSpec.ConfigValue biome; // public final ForgeConfigSpec.ConfigValue light; // public final ForgeConfigSpec.ConfigValue saturation; - // public final ForgeConfigSpec.ConfigValue system_time; - // public final ForgeConfigSpec.ConfigValue damage_value; - // public final ForgeConfigSpec.ConfigValue effects_list; - // public final ForgeConfigSpec.ConfigValue item_quantity; - // public final ForgeConfigSpec.ConfigValue client_chunk_size; + // public final ForgeConfigSpec.ConfigValue systemTime; + // public final ForgeConfigSpec.ConfigValue damageValue; + // public final ForgeConfigSpec.ConfigValue effectsList; + // public final ForgeConfigSpec.ConfigValue itemQuantity; + // public final ForgeConfigSpec.ConfigValue clientChunkSize; - public final ForgeConfigSpec.ConfigValue hide_effects; + public final ForgeConfigSpec.ConfigValue hideEffects; - public final ForgeConfigSpec.ConfigValue tps_sample_size; - public final ForgeConfigSpec.ConfigValue speed_sample_size; + public final ForgeConfigSpec.ConfigValue tpsSampleSize; + public final ForgeConfigSpec.ConfigValue speedSampleSize; public InfoDisplay() { super(); @@ -99,20 +99,20 @@ public class InfoDisplay extends HudModule { .fallback(true) .build(this); - this.hide_effects = Setting.Bool.builder() + this.hideEffects = Setting.Bool.builder() .name("hide-effects") .comment("hide effect icons on top right corner") .fallback(false) .build(this); - this.tps_sample_size = Setting.Number.builder() + this.tpsSampleSize = Setting.Number.builder() .min(2) .name("tps-sample-size") .comment("TPS samples to store (1 taken each second)") .fallback(60) .build(this); - this.speed_sample_size = Setting.Number.builder() + this.speedSampleSize = Setting.Number.builder() .min(2) .name("speed-sample-size") .comment("instant speed samples to store (1 taken each tick)") @@ -124,59 +124,59 @@ public class InfoDisplay extends HudModule { public void onTick(TickEvent.ClientTickEvent event) { if (!this.speed.get()) return; if (event.phase == Phase.START) return; - if (MC.player != null) { - this.instant_speed = this.last_position.distanceTo(MC.player.position()); - this.last_position = MC.player.position(); + if (MC.player != null && MC.getConnection() != null) { + this.instantSpeed = this.lastPosition.distanceTo(MC.player.position()); + this.lastPosition = MC.player.position(); NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( MC.player.getGameProfile().getId() ); if (info != null) { // bungeecord switching makes this null for a second - this.instant_ping = info.getLatency(); + this.instantPing = info.getLatency(); } } else { - this.instant_speed = 0.0; - this.instant_ping = 0; + this.instantSpeed = 0.0; + this.instantPing = 0; } - this.speed_history.offer(this.instant_speed); - while (this.speed_history.size() >= this.speed_sample_size.get()) { - this.speed_history.poll(); + this.speedHistory.offer(this.instantSpeed); + while (this.speedHistory.size() >= this.speedSampleSize.get()) { + this.speedHistory.poll(); } double buf = 0.0; - for (double v : this.speed_history) { buf += v; } - this.average_speed = buf / this.speed_history.size(); + for (double v : this.speedHistory) { buf += v; } + this.averageSpeed = buf / this.speedHistory.size(); - if (this.last_fps_string != MC.fpsString) { - this.last_fps_string = MC.fpsString; - this.curr_fps = this.last_fps_string.split(" ")[0]; + if (this.lastFpsString.equals(MC.fpsString)) { + this.lastFpsString = MC.fpsString; + this.currFps = this.lastFpsString.split(" ")[0]; } } @SubscribeEvent public void onPacket(PacketEvent.Incoming event) { if (event.packet instanceof SUpdateTimePacket) { - this.tps_history.offer(System.currentTimeMillis()); - while (this.tps_history.size() > this.tps_sample_size.get()) { - this.tps_history.poll(); + this.tpsHistory.offer(System.currentTimeMillis()); + while (this.tpsHistory.size() > this.tpsSampleSize.get()) { + this.tpsHistory.poll(); } - double positive_time = 0.; - double last_time = 0; - for (long t : this.tps_history) { - if (last_time != 0) { - double delta = (double) (t - last_time) / 1000.; - positive_time += Math.max(delta, 1.); + double positiveTime = 0.; + double lastTime = 0; + for (long t : this.tpsHistory) { + if (lastTime != 0) { + double delta = (double) (t - lastTime) / 1000.; + positiveTime += Math.max(delta, 1.); } - last_time = t; + lastTime = t; } - this.instant_tps = 20 / (positive_time / (this.tps_history.size() - 1)); + this.instantTps = 20 / (positiveTime / (this.tpsHistory.size() - 1)); } } @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent event) { if (event.getType() == ElementType.POTION_ICONS) { - if (this.hide_effects.get() && event.isCancelable()) { + if (this.hideEffects.get() && event.isCancelable()) { event.setCanceled(true); } } @@ -195,7 +195,7 @@ public class InfoDisplay extends HudModule { .style(Style.EMPTY.withColor(Color.fromRgb(12542314)).withBold(true)) .scale(scale * 4.0) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale * 4.0; + offset += (int) (MC.font.lineHeight * scale * 4.0); } long day = 0; @@ -207,46 +207,46 @@ public class InfoDisplay extends HudModule { if (this.fps.get()) { TextBuilder() - .txt(this.affixed("fps: %s", this.curr_fps)) + .txt(this.affixed("fps: %s", this.currFps)) .anchor(this.anchor.get()) .x(this.x.get()) .y(this.y.get() + offset) .scale(scale) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale; + offset += (int) (MC.font.lineHeight * scale); } if (this.ping.get()) { TextBuilder() - .txt(this.affixed("ping: %d", this.instant_ping)) + .txt(this.affixed("ping: %d", this.instantPing)) .anchor(this.anchor.get()) .x(this.x.get()) .y(this.y.get() + offset) .scale(scale) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale; + offset += (int) (MC.font.lineHeight * scale); } if (this.tps.get()) { TextBuilder() - .txt(this.affixed("tps: %.1f", this.instant_tps)) + .txt(this.affixed("tps: %.1f", this.instantTps)) .anchor(this.anchor.get()) .x(this.x.get()) .y(this.y.get() + offset) .scale(scale) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale; + offset += (int) (MC.font.lineHeight * scale); } if (this.speed.get()) { TextBuilder() - .txt(this.affixed("speed: %.1f [%.1f] m/s", this.instant_speed * 20.0, this.average_speed * 20.0)) + .txt(this.affixed("speed: %.1f [%.1f] m/s", this.instantSpeed * 20.0, this.averageSpeed * 20.0)) .anchor(this.anchor.get()) .x(this.x.get()) .y(this.y.get() + offset) .scale(scale) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale; + offset += (int) (MC.font.lineHeight * scale); } if (this.age.get()) { @@ -257,10 +257,11 @@ public class InfoDisplay extends HudModule { .y(this.y.get() + offset) .scale(scale) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale; + offset += (int) (MC.font.lineHeight * scale); } if (this.time.get()) { + int TPS = 20; TextBuilder() .txt(this.affixed("time: %d/%d (%s)", (time / TPS), this.getNextStep(time) / TPS, this.getTimePhase(time) )) .anchor(this.anchor.get()) @@ -268,12 +269,12 @@ public class InfoDisplay extends HudModule { .y(this.y.get() + offset) .scale(scale) .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight * scale; + offset += (int) (MC.font.lineHeight * scale); } } - private String last_fps_string; - private String curr_fps = "0"; + private String lastFpsString; + private String currFps = "0"; // TPS utils @@ -301,5 +302,4 @@ public class InfoDisplay extends HudModule { return 5500; } - private final int TPS = 20; } diff --git a/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java b/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java index a0cdd6b..ce5399a 100644 --- a/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java +++ b/src/main/java/ftbsc/bscv/modules/hud/PlayerList.java @@ -18,6 +18,7 @@ public class PlayerList extends HudModule { public void onRenderOverlay(RenderGameOverlayEvent event) { if (event.getType() != ElementType.TEXT) return; if (this.shouldHide()) return; + if (MC.level == null) return; int offset = 0; for (Entity e : MC.level.entitiesForRendering()) { diff --git a/src/main/java/ftbsc/bscv/modules/motion/GuiMove.java b/src/main/java/ftbsc/bscv/modules/motion/GuiMove.java index 3732e37..5b7079b 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/GuiMove.java +++ b/src/main/java/ftbsc/bscv/modules/motion/GuiMove.java @@ -2,7 +2,6 @@ package ftbsc.bscv.modules.motion; import com.google.auto.service.AutoService; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.patches.BackgroundPatch.RenderBackgroundEvent; @@ -30,7 +29,7 @@ public class GuiMove extends AbstractModule { public final ForgeConfigSpec.ConfigValue background; - private AutoWalk autoWalk_mod; + private AutoWalk autoWalkMod; public GuiMove() { super(); @@ -44,7 +43,7 @@ public class GuiMove extends AbstractModule { @Override public void enable() { - this.autoWalk_mod = (AutoWalk) Boscovicino.getInstance().modules.get(AutoWalk.class); + this.autoWalkMod = (AutoWalk) BSCV.modules.get(AutoWalk.class); super.enable(); } @@ -72,7 +71,7 @@ public class GuiMove extends AbstractModule { private void forceMovementTick(MovementInput input) { // TODO can we patch to make this always happen instead of duplicating code? - input.up = this.autoWalk_mod.isEnabled() || this.isKeyDown(MC.options.keyUp); + input.up = this.autoWalkMod.isEnabled() || this.isKeyDown(MC.options.keyUp); input.down = this.isKeyDown(MC.options.keyDown); input.left = this.isKeyDown(MC.options.keyLeft); input.right = this.isKeyDown(MC.options.keyRight); diff --git a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java index 0d1d736..66c94be 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java +++ b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java @@ -16,7 +16,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) public class VanillaFlight extends QuickModule { - private enum AntikickMode { + public enum AntiKickMode { NONE, PACKET, FORCED @@ -27,10 +27,10 @@ public class VanillaFlight extends QuickModule { public final ForgeConfigSpec.ConfigValue force; public final ForgeConfigSpec.ConfigValue drift; public final ForgeConfigSpec.ConfigValue speed; - public final ForgeConfigSpec.ConfigValue antikick; - public final ForgeConfigSpec.ConfigValue antikick_magnitude; - public final ForgeConfigSpec.ConfigValue antikick_cycle; - public final ForgeConfigSpec.ConfigValue antikick_duration; + public final ForgeConfigSpec.ConfigValue antikick; + public final ForgeConfigSpec.ConfigValue antikickMagnitude; + public final ForgeConfigSpec.ConfigValue antikickCycle; + public final ForgeConfigSpec.ConfigValue antikickDuration; private int tick = 0; @@ -56,20 +56,20 @@ public class VanillaFlight extends QuickModule { .comment("flight speed to set") .build(this); - this.antikick = Setting.Switch.builder(AntikickMode.class) - .fallback(AntikickMode.PACKET) + this.antikick = Setting.Switch.builder(AntiKickMode.class) + .fallback(AntiKickMode.PACKET) .name("antikick") .comment("prevent vanilla flight kick by descending") .build(this); - this.antikick_magnitude = Setting.Decimal.builder() + this.antikickMagnitude = Setting.Decimal.builder() .min(0.) .fallback(0.032) .name("magnitude") .comment("magnitude of antikick push") .build(this); - this.antikick_cycle = Setting.Number.builder() + this.antikickCycle = Setting.Number.builder() .min(1) .max(80) .fallback(70) @@ -77,7 +77,7 @@ public class VanillaFlight extends QuickModule { .comment("how often to run antikick routine") .build(this); - this.antikick_duration = Setting.Number.builder() + this.antikickDuration = Setting.Number.builder() .min(1) .max(80) .fallback(5) @@ -86,7 +86,7 @@ public class VanillaFlight extends QuickModule { .build(this); } - private long last_event = 0; + private long lastEvent = 0; private boolean couldFlyBefore = false; private float flyingSpeedBefore = 0.05f; @@ -113,11 +113,11 @@ public class VanillaFlight extends QuickModule { MC.player.setDeltaMovement(Vector3d.ZERO); } - this.tick = ( this.tick + 1 ) % this.antikick_cycle.get(); + this.tick = ( this.tick + 1 ) % this.antikickCycle.get(); Vector3d pos = MC.player.position(); - if (this.tick == 0 && this.antikick.get() == AntikickMode.PACKET) { - MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z); + if (this.tick == 0 && this.antikick.get() == AntiKickMode.PACKET) { + MC.player.setPos(pos.x, pos.y - this.antikickMagnitude.get(), pos.z); } } @@ -126,11 +126,11 @@ public class VanillaFlight extends QuickModule { long now = System.currentTimeMillis(); switch (this.antikickState) { case COOLDOWN: - if (now - this.last_event < this.antikick_cycle.get() * MS_PER_TICK) break; - this.last_event = now; + if (now - this.lastEvent < this.antikickCycle.get() * MS_PER_TICK) break; + this.lastEvent = now; this.antikickState = AntikickState.ACTIVE; // don't break and also run ACTIVE case ACTIVE: - if (now - this.last_event > this.antikick_duration.get() * MS_PER_TICK) { + if (now - this.lastEvent > this.antikickDuration.get() * MS_PER_TICK) { this.antikickState = AntikickState.COOLDOWN; break; } @@ -139,7 +139,7 @@ public class VanillaFlight extends QuickModule { event.packet instanceof CPlayerPacket.PositionRotationPacket ) { CPlayerPacket packet = (CPlayerPacket) event.packet; - packet.y = packet.y - this.antikick_magnitude.get(); + packet.y = packet.y - this.antikickMagnitude.get(); } } } diff --git a/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java b/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java index e0b8431..35db509 100644 --- a/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java +++ b/src/main/java/ftbsc/bscv/modules/network/PacketLogger.java @@ -59,7 +59,7 @@ public class PacketLogger extends QuickModule { @SubscribeEvent public void onPacketOutgoing(PacketEvent.Outgoing event) { try { - this.capture.add(this.packet_to_json(event.packet, this.pretty_time())); // get send time here + this.capture.add(this.packetToJson(event.packet, this.prettyTime())); // get send time here } catch (IllegalAccessException e) { Boscovicino.LOGGER.warn("Could not process fields of packet {}", event.packet.toString()); } @@ -68,7 +68,7 @@ public class PacketLogger extends QuickModule { @SubscribeEvent public void onPacketIncoming(PacketEvent.Incoming event) { try { - this.capture.add(this.packet_to_json(event.packet, this.pretty_time())); // get recv time here + this.capture.add(this.packetToJson(event.packet, this.prettyTime())); // get recv time here } catch (IllegalAccessException e) { Boscovicino.LOGGER.warn("Could not process fields of packet {}", event.packet.toString()); } @@ -88,7 +88,7 @@ public class PacketLogger extends QuickModule { } } - private JsonElement packet_to_json(IPacket packet, double time) throws IllegalAccessException { + private JsonElement packetToJson(IPacket packet, double time) throws IllegalAccessException { Class clazz = packet.getClass(); List classNames = new ArrayList<>(); JsonObject fields = new JsonObject(); @@ -97,7 +97,7 @@ public class PacketLogger extends QuickModule { for (Field field : clazz.getDeclaredFields()) { if (!Modifier.isStatic(field.getModifiers())) { field.setAccessible(true); - fields.add(field.getName(), this.format_value(field.get(packet))); // TODO deobfuscate field.getName() + fields.add(field.getName(), this.formatValue(field.get(packet))); // TODO deobfuscate field.getName() } } clazz = clazz.getSuperclass(); @@ -105,12 +105,12 @@ public class PacketLogger extends QuickModule { JsonObject json = new JsonObject(); json.addProperty("time", time); - json.addProperty("name", this.compose_packet_name(classNames)); + json.addProperty("name", this.composePacketName(classNames)); json.add("fields", fields); return json; } - private JsonElement format_value(Object value) { + private JsonElement formatValue(Object value) { if (value == null) return null; if (value instanceof ITextComponent) { ITextComponent component = (ITextComponent) value; @@ -119,7 +119,7 @@ public class PacketLogger extends QuickModule { return obj; } if (value.getClass().isArray()) { - return this.array_to_string(value); + return this.arrayToString(value); } if (value instanceof Number) { return new JsonPrimitive((Number) value); @@ -135,17 +135,17 @@ public class PacketLogger extends QuickModule { } if (value instanceof Vector3d) { Vector3d vec = (Vector3d) value; - return this.array_to_string(new double[] { vec.x(), vec.y(), vec.z() }); + return this.arrayToString(new double[] { vec.x(), vec.y(), vec.z() }); } if (value instanceof Vector2f) { Vector2f vec = (Vector2f) value; - return this.array_to_string(new float[] { vec.x, vec.y }); + return this.arrayToString(new float[] { vec.x, vec.y }); } // TODO pretty print some very noisy toStrings return new JsonPrimitive(value.toString()); } - private JsonArray array_to_string(Object value) { + private JsonArray arrayToString(Object value) { JsonArray out = new JsonArray(); if (value instanceof byte[]) { byte[] arr = (byte[]) value; @@ -192,7 +192,7 @@ public class PacketLogger extends QuickModule { return out; } - private String compose_packet_name(List classNames) { + private String composePacketName(List classNames) { StringBuilder builder = new StringBuilder(); for (int i = classNames.size() - 1; i >= 0; i--) { builder.append(classNames.get(i)); @@ -201,7 +201,7 @@ public class PacketLogger extends QuickModule { return builder.toString(); } - private double pretty_time() { + private double prettyTime() { return (double) System.nanoTime() / 1000000000.; } } diff --git a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java index f0c68e0..3186dc6 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java +++ b/src/main/java/ftbsc/bscv/modules/self/AntiHunger.java @@ -49,6 +49,7 @@ public class AntiHunger extends AbstractModule { this.hover.get() && event.packet instanceof CPlayerPacket && MC.player != null + && MC.gameMode != null && MC.player.fallDistance <= 0.f && !MC.gameMode.isDestroying() ) { diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java index 4e556ac..287cd1a 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java @@ -28,6 +28,7 @@ public class AutoDisconnect extends AbstractModule { @SubscribeEvent public void onPacket(PacketEvent.Incoming event) { + if(MC.player == null) return; if (event.packet instanceof SUpdateHealthPacket) { SUpdateHealthPacket packet = (SUpdateHealthPacket) event.packet; if (packet.getHealth() < this.threshold.get()) { diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java index 9394233..628b4ab 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java @@ -5,7 +5,6 @@ import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.patches.PacketPatch.PacketEvent; import ftbsc.bscv.tools.Setting; -import net.minecraft.client.Minecraft; import net.minecraft.network.play.server.SPlaySoundEffectPacket; import net.minecraft.util.Hand; import net.minecraft.util.SoundEvents; @@ -37,22 +36,23 @@ public class AutoFish extends AbstractModule { @SubscribeEvent public void onPacket(PacketEvent.Incoming event) { + if (MC.gameMode == null || MC.player == null || MC.level == null) + return; + if (event.packet instanceof SPlaySoundEffectPacket) { SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet; if (packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH)) { MC.gameMode.useItem(MC.player, MC.level, Hand.MAIN_HAND); if (this.recast.get()) { - new RecastThread(MC, this.delay.get()).start(); + new RecastThread(this.delay.get()).start(); } } } } - private class RecastThread extends Thread { - private long delay; - private Minecraft mc; - public RecastThread(Minecraft mc, long delay) { - this.mc = mc; + private static class RecastThread extends Thread { + private final long delay; + public RecastThread(long delay) { this.delay = delay; this.setDaemon(true); } @@ -60,8 +60,10 @@ public class AutoFish extends AbstractModule { public void run() { try { Thread.sleep(this.delay); - } catch (InterruptedException e) {} // ignore - this.mc.gameMode.useItem(this.mc.player, this.mc.level, Hand.MAIN_HAND); + } catch (InterruptedException ignored) {} // ignore + if (MC.gameMode == null || MC.player == null || MC.level == null) + return; + MC.gameMode.useItem(MC.player, MC.level, Hand.MAIN_HAND); } } } diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java index c37a8a2..975a6d6 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java @@ -2,7 +2,6 @@ package ftbsc.bscv.modules.self; import com.google.auto.service.AutoService; -import ftbsc.bscv.Boscovicino; import ftbsc.bscv.api.ILoadable; import ftbsc.bscv.modules.AbstractModule; import ftbsc.bscv.tools.Inventory; @@ -22,7 +21,7 @@ import java.util.List; public class AutoTool extends AbstractModule { public final ForgeConfigSpec.ConfigValue limit; - public final ForgeConfigSpec.ConfigValue prefer_looting; + public final ForgeConfigSpec.ConfigValue preferLooting; public AutoTool() { super(); @@ -33,7 +32,7 @@ public class AutoTool extends AbstractModule { .fallback(1) .build(this); - this.prefer_looting = Setting.Bool.builder() + this.preferLooting = Setting.Bool.builder() .name("prefer-looting") .comment("when picking best weapon, prefer looting over slight more DPS") .fallback(true) @@ -46,10 +45,11 @@ public class AutoTool extends AbstractModule { && item.getMaxDamage() - item.getDamageValue() <= this.limit.get(); } - public boolean selectBestWeapon() { + public void selectBestWeapon() { + if(MC.player == null || MC.gameMode == null) return; List hotbar = Inventory.hotbar(MC.player); - int current_slot = MC.player.inventory.selected; - double current_damage = Inventory.itemDPS(hotbar.get(current_slot).getItem()); + int currentSlot = MC.player.inventory.selected; + double currentDamage = Inventory.itemDPS(hotbar.get(currentSlot).getItem()); for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { ItemStack item = hotbar.get(i).getItem(); if (this.itemIsTooDamaged(item)) { @@ -59,51 +59,48 @@ public class AutoTool extends AbstractModule { double damage = Inventory.itemDPS(item); int looting = Inventory.getEnchLevel(item, Enchantments.MOB_LOOTING); - if (this.prefer_looting.get() && looting > 0) { + if (this.preferLooting.get() && looting > 0) { damage += 0.1 * looting; } - if (damage > current_damage) { - current_slot = i; - current_damage = damage; + if (damage > currentDamage) { + currentSlot = i; + currentDamage = damage; } } - if (current_slot != MC.player.inventory.selected) { - MC.player.inventory.selected = current_slot; + if (currentSlot != MC.player.inventory.selected) { + MC.player.inventory.selected = currentSlot; MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER - return true; } - return false; } - public boolean selectBestTool() { + public void selectBestTool() { + if(MC.player == null || MC.level == null || MC.hitResult == null || MC.gameMode == null) return; List hotbar = Inventory.hotbar(MC.player); - int current_slot = MC.player.inventory.selected; + int currentSlot = MC.player.inventory.selected; BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; BlockState state = MC.level.getBlockState(result.getBlockPos()); - float current_speed = hotbar.get(current_slot).getItem().getDestroySpeed(state); + float currentSpeed = hotbar.get(currentSlot).getItem().getDestroySpeed(state); for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { ItemStack item = hotbar.get(i).getItem(); if (this.itemIsTooDamaged(item)) { continue; } float speed = item.getDestroySpeed(state); - if (speed > current_speed) { - current_slot = i; - current_speed = speed; + if (speed > currentSpeed) { + currentSlot = i; + currentSpeed = speed; } } - if (current_slot != MC.player.inventory.selected) { - MC.player.inventory.selected = current_slot; + if (currentSlot != MC.player.inventory.selected) { + MC.player.inventory.selected = currentSlot; MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER - return true; } - return false; } @SubscribeEvent public void onClick(InputEvent.ClickInputEvent event) { - if (MC.player == null) return; + if (MC.player == null || MC.hitResult == null) return; // TODO this is fired many times consecutively, can we filter out // some without putting a dumb time cooldown?; if (event.isAttack()) { diff --git a/src/main/java/ftbsc/bscv/modules/self/FastInteract.java b/src/main/java/ftbsc/bscv/modules/self/FastInteract.java index 9cd37d7..9276779 100644 --- a/src/main/java/ftbsc/bscv/modules/self/FastInteract.java +++ b/src/main/java/ftbsc/bscv/modules/self/FastInteract.java @@ -9,12 +9,8 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) public class FastInteract extends QuickModule { - protected int getDefaultKey() { return UNBOUND; } - @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { - if (MC == null) return; - MC.rightClickDelay = 0; // ACCESSTRANSFORMER } } diff --git a/src/main/java/ftbsc/bscv/modules/self/Freecam.java b/src/main/java/ftbsc/bscv/modules/self/Freecam.java index 0544803..c88d72b 100644 --- a/src/main/java/ftbsc/bscv/modules/self/Freecam.java +++ b/src/main/java/ftbsc/bscv/modules/self/Freecam.java @@ -7,14 +7,17 @@ import ftbsc.bscv.modules.QuickModule; import ftbsc.bscv.patches.PacketPatch.PacketEvent; import ftbsc.bscv.tools.Keyboard; import ftbsc.bscv.tools.Setting; +import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.entity.player.RemoteClientPlayerEntity; import net.minecraft.client.network.play.NetworkPlayerInfo; +import net.minecraft.client.world.ClientWorld; import net.minecraft.network.play.client.CPlayerPacket; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.GameType; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import org.checkerframework.checker.nullness.qual.NonNull; @AutoService(ILoadable.class) public class Freecam extends QuickModule { @@ -23,15 +26,10 @@ public class Freecam extends QuickModule { public final ForgeConfigSpec.ConfigValue speed; public final ForgeConfigSpec.ConfigValue drift; - private Vector3d prev_pos = new Vector3d(0.0, 0.0, 0.0); - private float prev_speed = 0.05f; - private GameType prev_gamemode = GameType.SURVIVAL; - private MockPlayer mock_player; - - @Override - protected int getDefaultKey() { - return UNBOUND; - } + private Vector3d prevPos = new Vector3d(0.0, 0.0, 0.0); + private float prevSpeed = 0.05f; + private GameType prevGamemode = GameType.SURVIVAL; + private MockPlayer mockPlayer; public Freecam() { super(); @@ -77,52 +75,53 @@ public class Freecam extends QuickModule { @Override public void enable() { - if (MC.player == null) { + if (MC.player == null || MC.gameMode == null || MC.level == null) { Boscovicino.log("[!] Can only enable freecam while in-game"); return; } - this.prev_speed = MC.player.abilities.getFlyingSpeed(); - this.prev_pos = MC.player.position(); - this.prev_gamemode = MC.gameMode.getPlayerMode(); + this.prevSpeed = MC.player.abilities.getFlyingSpeed(); + this.prevPos = MC.player.position(); + this.prevGamemode = MC.gameMode.getPlayerMode(); MC.gameMode.setLocalMode(GameType.SPECTATOR); MC.player.noCulling = true; if (MC.getConnection() != null) { NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( MC.player.getGameProfile().getId() ); + if (info == null) return; info.gameMode = GameType.SPECTATOR; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b } - this.mock_player = new MockPlayer(); - this.mock_player.setPosAndOldPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); - this.mock_player.setYBodyRot(MC.player.yBodyRot); - MC.level.addPlayer(-666, this.mock_player); + this.mockPlayer = new MockPlayer(MC.level, MC.player); + this.mockPlayer.setPosAndOldPos(this.prevPos.x, this.prevPos.y, this.prevPos.z); + this.mockPlayer.setYBodyRot(MC.player.yBodyRot); + MC.level.addPlayer(-666, this.mockPlayer); super.enable(); } @Override public void disable() { super.disable(); - if (MC.player == null) return; - MC.gameMode.setLocalMode(this.prev_gamemode); + if (MC.player == null || MC.level == null || MC.gameMode == null) return; + MC.gameMode.setLocalMode(this.prevGamemode); MC.player.noCulling = false; - MC.player.abilities.setFlyingSpeed(this.prev_speed); + MC.player.abilities.setFlyingSpeed(this.prevSpeed); if (MC.getConnection() != null) { NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( MC.player.getGameProfile().getId() ); - info.gameMode = this.prev_gamemode; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b + if (info != null) info.gameMode = this.prevGamemode; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b } - MC.player.setPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); + MC.player.setPos(this.prevPos.x, this.prevPos.y, this.prevPos.z); MC.player.setDeltaMovement(Vector3d.ZERO); - MC.level.removeEntity(this.mock_player.getId()); - this.mock_player = null; // get rid of reference + MC.level.removeEntity(this.mockPlayer.getId()); + this.mockPlayer = null; // get rid of reference } - private class MockPlayer extends RemoteClientPlayerEntity { - public MockPlayer() { - super(MC.level, MC.player.getGameProfile()); + private static class MockPlayer extends RemoteClientPlayerEntity { + public MockPlayer(@NonNull ClientWorld world, @NonNull ClientPlayerEntity player) { + super(world, player.getGameProfile()); this.setId(-666); // TODO hax } diff --git a/src/main/java/ftbsc/bscv/modules/self/HandChanger.java b/src/main/java/ftbsc/bscv/modules/self/HandChanger.java index c7f8a03..2d4a20a 100644 --- a/src/main/java/ftbsc/bscv/modules/self/HandChanger.java +++ b/src/main/java/ftbsc/bscv/modules/self/HandChanger.java @@ -13,8 +13,8 @@ public class HandChanger extends AbstractModule { public final ForgeConfigSpec.ConfigValue main; public final ForgeConfigSpec.ConfigValue off; - public final ForgeConfigSpec.ConfigValue cancel_main; - public final ForgeConfigSpec.ConfigValue cancel_off; + public final ForgeConfigSpec.ConfigValue cancelMain; + public final ForgeConfigSpec.ConfigValue cancelOff; public HandChanger() { super(); @@ -35,13 +35,13 @@ public class HandChanger extends AbstractModule { .fallback(1.) .build(this); - this.cancel_main = Setting.Bool.builder() + this.cancelMain = Setting.Bool.builder() .name("cancel-main") .comment("completely prevent main hand rendering") .fallback(false) .build(this); - this.cancel_off = Setting.Bool.builder() + this.cancelOff = Setting.Bool.builder() .name("cancel-off") .comment("completely prevent off hand rendering") .fallback(false) @@ -52,7 +52,7 @@ public class HandChanger extends AbstractModule { public void onRenderHands(RenderHandEvent event) { switch (event.getHand()) { case MAIN_HAND: - if (this.cancel_main.get()) { + if (this.cancelMain.get()) { event.setCanceled(true); } else if (this.main.get() != 1.0) { MC.gameRenderer.itemInHandRenderer.mainHandHeight = this.main.get().floatValue(); // ACCESSTRANSFORMER public net.minecraft.client.renderer.FirstPersonRenderer field_187469_f @@ -60,7 +60,7 @@ public class HandChanger extends AbstractModule { } break; case OFF_HAND: - if (this.cancel_off.get()) { + if (this.cancelOff.get()) { event.setCanceled(true); } else if (this.off.get() != 1.0) { MC.gameRenderer.itemInHandRenderer.offHandHeight = this.off.get().floatValue(); // ACCESSTRANSFORMER public net.minecraft.client.renderer.FirstPersonRenderer field_187470_g diff --git a/src/main/java/ftbsc/bscv/modules/vision/Chams.java b/src/main/java/ftbsc/bscv/modules/vision/Chams.java index 21961eb..8182a96 100644 --- a/src/main/java/ftbsc/bscv/modules/vision/Chams.java +++ b/src/main/java/ftbsc/bscv/modules/vision/Chams.java @@ -13,8 +13,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; @AutoService(ILoadable.class) public class Chams extends QuickModule { - protected int getDefaultKey() { return UNBOUND; } - @SubscribeEvent public void onRenderLivingPre(RenderLivingEvent.Pre event) { GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL); diff --git a/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java b/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java index aa8143b..3c608ad 100644 --- a/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java +++ b/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java @@ -23,14 +23,19 @@ public class Fullbright extends QuickModule { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { - if (MC == null) return; if (MC.player == null) return; - MC.player.addEffect(new EffectInstance(Effect.byId(NIGHT_VISION_ID), FOUR_MINUTES_TWENTY_SECONDS)); + Effect nv = Effect.byId(NIGHT_VISION_ID); + if(nv != null) { + MC.player.addEffect(new EffectInstance(nv, FOUR_MINUTES_TWENTY_SECONDS)); + } } @Override public void disable() { super.disable(); - MC.player.removeEffect(Effect.byId(NIGHT_VISION_ID)); + Effect nv = Effect.byId(NIGHT_VISION_ID); + if(MC.player != null && nv != null) { + MC.player.removeEffect(nv); + } } } diff --git a/src/main/java/ftbsc/bscv/modules/vision/StorageESP.java b/src/main/java/ftbsc/bscv/modules/vision/StorageESP.java index 47553e3..fc00bff 100644 --- a/src/main/java/ftbsc/bscv/modules/vision/StorageESP.java +++ b/src/main/java/ftbsc/bscv/modules/vision/StorageESP.java @@ -49,8 +49,6 @@ public class StorageESP extends QuickModule { private static final Vector3f FURNACE_COLOR = new Vector3f( 85.f/255.f, 85.f/255.f, 85.f/255.f); private static final Vector3f DROPPER_COLOR = new Vector3f( 0.f/255.f, 170.f/255.f, 0.f/255.f); - protected int getDefaultKey() { return UNBOUND; } - public final ForgeConfigSpec.ConfigValue width; public final ForgeConfigSpec.ConfigValue alpha; diff --git a/src/main/java/ftbsc/bscv/system/Bindings.java b/src/main/java/ftbsc/bscv/system/Bindings.java index e5c5397..6c0f4e3 100644 --- a/src/main/java/ftbsc/bscv/system/Bindings.java +++ b/src/main/java/ftbsc/bscv/system/Bindings.java @@ -1,6 +1,7 @@ package ftbsc.bscv.system; import ftbsc.bscv.Boscovicino; +import ftbsc.bscv.ICommons; import ftbsc.bscv.api.IModule; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; @@ -13,7 +14,7 @@ import net.minecraftforge.fml.client.registry.ClientRegistry; import java.util.HashMap; -public class Bindings { +public class Bindings implements ICommons { public static final int UNBOUND = InputMappings.UNKNOWN.getValue(); private final HashMap executorMap; @@ -39,9 +40,7 @@ public class Bindings { public KeyBinding registerBinding(String name, int key, String macroFileName) { KeyBinding kb = this.createBinding(name, key); - this.executorMap.put(kb, () -> { - Boscovicino.getInstance().macros.execute(macroFileName); - }); + this.executorMap.put(kb, () -> BSCV.macros.execute(macroFileName)); return kb; } @@ -70,7 +69,9 @@ public class Bindings { long windowId = Minecraft.getInstance().getWindow().getWindow(); for(KeyBinding kb : this.executorMap.keySet()) { if(kb.getKey().getValue() == key) { - if(InputMappings.isKeyDown(windowId, key)) this.executorMap.get(kb).run(); + if(InputMappings.isKeyDown(windowId, key)) { + MC.execute(this.executorMap.get(kb)); + } return; } } diff --git a/src/main/java/ftbsc/bscv/system/Macros.java b/src/main/java/ftbsc/bscv/system/Macros.java index 302910e..48ee0b7 100644 --- a/src/main/java/ftbsc/bscv/system/Macros.java +++ b/src/main/java/ftbsc/bscv/system/Macros.java @@ -34,7 +34,7 @@ public class Macros { if(name.endsWith(".lua")) { String code = String.join("\n", Files.readAllLines(macro)); this.macroCache.put(name, code); - Boscovicino.getInstance().bindings.registerBinding(name, Bindings.UNBOUND, name); + bscv.bindings.registerBinding(name, Bindings.UNBOUND, name); } } } -- cgit v1.2.3-56-ga3b1