Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support being called as Java-Agent #14

Open
zbx1425 opened this issue Dec 24, 2023 · 0 comments
Open

Support being called as Java-Agent #14

zbx1425 opened this issue Dec 24, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@zbx1425
Copy link

zbx1425 commented Dec 24, 2023

Support being called as Java-Agent would enable Packwiz-Installer to be used on:

  • Launchers that has incorrect handling of $INST_JAVA, meaning they can't start packwiz-installer from pre-launch commands reliably (HMCL / PCL2)
  • Launchers that don't support pre-launch commands (Mojang Launcher, IIRC?)

Currently there's a community workaround for the aforementioned issues ("packwiz-installer-bootstrap-wrapper") by teacon.org:

package org.teacon.codenamed;

import java.io.File;
import java.lang.instrument.Instrumentation;

public class JavaAgentEntryPoint {

  public static void premain(String args, Instrumentation inst) {
    String javaExecutable = System.getProperty("java.home") + System.getProperty("java.home") + "bin" + File.separator;
    if (System.getProperty("os.name").startsWith("Win")) {
      javaExecutable = javaExecutable + "javaw.exe";
    } else {
      javaExecutable = javaExecutable + "java";
    } 
    try {
      Process p = (new ProcessBuilder(new String[] { javaExecutable, "-jar", "packwiz-installer-bootstrap.jar", "--bootstrap-main-jar", "packwiz-installer.jar", "--bootstrap-no-update", args })).inheritIO().start();
      int exitCode;
      if ((exitCode = p.waitFor()) != 0)
        throw new RuntimeException("Process exit status is " + exitCode + ", meaning an error has occurred."); 
    } catch (Exception e) {
      throw new RuntimeException("Game failed to launch, see console output for details.", e);
    } 
  }
}
@comp500 comp500 added the enhancement New feature or request label Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants