mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-03-30 04:58:13 +03:00
[FEATURE] ClientHookManager
This commit is contained in:
parent
c32e6c51db
commit
6cc18ec1b8
4 changed files with 35 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
||||||
import pro.gravit.launcher.gui.RuntimeProvider;
|
import pro.gravit.launcher.gui.RuntimeProvider;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
import pro.gravit.launcher.managers.ClientGsonManager;
|
import pro.gravit.launcher.managers.ClientGsonManager;
|
||||||
|
import pro.gravit.launcher.managers.ClientHookManager;
|
||||||
import pro.gravit.launcher.managers.ConsoleManager;
|
import pro.gravit.launcher.managers.ConsoleManager;
|
||||||
import pro.gravit.launcher.request.Request;
|
import pro.gravit.launcher.request.Request;
|
||||||
import pro.gravit.launcher.request.RequestException;
|
import pro.gravit.launcher.request.RequestException;
|
||||||
|
@ -74,8 +75,9 @@ public void start(String... args) throws Throwable {
|
||||||
LauncherConfig.getAutogenConfig().initModules();
|
LauncherConfig.getAutogenConfig().initModules();
|
||||||
Launcher.modulesManager.preInitModules();
|
Launcher.modulesManager.preInitModules();
|
||||||
if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider();
|
if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider();
|
||||||
|
ClientHookManager.initGuiHook.hook(runtimeProvider);
|
||||||
runtimeProvider.init(false);
|
runtimeProvider.init(false);
|
||||||
runtimeProvider.preLoad();
|
//runtimeProvider.preLoad();
|
||||||
if (Request.service == null) {
|
if (Request.service == null) {
|
||||||
String address = Launcher.getConfig().address;
|
String address = Launcher.getConfig().address;
|
||||||
LogHelper.debug("Start async connection to %s", address);
|
LogHelper.debug("Start async connection to %s", address);
|
||||||
|
@ -99,7 +101,7 @@ public void start(String... args) throws Throwable {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
LauncherGuardManager.initGuard(false);
|
LauncherGuardManager.initGuard(false);
|
||||||
UpdateRequest.setController(new LauncherUpdateController());
|
if(UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController());
|
||||||
Objects.requireNonNull(args, "args");
|
Objects.requireNonNull(args, "args");
|
||||||
if (started.getAndSet(true))
|
if (started.getAndSet(true))
|
||||||
throw new IllegalStateException("Launcher has been already started");
|
throw new IllegalStateException("Launcher has been already started");
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
import pro.gravit.launcher.managers.ClientGsonManager;
|
import pro.gravit.launcher.managers.ClientGsonManager;
|
||||||
|
import pro.gravit.launcher.managers.ClientHookManager;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launcher.profiles.PlayerProfile;
|
import pro.gravit.launcher.profiles.PlayerProfile;
|
||||||
import pro.gravit.launcher.request.Request;
|
import pro.gravit.launcher.request.Request;
|
||||||
|
@ -341,6 +342,7 @@ public static Process launch(
|
||||||
output.writeString(Launcher.gsonManager.gson.toJson(profile), 0);
|
output.writeString(Launcher.gsonManager.gson.toJson(profile), 0);
|
||||||
assetHDir.write(output);
|
assetHDir.write(output);
|
||||||
clientHDir.write(output);
|
clientHDir.write(output);
|
||||||
|
ClientHookManager.paramsOutputHook.hook(output);
|
||||||
}
|
}
|
||||||
clientStarted = true;
|
clientStarted = true;
|
||||||
}
|
}
|
||||||
|
@ -383,8 +385,10 @@ public static Process launch(
|
||||||
profile.pushOptionalJvmArgs(context.args);
|
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, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
|
||||||
Collections.addAll(context.args, "-javaagent:".concat(pathLauncher));
|
Collections.addAll(context.args, "-javaagent:".concat(pathLauncher));
|
||||||
|
ClientHookManager.clientLaunchHook.hook(context);
|
||||||
LauncherGuardManager.guard.addCustomParams(context);
|
LauncherGuardManager.guard.addCustomParams(context);
|
||||||
Collections.addAll(context.args, ClientLauncher.class.getName());
|
Collections.addAll(context.args, ClientLauncher.class.getName());
|
||||||
|
ClientHookManager.clientLaunchFinallyHook.hook(context);
|
||||||
|
|
||||||
// Print commandline debug message
|
// Print commandline debug message
|
||||||
LogHelper.debug("Commandline: " + context.args);
|
LogHelper.debug("Commandline: " + context.args);
|
||||||
|
@ -404,7 +408,9 @@ public static Process launch(
|
||||||
builder.redirectOutput(Redirect.PIPE);
|
builder.redirectOutput(Redirect.PIPE);
|
||||||
}
|
}
|
||||||
// Let's rock!
|
// Let's rock!
|
||||||
|
ClientHookManager.preStartHook.hook(context, builder);
|
||||||
process = builder.start();
|
process = builder.start();
|
||||||
|
if(ClientHookManager.postStartHook.hook(context, builder)) return process;
|
||||||
if (!pipeOutput) {
|
if (!pipeOutput) {
|
||||||
for (int i = 0; i < 50; ++i) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
if (!process.isAlive()) {
|
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);
|
profile = Launcher.gsonManager.gson.fromJson(input.readString(0), ClientProfile.class);
|
||||||
assetHDir = new HashedDir(input);
|
assetHDir = new HashedDir(input);
|
||||||
clientHDir = new HashedDir(input);
|
clientHDir = new HashedDir(input);
|
||||||
|
ClientHookManager.paramsInputHook.hook(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
|
@ -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<>();
|
||||||
|
}
|
|
@ -46,6 +46,10 @@ public interface UpdateController {
|
||||||
public static void setController(UpdateController controller) {
|
public static void setController(UpdateController controller) {
|
||||||
UpdateRequest.controller = controller;
|
UpdateRequest.controller = controller;
|
||||||
}
|
}
|
||||||
|
public static UpdateController getController()
|
||||||
|
{
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
|
Loading…
Reference in a new issue