Skip to content

Commit

Permalink
Revert "Make block class transformers also check subclasses for metho…
Browse files Browse the repository at this point in the history
…d overrides (#360)"

This reverts commit 508999a.
  • Loading branch information
TheCodex6824 committed Feb 18, 2024
1 parent c7ec5dc commit 989f23d
Show file tree
Hide file tree
Showing 38 changed files with 876 additions and 968 deletions.
185 changes: 69 additions & 116 deletions src/main/java/thecodex6824/thaumicaugmentation/core/TATransformer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public class ThaumicAugmentationCore implements IFMLLoadingPlugin {
private static boolean enabled;
private static ImmutableSet<String> excludedTransformers;

public ThaumicAugmentationCore() {}
public ThaumicAugmentationCore() {
}

public static Logger getLogger() {
return log;
Expand All @@ -74,9 +75,7 @@ public String getAccessTransformerClass() {

@Override
public String[] getASMTransformerClass() {
return new String[] {
"thecodex6824.thaumicaugmentation.core.TATransformer"
};
return new String[] {"thecodex6824.thaumicaugmentation.core.TATransformer"};
}

@Override
Expand All @@ -91,16 +90,15 @@ public String getSetupClass() {

@Override
public void injectData(Map<String, Object> data) {
config = new Configuration(new File("config", ThaumicAugmentationAPI.MODID + ".cfg"));
enabled = !config.getBoolean("DisableCoremod", "general", false, "");
excludedTransformers = ImmutableSet
.copyOf(config.getStringList("DisabledTransformers", "general", new String[0], ""));
if (enabled) {
ThaumicAugmentationAPI.setCoremodAvailable();
if (config == null) {
config = new Configuration(new File("config", ThaumicAugmentationAPI.MODID + ".cfg"));
enabled = !config.getBoolean("DisableCoremod", "general", false, "");
excludedTransformers = ImmutableSet.copyOf(config.getStringList("DisabledTransformers", "general", new String[0], ""));
}
else {
if (enabled)
ThaumicAugmentationAPI.setCoremodAvailable();
else
log.info("Thaumic Augmentation coremod disabled by config request");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

public interface ITransformer {

public boolean isTransformationNeeded(ClassNode node, String transformedName);

public boolean transform(ClassNode classNode, String transformedName);

public boolean isTransformationNeeded(String transformedName);
public boolean transform(ClassNode classNode, String name, String transformedName);
public RuntimeException getRaisedException();

public boolean needToComputeFrames();

public boolean isAllowedToFail();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package thecodex6824.thaumicaugmentation.core.transformer;

import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
Expand All @@ -33,184 +34,187 @@
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;

public final class TransformUtil {

private TransformUtil() {}

public static final String HOOKS_COMMON = "thecodex6824/thaumicaugmentation/common/internal/TAHooksCommon";
public static final String HOOKS_CLIENT = "thecodex6824/thaumicaugmentation/client/internal/TAHooksClient";

public static String remapFieldName(String internalName, String fieldName) {
String internal = FMLDeobfuscatingRemapper.INSTANCE.unmap(internalName);
return FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(internal, fieldName, null);
}

public static String remapMethodName(String internalName, String methodName, Type returnType,
Type... parameterTypes) {

public static String remapMethodName(String internalName, String methodName, Type returnType, Type... parameterTypes) {
String internal = FMLDeobfuscatingRemapper.INSTANCE.unmap(internalName);
String desc = Type.getMethodDescriptor(returnType, parameterTypes);
return FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(internal, methodName, desc);
}

public static MethodNode findMethod(ClassNode classNode, String name) {
for (MethodNode m : classNode.methods) {
if (m.name.equals(name))
return m;
}

return null;
}

public static MethodNode findMethod(ClassNode classNode, String name, String desc) {
for (MethodNode m : classNode.methods) {
if (m.name.equals(name) && m.desc.equals(desc))
return m;
}

return null;
}

public static int findFirstInstanceOfOpcode(MethodNode node, int startIndex, int opcode) {
if (startIndex < 0 || startIndex >= node.instructions.size())
return -1;

for (int i = startIndex; i < node.instructions.size(); ++i) {
if (node.instructions.get(i).getOpcode() == opcode)
return i;
}

return -1;
}

public static int findLastInstanceOfOpcode(MethodNode node, int endIndex, int opcode) {
if ((endIndex - 1) < 0 || (endIndex - 1) >= node.instructions.size())
return -1;

for (int i = endIndex - 1; i >= 0; --i) {
if (node.instructions.get(i).getOpcode() == opcode)
return i;
}

return -1;
}

public static int findFirstInstanceOfMethodCall(MethodNode node, int startIndex, String name, String desc,
String owningClass) {

if (startIndex < 0 || startIndex >= node.instructions.size())
return -1;

for (int i = startIndex; i < node.instructions.size(); ++i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof MethodInsnNode) {
MethodInsnNode method = (MethodInsnNode) insn;
if (method.name.equals(name) && method.desc.equals(desc) && method.owner.equals(owningClass))
if (method.name.equals(name) && method.desc.equals(desc) &&
method.owner.equals(owningClass))
return i;
}
}

return -1;
}

public static int findLastInstanceOfMethodCall(MethodNode node, int endIndex, String name, String desc,
String owningClass) {

if ((endIndex - 1) < 0 || (endIndex - 1) >= node.instructions.size())
return -1;

for (int i = endIndex - 1; i >= 0; --i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof MethodInsnNode) {
MethodInsnNode method = (MethodInsnNode) insn;
if (method.name.equals(name) && method.desc.equals(desc) && method.owner.equals(owningClass))
if (method.name.equals(name) && method.desc.equals(desc) &&
method.owner.equals(owningClass))
return i;
}
}

return -1;
}

public static int findFirstLabel(MethodNode node, int startIndex) {

if (startIndex < 0 || startIndex >= node.instructions.size())
return -1;

for (int i = startIndex; i < node.instructions.size(); ++i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof LabelNode)
return i;
}

return -1;
}

public static int findLastLabel(MethodNode node, int endIndex) {

if ((endIndex - 1) < 0 || (endIndex - 1) >= node.instructions.size())
return -1;

for (int i = endIndex - 1; i >= 0; --i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof LabelNode)
return i;
}

return -1;
}

public static int findLineNumber(MethodNode node, int number) {

for (int i = 0; i < node.instructions.size(); ++i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof LineNumberNode && ((LineNumberNode) insn).line == number)
return i;
}

return -1;
}

public static int findFirstField(MethodNode node, int startIndex, String name, String desc, String owningClass) {


public static int findFirstField(MethodNode node, int startIndex, String name, String desc,
String owningClass) {

if (startIndex < 0 || startIndex >= node.instructions.size())
return -1;

for (int i = startIndex; i < node.instructions.size(); ++i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) insn;
if (field.name.equals(name) && field.desc.equals(desc) && field.owner.equals(owningClass))
if (field.name.equals(name) && field.desc.equals(desc) &&
field.owner.equals(owningClass))
return i;
}
}

return -1;

}

public static int findLastField(MethodNode node, int endIndex, String name, String desc, String owningClass) {


public static int findLastField(MethodNode node, int endIndex, String name, String desc,
String owningClass) {

if ((endIndex - 1) < 0 || (endIndex - 1) >= node.instructions.size())
return -1;

for (int i = endIndex - 1; i >= 0; --i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) insn;
if (field.name.equals(name) && field.desc.equals(desc) && field.owner.equals(owningClass))
if (field.name.equals(name) && field.desc.equals(desc) &&
field.owner.equals(owningClass))
return i;
}
}

return -1;

}

public static int findFirstLoad(MethodNode node, int startIndex, int opcode, int objIndex) {
if (startIndex < 0 || startIndex >= node.instructions.size())
return -1;

for (int i = startIndex; i < node.instructions.size(); ++i) {
AbstractInsnNode insn = node.instructions.get(i);
if (insn.getOpcode() == opcode && insn instanceof VarInsnNode) {
Expand All @@ -219,7 +223,7 @@ public static int findFirstLoad(MethodNode node, int startIndex, int opcode, int
return i;
}
}

return -1;
}

Expand Down Expand Up @@ -251,29 +255,5 @@ public static int findExactLabel(MethodNode node, Label label) {

return -1;
}

public static boolean classExtends(ClassNode node, String fullClassWithDots) {
if (node.name.replace('/', '.').equals(fullClassWithDots)) {
return true;
}

try {
Class<?> check = Class.forName(node.superName.replace('/', '.'), false,
TransformUtil.class.getClassLoader());
while (check != null) {
if (check.getName().equals(fullClassWithDots)) {
return true;
}
else if (check == Object.class) {
return false;
}

check = check.getSuperclass();
}
}
catch (ClassCircularityError | ClassNotFoundException ex) {}

return false;
}


}
Loading

0 comments on commit 989f23d

Please sign in to comment.