From 344c61eaee604b28f75f11e5ed4353a018ad28bc Mon Sep 17 00:00:00 2001 From: Gravita Date: Wed, 10 Mar 2021 00:32:52 +0700 Subject: [PATCH] [FEATURE] DebugMain --- .../binary/tasks/MainBuildTask.java | 1 + .../pro/gravit/launcher/LauncherEngine.java | 4 ++ .../launcher/client/ClientModuleManager.java | 7 +- .../debug/DebugLauncherTrustManager.java | 31 +++++++++ .../pro/gravit/launcher/debug/DebugMain.java | 64 +++++++++++++++++++ .../pro/gravit/launcher/LauncherConfig.java | 15 +++++ build.gradle | 2 +- 7 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java create mode 100644 Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 19c1775b..cb4a4072 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -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 diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index bf67b5b6..9963bf34 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -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; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java index 882e3555..3b9d759c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -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); diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java new file mode 100644 index 00000000..d7869aa8 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java @@ -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); + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java new file mode 100644 index 00000000..0a3f8a55 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java @@ -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 clazz = (Class) Class.forName(className); + try { + return (LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, MethodType.methodType(void.class)).invoke(); + } catch (Throwable throwable) { + throw new InvocationTargetException(throwable); + } + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 77276ea4..bd45f1b0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -98,6 +98,21 @@ public LauncherConfig(String address, ECPublicKey publicKey, Map trustManager = null; } + public LauncherConfig(String address, Map 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 { diff --git a/build.gradle b/build.gradle index b53c73e8..574f9d74 100644 --- a/build.gradle +++ b/build.gradle @@ -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'