diff --git a/Client/src/main/java/com/baseband/client/event/FMLEventHandler.java b/Client/src/main/java/com/baseband/client/event/FMLEventHandler.java index b380358..bfabe46 100644 --- a/Client/src/main/java/com/baseband/client/event/FMLEventHandler.java +++ b/Client/src/main/java/com/baseband/client/event/FMLEventHandler.java @@ -22,7 +22,7 @@ public class FMLEventHandler { @SubscribeEvent public void chat(ClientChatEvent event) { - String prefix = BaseBand.getModule(Client.class).prefix; + String prefix = BaseBand.getFeature(Client.class).prefix; if(event.getMessage().startsWith(prefix)) { event.setCanceled(true); ChatUtil.history(event.getMessage()); diff --git a/Client/src/main/java/com/baseband/client/gui/GuiRewrite.java b/Client/src/main/java/com/baseband/client/gui/GuiRewrite.java index af6fa49..7cb57ee 100644 --- a/Client/src/main/java/com/baseband/client/gui/GuiRewrite.java +++ b/Client/src/main/java/com/baseband/client/gui/GuiRewrite.java @@ -26,8 +26,8 @@ public class GuiRewrite extends GuiScreen { private boolean allowMouse = false; public GuiRewrite() { - this.mc = BaseBand.INSTANCE.mc; - ClickGUI clickGUI = BaseBand.getModule(ClickGUI.class); + this.mc = BaseBand.mc; + ClickGUI clickGUI = BaseBand.getFeature(ClickGUI.class); if(!clickGUI.enabled) clickGUI.toggle(); createComponents(); @@ -89,7 +89,7 @@ public class GuiRewrite extends GuiScreen { @Override public void onGuiClosed() { super.onGuiClosed(); - BaseBand.getModule(ClickGUI.class).setEnabled(false); + BaseBand.getFeature(ClickGUI.class).setEnabled(false); for (Category category : categories) { com.baseband.client.module.Category c = com.baseband.client.module.Category.fromName(category.text); c.show = category.subComponentsShown; @@ -165,24 +165,24 @@ public class GuiRewrite extends GuiScreen { cy = mouseY; GUIManager.renderedComponents = new HashMap<>(); - for (int i = 0 ; i < categories.length ; i++) { - if(categories[i].location.getY() < -10000) { - categories[i].location.setY(categories[i].location.getY() + 10000); + for (Category category : categories) { + if (category.location.getY() < -10000) { + category.location.setY(category.location.getY() + 10000); } - if(categories[i].location.getY() > 10000) { - categories[i].location.setY(categories[i].location.getY() - 10000); + if (category.location.getY() > 10000) { + category.location.setY(category.location.getY() - 10000); } - categories[i].render(); + category.render(); } // TMP fix for a strange bug that causes the mouse to be hidden - if (BaseBand.getModule(ClickGUI.class).mouseFix) { + if (BaseBand.getFeature(ClickGUI.class).mouseFix) { drawRect(mouseX - 2, mouseY - 2, mouseX + 2, mouseY + 2, 0xffffffff); } int m = Mouse.getDWheel(); if(m != 0) { - for (int i = 0 ; i < categories.length ; i++) { - categories[i].location.setY(categories[i].location.getY() + m); + for (Category category : categories) { + category.location.setY(category.location.getY() + m); } } diff --git a/Client/src/main/java/com/baseband/client/gui/lib/GUIManager.java b/Client/src/main/java/com/baseband/client/gui/lib/GUIManager.java index 994e870..c6c2d22 100644 --- a/Client/src/main/java/com/baseband/client/gui/lib/GUIManager.java +++ b/Client/src/main/java/com/baseband/client/gui/lib/GUIManager.java @@ -66,7 +66,7 @@ public class GUIManager { } public static void update() { - GuiTheme.ITheme theme = BaseBand.getModule(Client.class).getTheme(); + GuiTheme.ITheme theme = BaseBand.getFeature(Client.class).getTheme(); fontColorOn = theme.getGreenColor(); fontColorOff = theme.getRedColor(); frameColor = theme.getFrameColor(); diff --git a/Client/src/main/java/com/baseband/client/init/BaseBand.java b/Client/src/main/java/com/baseband/client/init/BaseBand.java index 2610e40..df3dcb5 100644 --- a/Client/src/main/java/com/baseband/client/init/BaseBand.java +++ b/Client/src/main/java/com/baseband/client/init/BaseBand.java @@ -3,7 +3,6 @@ package com.baseband.client.init; import com.baseband.client.configuration.Updater; import com.baseband.client.event.EventManager; import com.baseband.client.event.FMLEventHandler; -import com.baseband.client.gui.GuiRewrite; import com.baseband.client.module.Feature; import com.baseband.client.util.config.KeyBind; import com.baseband.client.util.ingame.ChatUtil; @@ -11,6 +10,7 @@ import com.baseband.client.util.misc.GlobalUtil; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Arrays; @@ -21,7 +21,6 @@ public class BaseBand { private static final ArrayList updaters = new ArrayList<>(); private static final ArrayList keyBinds = new ArrayList<>(); private static boolean finishedDisabling = false; - public static GuiRewrite guiRewrite; public static String buildString = "Broadway"; public static final EventManager eventManager = new EventManager(); public static FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler(); @@ -58,12 +57,10 @@ public class BaseBand { Setup clientSetup = Setup.get(); Feature[] features = clientSetup.Features; - for (int i = 0; i < features.length; i++) { - features[i].register(this, mc); + for (Feature value : features) { + value.register(this, mc); } - guiRewrite = new GuiRewrite(); - for (Updater updater : updaters) { GlobalUtil.LOGGER.info("populating updater " + updater); updater.populate(); @@ -82,9 +79,7 @@ public class BaseBand { } for (Feature feature : features) { - MinecraftForge.EVENT_BUS.unregister(feature); - eventManager.unsubscribe(feature); - feature.onDisable(); + feature.setEnabledSilent(false); } finishedDisabling = true; @@ -97,14 +92,25 @@ public class BaseBand { GlobalUtil.LOGGER.info("Instantiated."); } - public static T getModule(Class clazz) { + @SuppressWarnings("DataFlowIssue") + @Nonnull + public static T getFeature(Class clazz) { if(finishedDisabling) return null; Feature[] features = Setup.get().Features; for (Feature feature : features) { if (feature.getClass() == clazz) + //noinspection unchecked untrue return (T) feature; } return null; } + + public static boolean isFeatureEnabled(Class clazz) { + Feature f = getFeature(clazz); + //noinspection ConstantValue + if(f == null) + return false; + return f.enabled; + } } diff --git a/Client/src/main/java/com/baseband/client/init/Setup.java b/Client/src/main/java/com/baseband/client/init/Setup.java index e4673c9..1f00d2e 100644 --- a/Client/src/main/java/com/baseband/client/init/Setup.java +++ b/Client/src/main/java/com/baseband/client/init/Setup.java @@ -8,6 +8,7 @@ import com.baseband.client.module.client.Client; import com.baseband.client.module.client.MidClick; import com.baseband.client.module.combat.AutoKill; import com.baseband.client.module.combat.AutoTotem; +import com.baseband.client.module.command.Bind; import com.baseband.client.module.command.Set; import com.baseband.client.module.command.Test; import com.baseband.client.module.movement.ElytraFly; @@ -35,6 +36,7 @@ public class Setup { new ClickGUI(), new HUD(), new Set(), + new Bind(), new ChatCrypt(), new Freecam(), new AutoTotem(), diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinGuiEditSign.java b/Client/src/main/java/com/baseband/client/mixins/MixinGuiEditSign.java index bce8469..c94b0fc 100644 --- a/Client/src/main/java/com/baseband/client/mixins/MixinGuiEditSign.java +++ b/Client/src/main/java/com/baseband/client/mixins/MixinGuiEditSign.java @@ -21,8 +21,8 @@ public class MixinGuiEditSign { @Inject(method = "initGui", at = @At("RETURN")) public void initGui(CallbackInfo callback) { - AutoSignText autoSignText = BaseBand.getModule(AutoSignText.class); - if(autoSignText != null && autoSignText.enabled) { + if(BaseBand.isFeatureEnabled(AutoSignText.class)) { + AutoSignText autoSignText = BaseBand.getFeature(AutoSignText.class); tileSign.signText[0] = new TextComponentString(autoSignText.signTextFirst); tileSign.signText[1] = new TextComponentString(autoSignText.signTextSecond); tileSign.signText[2] = new TextComponentString(autoSignText.signTextThird); diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinGuiNewChat.java b/Client/src/main/java/com/baseband/client/mixins/MixinGuiNewChat.java index 96699bb..3ace52a 100644 --- a/Client/src/main/java/com/baseband/client/mixins/MixinGuiNewChat.java +++ b/Client/src/main/java/com/baseband/client/mixins/MixinGuiNewChat.java @@ -15,22 +15,30 @@ import java.util.List; public class MixinGuiNewChat extends Gui { @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V")) private void drawRectHook(int left, int top, int right, int bottom, int color) { - ExtraChat extraChat = BaseBand.getModule(ExtraChat.class); + if(!BaseBand.isFeatureEnabled(ExtraChat.class)) { + Gui.drawRect(left, top, right, bottom, color); + return; + } - Gui.drawRect(left, top, right, bottom, extraChat == null || extraChat.clearchat && extraChat.enabled ? 0 : color); + ExtraChat extraChat = BaseBand.getFeature(ExtraChat.class); + Gui.drawRect(left, top, right, bottom, extraChat.clearchat ? 0 : color); } @Redirect(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", ordinal = 0, remap = false)) public int drawnChatLinesSize(List list) { - ExtraChat extraChat = BaseBand.getModule(ExtraChat.class); + if(!BaseBand.isFeatureEnabled(ExtraChat.class)) + return list.size(); - return extraChat == null || extraChat.infinitechat && extraChat.enabled ? -2147483647 : list.size(); + ExtraChat extraChat = BaseBand.getFeature(ExtraChat.class); + return extraChat.infinitechat ? -2147483647 : list.size(); } @Redirect(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", ordinal = 2, remap = false)) public int chatLinesSize(List list) { - ExtraChat extraChat = BaseBand.getModule(ExtraChat.class); + if(!BaseBand.isFeatureEnabled(ExtraChat.class)) + return list.size(); - return extraChat == null || extraChat.infinitechat && extraChat.enabled ? -2147483647 : list.size(); + ExtraChat extraChat = BaseBand.getFeature(ExtraChat.class); + return extraChat.infinitechat ? -2147483647 : list.size(); } } diff --git a/Client/src/main/java/com/baseband/client/mixins/MixinScreenshotHelper.java b/Client/src/main/java/com/baseband/client/mixins/MixinScreenshotHelper.java index 5969479..7513215 100644 --- a/Client/src/main/java/com/baseband/client/mixins/MixinScreenshotHelper.java +++ b/Client/src/main/java/com/baseband/client/mixins/MixinScreenshotHelper.java @@ -16,9 +16,12 @@ import java.io.File; @Mixin(value = {ScreenShotHelper.class}, priority = Integer.MAX_VALUE) public class MixinScreenshotHelper { @Inject(method = {"saveScreenshot(Ljava/io/File;Ljava/lang/String;IILnet/minecraft/client/shader/Framebuffer;)Lnet/minecraft/util/text/ITextComponent;"}, at = {@At(value = "HEAD")}) - private static void saveScreenshot(File file, String string, int n, int n2, Framebuffer framebuffer, CallbackInfoReturnable callbackInfoReturnable) { - Client client = BaseBand.getModule(Client.class); - if (client != null && client.screenshotUpload) { + private static void saveScreenshot(File file, String string, int n, int n2, Framebuffer framebuffer, CallbackInfoReturnable callbackInfoReturnable) { + if(!BaseBand.isFeatureEnabled(Client.class)) + return; + + Client client = BaseBand.getFeature(Client.class); + if (client.screenshotUpload) { ScreenshotHelper eventClientScreenShot = new ScreenshotHelper(ScreenShotHelper.createScreenshot(n, n2, framebuffer)); eventClientScreenShot.start(); } diff --git a/Client/src/main/java/com/baseband/client/module/Feature.java b/Client/src/main/java/com/baseband/client/module/Feature.java index a6fe752..4fe734c 100644 --- a/Client/src/main/java/com/baseband/client/module/Feature.java +++ b/Client/src/main/java/com/baseband/client/module/Feature.java @@ -166,9 +166,7 @@ public abstract class Feature extends ToggleButton implements SetCommand { handle = settings; BaseBand.registerUpdater(settings.linkWith(this, FieldFinder.findMarked(Feature.class, 1)).name("Enabled")); - if(category != Category.COMMAND) { - updateEnabled(); - } + updateEnabled(); setup(); } @@ -204,13 +202,18 @@ public abstract class Feature extends ToggleButton implements SetCommand { try { ConfigHandle h = Configuration.register("Feature/" + getID() + "/" + handle); ownedHandles.put(handle, h); - System.out.println("Feature " + toString() + " registered config: " + handle); + System.out.println("Feature " + this + " registered config: " + handle); return h; } catch (IllegalAccessException e) { throw new RuntimeException(e); } } + public void setEnabledSilent(boolean enable) { + enabled = enable; + updateEnabled(); + } + public void setEnabled(boolean enable) { if(enable != enabled) toggle(); diff --git a/Client/src/main/java/com/baseband/client/module/chat/ChatAppend.java b/Client/src/main/java/com/baseband/client/module/chat/ChatAppend.java index 841acc0..b4040c1 100644 --- a/Client/src/main/java/com/baseband/client/module/chat/ChatAppend.java +++ b/Client/src/main/java/com/baseband/client/module/chat/ChatAppend.java @@ -39,7 +39,7 @@ public class ChatAppend extends Feature { public void packetWrite(PacketEvent.Send event) { if(event.getPacket() instanceof CPacketChatMessage) { - if (BaseBand.getModule(ChatCrypt.class).enabled) { + if (BaseBand.isFeatureEnabled(ChatCrypt.class)) { ChatUtil.print("ChatAppend toggled, As using it simultaneously with ChatCrypt is not supported."); toggle(); return; @@ -62,31 +62,31 @@ public class ChatAppend extends Feature { private String toUnicode(String s) { return s.toLowerCase() - .replace("a", "\u1d00") - .replace("b", "\u0299") - .replace("c", "\u1d04") - .replace("d", "\u1d05") - .replace("e", "\u1d07") - .replace("f", "\ua730") - .replace("g", "\u0262") - .replace("h", "\u029c") - .replace("i", "\u026a") - .replace("j", "\u1d0a") - .replace("k", "\u1d0b") - .replace("l", "\u029f") - .replace("m", "\u1d0d") - .replace("n", "\u0274") - .replace("o", "\u1d0f") - .replace("p", "\u1d18") - .replace("q", "\u01eb") - .replace("r", "\u0280") - .replace("s", "\ua731") - .replace("t", "\u1d1b") - .replace("u", "\u1d1c") - .replace("v", "\u1d20") - .replace("w", "\u1d21") - .replace("x", "\u02e3") - .replace("y", "\u028f") - .replace("z", "\u1d22"); + .replace("a", "ᴀ") + .replace("b", "ʙ") + .replace("c", "ᴄ") + .replace("d", "ᴅ") + .replace("e", "ᴇ") + .replace("f", "ꜰ") + .replace("g", "ɢ") + .replace("h", "ʜ") + .replace("i", "ɪ") + .replace("j", "ᴊ") + .replace("k", "ᴋ") + .replace("l", "ʟ") + .replace("m", "ᴍ") + .replace("n", "ɴ") + .replace("o", "ᴏ") + .replace("p", "ᴘ") + .replace("q", "ǫ") + .replace("r", "ʀ") + .replace("s", "ꜱ") + .replace("t", "ᴛ") + .replace("u", "ᴜ") + .replace("v", "ᴠ") + .replace("w", "ᴡ") + .replace("x", "ˣ") + .replace("y", "ʏ") + .replace("z", "ᴢ"); } } diff --git a/Client/src/main/java/com/baseband/client/module/client/Client.java b/Client/src/main/java/com/baseband/client/module/client/Client.java index c14eecc..7301e04 100644 --- a/Client/src/main/java/com/baseband/client/module/client/Client.java +++ b/Client/src/main/java/com/baseband/client/module/client/Client.java @@ -50,5 +50,6 @@ public class Client extends Feature { MinecraftForge.EVENT_BUS.unregister(BaseBand.fmlEventHandlerInstance); mc.displayGuiScreen(null); BaseBand.disabled = true; + ChatUtil.print("Waiting for config..."); } } diff --git a/Client/src/main/java/com/baseband/client/module/command/Bind.java b/Client/src/main/java/com/baseband/client/module/command/Bind.java index b6cb453..d7c2387 100644 --- a/Client/src/main/java/com/baseband/client/module/command/Bind.java +++ b/Client/src/main/java/com/baseband/client/module/command/Bind.java @@ -13,7 +13,7 @@ public class Bind extends Feature { @Override public void onCommand(String[] args) { if(args.length != 3) { - ChatUtil.print("syntax: " + BaseBand.getModule(Client.class).prefix + toString() + " "); + ChatUtil.print("syntax: " + BaseBand.getFeature(Client.class).prefix + this + " "); return; } String module = args[0]; diff --git a/Client/src/main/java/com/baseband/client/module/command/Set.java b/Client/src/main/java/com/baseband/client/module/command/Set.java index 5ca6c75..6b1ce37 100644 --- a/Client/src/main/java/com/baseband/client/module/command/Set.java +++ b/Client/src/main/java/com/baseband/client/module/command/Set.java @@ -24,13 +24,13 @@ public class Set extends Feature { } public static void openQuickSet(int id, String field) { - ChatUtil.openChat(BaseBand.getModule(Client.class).prefix + "set " + id + " " + field.replace(' ', '_') + " "); + ChatUtil.openChat(BaseBand.getFeature(Client.class).prefix + "set " + id + " " + field.replace(' ', '_') + " "); } @Override public void onCommand(String[] args) { if(args.length < 3) { - ChatUtil.print("syntax: " + BaseBand.getModule(Client.class).prefix + toString() + " "); + ChatUtil.print("syntax: " + BaseBand.getFeature(Client.class).prefix + this + " "); return; } String module = args[0]; diff --git a/Client/src/main/java/com/baseband/client/module/render/ClickGUI.java b/Client/src/main/java/com/baseband/client/module/render/ClickGUI.java index 4d7466e..5409149 100644 --- a/Client/src/main/java/com/baseband/client/module/render/ClickGUI.java +++ b/Client/src/main/java/com/baseband/client/module/render/ClickGUI.java @@ -3,12 +3,13 @@ package com.baseband.client.module.render; import com.baseband.client.configuration.annotation.Config; import com.baseband.client.configuration.annotation.Gate; import com.baseband.client.gui.GuiRewrite; -import com.baseband.client.init.BaseBand; import com.baseband.client.module.Feature; import com.baseband.client.module.category.Render; @Render public class ClickGUI extends Feature { + public GuiRewrite guiRewrite = new GuiRewrite(); + public enum SaveExpandedMode { Always, UntilExit, @@ -78,7 +79,7 @@ public class ClickGUI extends Feature { feature.subComponentsShown = false; } } - mc.displayGuiScreen(BaseBand.guiRewrite); + mc.displayGuiScreen(guiRewrite); } @Override diff --git a/Client/src/main/java/com/baseband/client/module/render/HUD.java b/Client/src/main/java/com/baseband/client/module/render/HUD.java index 2cff67f..6d9045a 100644 --- a/Client/src/main/java/com/baseband/client/module/render/HUD.java +++ b/Client/src/main/java/com/baseband/client/module/render/HUD.java @@ -121,10 +121,10 @@ public class HUD extends Feature { public void text(RenderGameOverlayEvent.Text e) { ScaledResolution sr = new ScaledResolution(mc); - mc.fontRenderer.drawStringWithShadow("§lBaseBand§r - \"" + BaseBand.buildString + "\"", 2,2, BaseBand.getModule(Client.class).getTheme().getGreenColor()); + mc.fontRenderer.drawStringWithShadow("§lBaseBand§r - \"" + BaseBand.buildString + "\"", 2,2, BaseBand.getFeature(Client.class).getTheme().getGreenColor()); int y = 11; for (Feature f : Arrays.stream(Setup.Features).filter(m -> m.enabled && m.category != Category.COMMAND && m.category != Category.CLIENT && !m.toString().equals("HUD")).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(value.toString()))).toArray(Feature[]::new)) { - mc.fontRenderer.drawStringWithShadow(f.toString(), 2, y, BaseBand.getModule(Client.class).getTheme().getGreenColor()); + mc.fontRenderer.drawStringWithShadow(f.toString(), 2, y, BaseBand.getFeature(Client.class).getTheme().getGreenColor()); y = y + mc.fontRenderer.FONT_HEIGHT; } if(notifications) { diff --git a/Client/src/main/java/com/baseband/client/util/ingame/FreecamPlayer.java b/Client/src/main/java/com/baseband/client/util/ingame/FreecamPlayer.java index 1acefcd..24a413e 100644 --- a/Client/src/main/java/com/baseband/client/util/ingame/FreecamPlayer.java +++ b/Client/src/main/java/com/baseband/client/util/ingame/FreecamPlayer.java @@ -49,7 +49,7 @@ public class FreecamPlayer extends EntityOtherPlayerMP public void onLivingUpdate() { if(mc.world == null) { - BaseBand.getModule(Freecam.class).setEnabled(false); + BaseBand.getFeature(Freecam.class).setEnabled(false); return; } mc.renderChunksMany = false;