Skip to content

Commit

Permalink
Dump ways to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Jun 3, 2024
1 parent 54aaa64 commit f131edb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mappings_version=39-1.12
mod_id=fugue
mod_name=Fugue
mod_main_class=Fugue
mod_version=0.14.12
mod_version=0.15.0-alpha
mod_base_package=com.cleanroommc.fugue
mod_authors=kappa_maintainer
mod_description=A mod that patch dead mods for Cleanroom
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
package com.cleanroommc.fugue.transformer;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import com.cleanroommc.fugue.common.Fugue;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;
import top.outlands.foundation.IExplicitTransformer;

import java.io.ByteArrayInputStream;

public class EnergyConnectorSettingsTransformer implements IExplicitTransformer {
@Override
public byte[] transform(byte[] bytes) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
if (classNode.methods != null)
{
for (MethodNode methodNode : classNode.methods)
{
if (methodNode.name.equals("<clinit>")) {
InsnList instructions = methodNode.instructions;
if (instructions != null)
{
for (AbstractInsnNode insnNode : instructions)
{
if (insnNode.getOpcode() == Opcodes.INVOKESTATIC && insnNode instanceof MethodInsnNode methodInsnNode)
{
if (methodInsnNode.owner.equals("com/google/common/collect/ImmutableSet") && (methodInsnNode.name.equals("of")))
{
methodInsnNode.itf = true;
}
}
}
try {
CtClass cc = ClassPool.getDefault().makeClass(new ByteArrayInputStream(bytes));
cc.getClassInitializer().instrument(new ExprEditor(){
@Override
public void edit(MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals("of")) {
m.replace("$_ = $proceed($$);");
}
}
}
});
bytes = cc.toBytecode();
} catch (Throwable t) {
Fugue.LOGGER.error(t);
}
ClassWriter classWriter = new ClassWriter(0);

classNode.accept(classWriter);
return classWriter.toByteArray();
return bytes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ public byte[] transform(byte[] bytes) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
for (AnnotationNode anno : classNode.visibleAnnotations) {
if (anno.desc.equals("Lnet/minecraftforge/fml/relauncher/IFMLLoadingPlugin$TransformerExclusions;")) {
classNode.visibleAnnotations.remove(anno);
}
}
classNode.visibleAnnotations.removeIf(anno -> anno.desc.equals("Lnet/minecraftforge/fml/relauncher/IFMLLoadingPlugin$TransformerExclusions;"));
ClassWriter classWriter = new ClassWriter(0);

classNode.accept(classWriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public byte[] transform(byte[] bytes) {
cc.getClassInitializer().instrument(new ExprEditor(){
@Override
public void edit(NewArray a) throws CannotCompileException {
Foundation.LOGGER.info(a.getLineNumber());
if (a.getLineNumber() == 48) {
a.where().setBody(
"""
Expand Down

0 comments on commit f131edb

Please sign in to comment.