Skip to content

Commit

Permalink
Another sledgehammer (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 authored Dec 20, 2021
1 parent 93d56c3 commit ed853bf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mitchej123.hodgepodge.asm;

import com.mitchej123.hodgepodge.Hodgepodge;
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.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodNode;

import static org.objectweb.asm.Opcodes.ASM5;

public class BibliocraftTransformer implements IClassTransformer {
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if ("jds.bibliocraft.blocks.BlockLoader".equals(transformedName) ||
"jds.bibliocraft.items.ItemLoader".equals(transformedName)) {
Hodgepodge.log.info("Patching Bibliocraft {}", transformedName);
final ClassReader cr = new ClassReader(basicClass);
final ClassWriter cw = new ClassWriter(0);

final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (MethodNode m : cn.methods) {
if ("addRecipies".equals(m.name)) {
Hodgepodge.log.info("Taking a sledgehammer to {}.addRecipies()", transformedName);
//Replace the body with a RETURN opcode
InsnList insnList = new InsnList();
insnList.add(new InsnNode(Opcodes.RETURN));
m.instructions = insnList;
m.localVariables.clear();
m.maxStack = 0;
m.maxLocals = 0;
}
}
cn.accept(cw);
return cw.toByteArray();
}
else {
return basicClass;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public enum AsmTransformers {
THERMOS_SLEDGEHAMMER_FURNACE_FIX("Take a sledgehammer to CraftServer.resetRecipes() to prevent it from breaking our Furnace Fix",
()-> Hodgepodge.thermosTainted && Hodgepodge.config.speedupVanillaFurnace,
Collections.singletonList("com.mitchej123.hodgepodge.asm.ThermosFurnaceSledgeHammer")
)
),
BIBLIOCRAFT_RECIPE_SLEDGEHAMMER("Remove recipes from Bibliocraft BlockLoader and Itemloader : addRecipies()", () -> Hodgepodge.config.biblocraftRecipes,
Collections.singletonList("com.mitchej123.hodgepodge.asm.BibliocraftTransformer"))
;

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public class LoadingConfig {
public boolean speedupProgressBar;
public boolean fixUrlDetection;
public boolean speedupVanillaFurnace;

// ASM
public boolean pollutionAsm;
public boolean cofhWorldTransformer;
public boolean enableTileRendererProfiler;

public boolean biblocraftRecipes;

public String thermosCraftServerClass;


Expand Down Expand Up @@ -96,7 +98,8 @@ public LoadingConfig(File file) {
speedupProgressBar = config.get("asm", "speedupProgressBar", true, "Speedup progressbar").getBoolean();
pollutionAsm = config.get("asm", "pollutionAsm", true, "Enable pollution rendering ASM").getBoolean();
cofhWorldTransformer = config.get("asm", "cofhWorldTransformer", true, "Enable Glease's ASM patch to disable unused CoFH tileentity cache").getBoolean();

biblocraftRecipes = config.get("asm", "biblocraftRecipes", true, "Remove recipe generation from BiblioCraft").getBoolean();

thermosCraftServerClass = config.get("asm", "thermosCraftServerClass", "org.bukkit.craftbukkit.v1_7_R4.CraftServer", "If using Bukkit/Thermos, the CraftServer package.").getString();

if (config.hasChanged())
Expand Down

0 comments on commit ed853bf

Please sign in to comment.