Difference between revisions of "Code Modding"
| Line 8: | Line 8: | ||
== Project setup == | == Project setup == | ||
| − | To create your own mod start a .NET Class Library project in Visual Studio, targeted at the .NET 3.5 profile. You should download and install the '''.NET 3.5 Framework''' if you don't have it, '''.NET | + | To create your own mod start a .NET Class Library project in Visual Studio, targeted at the .NET 3.5 profile. You should download and install the '''.NET 3.5 Framework''' if you don't have it, '''.NET Core is not the same.''' |
You should add a reference to the following libraries: Note that you might need to add references to more, depending on what you want to do. | You should add a reference to the following libraries: Note that you might need to add references to more, depending on what you want to do. | ||
Revision as of 20:20, 7 February 2020
You can compile C# files or load dll libraries directly in Software Inc.
A good grasp of C# programming and the Unity3D API is required to make a code based mod.
Setup
Debugging console
Before you do anything, you should enable the in-game debugging console by binding the console key at the bottom of the key binding menu in the options window. This will help you debug your mod by giving you error messages and enabling the RELOAD_DLL_MOD and UNLOAD_DLL_MOD commands.
Project setup
To create your own mod start a .NET Class Library project in Visual Studio, targeted at the .NET 3.5 profile. You should download and install the .NET 3.5 Framework if you don't have it, .NET Core is not the same.
You should add a reference to the following libraries: Note that you might need to add references to more, depending on what you want to do.
- Software Inc_Data\Managed\UnityEngine.UI.dll
- Software Inc_Data\Managed\UnityEngine.dll
- Software Inc_Data\Managed\Assembly-CSharp.dll
Start by creating a class that implements the ModMeta abstract class, then implement as many classes that inherit from ModBehaviour as you want.
The ModMeta class will contain information about your mod and act as a manager for your mod.
ModBehaviours are just a subclass of Unity's MonoBehavior and work the same way, i.e. they use the same life cycle of Awake, Start, Update, OnDestroy, ModBehaviours only differ in that they have the abstract OnActive and OnDeactive methods, to signal when the mod is toggled. You should stick to the Update method, rather than trying to write your own update loop, as you cannot interact with Unity's system from other threads. Each ModBehaviour implementation will be instantiated once the mod is loaded.
Compile
When you're done, you can either compile your mod and place it in the game's folder, in a subfolder called "DLLMods", or create a new subfolder in the "DLLMods" folder and put your .cs files in that subfolder, and the game will compile them for you. Note that if you let the game compile the C# files for you, you are limited to C# version 3, but using the game's compiler is required, if you want to upload your mod to the Steam Workshop.
Please note that due to a bug in the compiler the game uses, you cannot use enums if you are using straight .cs files or the game will crash
Example mod
Here's an example of a mod that let's you change how many floors you can build on, complete with comments: Floor Mod (Updated to work with Alpha 10.7+)
Full access
By default certain namespaces and types are off limits to mods for security reasons. If you want to make a mod that writes to files or accesses the internet, you need to put a public static bool called GiveMeFreedom in your ModMeta implementation. Note that this only works for dll-based mods, which can't be uploaded to the Steam Workshop, and the user will be warned.
Entry points
| GameSettings.Instance | This class contains most of the objects that manage the game |
| GameSettings.Instance.MyCompany | The player's company |
| MarketSimulation.Active | Manages all companies and products |
| GameSettings.Instance.sRoomManager | Manages rooms, furniture and room segments |
| GameSettings.Instance.sActorManager | Manages employees and teams |
| SelectorController.Instance | Manages selection |
| TimeOfDay.Instance | Manages time |
| HUD.Instance | Manages the main HUD and windows |
| ObjectDatabase.Instance | Contains all furniture and room segments |
| WindowManager | Controls windows and has functions to create windows and GUI elements |