Skip to content

Instantly share code, notes, and snippets.

@its-truce
Last active March 17, 2024 17:17
Show Gist options
  • Save its-truce/11aa30e41cc06affa2d63b86065549a6 to your computer and use it in GitHub Desktop.
Save its-truce/11aa30e41cc06affa2d63b86065549a6 to your computer and use it in GitHub Desktop.
[tModLoader] How To Decompile Mods

[tModLoader] How To Decompile Mods

NOTE: Please don't copy other people's code unless you have permission. Respect other people's wishes about distributing code. Copying code is plagiarism. This tutorial is only to teach you how to do it.

This is a bite-sized tutorial on how to decompile Terraria mods. If you want to replicate a certain effect that you saw in a mod of your own, you can decompile that mod. Here's how you can do it:

Obtaining the DLL

To obtain the .dll file, we have to use a TML.Patcher, a 3rd party tool for decompiling mods. Here's how you can install and use it:

  • Open Command Prompt.
  • Run dotnet tool install -g Tomat.TML.Patcher to install it.
  • Run tmlpatcher extract "Path/To/The/Mod.tmod" to extract the mod file at Path/To/The/Mod.tmod. The extracted files will be in the folder you ran the command in. Well, even after all that, you probably only found sprites and text files. To get the code, proceed to the next step.

Decompiling the DLL

In the folder that you extracted the files to, you should find ModName.dll file. This is what we're going to be decompiling. These are the steps to decompile the mod you chose:

  • Download the latest release of ILSpy, a program for decompiling code (If you are on Linux or Mac, you will need to use AvaloniaILSpy instead of ILSpy).
  • Run ILSpy.exe and go to File -> Open. Navigate to the folder where you extracted the mod and open the .dll file.
  • Finally, make sure the mod is selected in the navigation panel on the left. Right click it and click on "Save Code". Navigate to a convenient and empty folder (I would recommend making a "Code folder inside the folder where you extracted the mod)
  • It might take a minute or so based on your computer, but once it's done you can navigate to the folder where you saved the code and open the .csproj file in VS or your IDE of choice. Voila! You've got yourself the code of the mod. While it isn't the actual original code and might be hard to read at times, it's the second best thing. Make sure you refer to the note at the start!
@godlyvex5
Copy link

After extracting the mod there was no folder created. It does succeed, TMLpatcher runs, and it says it's extracting, but no folder appears.

@steviegt6
Copy link

lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment