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

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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
17 hours ago, V0idWa1k3r said:

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

 

14 hours ago, Cadiboo said:

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

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
10 minutes ago, 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.

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)
2 minutes ago, 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.

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
10 hours ago, jumpak said:

but this way it's better

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

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Posted
9 hours ago, DaemonUmbra said:

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

Because I want to try "injecting" into Minecraft.

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)
1 hour ago, jumpak said:

Because I want to try "injecting" into Minecraft.

"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

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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 3: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.

 

On 5/8/2019 at 2: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  

 

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.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Posted (edited)
4 hours ago, 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.

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

2 hours ago, 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.

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

 

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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/10/2019 at 12:00 AM, 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 

 

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.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

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

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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
3 hours ago, jumpak said:

Do you know why this is ?

It’s because they’re obfuscated.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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
8 hours ago, Cadiboo said:

It’s because they’re obfuscated.

Oh.. I didn't notice that ! Now I know xD btw I'm not blaming you guys but I've clearly specified that in the post.

Posted
9 hours ago, 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.

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.