generated from Legacy-Fabric/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve coremods compatibility by a lot + Clean up CCC and NEI compat
- Loading branch information
1 parent
e9b9e96
commit c1f20f7
Showing
13 changed files
with
179 additions
and
119 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/CompatUtils.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
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
93 changes: 93 additions & 0 deletions
93
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/asm/ASMRemapperTransformer.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,93 @@ | ||
package fr.catcore.fabricatedforge.compat.asm; | ||
|
||
import fr.catcore.modremapperapi.api.IClassTransformer; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ASMRemapperTransformer implements IClassTransformer, Opcodes { | ||
private final static String[] EXCLUDED = new String[]{ | ||
"fr.catcore.", | ||
"cpw.mods.fml.", | ||
"net.minecraftforge.", | ||
"org.objectweb.asm.", | ||
"net.fabricmc.", | ||
"com.llamalad7.", | ||
"org.spongepowered.", | ||
"org.lwjgl." | ||
}; | ||
|
||
private final static Map<String, String> INSTANCE_REPLACER = arrayToMap(new String[][]{ | ||
{"org/objectweb/asm/tree/FieldInsnNode", "fr/catcore/fabricatedforge/compat/asm/BetterFieldInsnNode"}, | ||
{"org/objectweb/asm/tree/MethodInsnNode", "fr/catcore/fabricatedforge/compat/asm/BetterMethodInsnNode"}, | ||
{"org/objectweb/asm/ClassWriter", "fr/catcore/fabricatedforge/compat/asm/BetterClassWriter"} | ||
}); | ||
|
||
@Override | ||
public boolean handlesClass(String s, String s1) { | ||
for (String exclude : EXCLUDED) { | ||
if (s.startsWith(exclude)) return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public byte[] transformClass(String s, String s1, byte[] bytes) { | ||
ClassNode classNode = new ClassNode(); | ||
ClassReader classReader = new ClassReader(bytes); | ||
classReader.accept(classNode, 0); | ||
|
||
boolean touched = false; | ||
|
||
for (MethodNode methodNode : classNode.methods) { | ||
AbstractInsnNode insnNode = methodNode.instructions.getFirst(); | ||
|
||
if (insnNode != null) { | ||
while (insnNode != null) { | ||
if (insnNode.getOpcode() == NEW && insnNode instanceof TypeInsnNode) { | ||
TypeInsnNode typeInsnNode = (TypeInsnNode) insnNode; | ||
|
||
if (INSTANCE_REPLACER.containsKey(typeInsnNode.desc)) { | ||
typeInsnNode.desc = INSTANCE_REPLACER.get(typeInsnNode.desc); | ||
touched = true; | ||
} | ||
} else if (insnNode.getOpcode() == INVOKESPECIAL && insnNode instanceof MethodInsnNode) { | ||
MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; | ||
|
||
if (methodInsnNode.name.equals("<init>") && INSTANCE_REPLACER.containsKey(methodInsnNode.owner)) { | ||
methodInsnNode.owner = INSTANCE_REPLACER.get(methodInsnNode.owner); | ||
touched = true; | ||
} | ||
} | ||
|
||
insnNode = insnNode.getNext(); | ||
} | ||
} | ||
} | ||
|
||
if (touched) { | ||
ClassWriter classWriter = new ClassWriter(3); | ||
classNode.accept(classWriter); | ||
|
||
bytes = classWriter.toByteArray(); | ||
System.out.println("ASMRemapper transformed: " + s); | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
private static Map<String, String> arrayToMap(String[][] arrays) { | ||
Map<String, String> map = new HashMap<>(); | ||
|
||
for (String[] array : arrays) { | ||
map.put(array[0], array[1]); | ||
} | ||
|
||
return map; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...icatedforge/compat/BetterClassWriter.java → ...edforge/compat/asm/BetterClassWriter.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
35 changes: 35 additions & 0 deletions
35
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/asm/BetterFieldInsnNode.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,35 @@ | ||
package fr.catcore.fabricatedforge.compat.asm; | ||
|
||
import fr.catcore.fabricatedforge.Constants; | ||
import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; | ||
import org.objectweb.asm.Type; | ||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.FieldInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
|
||
import java.util.Map; | ||
|
||
public class BetterFieldInsnNode extends FieldInsnNode { | ||
/** | ||
* Constructs a new {@link FieldInsnNode}. | ||
* | ||
* @param opcode the opcode of the type instruction to be constructed. This opcode must be | ||
* GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD. | ||
* @param owner the internal name of the field's owner class (see {@link | ||
* Type#getInternalName()}). | ||
* @param name the field's name. | ||
* @param descriptor the field's descriptor (see {@link Type}). | ||
*/ | ||
public BetterFieldInsnNode(int opcode, String owner, String name, String descriptor) { | ||
this(opcode, Constants.mapClass(owner), Constants.mapFieldFromRemappedClass(Constants.mapClass(owner), name, descriptor)); | ||
} | ||
|
||
private BetterFieldInsnNode(int code, String owner, MappingUtils.ClassMember classMember) { | ||
super(code, owner, classMember.name, Constants.mapTypeDescriptor(classMember.desc)); | ||
} | ||
|
||
@Override | ||
public AbstractInsnNode clone(Map<LabelNode, LabelNode> clonedLabels) { | ||
return new BetterFieldInsnNode(opcode, owner, name, desc).cloneAnnotations(this); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/asm/BetterMethodInsnNode.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,29 @@ | ||
package fr.catcore.fabricatedforge.compat.asm; | ||
|
||
import fr.catcore.fabricatedforge.Constants; | ||
import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
|
||
import java.util.Map; | ||
|
||
public class BetterMethodInsnNode extends MethodInsnNode implements Opcodes { | ||
public BetterMethodInsnNode(int opcode, String owner, String name, String descriptor) { | ||
this(opcode, owner, name, descriptor, opcode == Opcodes.INVOKEINTERFACE); | ||
} | ||
|
||
public BetterMethodInsnNode(int opcode, String owner, String name, String descriptor, boolean isInterface) { | ||
this(opcode, Constants.mapClass(owner), Constants.mapMethodFromRemappedClass(Constants.mapClass(owner), name, descriptor), isInterface); | ||
} | ||
|
||
private BetterMethodInsnNode(int opcode, String owner, MappingUtils.ClassMember member, boolean isInterface) { | ||
super(opcode, owner, member.name, Constants.mapMethodDescriptor(member.desc), isInterface); | ||
} | ||
|
||
@Override | ||
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> clonedLabels) { | ||
return new BetterMethodInsnNode(opcode, owner, name, desc, itf).cloneAnnotations(this); | ||
} | ||
} |
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
29 changes: 0 additions & 29 deletions
29
.../fr/catcore/fabricatedforge/compat/mixin/codechickencore/FeatureHackTransformerMixin.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...n/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/TweakTransformerMixin.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/nei/NEITransformerMixin.java
This file was deleted.
Oops, something went wrong.
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