From 6cc18ec1b808a4951aa67bef321b3a8ea8ed5d9c Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 25 Aug 2019 12:05:24 +0700 Subject: [PATCH] [FEATURE] ClientHookManager --- .../pro/gravit/launcher/LauncherEngine.java | 6 ++++-- .../launcher/client/ClientLauncher.java | 7 +++++++ .../launcher/managers/ClientHookManager.java | 20 +++++++++++++++++++ .../request/update/UpdateRequest.java | 4 ++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index f2d84e0e..df2edcb3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -12,6 +12,7 @@ import pro.gravit.launcher.gui.RuntimeProvider; import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; +import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; @@ -74,8 +75,9 @@ public void start(String... args) throws Throwable { LauncherConfig.getAutogenConfig().initModules(); Launcher.modulesManager.preInitModules(); if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); + ClientHookManager.initGuiHook.hook(runtimeProvider); runtimeProvider.init(false); - runtimeProvider.preLoad(); + //runtimeProvider.preLoad(); if (Request.service == null) { String address = Launcher.getConfig().address; LogHelper.debug("Start async connection to %s", address); @@ -99,7 +101,7 @@ public void start(String... args) throws Throwable { }; } LauncherGuardManager.initGuard(false); - UpdateRequest.setController(new LauncherUpdateController()); + if(UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController()); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); 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 32b35dd4..b0be3c91 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -38,6 +38,7 @@ import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; +import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.Request; @@ -341,6 +342,7 @@ public static Process launch( output.writeString(Launcher.gsonManager.gson.toJson(profile), 0); assetHDir.write(output); clientHDir.write(output); + ClientHookManager.paramsOutputHook.hook(output); } clientStarted = true; } @@ -383,8 +385,10 @@ public static Process launch( profile.pushOptionalJvmArgs(context.args); Collections.addAll(context.args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(context.args, "-javaagent:".concat(pathLauncher)); + ClientHookManager.clientLaunchHook.hook(context); LauncherGuardManager.guard.addCustomParams(context); Collections.addAll(context.args, ClientLauncher.class.getName()); + ClientHookManager.clientLaunchFinallyHook.hook(context); // Print commandline debug message LogHelper.debug("Commandline: " + context.args); @@ -404,7 +408,9 @@ public static Process launch( builder.redirectOutput(Redirect.PIPE); } // Let's rock! + ClientHookManager.preStartHook.hook(context, builder); process = builder.start(); + if(ClientHookManager.postStartHook.hook(context, builder)) return process; if (!pipeOutput) { for (int i = 0; i < 50; ++i) { if (!process.isAlive()) { @@ -454,6 +460,7 @@ public static void main(String... args) throws Throwable { profile = Launcher.gsonManager.gson.fromJson(input.readString(0), ClientProfile.class); assetHDir = new HashedDir(input); clientHDir = new HashedDir(input); + ClientHookManager.paramsInputHook.hook(input); } } } catch (IOException ex) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java new file mode 100644 index 00000000..3758d281 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java @@ -0,0 +1,20 @@ +package pro.gravit.launcher.managers; + +import pro.gravit.launcher.client.ClientLauncherContext; +import pro.gravit.launcher.gui.RuntimeProvider; +import pro.gravit.launcher.serialize.HInput; +import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.utils.BiHookSet; +import pro.gravit.utils.HookSet; + +public class ClientHookManager { + public static HookSet initGuiHook = new HookSet<>(); + public static HookSet paramsInputHook = new HookSet<>(); + public static HookSet paramsOutputHook = new HookSet<>(); + + public static HookSet clientLaunchHook = new HookSet<>(); + public static HookSet clientLaunchFinallyHook = new HookSet<>(); + + public static BiHookSet preStartHook = new BiHookSet<>(); + public static BiHookSet postStartHook = new BiHookSet<>(); +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index c0977a38..7a45d41a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -46,6 +46,10 @@ public interface UpdateController { public static void setController(UpdateController controller) { UpdateRequest.controller = controller; } + public static UpdateController getController() + { + return controller; + } @Override public String getType() {