Script Files

The metadata file contains a Scripts field. This field is an array that lists all the scripts to be loaded by the mod as relative paths. While not necessary, it's convenient to split your mod into multiple files if it's big enough.

The EntryPoint field points the game to the entry point in your mod. This is typically formatted like Namespace.Class. The game will look for static void Main() at the specified entry point. This method is called every time the toybox (aka catalog) is repopulated. This typically happens when the map is opened or when a local contraption was modified.

The game will also look for static void OnLoad(). This is an optional method but it is useful for initialisation code that runs before anything else. The method is invoked right after the mod is compiled. Complementing OnLoad, static void OnUnload() is called just before the game window is closed.

using UnityEngine;

namespace CoolMod
{
    public class CoolMod
    {
        public static void OnLoad()
        {
            Debug.Log("Cool Mod has loaded! :)");
        }

        public static void Main()
        {
            ModAPI.Register(
                new Modification()
                {
                    OriginalItem = ModAPI.FindSpawnable("Generator"),
                    NameOverride = "Ultra gaming generator [CoolMod]",
                    NameToOrderByOverride = "Generator 2",
                    DescriptionOverride = "Generator specifically for gaming",
                    CategoryOverride = ModAPI.FindCategory("Machinery"), 
                    ThumbnailOverride = ModAPI.LoadSprite("gen2.png"),
                    AfterSpawn = (Instance) => 
                    {
                        Instance.transform.localScale = new Vector3(5, 5, 5);
                        Instance.GetComponent<GeneratorBehaviour>().TargetCharge = 150000;
                    }
                }
            );
        }

        public static void OnUnload()
        {
            Debug.Log("Cool Mod has been unloaded :(");
        }
    }
}

Common script file. The entry point would be CoolMod.CoolMod

A typical script file will look like the image above. The two important parts of the modding API are ModAPI and Modification. There are a few classes that may be useful aside from the two mentioned earlier.

Attention!

This member is obsolete and should not be used. It is a remnant from the past.

bi bij bibi