Fix mcregistry things?

This commit is contained in:
Daniella / Tove 2023-09-19 10:17:39 +02:00
parent cfbf62cf7d
commit 779e98bfc3
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
5 changed files with 56 additions and 31 deletions

Binary file not shown.

Binary file not shown.

View file

@ -6,26 +6,37 @@ import com.baseband.client.event.EventBus;
import com.baseband.client.event.FMLEventProcessor; import com.baseband.client.event.FMLEventProcessor;
import com.baseband.client.module.Module; import com.baseband.client.module.Module;
import com.baseband.client.module.modules.*; import com.baseband.client.module.modules.*;
import de.tudbut.mcregistry.MCRegistry;
import de.tudbut.tools.Registry; import de.tudbut.tools.Registry;
import de.tudbut.tools.Tools;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import tudbut.io.StreamRedirect;
import tudbut.parsing.TCN; import tudbut.parsing.TCN;
import tudbut.tools.Lock; import tudbut.tools.Lock;
import javax.swing.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
@Mod(modid = "baseband") @Mod(modid = "baseband")
public class BaseBand { public class BaseBand {
public static int majorVersion = 1; public static int majorVersion = 1;
public static int buildNumber = 80; public static int buildNumber = 84;
public static String hash = "7230b537553aaf14"; public static String hash = "0cfe2c39e4ab2abf";
public static String name = "BaseBand"; public static String name = "BaseBand";
public long timeOfCompile = 1695103883523L; public long timeOfCompile = 1695111349604L;
public CommandManager commandRegistry; public CommandManager commandRegistry;
public EventBus eventBus; public EventBus eventBus;
public ArrayList<Module> modules = new ArrayList<>(); public ArrayList<Module> modules = new ArrayList<>();
@ -61,21 +72,6 @@ public class BaseBand {
public void onInit() { public void onInit() {
Utils.check(); Utils.check();
//TODO: this is temporary and bad, Tud, figure out how the classloader can be used to not do this
try {
String key = System.getProperty("com.bb.key");
String[] data = new Key(key).decryptString(System.getProperty("com.bb.data")).split(":");
level = Integer.parseInt(data[0]);
System.clearProperty("com.bb.data");
System.clearProperty("com.bb.key");
}catch (Exception ignored){
//It's fine, we already Utils.check()ed
}
/*
try { try {
Registry = MCRegistry.registerMod("baseband"); Registry = MCRegistry.registerMod("baseband");
registryData = Registry.register("*"); registryData = Registry.register("*");
@ -84,16 +80,20 @@ public class BaseBand {
Utils.crash(); Utils.crash();
} }
// cant be a normal if statement because it might be null // cant be a normal if statement because it might be null
if(registryData.get("LoaderPresent") != Boolean.TRUE) { if (registryData.get("LoaderPresent") == Boolean.TRUE) {
String key = registryData.getString("Key");
TCN data = TCN.readMap(Tools.stringToMap(new Key(key).decryptString(registryData.getString("Data"))));
registryData.set("Key", null);
registryData.set("Level", null);
this.level = data.getInteger("level");
} else {
// do other stuff here later? // do other stuff here later?
log.info("No loader present, but able to start anyway ==> Debug environment detected."); log.info("No loader present, but able to start anyway ==> Debug environment detected.");
} }
// unset so this wont be discovered and manipulated // unset so this won't be discovered and manipulated
registryData.set("LoaderPresent", null); registryData.set("LoaderPresent", null);
*/
//TODO: fix
commandRegistry = new CommandManager(); commandRegistry = new CommandManager();
eventBus = new EventBus(); eventBus = new EventBus();
@ -164,7 +164,6 @@ public class BaseBand {
} }
public static <T extends Module> T getModule(Class<? extends T> module) { public static <T extends Module> T getModule(Class<? extends T> module) {
for (int i = 0; i < INSTANCE.modules.size(); i++) { for (int i = 0; i < INSTANCE.modules.size(); i++) {
if(INSTANCE.modules.get(i).getClass() == module) { if(INSTANCE.modules.get(i).getClass() == module) {

Binary file not shown.

View file

@ -1,10 +1,14 @@
package org.baseband.launcher.launch; package org.baseband.launcher.launch;
import de.tudbut.mcregistry.MCRegistry;
import de.tudbut.tools.Registry;
import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.Launch;
import org.baseband.launcher.Tweaker; import org.baseband.launcher.Tweaker;
import org.baseband.launcher.util.CustomClassloader; import org.baseband.launcher.util.CustomClassloader;
import org.baseband.launcher.util.Key; import org.baseband.launcher.util.Key;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import tudbut.io.StreamRedirect;
import tudbut.parsing.TCN;
import javax.swing.*; import javax.swing.*;
import java.io.*; import java.io.*;
@ -12,6 +16,7 @@ import java.lang.management.ManagementFactory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.Socket; import java.net.Socket;
import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.*; import java.util.*;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
@ -215,15 +220,16 @@ public class Loader {
} }
} }
downloadMCRegistry();
new CustomClassloader(classCache); new CustomClassloader(classCache);
//Registry baseBandRegistry = MCRegistry.registerMod("baseband"); Registry baseBandRegistry = MCRegistry.registerMod("baseband");
//TCN tcn = baseBandRegistry.register("*"); TCN tcn = baseBandRegistry.register("*");
//tcn.set("LoaderPresent", true); tcn.set("LoaderPresent", true);
// this is not the real mod, so unregister so the actual client can register it // this is not the real mod, therefore unregister so the actual client can register it
//baseBandRegistry.unregister("*", tcn); baseBandRegistry.unregister("*", tcn);
//MCRegistry.unregisterMod("baseband", baseBandRegistry); MCRegistry.unregisterMod("baseband", baseBandRegistry);
//TODO: fix
Tweaker.log(String.format("Loaded. (Took %s milliseconds.)", System.nanoTime() / 1000000L - startTime)); Tweaker.log(String.format("Loaded. (Took %s milliseconds.)", System.nanoTime() / 1000000L - startTime));
@ -234,6 +240,26 @@ public class Loader {
} }
} }
private static void downloadMCRegistry() {
try {
Class.forName("de.tudbut.mcregistry.MCRegistry");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Minecraft needs to restart to download BaseBand's required libraries.");
try {
InputStream uis = new URL("https://github.com/TudbuT/mcregistry/releases/download/v1.0/mcregistry-1.0.jar").openStream();
FileOutputStream fos = new FileOutputStream("mods/mcregistry-1.0.jar");
StreamRedirect.redirect(uis, fos, new HashMap<>()).waitForFinish(0);
uis.close();
fos.close();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Unable to download BaseBand's required libraries. Please install mcregistry manually.");
throw new RuntimeException(ex);
}
System.out.println("----------- THIS IS NOT A BUG. CRASHING ON PURPOSE TO END GAME QUICKLY.");
throw new Error("THIS IS NOT A BUG!!!");
}
}
public static String generate() { public static String generate() {
try { try {