use of org.objectweb.asm.tree.ClassNode in project Random-Things by lumien231.
the class ClassTransformer method patchVillageChurch.
private byte[] patchVillageChurch(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found VillagePiece Church Class: " + classNode.name);
MethodNode addComponentParts = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_74875_a"))) {
addComponentParts = mn;
}
}
if (addComponentParts != null) {
logger.log(Level.DEBUG, " - Found addComponentParts");
for (int i = 0; i < addComponentParts.instructions.size(); i++) {
AbstractInsnNode ain = addComponentParts.instructions.get(i);
if (ain instanceof InsnNode) {
InsnNode in = (InsnNode) ain;
if (in.getOpcode() == Opcodes.IRETURN) {
logger.log(Level.DEBUG, " - Patched addComponentParts");
AbstractInsnNode before = addComponentParts.instructions.get(i - 1);
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 1));
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 2));
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 3));
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 0));
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "lumien/randomthings/worldgen/WorldGenPeaceCandle", "addComponentParts", "(Lnet/minecraft/world/World;Ljava/util/Random;Lnet/minecraft/world/gen/structure/StructureBoundingBox;Lnet/minecraft/world/gen/structure/StructureVillagePieces$Church;)V", false));
i += 5;
addComponentParts.instructions.insertBefore(before, toInsert);
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.ClassNode in project BetterRain by OreCruncher.
the class Transformer method transformSoundManager.
private byte[] transformSoundManager(final byte[] classBytes) {
final String[] names;
if (TransformLoader.runtimeDeobEnabled)
names = new String[] { "func_148594_a" };
else
names = new String[] { "getNormalizedVolume" };
final String[] targetName = new String[] { "getNormalizedVolume" };
final ClassReader cr = new ClassReader(classBytes);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (final MethodNode m : cn.methods) {
if (m.name.equals(names[0])) {
logger.debug("Hooking " + names[0]);
final InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 1));
list.add(new VarInsnNode(ALOAD, 2));
list.add(new VarInsnNode(ALOAD, 3));
final String sig = "(Lnet/minecraft/client/audio/ISound;Lnet/minecraft/client/audio/SoundPoolEntry;Lnet/minecraft/client/audio/SoundCategory;)F";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/client/sound/SoundManager", targetName[0], sig, false));
list.add(new InsnNode(FRETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
break;
}
}
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
use of org.objectweb.asm.tree.ClassNode in project BetterRain by OreCruncher.
the class Transformer method transformEntityRenderer.
private byte[] transformEntityRenderer(final byte[] classBytes) {
final String[] names;
if (TransformLoader.runtimeDeobEnabled)
names = new String[] { "func_78474_d", "func_78484_h" };
else
names = new String[] { "renderRainSnow", "addRainParticles" };
final String[] targetName = new String[] { "renderRainSnow", "addRainParticles" };
final ClassReader cr = new ClassReader(classBytes);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (final MethodNode m : cn.methods) {
if (m.name.equals(names[0])) {
logger.debug("Hooking " + names[0]);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
list.add(new VarInsnNode(FLOAD, 1));
final String sig = "(Lnet/minecraft/client/renderer/EntityRenderer;F)V";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/client/RenderWeather", targetName[0], sig, false));
list.add(new InsnNode(RETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
} else if (m.name.equals(names[1])) {
logger.debug("Hooking " + names[1]);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
final String sig = "(Lnet/minecraft/client/renderer/EntityRenderer;)V";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/client/RenderWeather", targetName[1], sig, false));
list.add(new InsnNode(RETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
}
}
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
use of org.objectweb.asm.tree.ClassNode in project BetterRain by OreCruncher.
the class Transformer method transformWorld.
private byte[] transformWorld(final byte[] classBytes) {
final String[] names;
if (TransformLoader.runtimeDeobEnabled)
names = new String[] { "updateWeatherBody" };
else
names = new String[] { "updateWeatherBody" };
final String[] targetName = new String[] { "updateWeatherBody" };
final ClassReader cr = new ClassReader(classBytes);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (final MethodNode m : cn.methods) {
if (m.name.equals(names[0])) {
logger.debug("Hooking " + names[0]);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
final String sig = "(Lnet/minecraft/world/World;)V";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/server/WorldHandler", targetName[0], sig, false));
list.add(new InsnNode(RETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
break;
}
}
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
use of org.objectweb.asm.tree.ClassNode in project BetterRain by OreCruncher.
the class Transformer method transformWorldServer.
private byte[] transformWorldServer(final byte[] classBytes) {
final String[] names;
if (TransformLoader.runtimeDeobEnabled)
names = new String[] { "func_73051_P" };
else
names = new String[] { "resetRainAndThunder" };
final String[] targetName = new String[] { "resetRainAndThunder" };
final ClassReader cr = new ClassReader(classBytes);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (final MethodNode m : cn.methods) {
if (m.name.equals(names[0])) {
logger.debug("Hooking " + names[0]);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
final String sig = "(Lnet/minecraft/world/WorldServer;)V";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/server/PlayerSleepHandler", targetName[0], sig, false));
list.add(new InsnNode(RETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
break;
}
}
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
Aggregations