Skip to content

Commit

Permalink
Connector 1.21.1 beta 5 (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD authored Dec 25, 2024
2 parents abc8d98 + d309b3a commit 99441a8
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 71 deletions.
29 changes: 16 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import me.modmuss50.mpp.ReleaseType
import net.neoforged.moddevgradle.dsl.RunModel
import net.neoforged.moddevgradle.internal.RunGameTask
import java.time.LocalDateTime

plugins {
java
`maven-publish`
id("net.neoforged.moddev") version "2.0.1-beta"
id("net.neoforged.moddev") version "2.0.52-beta"
id("io.github.goooler.shadow") version "8.1.8" apply false
id("me.modmuss50.mod-publish-plugin") version "0.5.+"
id("net.neoforged.gradleutils") version "3.0.0"
id("org.sinytra.adapter.userdev") version "1.2-SNAPSHOT"
id("org.sinytra.adapter.userdev") version "1.2.1-SNAPSHOT"
}

val versionConnector: String by project
Expand Down Expand Up @@ -62,13 +63,9 @@ configurations {
}

"modCompileOnly" {
extendsFrom(configurations.compileOnly.get())
}

"modImplementation" {
extendsFrom(shade)
}

additionalRuntimeClasspath {
extendsFrom(shade)
}
Expand All @@ -95,23 +92,26 @@ neoForge {
systemProperty("connector.logging.markers", "MIXINPATCH,MERGER")
systemProperty("mixin.debug.export", "true")
gameDirectory.set(layout.projectDirectory.dir("run"))

mods {
maybeCreate("connector").apply {
sourceSet(mod)
}
}
}

create("client") {
client()
config(this)
}

create("server") {
server()
config(this)
}
}

addModdingDependenciesTo(mod)

mods {
maybeCreate("connector").apply {
sourceSet(mod)
}
}
}

