fix loader reloading
All checks were successful
/ Build BaseBand Loader (push) Successful in 1m59s

This commit is contained in:
Daniella / Tove 2024-10-14 01:52:55 +02:00
parent 34a9334eaf
commit 90ae1dad40
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -363,7 +363,7 @@ public class Loader implements Util {
}
options.set("build-name", branches.getSub(options.getString("branch")).getString("name"));
HashMap<String, byte[]> data = downloadFromSPL("https://download.baseband.com.de/download/client/" + options.getString("branch"));
HashMap<String, byte[]> data = downloadFromSPL("https://download.baseband.com.de/download/client/" + options.getString("branch"), null);
LOGGER.info("BaseBand downloaded: {} chunks.", data.size());
LOGGER.info("Booting BaseBand {} @ {}", options.getString("build-name"), new String(data.get("commit")).trim());
classLoader = new GameClassLoader(data);
@ -374,7 +374,7 @@ public class Loader implements Util {
private static void splUpdate() {
LOGGER.info("BaseBand is downloading a significant update...");
SimpleClassLoader loaderReloader = new SimpleClassLoader(downloadFromSPL("https://download.baseband.com.de/download/loader"));
SimpleClassLoader loaderReloader = new SimpleClassLoader(downloadFromSPL("https://download.baseband.com.de/download/loader", HTTPUtils.decodeUTF8(Loader.class.getProtectionDomain().getCodeSource().getLocation().getFile())));
LOGGER.info("BaseBand has downloaded a significant update. Applying...");
try {
loaderReloader.loadClass(Tweaker.class.getName()).getMethod("load").invoke(null);
@ -385,9 +385,18 @@ public class Loader implements Util {
}
}
private static HashMap<String, byte[]> downloadFromSPL(String url) {
private static HashMap<String, byte[]> downloadFromSPL(String url, String filename) {
HashMap<String, byte[]> data = new HashMap<>();
try (ZipInputStream jar = new ZipInputStream(new URL(url).openStream())) {
try (InputStream urlStream = new URL(url).openStream()) {
InputStream stream = urlStream;
if(filename != null) {
byte[] bytes = new StreamReader(stream).readAllAsBytes();
try(FileOutputStream os = new FileOutputStream(filename)) {
os.write(bytes);
}
stream = new ByteArrayInputStream(bytes);
}
ZipInputStream jar = new ZipInputStream(stream);
ZipEntry entry;
while ((entry = jar.getNextEntry()) != null) {
byte[] bytes = new StreamReader(jar).readAllAsBytes();