Modding

20MTD is a Unity game, which means you can mod the code, objects, and sprites.

Please backup your save file before using mods.

*Currently, the developer of 20 Minutes Till Dawn has **not** endorsed any mods of the game. Please exercise caution before downloading any and all files sent to you by Discord server members or made available by other means, and/or before visiting links to mods that were submitted to Discord by server members, mentioned on this wiki page, or listed on Nexus Mods. The developer of 20MTD, the moderators of the 20MTD discord, and the editor of this wiki, accept NO responsibility for malicious files obtained by any means, or for any game progress lost to the use of game mods.*

## General Links

* 20MTD on Thunderstore
* 20MTD on Nexus Mods
* 20MTD Discord Modding Channel (join here, see the pinned message for links to the old modding threads)
* Video tutorial by icebro

## Resources

This Google Drive folder has downloads for the game assets, for modding. The folder has two main downloads. They contain resources exported by AssetStudio, from the game version 0.6.2, and are sorted into folders:

* Texture2D - All the sprite sheets
* MonoBehaviour - Game objects (MonoBehaviour assets) as JSON. Helpful when trying to find object names for stat changes.

## Tools

The main tools you'll use are:

* **AssetStudio** - View/export assets in bulk. Very easy to use. No import options though. Can't show every asset type.
* **UABE** - Import/export assets. Clunky, but the only way to replace sprites.
* **dnSpy** - View and edit the game's c# code.

See below for details on each.

## AssetStudio

Explore and export sprites, and object data as JSON files.

Can't import assets, but is easy to use and has a great GUI.

### Links

* https://github.com/Perfare/AssetStudio
* https://github.com/Perfare/AssetStudio/releases

### View Assets

1. Go to File > Open Folder
2. Go to the data folder
	1. This is the folder named *MinutesTillDawn\_Data*, which is inside the game's main folder.
3. Confirm with the "Select Folder" button.
4. Click the Asset List tab.
5. Click an asset to preview it (if previews are supported for that asset type).
	* If the game asks you to "Select Assembly Folder", choose the "Managed" folder inside the data folder.
6. Filter assets via the Filter Type option in the top menu.

### Export Assets

1. First, click Options > Export options. In the dropdown for "Group exported assets by", choose "container path".
	1. This isn't especially useful for 20MTD but you should enable it anyway, in case you do this with other Unity games.
2. Make sure you're on the Asset List tab.
3. Use Filter Type to filter by the assets you want to export. I recommend just choosing "Texture2D2 at first.
4. Click Export (from the top menu) > Filtered assets.
	1. You can use any of the export options, this one is recommended first as it's the easiest to use.
5. Choose your output folder.

### Asset Types

* Sprite: Individual sprites. Generally not used by the game. Exports as PNG.
* Texture2D: Sprite sheets. These are what the game actually uses. Exports as PNG.
* MonoBehaviour: Game objects. Exports as JSON. Not every object type is supported, but most of the important ones are (eg. upgrades/rune effects).
* Text: The game's text. Only 1 file is useful, "localization".

### Localization

To export the localization file in particular:

* Download and open AssetStudio
* Click File > Load Folder *(from the top menu)*
* Choose the folder "MinutesTillDawn\_Data", inside the game's main folder
* Wait for it to load
* Click the "Asset List" tab
* Click Filter Type > TextAsset *(from the top menu)*
* Right-click "localization" and choose "Export selected assets"
* Choose somewhere to save the file
	+ The exported file won't have a file extension, but it's just a basic CSV
	+ If you rename the file to include the extension, you'll be able to use it easily in any spreadsheet editor (eg. Excel)
* To make a Google spreadsheet from the CSV:
	+ Upload the CSV to Google Drive
	+ Right-click on the CSV and choose to "Open with" » "Google Sheets"
	+ A new Google spreadsheet will be opened, using the CSV's data
	+ And the spreadsheet will have been created in the same folder as the CSV

## UABE

Import the updated Texture2D assets. It's clunky but once you know where things are, it gets easier.

Note: The latest release version (v3) is flagged by Windows as a malicious file. Until this is fixed, you can use the older version, 2.2-stable-d.

See also: this tutorial video by icebro.

### Links

* https://github.com/SeriousCache/UABE
* https://github.com/SeriousCache/UABE/releases/tag/2.2stabled *(version 2.2 stable-d)*

### Import Texture2D Assets

*Info for UABE v3.*

