mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-16 23:25:12 +00:00
Turbo ASM
This commit is contained in:
17 files changed
+1093
-123
No files matched your search
@@ -26,14 +26,24 @@ import com.falsepattern.lib.internal.FPLog;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.internal.impl.dependencies.DependencyLoaderImpl;
|
||||
import com.falsepattern.lib.mapping.MappingManager;
|
||||
import com.falsepattern.lib.turboasm.MergeableTurboTransformer;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.Name;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.falsepattern.lib.mixin.MixinInfo.isClassPresentSafe;
|
||||
@@ -44,7 +54,7 @@ import static com.falsepattern.lib.mixin.MixinInfo.isClassPresentSafe;
|
||||
@MCVersion("1.7.10")
|
||||
@Name(Tags.MODID)
|
||||
@SortingIndex(500)
|
||||
@IFMLLoadingPlugin.TransformerExclusions({Tags.GROUPNAME + ".internal.asm", Tags.GROUPNAME + ".asm"})
|
||||
@IFMLLoadingPlugin.TransformerExclusions({Tags.GROUPNAME + ".internal.asm", Tags.GROUPNAME + ".asm", Tags.GROUPNAME + ".turboasm"})
|
||||
public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
@Getter
|
||||
private static boolean obfuscated;
|
||||
@@ -117,25 +127,6 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
return skillIssue;
|
||||
}
|
||||
|
||||
public static void validateGasStation() {
|
||||
FPLog.LOG.info("Got any gas?");
|
||||
//Make sure everything is loaded correctly, crash if gasstation is bugged
|
||||
// @formatter:off
|
||||
if (!isClassPresentSafe("com.falsepattern.gasstation.core.GasStationCore") //Validate core class
|
||||
|| !isClassPresentSafe("makamys.mixingasm.api.TransformerInclusions") //Validate the mixingasm compat
|
||||
|| !isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore") //Validate the spongemixins compat
|
||||
|| !isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin") //Validate the MBL compat
|
||||
|| !isClassPresentSafe("org.spongepowered.asm.lib.Opcodes") //Validate correct mixins class
|
||||
|| isClassPresentSafe("org.spongepowered.libraries.org.objectweb.asm.Opcodes")
|
||||
) {
|
||||
FPLog.LOG.fatal("Somebody put diesel in my gas tank!");
|
||||
throw new Error("Failed to validate your GasStation mixin plugin installation. "
|
||||
+ "Please make sure you have the latest GasStation installed from the official source: "
|
||||
+ "https://github.com/FalsePattern/GasStation");
|
||||
}
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return new String[]{Tags.GROUPNAME + ".internal.asm.FPTransformer"};
|
||||
@@ -154,10 +145,32 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
obfuscated = (Boolean) data.get("runtimeDeobfuscationEnabled");
|
||||
mergeTurboTransformers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static synchronized void mergeTurboTransformers() {
|
||||
val f = LaunchClassLoader.class.getDeclaredField("transformers");
|
||||
f.setAccessible(true);
|
||||
|
||||
val transformers = (List<IClassTransformer>) f.get(Launch.classLoader);
|
||||
for (int i = 0; i < transformers.size() - 1; i++) {
|
||||
val a = transformers.get(i);
|
||||
if (!(a instanceof MergeableTurboTransformer))
|
||||
continue;
|
||||
|
||||
val b = transformers.get(i + 1);
|
||||
if (!(b instanceof MergeableTurboTransformer))
|
||||
continue;
|
||||
|
||||
transformers.remove(i + 1);
|
||||
transformers.set(i, MergeableTurboTransformer.merge((MergeableTurboTransformer) a, (MergeableTurboTransformer) b));
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,41 +24,25 @@
|
||||
package com.falsepattern.lib.internal.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.asm.SmartTransformer;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.internal.asm.transformers.ConfigOrderTransformer;
|
||||
import com.falsepattern.lib.internal.asm.transformers.GasStationValidatorTransformer;
|
||||
import com.falsepattern.lib.internal.asm.transformers.IMixinPluginTransformer;
|
||||
import com.falsepattern.lib.internal.asm.transformers.ITypeDiscovererTransformer;
|
||||
import com.falsepattern.lib.internal.asm.transformers.MixinPluginTransformer;
|
||||
import com.falsepattern.lib.internal.asm.transformers.TypeDiscovererModuleInfoSilencer;
|
||||
import com.falsepattern.lib.internal.impl.optifine.OptiFineTransformerHooksImpl;
|
||||
import lombok.Getter;
|
||||
import com.falsepattern.lib.turboasm.MergeableTurboTransformer;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Accessors(fluent = true)
|
||||
@StableAPI(since = "__INTERNAL__")
|
||||
public class FPTransformer implements SmartTransformer {
|
||||
public static final Logger LOG = LogManager.getLogger(Tags.MODNAME + " ASM");
|
||||
|
||||
@Getter
|
||||
private final List<IClassNodeTransformer> transformers;
|
||||
|
||||
@Getter
|
||||
private final Logger logger = LOG;
|
||||
|
||||
public class FPTransformer extends MergeableTurboTransformer {
|
||||
static {
|
||||
OptiFineTransformerHooksImpl.init();
|
||||
}
|
||||
|
||||
public FPTransformer() {
|
||||
transformers = Arrays.asList(new IMixinPluginTransformer(),
|
||||
new ITypeDiscovererTransformer(),
|
||||
new GasStationValidatorTransformer(),
|
||||
new ConfigOrderTransformer());
|
||||
super(Arrays.asList(new MixinPluginTransformer(),
|
||||
new TypeDiscovererModuleInfoSilencer(),
|
||||
new ConfigOrderTransformer()));
|
||||
}
|
||||
}
|
||||
+19
-6
@@ -23,26 +23,36 @@
|
||||
|
||||
package com.falsepattern.lib.internal.asm.transformers;
|
||||
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.config.Config;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.internal.impl.config.DeclOrderInternal;
|
||||
import com.falsepattern.lib.turboasm.ClassNodeHandle;
|
||||
import com.falsepattern.lib.turboasm.TurboClassTransformer;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
public class ConfigOrderTransformer implements IClassNodeTransformer {
|
||||
public class ConfigOrderTransformer implements TurboClassTransformer {
|
||||
private static final String DESC_CONFIG = Type.getDescriptor(Config.class);
|
||||
private static final String DESC_CONFIG_IGNORE = Type.getDescriptor(Config.Ignore.class);
|
||||
private static final String DESC_ORDER = Type.getDescriptor(DeclOrderInternal.class);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return "ConfigOrderTransformer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
public String owner() {
|
||||
return Tags.MODNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTransformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
|
||||
val cn = classNode.getNode();
|
||||
if (cn == null)
|
||||
return false;
|
||||
if (cn.visibleAnnotations != null) {
|
||||
for (val ann : cn.visibleAnnotations) {
|
||||
if (DESC_CONFIG.equals(ann.desc)) {
|
||||
@@ -54,7 +64,10 @@ public class ConfigOrderTransformer implements IClassNodeTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
public void transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
|
||||
val cn = classNode.getNode();
|
||||
if (cn == null)
|
||||
return;
|
||||
int order = 0;
|
||||
outer:
|
||||
for (val field : cn.fields) {
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is part of FalsePatternLib.
|
||||
*
|
||||
* Copyright (C) 2022-2024 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* FalsePatternLib is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* FalsePatternLib is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.falsepattern.lib.internal.asm.transformers;
|
||||
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
public class GasStationValidatorTransformer implements IClassNodeTransformer {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GasStationValidatorTransformer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
if (transformedName.equals("com.falsepattern.gasstation.GasStation")) {
|
||||
CoreLoadingPlugin.validateGasStation();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
|
||||
}
|
||||
}
|
||||
+33
-15
@@ -23,17 +23,19 @@
|
||||
|
||||
package com.falsepattern.lib.internal.asm.transformers;
|
||||
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.internal.asm.FPTransformer;
|
||||
import com.falsepattern.lib.turboasm.ClassNodeHandle;
|
||||
import com.falsepattern.lib.turboasm.TurboClassTransformer;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
public class MixinPluginTransformer implements TurboClassTransformer {
|
||||
private static final String IMIXINPLUGIN = Tags.GROUPNAME + ".mixin.IMixinPlugin";
|
||||
private static final String IMIXINPLUGIN_INTERNAL = IMIXINPLUGIN.replace('.', '/');
|
||||
private static final String IMIXINCONFIGPLUGIN = "org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin";
|
||||
@@ -57,25 +59,42 @@ public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "IMixinPluginTransformer";
|
||||
public String owner() {
|
||||
return Tags.MODNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
return IMIXINPLUGIN.equals(transformedName)
|
||||
|| IMIXINCONFIGPLUGIN.equals(transformedName)
|
||||
|| cn.interfaces.stream()
|
||||
.anyMatch((i) -> IMIXINPLUGIN_INTERNAL.equals(i)
|
||||
|| IMIXINCONFIGPLUGIN_INTERNAL.equals(i));
|
||||
public String name() {
|
||||
return "MixinPluginTransformer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
if (IMIXINCONFIGPLUGIN.equals(transformedName)) {
|
||||
public boolean shouldTransformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
|
||||
if (IMIXINPLUGIN.equals(className) ||
|
||||
IMIXINCONFIGPLUGIN.equals(className))
|
||||
return true;
|
||||
if (classNode.isOriginal()) {
|
||||
val meta = classNode.getOriginalMetadata();
|
||||
if (meta != null && meta.interfacesCount == 0)
|
||||
return false;
|
||||
}
|
||||
val cn = classNode.getNode();
|
||||
if (cn == null)
|
||||
return false;
|
||||
return cn.interfaces.stream()
|
||||
.anyMatch((i) -> IMIXINPLUGIN_INTERNAL.equals(i) ||
|
||||
IMIXINCONFIGPLUGIN_INTERNAL.equals(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
|
||||
val cn = classNode.getNode();
|
||||
if (cn == null)
|
||||
return;
|
||||
if (IMIXINCONFIGPLUGIN.equals(className)) {
|
||||
extractMixinConfigPluginData(cn);
|
||||
} else {
|
||||
transformPlugin(cn, transformedName);
|
||||
transformPlugin(cn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,8 +120,7 @@ public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
private static void transformPlugin(ClassNode cn, String transformedName) {
|
||||
FPTransformer.LOG.info("Transforming " + transformedName + " to fit current mixin environment.");
|
||||
private static void transformPlugin(ClassNode cn) {
|
||||
if (PREAPPLY_DESC == null) {
|
||||
PREAPPLY_DESC = extractMethodWithReflection("preApply");
|
||||
}
|
||||
+18
-7
@@ -23,24 +23,35 @@
|
||||
|
||||
package com.falsepattern.lib.internal.asm.transformers;
|
||||
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.turboasm.ClassNodeHandle;
|
||||
import com.falsepattern.lib.turboasm.TurboClassTransformer;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
|
||||
public class ITypeDiscovererTransformer implements IClassNodeTransformer {
|
||||
public class TypeDiscovererModuleInfoSilencer implements TurboClassTransformer {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ITypeDiscovererTransformer";
|
||||
public String owner() {
|
||||
return "FalsePatternLib";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
return "cpw.mods.fml.common.discovery.ITypeDiscoverer".equals(transformedName);
|
||||
public String name() {
|
||||
return "TypeDiscovererModuleInfoSilencer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
public boolean shouldTransformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
|
||||
return "cpw.mods.fml.common.discovery.ITypeDiscoverer".equals(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
|
||||
val cn = classNode.getNode();
|
||||
if (cn == null)
|
||||
return;
|
||||
for (val method : cn.methods) {
|
||||
if (!method.name.equals("<clinit>")) {
|
||||
continue;
|
||||
Reference in new issue
Block a user