use of com.builtbroken.mc.lib.asm.ObfMapping in project Engine by VoltzEngine-Project.
the class ChunkTransformer method transform.
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (transformedName.equals("net.minecraft.world.chunk.Chunk")) {
EngineCoreMod.logger.info("Transforming Chunk class for chunkModified event.");
ClassNode cnode = ASMHelper.createClassNode(bytes);
for (MethodNode method : cnode.methods) {
ObfMapping m = new ObfMapping(cnode.name, method.name, method.desc).toRuntime();
if (m.s_name.equals("func_150807_a")) {
EngineCoreMod.logger.info("[Voltz-Engine] Found method " + m.s_name);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
list.add(new VarInsnNode(ILOAD, 1));
list.add(new VarInsnNode(ILOAD, 2));
list.add(new VarInsnNode(ILOAD, 3));
list.add(new VarInsnNode(ALOAD, 4));
list.add(new VarInsnNode(ILOAD, 5));
list.add(new MethodInsnNode(INVOKESTATIC, "com/builtbroken/mc/core/asm/StaticForwarder", "chunkSetBlockEvent", "(Lnet/minecraft/world/chunk/Chunk;IIILnet/minecraft/block/Block;I)V"));
AbstractInsnNode lastInsn = method.instructions.getLast();
while (lastInsn instanceof LabelNode || lastInsn instanceof LineNumberNode) {
lastInsn = lastInsn.getPrevious();
}
if (isReturn(lastInsn)) {
method.instructions.insertBefore(lastInsn, list);
} else {
method.instructions.insert(list);
}
EngineCoreMod.logger.info("Injected instruction to method: " + m.s_name);
}
}
return ASMHelper.createBytes(cnode, 0);
}
return bytes;
}
use of com.builtbroken.mc.lib.asm.ObfMapping in project Engine by VoltzEngine-Project.
the class InjectionTemplate method init.
//Called late to avoid loading class data in the constructor
private boolean init() {
if (!init) {
init = true;
try {
final ClassNode cnode = ASMHelper.createClassNode(((LaunchClassLoader) InjectionTemplate.class.getClassLoader()).getClassBytes(className.replace('/', '.')));
for (MethodNode method : cnode.methods) {
this.methodImplementations.add(method);
method.desc = new ObfMapping(cnode.name, method.name, method.desc).toRuntime().s_desc;
}
} catch (IOException e) {
//TODO error out in dev mode
//TODO make notation to users that this injector failed
e.printStackTrace();
failedToLoadClass = true;
}
}
return failedToLoadClass;
}
use of com.builtbroken.mc.lib.asm.ObfMapping in project Engine by VoltzEngine-Project.
the class InjectionTemplate method patch.
/**
* Patches the cnode with the methods from this template.
*
* @param cnode
* @return
*/
public boolean patch(ClassNode cnode, boolean injectConstructor) {
//Init data, if return true then init failed
if (init()) {
return false;
}
for (String interfaceName : this.interfaces) {
String interfaceByteName = interfaceName.replace(".", "/");
if (!cnode.interfaces.contains(interfaceByteName)) {
cnode.interfaces.add(interfaceByteName);
} else {
return false;
}
}
boolean changed = false;
LinkedList<String> names = new LinkedList<String>();
for (MethodNode method : cnode.methods) {
ObfMapping m = new ObfMapping(cnode.name, method.name, method.desc).toRuntime();
names.add(m.s_name + m.s_desc);
}
for (MethodNode impl : this.methodImplementations) {
if (!impl.name.equals("<init>") || injectConstructor) {
/**
* If the method is ALREADY implemented, then skip it.
*/
if (names.contains(impl.name + impl.desc)) {
continue;
}
ObfMapping mapping = new ObfMapping(cnode.name, impl.name, impl.desc).toRuntime();
MethodNode copy = new MethodNode(impl.access, mapping.s_name, mapping.s_desc, impl.signature, impl.exceptions == null ? null : impl.exceptions.toArray(new String[0]));
ASMHelper.copy(impl, copy);
cnode.methods.add(impl);
changed = true;
}
}
return changed;
}
Aggregations