1. Find the Texture2D asset which you edited
2. While the asset is selected, click "Plugins" and then "Edit" and in the new window, click "Load" at the bottom
3. In the new file explorer window, select your modified asset and click "Open" and then "OK" in UABE
4. When you are done making all of your changes, click "File" at the top and "Apply and Save All"
5. In the new file explorer window find your games directory and save it
	1. You can't save over an existing sharedassets.asset file, because UABE is currently reading them.
	2. So you need to save your modded version as a new file.
	3. Eg. name your files like this:
		1. sharedassets0.*assets-mod*
		2. sharedassets1.*assets-mod*
6. Go to your games directory and rename the base file you edited (sharedassets) to anything (eg. sharedassets0.*assets-vanilla*) and rename your new file's file type from .assets-mod to .assets

### Mod Installer Packages (EMIPs)

Saving mods as *sharedassets0.assets* and *sharedassets0.assets* has its disadvantages: Mod users can only use one mod at a time, and if/when the game is updated, the mod creators will have to re-make those files and publish them.

An alternative to this is UABE's **mod installer packages** (EMIPs for short). These are essentially patch files, saved as *filename.emip*, and only store the modded data. Mod users can install EMIPs with UABE. Mod creators can distribute them, and use them as a kind of "save mod project" option.

#### Install EMIP

*Instructions for UABE v2.*

* Open UABE. Click File > Load Package File.
* Choose your EMIP.
* Check the 2nd box, named "Affected assets files".
	+ This will automatically check any boxes below it.
	+ See image below: *Load Package 1*.
* Where it says "Select the base folder of the files", click "Select", and choose your data folder.
	+ This is the folder named *MinutesTillDawn\_Data*, which is inside the game's main folder.
	+ After doing this, the paths shown for the affected assets should change, and will now show the correct path to these files on your HDD
	+ See image below: *Load Package 2*.
* Click OK.
	+ If you get an error *"Unable to open the file in read mode!"*, then you either set the wrong path to the data folder, or the mod creator made an error when saving the mod (which is easily done tbf).
* The Assets Info window will be shown.
	+ This window shows all the assets in the affected file(s).
	+ You can click the "Modified" column to sort the assets and move the modified files to the top.
		- See image below: *List Modified Assets*.
* Click File > Save.
* Save the file.
	+ This will be either *sharedassets0.assets* or *sharedassets1.assets*, or may be both files saved one after the other.
	+ You can't overwrite any sharedassets.asset files, you have to give the modded file a different name.
* Close UABE.
* Backup your old vanilla file, and rename your new file to replace the vanilla version.
	+ Eg. rename your old file to *sharedassets0.vanilla*
	+ Ie. rename the modded version to the same filename as the vanilla file, eg. *sharedassets0.asset*
* Load the game, and you should see your changes.

Load Package 1Load Package 2List Modified Assets
#### Save EMIP

*Instructions for UABE v2.*

* Open sharedassets1.assets
	+ You can open either 0/1, but sharedassets1 seems to reference everything included in sharedassets0.
* Make your changes.
* Click File > Mod Maker > Create installer package file *(the 2nd option)*.
* Ignore the text boxes on the left (name/credits/description).
* Click the + button next to "Affected assets files".
	+ This will list the affected asset files.
	+ By default, the full path to the file on your HDD will be shown.
	+ Obviously this is bad, because mod users won't have the same file paths as you, so we need to change this.
	+ See image below: *Create Package 1*.
* In the top-right, where it says "Select a base folder", click Select, and choose the game's data folder.
	+ This is the folder named *MinutesTillDawn\_Data*, which is inside the game's main folder.
	+ Now the "Affected assets files" should show the asset files as eg. ".\sharedassets0.assets"
* Click OK to save your package.
* You can also combine multiple packages that you've previously made, by clicking Import package.
	+ If you're making a very large mod, this might be a helpful alternative to saving everything to just one single EMIP file.
	+ This also lets you give mod users the option to only install/apply specific parts of your mod.
		- Eg. changes to just a single weapon, in a weapons mod pack.
	+ It can also be helpful to save each update to a new file.
		- See image: *Multiple EMIPs*

Create Package 1Create Package 2Multiple EMIPs
### UABEA

A version of UABE with a nicer interface and support for more recent Unity games. However, it has **a lot** of bugs and crashes frequently, causing you to lose your work often. Included here for the sake of completion.

* https://github.com/nesrak1/UABEA

## dnSpy

View and edit the game's source code (which is written in c#/Unity Mono).

Incredibly helpful if you're editing stuff like upgrade effects, as it shows you what data is available in game objects, and what it all does.

*Not needed at all for sprite modding.*

### Links

* https://github.com/dnSpy/dnSpy
* https://github.com/dnSpy/dnSpy/releases

### View Code

