This might be your problem.
Also, where are you getting '436' from?
huh, I don't remember where I got that but I know it's not right and I don't know how to get the correct index location of the PUTFIELD Opcode. I probably should have mentioned this in the first post but what I don't understand is how in the tutorial when he tests for the FDIV, how will it find the correct operation? What if in the method there are multiple divisions? I assume that's why you get the index but what if another mod injects first? Won't the index location change?
Hello. Thanks a lot for this tutorial. It's probably the only one up to date around.
I'm having trouble changing the accessibility of two methods from protected to public. This is my code, based on your tutorial (I'm very sorry about posting so much information. Probably very little of what I'm posting is really relevant. I just want to be sure I'm not leaving out anything important):
this is the IFMLLoadingPlugin implementation
public class MyLoadingPlugin implements IFMLLoadingPlugin
{
@Override
@Deprecated
public String[] getLibraryRequestClass()
{
return null;
}
@Override
public String[] getASMTransformerClass()
{
return new String[] {MyAccessTransformer.class.getName()};
}
@Override
public String getModContainerClass()
{
return MyModContainer.class.getName();
}
@Override
public String getSetupClass()
{
return null;
}
@Override
public void injectData(Map<String, Object> data)
{ }
}
this is the AccressTransformer subclass
public class MyAccessTransformer extends AccessTransformer
{
public MyAccessTransformer() throws IOException
{
super("my_at.cfg");
}
}
this is the DummyModContainer subclass
public class MyModContainer extends DummyModContainer
{
public MyModContainer()
{
super(new ModMetadata());
/* ModMetadata is the same as mcmod.info */
ModMetadata myMeta = super.getMetadata();
myMeta.authorList = Arrays.asList(new String[] { "Pedrinho99" });
myMeta.description = "Transforms access fields needed";
myMeta.modId = "My AccessTransformer";
myMeta.version = "1.6.2";
myMeta.name = "My Access Transformer";
}
@Override
public boolean registerBus(EventBus bus, LoadController controller)
{
bus.register(this);
return true;
}
}
this is the file my_at.cfg
# BlockCrops
# changes accessibility of getSeedItem() and getCropItem() from protected to public
public ano.j()I
public ano.k()I
I run recompile.bat and reobfuscate.bat.
I go to *mcp*\reobf\minecraft\ and there is a pedrinho folder there, as expected.
this is what is inside that pedrinho folder
\transform\
MyAccessTransformer.class
MyLoadingPlugin.class
MyModContainer.class
I select the pedrinho folder AND the META-INF folder (which contains only the MANIFEST.MF file described above) and I make a zip file of them. I then rename the file from pedrinho.zip to pedrinho.jar and put it in *mcp*\jars\mods\
Everything runs ok apparently. Then I have a Block which tries to access those fields. This is the method:
private void harvest(World world, int x, int y, int z, int growthStage, BlockCrops blockAbove)
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
int fortuneLevel = world.getBlockMetadata(x, y, z);
ArrayList<ItemStack> allItems = blockAbove.getBlockDropped(world, x, y + 1, z, growthStage, fortuneLevel);
for(ItemStack item : allItems)
{
/* because the accessibility of the methods is only changed at runtime, I can't try to
* directly access the protected fields, so I take a detour by using reflection. This way
* my calls will only be evaluated at runtime and I get no compile time errors */
Class blockCropsClass = blockAbove.getClass();
/* this is a test. I use the same logic to access a public method that has the same signature but is
* declared public. This works fine and I get "RenderType: 6" printed to the console, as expected.*/
Method getRenderTypeMethod = blockCropsClass.getMethod("getRenderType");
int renderType = ((Integer)getRenderTypeMethod.invoke(blockAbove, (Object[])null)).intValue();
System.out.println("RenderType: " + renderType);
/* the statement below throws a NoSuchMethodException, with the message:
* "net.minecraft.block.BlockCrops.getSeedItem()"
* I'm guessing the exception has something to do with my attempt to change the accessibility level
* failing, since we all know for sure there is a BlockCrops.getSeedItem() method*/
Method getSeedItemMethod = blockCropsClass.getMethod("getSeedItem");
Method getCropItemMethod = blockCropsClass.getMethod("getCropItem");
if(item.itemID == ((Integer)getSeedItemMethod.invoke(blockAbove, (Object[])null)).intValue())
{
//not yet implemented. The code never reaches this point anyway
world.setBlockToAir(x, y + 1, z);
}
else if(item.itemID == ((Integer)getCropItemMethod.invoke(blockAbove, (Object[])null)).intValue())
{
//not yet implemented. The code never reaches this point anyway
world.setBlockToAir(x, y + 1, z);
}
}
}
If you could tell me what did I do wrong that would be really great. Thanks again. And sorry again for such a long post with probably so little useful info. I just can't tell what's useful and what's not and so I posted the whole code.
Hello. Thanks a lot for this tutorial. It's probably the only one up to date around.
I'm having trouble changing the accessibility of two methods from protected to public. This is my code, based on your tutorial (I'm very sorry about posting so much information. Probably very little of what I'm posting is really relevant. I just want to be sure I'm not leaving out anything important):
this is the IFMLLoadingPlugin implementation
public class MyLoadingPlugin implements IFMLLoadingPlugin
{
@Override
@Deprecated
public String[] getLibraryRequestClass()
{
return null;
}
@Override
public String[] getASMTransformerClass()
{
return new String[] {MyAccessTransformer.class.getName()};
}
@Override
public String getModContainerClass()
{
return MyModContainer.class.getName();
}
@Override
public String getSetupClass()
{
return null;
}
@Override
public void injectData(Map<String, Object> data)
{ }
}
this is the AccressTransformer subclass
public class MyAccessTransformer extends AccessTransformer
{
public MyAccessTransformer() throws IOException
{
super("my_at.cfg");
}
}
this is the DummyModContainer subclass
public class MyModContainer extends DummyModContainer
{
public MyModContainer()
{
super(new ModMetadata());
/* ModMetadata is the same as mcmod.info */
ModMetadata myMeta = super.getMetadata();
myMeta.authorList = Arrays.asList(new String[] { "Pedrinho99" });
myMeta.description = "Transforms access fields needed";
myMeta.modId = "My AccessTransformer";
myMeta.version = "1.6.2";
myMeta.name = "My Access Transformer";
}
@Override
public boolean registerBus(EventBus bus, LoadController controller)
{
bus.register(this);
return true;
}
}
this is the file my_at.cfg
# BlockCrops
# changes accessibility of getSeedItem() and getCropItem() from protected to public
public ano.j()I
public ano.k()I
I run recompile.bat and reobfuscate.bat.
I go to *mcp*\reobf\minecraft\ and there is a pedrinho folder there, as expected.
this is what is inside that pedrinho folder
\transform\
MyAccessTransformer.class
MyLoadingPlugin.class
MyModContainer.class
I select the pedrinho folder AND the META-INF folder (which contains only the MANIFEST.MF file described above) and I make a zip file of them. I then rename the file from pedrinho.zip to pedrinho.jar and put it in *mcp*\jars\mods\
Everything runs ok apparently. Then I have a Block which tries to access those fields. This is the method:
private void harvest(World world, int x, int y, int z, int growthStage, BlockCrops blockAbove)
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
int fortuneLevel = world.getBlockMetadata(x, y, z);
ArrayList<ItemStack> allItems = blockAbove.getBlockDropped(world, x, y + 1, z, growthStage, fortuneLevel);
for(ItemStack item : allItems)
{
/* because the accessibility of the methods is only changed at runtime, I can't try to
* directly access the protected fields, so I take a detour by using reflection. This way
* my calls will only be evaluated at runtime and I get no compile time errors */
Class blockCropsClass = blockAbove.getClass();
/* this is a test. I use the same logic to access a public method that has the same signature but is
* declared public. This works fine and I get "RenderType: 6" printed to the console, as expected.*/
Method getRenderTypeMethod = blockCropsClass.getMethod("getRenderType");
int renderType = ((Integer)getRenderTypeMethod.invoke(blockAbove, (Object[])null)).intValue();
System.out.println("RenderType: " + renderType);
/* the statement below throws a NoSuchMethodException, with the message:
* "net.minecraft.block.BlockCrops.getSeedItem()"
* I'm guessing the exception has something to do with my attempt to change the accessibility level
* failing, since we all know for sure there is a BlockCrops.getSeedItem() method*/
Method getSeedItemMethod = blockCropsClass.getMethod("getSeedItem");
Method getCropItemMethod = blockCropsClass.getMethod("getCropItem");
if(item.itemID == ((Integer)getSeedItemMethod.invoke(blockAbove, (Object[])null)).intValue())
{
//not yet implemented. The code never reaches this point anyway
world.setBlockToAir(x, y + 1, z);
}
else if(item.itemID == ((Integer)getCropItemMethod.invoke(blockAbove, (Object[])null)).intValue())
{
//not yet implemented. The code never reaches this point anyway
world.setBlockToAir(x, y + 1, z);
}
}
}
If you could tell me what did I do wrong that would be really great. Thanks again. And sorry again for such a long post with probably so little useful info. I just can't tell what's useful and what's not and so I posted the whole code.
huh, I don't remember where I got that but I know it's not right and I don't know how to get the correct index location of the PUTFIELD Opcode. I probably should have mentioned this in the first post but what I don't understand is how in the tutorial when he tests for the FDIV, how will it find the correct operation? What if in the method there are multiple divisions? I assume that's why you get the index but what if another mod injects first? Won't the index location change?
Yes, it would. I would recommend checking for something else, like the previous button. Also, you are inserting your instructions at the top of the stack, not after the node you were searching for, this rendering that check useless. I will give an example tomorrow, as I can't access my computer right now.
Yes, it would. I would recommend checking for something else, like the previous button. Also, you are inserting your instructions at the top of the stack, not after the node you were searching for, this rendering that check useless. I will give an example tomorrow, as I can't access my computer right now.
I've already read that one. From that one I learned how to get the right obfuscated names. The rest is wrong and/or outdated.
Ah... Then I don't know. I've never used them. Have you read culegooner's tutorial on them?
Yes, I was asking him why the access transforming wasn't woking. But there's another way of doing the same. It doesn't involve creating a new mod for modifying access to members but it's probably a lot slower since I have to use reflection everytime I reference the member thats unaccessible by default, instead of just running the access modifier mod on minecraft load.
I just used reflection to invoke the method, calling getDeclaredMethod instead to get the protected method, and bypassing the access restriction by calling setAccessible(true) on the resulting method. I still hope to learn access transforming though. Reflection can hurt performance if used too frequently.
I have been working on upgrading my mod to 1.6.2, but I have to make it have coremod functionality now since forge changed the way it works. The problem is that the game keeps crashing. I have all of my source, more information, and all of my crash reports on my github repository.
Okay, does your code even crash in eclipse? And please upload the long crashlog (located at .\AppData\Roaming\.minecraft\ForgeModLoader-client-0.log).
I haven't tried in eclipse. I combined my coremod and normal mod workspace temporarily, so I can't test them together. Perhaps this might be the problem. However, if I did separate them into different workspaces, how would I test them together. Or is there a way to combine the normal (non-coremod) mods with the coremod.
It wouldn't let me put the ForgeModLoader-client-0.log in a post because it was too long, so I added it to me repo.
Is assume you've just modified EntityVillager in eclipse and tested if it works then? If you don't plan to use the class patcher in eclipse, which I think is unnecessary anyway, you can remove the EntityVillager.class file from your patch folder and the following line from your code:
Just a small optimization. Will do further testing now.
Edit: Didn't came up with a solution yet. Will do further testing tomorrow.
Oh. I tested it before I started making it be a coremod. It works, but I just can't get it to be a coremod. It gets passed the patching, but then it says that the non-obfuscated class doesn't exist.
I tried the method of using the manifest and having normal mods combined. Plus, I removed everything with the non-obfuscated class, and it still didn't work. I am going to attempt building against the latest minecraft forge (I have the latest installed in minecraft just not the source). Perhaps it is just an obfuscation bug or something. I will post my results tomorrow after I test.
It didn't work. I updated the changed source, uploaded updated logs and crash reports, and added a META-INF/MANIFEST.MF on my repo. I also added a jar, so you can see if my structure is correct. It will be located under releases on my repo.
It didn't work. I updated the changed source, uploaded updated logs and crash reports, and added a META-INF/MANIFEST.MF on my repo. I also added a jar, so you can see if my structure is correct. It will be located under releases on my repo.
That caused my Minecraft to crash with the following line:
java.lang.VerifyError: (class: net/minecraft/entity/passive/EntityVillager, method: <clinit> signature: ()V) Falling off the end of the code
Anyone an idea why this is happening to only a few classes?
Yes.
Classes are not created equal.
Some are big. Some are small.
The bigger they are, the harder they fall.
The log says the failed class is the biggest of all (that has been loaded so far).
Try
read the documentation thoroughly. read(byte[])read(byte[], int, int)
Catch
the possibility that sometimes the read function does not read all bytes.
And, finally,
create a loop to read the whole class.
It should be like this.
InputStream zin = zip.getInputStream(entry);
int size = (int) entry.getSize();
byte[] newbytes = new byte[size];
int pos = 0;
while (pos < size) {
int len = zin.read(newbytes,pos,size-pos);
if (len == 0)
throw new IOException();
pos += len;
}
zin.close();
However, when I try to start a world, I get this error:
java.lang.VerifyError: (class: net/minecraft/entity/player/EntityPlayer, method: getTranslatedEntityName signature: ()Ljava/lang/String;) Incompatible object argument for function call
at net.minecraft.server.management.ServerConfigurationManager.createPlayerForUser(ServerConfigurationManager.java:389)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:91)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:689)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:585)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2013-09-08 16:10:28 [INFO] [STDOUT] Patching Complete!
2013-09-08 16:10:28 [SEVERE] [ForgeModLoader] Unable to launch
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:57)
at net.minecraft.launchwrapper.Launch.main(Launch.java:18)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/entity/player/EntityPlayer
at net.minecraft.client.main.Main.main(Main.java:37)
... 6 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.entity.player.EntityPlayer
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Caused by: java.lang.NullPointerException
at org.objectweb.asm.Frame.merge(Frame.java:1292)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1303)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:592)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:515)
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:340)
at portables.asm.ClassTransformer.patchClassEnitityPlayer(ClassTransformer.java:97)
at portables.asm.ClassTransformer.transform(ClassTransformer.java:26)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:267)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:165)
... 9 more
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumhuh, I don't remember where I got that but I know it's not right and I don't know how to get the correct index location of the PUTFIELD Opcode. I probably should have mentioned this in the first post but what I don't understand is how in the tutorial when he tests for the FDIV, how will it find the correct operation? What if in the method there are multiple divisions? I assume that's why you get the index but what if another mod injects first? Won't the index location change?
I'm having trouble changing the accessibility of two methods from protected to public. This is my code, based on your tutorial (I'm very sorry about posting so much information. Probably very little of what I'm posting is really relevant. I just want to be sure I'm not leaving out anything important):
this is the IFMLLoadingPlugin implementation
public class MyLoadingPlugin implements IFMLLoadingPlugin { @Override @Deprecated public String[] getLibraryRequestClass() { return null; } @Override public String[] getASMTransformerClass() { return new String[] {MyAccessTransformer.class.getName()}; } @Override public String getModContainerClass() { return MyModContainer.class.getName(); } @Override public String getSetupClass() { return null; } @Override public void injectData(Map<String, Object> data) { } }this is the AccressTransformer subclass
public class MyAccessTransformer extends AccessTransformer { public MyAccessTransformer() throws IOException { super("my_at.cfg"); } }this is the DummyModContainer subclass
public class MyModContainer extends DummyModContainer { public MyModContainer() { super(new ModMetadata()); /* ModMetadata is the same as mcmod.info */ ModMetadata myMeta = super.getMetadata(); myMeta.authorList = Arrays.asList(new String[] { "Pedrinho99" }); myMeta.description = "Transforms access fields needed"; myMeta.modId = "My AccessTransformer"; myMeta.version = "1.6.2"; myMeta.name = "My Access Transformer"; } @Override public boolean registerBus(EventBus bus, LoadController controller) { bus.register(this); return true; } }this is the file my_at.cfg
finally, this is my MANIFEST.MF
I run recompile.bat and reobfuscate.bat.
I go to *mcp*\reobf\minecraft\ and there is a pedrinho folder there, as expected.
this is what is inside that pedrinho folder
\transform\
MyAccessTransformer.class
MyLoadingPlugin.class
MyModContainer.class
I select the pedrinho folder AND the META-INF folder (which contains only the MANIFEST.MF file described above) and I make a zip file of them. I then rename the file from pedrinho.zip to pedrinho.jar and put it in *mcp*\jars\mods\
Everything runs ok apparently. Then I have a Block which tries to access those fields. This is the method:
private void harvest(World world, int x, int y, int z, int growthStage, BlockCrops blockAbove) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { int fortuneLevel = world.getBlockMetadata(x, y, z); ArrayList<ItemStack> allItems = blockAbove.getBlockDropped(world, x, y + 1, z, growthStage, fortuneLevel); for(ItemStack item : allItems) { /* because the accessibility of the methods is only changed at runtime, I can't try to * directly access the protected fields, so I take a detour by using reflection. This way * my calls will only be evaluated at runtime and I get no compile time errors */ Class blockCropsClass = blockAbove.getClass(); /* this is a test. I use the same logic to access a public method that has the same signature but is * declared public. This works fine and I get "RenderType: 6" printed to the console, as expected.*/ Method getRenderTypeMethod = blockCropsClass.getMethod("getRenderType"); int renderType = ((Integer)getRenderTypeMethod.invoke(blockAbove, (Object[])null)).intValue(); System.out.println("RenderType: " + renderType); /* the statement below throws a NoSuchMethodException, with the message: * "net.minecraft.block.BlockCrops.getSeedItem()" * I'm guessing the exception has something to do with my attempt to change the accessibility level * failing, since we all know for sure there is a BlockCrops.getSeedItem() method*/ Method getSeedItemMethod = blockCropsClass.getMethod("getSeedItem"); Method getCropItemMethod = blockCropsClass.getMethod("getCropItem"); if(item.itemID == ((Integer)getSeedItemMethod.invoke(blockAbove, (Object[])null)).intValue()) { //not yet implemented. The code never reaches this point anyway world.setBlockToAir(x, y + 1, z); } else if(item.itemID == ((Integer)getCropItemMethod.invoke(blockAbove, (Object[])null)).intValue()) { //not yet implemented. The code never reaches this point anyway world.setBlockToAir(x, y + 1, z); } } }If you could tell me what did I do wrong that would be really great. Thanks again. And sorry again for such a long post with probably so little useful info. I just can't tell what's useful and what's not and so I posted the whole code.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumTry looking here.
Yes, it would. I would recommend checking for something else, like the previous button. Also, you are inserting your instructions at the top of the stack, not after the node you were searching for, this rendering that check useless. I will give an example tomorrow, as I can't access my computer right now.
-tlf
I've already read that one. From that one I learned how to get the right obfuscated names. The rest is wrong and/or outdated.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-tlf
Yes, I was asking him why the access transforming wasn't woking. But there's another way of doing the same. It doesn't involve creating a new mod for modifying access to members but it's probably a lot slower since I have to use reflection everytime I reference the member thats unaccessible by default, instead of just running the access modifier mod on minecraft load.
I just used reflection to invoke the method, calling getDeclaredMethod instead to get the protected method, and bypassing the access restriction by calling setAccessible(true) on the resulting method. I still hope to learn access transforming though. Reflection can hurt performance if used too frequently.
-
View User Profile
-
View Posts
-
Send Message
Curse Premium-tlf
GitHub Repo
I used reobfuscate to get the ua.class, and I used reobfuscate_srg to get the net.minecraft.entity.passive.EntityVillager.class
I haven't tried in eclipse. I combined my coremod and normal mod workspace temporarily, so I can't test them together. Perhaps this might be the problem. However, if I did separate them into different workspaces, how would I test them together. Or is there a way to combine the normal (non-coremod) mods with the coremod.
It wouldn't let me put the ForgeModLoader-client-0.log in a post because it was too long, so I added it to me repo.
GitHub Repo
Oh. I tested it before I started making it be a coremod. It works, but I just can't get it to be a coremod. It gets passed the patching, but then it says that the non-obfuscated class doesn't exist.
It didn't work. I updated the changed source, uploaded updated logs and crash reports, and added a META-INF/MANIFEST.MF on my repo. I also added a jar, so you can see if my structure is correct. It will be located under releases on my repo.
GitHub Repo
Edit: I also added my build process to the readme.
Okay. No hurry.
Yes.
Classes are not created equal.
Some are big. Some are small.
The bigger they are, the harder they fall.
The log says the failed class is the biggest of all (that has been loaded so far).
Don't do this.
Try
read the documentation thoroughly. read(byte[]) read(byte[], int, int)
Catch
the possibility that sometimes the read function does not read all bytes.
And, finally,
create a loop to read the whole class.
It should be like this.
InputStream zin = zip.getInputStream(entry); int size = (int) entry.getSize(); byte[] newbytes = new byte[size]; int pos = 0; while (pos < size) { int len = zin.read(newbytes,pos,size-pos); if (len == 0) throw new IOException(); pos += len; } zin.close();I have already post about this before. But no one listened at that time.
http://www.minecraftforum.net/index.php?app=forums&module=forums§ion=findpost&pid=23706913
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI'm back with another problem!
This time I'm trying to override the functionto change the return value fromto
However, when I try to start a world, I get this error:
at net.minecraft.server.management.ServerConfigurationManager.createPlayerForUser(ServerConfigurationManager.java:389)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:91)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:689)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:585)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Here's my transformer:
package tlf.playertag.ASM; import static org.objectweb.asm.Opcodes.ALOAD; import static org.objectweb.asm.Opcodes.GETFIELD; import static org.objectweb.asm.Opcodes.GETSTATIC; import static org.objectweb.asm.Opcodes.INVOKESTATIC; import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; import tlf.playertag.common.PlayerTag; import net.minecraft.launchwrapper.IClassTransformer; import java.util.Iterator; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; public class Transformer implements IClassTransformer { @Override public byte[] transform(String arg0, String arg1, byte[] arg2) { if (arg0.equals("ue")) { return patchClassASM(arg0, arg2, true); } else if (arg0.equals("net.minecraft.entity.player.EntityPlayer")) { return patchClassASM(arg0, arg2, false); } return arg2; } public byte[] patchClassASM(String name, byte[] bytes, boolean obfuscated) { String targetMethodName = obfuscated ? "ax" : "getTranslatedEntityName"; String targetMethodDesc = "()Ljava/lang/String;"; ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); Iterator methods = classNode.methods.iterator(); while(methods.hasNext()) { MethodNode m = methods.next(); int target_index = -1; if ((m.name.equals(targetMethodName) && m.desc.equals(targetMethodDesc))) { AbstractInsnNode currentNode = null; AbstractInsnNode targetNode = null; AbstractInsnNode targetNode2 = null; Iterator iter = m.instructions.iterator(); int index = -1; while (iter.hasNext()) { index++; currentNode = iter.next(); if (currentNode.getOpcode() == ALOAD) { if (currentNode.getPrevious().getOpcode() == INVOKEVIRTUAL) { targetNode = currentNode; } } if (currentNode.getOpcode() == INVOKESTATIC) { if (currentNode.getPrevious().getOpcode() == GETFIELD) { targetNode2 = currentNode.getPrevious(); target_index = index; } } } /* mv = cw.visitMethod(ACC_PUBLIC, "getTranslatedEntityName", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(2441, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/entity/player/EntityPlayer", "getTeam", "()Lnet/minecraft/scoreboard/Team;"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "net/minecraft/entity/player/EntityPlayer", "username", "Ljava/lang/String;"); mv.visitMethodInsn(INVOKESTATIC, "net/minecraft/scoreboard/ScorePlayerTeam", "formatPlayerName", "(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l1, 0); mv.visitMaxs(2, 1); mv.visitEnd(); */ /* mv.visitLabel(l36); mv.visitLineNumber(118, l36); mv.visitFieldInsn(GETSTATIC, "tlf/playertag/common/PlayerTag", "instance", "Ltlf/playertag/common/PlayerTag;"); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKEVIRTUAL, "tlf/playertag/common/PlayerTag", "getTaggedUsername", "(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(POP); */ /* mv = cw.visitMethod(ACC_PUBLIC, "getTranslatedEntityName", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(2441, l0); + mv.visitFieldInsn(GETSTATIC, "tlf/playertag/common/PlayerTag", "instance", "Ltlf/playertag/common/PlayerTag;"); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/entity/player/EntityPlayer", "getTeam", "()Lnet/minecraft/scoreboard/Team;"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "net/minecraft/entity/player/EntityPlayer", "username", "Ljava/lang/String;"); +- mv.visitMethodInsn(INVOKEVIRTUAL, "tlf/playertag/common/PlayerTag", "getTaggedUsername", "(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l1, 0); mv.visitMaxs(2, 1); mv.visitEnd(); */ if (targetNode == null || target_index == -1) { return bytes; } AbstractInsnNode toRemove = m.instructions.get(target_index); m.instructions.remove(toRemove); InsnList toInject = new InsnList(); //mv.visitFieldInsn(GETSTATIC, "tlf/playertag/common/PlayerTag", "instance", "Ltlf/playertag/common/PlayerTag;"); toInject.add(new FieldInsnNode(GETSTATIC, "tlf/playertag/common/PlayerTag", "instance", "Ltlf/playertag/common/PlayerTag;")); m.instructions.insertBefore(targetNode, toInject); toInject = new InsnList(); //INVOKEVIRTUAL, "tlf/playertag/common/PlayerTag", "getTaggedUsername", "(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;" toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "tlf/playertag/common/PlayerTag", "getTaggedUsername", "(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;")); m.instructions.insert(targetNode2, toInject); break; } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); return writer.toByteArray(); } }Any idea why this is happening? Thanks in advance,
-tlf
Also, what is this 'reobfuscate_srg' thing you keep talking about?
-tlf
Thanks a ton. Sorry I haven't been on in a while. For some reason, I stopped getting emails from the forums.
I am glad to hear that it was just a coremod rookie mistake. I will mention both of you on my forum when I release 1.2.2 of my mod.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumUh, no...? I didn't even know that existed until I saw you guys talking about it.
-tlf
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI'm trying to change that:
if (!this.worldObj.isRemote && this.openContainer != null && !this.openContainer.canInteractWith(this)) { this.closeScreen(); this.openContainer = this.inventoryContainer; }to this:
if (!this.worldObj.isRemote && this.openContainer != null && !this.openContainer.canInteractWith(this)) { }This is my code:
package portables.asm; import java.util.Iterator; import net.minecraft.launchwrapper.IClassTransformer; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.LineNumberNode; import org.objectweb.asm.tree.MethodNode; public class ClassTransformer implements IClassTransformer { @Override public byte[] transform(String arg0, String arg1, byte[] arg2) { if (arg0.equals("ue")) { return patchClassEnitityPlayer(arg0, arg2, true); } if (arg0.equals("net.minecraft.entity.player.EntityPlayer")) { return patchClassEnitityPlayer(arg0, arg2, false); } return arg2; } @SuppressWarnings("unused") public byte[] patchClassEnitityPlayer(String name, byte[] bytes, boolean obfuscated) { String targetMethodName = ""; if (obfuscated == true) targetMethodName = "l_"; else targetMethodName = "onUpdate"; ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); Iterator<MethodNode> methods = classNode.methods.iterator(); while (methods.hasNext()) { MethodNode m = methods.next(); int fdiv_index = -1; if ((m.name.equals(targetMethodName) && m.desc.equals("()V"))) { AbstractInsnNode currentNode = null; AbstractInsnNode targetNode = null; Iterator<AbstractInsnNode> iter = m.instructions.iterator(); int index = -1; while (iter.hasNext()) { index++; currentNode = iter.next(); if (currentNode instanceof LineNumberNode) { LineNumberNode line = (LineNumberNode)currentNode; if (line.line == 346) { targetNode = currentNode; fdiv_index = index; } } } AbstractInsnNode remNode = m.instructions.get(fdiv_index + 1); AbstractInsnNode remNode1 = m.instructions.get(fdiv_index + 2); AbstractInsnNode remNode2 = m.instructions.get(fdiv_index + 6); AbstractInsnNode remNode3 = m.instructions.get(fdiv_index + 7); AbstractInsnNode remNode4 = m.instructions.get(fdiv_index + 8); AbstractInsnNode remNode5 = m.instructions.get(fdiv_index + 9); m.instructions.remove(remNode); m.instructions.remove(remNode1); m.instructions.remove(remNode2); m.instructions.remove(remNode4); m.instructions.remove(remNode3); m.instructions.remove(remNode5); System.out.println("Patching Complete!"); break; } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); return writer.toByteArray(); } }2013-09-08 16:10:28 [INFO] [STDOUT] Patching Complete!
2013-09-08 16:10:28 [SEVERE] [ForgeModLoader] Unable to launch
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:57)
at net.minecraft.launchwrapper.Launch.main(Launch.java:18)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/entity/player/EntityPlayer
at net.minecraft.client.main.Main.main(Main.java:37)
... 6 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.entity.player.EntityPlayer
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Caused by: java.lang.NullPointerException
at org.objectweb.asm.Frame.merge(Frame.java:1292)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1303)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:592)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:515)
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:340)
at portables.asm.ClassTransformer.patchClassEnitityPlayer(ClassTransformer.java:97)
at portables.asm.ClassTransformer.transform(ClassTransformer.java:26)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:267)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:165)
... 9 more