Skip to content

Commit b149723

Browse files
committed
more mixin compat code
1 parent 0b3c0a9 commit b149723

File tree

4 files changed

+119
-38
lines changed

4 files changed

+119
-38
lines changed

build.gradle

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//version: 1656003793falsepattern31
1+
//version: 1656003793falsepattern32
22
/*
33
DO NOT CHANGE THIS FILE!
44
@@ -24,7 +24,7 @@ buildscript {
2424
mavenLocal()
2525
maven {
2626
name = "forge"
27-
url = "https://mvn.falsepattern.com/forge/"
27+
url = "https://mvn.falsepattern.com/forge"
2828
}
2929
maven {
3030
name = "sonatype"
@@ -39,7 +39,7 @@ buildscript {
3939
url = "https://mvn.falsepattern.com/jitpack/"
4040
}
4141
maven {
42-
name = "mvnpattern"
42+
name = "mavenpattern"
4343
url = "https://mvn.falsepattern.com/releases/"
4444
}
4545
}
@@ -126,12 +126,6 @@ propertyDefaultIfUnset("remoteMappings", "https://raw.githubusercontent.com/Mine
126126
propertyDefaultIfUnset("mappingsChannel", "stable")
127127
propertyDefaultIfUnset("mappingsVersion", "12")
128128

129-
if (usesMixins.toBoolean() && !useObsoleteSpongeMixins.toBoolean()) {
130-
//1.1.2
131-
//Currently using upstream, will make a fork soon(tm)
132-
apply from: 'https://raw.githubusercontent.com/tox1cozZ/mixin-booter-legacy/30de05f4c3e41360f423d8c5fd4adc73d4677a37/gradle/configurations/v1.gradle'
133-
}
134-
135129
String javaSourceDir = "src/main/java/"
136130
String scalaSourceDir = "src/main/scala/"
137131
String kotlinSourceDir = "src/main/kotlin/"
@@ -309,6 +303,7 @@ dependencies {
309303
compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
310304
} else {
311305
compile("com.github.tox1cozZ:mixin-booter-legacy:1.1.2")
306+
annotationProcessor("com.github.tox1cozZ:mixin-booter-legacy:1.1.2:processor")
312307
}
313308
}
314309
if(hasMixinDeps.toBoolean()) {
@@ -395,22 +390,18 @@ jar {
395390
}
396391

397392
reobf {
398-
if(usesMixins.toBoolean() && useObsoleteSpongeMixins.toBoolean() && file(mixinSrg).exists()) {
393+
if(usesMixins.toBoolean() && file(mixinSrg).exists()) {
399394
addExtraSrgFile mixinSrg
400395
}
401396
}
402397

403398
afterEvaluate {
404399
if(usesMixins.toBoolean()) {
405400
tasks.compileJava {
406-
if (useObsoleteSpongeMixins.toBoolean()) {
407-
options.compilerArgs += [
408-
"-AreobfSrgFile=${tasks.reobf.srg}",
409-
"-AoutSrgFile=${mixinSrg}",
410-
"-AoutRefMapFile=${refMap}"
411-
]
412-
}
413401
options.compilerArgs += [
402+
"-AreobfSrgFile=${tasks.reobf.srg}",
403+
"-AoutSrgFile=${mixinSrg}",
404+
"-AoutRefMapFile=${refMap}",
414405
// Elan: from what I understand they are just some linter configs so you get some warning on how to properly code
415406
"-XDenableSunApiLintControl",
416407
"-XDignore.symbol.file"

src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@
1515
@Accessors(fluent = true)
1616
@StableAPI(since = "__INTERNAL__")
1717
public class FPTransformer implements SmartTransformer {
18+
static final Logger LOG = LogManager.getLogger(Tags.MODNAME + " ASM");
19+
1820
@Getter
1921
private final List<IClassNodeTransformer> transformers;
2022

2123
@Getter
22-
private final Logger logger = LogManager.getLogger(Tags.MODNAME + " ASM");
24+
private final Logger logger = LOG;
2325

2426
public FPTransformer() {
25-
boolean obsolete;
26-
try {
27-
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
28-
logger.info("Detected MixinBooter Legacy.");
29-
obsolete = false;
30-
} catch (ClassNotFoundException e) {
31-
logger.info("Detected SpongeMixins or Grimoire. Applying legacy compat fix to IMixinPlugin.");
32-
obsolete = true;
33-
}
34-
transformers = Collections.singletonList(new IMixinPluginTransformer(obsolete));
27+
transformers = Collections.singletonList(new IMixinPluginTransformer());
3528
}
3629
}

src/main/java/com/falsepattern/lib/internal/asm/IMixinPluginTransformer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
import com.falsepattern.lib.asm.IClassNodeTransformer;
44
import com.falsepattern.lib.internal.Tags;
5-
import lombok.RequiredArgsConstructor;
5+
import com.falsepattern.lib.mixin.MixinInfo;
66
import lombok.val;
77
import org.objectweb.asm.tree.ClassNode;
88
import org.objectweb.asm.tree.MethodNode;
99

1010
import java.util.ArrayList;
1111

12-
@RequiredArgsConstructor
1312
public class IMixinPluginTransformer implements IClassNodeTransformer {
14-
private final boolean obsolete;
15-
1613
@Override
1714
public String getName() {
1815
return "IMixinPluginTransformer";
@@ -27,22 +24,25 @@ public boolean shouldTransform(ClassNode cn, String transformedName, boolean obf
2724
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
2825
val methods = cn.methods;
2926
val remove = new ArrayList<MethodNode>();
30-
if (obsolete) {
27+
if (MixinInfo.isMixinBooterLegacy()) {
28+
FPTransformer.LOG.info("Detected MixinBooterLegacy. Selecting proper methods in IMixinPlugin.");
3129
for (val method : methods) {
32-
if (method.name.equals("preApply") || method.name.equals("postApply")) {
30+
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
3331
remove.add(method);
3432
}
3533
}
3634
methods.removeAll(remove);
35+
} else {
36+
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Selecting proper methods in IMixinPlugin.");
3737
for (val method : methods) {
38-
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
39-
method.name = method.name.substring(0, method.name.indexOf('_'));
38+
if (method.name.equals("preApply") || method.name.equals("postApply")) {
39+
remove.add(method);
4040
}
4141
}
42-
} else {
42+
methods.removeAll(remove);
4343
for (val method : methods) {
4444
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
45-
remove.add(method);
45+
method.name = method.name.substring(0, method.name.indexOf('_'));
4646
}
4747
}
4848
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.falsepattern.lib.mixin;
2+
3+
import com.falsepattern.lib.StableAPI;
4+
import org.spongepowered.asm.launch.MixinBootstrap;
5+
6+
import java.util.Optional;
7+
8+
@StableAPI(since = "0.10.2")
9+
public final class MixinInfo {
10+
@StableAPI.Expose
11+
public static final MixinBootstrapperType mixinBootstrapper = detect();
12+
13+
@StableAPI.Expose
14+
public static boolean isMixinsInstalled() {
15+
return mixinBootstrapper != MixinBootstrapperType.None;
16+
}
17+
18+
@StableAPI.Expose
19+
public static boolean isOfficialSpongeMixins() {
20+
return (mixinBootstrapper == MixinBootstrapperType.SpongeMixins) && getVerUnsafe().equals("0.7.11");
21+
}
22+
23+
/**
24+
* The nh fork of spongemixins breaks some stuff since 1.5.0.
25+
*/
26+
@StableAPI.Expose
27+
public static boolean isTamperedSpongeMixins() {
28+
return (mixinBootstrapper == MixinBootstrapperType.SpongeMixins) && getVerUnsafe().equals("0.7.12");
29+
}
30+
31+
@StableAPI.Expose
32+
public static boolean isGrimoire() {
33+
return mixinBootstrapper == MixinBootstrapperType.Grimoire;
34+
}
35+
36+
@StableAPI.Expose
37+
public static boolean isMixinBooterLegacy() {
38+
return mixinBootstrapper == MixinBootstrapperType.MixinBooterLegacy;
39+
}
40+
41+
@StableAPI.Expose
42+
public static MixinBootstrapperType bootstrapperType() {
43+
return mixinBootstrapper;
44+
}
45+
46+
@StableAPI.Expose
47+
public static Optional<String> mixinVersion() {
48+
return mixinBootstrapper != MixinBootstrapperType.None ? Optional.of(getVerUnsafe()) : Optional.empty();
49+
}
50+
51+
private static String getVerUnsafe() {
52+
return MixinBootstrap.VERSION;
53+
}
54+
55+
private static MixinBootstrapperType detect() {
56+
try {
57+
Class.forName("org.spongepowered.asm.launch.MixinBootstrap");
58+
} catch (ClassNotFoundException ignored) {
59+
return MixinBootstrapperType.None;
60+
}
61+
try {
62+
Class.forName("ru.timeconqueror.spongemixins.core.SpongeMixinsCore");
63+
return MixinBootstrapperType.SpongeMixins;
64+
} catch (ClassNotFoundException ignored) {
65+
}
66+
try {
67+
Class.forName("io.github.crucible.grimoire.Grimoire");
68+
return MixinBootstrapperType.Grimoire;
69+
} catch (ClassNotFoundException ignored) {
70+
}
71+
try {
72+
Class.forName("io.github.crucible.grimoire.common.GrimoireCore");
73+
return MixinBootstrapperType.Grimoire;
74+
} catch (ClassNotFoundException ignored) {
75+
}
76+
try {
77+
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
78+
return MixinBootstrapperType.MixinBooterLegacy;
79+
} catch (ClassNotFoundException ignored) {}
80+
81+
return MixinBootstrapperType.Other;
82+
}
83+
84+
@StableAPI(since = "0.10.2")
85+
public enum MixinBootstrapperType {
86+
@StableAPI.Expose
87+
None,
88+
@StableAPI.Expose
89+
SpongeMixins,
90+
@StableAPI.Expose
91+
Grimoire,
92+
@StableAPI.Expose
93+
MixinBooterLegacy,
94+
@StableAPI.Expose
95+
Other
96+
}
97+
}

0 commit comments

Comments
 (0)