generated from kappa-maintainer/1.12.2-FG6-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
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
e3539e6
commit 45e36f7
Showing
5 changed files
with
67 additions
and
6 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
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
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
62 changes: 62 additions & 0 deletions
62
src/main/java/com/cleanroommc/transformer/ClassTransformerTransformer.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.cleanroommc.transformer; | ||
|
||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.*; | ||
|
||
public class ClassTransformerTransformer implements IClassTransformer { | ||
private static boolean hit = false; | ||
@Override | ||
public byte[] transform(String s, String s1, byte[] bytes) { | ||
if (bytes == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (hit || !s1.equals("zmaster587.advancedRocketry.asm.ClassTransformer")) | ||
{ | ||
return bytes; | ||
} | ||
|
||
|
||
ClassNode classNode = new ClassNode(); | ||
ClassReader classReader = new ClassReader(bytes); | ||
classReader.accept(classNode, 0); | ||
boolean modified = false; | ||
AbstractInsnNode prevLine = null; | ||
if (classNode.methods != null) | ||
{ | ||
for (MethodNode methodNode : classNode.methods) | ||
{ | ||
if (methodNode.name.equals("transform")) { | ||
InsnList instructions = methodNode.instructions; | ||
if (instructions != null) | ||
{ | ||
for (AbstractInsnNode insnNode : instructions) | ||
{ | ||
if (insnNode instanceof LineNumberNode lineNumberNode) | ||
{ | ||
if (lineNumberNode.line == 693) { | ||
instructions.remove(instructions.get(instructions.indexOf(lineNumberNode) + 1)); | ||
instructions.insert(lineNumberNode, new InsnNode(Opcodes.ICONST_0)); | ||
modified = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (modified) | ||
{ | ||
hit = true; | ||
ClassWriter classWriter = new ClassWriter(0); | ||
|
||
classNode.accept(classWriter); | ||
return classWriter.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
} |