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

Allowed the GameProvider to provide the namespace #428

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import net.fabricmc.mapping.tree.TinyMappingFactory;
import net.fabricmc.mapping.tree.TinyTree;

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 @@ -78,6 +80,11 @@ public TinyTree getMappings() {
}

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
Loading