generated from kappa-maintainer/1.12.2-FG6-Template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54aaa64
commit f131edb
Showing
4 changed files
with
22 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 20 additions & 30 deletions
50
src/main/java/com/cleanroommc/fugue/transformer/EnergyConnectorSettingsTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters