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 81bba9cd..14c71088 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 @@ -2,6 +2,7 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; @@ -14,7 +15,6 @@ import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.utils.HookException; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -170,7 +170,7 @@ public Path process(Path inputJar) throws IOException { //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); - context.clientModules.forEach(launcherConfigurator::addModuleClass); + properties.put("launcher.modules", context.clientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList())); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { try { diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index dbe125ce..1ea56772 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -31,7 +31,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep EnvHelper.checkDangerousParams(); LauncherConfig config = Launcher.getConfig(); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); + LauncherConfig.initModules(LauncherEngine.modulesManager); LogHelper.info("Launcher for project %s", config.projectName); if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index e468542f..301cd7b1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -80,7 +80,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); + LauncherConfig.initModules(LauncherEngine.modulesManager); LauncherEngine.modulesManager.initModules(null); // Start Launcher initGson(LauncherEngine.modulesManager); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index ecb96566..db685b77 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -443,7 +443,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); //INIT + LauncherConfig.initModules(LauncherEngine.modulesManager); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); LauncherEngine.verifyNoAgent(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 33219b4c..906fccb8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -1,12 +1,17 @@ package pro.gravit.launcher; +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.modules.LauncherModulesManager; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.security.cert.CertificateException; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; @@ -17,6 +22,8 @@ public final class LauncherConfig extends StreamObject { private static final int cenv = -1; @LauncherInject("launchercore.certificates") private static final List secureConfigCertificates = null; + @LauncherInject("launcher.modules") + private static final List> modulesClasses = null; @LauncherInject("launcher.address") public String address; @LauncherInject("launcher.projectName") @@ -118,17 +125,16 @@ public enum LauncherEnvironment { DEV, DEBUG, STD, PROD } - public static void initModules() { - // TODO Fill - /* - * Old filler - public void addModuleClass(String fullName) { - initModuleMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, launcherName, "modulesManager", modulesManagerDesc)); - initModuleMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); - initModuleMethod.instructions.add(new InsnNode(Opcodes.DUP)); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); - } - */ + private static final MethodType VOID_TYPE = MethodType.methodType(void.class); + + public static void initModules(LauncherModulesManager modulesManager) { + for (Class clazz : modulesClasses) + try { + modulesManager.loadModule((LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, VOID_TYPE).invokeWithArguments(Collections.emptyList())); + } catch (Throwable e) { + LogHelper.error(e); + } + // This method should be called once at exec time. + modulesClasses.clear(); } }