Skip to content

Commit

Permalink
Thanks to LexManos, he replaced all installers with the new version, …
Browse files Browse the repository at this point in the history
…so the codes for compatibility with the old installer do not need to exist.

The task of checking for extra files is now done by the installer instead of ForgeWrapper itself, thus avoiding some inaccurate checking.
  • Loading branch information
ZekerZhayard committed Mar 1, 2024
1 parent a3413eb commit 3c6712d
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 428 deletions.
11 changes: 1 addition & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ group = "io.github.zekerzhayard"
archivesBaseName = rootProject.name

configurations {
provided {
implementation.extendsFrom provided
}
multirelase {
implementation.extendsFrom multirelase
}
Expand All @@ -34,11 +31,9 @@ repositories {
dependencies {
compileOnly "com.google.code.gson:gson:2.8.7"
compileOnly "cpw.mods:modlauncher:8.0.9"
compileOnly "net.minecraftforge:installer:2.1.9"
compileOnly "net.minecraftforge:installer:2.2.7"
compileOnly "net.sf.jopt-simple:jopt-simple:5.0.4"

provided project(":common")
provided project(":legacy")
multirelase project(":jigsaw")
}

Expand All @@ -60,10 +55,6 @@ jar {
"GitCommit": String.valueOf(System.getenv("GITHUB_SHA"))
])

from configurations.provided.files.collect {
zipTree(it)
}

into "META-INF/versions/9", {
from configurations.multirelase.files.collect {
zipTree(it)
Expand Down
11 changes: 0 additions & 11 deletions common/build.gradle

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

org.gradle.daemon = false

fw_version = 1.5.8
fw_version = 1.6.0
4 changes: 0 additions & 4 deletions jigsaw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ configurations {
}
}
}

dependencies {
compileOnly project(":common")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.github.zekerzhayard.forgewrapper.util.CheckedLambdaUtil;
import sun.misc.Unsafe;

public class ModuleUtil {
Expand Down Expand Up @@ -53,17 +52,27 @@ public static void addModules(String modulePath) throws Throwable {
MethodHandle loadModuleMH = IMPL_LOOKUP.findVirtual(Class.forName("jdk.internal.loader.BuiltinClassLoader"), "loadModule", MethodType.methodType(void.class, ModuleReference.class));

// Resolve modules to a new config and load all extra modules in system class loader (unnamed modules for now)
Configuration config = Configuration.resolveAndBind(finder, List.of(ModuleLayer.boot().configuration()), finder, finder.findAll().stream().filter(mref -> !ModuleLayer.boot().findModule(mref.descriptor().name()).isPresent()).peek(CheckedLambdaUtil.wrapConsumer(mref -> loadModuleMH.invokeWithArguments(ClassLoader.getSystemClassLoader(), mref))).map(mref -> mref.descriptor().name()).collect(Collectors.toList()));
List<String> roots = new ArrayList<>();
for (ModuleReference mref : finder.findAll()) {
String name = mref.descriptor().name();
if (!ModuleLayer.boot().findModule(name).isPresent()) {
loadModuleMH.invokeWithArguments(ClassLoader.getSystemClassLoader(), mref);
roots.add(name);
}
}
Configuration config = Configuration.resolveAndBind(finder, List.of(ModuleLayer.boot().configuration()), finder, roots);

// Copy the new config graph to boot module layer config
MethodHandle graphGetter = IMPL_LOOKUP.findGetter(Configuration.class, "graph", Map.class);
HashMap<ResolvedModule, Set<ResolvedModule>> graphMap = new HashMap<>((Map<ResolvedModule, Set<ResolvedModule>>) graphGetter.invokeWithArguments(config));
MethodHandle cfSetter = IMPL_LOOKUP.findSetter(ResolvedModule.class, "cf", Configuration.class);
// Reset all extra resolved modules config to boot module layer config
graphMap.forEach(CheckedLambdaUtil.wrapBiConsumer((k, v) -> {
cfSetter.invokeWithArguments(k, ModuleLayer.boot().configuration());
v.forEach(CheckedLambdaUtil.wrapConsumer(m -> cfSetter.invokeWithArguments(m, ModuleLayer.boot().configuration())));
}));
for (Map.Entry<ResolvedModule, Set<ResolvedModule>> entry : graphMap.entrySet()) {
cfSetter.invokeWithArguments(entry.getKey(), ModuleLayer.boot().configuration());
for (ResolvedModule resolvedModule : entry.getValue()) {
cfSetter.invokeWithArguments(resolvedModule, ModuleLayer.boot().configuration());
}
}
graphMap.putAll((Map<ResolvedModule, Set<ResolvedModule>>) graphGetter.invokeWithArguments(ModuleLayer.boot().configuration()));
IMPL_LOOKUP.findSetter(Configuration.class, "graph", Map.class).invokeWithArguments(ModuleLayer.boot().configuration(), new HashMap<>(graphMap));

Expand Down Expand Up @@ -92,7 +101,17 @@ public static void addModules(String modulePath) throws Throwable {

// Add reads from extra modules to jdk modules
MethodHandle implAddReadsMH = IMPL_LOOKUP.findVirtual(Module.class, "implAddReads", MethodType.methodType(void.class, Module.class));
config.modules().forEach(rm -> ModuleLayer.boot().findModule(rm.name()).ifPresent(m -> oldBootModules.forEach(brm -> ModuleLayer.boot().findModule(brm.name()).ifPresent(CheckedLambdaUtil.wrapConsumer(bm -> implAddReadsMH.invokeWithArguments(m, bm))))));
for (ResolvedModule resolvedModule : config.modules()) {
Module module = ModuleLayer.boot().findModule(resolvedModule.name()).orElse(null);
if (module != null) {
for (ResolvedModule bootResolvedModule : oldBootModules) {
Module bootModule = ModuleLayer.boot().findModule(bootResolvedModule.name()).orElse(null);
if (bootModule != null) {
implAddReadsMH.invokeWithArguments(module, bootModule);
}
}
}
}
}

public static void addExports(List<String> exports) {
Expand Down Expand Up @@ -124,13 +143,26 @@ private enum TypeToAdd {
}

void implAdd(List<String> extras) {
extras.stream().map(ModuleUtil::parseModuleExtra).filter(Optional::isPresent).map(Optional::get).forEach(CheckedLambdaUtil.wrapConsumer(data -> ModuleLayer.boot().findModule(data.module).ifPresent(CheckedLambdaUtil.wrapConsumer(m -> {
if ("ALL-UNNAMED".equals(data.target)) {
this.implAddToAllUnnamedMH.invokeWithArguments(m, data.packages);
} else {
ModuleLayer.boot().findModule(data.target).ifPresent(CheckedLambdaUtil.wrapConsumer(tm -> this.implAddMH.invokeWithArguments(m, data.packages, tm)));
for (String extra : extras) {
ParserData data = ModuleUtil.parseModuleExtra(extra).orElse(null);
if (data != null) {
Module module = ModuleLayer.boot().findModule(data.module).orElse(null);
if (module != null) {
try {
if ("ALL-UNNAMED".equals(data.target)) {
this.implAddToAllUnnamedMH.invokeWithArguments(module, data.packages);
} else {
Module targetModule = ModuleLayer.boot().findModule(data.target).orElse(null);
if (targetModule != null) {
this.implAddMH.invokeWithArguments(module, data.packages, targetModule);
}
}
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
}))));
}
}
}

Expand Down
22 changes: 0 additions & 22 deletions legacy/build.gradle

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
rootProject.name = 'ForgeWrapper'

include 'common'
include 'legacy'
include 'jigsaw'
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import io.github.zekerzhayard.forgewrapper.installer.util.ModuleUtil;

public class Bootstrap {
public static void bootstrap(List<String> jvmArgs, String minecraftJar, String libraryDir) throws Throwable {
public static void bootstrap(String[] jvmArgs, String minecraftJar, String libraryDir) throws Throwable {
// Replace all placeholders
List<String> replacedJvmArgs = new ArrayList<>();
for (String arg : jvmArgs) {
replacedJvmArgs.add(arg.replace("${classpath}", System.getProperty("java.class.path").replace(File.separator, "/")).replace("${classpath_separator}", File.pathSeparator).replace("${library_directory}", libraryDir).replace("${version_name}", minecraftJar.substring(0, minecraftJar.lastIndexOf('.'))));
String[] replacedJvmArgs = new String[jvmArgs.length];
for (int i = 0; i < jvmArgs.length; i++) {
String arg = jvmArgs[i];
replacedJvmArgs[i] = arg.replace("${classpath}", System.getProperty("java.class.path").replace(File.separator, "/")).replace("${classpath_separator}", File.pathSeparator).replace("${library_directory}", libraryDir).replace("${version_name}", minecraftJar.substring(0, minecraftJar.lastIndexOf('.')));
}
jvmArgs = replacedJvmArgs;

Expand All @@ -27,23 +28,23 @@ public static void bootstrap(List<String> jvmArgs, String minecraftJar, String l
String modulePath = null;
List<String> addExports = new ArrayList<>();
List<String> addOpens = new ArrayList<>();
for (int i = 0; i < jvmArgs.size(); i++) {
String arg = jvmArgs.get(i);
for (int i = 0; i < jvmArgs.length; i++) {
String arg = jvmArgs[i];

if (arg.equals("-p") || arg.equals("--module-path")) {
modulePath = jvmArgs.get(i + 1);
modulePath = jvmArgs[i + 1];
} else if (arg.startsWith("--module-path=")) {
modulePath = arg.split("=", 2)[1];
}

if (arg.equals("--add-exports")) {
addExports.add(jvmArgs.get(i + 1));
addExports.add(jvmArgs[i + 1]);
} else if (arg.startsWith("--add-exports=")) {
addExports.add(arg.split("=", 2)[1]);
}

if (arg.equals("--add-opens")) {
addOpens.add(jvmArgs.get(i + 1));
addOpens.add(jvmArgs[i + 1]);
} else if (arg.startsWith("--add-opens=")) {
addOpens.add(arg.split("=", 2)[1]);
}
Expand Down
Loading

0 comments on commit 3c6712d

Please sign in to comment.