CWEnumUtils

版本 v1.0.3·更新於 2024-04-18

A library to help with creating and getting Enums

模組介紹 作者原文

Content Warning Enum Utils

A library with utilities for dynamically creating and getting Enums.

Originally for Lethal Company, but ported to Content Warning for a request. Everything is identical except the dll relies on CW files instead.

For feature requests or issues, go to my repo.

General Users

This mod is just a dependency for other mods, it doesn't add content by itself.

Recommended Install

Please use a mod manager. I recommend r2modman as the mod manager to use.

Developer Quick-Start

Download the latest release from either the.

Extract the zip and add a reference to the dll file of the mod in the IDE (Visual Studio, Rider, or etc) you use.

Enum Utilities

Getting Enums

Shortcuts for getting enums. There is various functions you can use.

Here are some of the examples.

[BepInPlugin(modGUID, modName, modVersion)]

public class ExampleModClass: BaseUnityPlugin

{

private void Start()

{

RARITY mythic = EnumUtils.Parse("mythic");

if (EnumUtils.TryParse("example", out RARITY example))

{

}

int numOfRarities = EnumUtils.Count();

RARITY minRarity = EnumUtils.GetMinValue();

RARITY maxRarity = EnumUtils.GetMaxValue();

RARITY randomRarity = EnumUtils.GetRandom();

RARITY unusedRarityValue = EnumUtils.GetFirstFreeValue();

string allRarityNames = EnumUtils.GetNames();

RARITY allRarityValues = EnumUtils.GetValues();

bool doesExampleRarityExist = EnumUtils.IsDefined("example");

Type valueType = EnumUtils.GetUnderlyingType();

bool hasFlags = EnumUtils.IsPowerOfTwoEnum();

}

}

Creating Enums

You can use the EnumUtils class to create enums just like this.

[BepInPlugin(modGUID, modName, modVersion)]

public class ExampleModClass: BaseUnityPlugin

{

// Associate an unused enum value with a name of your choosing.

private static readonly RARITY example = EnumUtils.Create("example");

// Associate a specific enum value with a name of your choosing.

private static readonly RARITY example2 = EnumUtils.Create("example2", -1);

private void Awake()

{

}

}

Enum Holders

Another way to create enums.

Add the [EnumHolder] attribute to a class, run the RegisterAllEnumHolders function, and any static enum fields will have an enum value created with the name of the field. It'll select any unused enum value to be associated with that name (or if you specify a value it'll use that one).

using System.Reflection;

[BepInPlugin(modGUID, modName, modVersion)]

public class ExampleModClass: BaseUnityPlugin

{

private void Awake()

{

EnumUtils.RegisterAllEnumHolders(Assembly.GetExecutingAssembly());

}

}

[EnumHolder]

public static class ExampleEnumHolderClass

{

public static readonly RARITY example;

public static readonly RARITY example2 = (RARITY)-1;

}

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

BepInEx-BepInExPack

檔案與校驗

檔案名稱
CWEnumUtils-1.0.3.zip
檔案大小
33.5 KiB