Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
coolGi69 authored Aug 17, 2024
2 parents 12cad12 + 785b695 commit d2e4326
Show file tree
Hide file tree
Showing 27 changed files with 499 additions and 279 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ group = org.quiltmc
description = The mod loading component of Quilt
url = https://github.com/quiltmc/quilt-loader
# Don't forget to change this in QuiltLoaderImpl as well
quilt_loader = 0.26.0-beta.4
quilt_loader = 0.26.4-beta.1

# Fabric & Quilt Libraries
asm = 9.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ protected static String getRelease(String version) {
int year = Integer.parseInt(matcher.group(1));
int week = Integer.parseInt(matcher.group(2));

if (year == 23 && week >= 51 || year >= 24) {
if (year >= 24 && week >= 18) {
return "1.21";
} else if (year == 23 && week >= 51 || year == 24 && week <= 14) {
return "1.20.5";
} else if (year == 23 && week >= 40 && week <= 46) {
return "1.20.3";
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/quiltmc/loader/impl/QuiltLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public final class QuiltLoaderImpl {

public static final int ASM_VERSION = Opcodes.ASM9;

public static final String VERSION = "0.26.0-beta.4";
public static final String VERSION = "0.26.4-beta.1";
public static final String MOD_ID = "quilt_loader";
public static final String DEFAULT_MODS_DIR = "mods";
public static final String DEFAULT_CACHE_DIR = ".cache";
Expand Down Expand Up @@ -604,6 +604,8 @@ private ModSolveResult runPlugins() {
temporarySourcePaths.put(mod.from(), plugins.convertToSourcePaths(mod.from()));
}

QuiltLauncherBase.getLauncher().setPluginPackages(plugins.getPluginPackages());

if (displayedMessage) {
return result;
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/quiltmc/loader/impl/gui/AbstractWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;

import org.quiltmc.loader.api.LoaderValue;
import org.quiltmc.loader.api.LoaderValue.LObject;
Expand Down Expand Up @@ -126,15 +127,22 @@ void onClosed() {
sendSignal("closed");
}

void waitUntilClosed() throws LoaderGuiException {
void waitUntilClosed(Supplier<Error> errorChecker) throws LoaderGuiException {
try {
while (true) {
try {
onClosedFuture.get(1, TimeUnit.SECONDS);
break;
} catch (TimeoutException e) {
if (QuiltForkComms.getCurrentComms() == null) {
throw new LoaderGuiException("Forked communication failure; check the log for details!", e);
Error error = errorChecker.get();
if (error == null) {
throw new LoaderGuiException("Forked communication failure; check the log for details!", e);
} else {
LoaderGuiException ex = new LoaderGuiException("Forked communication failure!", error);
ex.addSuppressed(e);
throw ex;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ public static QuiltLoaderIcon allocateIcons(Map<Integer, BufferedImage> imageSiz
}

public static QuiltLoaderIcon allocateIcons(byte[][] imageBytes) {
PluginIconImpl icon = new PluginIconImpl(imageBytes);
icon.send();
return icon;
return new PluginIconImpl(imageBytes);
}

public static QuiltLoaderIcon getModIcon(ModContainer mod) {
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/quiltmc/loader/impl/gui/QuiltFork.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.loader.impl.gui;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -56,10 +57,11 @@ public class QuiltFork {
private static final QuiltForkComms COMMS;
private static final LoaderValueHelper<IOException> HELPER = LoaderValueHelper.IO_EXCEPTION;
private static final IOException FORK_EXCEPTION;
private static Error previousServerError;

static {
GameProvider provider = QuiltLoaderImpl.INSTANCE.getGameProvider();
if (Boolean.getBoolean(SystemProperties.DISABLE_FORKED_GUIS) || !provider.canOpenGui()) {
if (Boolean.getBoolean(SystemProperties.DISABLE_FORKED_GUIS) || !provider.canOpenGui() || GraphicsEnvironment.isHeadless()) {
COMMS = null;
FORK_EXCEPTION = null;
} else {
Expand Down Expand Up @@ -130,13 +132,18 @@ public static void open(QuiltLoaderWindow<?> window, boolean shouldWait) throws
return;
}

if (previousServerError != null) {
// Gui NOT disabled, but it previously crashed.
throw new LoaderGuiException("The gui server encountered an error!", previousServerError);
}

AbstractWindow<?> realWindow = (AbstractWindow<?>) window;

realWindow.send();
realWindow.open();

if (shouldWait) {
realWindow.waitUntilClosed();
realWindow.waitUntilClosed(() -> previousServerError);
}
}

Expand Down Expand Up @@ -187,10 +194,15 @@ private static void handleMessageFromServer0(LoaderValue msg) throws IOException
switch (type) {
case ForkCommNames.ID_EXCEPTION: {
// The server encountered an exception
// We should really store the exception, but for now just exit
LoaderValue detail = packet.get("detail");
if (detail == null || detail.type() != LType.STRING) {
Log.error(LogCategory.COMMS, "The gui-server encountered an unknown error!");
previousServerError = new Error("[Unknown error: the gui server didn't send a detail trace]");
} else {
Log.error(LogCategory.COMMS, "The gui-server encountered an error:\n" + detail.asString());
previousServerError = new Error("Previous error stacktrace:\n" + detail.asString());
}
COMMS.close();
Log.error(LogCategory.COMMS, "The gui-server encountered an error!");
System.exit(1);
return;
}
case ForkCommNames.ID_GUI_OBJECT_UPDATE: {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/gui/QuiltForkComms.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.ProcessBuilder.Redirect;
import java.net.InetAddress;
import java.net.Socket;
Expand All @@ -47,11 +50,15 @@
import org.quiltmc.loader.impl.util.LimitedInputStream;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
import org.quiltmc.loader.impl.util.SystemProperties;
import org.quiltmc.loader.impl.util.log.Log;
import org.quiltmc.loader.impl.util.log.LogCategory;

@QuiltLoaderInternal(QuiltLoaderInternalType.NEW_INTERNAL)
public class QuiltForkComms {

private static final String SYS_PROP = "quiltmc.loader.fork.comms_port";
private static final boolean PRINT_NET_PACKETS = Boolean.getBoolean(SystemProperties.DEBUG_GUI_PACKETS);

private static ForkSide side;
private static final AtomicReference<QuiltForkComms> currentComms = new AtomicReference<>();
Expand Down Expand Up @@ -323,6 +330,12 @@ private void runWriter() {
try {
BlockingQueue<LoaderValue> queue = writerQueue;
LoaderValue value = queue == null ? lvf().nul() : queue.take();
if (PRINT_NET_PACKETS) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LoaderValueFactory.getFactory().write(value, baos);
String json = new String(baos.toByteArray(), StandardCharsets.UTF_8);
Log.info(LogCategory.GUI, "Sending packet: " + json);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
lvf().write(value, baos);
byte[] written = baos.toByteArray();
Expand Down Expand Up @@ -380,6 +393,14 @@ private void readMessage(LoaderValue value) {
} catch (Throwable t) {
Map<String, LoaderValue> map = new HashMap<>();
map.put("__TYPE", lvf().string(ForkCommNames.ID_EXCEPTION));

StringWriter sw = new StringWriter();
try (PrintWriter printer = new PrintWriter(sw)) {
t.printStackTrace(printer);
printer.flush();
}
map.put("detail", lvf().string(sw.toString()));

send(lvf().object(map));
throw t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public interface QuiltLauncher {
void setTransformCache(URL insideTransformCache);
void setHiddenClasses(Set<String> classes);
void setHiddenClasses(Map<String, String> classes);
void setPluginPackages(Map<String, ClassLoader> hiddenClasses);
void hideParentUrl(URL hidden);
void hideParentPath(Path obf);
void validateGameClassLoader(Object gameInstance);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/launch/knot/Knot.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ public void setHiddenClasses(Map<String, String> hiddenClasses) {
classLoader.getDelegate().setHiddenClasses(hiddenClasses);
}

@Override
public void setPluginPackages(Map<String, ClassLoader> hiddenClasses) {
classLoader.getDelegate().setPluginPackages(hiddenClasses);
}

@Override
public void hideParentUrl(URL parent) {
classLoader.getDelegate().hideParentUrl(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public Optional<ModContainer> getQuiltMod() {
/** Map of package to the reason why it cannot be loaded. If the package can be loaded then the value is the empty string. */
private final Map<String, String> packageLoadDenyCache = new ConcurrentHashMap<>();

private Map<String, ClassLoader> pluginPackages = Collections.emptyMap();

KnotClassDelegate(boolean isDevelopment, EnvType envType, KnotClassLoaderInterface itf, GameProvider provider) {
this.isDevelopment = isDevelopment;
this.envType = envType;
Expand Down Expand Up @@ -287,6 +289,11 @@ Class<?> tryLoadClass(String name, boolean allowFromParent) throws ClassNotFound
}
}

ClassLoader pluginCl = pluginPackages.get(pkgString);
if (pluginCl != null) {
return pluginCl.loadClass(name);
}

String hideReason = hiddenClasses.get(name);
if (hideReason != null) {
throw new RuntimeException("Cannot load " + name + " " + hideReason);
Expand Down Expand Up @@ -520,7 +527,7 @@ public byte[] getPreMixinClassByteArray(URL classFileURL, String name) {
Log.info(LogCategory.GENERAL, "Loading " + name + " early", new Throwable());
}

if (name.startsWith("org.quiltmc.loader.impl.patch.")) {
if (name.startsWith("org.quiltmc.loader.impl.patch.PATCHED.")) {
return PatchLoader.getNewPatchedClass(name);
}

Expand Down Expand Up @@ -574,6 +581,10 @@ public void setHiddenClasses(Map<String, String> hiddenClasses) {
this.hiddenClasses = hiddenClasses;
}

void setPluginPackages(Map<String, ClassLoader> map) {
pluginPackages = map;
}

public void hideParentUrl(URL parentPath) {
parentHiddenUrls.add(parentPath.toString());
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/patch/PatchLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@

package org.quiltmc.loader.impl.patch;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.impl.patch.reflections.ReflectionsClassPatcher;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
import org.quiltmc.loader.impl.util.SystemProperties;
import org.quiltmc.loader.impl.util.log.Log;
import org.quiltmc.loader.impl.util.log.LogCategory;

Expand All @@ -31,6 +37,24 @@ public abstract class PatchLoader {

public static void load() {
ReflectionsClassPatcher.load(patchedClasses);

if (Boolean.getBoolean(SystemProperties.DEBUG_DUMP_PATCHED_CLASSES)) {
Path root = QuiltLoader.getGameDir().resolve("quilt_loader_patched_classes");
try {
Files.createDirectories(root);
Files.write(root.resolve("FILE_LIST.txt"), patchedClasses.keySet().stream().sorted().collect(Collectors.toList()));
for (Map.Entry<String, byte[]> entry : patchedClasses.entrySet()) {
Path file = root.resolve(entry.getKey().replace(".", root.getFileSystem().getSeparator()) + ".class");
Files.createDirectories(file.getParent());
Files.write(file, entry.getValue());
}
} catch (IOException e) {
throw new Error(
"Failed to save patched classes! (If you don't need them then remove '-D"
+ SystemProperties.DEBUG_DUMP_PATCHED_CLASSES + "=true from your VM options)", e
);
}
}
}

public static byte[] getNewPatchedClass(String name) {
Expand Down
Loading

0 comments on commit d2e4326

Please sign in to comment.