Greetings fellow MPGH stalkers,
When I first started modding 7DTD almost a decade ago, the tools and resources we had were very primitive compared to what is available now. The learning curve was high, and the guides were scarce. More importantly, the native support 7DTD gave to modders was non-existent. Modders had to build from scratch and often had to create "core mods" by directly patching game assemblies. This caused mods to break every update and often created conflicts when using more than one mod at a time. However, things have greatly changed since those times. 7DTD has dramatically changed the native support for mods, and the general modding community has matured. 7DTD now natively supports loading mod assemblies and supplies Harmony with the game, making it far easier to create advanced mods for 7DTD without having to patch the Assembly-CSharp.dll directly. On top of being easier to learn and implement than traditional patches, if done correctly, the mod does not have to be updated every time 7DTD does.
I was personally quite slow at adopting this new "orthodox" modding system, but the learning curve is well worth it. I highly recommend everyone on MPGH change to this method rather than continuing to patch the Assembly-CSharp.dll directly. I won’t be putting a full tutorial here. MPGH is very restricted for posting external resources, but I do want to go over the basics and point everyone in the right direction.
------------------------------------
7DTD now provides a ModAPI that can load custom C# assemblies into the game when launched. This allows us modders to write custom C# code to change how the game functions instead of patching existing assemblies.
The basics steps for creating a mod are:
- Install and set up Visual Studio with .NET Framework support.
- Create a new .NET Framework class library (.dll) project.
- Add assembly references to 7DTD’s Assembly-CSharp.dll and any other library you need.
- Create a new class extending 7DTD’s IModApi class and implement the core InitMod method.
- Add any custom code.
To get started with these steps, I recommend checking out SphereII’s "Creating A New Visual Studio Project for A20 and above" tutorial on YouTube:
Here is an example C# class that implements everything needed. It (should) enable creative/debug menus, increase build distance/interval + item pickup range, as well as showing all players on the map:
Once finished writing a mod, build it in release mode to create a custom .dll assembly.
Like shown in SphereII's video, to add mods to 7DTD, create a Mods folder under the main 7 Days to Die root directory (if it doesn't already exist), and create another subdirectory for your new mod. In this directory, copy any mod .dll assemblies to it, as well as create a new file named "ModInfo.xml" and add my example content below (adjusting it to your needs):
Once done, the folder structure should look something like this:
Code:
7 Days to Die
\_ Mods
\_ MPGH
\_ ModInfo.xml
\_ MPGH.dll
On the 7DTD's ModAPI, to quote one of my comments on the forum:
There is no documentation for ModAPI except for the stuff fellow modders have gathered and posted around. The official ModAPI is very barebones, and there isn't a huge list of premade methods and capabilities built-in. It only provides a few ModEvents and a way to initialize custom code. The rest is left up to the modder to implement. There are several primary methods we use to add our custom functionality using the ModAPI, all through the provided InitMod entrypoint:
1. Register a handler for one of the built-in ModEvents.
2. Patch/hook a game method via the Harmony library.
3. Run custom code directly and/or add a new Unity GameObject to capitalize on its events.
Using a tool like dnSpy, we can decompile and read the game's code to determine how it works, and based on that, we can figure out how we need to adjust it in order to add our desired functionality.
In my MPGH code example, I am using the #1 capability of the ModAPI and registering a handler for 7DTD's built-in ModEvent, GameStartDone, which executes after the initial world loading is done. As mentioned, there are other ways of using the ModAPI, but the core methodology lies in using a tool like dnSpy to figure out how the game works (and what needs to be modified) and create a mod to adjust the game's functionality accordingly. For other learning resources on 7DTD modding, I recommend checking out 7DTD's modding section on their official forums.
------------------------------------
I've attached an example Visual Studio project of my MPGH mod, as well as the compiled version that can be used directly in the game.
VirusScans:
MPGH
https://virusscan.jotti.org/en-US/fi...job/4ggvfmtoa3
https://www.virustotal.com/gui/file/...50616892a82b28
MPGH_Project
https://virusscan.jotti.org/en-US/fi...job/mdui2c7lee
https://www.virustotal.com/gui/file/...35e39017cb1eae
==== Please wait until the attachments are approved before trying to download ====
If you get the following error: "Invalid Attachment specified. If you followed a valid link, please notify the administrator." You need to wait longer.