Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class dump agrs #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-511-GTNH:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.8.2:dev')
api("com.github.GTNewHorizons:GTNHLib:0.5.22:dev")

implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.11.7:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/com/glodblock/github/coremod/FCClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.minecraft.launchwrapper.IClassTransformer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
Expand All @@ -13,12 +15,15 @@
import com.glodblock.github.coremod.transform.ExternalStorageRegistryTransformer;
import com.glodblock.github.coremod.transform.GuiCraftingTransformer;
import com.glodblock.github.coremod.transform.NEITransformer;
import com.gtnewhorizon.gtnhlib.asm.ASMUtil;

public class FCClassTransformer implements IClassTransformer {

private static final Logger logger = LogManager.getLogger("ASM AE2FC");

@Override
public byte[] transform(String name, String transformedName, byte[] code) {
Transform tform;
public byte[] transform(String name, String transformedName, byte[] basicClass) {
ClassMapper tform;
switch (transformedName) {
case "appeng.crafting.CraftingTreeNode" -> tform = CraftingTreeNodeTransformer.INSTANCE;
case "appeng.me.cache.CraftingGridCache" -> tform = CraftingGridCacheTransformer.INSTANCE;
Expand All @@ -28,22 +33,21 @@ public byte[] transform(String name, String transformedName, byte[] code) {
case "appeng.integration.modules.NEI" -> tform = NEITransformer.INSTANCE;
case "appeng.core.features.registries.ExternalStorageRegistry" -> tform = ExternalStorageRegistryTransformer.INSTANCE;
default -> {
return code;
return basicClass;
}
}
System.out.println("[AE2FC] Transforming class: " + transformedName);
return tform.transformClass(code);
}

public interface Transform {

byte[] transformClass(byte[] code);
logger.debug("Transforming class: " + transformedName);
final byte[] bytes = tform.transformClass(basicClass);
if (FluidCraftCore.DUMP_CLASSES()) {
ASMUtil.saveAsRawClassFile(basicClass, transformedName + "_PRE", this);
ASMUtil.saveAsRawClassFile(bytes, transformedName + "_POST", this);
}
return bytes;
}

public abstract static class ClassMapper implements Transform {
public abstract static class ClassMapper {

@Override
public byte[] transformClass(byte[] code) {
public final byte[] transformClass(byte[] code) {
ClassReader reader = new ClassReader(code);
ClassWriter writer = new ClassWriter(reader, getWriteFlags());
reader.accept(getClassMapper(writer), ClassReader.EXPAND_FRAMES);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/glodblock/github/coremod/FluidCraftCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
@IFMLLoadingPlugin.TransformerExclusions("com.glodblock.github.coremod")
public class FluidCraftCore implements IFMLLoadingPlugin {

private static final boolean DUMP_CLASSES = Boolean.parseBoolean(System.getProperty("ae2fc.dumpClass", "false"));
private static boolean OBF_ENV;

@Override
public String[] getASMTransformerClass() {
return new String[] { FluidCraftCore.class.getPackage().getName() + ".FCClassTransformer" };
return new String[] { FCClassTransformer.class.getName() };
}

@Nullable
Expand All @@ -30,12 +33,16 @@ public String getSetupClass() {

@Override
public void injectData(Map<String, Object> data) {
// NO-OP
OBF_ENV = (boolean) data.get("runtimeDeobfuscationEnabled");
}

@Nullable
@Override
public String getAccessTransformerClass() {
return null;
}

public static boolean DUMP_CLASSES() {
return DUMP_CLASSES || !OBF_ENV;
}
}