Modding with dnspy (Tutorial)

While still in it's infancy, the simulation aims to be heavily customizable and allow users to customize their experience through adding mods to the game. The only *official* kind of modding are procedural sprite replacing mods. But with the use of an external tool, the game's code itself can be modified and changed.

This article is going to serve as a guide on how to do that, with the use the tool "dnspy".

## Getting Started

Download dnspy's latest release from here: https://github.com/dnSpy/dnSpy/releases. dnSpy is a .NET assembly editor. You can use it to edit and debug assemblies even if you don't have any source code available, which we don't.

Make a copy of the folder the game is stored it for the modding. This is done because it is unwise to directly modify game code without having a backup of it, in case you might screw things up.

## Working with dnspy

Open dnspy.exe to launch the program. Click on the "File" Tab in the upper left corner of the screen and select "Open". Navigate to your game's folder, open the "The Bibites\_Data" folder, open the "Managed" folder and finally open "BibitesAssembly.dll". This is the file where all the games code is stored.

On the left Assembly Explorer panel, you will now see "BibitesAssembly" as an item. Click on the little triangle to the left of it to expand it and click it again on the "BibitesAssembly.dll" sub item. If you do this, you will see a lot of items of yellow text show up. Of those, the "SimulationScripts" and "SimulationScripts.BibiteScripts" are the most important for modding, so expand them both. You will see a lot of items of green text show up. Those are the classes of this game. Double-click on one of them to open it up

With a class opened, you can start to modify the code. For that, press right click somewhere and choose "edit class" or press right click over a method and choose "edit method" to go into the editor view. From there, you can edit the game's code.

## Navigating the Code

#### With dnspy

To modify parts of a game, you first must know where those parts, whose functionalities you want to alter, are located. The names of the .cs files are a great place to start. You can then look through the file for the functions you want to alter, or you can use CTRL F to search for function names. You can click on methods, classes or field are brought automatically to its definition. Furthermore, you can do the reverse by right-clicking and selecting "Analyze" on a methods, class or field to find all places it is used.

#### With Visual Studio

Another good way to navigate the games code is with Visual Studio. It allows for much better search than dnspy with its solution explorer, searching not only the names of .cs files, but also the methods, classes and field within them. It can also find the definition and all references of a method, class or field by right-clicking and selecting "Go to Definition" and "Find all references" respectively.

In order to use Visual Studio, you first have to download that too. You can download it from here. But you also have to export your decompiled Assembly file as a Visual Studio Project. For that, go to the "File" tab in dnspy and select "Export to Project". Choose a folder to put the Project into, select the right Visual Studio version and click on export. You then just have to open the Project with Visual Studio.

NOTE: due to decompliation weirdness, you will not be able to compile the Visual Stuio project back into a .dll file. All modifications you want to make will have to be done though dnspy. The sole purpose Visual Studio Project in this Tutorial is just for better navigation tool and is entirely optional.

## Saving the Mod

From the code editor view, you have to click on the "Compile" Button on the window to compile the changes code. Note that the code it will show in the general view after compiling the program might look identical to the code you have written, but it will have identical functionality.

To save the whole Mod, click on the saving icon in the top command row. It's directly to the left of the field, where you select the language you want to decompile into. By default, it will replace the file you opened, so be sure to change the save location if you don't want that. To do that, click on the 3 dots next to the filename and select the location you do what the Mod to be saved in. Click on Ok once you're done.

NOTE: If you put this file in a different location, be sure to copy all .dll's used by the code over to that location. If you don't, dnspy will not be able to compile classes, as the referenced .dll's are not available to it.

## Publishing the Mod

To publish the Mod, just upload the edited "BibiteAssembly.dll" somewhere (preferably GitHub) for people to download. You should also include an installation guide, as installing Mods is not as straight forward as putting a mod folder in the Mods folder of the game, like it intended to be done in the future, but requires the replacement of the game's own "BibiteAssembly.dll". One sample installation guide:

```
How to install the Constance Mod:
1) Backup of your Bibite game folder
2) Download the zip file of the mod
3) Unpack the zip file somewhere
4) Take the file BibitesAssembly.dll and drop it into <path to executable folder>\The Bibites\_Data\Managed. When Windows asks you, whether you would like to you want to replace the file, you click yes.

```

## Solution to the Problems of Modding with dnspy

Since the Mod made through dnspy are installed by wholly replacing the singular file that holds the game's code, it is impossible to have multiple different mods installed at one time.

This can be somewhat remedied by packing a number of mods into one singular mod (-pack). Currently, there is one such project in existence: The Vanilla Expanded Modpack. It is a mod pack containing mods which could be reasonably added to the base game. People are free to contribute to the project and add their own mods to it. For that, fork the Development branch to add your mod to that. For questions about the specific workings of this mod pack, you can contact Reddit user YBKy for help. Once you're ready, you can make a pull request to attempt to merge your fork into the Development branch. Once it holds a sufficient number of mods, that will be merged into the main branch.