diff --git a/Client/build.gradle b/Client/build.gradle index 7e2b880..7394041 100644 --- a/Client/build.gradle +++ b/Client/build.gradle @@ -78,7 +78,8 @@ dependencies { } jarLibs(files('libs/TuddyLIB.jar')) - implementation(files('libs/mcregistry.jar')) + // should NOT go into the jar. + implementation(files('libs/mcregistry-1.0.jar')) jarLibs 'club.minnced:java-discord-rpc:2.0.2' diff --git a/Client/libs/TuddyLIB.jar b/Client/libs/TuddyLIB.jar index 8bc1d09..d1eb1de 100644 Binary files a/Client/libs/TuddyLIB.jar and b/Client/libs/TuddyLIB.jar differ diff --git a/Client/libs/mcregistry-1.0.jar b/Client/libs/mcregistry-1.0.jar index 6b2080b..98b9ed9 100644 Binary files a/Client/libs/mcregistry-1.0.jar and b/Client/libs/mcregistry-1.0.jar differ diff --git a/Client/src/main/java/com/baseband/client/BaseBand.java b/Client/src/main/java/com/baseband/client/BaseBand.java index f9f8fbb..3a93945 100644 --- a/Client/src/main/java/com/baseband/client/BaseBand.java +++ b/Client/src/main/java/com/baseband/client/BaseBand.java @@ -2,17 +2,19 @@ package com.baseband.client; import com.baseband.client.command.CommandManager; -import com.baseband.client.data.LCIO; import com.baseband.client.event.EventBus; import com.baseband.client.event.FMLEventProcessor; import com.baseband.client.module.Module; import com.baseband.client.module.modules.*; +import de.tudbut.tools.Registry; +import de.tudbut.mcregistry.MCRegistry; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import tudbut.parsing.TCN; import tudbut.tools.Lock; import java.util.ArrayList; @@ -20,16 +22,19 @@ import java.util.ArrayList; @Mod(modid = "baseband") public class BaseBand { public static int majorVersion = 1; - public static int buildNumber = 50; - public static String hash = "57ef0c99a21035ef"; + public static int buildNumber = 69; + public static String hash = "1251518fc0644b2b"; public static String name = "BaseBand"; - public long timeOfCompile = 1694973944897L; + public long timeOfCompile = 1694986783983L; public CommandManager commandRegistry; public EventBus eventBus; - public static ConfigManager configManager = new ConfigManager("config.bb"); public ArrayList modules = new ArrayList<>(); - public static BaseBand INSTANCE; { INSTANCE = this; } + public static BaseBand INSTANCE; + public static Registry Registry; + private static TCN registryData; + + { INSTANCE = this; } public static BaseBand getInstance() { if(INSTANCE == null) { @@ -39,10 +44,6 @@ public class BaseBand { } public static final Logger log = LogManager.getLogger("BaseBand"); - public static void handleLCIO(String key, Object value) { - - } - @Mod.EventHandler public void eventInit(FMLPreInitializationEvent event) { onInit(); @@ -50,9 +51,20 @@ public class BaseBand { public void onInit() { Utils.check(); - String lcioClass = System.getProperty("org.bb.lcio"); - System.setProperty("org.bb.lcio", ""); - LCIO.init(lcioClass); + try { + Registry = MCRegistry.registerMod("baseband"); + registryData = Registry.register("*"); + } catch (Exception e) { + // tamper detected + Utils.crash(); + } + // cant be a normal if statement because it might be null + if(registryData.get("LoaderPresent") != Boolean.TRUE) { + // do other stuff here later? + log.info("No loader present, but able to start anyway ==> Debug environment detected."); + } + // unset so this wont be discovered and manipulated + registryData.set("LoaderPresent", null); commandRegistry = new CommandManager(); eventBus = new EventBus(); @@ -73,7 +85,6 @@ public class BaseBand { MinecraftForge.EVENT_BUS.register(new FMLEventProcessor()); try { - configManager.load(); for (Module m : modules) { if(m.isEnabled()) { MinecraftForge.EVENT_BUS.register(m); @@ -81,14 +92,14 @@ public class BaseBand { } } } catch(Exception e) { - configManager.save(); + ConfigManager.save(); } new Thread(() -> { Lock lock = new Lock(); while(true) { lock.lock(10000); - configManager.save(); + ConfigManager.save(); lock.waitHere(); } }, "Config save thread").start(); diff --git a/Client/src/main/java/com/baseband/client/ConfigManager.java b/Client/src/main/java/com/baseband/client/ConfigManager.java index b9c6031..4621a31 100644 --- a/Client/src/main/java/com/baseband/client/ConfigManager.java +++ b/Client/src/main/java/com/baseband/client/ConfigManager.java @@ -13,38 +13,11 @@ import java.nio.file.Paths; public class ConfigManager { - private final String path; - - public ConfigManager(String path) { - this.path = path; - } - - public void save() { - TCN tcn = new TCN(); - - tcn.set("base", ConfigSaverTCN2.write(BaseBand.INSTANCE, false, true)); - + public static void save() { for (Module module : BaseBand.INSTANCE.modules) { - tcn.set(module.getClass().getSimpleName(), ConfigSaverTCN2.write(module, false, true)); - } - - try(OutputStream stream = Files.newOutputStream(Paths.get(path))) { - stream.write(JSON.write(tcn).getBytes()); - } catch (IOException e) { - e.printStackTrace(); + module.updateData(); } } - public void load() { - try(InputStream stream = Files.newInputStream(Paths.get(path))) { - TCN tcn = JSON.read(new StreamReader(stream).readAllAsString()); - ConfigSaverTCN2.read(tcn.getSub("base"), BaseBand.INSTANCE); - for (Module module : BaseBand.INSTANCE.modules) { - ConfigSaverTCN2.read(tcn.getSub(module.getClass().getSimpleName()), module); - } - } catch (IOException | JSONFormatException | ClassNotFoundException e) { - e.printStackTrace(); - } - } } diff --git a/Client/src/main/java/com/baseband/client/data/LCIO.java b/Client/src/main/java/com/baseband/client/data/LCIO.java deleted file mode 100644 index 2125376..0000000 --- a/Client/src/main/java/com/baseband/client/data/LCIO.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baseband.client.data; - -import com.baseband.client.BaseBand; - -import java.util.LinkedHashMap; -import java.util.Map; - -public class LCIO { - - private static Map params = new LinkedHashMap<>(); - - - public static void init(String loaderLCIO) { - try { - params = (Map) Class.forName(loaderLCIO).getMethod("init", Class.class).invoke(null, LCIO.class); - for (Map.Entry entry : params.entrySet().toArray(new Map.Entry[0])) { - BaseBand.handleLCIO(entry.getKey(), entry.getValue()); - } - } catch (Exception ignored) { - // ignore. no loader is fine after utils has checked it - } - } - - public static void update(String param, Object value, Map params) { - LCIO.params = params; - BaseBand.handleLCIO(param, value); - } - - -} diff --git a/Client/src/main/java/com/baseband/client/module/Module.java b/Client/src/main/java/com/baseband/client/module/Module.java index bb45ad1..371e4db 100644 --- a/Client/src/main/java/com/baseband/client/module/Module.java +++ b/Client/src/main/java/com/baseband/client/module/Module.java @@ -1,9 +1,13 @@ package com.baseband.client.module; import com.baseband.client.BaseBand; +import de.tudbut.tools.Registry; import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; +import scala.xml.dtd.impl.Base; import tudbut.obj.Save; +import tudbut.parsing.TCN; +import tudbut.tools.ConfigSaverTCN2; public abstract class Module { @Save @@ -27,7 +31,20 @@ public abstract class Module { } } + TCN data; + { + try { + data = BaseBand.Registry.register(this.toString()); + if(data.getSub("@Save") != null) + ConfigSaverTCN2.read(data.getSub("@Save"), this); + } catch (IllegalAccessException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + public void updateData() { + data.set("@Save", ConfigSaverTCN2.write(this, false, true)); + } protected static Minecraft mc = Minecraft.getMinecraft(); diff --git a/Loader/build.gradle b/Loader/build.gradle index 129cfa3..cf6a7b3 100644 --- a/Loader/build.gradle +++ b/Loader/build.gradle @@ -71,6 +71,8 @@ dependencies { } implementation project(path: ':Client') + // should NOT go into the jar. + implementation files('libs/mcregistry-1.0.jar') annotationProcessor('org.spongepowered:mixin:0.8.5:processor') { diff --git a/Loader/libs/mcregistry-1.0.jar b/Loader/libs/mcregistry-1.0.jar new file mode 100644 index 0000000..98b9ed9 Binary files /dev/null and b/Loader/libs/mcregistry-1.0.jar differ diff --git a/Loader/src/main/java/org/baseband/launcher/data/LCIO.java b/Loader/src/main/java/org/baseband/launcher/data/LCIO.java deleted file mode 100644 index 9a174d4..0000000 --- a/Loader/src/main/java/org/baseband/launcher/data/LCIO.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.baseband.launcher.data; - -import java.lang.reflect.InvocationTargetException; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Allows interop between loader and client - */ -public class LCIO { - - private static Class clientLCIO; - private static final Map params = new LinkedHashMap<>(); - - public static Map init(Class lcioClient) { - clientLCIO = lcioClient; - return params; - } - - public static void setClientParam(String param, Object data) { - params.put(param, data); - if(clientLCIO != null) { - // already initialized. update params - try { - clientLCIO.getMethod("update", String.class, Object.class, Map.class).invoke(null, param, data, params); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - -} diff --git a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java index cd25dca..41ea94e 100644 --- a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java +++ b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java @@ -1,11 +1,13 @@ package org.baseband.launcher.launch; +import de.tudbut.mcregistry.MCRegistry; +import de.tudbut.tools.Registry; import net.minecraft.launchwrapper.Launch; import org.baseband.launcher.Tweaker; -import org.baseband.launcher.data.LCIO; import org.baseband.launcher.util.CustomClassloader; import org.baseband.launcher.util.Key; import sun.misc.Unsafe; +import tudbut.parsing.TCN; import javax.swing.*; import java.io.*; @@ -213,7 +215,12 @@ public class Loader { } } - System.setProperty("org.bb.lcio", LCIO.class.getName()); + Registry baseBandRegistry = MCRegistry.registerMod("baseband"); + TCN tcn = baseBandRegistry.register("*"); + tcn.set("LoaderPresent", true); + // this is not the real mod, so unregister so the actual client can register it + baseBandRegistry.unregister("*", tcn); + MCRegistry.unregisterMod("baseband", baseBandRegistry); Tweaker.log("Loaded."); Tweaker.latch.countDown();