Jump to content

Recommended Posts

Posted (edited)

Hello, so recently I've got an idea to create a simple autoclicker in Minecraft, when I've discovered JNI. Java Native Interface (JNI) is a C++ framework from Java enables code inside a JVM (java virtual machine) to be called from for example C++.

So I've found C++ code for a simple C++ program that would attach to Minecraft Forge JVM(because original Minecraft is obfuscated and I've chose Forge) using JNI, get the Forge class loader if I understand it correctly and then use a method from it to get the Minecraft class. Here's what it does (this should be right):

1. It finds the class net.minecraft.launchwrapper.LaunchClassLoader

2. It gets the static field (it's an object that's a class) classLoader from it.

3. It executes a method in the classLoader called findClas with the parameters of the Minecraft class name (net.minecraft.client.Minecraft).

This code is working correctly as intended, it successfully returns the Minecraft class. However when I try to get the method getMinecraft from the class it says that the method is null (it probably doesn't exist). I'm 100% sure that the C++ code is working correctly but for some reason it can't find the method in the class. I've also tried getting the theMinecraft static field (which should be the instance of Minecraft class) from the Minecraft class, but that is null also. Do you guys know what is wrong here? Also, if you want I can post the C++ code but I'm 100% sure it's correct.

 

EDIT:

The reason why this was not working is because THE CLASS WAS REOBFUSCATED!

 

Best Regards - Martin.

 

Edited by jumpak
Posted

Yeah, only use the JNI when you absolutely need to (i.e. never).

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 5/6/2019 at 8:49 PM, V0idWa1k3r said:

Why are you using C++ to write minecraft mods? Don't do that. Use java.

Expand  

 

  On 5/7/2019 at 12:19 AM, Cadiboo said:

Yeah, only use the JNI when you absolutely need to (i.e. never).

Expand  

Yes, I know but I'm not trying to write a mod, I'm just trying to call the clickMouse method from C++, and I know everything is right so there has to be something wrong with forge, that's why I've started this topic here on Forge. For some reason the class does not contain the getMinecraft method, as I've said above. Do you guys know why this might be?

Posted

What stops you from calling this method from java? Why must you use C++? Just write a normal java mod.

Anyway, this is a forge forum. Forge is a modding framework written in java. I don't think you would get support with C++ modding here.

Posted
  On 5/7/2019 at 2:50 PM, V0idWa1k3r said:

What stops you from calling this method from java? Why must you use C++? Just write a normal java mod.

Anyway, this is a forge forum. Forge is a modding framework written in java. I don't think you would get support with C++ modding here.

Expand  

Yeah I know what you mean but does this work from java? I mean if I use the findClass method from the classloader to find the Minecraft class will it have the getMinecraft method?

Posted (edited)
  On 5/7/2019 at 3:04 PM, V0idWa1k3r said:

If you are using java then Minecraft.getMinecraft is a public method that doesn't need reflection to be called.

Again, just make a java mod.

Expand  

Yes, I know that but I want to make like an Minecraft autoclicker, which I could just do by simulating mouse clicks, but this way it's better. I have no clue why the class doesn't have the getMinecraft method. Today I will look into some forge mod coding, but still if you have any ideas why this isn't working I would be happy if you posted them.

Edited by jumpak
Posted
  On 5/7/2019 at 3:06 PM, jumpak said:

but this way it's better

Expand  

It’s really, really not. What advantage does the JNI give you? From everything I’ve seen it’s causing you many unnecessary problems without having any benefits at all. I’m guessing that your having problems with obfuscation or are just mixing up your method signatures. You haven’t posted your code so right now there’s nothing we can do except tell you better ways of achieving what you’re trying to do. 

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Can we just get to the point of why you appear to be avoiding Java like the plague?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

you are most likely not going to get help here this is outside the scope of this forum.

and you are making a auto clicker witch is in my book a cheat  

 

Posted (edited)
  On 5/8/2019 at 11:53 AM, jumpak said:

Because I want to try "injecting" into Minecraft.

Expand  

"Injecting" into Java Code (i.e. coremodding) is not done through the JNI.

If you want you need to answer the questions that you've been asked. Without those answers we can't help.

Edited by Cadiboo

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 5/8/2019 at 1:18 PM, Cadiboo said:

"Injecting" into Java Code (i.e. coremodding) is not done through the JNI.

If you want you need to answer the questions that you've been asked. Without those answers we can't help.

Expand  

 

  On 5/8/2019 at 12:54 PM, loordgek said:

you are most likely not going to get help here this is outside the scope of this forum.

and you are making a auto clicker witch is in my book a cheat  

 

Expand  

So I've decided to switch to Java Agents. I will try this using attaching a Java Agent to forge guys, and see if it will work. I will reply here.

Posted

Coremodding is also out of scope, as coremod authors are expected to know what they are doing and have a valid reason for not doing what they want without coremodding.

 

If your entire purpose for this project is to "inject" or "coremod" or "manipulate bytecode", you will not find help here.

If you are trying to make the autoclicker for the sake of an autoclicker, try doing it with what Forge provides out of the box.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted (edited)
  On 5/9/2019 at 5:19 PM, jumpak said:

So I've decided to switch to Java Agents. I will try this using attaching a Java Agent to forge guys, and see if it will work. I will reply here.

Expand  

Forge and Minecraft already provide all this as Tweakers/Coremods but we don’t support doing that on this forum because

  On 5/9/2019 at 7:59 PM, DaemonUmbra said:

coremod authors are expected to know what they are doing and have a valid reason for not doing what they want without coremodding.

Expand  

Here’s a topic where we go a little more in depth into coremodding 

 

Edited by Cadiboo

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 5/9/2019 at 10:00 PM, Cadiboo said:

Forge and Minecraft already provide all this as Tweakers/Coremods but we don’t support doing that on this forum because

Here’s a topic where we go a little more in depth into coremodding 

 

Expand  
2

I know I've should be supposed to know what I'm doing, but I've created a Java Agent, attached the Java Agent to forge, then from the javaagent I invoked the method findClass from the field classLoader in the class net.mnecraft.launchwrapper.Launch with the parameter of the Minecraft class name (net.minecraft.client.Minecraft) and it successfully returned the class! Unfortunately, the methods in the class are obfuscated :c Do you know why this is ?

Posted

Again i must point out that you appear to be going from zero to coremodding without trying to do what you want to do with a normal mod.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

You appear to be trying to write a coremod or write JNI code without even knowing Java. Writing either of those things requires extensive intimate knowledge of how the JVM works and how Java is executed internally. There are also much better ways of doing what you’re trying to do that don’t involve either of these methods.

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 5/11/2019 at 5:03 AM, jumpak said:

Do you know why this is ?

Expand  

It’s because they’re obfuscated.

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 5/11/2019 at 8:36 AM, Cadiboo said:

You appear to be trying to write a coremod or write JNI code without even knowing Java. Writing either of those things requires extensive intimate knowledge of how the JVM works and how Java is executed internally. There are also much better ways of doing what you’re trying to do that don’t involve either of these methods.

Expand  

Yeah, I might lok into how Java is executed internally, but I know the basics of Java. Everything's working now! 

Posted

In the future, please just don't respond to people like this.

He has no idea what he is doing or why he is doing it.

And he has been told many times to do things the correct/non-hacky way. And still refuses to.

So... Topic Locked.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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