* Open "Assembly-CSharp.dll". It's inside data > Managed.
* You can dump the full code via File > Save as project.
* In the left explorer tree, click Assembly-CSharp, and expand the nodes you want to view.
* Most Unity games have all their code in the {-} node.
* 20MTD also has code in a custom node called flanne (after the game's developer).

### Change Code

* Open the file you want to edit.
* Right-click the method name. Choose "Edit Method".
* A box should open with the code. If not, you might have clicked the wrong option after right-clicking.
* Before you make a chance, click "Compile".
	+ This makes sure that the decompiled code, that's generated by dnSpy, can be correctly re-compiled without errors.
* Make your change.
	+ *A*lways export to a project and edit the code separately, e.g. in VS Code (which is speedy) or Visual Studio (if you're hardcore).
	+ This way, you can re-structure stuff to how you want it, and your comments etc won't be removed when re-compiling.
* Click the Compile button.
	+ Warning: Re-compiling will remove any comments and may change your code's formatting slightly.
* Go to File > Save module to apply your changes to the Assembly-csharp.dll file (make sure you backup the vanilla version first).

### Distributing patched assembly Mods

In theory, you can distribute your mod by sharing the *Assembly-csharp.dll* file, but this will mean mod users can only use 1 modded version of this file at a time, and when the game gets updated, your modded file won't work -- and will almost definitely **break the game**, potentially **corrupting save file data** in the process. Therefore, distributing modded *Assembly-csharp.dll* files is **highly discouraged**.

The recommend alternative is to create a  BepInEx plugin.

## BepInEx

BepInEx is a plugin / modding framework for Unity Mono, IL2CPP and .NET framework games (XNA, FNA, MonoGame, etc.)

It provides an API to create mods in the form of BepInEx plugins which are loaded and applied at runtime. The advantage of using BepInEx is that the original game files stay completely unmodified and as such uninstalling mods and providing compatibility between mods is much easier.

### Links

* https://github.com/BepInEx/BepInEx
* https://github.com/BepInEx/BepInEx/releases
* https://docs.bepinex.dev/

### Installing BepInEx and mods

#### Installing BepInEx

To create or install mods using BepInEx first BepInEx needs to be installed. The BepInEx installation documentation can be found here.

1. Download the latest BepInEx 5 version from here. 20 Minutes Till Dawn is compiled for Windows 64 bit so the required version is BepInEx\_x64.
2. Extract the zip file and copy its content into your 20 Minutes Till Dawn game directory. The default path is [steam]\steamapps\common\20MinuteTillDawn.
3. Launch the game. The initial launch may take a while. This allows BepInEx to generate all required files and directories.
4. Once the game has sucessfully launched close the game.
5. Open the BepInEx directory in [steam]\steamapps\common\20MinuteTillDawn\BepInEx. It should now contain a folder called "config" and a folder called "plugins". If this is the case it means BepInEx was successfully installed.

#### Configuring BepInEx

After installing BepInEx it is now possible to configure it. The main configuration file is [steam]\steamapps\common\20MinuteTillDawn\BepInEx\config\BepInEx.cfg. For users the default configuration is sufficient and doesn't require any changes.

For developers it is recommended to set Enabled to true under Logging.Console.

```
[Logging.Console]

# Default value: false
Enabled = true

```
This will launch a developer console with lots of useful information regarding BepInEx alongside your main game window.

#### Installing plugins

Now that BepInEx is installed mods/plugins based on BepInEx can be installed by simply dropping the mod.dll into [steam]\steamapps\common\20MinuteTillDawn\BepInEx\plugins.

Mods can currently be found on nexusmods and in the unofficial modding channel on the 20 Minutes Till Dawn Discord server.

#### Configuring plugins

BepInEx plugins may generate their own configuration files upon launching them the first time. Such configuration files can be found in [steam]\steamapps\common\20MinuteTillDawn\BepInEx\config\ and have the same name as the plugin that installed them.

### Creating BepInEx plugins

BepInEx provides instruction on how to create a basic plugin.

It is also recommended to look at existing plugins for examples.

Examples of BepinEx plugins for MTD:

1. Github - Hexcede/MTDLib - A WIP modding library (discontinued)
2. Github - Zeprus/20MTD-RainbowTrails - A BepInEx plugin for Rainbow Trails
3. Nexus Mods - Endless20minutes

Tools that help with understanding the inner workings of 20 Minutes Till Dawn:

* dnSpy
* UnityExplorer

*Editor note: An Introduction into UnityExplorer would also be helpful here!*

## Misc

### Save File Backups

Please backup your save file before using mods. Open the Run dialog (Win+R) and enter this to open the save file folder:

`%AppData%\..\LocalLow\Flanne\MinutesTillDawn`

You can also open it by going here:

C:\Users\{YOUR\_USERNAME}\AppData\LocalLow\Flanne\MinutesTillDawn