Jump to content

Modifying the Main Menu


WinneonSword

Recommended Posts

I've already experimented with ASM and the sort, and I can modify access values with ASM. I can also replace a class fairly easily. What I would like to know is to easily in 1.6.4 change a method / insert code into a vanilla method, specifically the main menu. Could anyone help me on the matter?

 

EDIT: I have gotten most of it done. But now I'm getting a NullPointerException when trying to get the ClassNode to accept a ClassWriter.

 

Here is the error:

Caused by: java.lang.NullPointerException
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:340)
at net.winneonsword.WCClient.asm.WCClassTransformer.transform(WCClassTransformer.java:119)
at net.winneonsword.WCClient.asm.WCClassTransformer.transform(WCClassTransformer.java:64)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172)
... 9 more

 

And here is the transform method:

@Override
public byte[] transform(String x, String y, byte[] z){

	byte[] bytes = z;
	PatchInfo patch = this.getPatchInfo(y);

	if (patch != null){

		bytes = this.transform(patch, bytes);

	}

	return z;

}

private byte[] transform(PatchInfo patch, byte[] z){

	boolean patched = false;
	byte[] bytes = z;

	ClassNode node = new ClassNode();
	ClassReader reader = new ClassReader(bytes);

	reader.accept(node, 0);

	WCLog.fine("Patching Class: %s", new Object[] { patch.target });

	HashMap<MethodNode, MethodNode> replace = new HashMap();

	for (MethodNode target : node.methods){

		for (MethodInfo method : patch.methods){

			if ((method.name.equals(method.name) || method.name.equals(method.mappedName))
					&& (method.desc.equals(method.desc) || method.desc.equals(method.mappedDesc))){

				MethodNode replacement = this.getReplacementMethod(patch, method);

				replace.put(target, replacement);
				WCLog.fine("Successfully Patched: %s at %s", new Object[] { method.name, method.desc });

				patched = true;

			}

		}

	}

	if (patched){

		for (MethodNode method : replace.keySet()){

			MethodNode replacement = replace.get(method);

			node.methods.remove(method);
			node.methods.add(replacement);

		}

		ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

		node.accept(writer);

		bytes = writer.toByteArray();

	}

	return bytes;

}

 

The error is coming from here:

		ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

		node.accept(writer);

		bytes = writer.toByteArray();

 

Any ideas?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.