Allow exporting modified classes
This commit is contained in:
parent
938416a039
commit
7c78258bb3
|
@ -39,9 +39,9 @@ public class MixinPlugin implements IMixinConfigPlugin {
|
|||
AsmTransformer.INSTANCE.asmConfigs = new HashSet<>();
|
||||
DynamicEntry.execute(LibJf.MOD_ID + ":asm", AsmConfig.class, s -> {
|
||||
LibJf.LOGGER.info("Discovered LibJF asm plugin in " + s.modId());
|
||||
AsmTransformer.INSTANCE.asmConfigs.add(new BakedAsmConfig(s.instance()));
|
||||
AsmTransformer.INSTANCE.asmConfigs.add(new BakedAsmConfig(s.instance(), s.modId()));
|
||||
});
|
||||
|
||||
AsmTransformer.INSTANCE.init();
|
||||
mixinTransformerField.set(delegate, AsmTransformer.INSTANCE);
|
||||
} catch (NoSuchFieldException | IllegalAccessException | InstantiationException e) {
|
||||
LibJf.LOGGER.error("Could not initialize LibJF ASM", e);
|
||||
|
|
|
@ -7,4 +7,7 @@ import java.util.Set;
|
|||
public interface AsmConfig {
|
||||
Set<String> skipClasses();
|
||||
Set<Patch> getPatches();
|
||||
default boolean export() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
|
|||
import org.spongepowered.asm.mixin.transformer.ext.IExtensionRegistry;
|
||||
import org.spongepowered.asm.transformers.MixinClassWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -20,8 +24,23 @@ public class AsmTransformer implements IMixinTransformer {
|
|||
public static final MappingResolver MAPPING_RESOLVER = FabricLoader.getInstance().getMappingResolver();
|
||||
public static final String INTERMEDIARY = "intermediary";
|
||||
public IMixinTransformer delegate;
|
||||
public Set<AsmConfig> asmConfigs;
|
||||
public Set<BakedAsmConfig> asmConfigs;
|
||||
private AsmConfig currentConfig = null;
|
||||
private boolean export;
|
||||
|
||||
public void init() {
|
||||
Set<String> exportReasons = new LinkedHashSet<>();
|
||||
if (System.getProperty("libjf.asm.export") != null)
|
||||
exportReasons.add("Property: libjf.asm.export");
|
||||
for (BakedAsmConfig config : asmConfigs) {
|
||||
if (config.export())
|
||||
exportReasons.add("Mod: " + config.getSource());
|
||||
}
|
||||
export = !exportReasons.isEmpty();
|
||||
if (export) {
|
||||
LibJf.LOGGER.info("Exporting ASM due to: " + String.join(", ", exportReasons));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void audit(MixinEnvironment environment) {
|
||||
|
@ -52,10 +71,6 @@ public class AsmTransformer implements IMixinTransformer {
|
|||
ClassReader reader = new ClassReader(classBytes);
|
||||
reader.accept(klazz, ClassReader.EXPAND_FRAMES); //ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG
|
||||
|
||||
//if ((klazz.access & Opcodes.ACC_INTERFACE) != 0) {
|
||||
// return classBytes;
|
||||
//}
|
||||
|
||||
for (AsmConfig config : asmConfigs) {
|
||||
currentConfig = config;
|
||||
if (!isClassUnmoddable(name, config)) {
|
||||
|
@ -75,7 +90,18 @@ public class AsmTransformer implements IMixinTransformer {
|
|||
return null;
|
||||
}
|
||||
classBytes = writer.toByteArray();
|
||||
//MixinEnvironment.getCurrentEnvironment();
|
||||
if (export) {
|
||||
try {
|
||||
Path path = FabricLoader.getInstance().getGameDir().resolve("libjf").resolve("asm").resolve(name.replace('.', '/') + ".class");
|
||||
if (!Files.exists(path)) Files.createDirectories(path.getParent());
|
||||
Files.write(path, classBytes);
|
||||
//Path path = Path.of(FabricLoader.getInstance().getGameDir().toString(), ".meteor.asm.out", name.replace('.', '/') + ".class");
|
||||
//new File(path.toUri()).getParentFile().mkdirs();
|
||||
//Files.write(path, classBytes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return classBytes;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,13 @@ import java.util.Set;
|
|||
public class BakedAsmConfig implements AsmConfig {
|
||||
private final Set<String> skipClasses;
|
||||
private final Set<Patch> patches;
|
||||
public BakedAsmConfig(AsmConfig config) {
|
||||
private final Boolean export;
|
||||
private final String source;
|
||||
public BakedAsmConfig(AsmConfig config, String source) {
|
||||
skipClasses = config.skipClasses();
|
||||
patches = config.getPatches();
|
||||
export = config.export();
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,4 +25,13 @@ public class BakedAsmConfig implements AsmConfig {
|
|||
public Set<Patch> getPatches() {
|
||||
return patches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean export() {
|
||||
return export;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package io.gitlab.jfronny.libjf.unsafe.test;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import io.gitlab.jfronny.libjf.LibJf;
|
||||
import io.gitlab.jfronny.libjf.unsafe.asm.AsmConfig;
|
||||
import io.gitlab.jfronny.libjf.unsafe.asm.patch.Patch;
|
||||
import net.minecraft.client.main.Main;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
|
@ -42,4 +40,9 @@ public class AsmTest implements AsmConfig {
|
|||
" ##:::: ##:. ######:: ##:::: ##:::: ##:::: ########:. ######::::: ##::::\n" +
|
||||
"..:::::..:::......:::..:::::..:::::..:::::........:::......::::::..:::::");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean export() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue