mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-15 16:04:45 +00:00
more mixin compat code
This commit is contained in:
4 files changed
+120
-39
No files matched your search
+8
-17
@@ -1,4 +1,4 @@
|
||||
//version: 1656003793falsepattern31
|
||||
//version: 1656003793falsepattern32
|
||||
/*
|
||||
DO NOT CHANGE THIS FILE!
|
||||
|
||||
@@ -24,7 +24,7 @@ buildscript {
|
||||
mavenLocal()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "https://mvn.falsepattern.com/forge/"
|
||||
url = "https://mvn.falsepattern.com/forge"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
@@ -39,7 +39,7 @@ buildscript {
|
||||
url = "https://mvn.falsepattern.com/jitpack/"
|
||||
}
|
||||
maven {
|
||||
name = "mvnpattern"
|
||||
name = "mavenpattern"
|
||||
url = "https://mvn.falsepattern.com/releases/"
|
||||
}
|
||||
}
|
||||
@@ -126,12 +126,6 @@ propertyDefaultIfUnset("remoteMappings", "https://raw.githubusercontent.com/Mine
|
||||
propertyDefaultIfUnset("mappingsChannel", "stable")
|
||||
propertyDefaultIfUnset("mappingsVersion", "12")
|
||||
|
||||
if (usesMixins.toBoolean() && !useObsoleteSpongeMixins.toBoolean()) {
|
||||
//1.1.2
|
||||
//Currently using upstream, will make a fork soon(tm)
|
||||
apply from: 'https://raw.githubusercontent.com/tox1cozZ/mixin-booter-legacy/30de05f4c3e41360f423d8c5fd4adc73d4677a37/gradle/configurations/v1.gradle'
|
||||
}
|
||||
|
||||
String javaSourceDir = "src/main/java/"
|
||||
String scalaSourceDir = "src/main/scala/"
|
||||
String kotlinSourceDir = "src/main/kotlin/"
|
||||
@@ -309,6 +303,7 @@ dependencies {
|
||||
compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
|
||||
} else {
|
||||
compile("com.github.tox1cozZ:mixin-booter-legacy:1.1.2")
|
||||
annotationProcessor("com.github.tox1cozZ:mixin-booter-legacy:1.1.2:processor")
|
||||
}
|
||||
}
|
||||
if(hasMixinDeps.toBoolean()) {
|
||||
@@ -395,7 +390,7 @@ jar {
|
||||
}
|
||||
|
||||
reobf {
|
||||
if(usesMixins.toBoolean() && useObsoleteSpongeMixins.toBoolean() && file(mixinSrg).exists()) {
|
||||
if(usesMixins.toBoolean() && file(mixinSrg).exists()) {
|
||||
addExtraSrgFile mixinSrg
|
||||
}
|
||||
}
|
||||
@@ -403,14 +398,10 @@ reobf {
|
||||
afterEvaluate {
|
||||
if(usesMixins.toBoolean()) {
|
||||
tasks.compileJava {
|
||||
if (useObsoleteSpongeMixins.toBoolean()) {
|
||||
options.compilerArgs += [
|
||||
"-AreobfSrgFile=${tasks.reobf.srg}",
|
||||
"-AoutSrgFile=${mixinSrg}",
|
||||
"-AoutRefMapFile=${refMap}"
|
||||
]
|
||||
}
|
||||
options.compilerArgs += [
|
||||
"-AreobfSrgFile=${tasks.reobf.srg}",
|
||||
"-AoutSrgFile=${mixinSrg}",
|
||||
"-AoutRefMapFile=${refMap}",
|
||||
// Elan: from what I understand they are just some linter configs so you get some warning on how to properly code
|
||||
"-XDenableSunApiLintControl",
|
||||
"-XDignore.symbol.file"
|
||||
|
||||
@@ -15,22 +15,15 @@ import java.util.List;
|
||||
@Accessors(fluent = true)
|
||||
@StableAPI(since = "__INTERNAL__")
|
||||
public class FPTransformer implements SmartTransformer {
|
||||
static final Logger LOG = LogManager.getLogger(Tags.MODNAME + " ASM");
|
||||
|
||||
@Getter
|
||||
private final List<IClassNodeTransformer> transformers;
|
||||
|
||||
@Getter
|
||||
private final Logger logger = LogManager.getLogger(Tags.MODNAME + " ASM");
|
||||
private final Logger logger = LOG;
|
||||
|
||||
public FPTransformer() {
|
||||
boolean obsolete;
|
||||
try {
|
||||
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
|
||||
logger.info("Detected MixinBooter Legacy.");
|
||||
obsolete = false;
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.info("Detected SpongeMixins or Grimoire. Applying legacy compat fix to IMixinPlugin.");
|
||||
obsolete = true;
|
||||
}
|
||||
transformers = Collections.singletonList(new IMixinPluginTransformer(obsolete));
|
||||
transformers = Collections.singletonList(new IMixinPluginTransformer());
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,14 @@ package com.falsepattern.lib.internal.asm;
|
||||
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.falsepattern.lib.mixin.MixinInfo;
|
||||
import lombok.val;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
private final boolean obsolete;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "IMixinPluginTransformer";
|
||||
@@ -27,7 +24,16 @@ public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
val methods = cn.methods;
|
||||
val remove = new ArrayList<MethodNode>();
|
||||
if (obsolete) {
|
||||
if (MixinInfo.isMixinBooterLegacy()) {
|
||||
FPTransformer.LOG.info("Detected MixinBooterLegacy. Selecting proper methods in IMixinPlugin.");
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
|
||||
remove.add(method);
|
||||
}
|
||||
}
|
||||
methods.removeAll(remove);
|
||||
} else {
|
||||
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Selecting proper methods in IMixinPlugin.");
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply") || method.name.equals("postApply")) {
|
||||
remove.add(method);
|
||||
@@ -39,12 +45,6 @@ public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
method.name = method.name.substring(0, method.name.indexOf('_'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
|
||||
remove.add(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.falsepattern.lib.mixin;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@StableAPI(since = "0.10.2")
|
||||
public final class MixinInfo {
|
||||
@StableAPI.Expose
|
||||
public static final MixinBootstrapperType mixinBootstrapper = detect();
|
||||
|
||||
@StableAPI.Expose
|
||||
public static boolean isMixinsInstalled() {
|
||||
return mixinBootstrapper != MixinBootstrapperType.None;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static boolean isOfficialSpongeMixins() {
|
||||
return (mixinBootstrapper == MixinBootstrapperType.SpongeMixins) && getVerUnsafe().equals("0.7.11");
|
||||
}
|
||||
|
||||
/**
|
||||
* The nh fork of spongemixins breaks some stuff since 1.5.0.
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static boolean isTamperedSpongeMixins() {
|
||||
return (mixinBootstrapper == MixinBootstrapperType.SpongeMixins) && getVerUnsafe().equals("0.7.12");
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static boolean isGrimoire() {
|
||||
return mixinBootstrapper == MixinBootstrapperType.Grimoire;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static boolean isMixinBooterLegacy() {
|
||||
return mixinBootstrapper == MixinBootstrapperType.MixinBooterLegacy;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MixinBootstrapperType bootstrapperType() {
|
||||
return mixinBootstrapper;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static Optional<String> mixinVersion() {
|
||||
return mixinBootstrapper != MixinBootstrapperType.None ? Optional.of(getVerUnsafe()) : Optional.empty();
|
||||
}
|
||||
|
||||
private static String getVerUnsafe() {
|
||||
return MixinBootstrap.VERSION;
|
||||
}
|
||||
|
||||
private static MixinBootstrapperType detect() {
|
||||
try {
|
||||
Class.forName("org.spongepowered.asm.launch.MixinBootstrap");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return MixinBootstrapperType.None;
|
||||
}
|
||||
try {
|
||||
Class.forName("ru.timeconqueror.spongemixins.core.SpongeMixinsCore");
|
||||
return MixinBootstrapperType.SpongeMixins;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("io.github.crucible.grimoire.Grimoire");
|
||||
return MixinBootstrapperType.Grimoire;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("io.github.crucible.grimoire.common.GrimoireCore");
|
||||
return MixinBootstrapperType.Grimoire;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
|
||||
return MixinBootstrapperType.MixinBooterLegacy;
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
|
||||
return MixinBootstrapperType.Other;
|
||||
}
|
||||
|
||||
@StableAPI(since = "0.10.2")
|
||||
public enum MixinBootstrapperType {
|
||||
@StableAPI.Expose
|
||||
None,
|
||||
@StableAPI.Expose
|
||||
SpongeMixins,
|
||||
@StableAPI.Expose
|
||||
Grimoire,
|
||||
@StableAPI.Expose
|
||||
MixinBooterLegacy,
|
||||
@StableAPI.Expose
|
||||
Other
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user