i dunno this might break something but it'll look cool otherwise

This commit is contained in:
Jess H 2024-06-20 01:38:17 +01:00
parent 436b301378
commit 48703cd107
Signed by: UnixSystemV
GPG key ID: 9B21C50B68D67F19
2 changed files with 62 additions and 3 deletions

View file

@ -6,12 +6,14 @@ import de.com.baseband.launcher.security.impl.AntiInstrumentationImpl;
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.SecondCounter;
import de.com.baseband.launcher.util.Util;
import de.tudbut.io.TypedInputStream;
import de.tudbut.io.TypedOutputStream;
import de.tudbut.net.http.HTTPUtils;
import de.tudbut.parsing.TCN;
import de.tudbut.tools.Hasher;
import de.tudbut.tools.Lock;
import de.tudbut.tools.Tools;
import de.tudbut.tools.encryption.Key;
import de.tudbut.tools.encryption.RawKey;
@ -29,6 +31,7 @@ import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -86,9 +89,21 @@ public class Loader implements Util {
LOGGER.info("BaseBand has downloaded a significant update. Minecraft will exit.");
JOptionPane.showMessageDialog(null, "BaseBand has downloaded a significant update. Please restart Minecraft.");
exit();
}
else if(status == Response.OK) {
} else if(status == Response.OK) {
LOGGER.info(status.name);
SecondCounter secondCounter = new SecondCounter();
AtomicBoolean downloaded = new AtomicBoolean(false);
Thread thread = new Thread(() -> {
while(!downloaded.get()) {
new Lock().waitHere(2000);
if (secondCounter.getCount() == 0) {
LOGGER.warn("BaseBand appears to have stopped downloading.");
} else {
LOGGER.warn("BaseBand is downloading at a rate of " + (secondCounter.getCount() / 1024) + " kilobytes per second. (if this seems low then restart your game.)");
}
}
});
thread.start();
try {
TCN clientData = TCN.readMap(Tools.stringToMap(key.decryptString(inputStream.readString())));
@ -96,9 +111,14 @@ public class Loader implements Util {
RawKey rk = new RawKey(key.toBytes());
int n = inputStream.readInt();
for (int i = 0; i < n; i++) {
data.put(rk.decryptString(inputStream.readString()), rk.decryptBytes(inputStream.readByteArray()));
String name = inputStream.readString();
byte[] bytes = inputStream.readByteArray();
data.put(rk.decryptString(name), rk.decryptBytes(bytes));
secondCounter.increment(bytes.length);
}
downloaded.set(true);
LOGGER.info("BaseBand downloaded: {} classes.", data.size());
thread.stop();
classLoader = new CustomClassLoader(data);
classLoader.inject();
classLoader.informClient(clientData);

View file

@ -0,0 +1,39 @@
package de.com.baseband.launcher.util;
import java.util.LinkedList;
import java.util.Queue;
public class SecondCounter {
private static class TimeStampedByte {
long timestamp;
int bytes;
TimeStampedByte(long timestamp, int bytes) {
this.timestamp = timestamp;
this.bytes = bytes;
}
}
private final Queue<TimeStampedByte> count = new LinkedList<>();
public void increment(int bytes) {
count.add(new TimeStampedByte(System.currentTimeMillis() + 1000L, bytes));
}
public int getCount() {
long time = System.currentTimeMillis();
try {
while (!count.isEmpty() && count.peek().timestamp < time) {
count.remove();
}
} catch (Exception e) {
// empty catch block
}
int byteCount = 0;
for (TimeStampedByte tsb : count) {
byteCount += tsb.bytes;
}
return byteCount;
}
}