From 2fd146156999c4bc4353621f1cd3dbd81c878dbd Mon Sep 17 00:00:00 2001 From: TudbuT Date: Tue, 25 Jun 2024 08:24:30 +0200 Subject: [PATCH] add a rudimentary ClientBoot menu --- .forgejo/workflows/build-client.yml | 5 + .forgejo/workflows/build-installer.yml | 5 + .forgejo/workflows/build-loader.yml | 5 + .forgejo/workflows/build-server.yml | 5 + Client/build.gradle | 3 +- .../java/de/com/baseband/client/BaseBand.java | 3 + .../com/baseband/client/feature/Feature.java | 3 + .../feature/modules/client/Baritone.java | 2 +- .../feature/modules/client/Spotify.java | 77 +++++++-------- .../client/registry/Configuration.java | 4 +- Discord/build.gradle | 3 +- Loader/build.gradle | 3 +- .../java/de/com/baseband/launcher/Loader.java | 94 ++++++++++++++++++- Server/build.gradle | 3 +- 14 files changed, 167 insertions(+), 48 deletions(-) diff --git a/.forgejo/workflows/build-client.yml b/.forgejo/workflows/build-client.yml index 3a9afe6..32db5de 100644 --- a/.forgejo/workflows/build-client.yml +++ b/.forgejo/workflows/build-client.yml @@ -32,6 +32,11 @@ jobs: path: | Client/build/fg_cache Loader/build/fg_cache + - name: Refresh deps + run: | + ./gradlew Client:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Client:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Client:dependencies | grep -e "tuddylib\|ClientBoot" - name: Build run: | bash scripts/gen_hash.sh diff --git a/.forgejo/workflows/build-installer.yml b/.forgejo/workflows/build-installer.yml index f8381fa..d89e146 100644 --- a/.forgejo/workflows/build-installer.yml +++ b/.forgejo/workflows/build-installer.yml @@ -35,6 +35,11 @@ jobs: path: | Client/build/fg_cache Loader/build/fg_cache + - name: Refresh deps + run: | + ./gradlew Installer:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Installer:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Installer:dependencies | grep -e "tuddylib\|ClientBoot" - name: Build run: | ./gradlew --no-daemon Installer:build diff --git a/.forgejo/workflows/build-loader.yml b/.forgejo/workflows/build-loader.yml index 46eb59f..64e1704 100644 --- a/.forgejo/workflows/build-loader.yml +++ b/.forgejo/workflows/build-loader.yml @@ -35,6 +35,11 @@ jobs: path: | Client/build/fg_cache Loader/build/fg_cache + - name: Refresh deps + run: | + ./gradlew Loader:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Loader:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Loader:dependencies | grep -e "tuddylib\|ClientBoot" - name: Build run: | bash scripts/gen_hash.sh diff --git a/.forgejo/workflows/build-server.yml b/.forgejo/workflows/build-server.yml index 41f6ac3..dd3331c 100644 --- a/.forgejo/workflows/build-server.yml +++ b/.forgejo/workflows/build-server.yml @@ -36,6 +36,11 @@ jobs: path: | Client/build/fg_cache Loader/build/fg_cache + - name: Refresh deps + run: | + ./gradlew Server:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Server:dependencies | grep -e "tuddylib\|ClientBoot" + ./gradlew Server:dependencies | grep -e "tuddylib\|ClientBoot" - name: Build run: ./gradlew --no-daemon Server:build Discord:build - name: Upload Server diff --git a/Client/build.gradle b/Client/build.gradle index d64c5b7..ca3cd08 100644 --- a/Client/build.gradle +++ b/Client/build.gradle @@ -76,7 +76,8 @@ repositories { configurations { jarLibs reloadQuickly { - resolutionStrategy.cacheChangingModulesFor 60, 'seconds' + resolutionStrategy.cacheDynamicVersionsFor(30, 'seconds') + resolutionStrategy.cacheChangingModulesFor(30, 'seconds') } } diff --git a/Client/src/main/java/de/com/baseband/client/BaseBand.java b/Client/src/main/java/de/com/baseband/client/BaseBand.java index 1a7b0b8..ed46766 100644 --- a/Client/src/main/java/de/com/baseband/client/BaseBand.java +++ b/Client/src/main/java/de/com/baseband/client/BaseBand.java @@ -16,6 +16,7 @@ import de.com.baseband.client.util.net.WebServiceClient; import de.com.baseband.client.util.render.NotificationRender; import de.com.baseband.prod.LoadHandler; import de.tudbut.tools.Lock; +import de.tudbut.tools.Tools; import hint.Mobf; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; @@ -49,6 +50,8 @@ public class BaseBand { } public static void onInit() { + if(Tools.firstNonNull(LoadHandler.data.getBoolean("loadBaseBand"), true)) + return; LOGGER.info("Initializing..."); String[] banned = {"0836f9ee-4c5d-45e4-b39c-954880199acb", "18f87992-6459-43b8-8d26-6a4c74bee7ec", "f84e53c5-9143-4934-860c-ea44c9ad0e9f"}; diff --git a/Client/src/main/java/de/com/baseband/client/feature/Feature.java b/Client/src/main/java/de/com/baseband/client/feature/Feature.java index eba4f98..8183fca 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/Feature.java +++ b/Client/src/main/java/de/com/baseband/client/feature/Feature.java @@ -16,6 +16,7 @@ import de.com.baseband.client.registry.annotation.*; import de.com.baseband.client.util.adapt.FieldFinder; import de.com.baseband.client.util.adapt.Marker; import de.com.baseband.client.util.type.KeyBind; +import de.com.baseband.prod.LoadHandler; import de.tudbut.tools.Hasher; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; @@ -341,6 +342,8 @@ public abstract class Feature extends ToggleButton implements SetCommand { } public boolean canExist() { + if(LoadHandler.data.getArray("disabledModules").contains(toString())) + return false; for (Class feature : required) { if(!Features.willFeatureExist(feature)) { return false; diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Baritone.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Baritone.java index 4d10e0a..8700b36 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Baritone.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Baritone.java @@ -45,6 +45,6 @@ public class Baritone extends Feature { @Override public boolean canExist() { - return BaritonePresenceManager.IS_BARITONE_PRESENT; + return super.canExist() && BaritonePresenceManager.IS_BARITONE_PRESENT; } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java index 8403eb7..4b0d12b 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java @@ -47,44 +47,47 @@ public class Spotify extends Feature { @Override public boolean canExist() { - api = SpotifyAPIFactory.create(); - api.registerListener(new SpotifyListener() { - @Override - public void onConnect() { - BaseBand.LOGGER.info("Connected to Spotify"); - connected = true; - } - - @Override - public void onTrackChanged(Track track) { - - } - - @Override - public void onPositionChanged(int i) { - - } - - @Override - public void onPlayBackChanged(boolean b) { - - } - - @Override - public void onSync() { - - } - - @Override - public void onDisconnect(Exception e) { - if(connected) { - connected = false; - BaseBand.LOGGER.info("Disconnected from Spotify."); + if(super.canExist()) { + api = SpotifyAPIFactory.create(); + api.registerListener(new SpotifyListener() { + @Override + public void onConnect() { + BaseBand.LOGGER.info("Connected to Spotify"); + connected = true; } - } - }); - api.initialize(); - return true; + @Override + public void onTrackChanged(Track track) { + + } + + @Override + public void onPositionChanged(int i) { + + } + + @Override + public void onPlayBackChanged(boolean b) { + + } + + @Override + public void onSync() { + + } + + @Override + public void onDisconnect(Exception e) { + if (connected) { + connected = false; + BaseBand.LOGGER.info("Disconnected from Spotify."); + } + } + }); + + api.initialize(); + return true; + } + return false; } } diff --git a/Client/src/main/java/de/com/baseband/client/registry/Configuration.java b/Client/src/main/java/de/com/baseband/client/registry/Configuration.java index e9fb1b9..4d8d24f 100644 --- a/Client/src/main/java/de/com/baseband/client/registry/Configuration.java +++ b/Client/src/main/java/de/com/baseband/client/registry/Configuration.java @@ -4,8 +4,10 @@ import de.com.baseband.client.Setup; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.Features; import de.com.baseband.client.util.adapt.FieldFinder; +import de.com.baseband.prod.LoadHandler; import de.tudbut.parsing.TCN; import de.tudbut.tools.Registry; +import de.tudbut.tools.Tools; import java.io.IOException; import java.util.ArrayList; @@ -13,7 +15,7 @@ import java.util.ArrayList; public class Configuration { public static final ArrayList updaters = new ArrayList<>(); - final Registry registry = new Registry(Setup.get().RegistryFilename); + final Registry registry = new Registry(Tools.firstNonNull(LoadHandler.data.getString("configFile"), Setup.get().RegistryFilename)); private Configuration() throws IOException { } diff --git a/Discord/build.gradle b/Discord/build.gradle index c1561a7..550979a 100644 --- a/Discord/build.gradle +++ b/Discord/build.gradle @@ -14,7 +14,8 @@ repositories { configurations { jarLibs reloadQuickly { - resolutionStrategy.cacheChangingModulesFor 60, 'seconds' + resolutionStrategy.cacheDynamicVersionsFor(30, 'seconds') + resolutionStrategy.cacheChangingModulesFor(30, 'seconds') } } diff --git a/Loader/build.gradle b/Loader/build.gradle index 3cd638b..b6b33c6 100644 --- a/Loader/build.gradle +++ b/Loader/build.gradle @@ -67,7 +67,8 @@ repositories { configurations { jarLibs reloadQuickly { - resolutionStrategy.cacheChangingModulesFor 60, 'seconds' + resolutionStrategy.cacheDynamicVersionsFor(30, 'seconds') + resolutionStrategy.cacheChangingModulesFor(30, 'seconds') } } diff --git a/Loader/src/main/java/de/com/baseband/launcher/Loader.java b/Loader/src/main/java/de/com/baseband/launcher/Loader.java index 482876c..6e52ef0 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/Loader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/Loader.java @@ -1,5 +1,6 @@ package de.com.baseband.launcher; +import de.com.baseband.clientboot.ClientBoot; import de.com.baseband.launcher.classloader.CustomClassLoader; import de.com.baseband.launcher.security.SecurityImpl; import de.com.baseband.launcher.security.impl.AntiInstrumentationImpl; @@ -7,10 +8,14 @@ import de.com.baseband.launcher.security.impl.JVMArgImpl; import de.com.baseband.launcher.util.GitHash; import de.com.baseband.launcher.util.RSAKey; import de.com.baseband.launcher.util.Util; +import de.tudbut.io.StreamReader; import de.tudbut.io.TypedInputStream; import de.tudbut.io.TypedOutputStream; import de.tudbut.net.http.HTTPUtils; +import de.tudbut.obj.TLMap; +import de.tudbut.parsing.JSON; import de.tudbut.parsing.TCN; +import de.tudbut.parsing.TCNArray; import de.tudbut.security.AccessKiller; import de.tudbut.tools.Hasher; import de.tudbut.tools.SimpleLock; @@ -22,10 +27,7 @@ import oshi.SystemInfo; import oshi.hardware.Processor; import javax.swing.*; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; +import java.io.*; import java.lang.reflect.Method; import java.net.Socket; import java.nio.charset.StandardCharsets; @@ -68,7 +70,80 @@ public class Loader implements Util { CustomClassLoader.class, CustomClassLoader.CustomMixinServer.class); - try(Socket client = new Socket("baseband.com.de", 40000)) { + TCN preOptions; + try { + preOptions = JSON.read(new StreamReader(new FileInputStream("baseband_launch.json")).readAllAsString()); + preOptions.set("ip", null); + } catch (Exception e) { + preOptions = new TCN(); + } + preOptions.setIfAbsent("timeout", 5); + + TCN options = new ClientBoot("BaseBand", preOptions.getInteger("timeout") * 1000, preOptions) + .option("Run BaseBand now", ClientBoot::finish) + .option("Run without BaseBand", x -> { + x.data.set("loadBaseBand", false); + x.finish(); + }) + .option("Run in recovery mode", x -> { + x.data.set("configFile", "baseband.db.tmp"); + new File("baseband.db.tmp").deleteOnExit(); + x.finish(); + }) + .option("Run in debug mode", x -> { + // Broadway-PopBob + if(Hasher.sha512hex(JOptionPane.showInputDialog("I need to make sure you have permission to do this.")).equals("4d05926f29c573e2759f96958025a0a0f2ff6873270c3528d0066a9b6e29ab81f0c633890ef148a4b3da51e50e2c1b96cf9710b4a393bcf1261d54417e255a5e")) { + x.data.set("ip", "localhost"); + x.finish(); + } + else { + x.currentOption().name = "You are not permitted to do this."; + x.currentOption().toLabel(); + x.focus(); + } + }) + .option("Configure", x -> { + x.data.setIfAbsent("disabledModules", new TCNArray()); + x.newScreen() + .option(x.data.getArray("disabledModules").contains("AltControl") ? "Enable AltControl support" : "Disable AltControl support", x1 -> { + if(x.data.getArray("disabledModules").contains("AltControl")) { + x1.currentOption().name = "AltControl enabled."; + x1.data.getArray("disabledModules").remove("AltControl"); + } else { + x1.currentOption().name = "AltControl disabled."; + x1.data.getArray("disabledModules").add("AltControl"); + } + }) + .option("Change config file", x1 -> { + String file = JOptionPane.showInputDialog("Please input the desired name:"); + if(file != null && file.isEmpty()) + file = null; + x1.data.set("configFile", file); + x1.focus(); + }) + .option("Back", ClientBoot::back); + }) + .option("ClientBoot options", x -> x.newScreen() + .option("Set timeout: 2s", x1 -> x1.data.set("timeout", 2)) + .option("Set timeout: 5s", x1 -> x1.data.set("timeout", 5)) + .option("Set timeout: 10s", x1 -> x1.data.set("timeout", 10)) + .option("Back", ClientBoot::back)) + .option("Persist changes", x -> { + try(FileOutputStream fos = new FileOutputStream("baseband_launch.json")) { + fos.write(JSON.writeReadable(x.data).getBytes(StandardCharsets.UTF_8)); + } catch (Exception e) { + throw new RuntimeException(e); + } + }) + .option("Exit Minecraft", x -> exit()) + .show(); + options.setIfAbsent("ip", "baseband.com.de"); + options.setIfAbsent("disabledModules", new TCNArray()); + + if(options.getBoolean("loadBaseBand") == Boolean.FALSE) + return; + + try(Socket client = new Socket(options.getString("ip"), 40000)) { client.setSoTimeout(5000); client.getOutputStream().write(0); TypedInputStream inputStream = new TypedInputStream(client.getInputStream()); @@ -100,6 +175,15 @@ public class Loader implements Util { try { TCN clientData = TCN.readMap(Tools.stringToMap(key.decryptString(inputStream.readString()))); + for (TLMap.Entry entry : options.map.entries()) { + if(entry.val instanceof TCNArray && clientData.get(entry.key) != null) { + clientData.getArray(entry.key).addAll((TCNArray) entry.val); + } + else { + clientData.setIfAbsent(entry.key, entry.val); + } + } + HashMap data = new HashMap<>(); SimpleLock downloadUpdated = new SimpleLock(); SimpleLock continueDownload = new SimpleLock(); diff --git a/Server/build.gradle b/Server/build.gradle index 79dfe5c..3fbc21e 100644 --- a/Server/build.gradle +++ b/Server/build.gradle @@ -16,7 +16,8 @@ configurations { embed compile.extendsFrom(embed) reloadQuickly { - resolutionStrategy.cacheChangingModulesFor 60, 'seconds' + resolutionStrategy.cacheDynamicVersionsFor(30, 'seconds') + resolutionStrategy.cacheChangingModulesFor(30, 'seconds') } }