Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
heipiao233 committed Sep 5, 2023
1 parent e8a8a35 commit b2a8bc5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 51 deletions.
File renamed without changes.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

[中文](README.zh_hans.md) | English

## Quilt that runs on ModLauncher with NeoForge
## Run Quilt and Fancy Mod Loader on ModLauncher together

_Not implemented yet._

Yes, you can believe it. This mod will make Quilt and NeoForge run on ModLauncher *at the same time*.
This mod can let Quilt and Fancy Mod Loader run on the top of ModLauncher with Minecraft obfuscated with Searge name.
## Installing

_Not developed yet._
Expand All @@ -23,8 +21,8 @@ _Not opened yet._

## License

This project is licensed under [MIT](License.txt).
This project is licensed under [MIT License](License.txt).

Quilt loader is licensed under [Apache](License.Quilt.txt).

NeoForge is licensed under [LGPL 2.1](License.NeoForge.txt).
Fancy Mod Loader is licensed under [LGPL 2.1](License.FancyModLoader.txt).
10 changes: 4 additions & 6 deletions README.zh_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ _绝非机翻译名_

中文 | [English](README.md)

## 运行在 ModLauncher 上的 Quilt 和 NeoForge
## 运行在 ModLauncher 上的 Quilt 和 Fancy Mod Loader

_尚未实现_

没错,这个模组会让 Quilt 和 NeoForge *同时* 在 ModLauncher 上运行。
这个模组会让 Quilt 和 Fancy Mod Loader 在 ModLauncher 上和以 Searge 名混淆的 Minecraft 运行。

## 安装

Expand All @@ -25,8 +23,8 @@ _未开放_

## 许可证

这个项目的许可证是 [MIT](License.txt)
这个项目的许可证是 [MIT 许可证](License.txt)

Quilt 加载器项目的许可证是 [Apache](License.Quilt.txt)

