Well i'm back with another problems:
I wrote transformer for KeyBinding, but when i start the game it crashes...
Transformer class:
public class KeysOverhaulTransformer implements IClassTransformer{
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if(name.equals(KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding"))){
System.out.println("##################################################");
System.out.println("Patching KeyBinding");
byte[] b = patchKeyBinding(name, bytes);
System.out.println("Patching KeyBinding Completed");
System.out.println("##################################################");
return b;
}
return bytes;
}
private byte[] patchKeyBinding(String name, byte[] bytes) {
String onTick = KeysOverhaulTranslator.getMapedMethodName(name, "func_74507_a", "onTick");
String setKeyBindState = KeysOverhaulTranslator.getMapedMethodName(name, "func_74510_a", "setKeyBindState");
String resetKeyBindingArrayAndHash = KeysOverhaulTranslator.getMapedMethodName(name, "func_74508_b", "resetKeyBindingArrayAndHash");
String init = "<init>";
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
Iterator<MethodNode> methods = classNode.methods.iterator();
while(methods.hasNext()){
MethodNode method = methods.next();
if(method.name.equals(onTick)){
try{
System.out.println("**************************************************");
System.out.println("Patching onTick");
AbstractInsnNode currentNode = null;
AbstractInsnNode targetNode = null;
int place = -1;
int index = -1;
Iterator<AbstractInsnNode> iter = method.instructions.iterator();
while (iter.hasNext())
{
index++;
currentNode = iter.next();
if(currentNode.getOpcode() == Opcodes.ILOAD){
if(currentNode.getNext().getOpcode() == Opcodes.IFEQ){
targetNode = currentNode;
place = index;
break;
}
}
}
method.instructions.set(targetNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "code/elix_x/coremods/keysoverhaul/KeyBindingHelper", ".onTick", "(I)Z"));
System.out.println("Patching onTick Completed");
System.out.println("**************************************************");
}catch(Exception e){
System.out.println("Patching onTick Failed With Exception:");
e.printStackTrace();
System.out.println("**************************************************");
}
}
if(method.name.equals(setKeyBindState)){
try{
System.out.println("**************************************************");
System.out.println("Patching setKeyBindState");
AbstractInsnNode currentNode = null;
AbstractInsnNode targetNode = null;
int place = -1;
int index = -1;
Iterator<AbstractInsnNode> iter = method.instructions.iterator();
while (iter.hasNext())
{
index++;
currentNode = iter.next();
if(currentNode.getOpcode() == Opcodes.ILOAD){
if(currentNode.getNext().getOpcode() == Opcodes.IFEQ){
targetNode = currentNode;
place = index;
break;
}
}
}
method.instructions.insertBefore(targetNode, createNewListAndFillWith(new VarInsnNode(Opcodes.ILOAD, 1), new MethodInsnNode(Opcodes.INVOKESTATIC, "code/elix_x/coremods/keysoverhaul/KeyBindingHelper", ".setKeyBindState", "(I,Z)Z")));
method.instructions.remove(targetNode);
System.out.println("Patching setKeyBindState Completed");
System.out.println("**************************************************");
}catch(Exception e){
System.out.println("Patching setKeyBindState Failed With Exception:");
e.printStackTrace();
System.out.println("**************************************************");
}
}
if(method.name.equals(resetKeyBindingArrayAndHash)){
try{
System.out.println("**************************************************");
System.out.println("Patching resetKeyBindingArrayAndHash");
AbstractInsnNode currentNode = null;
AbstractInsnNode targetNode = null;
int place = -1;
int index = -1;
Iterator<AbstractInsnNode> iter = method.instructions.iterator();
while (iter.hasNext())
{
index++;
currentNode = iter.next();
if(currentNode.getOpcode() == Opcodes.GETSTATIC){
FieldInsnNode field = (FieldInsnNode) currentNode;
/*System.out.println("Owner: " + field.owner.replace("/", ".") + " Searching for: " + KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding"));
System.out.println("Name: " + field.name + " Searching for: " + KeysOverhaulTranslator.getMapedFieldName("client.settings.KeyBinding", "field_74514_b", "hash"));
System.out.println("Desc: " + field.desc);*/
if(field.owner.replace("/", ".").equals(KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding")) && field.name.equals(KeysOverhaulTranslator.getMapedFieldName("client.settings.KeyBinding", "field_74514_b", "hash"))){
targetNode = currentNode;
place = index;
break;
}
}
}
method.instructions.insert(targetNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "code/elix_x/coremods/keysoverhaul/KeyBindingHelper", ".resetKeyBindingArrayAndHash", "(Lnet/minecraft/util/IntHashMap;)Lnet/minecraft/util/IntHashMap;"));
System.out.println("Patching resetKeyBindingArrayAndHash Completed");
System.out.println("**************************************************");
}catch(Exception e){
System.out.println("Patching resetKeyBindingArrayAndHash Failed With Exception:");
e.printStackTrace();
System.out.println("**************************************************");
}
}
if(method.name.equals(init)){
try{
System.out.println("**************************************************");
System.out.println("Patching <init>");
AbstractInsnNode currentNode = null;
AbstractInsnNode targetNode = null;
int place = -1;
int index = -1;
Iterator<AbstractInsnNode> iter = method.instructions.iterator();
while (iter.hasNext())
{
index++;
currentNode = iter.next();
if(currentNode.getOpcode() == Opcodes.GETSTATIC){
FieldInsnNode field = (FieldInsnNode) currentNode;
if(field.owner.replace("/", ".").equals(KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding")) && field.name.equals(KeysOverhaulTranslator.getMapedFieldName("client.settings.KeyBinding", "field_74514_b", "hash"))){
targetNode = currentNode;
place = index;
break;
}
}
}
method.instructions.remove(targetNode.getNext());
method.instructions.remove(targetNode.getNext());
System.out.println("(IL" + KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding") + ";)L" + KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding") + ";");
method.instructions.insert(targetNode, createNewListAndFillWith(new VarInsnNode(Opcodes.ILOAD, 2), new VarInsnNode(Opcodes.ILOAD, 2), new VarInsnNode(Opcodes.ALOAD, 0), new MethodInsnNode(Opcodes.INVOKESTATIC, "code/elix_x/coremods/keysoverhaul/KeyBindingHelper", ".register", "(IL" + KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding") + ";)L" + KeysOverhaulTranslator.getMapedClassName("client.settings.KeyBinding") + ";")));
System.out.println("Patching <init> Completed");
System.out.println("**************************************************");
}catch(Exception e){
System.out.println("Patching <init> Failed With Exception:");
e.printStackTrace();
System.out.println("**************************************************");
}
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
private InsnList createNewListAndFillWith(Object... nodes) {
InsnList list = new InsnList();
for(Object node : nodes){
if(node instanceof AbstractInsnNode){
list.add((AbstractInsnNode) node);
}
if(node instanceof InsnList){
list.add(list);
}
}
return list;
}
}
And console log + crash:
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:transform:26]: ##################################################
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:transform:27]: Patching KeyBinding
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:56]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:57]: Patching onTick
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:82]: Patching onTick Completed
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:83]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:94]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:95]: Patching setKeyBindState
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:121]: Patching setKeyBindState Completed
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:122]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:133]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:134]: Patching resetKeyBindingArrayAndHash
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:163]: Patching resetKeyBindingArrayAndHash Completed
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:164]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:174]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:175]: Patching <init>
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:226]: (ILnet.minecraft.client.settings.KeyBinding;)Lnet.minecraft.client.settings.KeyBinding;
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:229]: Patching <init> Completed
[18:38:22] [Client thread/INFO] [sTDOUT]: [code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer:patchKeyBinding:230]: **************************************************
[18:38:22] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----
// Everything's going to plan. No, really, that was supposed to happen.
Time: 15.03.15 18:38
Description: Initializing game
java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at net.minecraft.client.settings.GameSettings.<init>(GameSettings.java:204)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:420)
at net.minecraft.client.Minecraft.run(Minecraft.java:931)
at net.minecraft.client.main.Main.main(Main.java:164)
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:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
at GradleStart.main(GradleStart.java:45)
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.settings.KeyBinding
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
Caused by: java.lang.NegativeArraySizeException
at org.objectweb.asm.Frame.merge(Frame.java:1343)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:834)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:726)
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:412)
at code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer.patchKeyBinding(KeysOverhaulTransformer.java:240)
at code.elix_x.coremods.keysoverhaul.core.KeysOverhaulTransformer.transform(KeysOverhaulTransformer.java:29)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176)
... 14 more
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at net.minecraft.client.settings.GameSettings.<init>(GameSettings.java:204)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:420)
-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:931)
at net.minecraft.client.main.Main.main(Main.java:164)
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:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
at GradleStart.main(GradleStart.java:45)
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_25, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 783634056 bytes (747 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML:
Launched Version: 1.7.10
LWJGL: 2.9.1
OpenGL: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
GL Caps:
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: ~~ERROR~~ NullPointerException: null
Current Language: ~~ERROR~~ NullPointerException: null
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: ~~ERROR~~ NullPointerException: null
[18:38:22] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:398]: #@!@# Game crashed! Crash report saved to: #@!@# C:\my\mcmodding\mods\toolscompressor\eclipse\.\crash-reports\crash-2015-03-15_18.38.22-client.txt
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release