How to modify the Assembly-CSharp.dll. (Wall of Text Edition)
Hey MPGH users!
Introduction
Here's a detailed, step-by-step, tutorial on modifying 7DTD's Assembly-CSharp.dll that's hopefully comprehensive enough to shine light onto how to make basic "hacks" for 7DTD. This is aimed for an average 7DTD player that wants to make their own modified assembly file.
To make things clear, this will not bypass EAC. You can only use this on servers with EAC disabled. You also have to start the game with EAC disabled. So you'll need to either start it manually, or disable EAC in the launcher. If you're looking for a quick troll, I'd recommend finding a peer-to-peer game. The majority of those usually always have EAC disabled and obviously always has at least one player online.
Most tutorials like this, that I've seen, always use .NET Reflector with the Reflexil plugin. However, I'm going to be using ILSpy, which is a free alternative, with the Reflexil plugin. However, if you want to use .NET Reflector, the process should pretty much the same. I personally use .NET Reflector in my day-to-day use, as I think it works better, but most people don't want to spend money for a program that they're only going to use a couple of times. Unless you pirated it, of course. However, that's not my business. Do whatever floats your boat.
Setting up ILSpy
So to start out, you'll need to download ILSpy. Just google "ILSpy." It should the first .net URL you come across. Once there, simply click the blue "Download Binaries" button and download the .zip file containing the program. Once downloaded, extract it to your desired location.
Next you'll need to get Reflexil. So google "Reflexil." As before, the website you're looking for should be a .net address. Just like with ILSpy, find the blue "Download" button and click it. This time instead of downloading a .zip file, it should redirect you to the Reflexil Github repository. Find the latest release and download the .zip file called "reflexil.for.ILSpy.<version>.<number>.AIO.bin.zip ." It's usually the top file. Then, extract that file and copy the .dll file inside (it should be called "Reflexil.ILSpy.Plugin.dll") to the ILSpy directory with all the other .dlls that ILSpy comes with.
Now make sure 7DTD isn't running, then go to the location where 7DTD is installed. It's usually at "C:\Program Files (x86)\Steam\SteamApps\common\7 Days To Die\." Then navigate into the "7DaysToDie_Data" folder, then from there, into the "Managed" folder. Find the .dll called "Assembly-CSharp.dll" and make a backup of it. This is so if you mess up, or want to restore back to vanilla 7DTD.
Now start ILSpy and open the "Assembly-CSharp.dll" file. (Hopefully you'll be able to managed this without detailed instructions.) Then expand the assembly by pressing the "+" button next to the assembly's name in the list of linked assemblies on the left side of the ILSpy window. (The name of the assembly is probably "Assembly-CSharp (0.0.0.0).") Then expand the "sub-directory" "-" of the Assembly-CSharp. In this "directory" you'll find most of the code that you'll be modifying.
"Hack" locations
The following section are several examples of editing the assembly to enable a particular "hack." You will need the locations for different "hacks" before you can edit them. You can either find them yourself, or you can find a fullish list of locations for A16.1 in the MPGH thread called "A16.1 B1 Cheat Sheet." The only notable difference is that the location for the creative/debug menu is now "-/GameManager/UD/MoveNext(): Boolean" instead of "-/GameManager/GL/MoveNext(): Boolean" in A16.1. Just note that these locations can change with every game update.
Editing the assembly
So for example, If I wanted to enable the debug menu in A16.1. I'll go to big list of "directories" that appeared when I expanded the "-" "directory" earlier, I'm going to look for the "sub-directory" "GameManager." Once I find that, I'll expand it. (My "path" so far, counting the "-" "directory", is "-/GameManager/.") Then I'll look for the inner class called "UD." (If it's not visible in ILSpy, make sure the code is decompiled to "IL" and the option "Show internal types and members" is enabled. However, having the code decompiled to C# is preferred, if possible.) Once I find it, I'll expand it. Then I'll look for the method "MoveNext(): Boolean" and select it. (Now my "path" is "-/GameManager/UD/MoveNext(): Boolean.") A whole bunch of code should appear in the right side of the ILSpy window. Now I can read the code, but I can't modify it. This is where the Reflexil plugin comes into play. So to activate Reflexil, go to the "View" tab on the top-left of the ILSpy window. Inside that, you should see an option for "Reflexil <versionnumber>." Once clicked, an additional window should appear on the bottom of where the decompiled code is being displayed. Inside this new window, under the "Instructions" tab, there should be several columns called "Offset," "OpCode," and "Operand." Now while looking at the "OpCode" column, scroll down that list until you see the opcode of "ldc.i4.s," with the operand of "40". (This is referring to the entry at index 40 in the "EnumGamePrefs" enumerator. In this case, the "DebugMenuEnabled" entry.) For A16.1, it should be at line 133, but this changes with every 7DTD update. Once I find it, I'll select the opcode that's immediately after it. It should be "ldc.i4.0." (In case you're wondering, this typically means false, in code) Right-click it and select the "Edit..." button. Then I'll change the "OpCode" from "Idc.i4.0" to "Idc.i4.1" and click the "Update" button. Don't touch the "Operand type" or "Operand" fields. By doing this, I've changed a false to true in the code, and by doing so, enabled the debug menu.
Since the location for the creative menu is located at the same place. I'll enabled it since I'm already there. So I will continue to scroll down in the list of opcodes until I find the opcode "ldc.i4.s," with the operand of "42". (Like before, this is referring to the "CreativeMenuEnabled" entry in the "EnumGamePrefs" enum.) I will repeat what I did to the first one and change the "ldc.i4.0" immediately after it to "Idc.i4.1" by selecting it. Then by right-clicking the "Edit..." button and changing the "OpCode" to "ldc.i4.1," and clicking "Update." Now I have both the creative and debug menus enabled.
I'll do two more different examples, then I'll wrap up with exporting the finished .dll file.
So now I'll enable extreme damage. There are several ways to do this, but for this example, I'm going to use my favorite method. So back in the base "-" "directory", I'm going to look the for the "sub-directory" "EntityPlayerLocal." Once I've expanded it, I'll look for the "GetStaminaMultiplier(): Single" method (the return type, the ": Single," can change depending on the language the code is decompiled to). Once this method is selected, in Reflexil's "Instructions" tab, I'll right-click in the list of opcodes and click "Delete all." Now I'll right-click and click the "Create new..." button. Now in the OpCode field I'll type "ldc.r4," in the "Operand" field, I'll type "99999," and finally change the "Operand type" to "Single," then click "Append." Now I'll create another opcode and type in "ret" in the OpCode field (leaving the other fields blank), then the click "Insert after selection" button. Just make sure the "ret" is after the "ldc.r4" in the list of opcodes. If it's not, drag it to the proper spot. Now I have extreme damage enabled.
Finally I'll add all players to my map. So again starting from the "-" "directory," I'll find the "sub-directory" "EntityPlayer." (It's the "directory" above "EntityPlayerLocal.") Now I'll select the method "IsDrawMapIcon(): Boolean," delete all the opcodes like before. I'll create a new opcode of "ldc.i4.1," making sure to leave the "Operand" and "Operand type" fields blank. Then I'll create another opcode of "ret," also like before, making sure that it's after the "ldc.i4.1" opcode in the list of opcodes.
Just as a note, the decompiled code inside ILSpy will not change when modifying with Reflexil until the assembly is save and re-opened. So don't freak out and think it's not working because of that.
Saving the edited assembly
Now that I've made my modifications, I'm going to save my changes. I'll do this by right-clicking on the assembly (it's probably called "Assembly-CSharp (0.0.0.0)," if you haven't been paying attention) and clicking on the "Save as..." button. (Under the Reflexil tab if you're using .NET Reflector.) Now I'll navigate to my "Managed" folder in my 7DTD directory, then naming by new assembly "Assembly-CSharp.dll," and clicking "Save." (Make sure you have a backup of the original before overwriting it!) Now I'm ready to go. I can start 7DTD (making sure EAC is disabled) and troll some nubs on their server.
Wrapping up
I've read this thing to death, but there are still probably unclear portions, or flat out mistakes. If you find one, feel free to msg me or leave a reply. Leave a thanks if this helped you out!
Happy hacking!
- Sqeegie