From dfda2378143c6abfca5d830b27bbfc43b6cb2391 Mon Sep 17 00:00:00 2001 From: Gregorius Techneticies Date: Mon, 12 Sep 2022 21:33:55 +0200 Subject: [PATCH] Aaaaand that mod has two parts --- src/main/java/gregtech/asm/GT_ASM.java | 1 + .../MicroBlock_FixLoggerCrash.java | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/main/java/gregtech/asm/transformers/MicroBlock_FixLoggerCrash.java diff --git a/src/main/java/gregtech/asm/GT_ASM.java b/src/main/java/gregtech/asm/GT_ASM.java index 0d26d9d09..057c470aa 100644 --- a/src/main/java/gregtech/asm/GT_ASM.java +++ b/src/main/java/gregtech/asm/GT_ASM.java @@ -94,6 +94,7 @@ public ASMConfig(File mclocation) { if (mclocation == null) throw new RuntimeException("Failed to acquire `location` in GT6 CoreMod"); transformers.put(MultiPart_FixLoggerCrash.class.getName(), true); + transformers.put(MicroBlock_FixLoggerCrash.class.getName(), true); transformers.put(CoFHCore_CrashFix.class.getName(), true); transformers.put(CoFHLib_HashFix.class.getName(), true); transformers.put(ExtraUtils_FixThaumcraftAspects.class.getName(), true); diff --git a/src/main/java/gregtech/asm/transformers/MicroBlock_FixLoggerCrash.java b/src/main/java/gregtech/asm/transformers/MicroBlock_FixLoggerCrash.java new file mode 100644 index 000000000..3138d0ff8 --- /dev/null +++ b/src/main/java/gregtech/asm/transformers/MicroBlock_FixLoggerCrash.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2022 GregTech-6 Team + * + * This file is part of GregTech. + * + * GregTech is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GregTech is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GregTech. If not, see . + */ + +package gregtech.asm.transformers; + +import gregapi.log.LoggerFML; +import gregtech.asm.GT_ASM; +import net.minecraft.launchwrapper.IClassTransformer; +import org.apache.logging.log4j.Logger; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.MethodNode; + +/** + * @author Gregorius Techneticies + */ +public class MicroBlock_FixLoggerCrash implements IClassTransformer { + public static Logger FAKE_LOGGER = new LoggerFML("FMB"); + + @Override + public byte[] transform(String name, String transformedName, byte[] basicClass) { + if (!transformedName.equals("codechicken.microblock.handler.MicroblockProxy")) return basicClass; + ClassNode classNode = GT_ASM.makeNodes(basicClass); + + for (MethodNode m: classNode.methods) { + if (m.name.equals("logger")) { + GT_ASM.logger.info("Transforming codechicken.microblock.handler.MicroblockProxy.logger"); + m.instructions.clear(); + m.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, "gregtech/asm/transformers/MicroBlock_FixLoggerCrash", "FAKE_LOGGER", "Lorg/apache/logging/log4j/Logger;")); + m.instructions.add(new InsnNode(Opcodes.ARETURN)); + } + } + + return GT_ASM.writeByteArray(classNode); + } +}