NeoForge 项目的许可证是 [LGPL 2.1](License.NeoForge.txt)
Fancy Mod Loader 项目的许可证是 [LGPL 2.1](License.FancyModLoader.txt)
18 changes: 6 additions & 12 deletions src/main/java/net/pillowmc/pillow/PillowGameProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,17 @@ public String getNormalizedGameVersion() {
@Override
public Collection<BuiltinMod> getBuiltinMods() {
V1ModMetadataBuilder minecraftMetadata = new V1ModMetadataBuilder();
minecraftMetadata.id = getGameId();
minecraftMetadata.version = Version.of(getRawGameVersion());
minecraftMetadata.name = getGameName();
minecraftMetadata.group = "builtin";
minecraftMetadata.description = "Obfuscated as Searge name, MCP version = %s".formatted(FMLLoader.versionInfo().mcpVersion());
V1ModMetadataBuilder forgeMetadata = new V1ModMetadataBuilder();
forgeMetadata.id = "forge";
forgeMetadata.version = Version.of(FMLLoader.versionInfo().forgeVersion());
forgeMetadata.group = "net.neoforged";
minecraftMetadata.setId(getGameId());
minecraftMetadata.setVersion(Version.of(getRawGameVersion()));
minecraftMetadata.setName(getGameName());
minecraftMetadata.setGroup("builtin");
minecraftMetadata.setDescription("Obfuscated as Searge name, MCP version = %s".formatted(FMLLoader.versionInfo().mcpVersion()));
try {
var output = File.createTempFile("minecraft.virtual", ".jar");
var path=output.toPath();
JarOutputStream outJar=new JarOutputStream(new FileOutputStream(output));
outJar.close();
return Arrays.asList(new BuiltinMod(List.of(path), minecraftMetadata.build()),
new BuiltinMod(List.of(path), forgeMetadata.build())
);
return Arrays.asList(new BuiltinMod(List.of(path), minecraftMetadata.build()));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/net/pillowmc/pillow/asm/AWTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.ClassNode;
import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.launch.common.QuiltLauncherBase;

import cpw.mods.modlauncher.api.ITransformer;
import cpw.mods.modlauncher.api.ITransformerVotingContext;
Expand All @@ -18,25 +16,17 @@

public class AWTransformer implements ITransformer<ClassNode> {
private final AccessWidener aw;
private final Remapper remapperIn;
private final Remapper remapperOut;
AWTransformer(){
public AWTransformer(){
aw=QuiltLoaderImpl.INSTANCE.getAccessWidener();
var mappings = QuiltLauncherBase.getLauncher().getMappingConfiguration().getMappings();
remapperOut = RemapperUtils.create(mappings, PillowNamingContext.fromName, PillowNamingContext.toName);
remapperIn = RemapperUtils.create(mappings, PillowNamingContext.toName, PillowNamingContext.fromName);
}

@Override
public @NotNull ClassNode transform(ClassNode input, ITransformerVotingContext context) {
ClassNode output=new ClassNode(QuiltLoaderImpl.ASM_VERSION);
ClassVisitor remapOut=new PillowClassRemapper(output, remapperOut);
ClassVisitor visitor=AccessWidenerClassVisitor.createClassVisitor(QuiltLoaderImpl.ASM_VERSION, remapOut,
ClassVisitor visitor=AccessWidenerClassVisitor.createClassVisitor(QuiltLoaderImpl.ASM_VERSION, output,
QuiltLoaderImpl.INSTANCE.getAccessWidener()
);

ClassVisitor remapIn=new PillowClassRemapper(visitor, remapperIn);
input.accept(remapIn);
input.accept(visitor);
return output;
}

Expand All @@ -49,7 +39,6 @@ public class AWTransformer implements ITransformer<ClassNode> {
public @NotNull Set<Target> targets() {
return aw.getTargets().stream()
.map(i->i.replace(".", "/"))
.map(remapperOut::map)
.map(name->ITransformer.Target.targetPreClass(name.replace('/', '.')))
.collect(Collectors.toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -40,10 +41,9 @@
import cpw.mods.modlauncher.api.ITransformationService;
import cpw.mods.modlauncher.api.ITransformer;
import net.fabricmc.api.EnvType;
import net.minecraftforge.fml.loading.LibraryFinder;
import net.pillowmc.pillow.PillowGameProvider;
import net.pillowmc.pillow.Utils;
import net.pillowmc.pillow.asm.qsl.itemsettings.LivingEntityMixinTransformer;
import net.pillowmc.pillow.asm.qsl.resourceloader.MinecraftClientMixinTransformer;
import sun.misc.Unsafe;

public class PillowTransformationService extends QuiltLauncherBase implements ITransformationService {
Expand Down Expand Up @@ -93,6 +93,7 @@ public PillowTransformationService() {
@Override
@SuppressWarnings("unchecked")
public void initialize(IEnvironment environment) {
setProperties(new HashMap<>());
setupUncaughtExceptionHandler();
// Don't touch here
try {
Expand Down Expand Up @@ -144,9 +145,12 @@ public List<Resource> completeScan(IModuleLayerManager environment) {
Log.debug(LogCategory.DISCOVERY, "Completing scan with classpath %s", cp);
if (cp.isEmpty())
return List.of();
return List.of(new Resource(Layer.GAME,
List.of(SecureJar.from(sj -> createJarMetadata(sj, "quiltMods"),
cp.toArray(new Path[0])))));
var modResource = new Resource(Layer.GAME,
List.of(SecureJar.from(sj -> createJarMetadata(sj, "quiltMods"),
cp.toArray(new Path[0]))));
var dfuJar = SecureJar.from(LibraryFinder.findPathForMaven("com.mojang", "datafixerupper", "", "", "6.0.8"));
var depResource = new Resource(Layer.GAME, List.of(dfuJar));
return List.of(modResource, depResource);
}

@Override
Expand All @@ -160,8 +164,7 @@ public void onLoad(IEnvironment env, Set<String> otherServices) {
return List.of(
Utils.getSide() == EnvType.CLIENT ? new ClientEntryPointTransformer()
: new ServerEntryPointTransformer(),
new AWTransformer(), new ModListScreenTransformer(), new RemapModTransformer(),
new MinecraftClientMixinTransformer(), new LivingEntityMixinTransformer());
new AWTransformer());
}

public static JarMetadata createJarMetadata(SecureJar sj, String name) {
Expand Down Expand Up @@ -230,7 +233,9 @@ public Manifest getManifest(Path originPath) {

@Override
public boolean isDevelopment() {
return Thread.currentThread().getStackTrace()[2].getClassName().contains("ClasspathModCandidateFinder");
var trace = Thread.currentThread().getStackTrace();
return trace[2].getClassName().contains("ClasspathModCandidateFinder")
|| trace[4].getMethodName().equals("scan0");
}

@Override
Expand All @@ -240,7 +245,7 @@ public String getEntrypoint() {

@Override
public String getTargetNamespace() {
return "intermediary"; // Trick Quilt
return "srg";
}

@Override
Expand Down
34 changes: 31 additions & 3 deletions src/main/java/net/pillowmc/pillow/asm/RemapModTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import org.quiltmc.loader.impl.launch.common.QuiltLauncherBase;

import cpw.mods.modlauncher.api.ITransformer;
Expand All @@ -23,9 +26,34 @@ public class RemapModTransformer implements ITransformer<ClassNode> {

@Override
public @NotNull ClassNode transform(ClassNode input, ITransformerVotingContext context) {
ClassNode output = new ClassNode();
input.accept(new PillowClassRemapper(output, remapper));
return output;
if (input.invisibleAnnotations == null) return input;
boolean isMixin = false;
for (AnnotationNode node : input.invisibleAnnotations) {
if (node.desc.equals("Lorg/spongepowered/asm/mixin/Mixin;")) {
isMixin = true;
break;
}
}
if (!isMixin) return input;
for (FieldNode node : input.fields) {
if (node.visibleAnnotations == null) continue;
for (AnnotationNode ann : node.visibleAnnotations) {
if (ann.desc.equals("Lorg/spongepowered/asm/mixin/Shadow;")) {
node.name = remapper.mapFieldName("", node.name, node.desc);
return input;
}
}
}
for (MethodNode node : input.methods) {
if (node.visibleAnnotations == null) continue;
for (AnnotationNode ann : node.visibleAnnotations) {
if (ann.desc.equals("Lorg/spongepowered/asm/mixin/Overwrite;")) {
node.name = remapper.mapMethodName("", node.name, node.desc);
return input;
}
}
}
return input;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/pillowmc/pillow/asm/RemapperUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.pillowmc.remapper.NameOnlyRemapper;

public class RemapperUtils {
private static final Predicate<String> NAME_FILTER = Pattern.compile("^((field|method)_\\d+|[fm]_\\d+_)$").asPredicate();
private static final Predicate<String> NAME_FILTER = Pattern.compile("^((field|method|comp)_\\d+|[fm]_\\d+_)$").asPredicate();
private RemapperUtils(){}
public static NameOnlyRemapper create(TinyTree tree, String from, String to){
var classes = new HashMap<String, String>();
Expand Down

0 comments on commit b2a8bc5

Please sign in to comment.