Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into mappings-fun
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/quiltmc/loader/impl/launch/common/MappingConfiguration.java
  • Loading branch information
TheGlitch76 committed Jul 30, 2024
2 parents f1b1190 + 785b695 commit 39d7537
Show file tree
Hide file tree
Showing 36 changed files with 559 additions and 294 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.2
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.quiltmc.loader.impl.game.minecraft.patch.EntrypointPatch;
import org.quiltmc.loader.impl.game.minecraft.patch.TinyFDPatch;
import org.quiltmc.loader.impl.launch.common.QuiltLauncher;
import org.quiltmc.loader.impl.launch.common.QuiltLauncherBase;
import org.quiltmc.loader.impl.metadata.qmj.V1ModMetadataBuilder;
import org.quiltmc.loader.impl.util.Arguments;
import org.quiltmc.loader.impl.util.ExceptionUtil;
Expand Down Expand Up @@ -189,6 +190,11 @@ public boolean isObfuscated() {
return true; // generally yes...
}

@Override
public String getNamespace() {
return QuiltLauncherBase.getLauncher().isDevelopment() ? "named" : "intermediary";
}

@Override
public boolean requiresUrlClassLoader() {
return hasModLoader;
Expand Down Expand Up @@ -431,7 +437,7 @@ public void initialize(QuiltLauncher launcher) {

setupLogHandler(launcher, true);

transformer.locateEntrypoints(launcher, gameJars);
transformer.locateEntrypoints(launcher, getNamespace(), gameJars);
}

private void setupLogHandler(QuiltLauncher launcher, boolean useTargetCl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public final class BrandingPatch extends GamePatch {
@Override
public void process(QuiltLauncher launcher, GamePatchContext context) {
public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
for (String brandClassName : new String[] {
"net.minecraft.client.ClientBrandRetriever",
"net.minecraft.server.MinecraftServer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void finishEntrypoint(EnvType type, ListIterator<AbstractInsnNode> it) {
}

@Override
public void process(QuiltLauncher launcher, GamePatchContext context) {
public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
EnvType type = launcher.getEnvironmentType();
String entrypoint = launcher.getEntrypoint();
Version gameVersion = getGameVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class TinyFDPatch extends GamePatch {
private static final String DIALOG_TITLE = "Select settings file (.json)";

@Override
public void process(QuiltLauncher launcher, GamePatchContext context) {
public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
if (launcher.getEnvironmentType() != EnvType.CLIENT) {
// Fix should only be applied to clients.
return;
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 @@ -131,7 +131,7 @@ public final class QuiltLoaderImpl {

public static final int ASM_VERSION = Opcodes.ASM9;

public static final String VERSION = "0.26.0-beta.2";
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 @@ -603,6 +603,8 @@ private ModSolveResult runPlugins() {
temporarySourcePaths.put(mod.from(), plugins.convertToSourcePaths(mod.from()));
}

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

if (displayedMessage) {
return result;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/quiltmc/loader/impl/entrypoint/GamePatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.quiltmc.loader.impl.entrypoint;

import org.objectweb.asm.ClassReader;
import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.launch.common.QuiltLauncher;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
Expand Down Expand Up @@ -128,12 +129,18 @@ protected boolean isPublicInstance(int access) {
return ((access & 0x0F) == (Opcodes.ACC_PUBLIC | 0 /* non-static */));
}

public void process(QuiltLauncher launcher, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
public void process(QuiltLauncher launcher, String namespace, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
throw new AbstractMethodError(getClass() + " must override one of the 'process' methods!");
}
public void process(QuiltLauncher launcher, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
process(launcher, launcher.getTargetNamespace(), classSource, classEmitter);
}

public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
process(launcher, namespace, context::getClassSourceReader, context::addPatchedClass);
}
public void process(QuiltLauncher launcher, GamePatchContext context) {
process(launcher, context::getClassSourceReader, context::addPatchedClass);
process(launcher, launcher.getTargetNamespace(), context);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private void addPatchedClass(ClassNode node) {
}

public void locateEntrypoints(QuiltLauncher launcher, List<Path> gameJars) {
this.locateEntrypoints(launcher, null, gameJars);
}
public void locateEntrypoints(QuiltLauncher launcher, String namespace, List<Path> gameJars) {
if (entrypointsLocated) {
return;
}
Expand Down Expand Up @@ -129,7 +132,10 @@ public void addPatchedClass(ClassNode node) {
};

for (GamePatch patch : patches) {
patch.process(launcher, context);
if (namespace == null)
patch.process(launcher, context);
else
patch.process(launcher, namespace, context);
}

for (ClassNode node : addedClassNodes.values()) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/game/GameProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public interface GameProvider {
String getEntrypoint();
Path getLaunchDirectory();
boolean isObfuscated();
default String getNamespace() {
return isObfuscated()? "intermediary": "named";
};
boolean requiresUrlClassLoader();

boolean isEnabled();
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 @@ -39,6 +39,8 @@
import net.fabricmc.mappingio.format.tiny.Tiny2FileReader;

import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.game.GameProvider;
import org.quiltmc.loader.impl.util.ManifestUtil;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
Expand Down Expand Up @@ -101,6 +103,11 @@ public List<String> getNamespaces() {
}

public String getTargetNamespace() {
GameProvider gameProvider = QuiltLoaderImpl.INSTANCE.tryGetGameProvider();
if (gameProvider != null)
return gameProvider.getNamespace();
// else
// If the game provider doesn't exist yet, use the development flag to set the namespace
return QuiltLauncherBase.getLauncher().isDevelopment() ? "named" : "intermediary";
}

Expand Down Expand Up @@ -186,7 +193,7 @@ private void initialize() {
String mojmapPath = System.getProperty(SystemProperties.MOJMAP_PATH);
if (mojmapPath != null) {
try (BufferedReader reader = Files.newBufferedReader(Paths.get(mojmapPath))) {
ProGuardFileReader.read(reader, "mojmap", "official", new MappingSourceNsSwitch(mappings, "official"));
ProGuardFileReader.read(reader, "mojang", "official", new MappingSourceNsSwitch(mappings, "official"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
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 @@ -318,6 +318,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
Loading

0 comments on commit 39d7537

Please sign in to comment.