repositories {
Expand Down Expand Up @@ -218,6 +218,9 @@ tasks {
assemble {
dependsOn(fullJar)
}
withType<RunGameTask> {
dependsOn(jar)
}
}

publishMods {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ org.gradle.caching=true
#org.gradle.configuration-cache=true

# Versions
versionConnector=2.0.0-beta.4
versionConnector=2.0.0-beta.5
versionAdapter=1.13.20+1.21.1-20240811.191740
versionAdapterDefinition=1.13.21+1.21.1
versionAdapterDefinition=1.13.23+1.21.1
versionAdapterRuntime=1.0.0+1.21.1

versionMc=1.21.1
versionNeoForge=21.1.57
versionNeoForge=21.1.90
versionParchmentMc=1.21
versionParchment=2024.07.28
versionForgeAutoRenamingTool=1.0.12
versionForgifiedFabricLoader=2.5.33+0.16.0+1.21.1
versionForgifiedFabricLoader=2.5.34+0.16.0+1.21.1
versionAccessWidener=2.1.0
versionForgifiedFabricApi=0.104.0+2.0.13+1.21.1

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions src/main/java/org/sinytra/connector/ConnectorCoremods.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private static List<ITransformer<?>> getFabricASMTransformers() {
TargetType.METHOD,
Set.of(
ITransformer.Target.targetMethod("com.chocohead.mm.Plugin$1", "generate", "()Ljava/util/function/Consumer;"),
ITransformer.Target.targetMethod("com.chocohead.mm.Plugin$1", "generate", "(Ljava/lang/String;Ljava/util/Collection;)V"),
ITransformer.Target.targetMethod("me.shedaniel.mm.Plugin$1", "generate", "(Ljava/lang/String;Ljava/util/Collection;)V")
),
input -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ private List<IModFile> locateFabricMods(List<IModFile> discoveredMods) {
// Run jar transformations (or get existing outputs from cache)
List<JarTransformer.TransformedFabricModPath> transformed = JarTransformer.transform(candidates, renameLibs, loadedModFiles);

List<JarTransformer.TransformedFabricModPath> failing = transformed.stream().filter(j -> j.auditTrail() != null && j.auditTrail().hasFailingMixins()).toList();
if (!failing.isEmpty()) {
MixinTransformSafeguard.trigger(failing);
}

// Skip last step to save time if an error occured during transformation
if (ConnectorEarlyLoader.hasEncounteredException()) {
StartupNotificationManager.addModMessage("JAR TRANSFORMATION ERROR");
Expand All @@ -147,6 +152,9 @@ private List<IModFile> locateFabricMods(List<IModFile> discoveredMods) {

private static IModFile createConnectorModFile(SplitPackageMerger.FilteredModPath modPath) {
JarContents jarContents = new JarContentsBuilder().paths(modPath.paths()).pathFilter(modPath.filter()).build();
if (modPath.metadata().generated()) {
return IModFile.create(SecureJar.from(jarContents), JarModsDotTomlModFileReader::manifestParser, IModFile.Type.LIBRARY, ModFileDiscoveryAttributes.DEFAULT);
}
ModJarMetadata modJarMetadata = new ModJarMetadata(jarContents);
SecureJar secureJar = SecureJar.from(jarContents, modJarMetadata);
IModFile modFile = IModFile.create(secureJar, f -> FabricModMetadataParser.createForgeMetadata(f, modPath.metadata().modMetadata(), modPath.metadata().visibleMixinConfigs(), modPath.metadata().generated()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.sinytra.connector.locator;

import com.mojang.logging.LogUtils;
import net.neoforged.fml.ModLoadingException;
import net.neoforged.fml.ModLoadingIssue;
import net.neoforged.fml.loading.progress.StartupNotificationManager;
import org.sinytra.adapter.patch.api.PatchAuditTrail;
import org.sinytra.connector.transformer.jar.JarTransformer;
import org.sinytra.connector.util.ConnectorConfig;
import org.slf4j.Logger;

import java.util.List;

public final class MixinTransformSafeguard {
private static final Logger LOGGER = LogUtils.getLogger();

public static boolean isEnabled() {
return ConnectorConfig.INSTANCE.get().enableMixinSafeguard();
}

public static void trigger(List<JarTransformer.TransformedFabricModPath> failing) throws ModLoadingException {
if (!isEnabled()) {
LOGGER.warn("Ignoring {} found incompatibilities as mixin safeguard is disabled", failing.size());
return;
}

StartupNotificationManager.addModMessage("INCOMPATIBLE FABRIC MOD FOUND");
StringBuilder builder = new StringBuilder();

String msg = "Found §e" + failing.size() + " incompatible Fabric " + (failing.size() > 1 ? "mods" : "mod") + "§r. Details are provided below.\n\n" +
"With the current configuration, Connector §ccannot guarantee§r a stable environment. Should you still want to proceed, please restart the game.\n\n" +
"§7This one-time safety check can be disabled in Connector's config file under \"enableMixinSafeguard\".§r";
builder.append(msg).append("\n\n");

failing.forEach(p -> {
builder.append("Mod file §e").append(p.input().getFileName().toString()).append("§r has failing mixins:\n");
for (PatchAuditTrail.Candidate failed : p.auditTrail().getFailingMixins()) {
String[] parts = failed.classNode().name.split("/");
builder.append("- §c").append(parts[parts.length - 1]).append("§7#§3").append(failed.methodNode().name).append("§r\n");
}
builder.append("\n");
});

throw new ModLoadingException(ModLoadingIssue.error(builder.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.neoforged.fml.loading.LoadingModList;
import net.neoforged.neoforgespi.earlywindow.ImmediateWindowProvider;
import org.sinytra.connector.ConnectorEarlyLoader;
import org.sinytra.connector.locator.ConnectorLocator;
import org.sinytra.connector.service.hacks.ConnectorForkJoinThreadFactory;
import org.sinytra.connector.service.hacks.FabricASMFixer;
import org.sinytra.connector.service.hacks.LenientRuntimeEnumExtender;
Expand All @@ -38,6 +37,7 @@
public class ConnectorLoaderService implements ITransformationService {
private static final String NAME = "connector_loader";
private static final String AUTHLIB_MODULE = "authlib";
private static final String BRIGADIER_MODULE = "brigadier";
private static final Logger LOGGER = LogUtils.getLogger();
private static final VarHandle PLUGINS = uncheck(() -> ConnectorUtil.TRUSTED_LOOKUP.findVarHandle(LaunchPluginHandler.class, "plugins", Map.class));

Expand Down Expand Up @@ -122,7 +122,8 @@ public List<Resource> completeScan(IModuleLayerManager layerManager) {
}
return List.of(new Resource(IModuleLayerManager.Layer.GAME, List.of(
FabricASMFixer.provideGeneratedClassesJar(),
ModuleLayerMigrator.moveModule(AUTHLIB_MODULE)
ModuleLayerMigrator.moveModule(AUTHLIB_MODULE),
ModuleLayerMigrator.moveModule(BRIGADIER_MODULE)
)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@
import net.minecraftforge.fart.internal.RenamingTransformer;
import net.minecraftforge.srgutils.IMappingFile;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.*;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.objectweb.asm.tree.*;
import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
Expand All @@ -33,12 +19,7 @@
import org.spongepowered.asm.mixin.gen.AccessorInfo;

import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -107,7 +88,8 @@ protected void postProcess(ClassNode node) {
}

private void avoidAmbigousMappingRecursion(ClassNode classNode, MethodNode method) {
if (isAmbigousOverridenMethod(classNode, method)) {
int parentMethods = countAmbigousOverridenMethods(classNode, method);
if (parentMethods > 1) {
for (AbstractInsnNode insn : method.instructions) {
if (insn instanceof MethodInsnNode minsn && minsn.getOpcode() == Opcodes.INVOKEVIRTUAL && minsn.owner.equals(classNode.name) && minsn.name.equals(method.name) && minsn.desc.equals(method.desc)) {
List<AbstractInsnNode> insns = MethodCallAnalyzer.findMethodCallParamInsns(method, minsn);
Expand All @@ -117,16 +99,25 @@ private void avoidAmbigousMappingRecursion(ClassNode classNode, MethodNode metho
}
}
}
// Look for ambigous methods in our own class
if (parentMethods > 0) {
int i = 1;
for (MethodNode m : classNode.methods) {
if (m != method && m.name.equals(method.name) && m.desc.equals(method.desc)) {
m.name += "$connector_disabled$" + i;
}
}
}
}

private boolean isAmbigousOverridenMethod(ClassNode classNode, MethodNode method) {
return classNode.superName != null && this.remapper.getClass(classNode.name)
.map(c -> c.getMethods().stream()
private int countAmbigousOverridenMethods(ClassNode classNode, MethodNode method) {
return classNode.superName != null ? this.remapper.getClass(classNode.name)
.map(c -> (int) c.getMethods().stream()
.flatMap(Optional::stream)
.filter(m -> !m.getName().equals(m.getMapped()) && m.getMapped().equals(method.name) && method.desc.equals(this.remapper.mapMethodDesc(m.getDescriptor()))
&& (m.getAccess() & (ACC_PRIVATE | ACC_STATIC)) == 0)
.count() > 1)
.orElse(false);
.count())
.orElse(0) : 0;
}

private void processMixinAnnotation(AnnotationNode annotation, PostProcessRemapper postProcessRemapper) {
Expand Down Expand Up @@ -282,10 +273,6 @@ public MixinAwareEnhancedRemapper(ClassProvider classProvider, IMappingFile map,
this.flatMappings = flatMappings;
}

public ClassProvider getUpstreamProvider() {
return ((IntermediaryClassProvider) this.classProvider).upstream;
}

@Override
public String map(final String key) {
String fastMapped = this.flatMappings.map(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.neoforged.fml.loading.LibraryFinder;
import net.neoforged.fml.loading.MavenCoordinate;
import net.neoforged.neoforgespi.locating.IModFile;
import org.jetbrains.annotations.Nullable;
import org.sinytra.adapter.patch.LVTOffsets;
import org.sinytra.adapter.patch.api.Patch;
import org.sinytra.adapter.patch.api.PatchAuditTrail;
Expand Down Expand Up @@ -111,12 +112,13 @@ public BytecodeFixerUpperFrontend getBfu() {
return bfu;
}

public void transformJar(File input, Path output, JarTransformer.FabricModFileMetadata metadata) throws IOException {
@Nullable
public PatchAuditTrail transformJar(File input, Path output, JarTransformer.FabricModFileMetadata metadata) throws IOException {
Stopwatch stopwatch = Stopwatch.createStarted();

if (metadata.generated()) {
processGeneratedJar(input, output, stopwatch);
return;
return null;
}

String jarMapping = metadata.manifestAttributes().getValue(FABRIC_MAPPING_NAMESPACE);
Expand All @@ -130,10 +132,11 @@ public void transformJar(File input, Path output, JarTransformer.FabricModFileMe
IMappingFile intermediaryToSrg = resolver.getCurrentMap(JarTransformer.SOURCE_NAMESPACE);
AccessorRedirectTransformer accessorRedirectTransformer = new AccessorRedirectTransformer(srgToIntermediary);

PatchAuditTrail jarTrail = PatchAuditTrail.create();
List<Patch> extraPatches = Stream.concat(this.adapterPatches.stream(), AccessorRedirectTransformer.PATCHES.stream()).toList();
ConnectorRefmapHolder refmapHolder = new ConnectorRefmapHolder(refmap.merged(), refmap.files());
int fabricLVTCompatibility = FabricMixinBootstrap.MixinConfigDecorator.getMixinCompat(metadata.modMetadata());
PatchEnvironment environment = PatchEnvironment.create(refmapHolder, this.cleanClassLookup, this.bfu.unwrap(), fabricLVTCompatibility, this.auditTrail);
PatchEnvironment environment = PatchEnvironment.create(refmapHolder, this.cleanClassLookup, this.bfu.unwrap(), fabricLVTCompatibility, jarTrail);
MixinPatchTransformer patchTransformer = new MixinPatchTransformer(this.lvtOffsetsData, environment, extraPatches);
RefmapRemapper refmapRemapper = new RefmapRemapper(refmap.files());
Renamer.Builder builder = Renamer.builder()
Expand Down Expand Up @@ -168,6 +171,9 @@ public void transformJar(File input, Path output, JarTransformer.FabricModFileMe

stopwatch.stop();
LOGGER.debug(JarTransformer.TRANSFORM_MARKER, "Jar {} transformed in {} ms", input.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS));

this.auditTrail.merge(jarTrail);
return jarTrail;
}

private static void processGeneratedJar(File input, Path output, Stopwatch stopwatch) throws IOException {
Expand Down
Loading

0 comments on commit 99441a8

Please sign in to comment.