Enum Patching - SlimeRancherModding/SRML GitHub Wiki

Introduction

Due to the fact that Slime Rancher relies so heavily on enums for important things such as Identifiable.Ids, SRML provides utilities for adding new values to enums

EnumPatcher

In the main SRML namespace, there is a static class called EnumPatcher that provides utilities for adding new values to enums. Some enums require you to use a Registry class, and cannot be patched through EnumPatcher. To add a new value to an enum with EnumPatcher use EnumPatcher.AddEnumValue(Type enumType, object value, string name)

Automatic Enum Registration

It's tedious to use EnumPatcher every time you need to add a new enum value, so SRML provides an easy to use attribute for it, called EnumHolder in the SRML.Utils.Enum namespace. Simply attach this attribute to a static class and when your mod is loaded, SRML will register and assign all readonly static fields with the first available free value in that enum.

[EnumHolder]
public static class ModdedIds
{
    public static readonly Identifiable.Id CUSTOM_IDENTIFIABLE; // Creates a new Identifiable.id with the first free value in Identifiable.Id with the name CUSTOM_IDENTIFIABLE
    public static readonly Gadget.Id TEST_GADGET; // Multiple different enum types can be in the same enumholder, and work much the same!
}