Sign in to follow this  
joedobo

Setting up IntelliJ for WU modding

Recommended Posts

Decompiling WU code

In order to decompile the server, server-common, client and client-common I use Procyon(https://bitbucket.org/mstrobel/procyon). It's used with a simple .bat file to decompile the whole server related code (and client) into its own IntelliJ project. This works well as you can switch over to that project and search for things or use it as a reference. My video starts out using WurmServerReference project and that is what it is, the server related code decompiled and put in it's own area. The following code is the .bat code I use to make it.

cd C:\Users\Jason\IdeaProjects
java -jar procyon-decompiler-0.5.30.jar -jar "C:\Users\Jason\Documents\WU\WU-Server\server.jar" -o  "C:\Users\Jason\IdeaProjects\WurmServerReference\src"
java -jar procyon-decompiler-0.5.30.jar -jar "C:\Users\Jason\Documents\WU\WU-Server\common.jar" -o  "C:\Users\Jason\IdeaProjects\WurmServerReference\src"

You may need to change the paths for your computer system. Once the paths reflect your system copy the code, paste it into a any text editor, name it whatever (I use "server to java.bat"), finally save it somewhere you'll remember so you can run it when CodeClub updates WU.

The client-approach equilvent to this is pretty much the same thing except I put it in its own IntelliJ project, "WurmClientReference".

 

Video to demonstrate: setting up mod, coding  it (I just quickly copied for this step), making it into ".jar", and testing in WU.

About the video:
1. You'll see me switch over to another project like the one I made. I did this so I could quickly copy the code and test it out first. I had to do a few debug runs to get things working even for a mod as simple as this. I frequently copy code form other mods anyway as there is more stuff then I seem to be able to remember.

2. This is a manual way of setting up intelliJ. I'm pretty sure it's possible to make a default Maven/Gradle/Ant/etc... code to set this all up by default. For how the manual ways works.

https://screencast-o-matic.com/watch/cbibh4lZik

 

 

Debugging Code (Thank you so much bdew!)

Do what bdew said in the quotes to setup a remote debug configuration and run it. 

 

On 4/21/2017 at 8:16 AM, bdew said:

So the easiest way to get a debugger to work in intellij:

 

  1. Go to run configurations
  2. Add a "Remote" config,
  3. Switch "transport" to "shared memory" (you can leave this on socket, but i've ran into windows not closing the socket when restarting debug sessions)
  4. Write something unique in "shared memory address" (if you are debugging multiple instances, or client+server, etc.) 
  5. Copy the text from "command line arguments blah blah blah" box (the first one)
  6. Paste it somewhere in the command line in modlauncher.bat, e.g. 
    
    %JAVA% "-Dworkdir=%CD%" "-Djava.library.path=%CD%\nativelibs" %LOGGING% -Xmn256M -Xms512m -Xmx2048m -XX:+OptimizeStringConcat -XX:+AggressiveOpts -agentlib:jdwp=transport=dt_shmem,server=y,suspend=n,address=youradresshere -jar modlauncher.jar  %*

     

  7. Run modlauncher.bat
  8. Make sure your new remote profile is selected in IDEA
  9. Click debug

The first 6 steps need only be done once, for future use just repeat 7-9.

 

Also, if for debugging vanilla code - don't attach sources decompiled by an external decompiler (procyon/jd/whatever), let intellij use it's internal decompiler, or your debugging will be wonky due to line number mismatches.

 

 

On 6/26/2017 at 10:23 AM, bdew said:

If i'm understanding correctly what the problem is... just change suspend=n to suspend=y in the command line (-agentlib:jdwp... section). It will make the process suspend immediately on startup and wait for a debugger to attach.

 

You will need to set breakpoints in the right places before attaching as it will un-suspend the process when you do.

 

 

 

 

  • Like 9

Share this post


Link to post
Share on other sites
On ‎7‎/‎17‎/‎2017 at 2:37 PM, joedobo said:

Decompiling WU code

In order to decompile the server, server-common, client and client-common I use Procyon(https://bitbucket.org/mstrobel/procyon). It's used with a simple .bat file to decompile the whole server related code (and client) into its own IntelliJ project. This works well as you can switch over to that project and search for things or use it as a reference. My video starts out using WurmServerReference project and that is what it is, the server related code decompiled and put in it's own area. The following code is the .bat code I use to make it.


cd C:\Users\Jason\IdeaProjects
java -jar procyon-decompiler-0.5.30.jar -jar "C:\Users\Jason\Documents\WU\WU-Server\server.jar" -o  "C:\Users\Jason\IdeaProjects\WurmServerReference\src"
java -jar procyon-decompiler-0.5.30.jar -jar "C:\Users\Jason\Documents\WU\WU-Server\common.jar" -o  "C:\Users\Jason\IdeaProjects\WurmServerReference\src"

You may need to change the paths for your computer system. Once the paths reflect your system copy the code, paste it into a any text editor, name it whatever (I use "server to java.bat"), finally save it somewhere you'll remember so you can run it when CodeClub updates WU.

The client-approach equilvent to this is pretty much the same thing except I put it in its own IntelliJ project, "WurmClientReference".

 

You can also use this website to decompile a .jar file very easily. You can choose from many different programs to decompile with also. ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this