Making Mods for 1.81+

In general, there are two types of modding:


 * Item Modding which uses ModComponent to insert new items into the game
 * Normal Modding which changes the game through Melon Loader and Harmony Patches

Item Modding
See the ModComponent Wiki for more details

Normal Modding
This is an introductory tutorial on Normal Modding. I will be using Visual Studio Community Edition.


 * 1) Launch Visual StudioMakingMods1.png
 * 2) Click "Create a new project"MakingMods2.png
 * 3) We are coding in C#. Select "Class Library (.Net Framework)" from the options. Under the list of frameworks, select ".NET Framework 4.7.2". Press "Next"MakingMods3.png
 * 4) Name your Mod. For this example, I named it "ExampleMod". After you've chosen your name, click "Create".MakingMods4.png
 * 5) Click on the heading "Project".MakingMods5.png
 * 6) Click on "ExampleMod Properties"MakingMods6.png
 * 7) If the target framework is not ".NET Framework 4.7.2", you need to change it to that, save everything, and reload the project. If everything is good, you can continue by clicking on "Reference Paths".MakingMods7.png
 * 8) This is the list of folders where Visual Studio will look for assemblies your mod can access. Click on "Browse" and find your mods folder.MakingMods8.png
 * 9) Once you've selected your Mods folder, click "Select Folder".MakingMods9.png
 * 10) The folder is not yet on the list of reference paths. We must click "Add Folder".MakingMods10.png
 * 11) We're going to repeat this for two more folders. The first is called "MelonLoader". It is located in the same folder as your mods folder. Click "Browse" and find it.MakingMods11.png
 * 12) Select the MelonLoader folder and click "Select Folder". Then click "Add Folder".MakingMods12.png
 * 13) The second is called "Managed". It is located in the MelonLoader folder. Click "Browse" and find it.MakingMods13.png
 * 14) Select the Managed folder and click "Select Folder". Then click "Add Folder".MakingMods14.png
 * 15) We're now ready to add references to our project. Click on "Project" in the header.MakingMods15.png
 * 16) Click on "Add Reference"MakingMods16.png
 * 17) This is the menu where you add references to your project. Many of the references we're about to add are required and cannot be left out. Search for "assembly-csharp".MakingMods17.png
 * 18) Enable "Assembly-CSharp". This file contains most of The Long Dark's code.MakingMods18.png
 * 19) Search for "il2cpp".MakingMods19.png
 * 20) Enable "Il2Cppmscorlib" and "Il2CppSystem"MakingMods20.png
 * 21) Search for "MelonLoader"MakingMods21.png
 * 22) Enable "MelonLoader". This loads your mod.MakingMods22.png
 * 23) Search for "unhollower"MakingMods23.png
 * 24) Enable "UnhollowerBaseLib" and "UnhollowerRuntimeLib"MakingMods24.png
 * 25) Search for "unity"MakingMods25.png
 * 26) Enable "UnityEngine" and "UnityEngine.CoreModule". If your mod requires any other unity modules, you should also enable them.MakingMods26.png
 * 27) We've added all the references typically required. If your mod uses another mod as a dependency (such as ModSettings), you should also search for and add that mod as a reference. Note that these dependency mods won't show up in the search results unless they're already in your Mods folder. If you have no other references to add, click "OK".MakingMods27.png
 * 28) Steps 28 through 30 are optional but remove an annoyance of many modders. Click on "Assembly-CSharp"MakingMods28.png
 * 29) In the reference properties for Assembly-CSharp, change "Copy Local" from true to false.MakingMods29.png
 * 30) Do the same on all the other references. Some references (such as System) may be set to false by default.MakingMods30.png
 * 31) Hide the references and click on "Class1.cs"MakingMods31.png
 * 32) Right click on "Class1.cs" and rename it to "Implementation". This is optional but a good convention.MakingMods32.png
 * 33) Click "Yes" so that it renames the class inside the file.MakingMods33.png
 * 34) We need to add two "using" statements to this file.MakingMods34.png
 * 35) We want "Implementation" to inherit from the class "MelonMod".MakingMods35.png
 * 36) We're going to add an override of "OnApplicationStart". This runs right after MelonLoader loads all the mods.MakingMods36.png
 * 37) We're going to add a log statement to identify our mod's presence in the game logs.MakingMods37.png
 * 38) In the Solution Explorer, show the PropertiesMakingMods38.png
 * 39) Click on "AssemblyInfo.cs"MakingMods39.png
 * 40) Add a "using" statement for MelonLoaderMakingMods40.png
 * 41) Scroll to the bottomMakingMods41.png
 * 42) Add these lines of codeMakingMods42.png
 * 43) In the Solution Explorer, right click on "ExampleMod"MakingMods43.png
 * 44) Move your mouse to the "Add" menu.MakingMods44.png
 * 45) Click on "New Item"MakingMods45.png
 * 46) We want to add a class file, and we want to name it "Patches.cs"MakingMods46.png
 * 47) Click "Add"MakingMods47.png
 * 48) Add "using" statements for HarmonyLib and UnityEngineMakingMods48.png
 * 49) We're going to put a patch in this file. It will run anytime "GameManager" is created. When this patch runs, it will output "Hello World" to the MelonLoader terminal.MakingMods49.png
 * 50) In the header, click on "Build".MakingMods50.png
 * 51) Click "Build Solution"MakingMods51.png
 * 52) If your build was successful, you should find "ExampleMod.dll" in your project's debug folder. This file can then be copied to the Mods folder for testing.MakingMods52.png
 * 53) This was my output in the MelonLoader terminal. (Note that these 2 screenshots were from MelonLoader 2.7.4. Your output will be slightly different in MelonLoader 4, but almost the same.)MakingMods output1.pngMakingMods output2.png

Additional Resources
C Sharp

Harmony Patching

MelonLoader Wiki

Intro to Reflection

TinyJSON Documentation (accessed with MelonLoader.TinyJSON)

Unhollower Documentation

Contributing on Github