aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Java/gtPlusPlus/core/common/CommonProxy.java4
-rw-r--r--src/Java/gtPlusPlus/core/recipe/common/CI.java94
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java8
-rw-r--r--src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java171
-rw-r--r--src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java3
5 files changed, 159 insertions, 121 deletions
diff --git a/src/Java/gtPlusPlus/core/common/CommonProxy.java b/src/Java/gtPlusPlus/core/common/CommonProxy.java
index 191f81cef5..6acdf9b0c3 100644
--- a/src/Java/gtPlusPlus/core/common/CommonProxy.java
+++ b/src/Java/gtPlusPlus/core/common/CommonProxy.java
@@ -78,7 +78,7 @@ public class CommonProxy {
//29/01/18 - Alkalus
ModItems.init();
ModBlocks.init();
- CI.Init();
+ CI.preInit();
}
@@ -88,6 +88,8 @@ public class CommonProxy {
if (CORE.DEBUG){
DEBUG_INIT.registerHandlers();
}
+
+ CI.init();
/**
* Register the Event Handlers.
diff --git a/src/Java/gtPlusPlus/core/recipe/common/CI.java b/src/Java/gtPlusPlus/core/recipe/common/CI.java
index f9dc105792..03bf3a6020 100644
--- a/src/Java/gtPlusPlus/core/recipe/common/CI.java
+++ b/src/Java/gtPlusPlus/core/recipe/common/CI.java
@@ -171,20 +171,7 @@ public class CI {
public static ItemStack explosiveTNT;
public static ItemStack explosiveITNT;
- public static void Init(){
-
- //Set Explosives
- if (ItemList.valueOf("Block_Powderbarrel") != null){
- explosivePowderKeg = ItemList.valueOf("Block_Powderbarrel").get(1);
- }
- else {
- explosivePowderKeg = ItemUtils.getSimpleStack(Items.gunpowder);
- }
- explosiveTNT = ItemUtils.getSimpleStack(Blocks.tnt);
- explosiveITNT = Ic2Items.industrialTnt.copy();
-
-
-
+ public static void preInit(){
//Tiered Components
component_Plate = new String[]{
@@ -241,39 +228,7 @@ public class CI {
circuitTier7 = getTieredCircuit(7);
circuitTier8 = getTieredCircuit(8);
circuitTier9 = getTieredCircuit(9);
-
- //Machine Components
- LOADER_Machine_Components.initialise();
-
- //Machine Casings
- machineCasing_ULV = ItemList.Casing_ULV.get(1);
- machineCasing_LV = ItemList.Casing_LV.get(1);
- machineCasing_MV = ItemList.Casing_MV.get(1);
- machineCasing_HV = ItemList.Casing_HV.get(1);
- machineCasing_EV = ItemList.Casing_EV.get(1);
- machineCasing_IV = ItemList.Casing_IV.get(1);
- machineCasing_LuV = ItemList.Casing_LuV.get(1);
- machineCasing_ZPM = ItemList.Casing_ZPM.get(1);
- machineCasing_UV = ItemList.Casing_UV.get(1);
- machineCasing_MAX = ItemList.Casing_MAX.get(1);
-
- //Machine Hulls
- machineHull_ULV = ItemList.Hull_ULV.get(1);
- machineHull_LV = ItemList.Hull_LV.get(1);
- machineHull_MV = ItemList.Hull_MV.get(1);
- machineHull_HV = ItemList.Hull_HV.get(1);
- machineHull_EV = ItemList.Hull_EV.get(1);
- machineHull_IV = ItemList.Hull_IV.get(1);
- machineHull_LuV = ItemList.Hull_LuV.get(1);
- machineHull_ZPM = ItemList.Hull_ZPM.get(1);
- machineHull_UV = ItemList.Hull_UV.get(1);
- machineHull_MAX = ItemList.Hull_MAX.get(1);
-
- //Gear box Casings
- gearboxCasing_Tier_1 = ItemList.Casing_Gearbox_Bronze.get(1);
- gearboxCasing_Tier_2 = ItemList.Casing_Gearbox_Steel.get(1);
- gearboxCasing_Tier_3 = ItemList.Casing_Gearbox_Titanium.get(1);
- gearboxCasing_Tier_4 = ItemList.Casing_Gearbox_TungstenSteel.get(1);
+
}
public static Object getTieredCircuit(int tier){
@@ -500,5 +455,50 @@ public class CI {
return machineCasing_MAX;
}
}
+
+ public static void init() {
+ //Set Explosives
+ if (ItemList.valueOf("Block_Powderbarrel") != null){
+ explosivePowderKeg = ItemList.valueOf("Block_Powderbarrel").get(1);
+ }
+ else {
+ explosivePowderKeg = ItemUtils.getSimpleStack(Items.gunpowder);
+ }
+ explosiveTNT = ItemUtils.getSimpleStack(Blocks.tnt);
+ explosiveITNT = Ic2Items.industrialTnt.copy();
+
+ //Machine Casings
+ machineCasing_ULV = ItemList.Casing_ULV.get(1);
+ machineCasing_LV = ItemList.Casing_LV.get(1);
+ machineCasing_MV = ItemList.Casing_MV.get(1);
+ machineCasing_HV = ItemList.Casing_HV.get(1);
+ machineCasing_EV = ItemList.Casing_EV.get(1);
+ machineCasing_IV = ItemList.Casing_IV.get(1);
+ machineCasing_LuV = ItemList.Casing_LuV.get(1);
+ machineCasing_ZPM = ItemList.Casing_ZPM.get(1);
+ machineCasing_UV = ItemList.Casing_UV.get(1);
+ machineCasing_MAX = ItemList.Casing_MAX.get(1);
+
+ //Machine Hulls
+ machineHull_ULV = ItemList.Hull_ULV.get(1);
+ machineHull_LV = ItemList.Hull_LV.get(1);
+ machineHull_MV = ItemList.Hull_MV.get(1);
+ machineHull_HV = ItemList.Hull_HV.get(1);
+ machineHull_EV = ItemList.Hull_EV.get(1);
+ machineHull_IV = ItemList.Hull_IV.get(1);
+ machineHull_LuV = ItemList.Hull_LuV.get(1);
+ machineHull_ZPM = ItemList.Hull_ZPM.get(1);
+ machineHull_UV = ItemList.Hull_UV.get(1);
+ machineHull_MAX = ItemList.Hull_MAX.get(1);
+
+ //Gear box Casings
+ gearboxCasing_Tier_1 = ItemList.Casing_Gearbox_Bronze.get(1);
+ gearboxCasing_Tier_2 = ItemList.Casing_Gearbox_Steel.get(1);
+ gearboxCasing_Tier_3 = ItemList.Casing_Gearbox_Titanium.get(1);
+ gearboxCasing_Tier_4 = ItemList.Casing_Gearbox_TungstenSteel.get(1);
+
+ //Machine Components
+ LOADER_Machine_Components.initialise();
+ }
}
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index 2a98f0a75a..a0968fd5c1 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -16,14 +16,16 @@ public class ReflectionUtils {
public static Field getField(final Class clazz, final String fieldName) throws NoSuchFieldException {
try {
- return clazz.getDeclaredField(fieldName);
+ Field k = clazz.getDeclaredField(fieldName);
+ makeAccessible(k);
+ return k;
} catch (final NoSuchFieldException e) {
final Class<?> superClass = clazz.getSuperclass();
if (superClass == null) {
- //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+".");
+ Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+".");
throw e;
}
- //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+". Trying super class.");
+ Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+". Trying super class.");
return getField(superClass, fieldName);
}
}
diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java
index 55c384c58b..89c41452d5 100644
--- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java
+++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2.java
@@ -2,39 +2,68 @@ package gtPlusPlus.preloader.asm.transformers;
import static org.objectweb.asm.Opcodes.*;
-import java.rmi.AccessException;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.*;
+import org.objectweb.asm.commons.GeneratorAdapter;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.metatileentity.BaseMetaTileEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank;
import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.util.item.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraftforge.fluids.FluidStack;
public class Preloader_ClassTransformer2 {
+ private final static Class<BaseMetaTileEntity> customTransformer2 = BaseMetaTileEntity.class;
- public ArrayList<ItemStack> getDrops(BaseMetaTileEntity o) {
+ public static ArrayList<ItemStack> getDrops(BaseMetaTileEntity o) {
+ Logger.INFO("DROP!");
try {
- int tID = (int) ReflectionUtils.getField(getClass(), "mID").get(o);
- NBTTagCompound tRecipeStuff = (NBTTagCompound) ReflectionUtils.getField(getClass(), "mRecipeStuff").get(o);
- boolean tMuffler = (boolean) ReflectionUtils.getField(getClass(), "mMuffler").get(o);
- boolean tLockUpgrade = (boolean) ReflectionUtils.getField(getClass(), "mLockUpgrade").get(o);
- boolean tSteamConverter = (boolean) ReflectionUtils.getField(getClass(), "mSteamConverter").get(o);
- byte tColor = (byte) ReflectionUtils.getField(getClass(), "mColor").get(o);
- byte tOtherUpgrades = (byte) ReflectionUtils.getField(getClass(), "mOtherUpgrades").get(o);
- byte tStrongRedstone = (byte) ReflectionUtils.getField(getClass(), "mStrongRedstone").get(o);
- int[] tCoverSides = (int[]) ReflectionUtils.getField(getClass(), "mCoverSides").get(o);
- int[] tCoverData = (int[]) ReflectionUtils.getField(getClass(), "mCoverData").get(o);
- BaseMetaTileEntity tMetaTileEntity = (BaseMetaTileEntity) ReflectionUtils.getField(getClass(), "mMetaTileEntity").get(o);
-
+ short tID = (short) ReflectionUtils.getField(customTransformer2, "mID").get(o);
+ NBTTagCompound tRecipeStuff = (NBTTagCompound) ReflectionUtils.getField(customTransformer2, "mRecipeStuff").get(o);
+ boolean tMuffler = (boolean) ReflectionUtils.getField(customTransformer2, "mMuffler").get(o);
+ boolean tLockUpgrade = (boolean) ReflectionUtils.getField(customTransformer2, "mLockUpgrade").get(o);
+ boolean tSteamConverter = (boolean) ReflectionUtils.getField(customTransformer2, "mSteamConverter").get(o);
+ byte tColor = (byte) ReflectionUtils.getField(customTransformer2, "mColor").get(o);
+ byte tOtherUpgrades = (byte) ReflectionUtils.getField(customTransformer2, "mOtherUpgrades").get(o);
+ byte tStrongRedstone = (byte) ReflectionUtils.getField(customTransformer2, "mStrongRedstone").get(o);
+ int[] tCoverSides = (int[]) ReflectionUtils.getField(customTransformer2, "mCoverSides").get(o);
+ int[] tCoverData = (int[]) ReflectionUtils.getField(customTransformer2, "mCoverData").get(o);
+ FluidStack tFluid = null;
+ if (GT_MetaTileEntity_BasicTank.class.isInstance(o)) {
+ try {
+ tFluid = (FluidStack) ReflectionUtils.getField(GT_MetaTileEntity_BasicTank.class, "mFluid").get(o);
+ }
+ catch (Throwable t) {
+ Logger.REFLECTION("mFluid was not set.");
+ }
+ }
+ else {
+ Logger.REFLECTION("mFluid was not found.");
+ }
+ BaseMetaTileEntity tMetaTileEntity = o;
+
+ Logger.REFLECTION("tID: "+(tID != 0));
+ Logger.REFLECTION("tRecipeStuff: "+(tRecipeStuff != null));
+ Logger.REFLECTION("tMuffler: "+(tMuffler != false));
+ Logger.REFLECTION("tLockUpgrade: "+(tLockUpgrade != false));
+ Logger.REFLECTION("tSteamConverter: "+(tSteamConverter != false));
+ Logger.REFLECTION("tColor: "+(tColor != 0));
+ Logger.REFLECTION("tOtherUpgrades: "+(tOtherUpgrades != 0));
+ Logger.REFLECTION("tCoverSides: "+(tCoverSides != null));
+ Logger.REFLECTION("tCoverData: "+(tCoverData != null));
+ Logger.REFLECTION("tMetaTileEntity: "+(tMetaTileEntity != null));
+
ItemStack rStack = new ItemStack(GregTech_API.sBlockMachines, 1, tID);
NBTTagCompound tNBT = new NBTTagCompound();
@@ -43,6 +72,8 @@ public class Preloader_ClassTransformer2 {
if (tLockUpgrade) tNBT.setBoolean("mLockUpgrade", tLockUpgrade);
if (tSteamConverter) tNBT.setBoolean("mSteamConverter", tSteamConverter);
if (tColor > 0) tNBT.setByte("mColor", tColor);
+ //if (tFluid != null) tFluid.writeToNBT(tNBT);
+ if (tFluid != null) tNBT.setTag("mFluid", tFluid.tag);
if (tOtherUpgrades > 0) tNBT.setByte("mOtherUpgrades", tOtherUpgrades);
if (tStrongRedstone > 0) tNBT.setByte("mStrongRedstone", tStrongRedstone);
for (byte i = 0; i < tCoverSides.length; i++) {
@@ -62,15 +93,22 @@ public class Preloader_ClassTransformer2 {
Logger.REFLECTION("Trying to set NBT data to Itemstack from invalid tile, World might explode.");
((IMetaTileEntity) tMetaTileEntity).setItemNBT(tNBT); //Valid? Idk
}
- catch (Throwable t){}
+ catch (Throwable t){
+ Logger.REFLECTION("getDropsHack1");
+ t.printStackTrace();
+ }
}
-
+
//Set stack NBT
if (!tNBT.hasNoTags()) rStack.setTagCompound(tNBT);
return new ArrayList<ItemStack>(Arrays.asList(rStack));
}
- catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException a){}
- return null;
+ catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException a){
+ Logger.REFLECTION("getDropsHack2");
+ a.printStackTrace();
+ }
+ ArrayList<ItemStack> u = new ArrayList<ItemStack>(Arrays.asList(new ItemStack[]{ItemUtils.getSimpleStack(Blocks.bedrock)}));
+ return u;
}
@@ -84,75 +122,70 @@ public class Preloader_ClassTransformer2 {
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
if(name.equals("getDrops") && desc.equals("()Ljava/util/ArrayList;")) {
- FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Found target method. [Unobfuscated]");
- return new RegisterOreImplVisitor(methodVisitor, false);
- }
- else if(name.equals("getDrops") && desc.equals("(Ljava/lang/String;Ladd;)V")) {
- FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Found target method. [Obfuscated]");
- return new RegisterOreImplVisitor(methodVisitor, true);
+ FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Found target method. Access OpCode: "+access);
+ //return new TrySwapMethod(methodVisitor, access, name, desc);
+ return new SwapTwo(methodVisitor);
}
return methodVisitor;
}
}
- private static final class RegisterOreImplVisitor extends MethodVisitor {
+ /*private static final class TrySwapMethod extends GeneratorAdapter {
- private final boolean mObfuscated;
+ public TrySwapMethod(MethodVisitor mv, int access, String name, String desc) {
+ super(Opcodes.ASM5, mv, access, name, desc);
+ FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Created method swapper for '"+name+"' in 'gregtech/api/metatileentity/BaseMetaTileEntity'. Desc: "+desc);
+ }
- public RegisterOreImplVisitor(MethodVisitor mv, boolean obfuscated) {
+ @Override
+ public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
+ //gtPlusPlus.preloader.asm.transformers.Preloader_ClassTransformer2
+ if(opcode==INVOKESPECIAL && owner.equals("net/minecraft/item/ItemStack")
+ && name.equals("<init>") && desc.equals("(Lnet/minecraft/block/Block;II)V")) {
+ FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Trying to proccess '"+name+"' | Opcode: "+opcode+" | Desc: "+desc+" | Owner: "+owner);
+ FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Fixing Greg & Blood's poor attempt at setItemNBT().");
+ // not relaying the original instruction to super effectively removes the original
+ // instruction, instead we're producing a different instruction:
+ super.visitVarInsn(ALOAD, 0);
+ super.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2",
+ "getDrops", "()Ljava/util/ArrayList;", false);
+ FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Method should now be replaced.");
+ }
+ else { // relaying to super will reproduce the same instruction
+ //FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Original method call.");
+ super.visitMethodInsn(opcode, owner, name, desc, itf);
+ }
+ }
+
+ // all other, not overridden visit methods reproduce the original instructions
+ }*/
+
+ private static final class SwapTwo extends MethodVisitor {
+
+ public SwapTwo(MethodVisitor mv) {
super(ASM5, mv);
- this.mObfuscated = obfuscated;
}
@Override
public void visitCode() {
FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Fixing Greg & Blood's poor attempt at setItemNBT().");
- /*super.visitCode();
+ super.visitCode();
+ //ALOAD 0
+ //INVOKESTATIC gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2 getDrops (Lgregtech/api/metatileentity/BaseMetaTileEntity;)Ljava/util/ArrayList;
+ //ARETURN
+
super.visitVarInsn(ALOAD, 0);
- super.visitVarInsn(ALOAD, 1);
- if (!mObfuscated){
- FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Injecting target method. [Unobfuscated]");
- super.visitMethodInsn(INVOKESTATIC,
- "gtPlusPlus/preloader/Preloader_GT_OreDict",
- "shouldPreventRegistration",
- "(Ljava/lang/String;Lnet/minecraft/item/ItemStack;)Z",
+ super.visitMethodInsn(INVOKESTATIC,
+ "gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer2",
+ "getDrops",
+ "(Lgregtech/api/metatileentity/BaseMetaTileEntity;)Ljava/util/ArrayList;",
false);
- }
- else {
- FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Injecting target method. [Obfuscated]");
- super.visitMethodInsn(INVOKESTATIC,
- "gtPlusPlus/preloader/Preloader_GT_OreDict",
- "shouldPreventRegistration",
- "(Ljava/lang/String;Ladd;)Z",
- false);
- }
- Label endLabel = new Label();
- super.visitJumpInsn(IFEQ, endLabel);
- super.visitInsn(RETURN);
- super.visitLabel(endLabel);*/
+ FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Method should now be replaced.");
+ //super.visitVarInsn(ARETURN, 0);
+ super.visitInsn(ARETURN);
}
}
-
- public static class GetDropsReplacer extends MethodVisitor {
- private final MethodVisitor target;
-
- public GetDropsReplacer(MethodVisitor methodVisitor) {
- super(ASM4, null);
- this.target=methodVisitor;
- }
-
- @Override
- public void visitCode() {
- target.visitCode();
- target.visitTypeInsn(NEW, "java/io/IOException");
- target.visitInsn(DUP);
- target.visitMethodInsn(INVOKESPECIAL,"java/io/IOException","<init>","()V",false);
- target.visitInsn(ATHROW);
- target.visitMaxs(2, 0);
- target.visitEnd();
- }
- }
}
diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java
index 0a2f674875..723061f998 100644
--- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java
+++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java
@@ -21,7 +21,8 @@ public class Preloader_Transformer_Handler implements IClassTransformer {
if(transformedName.equals("gregtech.api.metatileentity.BaseMetaTileEntity")) {
FMLRelaunchLog.log("[GT++ ASM] NBTFixer", Level.INFO, "Transforming %s", transformedName);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
- new ClassReader(basicClass).accept(new GT_MetaTile_Visitor(classWriter), 0);
+ ClassReader x = new ClassReader(basicClass);
+ x.accept(new GT_MetaTile_Visitor(classWriter), ClassReader.EXPAND_FRAMES);
return classWriter.toByteArray();
}
return basicClass;