[FEATURE] ClientHookManager

This commit is contained in:
Gravit 2019-08-25 12:05:24 +07:00
parent c32e6c51db
commit 6cc18ec1b8
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 35 additions and 2 deletions

View file

@ -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");

View file

@ -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) {

View file

@ -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<RuntimeProvider> initGuiHook = new HookSet<>();
public static HookSet<HInput> paramsInputHook = new HookSet<>();
public static HookSet<HOutput> paramsOutputHook = new HookSet<>();
public static HookSet<ClientLauncherContext> clientLaunchHook = new HookSet<>();
public static HookSet<ClientLauncherContext> clientLaunchFinallyHook = new HookSet<>();
public static BiHookSet<ClientLauncherContext, ProcessBuilder> preStartHook = new BiHookSet<>();
public static BiHookSet<ClientLauncherContext, ProcessBuilder> postStartHook = new BiHookSet<>();
}

View file

@ -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() {