make unloading a bit more unterrible, fix warnings

This commit is contained in:
Daniella / Tove 2024-05-25 21:12:30 +02:00
parent 4e6ccd102c
commit 2c9a14750d
16 changed files with 98 additions and 74 deletions

View file

@ -22,7 +22,7 @@ public class FMLEventHandler {
@SubscribeEvent @SubscribeEvent
public void chat(ClientChatEvent event) { public void chat(ClientChatEvent event) {
String prefix = BaseBand.getModule(Client.class).prefix; String prefix = BaseBand.getFeature(Client.class).prefix;
if(event.getMessage().startsWith(prefix)) { if(event.getMessage().startsWith(prefix)) {
event.setCanceled(true); event.setCanceled(true);
ChatUtil.history(event.getMessage()); ChatUtil.history(event.getMessage());

View file

@ -26,8 +26,8 @@ public class GuiRewrite extends GuiScreen {
private boolean allowMouse = false; private boolean allowMouse = false;
public GuiRewrite() { public GuiRewrite() {
this.mc = BaseBand.INSTANCE.mc; this.mc = BaseBand.mc;
ClickGUI clickGUI = BaseBand.getModule(ClickGUI.class); ClickGUI clickGUI = BaseBand.getFeature(ClickGUI.class);
if(!clickGUI.enabled) if(!clickGUI.enabled)
clickGUI.toggle(); clickGUI.toggle();
createComponents(); createComponents();
@ -89,7 +89,7 @@ public class GuiRewrite extends GuiScreen {
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
super.onGuiClosed(); super.onGuiClosed();
BaseBand.getModule(ClickGUI.class).setEnabled(false); BaseBand.getFeature(ClickGUI.class).setEnabled(false);
for (Category category : categories) { for (Category category : categories) {
com.baseband.client.module.Category c = com.baseband.client.module.Category.fromName(category.text); com.baseband.client.module.Category c = com.baseband.client.module.Category.fromName(category.text);
c.show = category.subComponentsShown; c.show = category.subComponentsShown;
@ -165,24 +165,24 @@ public class GuiRewrite extends GuiScreen {
cy = mouseY; cy = mouseY;
GUIManager.renderedComponents = new HashMap<>(); GUIManager.renderedComponents = new HashMap<>();
for (int i = 0 ; i < categories.length ; i++) { for (Category category : categories) {
if(categories[i].location.getY() < -10000) { if (category.location.getY() < -10000) {
categories[i].location.setY(categories[i].location.getY() + 10000); category.location.setY(category.location.getY() + 10000);
} }
if(categories[i].location.getY() > 10000) { if (category.location.getY() > 10000) {
categories[i].location.setY(categories[i].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 // 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); drawRect(mouseX - 2, mouseY - 2, mouseX + 2, mouseY + 2, 0xffffffff);
} }
int m = Mouse.getDWheel(); int m = Mouse.getDWheel();
if(m != 0) { if(m != 0) {
for (int i = 0 ; i < categories.length ; i++) { for (Category category : categories) {
categories[i].location.setY(categories[i].location.getY() + m); category.location.setY(category.location.getY() + m);
} }
} }

View file

@ -66,7 +66,7 @@ public class GUIManager {
} }
public static void update() { public static void update() {
GuiTheme.ITheme theme = BaseBand.getModule(Client.class).getTheme(); GuiTheme.ITheme theme = BaseBand.getFeature(Client.class).getTheme();
fontColorOn = theme.getGreenColor(); fontColorOn = theme.getGreenColor();
fontColorOff = theme.getRedColor(); fontColorOff = theme.getRedColor();
frameColor = theme.getFrameColor(); frameColor = theme.getFrameColor();

View file

@ -3,7 +3,6 @@ package com.baseband.client.init;
import com.baseband.client.configuration.Updater; import com.baseband.client.configuration.Updater;
import com.baseband.client.event.EventManager; import com.baseband.client.event.EventManager;
import com.baseband.client.event.FMLEventHandler; import com.baseband.client.event.FMLEventHandler;
import com.baseband.client.gui.GuiRewrite;
import com.baseband.client.module.Feature; import com.baseband.client.module.Feature;
import com.baseband.client.util.config.KeyBind; import com.baseband.client.util.config.KeyBind;
import com.baseband.client.util.ingame.ChatUtil; 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.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -21,7 +21,6 @@ public class BaseBand {
private static final ArrayList<Updater> updaters = new ArrayList<>(); private static final ArrayList<Updater> updaters = new ArrayList<>();
private static final ArrayList<KeyBind> keyBinds = new ArrayList<>(); private static final ArrayList<KeyBind> keyBinds = new ArrayList<>();
private static boolean finishedDisabling = false; private static boolean finishedDisabling = false;
public static GuiRewrite guiRewrite;
public static String buildString = "Broadway"; public static String buildString = "Broadway";
public static final EventManager eventManager = new EventManager(); public static final EventManager eventManager = new EventManager();
public static FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler(); public static FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler();
@ -58,12 +57,10 @@ public class BaseBand {
Setup clientSetup = Setup.get(); Setup clientSetup = Setup.get();
Feature[] features = clientSetup.Features; Feature[] features = clientSetup.Features;
for (int i = 0; i < features.length; i++) { for (Feature value : features) {
features[i].register(this, mc); value.register(this, mc);
} }
guiRewrite = new GuiRewrite();
for (Updater updater : updaters) { for (Updater updater : updaters) {
GlobalUtil.LOGGER.info("populating updater " + updater); GlobalUtil.LOGGER.info("populating updater " + updater);
updater.populate(); updater.populate();
@ -82,9 +79,7 @@ public class BaseBand {
} }
for (Feature feature : features) { for (Feature feature : features) {
MinecraftForge.EVENT_BUS.unregister(feature); feature.setEnabledSilent(false);
eventManager.unsubscribe(feature);
feature.onDisable();
} }
finishedDisabling = true; finishedDisabling = true;
@ -97,14 +92,25 @@ public class BaseBand {
GlobalUtil.LOGGER.info("Instantiated."); GlobalUtil.LOGGER.info("Instantiated.");
} }
public static <T extends Feature> T getModule(Class<? extends T> clazz) { @SuppressWarnings("DataFlowIssue")
@Nonnull
public static <T extends Feature> T getFeature(Class<? extends T> clazz) {
if(finishedDisabling) return null; if(finishedDisabling) return null;
Feature[] features = Setup.get().Features; Feature[] features = Setup.get().Features;
for (Feature feature : features) { for (Feature feature : features) {
if (feature.getClass() == clazz) if (feature.getClass() == clazz)
//noinspection unchecked untrue
return (T) feature; return (T) feature;
} }
return null; return null;
} }
public static boolean isFeatureEnabled(Class<? extends Feature> clazz) {
Feature f = getFeature(clazz);
//noinspection ConstantValue
if(f == null)
return false;
return f.enabled;
}
} }

View file

@ -8,6 +8,7 @@ import com.baseband.client.module.client.Client;
import com.baseband.client.module.client.MidClick; import com.baseband.client.module.client.MidClick;
import com.baseband.client.module.combat.AutoKill; import com.baseband.client.module.combat.AutoKill;
import com.baseband.client.module.combat.AutoTotem; 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.Set;
import com.baseband.client.module.command.Test; import com.baseband.client.module.command.Test;
import com.baseband.client.module.movement.ElytraFly; import com.baseband.client.module.movement.ElytraFly;
@ -35,6 +36,7 @@ public class Setup {
new ClickGUI(), new ClickGUI(),
new HUD(), new HUD(),
new Set(), new Set(),
new Bind(),
new ChatCrypt(), new ChatCrypt(),
new Freecam(), new Freecam(),
new AutoTotem(), new AutoTotem(),

View file

@ -21,8 +21,8 @@ public class MixinGuiEditSign {
@Inject(method = "initGui", at = @At("RETURN")) @Inject(method = "initGui", at = @At("RETURN"))
public void initGui(CallbackInfo callback) { public void initGui(CallbackInfo callback) {
AutoSignText autoSignText = BaseBand.getModule(AutoSignText.class); if(BaseBand.isFeatureEnabled(AutoSignText.class)) {
if(autoSignText != null && autoSignText.enabled) { AutoSignText autoSignText = BaseBand.getFeature(AutoSignText.class);
tileSign.signText[0] = new TextComponentString(autoSignText.signTextFirst); tileSign.signText[0] = new TextComponentString(autoSignText.signTextFirst);
tileSign.signText[1] = new TextComponentString(autoSignText.signTextSecond); tileSign.signText[1] = new TextComponentString(autoSignText.signTextSecond);
tileSign.signText[2] = new TextComponentString(autoSignText.signTextThird); tileSign.signText[2] = new TextComponentString(autoSignText.signTextThird);

View file

@ -15,22 +15,30 @@ import java.util.List;
public class MixinGuiNewChat extends Gui { public class MixinGuiNewChat extends Gui {
@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V")) @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) { 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)) @Redirect(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", ordinal = 0, remap = false))
public int drawnChatLinesSize(List<ChatLine> list) { public int drawnChatLinesSize(List<ChatLine> 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)) @Redirect(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", ordinal = 2, remap = false))
public int chatLinesSize(List<ChatLine> list) { public int chatLinesSize(List<ChatLine> 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();
} }
} }

View file

@ -16,9 +16,12 @@ import java.io.File;
@Mixin(value = {ScreenShotHelper.class}, priority = Integer.MAX_VALUE) @Mixin(value = {ScreenShotHelper.class}, priority = Integer.MAX_VALUE)
public class MixinScreenshotHelper { 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")}) @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) { private static void saveScreenshot(File file, String string, int n, int n2, Framebuffer framebuffer, CallbackInfoReturnable<?> callbackInfoReturnable) {
Client client = BaseBand.getModule(Client.class); if(!BaseBand.isFeatureEnabled(Client.class))
if (client != null && client.screenshotUpload) { return;
Client client = BaseBand.getFeature(Client.class);
if (client.screenshotUpload) {
ScreenshotHelper eventClientScreenShot = new ScreenshotHelper(ScreenShotHelper.createScreenshot(n, n2, framebuffer)); ScreenshotHelper eventClientScreenShot = new ScreenshotHelper(ScreenShotHelper.createScreenshot(n, n2, framebuffer));
eventClientScreenShot.start(); eventClientScreenShot.start();
} }

View file

@ -166,9 +166,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
handle = settings; handle = settings;
BaseBand.registerUpdater(settings.linkWith(this, FieldFinder.findMarked(Feature.class, 1)).name("Enabled")); BaseBand.registerUpdater(settings.linkWith(this, FieldFinder.findMarked(Feature.class, 1)).name("Enabled"));
if(category != Category.COMMAND) {
updateEnabled(); updateEnabled();
}
setup(); setup();
} }
@ -204,13 +202,18 @@ public abstract class Feature extends ToggleButton implements SetCommand {
try { try {
ConfigHandle h = Configuration.register("Feature/" + getID() + "/" + handle); ConfigHandle h = Configuration.register("Feature/" + getID() + "/" + handle);
ownedHandles.put(handle, h); ownedHandles.put(handle, h);
System.out.println("Feature " + toString() + " registered config: " + handle); System.out.println("Feature " + this + " registered config: " + handle);
return h; return h;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public void setEnabledSilent(boolean enable) {
enabled = enable;
updateEnabled();
}
public void setEnabled(boolean enable) { public void setEnabled(boolean enable) {
if(enable != enabled) if(enable != enabled)
toggle(); toggle();

View file

@ -39,7 +39,7 @@ public class ChatAppend extends Feature {
public void packetWrite(PacketEvent.Send event) { public void packetWrite(PacketEvent.Send event) {
if(event.getPacket() instanceof CPacketChatMessage) { 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."); ChatUtil.print("ChatAppend toggled, As using it simultaneously with ChatCrypt is not supported.");
toggle(); toggle();
return; return;
@ -62,31 +62,31 @@ public class ChatAppend extends Feature {
private String toUnicode(String s) { private String toUnicode(String s) {
return s.toLowerCase() return s.toLowerCase()
.replace("a", "\u1d00") .replace("a", "")
.replace("b", "\u0299") .replace("b", "ʙ")
.replace("c", "\u1d04") .replace("c", "")
.replace("d", "\u1d05") .replace("d", "")
.replace("e", "\u1d07") .replace("e", "")
.replace("f", "\ua730") .replace("f", "")
.replace("g", "\u0262") .replace("g", "ɢ")
.replace("h", "\u029c") .replace("h", "ʜ")
.replace("i", "\u026a") .replace("i", "ɪ")
.replace("j", "\u1d0a") .replace("j", "")
.replace("k", "\u1d0b") .replace("k", "")
.replace("l", "\u029f") .replace("l", "ʟ")
.replace("m", "\u1d0d") .replace("m", "")
.replace("n", "\u0274") .replace("n", "ɴ")
.replace("o", "\u1d0f") .replace("o", "")
.replace("p", "\u1d18") .replace("p", "")
.replace("q", "\u01eb") .replace("q", "ǫ")
.replace("r", "\u0280") .replace("r", "ʀ")
.replace("s", "\ua731") .replace("s", "")
.replace("t", "\u1d1b") .replace("t", "")
.replace("u", "\u1d1c") .replace("u", "")
.replace("v", "\u1d20") .replace("v", "")
.replace("w", "\u1d21") .replace("w", "")
.replace("x", "\u02e3") .replace("x", "ˣ")
.replace("y", "\u028f") .replace("y", "ʏ")
.replace("z", "\u1d22"); .replace("z", "");
} }
} }

View file

@ -50,5 +50,6 @@ public class Client extends Feature {
MinecraftForge.EVENT_BUS.unregister(BaseBand.fmlEventHandlerInstance); MinecraftForge.EVENT_BUS.unregister(BaseBand.fmlEventHandlerInstance);
mc.displayGuiScreen(null); mc.displayGuiScreen(null);
BaseBand.disabled = true; BaseBand.disabled = true;
ChatUtil.print("Waiting for config...");
} }
} }

View file

@ -13,7 +13,7 @@ public class Bind extends Feature {
@Override @Override
public void onCommand(String[] args) { public void onCommand(String[] args) {
if(args.length != 3) { if(args.length != 3) {
ChatUtil.print("syntax: " + BaseBand.getModule(Client.class).prefix + toString() + " <module> <binding> <key>"); ChatUtil.print("syntax: " + BaseBand.getFeature(Client.class).prefix + this + " <module> <binding> <key>");
return; return;
} }
String module = args[0]; String module = args[0];

View file

@ -24,13 +24,13 @@ public class Set extends Feature {
} }
public static void openQuickSet(int id, String field) { 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 @Override
public void onCommand(String[] args) { public void onCommand(String[] args) {
if(args.length < 3) { if(args.length < 3) {
ChatUtil.print("syntax: " + BaseBand.getModule(Client.class).prefix + toString() + " <module> <setting> <value...>"); ChatUtil.print("syntax: " + BaseBand.getFeature(Client.class).prefix + this + " <module> <setting> <value...>");
return; return;
} }
String module = args[0]; String module = args[0];

View file

@ -3,12 +3,13 @@ package com.baseband.client.module.render;
import com.baseband.client.configuration.annotation.Config; import com.baseband.client.configuration.annotation.Config;
import com.baseband.client.configuration.annotation.Gate; import com.baseband.client.configuration.annotation.Gate;
import com.baseband.client.gui.GuiRewrite; import com.baseband.client.gui.GuiRewrite;
import com.baseband.client.init.BaseBand;
import com.baseband.client.module.Feature; import com.baseband.client.module.Feature;
import com.baseband.client.module.category.Render; import com.baseband.client.module.category.Render;
@Render @Render
public class ClickGUI extends Feature { public class ClickGUI extends Feature {
public GuiRewrite guiRewrite = new GuiRewrite();
public enum SaveExpandedMode { public enum SaveExpandedMode {
Always, Always,
UntilExit, UntilExit,
@ -78,7 +79,7 @@ public class ClickGUI extends Feature {
feature.subComponentsShown = false; feature.subComponentsShown = false;
} }
} }
mc.displayGuiScreen(BaseBand.guiRewrite); mc.displayGuiScreen(guiRewrite);
} }
@Override @Override

View file

@ -121,10 +121,10 @@ public class HUD extends Feature {
public void text(RenderGameOverlayEvent.Text e) { public void text(RenderGameOverlayEvent.Text e) {
ScaledResolution sr = new ScaledResolution(mc); 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; 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)) { 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; y = y + mc.fontRenderer.FONT_HEIGHT;
} }
if(notifications) { if(notifications) {

View file

@ -49,7 +49,7 @@ public class FreecamPlayer extends EntityOtherPlayerMP
public void onLivingUpdate() public void onLivingUpdate()
{ {
if(mc.world == null) { if(mc.world == null) {
BaseBand.getModule(Freecam.class).setEnabled(false); BaseBand.getFeature(Freecam.class).setEnabled(false);
return; return;
} }
mc.renderChunksMany = false; mc.renderChunksMany = false;