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.
- Loading branch information
1 parent
ba9b122
commit ae73bc2
Showing
6 changed files
with
391 additions
and
99 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
58 changes: 51 additions & 7 deletions
58
.../fr/catcore/fabricatedforge/compat/mixin/codechickencore/FeatureHackTransformerMixin.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,18 +1,62 @@ | ||
package fr.catcore.fabricatedforge.compat.mixin.codechickencore; | ||
|
||
import codechicken.core.asm.ASMHelper; | ||
import codechicken.core.asm.FeatureHackTransformer; | ||
import codechicken.core.asm.InstructionComparator; | ||
import codechicken.core.asm.ObfuscationMappings; | ||
import org.objectweb.asm.tree.*; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(FeatureHackTransformer.class) | ||
public class FeatureHackTransformerMixin { | ||
@ModifyArg(method = "<init>", index = 2, | ||
remap = false, | ||
at = @At(value = "INVOKE", | ||
remap = false, | ||
target = "Lcodechicken/core/asm/ObfuscationMappings$DescriptorMapping;<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0)) | ||
private String fixMethodArg(String arg) { | ||
return "(Lnet/minecraft/class_1069;)V"; | ||
@Shadow(remap = false) | ||
ObfuscationMappings.DescriptorMapping f_lastBrightness; | ||
|
||
/** | ||
* @author CatCore | ||
* @reason fix mappings | ||
*/ | ||
@Overwrite(remap = false) | ||
private byte[] transformer002(String name, byte[] bytes) { | ||
ClassNode cnode = ASMHelper.createClassNode(bytes); | ||
FieldNode fnode = ASMHelper.findField(this.f_lastBrightness, cnode); | ||
if (fnode == null) { | ||
cnode.fields.add(new FieldNode(9, this.f_lastBrightness.s_name, this.f_lastBrightness.s_desc, null, null)); | ||
MethodNode mlightmap = ASMHelper.findMethod(new ObfuscationMappings.DescriptorMapping("bfe", "a", "(IFF)V"), cnode); | ||
InsnList hook = new InsnList(); | ||
LabelNode lend = new LabelNode(); | ||
hook.add(new VarInsnNode(21, 0)); | ||
hook.add(new ObfuscationMappings.DescriptorMapping("bfe", "b", "I").toFieldInsn(178)); | ||
hook.add(new JumpInsnNode(160, lend)); | ||
hook.add(new VarInsnNode(23, 2)); | ||
hook.add(new InsnNode(139)); | ||
hook.add(new IntInsnNode(16, 16)); | ||
hook.add(new InsnNode(120)); | ||
hook.add(new VarInsnNode(23, 1)); | ||
hook.add(new InsnNode(139)); | ||
hook.add(new InsnNode(128)); | ||
hook.add(this.f_lastBrightness.toFieldInsn(179)); | ||
hook.add(lend); | ||
InsnList needle = new InsnList(); | ||
needle.add(new InsnNode(177)); | ||
List ret = InstructionComparator.insnListFindEnd(mlightmap.instructions, needle); | ||
if (ret.size() != 1) { | ||
throw new RuntimeException( | ||
"Needle not found in Haystack: " + ASMHelper.printInsnList(mlightmap.instructions) + "\n" + ASMHelper.printInsnList(needle) | ||
); | ||
} | ||
|
||
mlightmap.instructions.insertBefore((AbstractInsnNode)ret.get(0), hook); | ||
bytes = ASMHelper.createBytes(cnode, 3); | ||
System.out.println("Brightness hook injected"); | ||
} | ||
|
||
return bytes; | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
...n/java/fr/catcore/fabricatedforge/compat/mixin/codechickencore/TweakTransformerMixin.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,163 @@ | ||
package fr.catcore.fabricatedforge.compat.mixin.codechickencore; | ||
|
||
import codechicken.core.asm.*; | ||
import codechicken.core.config.ConfigFile; | ||
import codechicken.core.config.ConfigTag; | ||
import org.objectweb.asm.tree.*; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
@Mixin(TweakTransformer.class) | ||
public abstract class TweakTransformerMixin { | ||
|
||
@Shadow(remap = false) public static ConfigTag tweaks; | ||
|
||
@Shadow(remap = false) | ||
private static void alterMethod(ASMHelper.MethodAltercator ma) { | ||
} | ||
|
||
/** | ||
* @author CatCore | ||
* @reason fix mappings | ||
*/ | ||
@Overwrite(remap = false) | ||
public static void load() { | ||
File cfgDir = new File(CodeChickenCorePlugin.minecraftDir + "/config"); | ||
if (!cfgDir.exists()) { | ||
cfgDir.mkdirs(); | ||
} | ||
|
||
ConfigFile config = new ConfigFile(new File(cfgDir, "CodeChickenCore.cfg")).setComment("CodeChickenCore configuration file."); | ||
tweaks = config.getTag("tweaks").setComment("Various tweaks that can be applied to game mechanics.").useBraces(); | ||
if (!tweaks.getTag("persistantLava") | ||
.setComment("Set to false to make lava fade away like water if all the source blocks are destroyed") | ||
.getBooleanValue(true)) { | ||
ObfuscationMappings.ClassMapping blockFlowing = new ObfuscationMappings.ClassMapping("aky"); | ||
alterMethod( | ||
new ASMHelper.MethodAltercator(new ObfuscationMappings.DescriptorMapping(blockFlowing.s_class, new ObfuscationMappings.DescriptorMapping("amq", "b", "(Lyc;IIILjava/util/Random;)V"))) { | ||
public void alter(MethodNode mv) { | ||
InsnList needle = new InsnList(); | ||
needle.add(new VarInsnNode(21, 6)); | ||
needle.add(new VarInsnNode(54, -1)); | ||
needle.add(new InsnNode(3)); | ||
needle.add(new VarInsnNode(54, 8)); | ||
List lists = InstructionComparator.insnListFindL(mv.instructions, needle); | ||
if (lists.size() != 1) { | ||
throw new RuntimeException( | ||
"Needle found " + lists.size() + " times in Haystack: " + mv.instructions + "\n" + ASMHelper.printInsnList(needle) | ||
); | ||
} else { | ||
InstructionComparator.InsnListSection subsection = (InstructionComparator.InsnListSection)lists.get(0); | ||
AbstractInsnNode insn = subsection.first; | ||
|
||
while(true) { | ||
AbstractInsnNode next = insn.getNext(); | ||
mv.instructions.remove(insn); | ||
if (insn == subsection.last) { | ||
return; | ||
} | ||
|
||
insn = next; | ||
} | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
if (tweaks.getTag("environmentallyFriendlyCreepers") | ||
.setComment("If set to true, creepers will not destroy landscape. (A version of mobGreifing setting just for creepers)") | ||
.getBooleanValue(false)) { | ||
final ObfuscationMappings.ClassMapping entityCreeper = new ObfuscationMappings.ClassMapping("qc"); | ||
alterMethod( | ||
new ASMHelper.MethodAltercator(new ObfuscationMappings.DescriptorMapping(entityCreeper.s_class, new ObfuscationMappings.DescriptorMapping("lq", "j_", "()V"))) { | ||
public void alter(MethodNode mv) { | ||
InsnList needle = new InsnList(); | ||
needle.add(new VarInsnNode(25, 0)); | ||
needle.add(new ObfuscationMappings.DescriptorMapping(entityCreeper.s_class, new ObfuscationMappings.DescriptorMapping("lq", "p", "Lyc;")).toFieldInsn(180)); | ||
needle.add(new ObfuscationMappings.DescriptorMapping("yc", "L", "()Lxz;").toInsn(182)); | ||
needle.add(new LdcInsnNode("mobGriefing")); | ||
needle.add(new ObfuscationMappings.DescriptorMapping("xz", "b", "(Ljava/lang/String;)Z").toInsn(182)); | ||
List lists = InstructionComparator.insnListFindL(mv.instructions, needle); | ||
if (lists.size() != 1) { | ||
throw new RuntimeException( | ||
"Needle found " + lists.size() + " times in Haystack: " + mv.instructions + "\n" + ASMHelper.printInsnList(needle) | ||
); | ||
} else { | ||
InstructionComparator.InsnListSection subsection = (InstructionComparator.InsnListSection)lists.get(0); | ||
mv.instructions.insertBefore(subsection.first, new InsnNode(3)); | ||
AbstractInsnNode insn = subsection.first; | ||
|
||
while(true) { | ||
AbstractInsnNode next = insn.getNext(); | ||
mv.instructions.remove(insn); | ||
if (insn == subsection.last) { | ||
return; | ||
} | ||
|
||
insn = next; | ||
} | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
if (!tweaks.getTag("softLeafReplace").setComment("If set to false, leaves will only replace air when growing").getBooleanValue(false)) { | ||
alterMethod(new ASMHelper.MethodAltercator(new ObfuscationMappings.DescriptorMapping("amq", "canBeReplacedByLeaves", "(Lyc;III)Z")) { | ||
public void alter(MethodNode mv) { | ||
InsnList replacement = new InsnList(); | ||
replacement.add(new VarInsnNode(25, 0)); | ||
replacement.add(new VarInsnNode(25, 1)); | ||
replacement.add(new VarInsnNode(21, 2)); | ||
replacement.add(new VarInsnNode(21, 3)); | ||
replacement.add(new VarInsnNode(21, 4)); | ||
replacement.add(new ObfuscationMappings.DescriptorMapping("amq", "isAirBlock", "(Lyc;III)Z").toInsn(182)); | ||
replacement.add(new InsnNode(172)); | ||
mv.instructions = replacement; | ||
} | ||
}); | ||
} | ||
|
||
if (tweaks.getTag("doFireTickOut") | ||
.setComment("If set to true and doFireTick is disabed in the game rules, fire will still dissipate if it's not over a fire source") | ||
.getBooleanValue(true)) { | ||
alterMethod( | ||
new ASMHelper.MethodAltercator(new ObfuscationMappings.DescriptorMapping("akf", "b", "(Lyc;IIILjava/util/Random;)V")) { | ||
public void alter(MethodNode mv) { | ||
InsnList needle = new InsnList(); | ||
needle.add(new LdcInsnNode("doFireTick")); | ||
needle.add(new ObfuscationMappings.DescriptorMapping("xz", "b", "(Ljava/lang/String;)Z").toInsn(182)); | ||
needle.add(new JumpInsnNode(153, new LabelNode())); | ||
List lists = InstructionComparator.insnListFindL(mv.instructions, needle); | ||
if (lists.size() != 1) { | ||
throw new RuntimeException( | ||
"Needle found " + lists.size() + " times in Haystack: " + mv.instructions + "\n" + ASMHelper.printInsnList(needle) | ||
); | ||
} else { | ||
InstructionComparator.InsnListSection subsection = (InstructionComparator.InsnListSection)lists.get(0); | ||
LabelNode jlabel = ((JumpInsnNode)subsection.last).label; | ||
LabelNode ret = new LabelNode(); | ||
mv.instructions.insertBefore(jlabel, new JumpInsnNode(167, ret)); | ||
InsnList inject = new InsnList(); | ||
inject.add(new VarInsnNode(25, 1)); | ||
inject.add(new VarInsnNode(21, 2)); | ||
inject.add(new VarInsnNode(21, 3)); | ||
inject.add(new VarInsnNode(21, 4)); | ||
inject.add(new VarInsnNode(25, 5)); | ||
inject.add( | ||
new ObfuscationMappings.DescriptorMapping("codechicken/core/featurehack/TweakTransformerHelper", "quenchFireTick", "(Lyc;IIILjava/util/Random;)V").toInsn(184) | ||
); | ||
inject.add(ret); | ||
mv.instructions.insert(jlabel, inject); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.