mirror of
https://github.com/GTNewHorizons/lwjgl3ify.git
synced 2026-11-21 12:42:15 +00:00
Start work on the relauncher coremod
This commit is contained in:
1 parent
e4b8c6ea95
commit
6f0e9e7d28
9 files changed
+334
-29
No files matched your search
+45
-2
@@ -32,6 +32,10 @@ for (openSpec in addOpens) {
|
||||
extraJavaArgs += ["--add-opens", openSpec]
|
||||
}
|
||||
|
||||
minecraft {
|
||||
injectedTags.put "RECOMMENDED_JAVA_ARGS", extraJavaArgs.join("\t")
|
||||
}
|
||||
|
||||
SourceSet forgePatchesSet
|
||||
SourceSet hotswapSet
|
||||
|
||||
@@ -105,6 +109,7 @@ def forgePatchesJar = tasks.register(forgePatchesSet.jarTaskName, Jar) {
|
||||
}
|
||||
}
|
||||
exclude("module-info.class")
|
||||
exclude("META-INF/versions/9/module-info.class")
|
||||
exclude("log4j2.xml")
|
||||
archiveClassifier.set("forgePatches")
|
||||
manifest {
|
||||
@@ -217,8 +222,6 @@ veryNewJavaToolchainSpec.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
def newJavaLauncher = javaToolchains.launcherFor(veryNewJavaToolchainSpec)
|
||||
|
||||
minecraft.extraRunJvmArguments.addAll(extraJavaArgs)
|
||||
|
||||
for (jarTask in ["jar", "shadowJar", "forgePatchesJar"]) {
|
||||
tasks.named(jarTask, Jar).configure {
|
||||
manifest {
|
||||
@@ -230,6 +233,7 @@ for (jarTask in ["jar", "shadowJar", "forgePatchesJar"]) {
|
||||
for (runTask in ["runClient", "runServer"]) {
|
||||
tasks.named(runTask, JavaExec).configure {
|
||||
classpath = forgePatchesSet.output + classpath
|
||||
extraJvmArgs = extraJavaArgs
|
||||
javaLauncher.set(newJavaLauncher)
|
||||
}
|
||||
}
|
||||
@@ -237,10 +241,49 @@ for (runTask in ["runClient", "runServer"]) {
|
||||
for (runTask in ["runObfClient", "runObfServer"]) {
|
||||
tasks.named(runTask, JavaExec).configure {
|
||||
classpath = files(forgePatchesJar) + classpath
|
||||
extraJvmArgs = extraJavaArgs
|
||||
javaLauncher.set(newJavaLauncher)
|
||||
}
|
||||
}
|
||||
|
||||
def CLIENT = Class.forName("com.gtnewhorizons.retrofuturagradle.util.Distribution", true, tasks.runClient.class.classLoader).getField("CLIENT").get(null)
|
||||
|
||||
def originalLaunchWrapperPath = project.layout.buildDirectory.file("launchwrapper-1.12.jar").get().asFile
|
||||
|
||||
def runWithRelauncher = tasks.register("runClientWithRelauncher", tasks.runClient.class, CLIENT, gradle)
|
||||
runWithRelauncher.configure {
|
||||
setup(project)
|
||||
group = "lwjgl3ify"
|
||||
description = "Runs the deobfuscated client while triggering the relauncher"
|
||||
dependsOn(
|
||||
sourceSets.mcLauncher.classesTaskName,
|
||||
tasks.downloadVanillaAssets,
|
||||
tasks.packagePatchedMc,
|
||||
"jar")
|
||||
|
||||
username = minecraft.getUsername()
|
||||
userUUID = minecraft.getUserUUID()
|
||||
lwjglVersion = 2
|
||||
|
||||
systemProperty "gradlestart.bouncerClient", "net.minecraft.launchwrapper.Launch"
|
||||
|
||||
classpath(tasks.packageMcLauncher)
|
||||
classpath(tasks.packagePatchedMc)
|
||||
classpath(originalLaunchWrapperPath)
|
||||
classpath(configurations.patchedMinecraft)
|
||||
classpath(tasks.jar)
|
||||
classpath(configurations.runtimeClasspath)
|
||||
mainClass = "GradleStart"
|
||||
|
||||
doFirst {
|
||||
download.run {
|
||||
src 'https://libraries.minecraft.net/net/minecraft/launchwrapper/1.12/launchwrapper-1.12.jar'
|
||||
dest originalLaunchWrapperPath
|
||||
overwrite false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("runObfClient", JavaExec) {
|
||||
mainClass.set("com.gtnewhorizons.retrofuturabootstrap.Main")
|
||||
}
|
||||
|
||||
@@ -2,3 +2,11 @@
|
||||
// Regular runClient/runServer tasks run in Java 17 in this project.
|
||||
tasks.named("runClient17") { enabled = false }
|
||||
tasks.named("runServer17") { enabled = false }
|
||||
|
||||
tasks.named("jar", Jar) {
|
||||
manifest.attributes.put("TweakClass", "me.eigenraven.lwjgl3ify.relauncher.Lwjgl3ifyRelauncherTweaker")
|
||||
}
|
||||
|
||||
tasks.named("shadowJar", Jar) {
|
||||
manifest.attributes.put("TweakClass", "me.eigenraven.lwjgl3ify.relauncher.Lwjgl3ifyRelauncherTweaker")
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
//version: 1705357285
|
||||
//version: 1706545953
|
||||
/*
|
||||
DO NOT CHANGE THIS FILE!
|
||||
Also, you may replace this file at any time if there is an update available.
|
||||
@@ -53,7 +53,7 @@ plugins {
|
||||
id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version
|
||||
id 'com.modrinth.minotaur' version '2.+' apply false
|
||||
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
|
||||
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.27'
|
||||
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.31'
|
||||
}
|
||||
|
||||
print("You might want to check out './gradlew :faq' if your build fails.\n")
|
||||
@@ -651,7 +651,7 @@ repositories {
|
||||
|
||||
def mixinProviderGroup = "io.github.legacymoddingmc"
|
||||
def mixinProviderModule = "unimixins"
|
||||
def mixinProviderVersion = "0.1.13"
|
||||
def mixinProviderVersion = "0.1.15"
|
||||
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
|
||||
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
|
||||
ext.mixinProviderSpec = mixinProviderSpec
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ def addGtForTesting = false
|
||||
def addReikaModsForTesting = false
|
||||
|
||||
def asmVersion = '9.6'
|
||||
def rfbVersion = '0.3.3'
|
||||
def rfbVersion = '0.3.5'
|
||||
// 100% binary compatible, 1 minor source compatibility issue (removed a throws IOException clause)
|
||||
def gsonVersion = '2.10.1'
|
||||
|
||||
@@ -23,7 +23,7 @@ dependencies {
|
||||
vanilla_minecraft("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:${rfbVersion}") { transitive = false }
|
||||
forgePatchesEmbedded("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:${rfbVersion}") { transitive = false }
|
||||
vanilla_minecraft("com.google.code.gson:gson:${gsonVersion}")
|
||||
patchedMinecraft("com.google.code.gson:gson:${gsonVersion}")
|
||||
forgePatchesEmbedded("com.google.code.gson:gson:${gsonVersion}")
|
||||
|
||||
utilImplementation("org.ow2.asm:asm:${asmVersion}")
|
||||
utilImplementation("org.ow2.asm:asm-tree:${asmVersion}")
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.eigenraven.lwjgl3ify.core;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import org.lwjgl.system.Configuration;
|
||||
import org.lwjgl.system.Platform;
|
||||
import org.lwjglx.Sys;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
|
||||
public class LateInit {
|
||||
|
||||
public static void lateConstruct() {
|
||||
// Ensure javax.script.ScriptEngineManager gets loaded
|
||||
try {
|
||||
Class.forName("javax.script.ScriptEngineManager");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (FMLLaunchHandler.side()
|
||||
.isClient()) {
|
||||
clientMacOsFix();
|
||||
Sys.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
private static void clientMacOsFix() {
|
||||
if (Platform.get() == Platform.MACOSX) {
|
||||
Configuration.GLFW_LIBRARY_NAME.set("glfw_async");
|
||||
Configuration.GLFW_CHECK_THREAD0.set(false);
|
||||
Toolkit.getDefaultToolkit(); // Initialize AWT before GLFW
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package me.eigenraven.lwjgl3ify.core;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -13,9 +12,6 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.system.Configuration;
|
||||
import org.lwjgl.system.Platform;
|
||||
import org.lwjglx.Sys;
|
||||
|
||||
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
|
||||
|
||||
@@ -40,25 +36,10 @@ public class Lwjgl3ifyCoremod implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
.getClass(),
|
||||
e);
|
||||
}
|
||||
// Ensure javax.script.ScriptEngineManager gets loaded
|
||||
try {
|
||||
Class.forName("javax.script.ScriptEngineManager");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (FMLLaunchHandler.side()
|
||||
.isClient()) {
|
||||
clientMacOsFix();
|
||||
Sys.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
private void clientMacOsFix() {
|
||||
if (Platform.get() == Platform.MACOSX) {
|
||||
Configuration.GLFW_LIBRARY_NAME.set("glfw_async");
|
||||
Configuration.GLFW_CHECK_THREAD0.set(false);
|
||||
Toolkit.getDefaultToolkit(); // Initialize AWT before GLFW
|
||||
if (Launch.blackboard.get("lwjgl3ify:rfb-booted") != Boolean.TRUE) {
|
||||
return;
|
||||
}
|
||||
LateInit.lateConstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.eigenraven.lwjgl3ify.relauncher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
|
||||
public class Lwjgl3ifyRelauncherTweaker implements ITweaker {
|
||||
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
if (Launch.blackboard.get("lwjgl3ify:rfb-booted") != Boolean.TRUE) {
|
||||
if (FMLLaunchHandler.side()
|
||||
.isServer()) {
|
||||
LogManager.getLogger()
|
||||
.fatal(
|
||||
"lwjgl3ify relauncher does not support server launches, install according to lwjgl3ify's README.");
|
||||
FMLCommonHandler.instance()
|
||||
.exitJava(1, false);
|
||||
}
|
||||
// Not launched via RFB, transfer control to the relauncher.
|
||||
try {
|
||||
new Relauncher(args.toArray(new String[0]), profile).run();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {}
|
||||
|
||||
@Override
|
||||
public String getLaunchTarget() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getLaunchArguments() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package me.eigenraven.lwjgl3ify.relauncher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import me.eigenraven.lwjgl3ify.Tags;
|
||||
|
||||
public class Relauncher {
|
||||
|
||||
static final Logger logger = LogManager.getLogger("Lwjgl3ify/Relauncher");
|
||||
static final String[] SYSTEM_PROPERTY_PREFIXES = new String[] { "java.", "os.", "path.", "file.", "line.", "user.",
|
||||
"native.", "com.sun.", "sun.", "awt.", };
|
||||
static final String[] RECOMMENDED_JAVA_ARGS = Tags.RECOMMENDED_JAVA_ARGS.split("\t");
|
||||
final Path osCache;
|
||||
final Path mavenDownloadPath;
|
||||
final String[] args;
|
||||
final String gameVersion;
|
||||
|
||||
public Relauncher(String[] args, String gameVersion) {
|
||||
this.args = args;
|
||||
this.gameVersion = gameVersion;
|
||||
|
||||
final String userHome = System.getProperty("user.home");
|
||||
final String system = System.getProperty("os.name")
|
||||
.toLowerCase();
|
||||
Path cacheDir;
|
||||
try {
|
||||
if (system.contains("win")) {
|
||||
String temp = System.getenv("TEMP");
|
||||
String localAppData = System.getenv("LOCALAPPDATA");
|
||||
if (temp != null) {
|
||||
cacheDir = Paths.get(temp, "lwjgl3ify");
|
||||
} else if (localAppData != null) {
|
||||
cacheDir = Paths.get(localAppData, "Temp", "lwjgl3ify");
|
||||
} else {
|
||||
cacheDir = Paths.get(userHome, "AppData", "Local", "Temp", "lwjgl3ify");
|
||||
}
|
||||
} else if (system.contains("mac")) {
|
||||
cacheDir = Paths.get(userHome, "Library", "Caches", "lwjgl3ify");
|
||||
} else {
|
||||
String xdgCacheHome = System.getenv("XDG_CACHE_HOME");
|
||||
if (xdgCacheHome == null) {
|
||||
cacheDir = Paths.get(userHome, ".cache", "lwjgl3ify");
|
||||
} else {
|
||||
cacheDir = Paths.get(xdgCacheHome, "lwjgl3ify");
|
||||
}
|
||||
}
|
||||
} catch (InvalidPathException e) {
|
||||
if (system.contains("win")) {
|
||||
cacheDir = Paths.get(userHome, "AppData", "Local", "Temp", "lwjgl3ify");
|
||||
} else {
|
||||
cacheDir = Paths.get(userHome, ".cache", "lwjgl3ify");
|
||||
}
|
||||
logger.warn(
|
||||
"An error occurred while the lwjgl3ify relauncher cache path was created. The environment variable TEMP or LOCALAPPDATA could be set incorrectly. Using the default cache location: "
|
||||
+ cacheDir,
|
||||
e);
|
||||
}
|
||||
osCache = cacheDir;
|
||||
|
||||
final String mavenDownloadRoot = System.getProperty("lwjgl3ify.relauncher.mavenDownloadRoot", "");
|
||||
final Path mavenDownloadPath;
|
||||
if (mavenDownloadRoot.isEmpty()) {
|
||||
mavenDownloadPath = osCache.resolve("maven");
|
||||
} else {
|
||||
mavenDownloadPath = Paths.get(mavenDownloadRoot);
|
||||
}
|
||||
if (!Files.isDirectory(mavenDownloadPath)) {
|
||||
try {
|
||||
Files.createDirectories(mavenDownloadPath);
|
||||
} catch (IOException e) {
|
||||
logger.fatal("Could not create Maven download cache at {}", mavenDownloadPath, e);
|
||||
FMLCommonHandler.instance()
|
||||
.exitJava(1, false);
|
||||
}
|
||||
}
|
||||
this.mavenDownloadPath = mavenDownloadPath;
|
||||
}
|
||||
|
||||
// TODO: Unhardcode
|
||||
public Path javaBinary = Paths.get("/usr/lib/jvm/java-21-openjdk/bin/java");
|
||||
|
||||
public List<String> calculateClasspath() {
|
||||
final List<String> classpath = new ArrayList<>();
|
||||
// TODO: Add lwjgl, rfb
|
||||
for (final String cpEntry : System.getProperty("java.class.path")
|
||||
.split(File.pathSeparator)) {
|
||||
final Path cpFile = Paths.get(cpEntry);
|
||||
if (!Files.exists(cpFile)) {
|
||||
continue;
|
||||
}
|
||||
final String cpFileName = cpFile.getFileName()
|
||||
.toString();
|
||||
if (cpFileName.startsWith("lwjgl") || cpFileName.contains("commons-io")
|
||||
|| cpFileName.contains("commons-lang")
|
||||
|| cpFileName.contains("commons-compress")) {
|
||||
continue;
|
||||
}
|
||||
classpath.add(cpEntry);
|
||||
}
|
||||
return classpath;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() throws IOException {
|
||||
|
||||
final List<String> cmd = new ArrayList<>();
|
||||
cmd.addAll(Arrays.asList(RECOMMENDED_JAVA_ARGS));
|
||||
cmd.addAll(
|
||||
Arrays.asList(
|
||||
"--version",
|
||||
gameVersion,
|
||||
"--gameDir",
|
||||
Launch.minecraftHome.toString(),
|
||||
"--assetsDir",
|
||||
Launch.assetsDir.toString(),
|
||||
"--tweakClass",
|
||||
"cpw.mods.fml.common.launcher.FMLTweaker"));
|
||||
cmd.addAll(Arrays.asList(args));
|
||||
cmd.add("-cp");
|
||||
cmd.add(StringUtils.join(calculateClasspath(), File.pathSeparatorChar));
|
||||
|
||||
// Forward any custom system properties
|
||||
outer: for (final Map.Entry<Object, Object> prop : System.getProperties()
|
||||
.entrySet()) {
|
||||
if (prop.getKey() == null || prop.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
final String key = prop.getKey()
|
||||
.toString();
|
||||
for (final String systemPrefix : SYSTEM_PROPERTY_PREFIXES) {
|
||||
if (key.startsWith(systemPrefix)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
final String value = prop.getValue()
|
||||
.toString();
|
||||
cmd.add("-D" + key + "=" + value);
|
||||
}
|
||||
|
||||
final Path argFile = Files.createTempFile("lwjgl3ify-relaunch-", ".arg");
|
||||
Files.write(
|
||||
argFile,
|
||||
cmd.stream()
|
||||
.map(c -> '"' + StringEscapeUtils.escapeJava(c) + '"')
|
||||
.collect(Collectors.toList()),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
final List<String> bootstrapCmd = new ArrayList<>();
|
||||
bootstrapCmd.add(javaBinary.toString());
|
||||
bootstrapCmd.add("@" + argFile);
|
||||
|
||||
final ProcessBuilder pb = new ProcessBuilder(bootstrapCmd);
|
||||
logger.info("Starting relaunched process using args {}", bootstrapCmd);
|
||||
final Process p = pb.inheritIO()
|
||||
.start();
|
||||
while (p.isAlive()) {
|
||||
try {
|
||||
p.waitFor();
|
||||
break;
|
||||
} catch (InterruptedException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance()
|
||||
.exitJava(p.exitValue(), false);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.eigenraven.lwjgl3ify.rfb;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -15,6 +17,7 @@ public class Lwjgl3ifyRfbPlugin implements RfbPlugin {
|
||||
|
||||
@Override
|
||||
public void onConstruction(PluginContext ctx) {
|
||||
Launch.blackboard.put("lwjgl3ify:rfb-booted", Boolean.TRUE);
|
||||
EarlyConfig.load();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user