[FEATURE] DebugMain

This commit is contained in:
Gravita 2021-03-10 00:32:52 +07:00
parent 1e7f5c9eb4
commit 344c61eaee
7 changed files with 117 additions and 7 deletions

View file

@ -40,6 +40,7 @@ public MainBuildTask(LaunchServer srv) {
reader = new ClassMetadataReader();
InjectClassAcceptor injectClassAcceptor = new InjectClassAcceptor(properties);
transformers.add(injectClassAcceptor);
blacklist.add("pro/gravit/launcher/debug/");
}
@Override

View file

@ -140,6 +140,10 @@ public static LauncherEngine clientInstance() {
return new LauncherEngine();
}
public static LauncherEngine newInstance() {
return new LauncherEngine();
}
public void readKeys() throws IOException, InvalidKeySpecException {
if (privateKey != null || publicKey != null) return;
Path dir = DirBridge.dir;

View file

@ -8,7 +8,7 @@
import java.nio.file.Path;
import java.util.Collection;
public class ClientModuleManager extends SimpleModuleManager {
public final class ClientModuleManager extends SimpleModuleManager {
public ClientModuleManager() {
super(null, null, Launcher.getConfig().trustManager);
}
@ -23,11 +23,6 @@ public void autoload(Path dir) {
throw new UnsupportedOperationException();
}
@Override
public LauncherModule loadModule(Path file) {
throw new UnsupportedOperationException();
}
@Override
public LauncherModule loadModule(LauncherModule module) {
return super.loadModule(module);

View file

@ -0,0 +1,31 @@
package pro.gravit.launcher.debug;
import pro.gravit.launcher.LauncherTrustManager;
import java.security.cert.X509Certificate;
public class DebugLauncherTrustManager extends LauncherTrustManager {
private final TrustDebugMode mode;
public DebugLauncherTrustManager(X509Certificate[] trustSigners) {
super(trustSigners);
this.mode = null;
}
public DebugLauncherTrustManager() {
super(new X509Certificate[0]);
this.mode = null;
}
public DebugLauncherTrustManager(TrustDebugMode mode) {
super(new X509Certificate[0]);
this.mode = mode;
}
public enum TrustDebugMode {
TRUST_ALL
}
@Override
public CheckClassResult checkCertificates(X509Certificate[] certs, CertificateChecker checker) {
if(mode == TrustDebugMode.TRUST_ALL) return new CheckClassResult(CheckClassResultType.SUCCESS, null, null);
return super.checkCertificates(certs, checker);
}
}

View file

@ -0,0 +1,64 @@
package pro.gravit.launcher.debug;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherConfig;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.client.ClientLauncherCoreModule;
import pro.gravit.launcher.client.ClientModuleManager;
import pro.gravit.launcher.managers.ConsoleManager;
import pro.gravit.launcher.modules.LauncherModule;
import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.utils.helper.LogHelper;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
public class DebugMain {
public static final AtomicBoolean IS_DEBUG = new AtomicBoolean(false);
public static String webSocketURL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api");
public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft");
public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(",");
public static String[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(",");
public static LauncherConfig.LauncherEnvironment environment = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD"));
public static void main(String[] args) throws Throwable {
LogHelper.printVersion("Launcher");
LogHelper.printLicense("Launcher");
IS_DEBUG.set(true);
LogHelper.info("Launcher start in DEBUG mode (Only for developers)");
LogHelper.debug("Initialization LauncherConfig");
LauncherConfig config = new LauncherConfig(webSocketURL, new HashMap<>(), projectName, environment, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL));
Launcher.setConfig(config);
Launcher.applyLauncherEnv(environment);
LauncherEngine.modulesManager = new ClientModuleManager();
LauncherEngine.modulesManager.loadModule(new ClientLauncherCoreModule());
for(String moduleClassName : moduleClasses) {
if(moduleClassName.isEmpty()) continue;
LauncherEngine.modulesManager.loadModule(newModule(moduleClassName));
}
for(String moduleFileName : moduleFiles) {
if(moduleFileName.isEmpty()) continue;
LauncherEngine.modulesManager.loadModule(Paths.get(moduleFileName));
}
LauncherEngine.modulesManager.initModules(null);
LauncherEngine.initGson(LauncherEngine.modulesManager);
ConsoleManager.initConsole();
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
LogHelper.debug("Initialization LauncherEngine");
LauncherEngine instance = LauncherEngine.newInstance();
instance.start(args);
}
@SuppressWarnings("unchecked")
public static LauncherModule newModule(String className) throws ClassNotFoundException, InvocationTargetException {
Class<? extends LauncherModule> clazz = (Class<? extends LauncherModule>) Class.forName(className);
try {
return (LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, MethodType.methodType(void.class)).invoke();
} catch (Throwable throwable) {
throw new InvocationTargetException(throwable);
}
}
}

View file

@ -98,6 +98,21 @@ public LauncherConfig(String address, ECPublicKey publicKey, Map<String, byte[]>
trustManager = null;
}
public LauncherConfig(String address, Map<String, byte[]> runtime, String projectName, LauncherEnvironment env, LauncherTrustManager trustManager) {
this.address = address;
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
this.projectName = projectName;
this.clientPort = 32148;
this.publicKey = null;
this.trustManager = trustManager;
environment = env;
guardType = "no";
isWarningMissArchJava = true;
secureCheckSalt = null;
secureCheckHash = null;
passwordEncryptKey = null;
}
public static void initModules(LauncherModulesManager modulesManager) {
for (Class<?> clazz : modulesClasses)
try {

View file

@ -5,7 +5,7 @@
id 'org.openjfx.javafxplugin' version '0.0.8' apply false
}
group = 'pro.gravit.launcher'
version = '5.1.10'
version = '5.1.11-SNAPSHOT'
apply from: 'props.gradle'