Skip to content

Commit 58be5af

Browse files
authored
Develop beta 35 (#771)
2 parents 37ae102 + c494b59 commit 58be5af

File tree

7 files changed

+97
-34
lines changed

7 files changed

+97
-34
lines changed

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ org.gradle.jvmargs=-Xmx3G
44
org.gradle.daemon=true
55

66
# Versions
7-
versionConnector=1.0.0-beta.34
8-
versionAdapter=1.11.12-1.20.1-20240124.174344
9-
versionAdapterDefinition=1.11.12
7+
versionConnector=1.0.0-beta.35
8+
versionAdapter=1.11.19-1.20.1-20240126.215012
9+
versionAdapterDefinition=1.11.22
1010

1111
versionMc=1.20.1
1212
versionForge=47.1.3
1313
versionForgeAutoRenamingTool=1.0.9
1414
versionFabricLoader=2.7.1+0.15.3+1.20.1
1515
versionAccessWidener=2.1.0
16-
versionFabricApi=0.90.7+1.10.3+1.20.1
16+
versionFabricApi=0.91.0+1.10.8+1.20.1
1717
versionMixin=0.12.5+mixin.0.8.5
1818
versionMixinTransmog=0.4.3+1.20.1
1919

src/main/java/dev/su5ed/sinytra/connector/locator/DependencyResolver.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.su5ed.sinytra.connector.locator;
22

3+
import com.google.common.base.Suppliers;
34
import com.google.common.collect.BiMap;
45
import com.google.common.collect.HashBiMap;
56
import com.google.common.collect.Multimap;
@@ -35,6 +36,7 @@
3536
import java.util.Map;
3637
import java.util.Objects;
3738
import java.util.function.Function;
39+
import java.util.function.Supplier;
3840
import java.util.stream.Stream;
3941
import java.util.stream.StreamSupport;
4042

@@ -43,7 +45,7 @@
4345
public final class DependencyResolver {
4446
private static final Logger LOGGER = LogUtils.getLogger();
4547
public static final VersionOverrides VERSION_OVERRIDES = new VersionOverrides();
46-
public static final DependencyOverrides DEPENDENCY_OVERRIDES = new DependencyOverrides(FMLPaths.CONFIGDIR.get());
48+
public static final Supplier<DependencyOverrides> DEPENDENCY_OVERRIDES = Suppliers.memoize(DependencyResolver::loadDependencyOverrides);
4749
private static final GlobalModAliases GLOBAL_MOD_ALIASES = new GlobalModAliases(FMLPaths.CONFIGDIR.get(), ConnectorUtil.DEFAULT_GLOBAL_MOD_ALIASES);
4850

4951
public static List<JarTransformer.TransformableJar> resolveDependencies(Collection<JarTransformer.TransformableJar> keys, Multimap<JarTransformer.TransformableJar, JarTransformer.TransformableJar> jars, Iterable<IModFile> loadedMods) {
@@ -100,7 +102,7 @@ private static ModCandidate createJavaMod() {
100102
.build();
101103
GameProvider.BuiltinMod builtinMod = new GameProvider.BuiltinMod(Collections.singletonList(Paths.get(System.getProperty("java.home"))), metadata);
102104

103-
return ModCandidate.createBuiltin(builtinMod, VERSION_OVERRIDES, DEPENDENCY_OVERRIDES);
105+
return ModCandidate.createBuiltin(builtinMod, VERSION_OVERRIDES, DEPENDENCY_OVERRIDES.get());
104106
}
105107

106108
private static ModCandidate createFabricLoaderMod() {
@@ -125,6 +127,14 @@ private static ModCandidate createFabricLoaderMod() {
125127

126128
GameProvider.BuiltinMod builtinMod = new GameProvider.BuiltinMod(Collections.singletonList(Path.of(uncheck(() -> FabricLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI()))), metadata);
127129

128-
return ModCandidate.createBuiltin(builtinMod, VERSION_OVERRIDES, DEPENDENCY_OVERRIDES);
130+
return ModCandidate.createBuiltin(builtinMod, VERSION_OVERRIDES, DEPENDENCY_OVERRIDES.get());
131+
}
132+
133+
private static DependencyOverrides loadDependencyOverrides() {
134+
try {
135+
return new DependencyOverrides(FMLPaths.CONFIGDIR.get());
136+
} catch (Exception e) {
137+
throw ConnectorEarlyLoader.createGenericLoadingException(e, "Invalid config file fabric_loader_dependencies.json");
138+
}
129139
}
130140
}

src/main/java/dev/su5ed/sinytra/connector/service/ConnectorPreLaunchPlugin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public String name() {
2626
public void initializeLaunch(ITransformerLoader transformerLoader, NamedPath[] specialPaths) {
2727
// Apply provider inheritance fix from newer SJH versions
2828
ServiceProviderInheritanceWorkaround.apply();
29-
// Decorate mixin config's with mod IDs, enabling method prefix functionality
30-
FabricMixinBootstrap.init();
3129
// Setup Fabric Loader
3230
ConnectorEarlyLoader.init();
31+
// Decorate mixin config's with mod IDs, enabling method prefix functionality
32+
FabricMixinBootstrap.init();
3333
// Apply Fabric ASM fix
3434
FabricASMFixer.injectMinecraftModuleReader();
3535
}

src/main/java/dev/su5ed/sinytra/connector/transformer/jar/JarTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static FabricModFileMetadata readModMetadata(File input) throws IOExcept
176176
ConnectorLoaderModMetadata metadata;
177177
Set<String> configs;
178178
try (InputStream ins = jarFile.getInputStream(jarFile.getEntry(ConnectorUtil.FABRIC_MOD_JSON))) {
179-
LoaderModMetadata rawMetadata = ModMetadataParser.parseMetadata(ins, "", Collections.emptyList(), DependencyResolver.VERSION_OVERRIDES, DependencyResolver.DEPENDENCY_OVERRIDES, false);
179+
LoaderModMetadata rawMetadata = ModMetadataParser.parseMetadata(ins, "", Collections.emptyList(), DependencyResolver.VERSION_OVERRIDES, DependencyResolver.DEPENDENCY_OVERRIDES.get(), false);
180180
metadata = new ConnectorLoaderModMetadata(rawMetadata);
181181

182182
configs = new HashSet<>(metadata.getMixinConfigs(FabricLoader.getInstance().getEnvironmentType()));

src/main/java/dev/su5ed/sinytra/connector/transformer/patch/ClassAnalysingTransformer.java

+9-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dev.su5ed.sinytra.adapter.patch.analysis.MethodCallAnalyzer;
44
import dev.su5ed.sinytra.adapter.patch.api.Patch;
5+
import dev.su5ed.sinytra.adapter.patch.util.MethodQualifier;
56
import dev.su5ed.sinytra.connector.transformer.jar.IntermediateMapping;
67
import net.minecraftforge.srgutils.IMappingFile;
78
import org.jetbrains.annotations.Nullable;
@@ -15,12 +16,13 @@
1516
import org.objectweb.asm.tree.analysis.SourceInterpreter;
1617
import org.objectweb.asm.tree.analysis.SourceValue;
1718

18-
import java.util.ArrayList;
1919
import java.util.Collection;
2020
import java.util.HashSet;
2121
import java.util.List;
2222

2323
public class ClassAnalysingTransformer implements ClassNodeTransformer.ClassProcessor {
24+
private static final MethodQualifier GET_RESOURCE_AS_STREAM = new MethodQualifier("Ljava/lang/Class;", "getResourceAsStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
25+
2426
private final IMappingFile mappings;
2527
private final IntermediateMapping fastMappings;
2628

@@ -29,27 +31,25 @@ public ClassAnalysingTransformer(IMappingFile mappings, IntermediateMapping fast
2931
this.fastMappings = fastMappings;
3032
}
3133

32-
record Replacement(MethodInsnNode methodInsn, AbstractInsnNode paramInsn) {}
33-
3434
@Override
3535
public Patch.Result process(ClassNode node) {
3636
boolean applied = false;
3737
for (MethodNode method : node.methods) {
3838
ScanningSourceInterpreter i = MethodCallAnalyzer.analyzeInterpretMethod(method, new ScanningSourceInterpreter(Opcodes.ASM9));
39-
4039
applied |= i.remapApplied();
41-
for (Replacement replacement : i.getReplacements()) {
42-
method.instructions.insert(replacement.paramInsn, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getClassLoader", "()Ljava/lang/ClassLoader;"));
43-
replacement.methodInsn.owner = "java/lang/ClassLoader";
44-
applied = true;
40+
41+
for (AbstractInsnNode insn : method.instructions) {
42+
if (insn instanceof MethodInsnNode minsn && GET_RESOURCE_AS_STREAM.matches(minsn)) {
43+
method.instructions.set(insn, new MethodInsnNode(Opcodes.INVOKESTATIC, "dev/su5ed/sinytra/connector/mod/ConnectorMod", "getModResourceAsStream", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/io/InputStream;", false));
44+
applied = true;
45+
}
4546
}
4647
}
4748
return applied ? Patch.Result.APPLY : Patch.Result.PASS;
4849
}
4950

5051
private class ScanningSourceInterpreter extends SourceInterpreter {
5152
private static final Type STR_TYPE = Type.getType(String.class);
52-
private final List<Replacement> replacements = new ArrayList<>();
5353
private final Collection<MethodInsnNode> seen = new HashSet<>();
5454
private boolean remapApplied = false;
5555

@@ -61,24 +61,9 @@ public boolean remapApplied() {
6161
return this.remapApplied;
6262
}
6363

64-
public List<Replacement> getReplacements() {
65-
return this.replacements;
66-
}
67-
6864
@Override
6965
public SourceValue naryOperation(AbstractInsnNode insn, List<? extends SourceValue> values) {
7066
if (insn instanceof MethodInsnNode methodInsn && !this.seen.contains(methodInsn)) {
71-
if (methodInsn.owner.equals("java/lang/Class") && methodInsn.name.equals("getResourceAsStream") && methodInsn.desc.equals("(Ljava/lang/String;)Ljava/io/InputStream;")) {
72-
SourceValue value = values.get(0);
73-
if (value.insns.size() == 1) {
74-
AbstractInsnNode sourceInsn = value.insns.iterator().next();
75-
this.replacements.add(new Replacement(methodInsn, sourceInsn));
76-
this.seen.add(methodInsn);
77-
}
78-
else {
79-
throw new IllegalStateException("Got multiple source value insns: " + value.insns);
80-
}
81-
}
8267
// Try to remap reflection method call args
8368
Type[] args = Type.getArgumentTypes(methodInsn.desc);
8469
if (args.length >= 3 && STR_TYPE.equals(args[0]) && STR_TYPE.equals(args[1]) && STR_TYPE.equals(args[2]) && values.size() >= 3) {

src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
1515
import net.minecraftforge.fml.loading.FMLLoader;
1616

17+
import java.io.InputStream;
18+
1719
@Mod(ConnectorUtil.CONNECTOR_MODID)
1820
public class ConnectorMod {
1921
private static boolean clientLoadComplete;
@@ -44,4 +46,11 @@ private static void onClientSetup(FMLClientSetupEvent event) {
4446
private static void onLoadComplete(FMLLoadCompleteEvent event) {
4547
LateSheetsInit.completeSheetsInit();
4648
}
49+
50+
// Injected into mod code by ClassAnalysingTransformer
51+
@SuppressWarnings("unused")
52+
public static InputStream getModResourceAsStream(Class<?> clazz, String name) {
53+
InputStream classRes = clazz.getResourceAsStream(name);
54+
return classRes != null ? classRes : clazz.getClassLoader().getResourceAsStream(name);
55+
}
4756
}

src/mod/resources/META-INF/asm/expandLocalVarScope.js

+59
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI');
22
var Opcodes = Java.type('org.objectweb.asm.Opcodes');
33
var InsnNode = Java.type('org.objectweb.asm.tree.InsnNode');
44
var VarInsnNode = Java.type('org.objectweb.asm.tree.VarInsnNode');
5+
var LabelNode = Java.type('org.objectweb.asm.tree.LabelNode');
56

67
function initializeCoreMod() {
78
return {
@@ -35,6 +36,64 @@ function initializeCoreMod() {
3536
ASMAPI.log('DEBUG', 'Expanded local variable scope for LivingEntity#forceAddEffect index 3');
3637
return node;
3738
}
39+
},
40+
'insertBooleanInjectionTarget': {
41+
'target': {
42+
'type': 'METHOD',
43+
'class': 'net.minecraft.world.level.BaseSpawner',
44+
'methodName': 'm_151311_',
45+
'methodDesc': '(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;)V'
46+
},
47+
'transformer': function (node) {
48+
var targetLocal = null;
49+
for (var i = 0; i < node.localVariables.size(); i++) {
50+
var lvn = node.localVariables.get(i);
51+
if (lvn.desc === 'Z') {
52+
targetLocal = lvn;
53+
break;
54+
}
55+
}
56+
57+
var instance = null;
58+
for (var i = 0; i < node.localVariables.size(); i++) {
59+
var lvn = node.localVariables.get(i);
60+
if (lvn.index === 0) {
61+
instance = lvn;
62+
break;
63+
}
64+
}
65+
66+
for (var i = 0; i < node.localVariables.size(); i++) {
67+
var lvn = node.localVariables.get(i);
68+
if (lvn === targetLocal) {
69+
lvn.start = instance.start;
70+
break;
71+
}
72+
}
73+
74+
var endLabel = null;
75+
for (var i = node.instructions.size() - 1; i > 0; i--) {
76+
if (node.instructions.get(i) instanceof LabelNode) {
77+
endLabel = node.instructions.get(i);
78+
break;
79+
}
80+
}
81+
82+
for (var i = 0; i < node.localVariables.size(); i++) {
83+
var lvn = node.localVariables.get(i);
84+
if (lvn === targetLocal) {
85+
lvn.end = endLabel;
86+
break;
87+
}
88+
}
89+
90+
node.instructions.insert(instance.start, ASMAPI.listOf(
91+
new InsnNode(Opcodes.ICONST_0),
92+
new VarInsnNode(Opcodes.ISTORE, targetLocal.index)
93+
));
94+
ASMAPI.log('DEBUG', 'Expanded local variable scope for BaseSpawner#serverTick index 3');
95+
return node;
96+
}
3897
}
3998
}
4099
}

0 commit comments

Comments
 (0)