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.
Merge remote-tracking branch 'origin/1.3.2-forge' into 1.4-forge
# Conflicts: # gradle.properties # mod-compat/src/main/resources/fabric.mod.json # mod-compat/src/main/resources/fabricated-forge.mods.mixins.json # src/main/java/cpw/mods/fml/relauncher/RelaunchClassLoader.java # src/main/resources/fabric.mod.json
- Loading branch information
Showing
10 changed files
with
134 additions
and
16 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
39 changes: 39 additions & 0 deletions
39
mod-compat/src/main/java/fr/catcore/fabricatedforge/compat/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fr.catcore.fabricatedforge.compat; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
|
||
public class BetterClassWriter extends ClassWriter { | ||
public BetterClassWriter(int flags) { | ||
super(flags); | ||
} | ||
|
||
public BetterClassWriter(ClassReader classReader, int flags) { | ||
super(classReader, flags); | ||
} | ||
|
||
@Override | ||
protected String getCommonSuperClass(String type1, String type2) { | ||
try { | ||
return super.getCommonSuperClass(type1, type2); | ||
} catch (TypeNotPresentException e) { | ||
if ("net/minecraft/class_1071".equals(type1) && "net/minecraft/class_987".equals(type2)) { | ||
return "java/lang/Object"; | ||
} | ||
|
||
if ("net/minecraft/class_987".equals(type1) && "java/lang/Object".equals(type2)) { | ||
return type2; | ||
} | ||
|
||
System.out.println("Common of: " + type1 + " " + type2); | ||
e.printStackTrace(); | ||
return "java/lang/Object"; | ||
} | ||
} | ||
|
||
@Override | ||
protected ClassLoader getClassLoader() { | ||
return FabricLoader.getInstance().getClass().getClassLoader(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.catcore.fabricatedforge.compat; | ||
|
||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
public class CompatUtils { | ||
public static ClassNode createNode(byte[] bytes, int parsingOptions) { | ||
ClassNode node = new ClassNode(Opcodes.ASM4); | ||
ClassReader reader = new ClassReader(bytes); | ||
reader.accept(node, parsingOptions); | ||
|
||
return node; | ||
} | ||
|
||
public static byte[] writeClass(ClassNode node, int flags) { | ||
BetterClassWriter classWriter = new BetterClassWriter(flags); | ||
node.accept(classWriter); | ||
|
||
return classWriter.toByteArray(); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...compat/src/main/java/fr/catcore/fabricatedforge/compat/mixin/nei/NEITransformerMixin.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,52 @@ | ||
package fr.catcore.fabricatedforge.compat.mixin.nei; | ||
|
||
import codechicken.core.asm.ClassHeirachyManager; | ||
import codechicken.core.asm.InstructionComparator; | ||
import codechicken.core.asm.ObfuscationManager; | ||
import codechicken.nei.asm.NEITransformer; | ||
import fr.catcore.fabricatedforge.compat.CompatUtils; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
|
||
@Mixin(NEITransformer.class) | ||
public class NEITransformerMixin { | ||
/** | ||
* @author CatCore | ||
* @reason fix classwriter | ||
*/ | ||
@Overwrite(remap = false) | ||
public byte[] transformer001(String name, byte[] bytes) { | ||
ObfuscationManager.ClassMapping classmap = new ObfuscationManager.ClassMapping("aqh"); | ||
|
||
if (ClassHeirachyManager.classExtends(name, classmap.classname, bytes)) { | ||
ClassNode node = CompatUtils.createNode(bytes, 0); | ||
|
||
ObfuscationManager.MethodMapping methodmap = new ObfuscationManager.MethodMapping("apn", "c", "()V"); | ||
ObfuscationManager.MethodMapping supermap = new ObfuscationManager.MethodMapping(node.superName, methodmap); | ||
InsnList supercall = new InsnList(); | ||
supercall.add(new VarInsnNode(25, 0)); | ||
supercall.add(supermap.toInsn(183)); | ||
|
||
for(MethodNode methodnode : node.methods) { | ||
if (methodmap.matches(methodnode)) { | ||
InsnList importantNodeList = InstructionComparator.getImportantList(methodnode.instructions); | ||
|
||
if (!InstructionComparator.insnListMatches(importantNodeList, supercall, 0)) { | ||
methodnode.instructions.insertBefore(methodnode.instructions.getFirst(), supercall); | ||
System.out.println("Inserted super call into " + name + "." + supermap.name); | ||
} | ||
} | ||
} | ||
|
||
bytes = CompatUtils.writeClass(node, 3); | ||
} | ||
|
||
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
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